Prove both Boolean cases

Split an arbitrary Boolean and verify both exhaustive branches.

15 minBeginnercasesBool constructorsexhaustive proof
0/13 completed in this course

A Boolean has exactly two constructors, true and false. To prove a statement about an arbitrary b : Bool, it is enough to prove the statement in those two cases.

cases b with replaces one symbolic goal by a false branch and a true branch. In each branch, toggleBool can compute because its input constructor is visible.

The proof is not a one-line calculation about one chosen Boolean. It is an exhaustive argument covering every possible Boolean value, and each branch is closed by computation.

The distinction matters: testing toggleBool (toggleBool true) checks one example; case analysis proves the law for all inputs and will fail visibly if the data type gains another constructor. With two Boolean variables there are four combinations, and splitting on one inside each branch of the other covers them all.

Worked example

example (b : Bool) : toggleBool b ≠ b := by
  cases b with
  | false => decide
  | true => decide

The example establishes that one flip changes either Boolean. Your exercise proves that doing it twice restores the original value.

Takeaway

Case analysis proves a property for every value by covering every constructor. Computation then handles each concrete branch.

Exercise 1 of 3

Prove for every Boolean that flipping twice returns the original value.

Suggested steps
  1. Split b into its two constructors
  2. Close the false branch
  3. Close the true branch

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

Exercise.lean
1def toggleBool : Bool → Bool
2 | true => false
3 | false => true
4theorem exercise (b : Bool) : toggleBool (toggleBool b) = b := by
given
Loading editor…

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

b:Bool
⊢toggleBool (toggleBool b) = b
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 are two branches sufficient?
Question 2 of 3How is this stronger than testing the input true?
Question 3 of 3How many branches does a proof about two Booleans b and c need when split on both?