The Proof State
When you enter tactic mode, Lean shows you the "proof state"—what you have and what you need to prove. Learning to read it is essential.
Entering Tactic Mode
Use by to switch from writing terms to writing tactics:
1-- Term mode: write the proof directly2example : 2 + 2 = 4 := rfl34-- Tactic mode: build the proof step by step5example : 2 + 2 = 4 := by6 rflIn your editor (with the Lean extension), placing your cursor after byshows the proof state in the Infoview panel.
Reading the Proof State
The proof state has two parts:
1-- Hypotheses (what you have)2a : Nat3b : Nat4h : a = b5⊢ b = a -- Goal (what you need to prove)- Above the ⊢: Your hypotheses (assumptions you can use)
- After the ⊢: Your goal (what you need to prove)
The turnstile ⊢ (typed as \vdash) separates what you have from what you need.
Goals and Subgoals
Some tactics split one goal into multiple subgoals:
1example : True ∧ True := by2 constructor3 -- Now we have TWO goals:4 -- case left: ⊢ True5 -- case right: ⊢ True6 · trivial -- Solve first goal7 · trivial -- Solve second goalThe · (bullet) focuses on one goal at a time. You can also use braces or indentation:
1example : True ∧ True := by2 constructor3 { trivial } -- First goal4 { trivial } -- Second goal56-- Or just chain them (when order is unambiguous)7example : True ∧ True := by8 constructor <;> trivial -- Apply trivial to all goalsWatching the State Change
Each tactic transforms the proof state. Watch how it evolves:
1example (a b : Nat) : a + b = b + a := by2 -- State: a b : Nat ⊢ a + b = b + a3 4 rw [Nat.add_comm]5 -- State: a b : Nat ⊢ b + a = b + a6 7 rfl8 -- No goals! Proof complete.Common Proof State Patterns
Simple Goal
1⊢ 2 + 2 = 4No hypotheses, just need to prove the goal directly.
Goal with Hypotheses
1n : Nat2h : n > 03⊢ n ≠ 0You have a natural number n and know it's positive. Use this to prove it's not zero.
Function to Prove (→)
1⊢ a = b → b = aUse intro to assume a = band prove b = a.
Universal Statement (∀)
1⊢ ∀ n : Nat, n + 0 = nUse intro n to fix an arbitrary nand prove the property for it.
The Infoview Panel
In VS Code with the Lean 4 extension, the Infoview panel (usually on the right) shows:
- The current proof state at your cursor position
- Type information for expressions
- Error messages and suggestions
- Documentation for tactics and lemmas
Interactive Example
1-- Try stepping through this proof in your editor2theorem symmetry (a b : Nat) (h : a = b) : b = a := by3 -- Cursor here:4 -- a b : Nat5 -- h : a = b6 -- ⊢ b = a7 8 rw [h]9 -- Cursor here:10 -- a b : Nat11 -- h : a = b12 -- ⊢ a = a13 14 rfl15 -- No goalsDeep Dive: What is a Tactic Really?
Under the hood, a tactic is a program that manipulates proof terms. When you write:
1example : P := by tactic1; tactic2; tactic3Lean is actually building a proof term of type P. Each tactic contributes a piece of that term. When all goals are closed, the complete term has been constructed.
You can see the generated term with #print:
1theorem myThm : 2 + 2 = 4 := by rfl23#print myThm -- Shows: theorem myThm : 2 + 2 = 4 := rflProof Complete
When no goals remain, the proof state shows:
1No goalsor simply nothing. At this point, Lean has verified your proof is complete and correct.