Day 5: And, or, not, if and only if
Read ∧, ∨, ¬, ≠ and ↔, and know how they group.
Four more symbols, and you can read most statements:
-
P ∧ Q: P and Q (both hold). -
P ∨ Q: P or Q (at least one holds, maybe both). -
¬ P: not P. Anda ≠ bis short for¬ (a = b). -
P ↔ Q: P if and only if Q (each implies the other).
theorem facts : 2 < 3 ∧ 3 < 4 := ⊢ 2 < 3 ∧ 3 < 4 All goals completed! 🐙
theorem either : 2 = 3 ∨ 2 = 2 := ⊢ 2 = 3 ∨ 2 = 2 All goals completed! 🐙
theorem nope : ¬ (2 = 3) := ⊢ ¬2 = 3 All goals completed! 🐙
(by decide asks Lean to settle a statement about specific numbers by computing.)
Like × before + in arithmetic, these symbols have an order. From tightest to loosest:
-
¬(applies to the smallest piece after it) -
=,<,≤,≠(comparisons) -
∧ -
∨ -
→ -
↔
So ¬ P ∧ Q means (¬ P) ∧ Q, not ¬ (P ∧ Q). And P ∧ Q → R means (P ∧ Q) → R. When in doubt, look for brackets.
↔ is two arrows in one: P ↔ Q means P → Q and Q → P.
theorem even_iff (n : Nat) : n % 2 = 0 ↔ (n + 2) % 2 = 0 := n:Nat⊢ n % 2 = 0 ↔ (n + 2) % 2 = 0 All goals completed! 🐙
A common slip is to treat a one-way → as if it were ↔. When a claim says “exactly when” or “if and only if”, the Lean statement must use ↔.
Now you can read hypotheses that combine conditions:
theorem small (n : Nat) (h : n > 2 ∧ n < 5) : n = 3 ∨ n = 4 := n:Nath:n > 2 ∧ n < 5⊢ n = 3 ∨ n = 4 All goals completed! 🐙
For every n, if n > 2 and n < 5, then n = 3 or n = 4.