A message is a clue
Mistakes belong here.
Lean is telling us something useful. Read the first error, find what it expected, then make one small change.
“Start with one message. The later ones may disappear once you fix the first.”
Typo · Your error-reading companion
How to read any error
example : 2 + 2 = 5 := by
rflThe real message, part by part- Which step failed. Here the tactic rfl could not finish its job.
- What Lean worked out on the left side of the equation.
- What it needed to match on the right side. 2 + 2 is not 5, so they don’t match.
- The goal at that moment, after ⊢. This is exactly what still needed proving.
- Read only the first errorLater errors often vanish once it is fixed.
- Find what Lean expectedLook for words like expected, failed or unknown.
- Look at the goalThe line after ⊢ shows what you really had to prove.
- Change one thingThen let Lean check again. Small steps, like on the trail.
Twelve common patterns
Pattern 01
The value has the wrong type
#check (3 : String)
failed to synthesize instance of type class OfNat String 3 numerals are polymorphic in Lean, but the numeral `3` cannot be used in a context where the expected type is String due to the absence of the instance above Hint: Type class instance resolution failures can be inspected with the `set_option trace.Meta.synthInstance true` command.
Lean expected one type and received another.
Try this: Read both types. Change the value, the annotation, or the operation so they agree.
Pattern 02
A function received the wrong argument
#check Nat.succ "hello"
Application type mismatch: The argument "hello" has type String but is expected to have type Nat in the application Nat.succ "hello"
The function’s input type does not match the argument you gave it.
Try this: Check the function’s type, then supply an argument of that type.
Pattern 03
A name cannot be found
#check myMissingNumber
Unknown identifier `myMissingNumber`
There is no available declaration with this spelling.
Try this: Check spelling, capitalization, declaration order, namespaces, and imports.
Pattern 04
A tactic name is unknown
example : True := by
magic
unknown tactic unsolved goals ⊢ True
The parser does not recognize this tactic in the current imports.
Try this: Check the name and required import. The cheat sheet lists the tactics this course uses.
Pattern 05
rfl cannot close this equality
example : 2 + 2 = 5 := by
rfl
Tactic `rfl` failed: The left-hand side 2 + 2 is not definitionally equal to the right-hand side 5 ⊢ 2 + 2 = 5
The two sides are not definitionally equal.
Try this: Check the statement. For a true but noncomputational equality, use suitable lemmas or other tactics.
Pattern 06
A goal remains
example : True ∧ True := by
constructor
· exact True.intro
unsolved goals case right ⊢ True
The proof finished its tactic block with work still left.
Try this: Read the remaining goals and finish every case or constructor argument.
Pattern 07
The rewrite pattern is absent
example (n : Nat) (h : n = 2) : 3 = 3 := by
rw [h]
Tactic `rewrite` failed: Did not find an occurrence of the pattern n in the target expression 3 = 3 n : Nat h : n = 2 ⊢ 3 = 3
Lean could not find the expression to replace at the chosen location.
Try this: Inspect the goal and hypothesis. Check the equality’s direction and the rewrite target.
Pattern 08
Nothing can be introduced here
example : True := by
intro h
Tactic `introN` failed: There are no additional binders or `let` bindings in the goal to introduce ⊢ True
The goal does not expose an appropriate input or implication premise.
Try this: Inspect the current goal. Use intro for a function-like goal, an implication, or a for-all statement.
Pattern 09
The supplied proof does not match
example (P Q : Prop) (h : P) : Q := by
exact h
Type mismatch h has type P but is expected to have type Q
The proof term establishes a different proposition from the goal.
Try this: Read the type of the supplied hypothesis and compare it with the goal.
Pattern 10
A negative literal was used as a Nat
#check (-3 : Nat)
failed to synthesize instance of type class Neg Nat Hint: Type class instance resolution failures can be inspected with the `set_option trace.Meta.synthInstance true` command.
Natural numbers have no negative-number interpretation here.
Try this: Use the integer type when negative whole numbers are required.
Pattern 11
No suitable decision procedure
example (P : Prop) : P := by
decide
Expected type must not contain free variables P Hint: Use the `+revert` option to automatically clean up and revert free variables
An arbitrary proposition does not automatically have a Decidable instance.
Try this: Use a suitable assumption or proof method. Use decide for propositions with a decision procedure.
Pattern 12
The expression is incomplete
example : 2 + 2 = 4 := by
exact (
unexpected end of input; expected ')', '_' or identifier
The parser expected more syntax before it could read a complete expression.
Try this: Check parentheses, punctuation, and the expression after each defining symbol.