Reason from alternatives

cases h with | inl hp | inr hq handles both possibilities.

16 minBeginnercasescase analysisinl and inr branches
0/11 completed in this course

h : P ∨ Q says one of the two holds and refuses to say which. To use it you must handle both possibilities, so a proof that consumes a disjunction splits into two.

cases h with creates one branch per constructor: | inl hp => where hp : P, and | inr hq => where hq : Q. The tactics of a branch go on the following lines, indented under the =>. Both branches have to close the same goal.

Inside a branch you know more than you did outside it. In inl you hold a proof of P; in inr a proof of Q. Gaining that knowledge is the whole reason to split.

This is called elimination: the disjunction is consumed by covering its cases, the way obtain consumed a conjunction. Introduction builds a connective, elimination spends one.

Worked example

example (A B : Prop) (h : A ∨ B) : B ∨ A := by
  cases h with
  | inl ha =>
    right
    exact ha
  | inr hb =>
    left
    exact hb

The goal here is itself a disjunction, so each branch ends with a choice: knowing A holds, the new goal B ∨ A is proven on the right. Your exercise has a plain goal R instead, and each branch has an implication ready to produce it.

Takeaway

cases h with | inl hp => … | inr hq => … proves a goal from P ∨ Q by covering both possibilities.

Exercise 1 of 3

Prove R from h : P ∨ Q, using hpr in one branch and hqr in the other.

Suggested steps
  1. Split on the disjunction
  2. Handle the inl branch with hpr
  3. Handle the inr branch with hqr

These marks only recognize text. Another correct proof may use different steps; Lean checks whether it works.

Exercise.lean
1theorem exercise (P Q R : Prop) (h : P ∨ Q) (hpr : P → R) (hqr : Q → R) : R := by
given
Loading editor…

Where you start. Everything above ⊢ may be assumed; the line below it is what you must prove.

P Q R:Prop
h:P ∨ Q
hpr:P → R
hqr:Q → R
⊢R
ReadyLn 1, Col 1Lean 4
Draft saved in this browser
Stuck?
Recall and apply

Knowledge check

Answer without looking back, then check your reasoning.

0of 3
correct
Question 1 of 3In the branch | inr hq => of cases h with h : P ∨ Q, what is hq?
Question 2 of 3Why can you not write exact hpr hp without cases?
Question 3 of 3Must both branches close the same goal?