Stage 03 · Step 15 of 50
Follow both possibilities.
01The idea
A parcel can arrive by bike or by van. A plan for either arrival method covers the possibilities.
A proof by cases must handle every constructor.
02In maths
If P ∨ Q holds, then Q ∨ P holds.
Picture it
Swipe sideways to see the whole picture.
cases h forks the trail: one path where you hold hP : P, one where you hold hQ : Q. You must reach the goal on both paths. Each path then proves Q ∨ P by choosing a door, as in the last step.03In Lean
This code comes directly from the file checked by Lean.
example (P Q : Prop) (h : P ∨ Q) : Q ∨ P := by
cases h with
| inl hP =>
right
exact hP
| inr hQ =>
left
exact hQ
A case is one possible way a value was built. A disjunction has a left constructor and a right constructor.
Unlike proving an or statement, using an or hypothesis requires both cases. You do not choose which hypothesis was originally provided.
The names introduced in each branch are available only inside that branch.
04Step by step
Choose a line to see Lean’s recorded goal state after that line.
P Q : Prop h : P ∨ Q ⊢ Q ∨ P
After line 1: example (P Q : Prop) (h : P ∨ Q) : Q ∨ P := by
P Q : Prop h : P ∨ Q ⊢ Q ∨ P
After line 2: cases h with
P Q : Prop h : P ∨ Q ⊢ Q ∨ P
After line 3: | inl hP =>
case inl P Q : Prop hP : P ⊢ Q ∨ P
After line 4: right
case inl P Q : Prop hP : P ⊢ P
After line 5: exact hP
no goals
After line 6: | inr hQ =>
case inr P Q : Prop hQ : Q ⊢ Q ∨ P
After line 7: left
case inr P Q : Prop hQ : Q ⊢ Q
After line 8: exact hQ
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 ∨ P := by
cases h with
| inl hP => exact Or.inr hP
Alternative `inr` has not been provided
The proof leaves the right constructor case unhandled.
The fix: Add the branch for a proof of Q.
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 either side of P or P to conclude P.
Show a hint
There are two cases.
One more hint
Each case gives the proof you need.
- A little stretch
Prove R from P or Q and two implications leading to R.
Show a hint
Split the disjunction into cases.
One more hint
Apply the implication that matches each case.
example (P : Prop) (h : P ∨ P) : P := by
sorry
example (P Q R : Prop) (h : P ∨ Q) (f : P → R) (g : Q → R) : 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 : Prop) (h : P ∨ P) : P := by
cases h with
| inl hP => exact hP
| inr hP => exact hP
example (P Q R : Prop) (h : P ∨ Q) (f : P → R) (g : Q → R) : R := by
cases h with
| inl hP => exact f hP
| inr hQ => exact g hQ
no goals
08A quick check
09New words & tools
Take your time. Progress is yours to mark.