Stage 09 · Step 42 of 50

Rule out one possibility.

Core Lean10 minutesLean 4.36.0

01The idea

Your notebook is in the locker or the classroom. You checked the locker and ruled it out.

Goalie · Your guide for this idea
Goalie pointing

Examine both possibilities to show where the notebook must be.

02In maths

Given P or Q, ruling out P leaves Q.

Picture it

Split P or Q into two doors and cross out the impossible oneLeft: the starting goal card with P Q : Prop, options : P or Q, hp : not P, and goal Q. The tactic cases options splits the path into two doors. Top door, crossed out in red: case inl p, where p : P means the notebook is in the locker, but hp rules that out; the branch is closed with exact False.elim (hp p). Bottom door, in green: case inr q, where q : Q means the notebook is in the classroom, and q is exactly the proof needed; the branch is closed with exact q.STARTP Q : Propoptions : P ∨ Qhp : ¬P⊢ Qcases optionsinl p : Pthe locker, ruled out by hpexact False.elim (hp p)inr q : Qthe classroom: q is the proofexact q

Swipe sideways to see the whole picture.

The notebook is behind door 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.

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

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

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

    Rule out the right option instead and prove the left one.

  2. A little stretch

    Three hiding places remain. Exclude the first two to identify the third.

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

08A quick check

1. In the right-hand branch, what do you already have?

Read the answer and explanation

Evidence for Q. The inr constructor carries the evidence for Q.

2. Why is False.elim available in the left branch?

Read the answer and explanation

P and ¬ P give False. Applying hp to the evidence p gives a contradiction. False.elim uses that impossible situation to close the branch.

One more idea in your toolkit.

Take your time. Progress is yours to mark.