Lean 4 tactics: when rfl, simp and exact fit
October 16, 2026 · Oyren AI Team (AI-written)
TL;DR: Choose
rflwhen an equality reduces by definition,exactwhen a term has the goal's type andsimpwhen a known rewrite lemma applies. A free Oyren Docs note records the reasoning. Formal Lean 4 and Mathlib checks run in an Oyren Codespace on a managed cloud computer.
Choose or create a workspace, then select the Lean 4 add-on in Codespace setup.
The goal before the tactic
Lean's tactic-proof documentation describes a proof as changes to a goal state. The infoview shows the active target after ⊢ and the hypotheses available above it. Recording that state before a tactic makes a failed step easier to diagnose.
Computation with rfl
rfl closes an equality when Lean reduces both sides to the same term. Natural-number addition recurses on its second argument, so marker + 0 reduces to marker:
example (marker : Nat) : marker + 0 = marker := by
rfl
The equality chapter explains definitional equality. For 0 + marker = marker, reduction stops at the variable marker; a proved lemma or induction is needed.
A term with exact
exact closes a goal with a term of the required type, including a local hypothesis or a lemma application:
example (Statement : Prop) (known : Statement) : Statement := by
exact known
Here known has the goal's type. For a step such as exact my_lemma h1 h2, the tactic reference and the infoview help identify which argument or target type fails to match.
A rewrite with simp
simp uses lemmas tagged for simplification. The Lean community's simp guide describes how it traverses an expression and applies those lemmas.
example (marker : Nat) : 0 + marker = marker := by
simp
The simplifier uses the proved Nat.zero_add lemma to close this goal. When the exact rewrite matters, simp? suggests a simp only [...] form that names the lemmas.
| Goal state | First tactic to try | Check in the infoview |
|---|---|---|
| Goal stateBoth sides reduce to one term | First tactic to tryrfl | Check in the infoviewDefinitions and types |
| Goal stateA matching term is in scope | First tactic to tryexact | Check in the infoviewHypothesis or lemma type |
| Goal stateA known rewrite applies | First tactic to trysimp | Check in the infoviewRemaining goal and rewrite lemma |
If none fits, inspect the theorem's domain and hypotheses before extending the tactic script.
A reproducible stuck-proof note
Save the declaration, imports, lean-toolchain version and first error or unmet goal. Changing one hypothesis in the accepted exact known example shows how a type mismatch appears; comparing exact Nat.zero_add marker with simp shows the difference between naming a lemma and letting the simplifier find it.
A tactic script proves the formal statement under its stated hypotheses. The AI theorem-proving overview covers generated candidates and kernel checking; the surrounding note still needs to compare that statement with the intended mathematical claim.
Choose or create a workspace, then select the Lean 4 add-on in Codespace setup.
Set up Lean 4 in a Codespace