Stage 09 · Step 44 of 50

Connect two two-way rules.

Core Lean12 minutesLean 4.36.0

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.

Goalie · Your guide for this idea
Goalie pointing

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

Two two-way passes make a road both ways between P and RThree doors P, Q and R in a row. A two-way pass a : P iff Q joins P and Q, and b : Q iff R joins Q and R. Above, the forward trip for case mp, goal P implies R: after intro p, go from P to Q with a.mp and from Q to R with b.mp, giving b.mp (a.mp p). Below, the return trip for case mpr, goal R implies P: after intro r, go from R to Q with b.mpr and from Q to P with a.mpr, giving a.mpr (b.mpr r).constructor turns P ↔ R into two tripscase mp⊢ P → Rintro pcase mpr⊢ R → Pintro ra : P ↔ Qb : Q ↔ RPQRa.mpb.mpb.mpra.mprb.mp (a.mp p)lands on Ra.mpr (b.mpr r)lands on P

Swipe sideways to see the whole picture.

Each pass 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.

E44.leanTry it live (opens official Lean editor)
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.

After line 1
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

Captured from Lean 4.36.0
no goals

A goal is what remains to prove. The symbol ⊢ points to it. Meet the turnstile.

07Your turn

sorry is a placeholder for unfinished work. Replace it as you solve each task. A finished proof has no placeholders.

  1. Warm-up

    Use a two-way rule to travel from Q back to P.

  2. A little stretch

    One pass is written Q ↔ P. Build both routes between P and R.

Exercises/E44.leanTry it live (opens official Lean editor)
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

08A quick check

1. Why does constructor produce two goals?

Read the answer and explanation

An equivalence needs both implications. Each direction of ↔ needs its own proof.

2. Which trip starts at R?

Read the answer and explanation

b.mpr then a.mpr. Travel backward to Q, then backward again to P.

One more idea in your toolkit.

Take your time. Progress is yours to mark.