Stage 10 · Step 46 of 50
Flip a switch twice.
01The idea
A light switch starts either on or off. Flip it twice and it returns to where it started.
Lean can inspect both possible starting positions.
02In maths
For every Boolean b, negating b twice returns b.
Picture it
Swipe sideways to see the whole picture.
Bool is a switch with only two positions, true and false. cases b says “just try both”. In each case Lean can compute the two flips itself, so rfl sees that the switch is back where it started. <;> sends the same rfl to both cases at once.03In Lean
This code comes directly from the file checked by Lean.
example (b : Bool) : (!(!b)) = b := by
cases b <;> rfl
04Step by step
Choose a line to see Lean’s recorded goal state after that line.
b : Bool ⊢ (!!b) = b
After line 1: example (b : Bool) : (!(!b)) = b := by
b : Bool ⊢ (!!b) = b
After line 2: cases b <;> rfl
no goals
05Lean says
no goals
A goal is what remains to prove. The symbol ⊢ points to it. Meet the turnstile.
06A common slip
Lean is telling us something useful here.
example : (!true) = true := by
rfl
Tactic `rfl` failed: The left-hand side !true is not definitionally equal to the right-hand side true ⊢ (!true) = true
Flipping true once computes to false. Lean cannot identify that value with true.
The fix: Use false as the one-flip result, or add a second flip to return to true.
07Your turn
sorry is a placeholder for unfinished work. Replace it as you solve each task. A finished proof has no placeholders.
- Warm-up
Calculate the result of flipping true once.
Show a hint
The switch starts on.
One more hint
Use rfl to check the computed result.
- A little stretch
Show that three flips have the same effect as one flip.
Show a hint
Split on the unknown starting state.
One more hint
In each branch, all the flips compute.
example : (!true) = false := by
sorry
example (b : Bool) : (!(!(!b))) = (!b) := by
sorry
Compare with the checked solutions
There are often several valid proofs. These solutions were compiled with the same pinned Lean version.
example : (!true) = false := by
rfl
example (b : Bool) : (!(!(!b))) = (!b) := by
cases b <;> rfl
no goals
08A quick check
09New words & tools
Take your time. Progress is yours to mark.