5. Propositions are types of evidence
A proposition is a statement that can have a proof. In Lean, propositions inhabit Prop, and a proof of P is a term whose type is P. This is the bridge between programs and proofs: constructing a function and constructing a proof both involve producing a value of an expected type.
Lean erases proofs during compilation. Lean also treats proofs of the same proposition as indistinguishable for definitional equality, a principle called proof irrelevance.
The logical constructors
| Statement | Read it as | Construct its evidence by |
|---|---|---|
P → Q | P implies Q | A function accepting a proof of P |
P ∧ Q | P and Q | A pair of proofs |
P ∨ Q | P or Q | A chosen side and its proof |
¬ P | not P | A function from P to False |
P ↔ Q | P if and only if Q | A proof in each direction |
∀ x : α, R x | R holds for every x | A function accepting any x |
∃ x : α, R x | Some x satisfies R | A witness and its proof |
The following examples construct proofs directly as terms.
variable {P Q R : Prop}
theorem swapAnd (h : P ∧ Q) : Q ∧ P :=
⟨h.2, h.1⟩
theorem chain (hpq : P → Q) (hqr : Q → R) : P → R :=
fun hp => hqr (hpq hp)
theorem leftChoice (hp : P) : P ∨ Q :=
Or.inl hp
theorem existsNext (n : Nat) : ∃ m : Nat, m = n + 1 :=
⟨n + 1, rfl⟩
Angle brackets construct tuples or constructor values when the expected type determines which constructor is needed. h.1 and h.2 project the left and right proofs of a conjunction.
A proof of P ∧ Q gives you both component proofs. For P ∨ Q, consider each constructor in turn. For an existential, introduce a witness and its proof.
Core Lean’s cases can express these steps. Tactics such as rcases offer more compact ways to decompose evidence.
Bool, Prop, and decidability
Bool is a data type with true and false. Prop is a universe of statements. For example, n == 0 normally computes a Boolean through BEq, while n = 0 is a proposition.
A Decidable P value contains either evidence of P or evidence of ¬ P. It allows programs to branch on a proposition. Natural-number equality and order have executable decision procedures, which is why if amount ≤ balance then ... else ... works.
example : (7 : Nat) ≤ 10 := by decide
example : ¬ ((9 : Nat) = 4) := by decide
decide proves a closed decidable proposition through its decision procedure. Use it when Lean has a decision procedure it can evaluate for the goal.
Classical supplies classical principles, including noncomputable decisions for arbitrary propositions. Proofs can use classical reasoning, while executable application logic needs a computational decision procedure. Mark definitions that rely on noncomputable decisions with noncomputable.
Quantifier order is a design decision
∀ x, ∃ y, R x y allows y to depend on x. ∃ y, ∀ x, R x y requires a shared y. Decide which dependency the requirement calls for before writing the proof.
Exercises
- Prove
P → Q → P ∧ Qas a term. - Prove
P ∧ Q → P. - Prove
¬ P → P → QusingFalse.elim. - Give an informal example where changing the order of
∀and∃changes a true statement into a false one.