2.3. Tactics in Lean
In the previous chapter we stated theorems, often leaving the proof as
sorry. In this chapter we learn how to prove them using tactics. A
tactic is a command that transforms the current proof state into zero or more
new states (the subgoals). A proof state has the form
\underbrace{h_1 : P_1,\; \ldots,\; h_n : P_n}_{\text{hypotheses}} \;\vdash\; \underbrace{G}_{\text{goal}}
that is, a list of hypotheses (the local context) and a goal to be proved. When a tactic closes the goal without producing new subgoals, that branch of the proof is finished; the proof is complete when no goals remain.
The proof style we study here is that of backward proofs: we start from the goal and decompose it into smaller subgoals until we reach hypotheses or already known facts. The opposite style, forward proofs, proceeds from the hypotheses toward the conclusion and will be studied in the next chapter.
At the end of the chapter we prove the equivalence of three principles of classical logic: the law of excluded middle, Peirce's law, and double-negation elimination.
2.3.1. Tactic mode
The keyword by introduces a block of tactics, executed in sequence from top
to bottom:
theorem name : statement :=
by
tactic₁
…
tacticN
A minimal example is the proof of \forall a\; b : \mathsf{Prop},\; a \to b \to a:
namespace Ch10
theorem fst_of_two_props :
∀ a b : Prop, a → b → a :=
⊢ ∀ (a b : Prop), a → b → a
intro a a:Propb:Prop⊢ a → b → a a:Propb:Propha:a⊢ b → a a:Propb:Propha:ahb:b⊢ a
All goals completed! 🐙
Before the first tactic, the state is ⊢ ∀ (a b : Prop), a → b → a. After
intro a b ha hb, the variables and hypotheses move into the context and the
state becomes a b : Prop, ha : a, hb : b ⊢ a. The tactic exact ha closes
the goal. In an editor with Lean support (such as VS Code), the proof state is
displayed at every step, and following it is the best way to understand a
tactic proof.
An important remark: Prop is a type just like ℕ or List Bool.
Propositions are terms of type Prop, and that is why we can quantify over
them, as we did above with ∀ a b : Prop.
2.3.2. Basic tactics
2.3.2.1. intro, apply, and exact
The intro tactic moves universal quantifiers (\forall) and premises of
implications (\to) from the conclusion into the hypotheses. The tactic
apply h tries to unify the conclusion of h with the goal; if it
succeeds, the premises of h become new goals. The tactic exact h is like
apply, but requires that h prove the goal exactly, without leaving pending
premises; it signals that the goal is completely solved.
theorem prop_comp (a b c : Prop)
(hab : a → b) (hbc : b → c) :
a → c :=
a:Propb:Propc:Prophab:a → bhbc:b → c⊢ a → c
a:Propb:Propc:Prophab:a → bhbc:b → cha:a⊢ c -- goal: c
a:Propb:Propc:Prophab:a → bhbc:b → cha:a⊢ b -- goal: b
a:Propb:Propc:Prophab:a → bhbc:b → cha:a⊢ a -- goal: a
All goals completed! 🐙 -- closes the goal
Read the proof backward: to show c it suffices to show b (thanks to
hbc); to show b it suffices to show a (thanks to hab); and a is the
hypothesis ha.
2.3.2.2. assumption
The assumption tactic automatically searches the local hypotheses for one
that matches the goal:
theorem fst_of_two (a b : Prop) (ha : a) (hb : b) : a :=
a:Propb:Propha:ahb:b⊢ a All goals completed! 🐙
2.3.3. The rfl tactic
The rfl tactic closes goals of the form l = r when both sides are
definitionally equal, that is, equal by computation. The recognized
reductions are the following, identified by Greek letters:
-
α (renaming of bound variables):
(fun x ↦ f x) = (fun y ↦ f y); -
β (application of an anonymous function):
(fun x ↦ f x) a = f a; -
δ (unfolding of definitions):
double 5 = 5 + 5, ifdouble n := n + n; -
ζ (unfolding of
let):(let n : ℕ := 2; n + n) = 4; -
η (syntactic extensionality):
(fun x ↦ f x) = f; -
ι (reduction of constructors and projections):
Prod.fst (a, b) = a.
Examples in Lean:
theorem α_example {α β : Type} (f : α → β) :
(fun x ↦ f x) = (fun y ↦ f y) := α:Typeβ:Typef:α → β⊢ (fun x => f x) = fun y => f y All goals completed! 🐙
theorem β_example {α β : Type} (f : α → β) (a : α) :
(fun x ↦ f x) a = f a := α:Typeβ:Typef:α → βa:α⊢ (fun x => f x) a = f a All goals completed! 🐙
def double (n : ℕ) : ℕ := n + n
theorem δ_example : double 5 = 5 + 5 := ⊢ double 5 = 5 + 5 All goals completed! 🐙
theorem ζ_example :
(let n : ℕ := 2; n + n) = 4 := ⊢ (let n := 2;
n + n) =
4 All goals completed! 🐙
theorem η_example {α β : Type} (f : α → β) :
(fun x ↦ f x) = f := α:Typeβ:Typef:α → β⊢ (fun x => f x) = f All goals completed! 🐙
theorem ι_example {α β : Type} (a : α) (b : β) :
Prod.fst (a, b) = a := α:Typeβ:Typea:αb:β⊢ (a, b).1 = a All goals completed! 🐙
2.3.4. The rw tactic
The tactic rw [h] rewrites the goal using the equation h : l = r: it
replaces occurrences of l with r, from left to right. With rw [← h], the
rewriting is done from right to left. After rewriting, rw tries to close the
goal with rfl.
theorem Eq_trans_symm {α : Type} (a b c : α)
(hab : a = b) (hcb : c = b) : a = c :=
α:Typea:αb:αc:αhab:a = bhcb:c = b⊢ a = c
α:Typea:αb:αc:αhab:a = bhcb:c = b⊢ b = c -- goal: b = c
All goals completed! 🐙 -- goal: b = b, closed by rfl
The rw tactic can also unfold definitions: rw [Not] replaces ¬ p with
the definition of Not, which is p → False (we will see this below).
theorem a_proof_of_negation (a : Prop) : a → ¬¬ a :=
a:Prop⊢ a → ¬¬a
a:Prop⊢ a → ¬a → False -- ¬¬a becomes (¬a → False)
a:Prop⊢ a → (a → False) → False -- ¬a becomes (a → False)
intro ha a:Propha:ahna:a → False⊢ False
a:Propha:ahna:a → False⊢ a
All goals completed! 🐙
2.3.5. The simp and ac_rfl tactics
The simp tactic exhaustively applies a set of rewrite rules, the simp
set, made up of lemmas tagged with the @[simp] attribute in the library.
Extra lemmas can be passed in brackets, simp [h₁, …, hN], including local
hypotheses and names of definitions (which are then unfolded):
theorem cong_two_args {α : Type} (a b c d : α)
(g : α → α → ℕ → α)
(hab : a = b) (hcd : c = d) :
g a c (1 + 1) = g b d 2 :=
α:Typea:αb:αc:αd:αg:α → α → ℕ → αhab:a = bhcd:c = d⊢ g a c (1 + 1) = g b d 2 All goals completed! 🐙
Here simp rewrites a to b and c to d, and computes 1 + 1 = 2.
The ac_rfl tactic closes goals whose two sides are equal modulo
associativity and commutativity of operators such as + and *:
theorem abc_Eq_cba (a b c : ℕ) :
a + b + c = c + b + a :=
a:ℕb:ℕc:ℕ⊢ a + b + c = c + b + a All goals completed! 🐙
2.3.6. Rules for the connectives
Each logical connective has introduction rules, which say how to prove a
formula with that connective, and elimination rules, which say how to use a
hypothesis with that connective. In Lean, these rules are simply lemmas (or
constructors) from the library, which we use with apply and exact. The
introduction rules are:
-
True.intro : True -
And.intro : a → b → a ∧ b -
Or.inl : a → a ∨ bandOr.inr : b → a ∨ b -
Iff.intro : (a → b) → (b → a) → (a ↔ b) -
Exists.intro : (t : α) → p t → ∃ x, p x
And the elimination rules:
-
False.elim : False → a -
And.left : a ∧ b → aandAnd.right : a ∧ b → b -
Or.elim : a ∨ b → (a → c) → (b → c) → c -
Iff.mp : (a ↔ b) → a → bandIff.mpr : (a ↔ b) → b → a -
Exists.elim : (∃ x, p x) → (∀ x, p x → b) → b
Compare these with the natural deduction rules studied in the first part of
the course: they are exactly the same, now as Lean constants. For \to and
\forall, introduction is done by intro and elimination by application
(apply h, or h t).
Let us look at some examples. Commutativity of conjunction uses And.intro
to build the conclusion and And.left/And.right to take the hypothesis
apart.
theorem And_swap (a b : Prop) : a ∧ b → b ∧ a :=
a:Propb:Prop⊢ a ∧ b → b ∧ a
a:Propb:Prophab:a ∧ b⊢ b ∧ a
a:Propb:Prophab:a ∧ b⊢ ba:Propb:Prophab:a ∧ b⊢ a
a:Propb:Prophab:a ∧ b⊢ b All goals completed! 🐙
a:Propb:Prophab:a ∧ b⊢ a All goals completed! 🐙
After apply And.intro, two goals remain, b and a; each one is handled by
a block starting with ·. Commutativity of disjunction uses Or.elim,
producing one case for each side of the disjunction:
theorem Or_swap (a b : Prop) : a ∨ b → b ∨ a :=
a:Propb:Prop⊢ a ∨ b → b ∨ a
a:Propb:Prophab:a ∨ b⊢ b ∨ a
a:Propb:Prophab:a ∨ b⊢ a → b ∨ aa:Propb:Prophab:a ∨ b⊢ b → b ∨ a
a:Propb:Prophab:a ∨ b⊢ a → b ∨ a a:Propb:Prophab:a ∨ bha:a⊢ b ∨ a; All goals completed! 🐙
a:Propb:Prophab:a ∨ b⊢ b → b ∨ a a:Propb:Prophab:a ∨ bhb:b⊢ b ∨ a; All goals completed! 🐙
To prove an existential, we must exhibit a witness. Using the function
double defined above:
theorem Exists_double_iden : ∃ n : ℕ, double n = n :=
⊢ ∃ n, double n = n
⊢ double 0 = 0
All goals completed! 🐙
After apply Exists.intro 0, the goal is double 0 = 0, which holds by
computation. To use an existential hypothesis, we apply Exists.elim, which
gives us an arbitrary witness together with the property it satisfies:
theorem Exists_double_six (h : ∃ n : ℕ, double n = 6) :
∃ m : ℕ, m + m = 6 :=
h:∃ n, double n = 6⊢ ∃ m, m + m = 6
h:∃ n, double n = 6⊢ ∀ (a : ℕ), double a = 6 → ∃ m, m + m = 6
intro n h:∃ n, double n = 6n:ℕhn:double n = 6⊢ ∃ m, m + m = 6
h:∃ n, double n = 6n:ℕhn:double n = 6⊢ n + n = 6
All goals completed! 🐙
The step exact hn works because double n = 6 and n + n = 6 are
definitionally equal (δ-reduction).
An equivalence is proved through its two implications:
theorem And_comm_iff (a b : Prop) : a ∧ b ↔ b ∧ a :=
a:Propb:Prop⊢ a ∧ b ↔ b ∧ a
a:Propb:Prop⊢ a ∧ b → b ∧ aa:Propb:Prop⊢ b ∧ a → a ∧ b
a:Propb:Prop⊢ a ∧ b → b ∧ a All goals completed! 🐙
a:Propb:Prop⊢ b ∧ a → a ∧ b All goals completed! 🐙
2.3.7. Negation
In Lean, negation is defined as implication of absurdity:
\neg P \;\stackrel{\text{def}}{=}\; P \to \mathsf{False}
#print Not
This is why there are no separate rules for \neg: we use the same rules as
for implication. To prove ¬ p, we introduce a hypothesis hp : p and derive
False; to use hn : ¬ p, we apply it to a proof of p. For example,
double-negation introduction holds without classical logic:
theorem Not_Not_intro (a : Prop) : a → ¬¬ a :=
a:Prop⊢ a → ¬¬a
intro ha a:Propha:ahna:¬a⊢ False
a:Propha:ahna:¬a⊢ a
All goals completed! 🐙
The converse, \neg\neg a \to a, is not provable in intuitionistic logic.
Lean, however, provides classical axioms:
#check Classical.em
#check Classical.byContradiction
2.3.8. Equality
Equality has four fundamental rules: reflexivity, symmetry, transitivity, and
substitution (if a = b and p a, then p b).
#check @Eq.refl
#check @Eq.symm
#check @Eq.trans
#check @Eq.subst
The type Sort u_1 generalizes Type and Prop; for now, it is enough to
think of α as an arbitrary type. We can reprove Eq_trans_symm using the
combinators directly:
theorem Eq_trans_symm' {α : Type} (a b c : α)
(hab : a = b) (hcb : c = b) : a = c :=
α:Typea:αb:αc:αhab:a = bhcb:c = b⊢ a = c
α:Typea:αb:αc:αhab:a = bhcb:c = b⊢ a = ?bα:Typea:αb:αc:αhab:a = bhcb:c = b⊢ ?b = cα:Typea:αb:αc:αhab:a = bhcb:c = b⊢ α
α:Typea:αb:αc:αhab:a = bhcb:c = b⊢ a = ?b All goals completed! 🐙
α:Typea:αb:αc:αhab:a = bhcb:c = b⊢ b = c α:Typea:αb:αc:αhab:a = bhcb:c = b⊢ c = b; All goals completed! 🐙
The version with rw is more idiomatic; Eq.trans and Eq.symm are useful
when we need the combinators as first-class terms, for instance when writing
proof terms directly (next chapter).
2.3.9. Mathematical induction
The tactic induction x with performs structural induction on x, creating
one subgoal for each constructor of the inductive type of x. For the natural
numbers there is the zero case and the succ case; in the latter, we gain
an induction hypothesis (which we name ih) for the predecessor.
Let us return to the addition and multiplication of the previous chapter:
def add : ℕ → ℕ → ℕ
| m, Nat.zero => m
| m, Nat.succ n => Nat.succ (add m n)
def mul : ℕ → ℕ → ℕ
| _, Nat.zero => Nat.zero
| m, Nat.succ n => add m (mul m n)
Since add is defined by recursion on the second argument, add m 0 = m
holds by definition, but add 0 n = n requires induction:
theorem add_zero (n : ℕ) : add 0 n = n :=
n:ℕ⊢ add 0 n = n
induction n with
⊢ add 0 0 = 0 All goals completed! 🐙
n':ℕih:add 0 n' = n'⊢ add 0 (n' + 1) = n' + 1 All goals completed! 🐙
In the succ case, the goal is add 0 (n' + 1) = n' + 1; simp [add, ih]
unfolds the definition, obtaining (up to notation) Nat.succ (add 0 n') on
the left-hand side, and the hypothesis ih : add 0 n' = n' finishes the job.
Commutativity additionally requires a lemma about the successor in the first
argument:
theorem add_succ (m n : ℕ) :
add (Nat.succ m) n = Nat.succ (add m n) :=
m:ℕn:ℕ⊢ add m.succ n = (add m n).succ
induction n with
m:ℕ⊢ add m.succ 0 = (add m 0).succ All goals completed! 🐙
m:ℕn':ℕih:add m.succ n' = (add m n').succ⊢ add m.succ (n' + 1) = (add m (n' + 1)).succ All goals completed! 🐙
theorem add_comm (m n : ℕ) : add m n = add n m :=
m:ℕn:ℕ⊢ add m n = add n m
induction n with
m:ℕ⊢ add m 0 = add 0 m All goals completed! 🐙
m:ℕn':ℕih:add m n' = add n' m⊢ add m (n' + 1) = add (n' + 1) m All goals completed! 🐙
theorem add_assoc (l m n : ℕ) :
add (add l m) n = add l (add m n) :=
l:ℕm:ℕn:ℕ⊢ add (add l m) n = add l (add m n)
induction n with
l:ℕm:ℕ⊢ add (add l m) 0 = add l (add m 0) All goals completed! 🐙
l:ℕm:ℕn':ℕih:add (add l m) n' = add l (add m n')⊢ add (add l m) (n' + 1) = add l (add m (n' + 1)) All goals completed! 🐙
Distributivity of multiplication over addition combines simp and ac_rfl.
For ac_rfl to know that our add is associative and commutative, we must
register these facts as instances of the classes Std.Associative and
Std.Commutative:
instance : Std.Associative add := ⟨add_assoc⟩
instance : Std.Commutative add := ⟨add_comm⟩
theorem mul_add (l m n : ℕ) :
mul l (add m n) = add (mul l m) (mul l n) :=
l:ℕm:ℕn:ℕ⊢ mul l (add m n) = add (mul l m) (mul l n)
induction n with
l:ℕm:ℕ⊢ mul l (add m 0) = add (mul l m) (mul l 0) All goals completed! 🐙
l:ℕm:ℕn':ℕih:mul l (add m n') = add (mul l m) (mul l n')⊢ mul l (add m (n' + 1)) = add (mul l m) (mul l (n' + 1))
l:ℕm:ℕn':ℕih:mul l (add m n') = add (mul l m) (mul l n')⊢ add l (add (mul l m) (mul l n')) = add (mul l m) (add l (mul l n'))
All goals completed! 🐙
In the succ case, after simp the goal is
add l (add (mul l m) (mul l n')) = add (mul l m) (add l (mul l n')), which
holds merely by rearranging the terms — exactly the job of ac_rfl.
2.3.10. Focusing on subgoals
When a tactic such as apply produces several goals, it is good practice to
make explicit which part of the proof solves each one. The marker · tactic
focuses on the first pending goal and requires the tactics in the block to
close it completely (otherwise an error is reported). The same effect can be
obtained with braces, { tactic }.
theorem And_swap_braces :
∀ a b : Prop, a ∧ b → b ∧ a :=
⊢ ∀ (a b : Prop), a ∧ b → b ∧ a
intro a a:Propb:Prop⊢ a ∧ b → b ∧ a a:Propb:Prophab:a ∧ b⊢ b ∧ a
a:Propb:Prophab:a ∧ b⊢ ba:Propb:Prophab:a ∧ b⊢ a
a:Propb:Prophab:a ∧ b⊢ b All goals completed! 🐙
a:Propb:Prophab:a ∧ b⊢ a All goals completed! 🐙
Explicit focusing makes the proof more robust and readable: if something changes, the error shows up in the right block.
2.3.11. Cleaning up the context
In long proofs, the context may accumulate irrelevant hypotheses. The tactic
clear h removes the hypothesis (or variable) h, provided nothing else
depends on it. To rename a hypothesis, we use rename' h => h' (from
Mathlib); the rename tactic of core Lean has a different syntax,
rename P => h, and renames the hypothesis whose type is P.
theorem cleanup_example (a b c : Prop)
(ha : a) (hb : b) (hab : a → b) (hbc : b → c) :
c :=
a:Propb:Propc:Propha:ahb:bhab:a → bhbc:b → c⊢ c
b:Propc:Prophb:bhbc:b → c⊢ c
b:Propc:Prophb:bhbc:b → c⊢ b
b:Prophb:b⊢ b
b:Proph:b⊢ b
All goals completed! 🐙
2.3.12. Classical axioms
Three principles of classical logic can be formulated as Lean propositions
(note that we quantify over propositions, which is possible because Prop is
a type):
def ExcludedMiddle : Prop :=
∀ a : Prop, a ∨ ¬ a
def Peirce : Prop :=
∀ a b : Prop, ((a → b) → a) → a
def DoubleNegation : Prop :=
∀ a : Prop, ¬¬ a → a
None of them is provable in intuitionistic logic, but they are logically equivalent to one another: assuming any one of them, the other two become provable.
\mathsf{ExcludedMiddle} \;\Leftrightarrow\; \mathsf{Peirce} \;\Leftrightarrow\; \mathsf{DoubleNegation}
It suffices to prove the circular chain of implications
\mathsf{EM} \longrightarrow \mathsf{Peirce} \longrightarrow \mathsf{DN} \longrightarrow \mathsf{EM}
2.3.12.1. From excluded middle to Peirce
Assume excluded middle and the hypothesis h : (a → b) → a. By cases on
a ∨ ¬ a: if a holds, we are done; if ¬ a holds, we apply h, and it
remains to prove a → b; given ha : a, we have a contradiction with ¬ a,
from which anything follows by False.elim. Since ExcludedMiddle is a
definition, we first unfold it with rw.
theorem Peirce_of_EM : ExcludedMiddle → Peirce :=
⊢ ExcludedMiddle → Peirce
⊢ (∀ (a : Prop), a ∨ ¬a) → ∀ (a b : Prop), ((a → b) → a) → a
intro em em:∀ (a : Prop), a ∨ ¬aa:Prop⊢ ∀ (b : Prop), ((a → b) → a) → a em:∀ (a : Prop), a ∨ ¬aa:Propb:Prop⊢ ((a → b) → a) → a em:∀ (a : Prop), a ∨ ¬aa:Propb:Proph:(a → b) → a⊢ a
em:∀ (a : Prop), a ∨ ¬aa:Propb:Proph:(a → b) → a⊢ a → aem:∀ (a : Prop), a ∨ ¬aa:Propb:Proph:(a → b) → a⊢ ¬a → a
em:∀ (a : Prop), a ∨ ¬aa:Propb:Proph:(a → b) → a⊢ a → a em:∀ (a : Prop), a ∨ ¬aa:Propb:Proph:(a → b) → aha:a⊢ a
All goals completed! 🐙
em:∀ (a : Prop), a ∨ ¬aa:Propb:Proph:(a → b) → a⊢ ¬a → a em:∀ (a : Prop), a ∨ ¬aa:Propb:Proph:(a → b) → ahna:¬a⊢ a
em:∀ (a : Prop), a ∨ ¬aa:Propb:Proph:(a → b) → ahna:¬a⊢ a → b
em:∀ (a : Prop), a ∨ ¬aa:Propb:Proph:(a → b) → ahna:¬aha:a⊢ b
em:∀ (a : Prop), a ∨ ¬aa:Propb:Proph:(a → b) → ahna:¬aha:a⊢ False
All goals completed! 🐙
2.3.12.2. From Peirce to double negation
Given hnna : ¬¬ a, we instantiate Peirce with b := False: to prove a, it
suffices to prove (a → False) → a, that is, ¬ a → a. Given hna : ¬ a, we
have hnna hna : False, and hence a.
theorem DN_of_Peirce : Peirce → DoubleNegation :=
⊢ Peirce → DoubleNegation
⊢ (∀ (a b : Prop), ((a → b) → a) → a) → ∀ (a : Prop), ¬¬a → a
intro peirce peirce:∀ (a b : Prop), ((a → b) → a) → aa:Prop⊢ ¬¬a → a peirce:∀ (a b : Prop), ((a → b) → a) → aa:Prophnna:¬¬a⊢ a
peirce:∀ (a b : Prop), ((a → b) → a) → aa:Prophnna:¬¬a⊢ (a → False) → a
peirce:∀ (a b : Prop), ((a → b) → a) → aa:Prophnna:¬¬ahna:a → False⊢ a
peirce:∀ (a b : Prop), ((a → b) → a) → aa:Prophnna:¬¬ahna:a → False⊢ False
All goals completed! 🐙
2.3.12.3. From double negation to excluded middle
This is the most ingenious part. By double negation, it suffices to prove
¬¬ (a ∨ ¬ a). Suppose hn : ¬ (a ∨ ¬ a); we need False. Applying hn, it
suffices to prove a ∨ ¬ a; we choose the right-hand side, ¬ a. Given
ha : a, we apply hn again, this time proving the left-hand side with ha.
theorem EM_of_DN : DoubleNegation → ExcludedMiddle :=
⊢ DoubleNegation → ExcludedMiddle
⊢ (∀ (a : Prop), ¬¬a → a) → ∀ (a : Prop), a ∨ ¬a
intro dn dn:∀ (a : Prop), ¬¬a → aa:Prop⊢ a ∨ ¬a
dn:∀ (a : Prop), ¬¬a → aa:Prop⊢ ¬¬(a ∨ ¬a)
dn:∀ (a : Prop), ¬¬a → aa:Prophn:¬(a ∨ ¬a)⊢ False
dn:∀ (a : Prop), ¬¬a → aa:Prophn:¬(a ∨ ¬a)⊢ a ∨ ¬a
dn:∀ (a : Prop), ¬¬a → aa:Prophn:¬(a ∨ ¬a)⊢ ¬a
dn:∀ (a : Prop), ¬¬a → aa:Prophn:¬(a ∨ ¬a)ha:a⊢ False
dn:∀ (a : Prop), ¬¬a → aa:Prophn:¬(a ∨ ¬a)ha:a⊢ a ∨ ¬a
All goals completed! 🐙
With the three implications in hand, we obtain the equivalences. For example:
theorem EM_iff_DN : ExcludedMiddle ↔ DoubleNegation :=
⊢ ExcludedMiddle ↔ DoubleNegation
⊢ ExcludedMiddle → DoubleNegation⊢ DoubleNegation → ExcludedMiddle
⊢ ExcludedMiddle → DoubleNegation em:ExcludedMiddle⊢ DoubleNegation
All goals completed! 🐙
⊢ DoubleNegation → ExcludedMiddle All goals completed! 🐙
end Ch10
Note that, although ExcludedMiddle is accepted as an axiom in Lean
(Classical.em), the proofs above do not use it: they are intuitionistic
proofs of implications between classical principles.
2.3.13. Summary
The tactics seen in this chapter are:
-
intro: introduces variables of\foralland premises of\to; -
apply h: unifies the conclusion ofhwith the goal and produces goals for the premises; -
exact h: closes the goal with exactlyh; -
assumption: closes the goal with a hypothesis from the context; -
rfl: closes definitional equalities (α, β, δ, ζ, η, ι); -
rw [h],rw [← h]: rewrites with an equation or definition; -
simp [h₁, …]: exhaustive rewriting with the simp set; -
ac_rfl: equality modulo associativity and commutativity; -
induction x with: structural induction; -
·: focusing on a subgoal;clearandrename': cleaning up the context.
References: Avigad et al., The Hitchhiker's Guide to Logical Verification (2025), ch. 3; Nipkow and Klein, Concrete Semantics (2014), ch. 3.
2.3.14. Exercises
-
Prove, using only
intro,apply, andexact:theorem I (a : Prop) : a → a := sorry theorem K (a b : Prop) : a → b → b := sorry theorem C (a b c : Prop) : (a → b → c) → b → a → c := sorry theorem proj_fst (a : Prop) : a → a → a := sorry theorem some_nonsense (a b c : Prop) : (a → b → c) → a → (a → c) → b → c := sorry -
Prove contraposition and the distributivity of
\forallover\land:theorem contrapositive (a b : Prop) : (a → b) → ¬ b → ¬ a := sorry theorem forall_and {α : Type} (p q : α → Prop) : (∀ x, p x ∧ q x) ↔ (∀ x, p x) ∧ (∀ x, q x) := sorry -
Prove the commutativity and associativity of the multiplication defined in this chapter (
mul_commandmul_assoc). You will need auxiliary lemmas analogous toadd_zeroandadd_succ. -
Prove the De Morgan law that holds intuitionistically and, using
Classical.em, the one that requires classical logic:theorem not_or (a b : Prop) : ¬ (a ∨ b) ↔ ¬ a ∧ ¬ b := sorry theorem not_and (a b : Prop) : ¬ (a ∧ b) ↔ (¬ a ∨ ¬ b) := sorry
-
Complete the equivalences between the classical axioms by proving
Peirce ↔ DoubleNegationandExcludedMiddle ↔ Peircefrom the three theorems of the chapter. -
Prove directly (without going through Peirce) that
ExcludedMiddle → DoubleNegation.