Stage 04 · Step 18 of 50
A two-way promise.
01The idea
A two-way bridge needs a route in both directions. “If and only if” also makes two promises.
Prove each implication to establish the equivalence.
02In maths
P ∧ Q if and only if Q ∧ P.
Picture it
Swipe sideways to see the whole picture.
↔ is two one-way roads, one in each direction. constructor splits it into the forward road (case mp) and the road back (case mpr), and you must build both. Each road is an implication: intro h takes the pair you start with, and ⟨h.right, h.left⟩ repacks its two halves in swapped order.03In Lean
This code comes directly from the file checked by Lean.
example (P Q : Prop) : (P ∧ Q) ↔ (Q ∧ P) := by
constructor
· intro h
exact ⟨h.right, h.left⟩
· intro h
exact ⟨h.right, h.left⟩
The symbol ↔ means “if and only if.” Type it with \iff. This is a logical equivalence.
The constructor for an equivalence asks for a forward implication and a reverse implication.
An equivalence and an equality are different kinds of statement. Here we prove the two implications directly.
04Step by step
Choose a line to see Lean’s recorded goal state after that line.
P Q : Prop ⊢ P ∧ Q ↔ Q ∧ P
After line 1: example (P Q : Prop) : (P ∧ Q) ↔ (Q ∧ P) := by
P Q : Prop ⊢ P ∧ Q ↔ Q ∧ P
After line 2: constructor
case mp P Q : Prop ⊢ P ∧ Q → Q ∧ P case mpr P Q : Prop ⊢ Q ∧ P → P ∧ Q
After line 3: · intro h
case mp P Q : Prop h : P ∧ Q ⊢ Q ∧ P
After line 4: exact ⟨h.right, h.left⟩
no goals
After line 5: · intro h
case mpr P Q : Prop h : Q ∧ P ⊢ P ∧ Q
After line 6: exact ⟨h.right, h.left⟩
no goals
05Lean says
no goals
A goal is what remains to prove. The symbol ⊢ points to it. Meet the turnstile.
06A common slip
Lean is telling us something useful here.
example (P : Prop) : P ↔ P := by
constructor
· intro h
exact h
unsolved goals case mpr P : Prop ⊢ P → P
Only one direction of the equivalence has been supplied.
The fix: Prove the other implication as well.
07Your turn
sorry is a placeholder for unfinished work. Replace it as you solve each task. A finished proof has no placeholders.
- Warm-up
Prove that P is equivalent to itself.
Show a hint
There are two implications.
One more hint
Introduce and return the proof in each direction.
- A little stretch
Show that P and P is equivalent to P.
Show a hint
Extract one component in the forward direction.
One more hint
Duplicate the supplied proof in the reverse direction.
example (P : Prop) : P ↔ P := by
sorry
example (P : Prop) : (P ∧ P) ↔ P := by
sorry
Compare with the checked solutions
There are often several valid proofs. These solutions were compiled with the same pinned Lean version.
example (P : Prop) : P ↔ P := by
constructor
· intro h
exact h
· intro h
exact h
example (P : Prop) : (P ∧ P) ↔ P := by
constructor
· intro h
exact h.left
· intro h
exact ⟨h, h⟩
no goals
08A quick check
09New words & tools
Take your time. Progress is yours to mark.