Split on whether P holds

by_cases and the classical De Morgan law ¬(P ∧ Q) → ¬P ∨ ¬Q.

17 minBeginnerconstructive and classical proofsexcluded middleby_cases
0/11 completed in this course

Every proof so far has been constructive. To prove P ∨ Q you picked a side, so the proof itself shows which side holds. Some true statements cannot be proved that way. The other De Morgan law, ¬(P ∧ Q) → ¬P ∨ ¬Q, is one of them: knowing that P and Q are not both true does not tell you which one fails.

Classical logic adds the law of the excluded middle: every proposition is either true or false. In Lean it is the theorem Classical.em P : P ∨ ¬P. It is part of the standard library, and Mathlib uses it freely.

The tactic by_cases hp : P uses it to split the proof in two. In the first goal you have hp : P; in the second you have hp : ¬P. You do not need to know which case is the real one, because you prove the goal in both.

In the exercise, ask in each case which side of the goal you can now prove. If P holds, Q cannot also hold without contradicting h. If P fails, the context already says so.

Worked example

example (P Q : Prop) (hpq : P → Q) (hnpq : ¬P → Q) : Q := by
  by_cases hp : P
  · exact hpq hp
  · exact hnpq hp

The example proves Q from two implications that together cover every case, one branch each. In your exercise the two branches prove different sides of a disjunction.

Takeaway

When you cannot tell which case holds, by_cases splits on excluded middle and lets you prove the goal in both.

Practise on Problems
Exercise 1 of 3

Prove the classical De Morgan law: from h : ¬(P ∧ Q), conclude ¬P ∨ ¬Q.

Suggested steps
  1. Split on whether P holds
  2. When P holds, prove ¬Q
  3. When P fails, prove ¬P

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

Exercise.lean
1theorem exercise (P Q : Prop) (h : ¬(P ∧ 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
h:¬(P ∧ 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 3Why can this proof not start with left or right?
Question 2 of 3What does by_cases hp : P produce?
Question 3 of 3Which law does by_cases rely on?