Prove an or-statement

To prove P ∨ Q, pick the side you can prove.

12 minBeginnerdisjunctionleftrightOr.inl / Or.inr
0/11 completed in this course

A proof of P ∨ Q is a proof of one side carrying a label that says which side it is. There is no way to prove a disjunction without committing. Lean has to record which half you established, because later proofs will ask.

In tactic mode you commit with left or right. left replaces the goal P ∨ Q by P; right replaces it by Q. The same two choices written as terms are Or.inl and Or.inr, and those names show up in proof terms and error messages, so it is worth knowing both spellings.

Pick the side you can actually prove. Choosing wrong gives no warning at the left or right line; it gives a type mismatch at the exact after it, naming the proposition you were supposed to produce. The commented block below shows the message.

The goal decides, not the hypothesis. In the worked example one proof ha : A is used on the left in the first conjunct and on the right in the second, because A sits in a different position each time. Read the goal before every left or right.

Worked example

example (A B : Prop) (ha : A) : (A ∨ B) ∧ (B ∨ A) := by
  constructor
  · left
    exact ha
  · right
    exact ha

-- Committing to a side you cannot prove fails at the next line, not at the choice:
--   example (A B : Prop) (hb : B) : A ∨ B := by
--     left
--     exact hb
--
--   Type mismatch
--     hb
--   has type
--     B
--   but is expected to have type
--     A

The same hypothesis answers both bullets, but the tactic differs because A is the left disjunct in one goal and the right disjunct in the other. Your exercise has only one disjunction, so there is only one correct choice.

Takeaway

To prove P ∨ Q you must pick a side with left or right, and the goal is what tells you which one.

Exercise 1 of 3

Prove P ∨ Q when the only proof you hold is hq : Q.

Suggested steps
  1. Commit to the side you can prove
  2. Close the remaining goal

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

Exercise.lean
1theorem exercise (P Q : Prop) (hq : Q) : P ∨ Q := by
given
Loading editor…

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

P Q:Prop
hq:Q
⊢P ∨ Q
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 3The goal is A ∨ B and the context contains only ha : A. Which is correct?
Question 2 of 3Where does a wrong choice of side show up?
Question 3 of 3What is the term form of right on the goal P ∨ Q?