Stage 09 · Step 44 of 50
Connect two two-way rules.
01The idea
A puzzle has three doors labeled P, Q, and R. You have two passes that work in both directions, one between P and Q and one between Q and R.
Show how to travel between the outer doors.
02In maths
If P is equivalent to Q and Q is equivalent to R, then P is equivalent to R.
Picture it
Swipe sideways to see the whole picture.
a : P ↔ Q works both ways: a.mp goes forward and a.mpr goes back. To reach R from P, cross both passes forward. To come home from R, cross them backward in the opposite order, b.mpr first. constructor asks for both trips because a two-way rule needs both directions.03In Lean
This code comes directly from the file checked by Lean.
example (P Q R : Prop) (a : P ↔ Q) (b : Q ↔ R) : P ↔ R := by
constructor
· intro p
exact b.mp (a.mp p)
· intro r
exact a.mpr (b.mpr r)
For a pass a : P ↔ Q, a.mp travels forward and a.mpr travels backward. Read the last letter of mpr as a reminder to reverse direction.
Follow the type at each door. In the return trip, b.mpr r reaches Q, so a.mpr can carry that result to P.
04Step by step
Choose a line to see Lean’s recorded goal state after that line.
P Q R : Prop a : P ↔ Q b : Q ↔ R ⊢ P ↔ R
After line 1: example (P Q R : Prop) (a : P ↔ Q) (b : Q ↔ R) : P ↔ R := by
P Q R : Prop a : P ↔ Q b : Q ↔ R ⊢ P ↔ R
After line 2: constructor
case mp P Q R : Prop a : P ↔ Q b : Q ↔ R ⊢ P → R case mpr P Q R : Prop a : P ↔ Q b : Q ↔ R ⊢ R → P
After line 3: · intro p
case mp P Q R : Prop a : P ↔ Q b : Q ↔ R p : P ⊢ R
After line 4: exact b.mp (a.mp p)
no goals
After line 5: · intro r
case mpr P Q R : Prop a : P ↔ Q b : Q ↔ R r : R ⊢ P
After line 6: exact a.mpr (b.mpr r)
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 Q : Prop) (h : P ↔ Q) (q : Q) : P := by
exact h.mp q
Application type mismatch: The argument q has type Q but is expected to have type P in the application h.mp q
The forward direction h.mp accepts P, but q supplies Q.
The fix: Choose h.mpr to travel from Q back to P.
07Your turn
sorry is a placeholder for unfinished work. Replace it as you solve each task. A finished proof has no placeholders.
- Warm-up
Use a two-way rule to travel from Q back to P.
Show a hint
Check which side q proves.
One more hint
The backward implication is a.mpr.
- A little stretch
One pass is written Q ↔ P. Build both routes between P and R.
Show a hint
Start by splitting the equivalence into two directions.
One more hint
From P, use a.mpr before b.mp. From R, use b.mpr before a.mp.
example (P Q : Prop) (a : P ↔ Q) (q : Q) : P := by
sorry
example (P Q R : Prop) (a : Q ↔ P) (b : Q ↔ R) : P ↔ R := 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 Q : Prop) (a : P ↔ Q) (q : Q) : P := by
exact a.mpr q
example (P Q R : Prop) (a : Q ↔ P) (b : Q ↔ R) : P ↔ R := by
constructor
· intro p
exact b.mp (a.mpr p)
· intro r
exact a.mp (b.mpr r)
no goals
08A quick check
09New words & tools
Take your time. Progress is yours to mark.