Stage 09 · Step 42 of 50
Rule out one possibility.
01The idea
Your notebook is in the locker or the classroom. You checked the locker and ruled it out.
Examine both possibilities to show where the notebook must be.
02In maths
Given P or Q, ruling out P leaves Q.
Picture it
Swipe sideways to see the whole picture.
P (locker) or door Q (classroom). cases options makes you check both doors. Behind the first, hp p is a contradiction, so False.elim closes that impossible branch. Behind the second, q already proves Q.03In Lean
This code comes directly from the file checked by Lean.
example (P Q : Prop) (options : P ∨ Q) (hp : ¬ P) : Q := by
cases options with
| inl p => exact False.elim (hp p)
| inr q => exact q
cases options opens one branch per possible piece of evidence. In the left branch, hp p gives False, so that branch cannot occur under the assumptions.
In the right branch the name q already refers to exactly the proof you need.
04Step by step
Choose a line to see Lean’s recorded goal state after that line.
P Q : Prop options : P ∨ Q hp : ¬P ⊢ Q
After line 1: example (P Q : Prop) (options : P ∨ Q) (hp : ¬ P) : Q := by
P Q : Prop options : P ∨ Q hp : ¬P ⊢ Q
After line 2: cases options with
P Q : Prop options : P ∨ Q hp : ¬P ⊢ Q
After line 3: | inl p => exact False.elim (hp p)
no goals
After line 4: | inr q => exact q
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) (options : P ∨ Q) : Q := by
exact options
Type mismatch options has type P ∨ Q but is expected to have type Q
The term options has type P ∨ Q. Lean still needs evidence for Q itself.
The fix: Split options into cases and use the extra premise that rules out 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
Rule out the right option instead and prove the left one.
Show a hint
Split options into its two constructors.
One more hint
In the right branch, apply hq to q.
- A little stretch
Three hiding places remain. Exclude the first two to identify the third.
Show a hint
Split the outer or first.
One more hint
In its right branch, split the remaining Q ∨ R.
example (P Q : Prop) (options : P ∨ Q) (hq : ¬ Q) : P := by
sorry
example (P Q R : Prop) (options : P ∨ (Q ∨ R)) (hp : ¬ P) (hq : ¬ 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 : Prop) (options : P ∨ Q) (hq : ¬ Q) : P := by
cases options with
| inl p => exact p
| inr q => exact False.elim (hq q)
example (P Q R : Prop) (options : P ∨ (Q ∨ R)) (hp : ¬ P) (hq : ¬ Q) : R := by
cases options with
| inl p => exact False.elim (hp p)
| inr rest =>
cases rest with
| inl q => exact False.elim (hq q)
| inr r => exact r
no goals
08A quick check
09New words & tools
Take your time. Progress is yours to mark.