Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

StatementRead it asConstruct its evidence by
P → QP implies QA function accepting a proof of P
P ∧ QP and QA pair of proofs
P ∨ QP or QA chosen side and its proof
¬ Pnot PA function from P to False
P ↔ QP if and only if QA proof in each direction
∀ x : α, R xR holds for every xA function accepting any x
∃ x : α, R xSome x satisfies RA 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

  1. Prove P → Q → P ∧ Q as a term.
  2. Prove P ∧ Q → P.
  3. Prove ¬ P → P → Q using False.elim.
  4. Give an informal example where changing the order of ∀ and ∃ changes a true statement into a false one.