Stage 09 · Step 43 of 50
Keep a clue in both cases.
01The idea
Everyone on the trip has a ticket and either a red wristband or a blue one. Sort the group by wristband.
Each group still has its tickets.
02In maths
P and (Q or R) implies (P and Q) or (P and R).
Picture it
Swipe sideways to see the whole picture.
h holds a ticket h.1 and a wristband choice h.2. cases h.2 sorts people by wristband, but the ticket is untouched, so it is still there in both cases. Each case pairs the ticket with its band using ⟨h.1, …⟩, then Or.inl or Or.inr says which side of the goal that pair proves.03In Lean
This code comes directly from the file checked by Lean.
example (P Q R : Prop) (h : P ∧ (Q ∨ R)) : (P ∧ Q) ∨ (P ∧ R) := by
cases h.2 with
| inl q => exact Or.inl ⟨h.1, q⟩
| inr r => exact Or.inr ⟨h.1, r⟩
h.1 is the ticket, and h.2 carries the wristband choice. Split only h.2 so you can reuse the ticket in either branch.
In Or.inl ⟨h.1, q⟩, the angle brackets build a pair of proofs. The outer constructor identifies which alternative that pair establishes.
04Step by step
Choose a line to see Lean’s recorded goal state after that line.
P Q R : Prop h : P ∧ (Q ∨ R) ⊢ P ∧ Q ∨ P ∧ R
After line 1: example (P Q R : Prop) (h : P ∧ (Q ∨ R)) : (P ∧ Q) ∨ (P ∧ R) := by
P Q R : Prop h : P ∧ (Q ∨ R) ⊢ P ∧ Q ∨ P ∧ R
After line 2: cases h.2 with
P Q R : Prop h : P ∧ (Q ∨ R) x✝ : Q ∨ R ⊢ P ∧ Q ∨ P ∧ R
After line 3: | inl q => exact Or.inl ⟨h.1, q⟩
no goals
After line 4: | inr r => exact Or.inr ⟨h.1, 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 R : Prop) (h : P ∧ (Q ∨ R)) : P ∧ Q := by
exact ⟨h.1, h.2⟩
Application type mismatch: The argument h.right has type Q ∨ R but is expected to have type Q in the application ⟨h.left, h.right⟩
The second clue is an alternative, so h.2 alone cannot establish Q.
The fix: Inspect the alternative. Build the matching pair in each branch.
07Your turn
sorry is a placeholder for unfinished work. Replace it as you solve each task. A finished proof has no placeholders.
- Warm-up
Given P and R separately, build the right-hand alternative.
Show a hint
The right alternative asks for P ∧ R.
One more hint
Use Or.inr with the pair of proofs.
- A little stretch
Reverse the worked proof and recover the shared clue.
Show a hint
Split the outer disjunction to see which pair you have.
One more hint
Keep the first component and wrap the second with Or.inl or Or.inr.
example (P Q R : Prop) (p : P) (r : R) : (P ∧ Q) ∨ (P ∧ R) := by
sorry
example (P Q R : Prop) (h : (P ∧ Q) ∨ (P ∧ R)) : P ∧ (Q ∨ 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 R : Prop) (p : P) (r : R) : (P ∧ Q) ∨ (P ∧ R) := by
exact Or.inr ⟨p, r⟩
example (P Q R : Prop) (h : (P ∧ Q) ∨ (P ∧ R)) : P ∧ (Q ∨ R) := by
cases h with
| inl pq => exact ⟨pq.1, Or.inl pq.2⟩
| inr pr => exact ⟨pr.1, Or.inr pr.2⟩
no goals
08A quick check
09New words & tools
Take your time. Progress is yours to mark.