Review: pick the right tool

Mixed proofs about lights and fees, with no step checklist.

New lesson18 minBeginnerreviewno checklist
Lesson 8 of 80/8 done0 of 8 lessons completed in this course. Open the list of lessons.
Go to the exercise ↓

No new material: each exercise mixes the tools of this course, and none has a checklist. Before each one, ask which tool fits the goal: unfold to look inside a definition, simp to simplify, omega for arithmetic, cases to split a value of an inductive type, contradiction for impossible branches.

The traffic light from Lean foundations is given above the editor: next moves red to green, green to yellow and yellow to red, and canGo is true only for green.

Worked example

Defined for this lesson
inductive Light where
  | red
  | yellow
  | green

def next : Light → Light
  | .red => .green
  | .green => .yellow
  | .yellow => .red

def canGo : Light → Bool
  | .green => true
  | _ => false
example (l : Light) (h : l = Light.red) : canGo (next l) = true := by
  rw [h]
  rfl
Step through the proof1 / 3

At the start of the proof on line 1. Everything above ⊢ may be used; the line below it is what must be proved.

l:Light
h:l = Light.red
⊢canGo (next l) = true

With h the light is known, so after rewriting everything computes.

Takeaway

Match the tool to the goal: unfold to look inside, simp to simplify, omega for arithmetic, cases to split, contradiction for the impossible.

Exercise 1 of 4

Prove that after three steps a light is back where it started.

Exercise.lean
1inductive Light where
2 | red
3 | yellow
4 | green
5
6def next : Light → Light
7 | .red => .green
8 | .green => .yellow
9 | .yellow => .red
10example (l : Light) : next (next (next l)) = l := by
given
Loading editor…

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

l:Light
⊢next (next (next l)) = l
ReadyLn 1, Col 1Lean 4
Draft saved in this browser
Stuck?

Knowledge check

Answer from memory. Each answer is checked as you pick it.

0 / 2
1Which tool splits l : Light into its three cases?
2After unfold, the goal is plain arithmetic with a hypothesis. What finishes it?