Stage 03 · Step 15 of 50

Follow both possibilities.

Core Lean8 minutesLean 4.36.0

01The idea

A parcel can arrive by bike or by van. A plan for either arrival method covers the possibilities.

Goalie · Your guide for this idea
Goalie pointing

A proof by cases must handle every constructor.

02In maths

If P ∨ Q holds, then Q ∨ P holds.

Picture it

Using an “or”: the trail forks and you must walk both pathsThe start card has P Q : Prop and h : P or Q, with goal Q or P. The tactic cases h forks the proof into two paths, and both must be finished. Upper path, case inl: you have hP : P and the goal is still Q or P; the tactics right, then exact hP finish it. Lower path, case inr: you have hQ : Q and the goal is Q or P; the tactics left, then exact hQ finish it. Each path ends in a no goals card with a green tick.STARTP Q : Proph : P ∨ Q⊢ Q ∨ Pcases hwalk BOTH pathscase inlP Q : ProphP : P⊢ Q ∨ Prightexact hPPATH 1 DONEno goalscase inrP Q : ProphQ : Q⊢ Q ∨ Pleftexact hQPATH 2 DONEno goals

Swipe sideways to see the whole picture.

When you have an “or”, you don’t know which side it came from. 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.

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

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

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 either side of P or P to conclude P.

  2. A little stretch

    Prove R from P or Q and two implications leading to R.

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

08A quick check

1. How many disjunction cases must this proof handle?

Read the answer and explanation

Both. The proof must work whichever constructor supplied the hypothesis.

2. What do inl and inr identify?

Read the answer and explanation

The left and right constructors. Each branch receives the proof carried by its constructor.

One more idea in your toolkit.

Take your time. Progress is yours to mark.