Chapter 5 · Verified programs

Practice: choose the tactic

You are reading the whole lesson on one page. Back to one step at a time

Step 1 of 14 · Concept

The goal tells you the tactic

In this lesson you practise choosing tactics, and no task names one. Read the goal first: its shape names the first tactic to try. A hypothesis's shape says how to use it.

When a hypothesis fits the goal, exact or apply uses it (lesson 5). A recursive function calls for induction (lesson 13). After each tactic, read the goal panel again.

Stuck on one goal? A sorry there lets you check the rest, but the check refuses it.

theorem times_swap (a b : Nat) : a * b = b * a := by
  sorry
theorem regroup (p q r : Prop) (h : p ∧ (q ∧ r)) :
    (p ∧ q) ∧ r := by
  sorry
theorem two_up (P : Nat → Prop) (h : ∀ n, P n → P (n + 1))
    (h0 : P 0) : P 2 := by
  sorry
def len : List Nat → Nat
  | [] => 0
  | _ :: xs => 1 + len xs
def rep : Nat → Nat → List Nat
  | 0, _ => []
  | n + 1, x => x :: rep n x
theorem rep_len (n x : Nat) : len (rep n x) = n := by
  sorry
theorem even_plus_two (n : Nat) (h : ∃ m, n = 2 * m) :
    ∃ m, n + 2 = 2 * m := by
  sorry
theorem mixed (p : Prop) (hp : p) (n : Nat) (h : n + 1 = 4) :
    p ∧ n = 3 ∧ ∃ m, m + n = 5 := by
  sorry
def rep : Nat → Nat → List Nat
  | 0, _ => []
  | n + 1, x => x :: rep n x
theorem rep_all (n x : Nat) : ∀ y, y ∈ rep n x → y = x := by
  sorry
Terminal
Step 1 of 7Try it: let Lean find the fact

Keyboard shortcuts

The step

ContinueEnter
Previous / next stepAlt+[ · Alt+]
Move along the steps bar← → Home End, then Enter
From a quiz's title to its answers↓
Skip to the stepTab, then Enter (first on the page)
Course outlineAlt+O
These shortcuts?

The workspace

Run the stepCtrl+Enter (⌘↵ on a Mac)
Lesson → editor → consoleF6 (Shift+F6 back)
Output ↔ TerminalCtrl+`
Focus the editorCtrl+. (⌘. on a Mac)
Hide or show the lessonAlt+L
Restore, close a messageEsc (outside the editor and the terminal)

The editor

Leave the editorF6 (Shift+F6 back); or Ctrl+M (⌃⇧M on a Mac), then Tab moves the focus (not in the vim mode)
Open a file by nameCtrl+P (⌘P on a Mac)
All commandsCtrl+Shift+P (⌘⇧P on a Mac) or F1
Go to a lineCtrl+G (⌃G on a Mac)
Show or hide the filesCtrl+B (⌘B on a Mac)
Previous / next file tabCtrl+Shift+[ · Ctrl+Shift+] (⌘⇧[ · ⌘⇧] on a Mac)
The file tabs← → Home End on a tab; Delete closes it
Save the files nowCtrl+S (⌘S on a Mac)
Go to a symbol in the fileCtrl+Shift+O (⌘⇧O on a Mac)
Go to the definitionF12
Format the fileCtrl+Shift+F (⌘⇧F on a Mac), or Shift+Alt+F
Go back / forward after a jumpAlt+← · Alt+→ (⌃- · ⌃⇧- on a Mac)