Lean errors → fixes
64 error patterns
Disproof type is not ¬ (reference statement) · nosorry, elaboration
X.not_conj must have type ¬ (reference statement)
The not_… theorem was found, but its type is not syntactically ¬ S for the reference type S. In the logs the usual cause was a universe mismatch: the reference uses Type* (elaborated as Type u_1), while the disproof wrote Type u or a fresh Type* inside the negation.
- Copy the reference statement verbatim inside
¬ ( … ), turning the theorem's binders into∀binders, in the same order and with the same implicitness and instance arguments. - Match universe names: write
Type u_1(declareuniverse u_1) where the reference hasType*, and instantiate the counterexample at that level, e.g.G.{u_1}orULift.{u_1} (Fin n). This fixed the rejected submissions in the logs. - Keep inline proof terms such as
(by simp)inside the statement exactly as in the reference.
Definitions or auxiliary proofs of the statement differ · nosorry, elaboration
declarations the statement depends on were changed or are missing: Ns.thm._proof_1
The checker compares every constant the target's statement uses. A name ending in ._proof_1 is the auxiliary proof Lean extracts from a by … term inside the statement (e.g. Finset.max' (by simp)). It changes when the surrounding statement text, universes or instances change.
- Do not redefine or copy the challenge's definitions; use the ones in the challenge file unchanged.
- If the listed name ends in
_proof_N, the statement around an inlinebydiffers from the reference (often the universe level). Restore the exact reference text. - Never edit the statement to make the proof easier; prove a helper lemma instead and apply it.
Target (or not_ target) missing · nosorry
Ns.thm.parts.not_i not found in the submission
The checker did not find the expected declaration name. For a disproof the name is the reference name with its last component prefixed by not_, in the same namespace (for A.b.parts.i it is A.b.parts.not_i).
- Rename the theorem to the exact expected name. The rejection message spells it out.
- Check that it is not inside an extra
namespace/sectionwith a name, and that it is notprivate. - For a proof, keep the reference theorem's name and replace only its
sorry.
Statement differs from the reference · nosorry, elaboration
statement differs from the reference
The type of your target theorem is not identical (after elaboration) to the reference type. Harmless-looking edits such as renaming a bound variable are fine, but changing binders, coercions, ≤ vs <, instance arguments or universes is not.
- Start from the challenge file and replace only the
sorryof the target. - If you need a different but equivalent form, prove it as a separate lemma and close the target with
exact (my_lemma …)orsimpa using …. - Partial proofs are checked the same way: open lemmas may change, the target statement may not.
Finset literal or operation needs DecidableEq · typeclass, elaboration
failed to synthesize instance of type class Insert α (Finset α)
{u, v} : Finset α, insert, ∪, ∩ and \ on finsets need DecidableEq α. Without it Lean cannot build the Insert instance, and {u, v} may also be tried as structure-instance notation ("u is not a field of structure Finset"). The failure then shows up later as goals mentioning sorry.
- Add
classicalat the start of the proof, or add[DecidableEq α]to the lemma's binders, if the statement allows it. - Annotate the literal:
({u, v} : Finset α). Or use aSet(({u, v} : Set α)) when decidability is not needed. - Fix this first: the later errors with goals that mention
sorryfollow from it.
Import not allowed · nosorry, import
import not allowed: Foo.Bar
nosorry accepts imports only from Mathlib, Batteries, Aesop, Qq, Plausible, ProofWidgets, Init, Std, FormalConjectures*, Physlib and QuantumInfo. SciLean and PhyslibAlpha are refused on purpose. A module name that is malformed or truncated is also reported this way.
- Remove the import and inline the definitions or lemmas you need into the solution file.
- To import another numbered formal-conjectures problem, quote the numeric component:
import FormalConjectures.ErdosProblems.«28». - Use
import Mathlib(or the specific Mathlib modules) rather than a third-party package.
native_decide is not accepted · nosorry, kernel
`native_decide` trusts the compiler and is not accepted
native_decide, decide +native and Lean.ofReduceBool trust compiled code, and nosorry accepts only propext, Quot.sound and Classical.choice. This was the most frequent preflight rejection in the logs. A native_decide that is literally present in the reference statement is tolerated as long as your target does not depend on it.
- Replace it by
decide +kernel(kernel evaluation, no compiler), or bydecideon smaller pieces. - Split a big computation into named lemmas over small ranges, each closed by
decide +kernelornorm_num, and combine them withrw/simp. - For number theory, prove facts structurally (multiplicativity,
norm_numprimality) instead of evaluating huge numbers.
rfl failed: sides are not definitionally equal · tactic
Tactic `rfl` failed: The left-hand side f (z, h) is not definitionally equal to the right-hand side ((0, z), h)
rfl needs the two sides to be equal by unfolding definitions. Linear maps and equivalences built by tactics (LinearEquiv.ofFinrankEq, Classical.choice-based constructions), well-founded recursion and irreducible definitions do not unfold to the value you expect.
- Prove the equation by its defining lemma:
simp [myFun],rw [myFun_apply], orextfollowed bysimp. - If the map comes from an existence theorem, keep the property you need (
hE : ∀ x, E x = …) when you construct it, instead of hoping it unfolds. - Try
decidefor decidable closed goals,norm_numfor numerals,ringfor commutative-ring identities.
Reference statement does not compile (infrastructure) · nosorry, import
reference does not compile: error: unknown module prefix 'Foo'
The challenge file itself failed to build on the verifier, for example "unknown module prefix 'FormalConjecturesUtil'" when the build environment lacked a library. This is not a fault in your proof.
- Resubmit later or report it to the maintainers. Do not change the imports of the challenge file to work around it.
- If you are submitting a formalization, check that the file compiles locally with the same toolchain (Lean v4.33.1) and imports only allowed modules.
Statement checker crashed (infrastructure) · nosorry
checker output unreadable:
The statement/axiom checker produced no readable verdict, usually because it ran out of time or memory on a very large environment. It is a verifier-side error, not a rejection of the proof.
- Resubmit. If it repeats, report it, mentioning the submission size.
- Very large files (hundreds of thousands of characters) are more likely to hit this. Removing unused helper code helps.
Remote verifier run failed (infrastructure) · nosorry
verifier run failed: the run stopped before producing a result
Large or repository submissions are checked on a remote runner. The run was interrupted or could not be read, so there is no verdict yet.
- Resubmit later. The submission was not rejected on its merits.
- Report it if it repeats for the same submission.
Linter: let preferred over letI (warning) · tactic
warning: The goal is a proposition, so `let` is preferred over `letI`.
A style warning, not an error: in a proof (a Prop goal) letI/haveI are unnecessary. It can flood the compiler output and hide the real error.
- Ignore it while hunting the error: search the output for
error:. - Replace
letI/haveIbylet/haveinside proofs, or addset_option linter.style.haveILetI false(allowed by nosorry).
Linter: unused simp argument (warning) · tactic
warning: This simp argument is unused: Foo.bar
A warning that a lemma passed to simp/simp only was not used. Harmless, but the noise can bury real errors.
- Remove the listed argument, or silence the linter with
set_option linter.unusedSimpArgs false. - Look for lines with
error:to find what actually failed.
Declaration uses sorry · nosorry, elaboration
warning: declaration uses `sorry`
A warning that a declaration still contains sorry (or admit). nosorry accepts it only in declarations the target does not depend on, or in a partial proof whose open lemmas are shared.
- Find which
sorryyour target depends on. The verdict lists them as open lemmas. - For a complete proof, remove every
sorryon which the target depends. Otherwise submit aspartialwith shared lemmas. - Other theorems of the challenge file may keep their
sorry.
Target theorem still uses sorry · nosorry
the target theorem itself still uses sorry
The theorem you are proving still contains sorry directly, so this is neither a proof nor a partial proof.
- Replace the target's
sorryby a proof. If you can only reduce it to lemmas, state them as separate theorems withsorryand submit aspartial.
Proof depends on sorry: submit as partial · nosorry
the proof still depends on sorry (Ns.helper) — submit it as a partial proof instead
Your target is sorry-free, but some lemma it uses (listed) still has sorry. Proofs and disproofs must be complete.
- Prove the listed lemmas, or resubmit with kind
partial(ideally with shared lemmas so others can prove them). - Check for a forgotten
sorryin a helper'shaveor in adecreasing_byblock.
Non-standard axioms · nosorry, kernel
non-standard axioms: Lean.ofReduceBool
#print axioms of the target shows something beyond propext, Quot.sound and Classical.choice, typically Lean.ofReduceBool (from native_decide), or an axiom declared in a dependency.
- Remove
native_decide/decide +nativeand usedecide +kernelor a structural proof. - Do not declare
axioms. State the fact as a theorem (withsorry, as a partial proof) instead.
axiom declarations refused · nosorry
new axioms are not allowed
The preflight found an axiom command. Axioms would let anything be proved.
- Turn the axiom into a
theorem … := by sorryand submit aspartialwith shared lemmas, so the step becomes a lemma problem.
unsafe / partial / extern / opaque refused · nosorry, syntax
`unsafe` / `partial` definitions are not allowed
Constructs that bypass the kernel or hide definitions (unsafe, partial def, implemented_by, extern, opaque, initialize, @[csimp] and similar attributes) are refused.
- Write a total definition: structural recursion, or
termination_bywith adecreasing_byproof, orNat.rec/Nat.iterate. - Use
def(ornoncomputable def) instead ofopaque;irreducible_defis fine if you need opacity for performance.
#eval / #print / #check refused · nosorry, syntax
evaluation / debugging commands are not allowed
#eval, #print, #check, #reduce, #synth, #exit, run_cmd and similar commands are refused in submissions, including #print axioms lines copied from ported code.
- Delete these lines before submitting. Use them only locally.
exact? / apply? / hint / #loogle refused · nosorry, tactic
search commands (#leansearch, #loogle, exact?…) must be replaced by the lemmas they found before submitting
Search tactics and commands (exact?, apply?, rw?, hint, #leansearch, #loogle, #moogle) must be replaced by what they found. The rule also fires on a hypothesis named hint used at the start of a tactic line.
- Run
exact?locally, then paste the suggestedexact foo …term. - Rename hypotheses called
hint(e.g. tohInt).
Custom syntax / metaprogramming refused · nosorry, syntax
custom syntax / elaborators are not allowed in solutions
macro, syntax, notation, elab, infix and import Lean/Lean.Elab/Lean.Meta are refused in solutions. Notation that already appears verbatim in the reference statement is tolerated.
- Replace notation by plain definitions or
abbrevs, and macros by repeated tactic blocks orall_goals/<;>. - If you need a local
open … in, that is fine; it is not custom syntax.
set_option not allowed · nosorry, performance
only maxHeartbeats (≤ 9,999,999), maxRecDepth, synthInstance.maxHeartbeats, linter.*, autoImplicit and pp.* options are allowed
Only maxHeartbeats and synthInstance.maxHeartbeats up to 9,999,999, maxRecDepth up to 99,999, linter.*, autoImplicit/relaxedAutoImplicit and pp.* are accepted. Values of 10,000,000 heartbeats or 100,000 recursion depth are refused, as is any other option.
- Lower the value (e.g.
set_option maxRecDepth 99999), and scope it withset_option … inbefore a single declaration. - Remove options like
trace.*,maxSynthPendingDepthorbackward.*; restructure the proof instead.
IO refused · nosorry
IO is not allowed
Any mention of IO, EIO, BaseIO or System.* is refused, even in a definition that is never run.
- Remove the code. Proofs never need IO. If a name merely contains the token
IO, rename it.
Target is not a theorem · nosorry
target is not a theorem
The target was declared with def, abbrev or instance (or it is missing and a definition with the same name exists).
- Declare it with
theorem(orlemma) under the exact reference name.
Compilation timed out · nosorry, performance
compilation timed out
The whole file took longer than the verifier's wall-clock limit. Heartbeat limits are per declaration; this one is for the whole build.
- Profile locally and speed up the slowest declarations:
simp only [...]instead ofsimp,nlinarith only [...], smallerdecidechunks. - Delete unused helper lemmas, especially heavy computations.
Kernel replay failed · nosorry, kernel
kernel replay failed: (kernel) deep recursion detected
The compiled module was re-checked by leanchecker and a declaration failed. Usually this is a kernel-only limit (deep recursion, a definitional unfolding the elaborator accepted lazily), and rarely a genuine soundness issue.
- Look for
decide/rflproofs on large terms. Replace them withdecide +kernelon smaller pieces, or with structural lemmas. - Check that the file compiles locally with
lake env leanand replays withleanchecker.
Comparator rejected · nosorry
comparator rejected:
The independent comparator (leanprover/comparator) found a difference in the theorem, its definitions or its axioms relative to the reference.
- Treat it like a statement mismatch: restore the exact reference statement and definitions, and remove non-standard axioms.
Duplicate of an earlier submission · nosorry
identical to earlier submission s-… on this problem
After removing comments, whitespace and declaration names, your source is identical to another user's earlier submission on this problem.
- Do not resubmit someone else's proof. Build on it (cite it) or find a different argument. Another proof of a settled problem earns nothing.
Reference contains sorry outside an answer(...) slot · nosorry
the reference type contains sorry outside an answer(...) slot; report it as a critique
The reference type itself contains a sorry that is not an answer(...) hole. The statement is incomplete and cannot be proved as stated.
- Report it as a critique of the statement instead of submitting a proof.
Formalization must be a sorry'd statement · nosorry
Ns.thm must be stated with sorry as its proof: a formalization is a problem, not a proof
A formalization submission states a problem: its target must be a theorem whose proof is sorry, and it must not add axioms.
- Write
theorem name : statement := by sorry, and keep auxiliary definitions sorry-free and axiom-free. - Sanity checks with
native_decideare not accepted in formalizations either; usedecideordecide +kernel.
Unknown identifier · elaboration, import
unknown identifier 'foo_bar'
The name does not exist in scope. Common causes: a Mathlib rename (lemma names drift between versions), a missing open, a Lean 3 name, or a typo in a local hypothesis.
- Search for the current name: try the obvious modern spelling (
Nat.lt_irrefl→lt_irrefl,_iffvariants,Finset.card_le_of_subset→Finset.card_le_card), or useexact?locally. - Add the namespace (
Nat.,Finset.,SimpleGraph.) or anopen … in. - Check
autoImplicit: with it off, unbound lowercase names in signatures are errors.
Unknown constant · elaboration, import
unknown constant 'Nat.foo_bar'
A fully qualified name (in rw, simp, @foo or the dot notation) does not exist, typically after a Mathlib rename or deprecation removal.
- Find the replacement: deprecated aliases name their successor in the warning of the previous version, and Mathlib usually keeps the same statement under a new name (
dite_eq_left→dif_pos). - Add a local shim lemma with the old name proved by the new one when porting large files.
Failed to synthesize instance · typeclass
failed to synthesize Fintype ↑s
Type class resolution could not find an instance: decidability (Decidable, DecidableEq, DecidablePred), finiteness (Fintype, Finite), an algebraic structure, or a coercion that does not exist.
- For decidability, add
classicalat the start of the tactic proof, oropen Classical inbefore a definition. - For
Fintypeof a subtype or set, useSet.toFinite/Fintype.ofFinite, or state the lemma with[Fintype α] [DecidableEq α]. - Check the types:
HAdd ℕ ℝ ?orHDiv ℕ ℕ ℝmeans a missing cast; write(n : ℝ).
Numeral on a type without numerals · typeclass, elaboration
failed to synthesize OfNat (Set ℕ) 2
A literal such as 2 was elaborated at a type that has no OfNat instance (a Prop, a Set, a function type), usually because of a wrong argument order or missing parentheses.
- Add a type ascription
(2 : ℕ)and check the expected type of the argument. - Check operator precedence:
f 2 ^ kis(f 2) ^ k.
Typeclass instance problem is stuck · typeclass, elaboration
typeclass instance problem is stuck, it is often due to metavariables
Lean cannot even start instance search because a type is still a metavariable, typically a numeral or a lambda whose type is not determined.
- Add type ascriptions:
(0 : ℝ),(fun n : ℕ => …), or give explicit arguments with(α := ℕ).
Type mismatch (often a coercion ℕ → ℤ → ℝ) · elaboration
type mismatch: h has type ↑(a + b) ≤ ↑c but is expected to have type ↑a + ↑b ≤ ↑c
The term has a different type than expected. With numbers this is usually a coercion problem: ↑(a + b) vs ↑a + ↑b, ((n : ℤ) : ℝ) vs (n : ℝ), or ℕ subtraction/division that does not commute with casts.
- Normalise casts with
push_cast,norm_cast,exact_mod_cast horsimpa using h. - For
↑(n - k)giveNat.cast_sub hk(needsk ≤ n); for↑(n / k)useNat.cast_div(needs divisibility) or avoid it. - Use
zify/qify/rifywith the needed≤facts to move a whole goal to ℤ/ℚ/ℝ.
Application type mismatch · elaboration
application type mismatch: foo h argument h has type a < b but is expected to have type a ≤ b
An argument passed to a function or lemma has the wrong type, often because the arguments are in the wrong order, an implicit argument was made explicit, or a hypothesis is stated with < where ≤ is expected.
- Check the lemma's signature (hover, or
#checklocally) and pass named arguments:foo (n := 3) (h := hk). - Convert the hypothesis first:
hk.le,Nat.lt_succ_iff.mp hk,by omega. - Use
convert foo … using 2to see exactly which parts differ.
Motive is not type correct (rw) · tactic, elaboration
motive is not type correct
rw abstracted the term you are rewriting, but some other part of the goal (a proof term, a dependent type such as Fin n, or a Finset.max' s h) depends on it, so the result does not typecheck.
- Use
simp only [h]orsimp_rw [h], which can rewrite under binders and handle dependencies better. - Generalise first:
generalize hx : f n = x at *, orsubstifh : x = twithxa variable. - Use
Fin.cast/congr/convertfor dependent types, or prove the statement for a generalnand specialise.
Maximum recursion depth reached · performance, kernel
maximum recursion depth has been reached; use `set_option maxRecDepth <num>` to increase limit
Elaboration recursed too deeply, typically in decide, rfl or simp evaluating a large term, or in whnf on big numerals or long lists.
- Replace
decidebydecide +kernel, which skips the elaborator's evaluation and lets the kernel check the instance. - Split the computation into smaller lemmas, or prove it structurally (
norm_num,simpwith recursion equations). - As a last resort
set_option maxRecDepth 99999 in(nosorry's maximum).
Deterministic timeout (maxHeartbeats) · performance
(deterministic) timeout at `whnf`, maximum number of heartbeats (200000) has been reached
A declaration used more than its heartbeat budget (200000 by default). Typical culprits are unrestricted simp, nlinarith/polyrith with many hypotheses, decide on large structures and expensive instance search.
- Locate the slow tactic (comment out parts, or use
set_option profiler truelocally). - Use
simp only [...],nlinarith only [...],norm_num [specific lemmas]. Split the proof into lemmas. - If it is just big,
set_option maxHeartbeats 1600000 inbefore that declaration (≤ 9,999,999 on nosorry).
linarith / nlinarith failed · tactic
linarith failed to find a contradiction
linarith found no linear combination of the hypotheses that proves the goal. nlinarith reports the same message when its products of hypotheses are not enough. Common causes: the needed fact is nonlinear, lives behind a cast, or is not in the context.
- Add the missing facts explicitly:
linarith [h1, sq_nonneg (a - b), mul_pos ha hb]. - For nonlinear goals, give
nlinariththe exact products:nlinarith [mul_nonneg ha hb, sq_nonneg (x - 1)]. - Normalise casts first (
push_cast at *), and for ℕ goals with subtraction preferomega.
omega could not prove the goal · tactic
omega could not prove the goal: a possible counterexample may satisfy the constraints
omega handles linear arithmetic over ℕ and ℤ with +, * by constants, / and % by numerals, and truncated subtraction. It fails on products of variables, on ^, or when the fact it needs is hidden inside a definition.
- Bring the needed facts into the context as hypotheses (
have := Nat.mul_le_mul …) and name nonlinear subterms (set m := a * b with hm). - Unfold definitions first (
simp only [f] at *orunfold f), since omega does not see through them. - For real or rational goals use
linarith; for nonlinear onesnlinarithorpositivity.
simp made no progress · tactic
simp made no progress
None of the simp lemmas applied. The term is probably not in the syntactic form the lemmas expect (hidden behind a definition, a coercion, or a different but equal expression).
- Unfold the definition explicitly:
simp [myDef]orunfold myDef. - Check the goal with the infoview; use
rwwith the exact lemma, orsimp only [...]with the right lemma names. - Remove the
simpif the goal is already in the form you want;simp at hfailing can also meanhis unchanged.
Unsolved goals · tactic
unsolved goals case h ⊢ 0 < n
The tactic block ended while goals remained. Often a case split (rcases, interval_cases, constructor, induction) produced more goals than the following tactics handled, or a <;> combinator closed only some of them.
- Read the listed goals: handle each case with
·bullets, or close them uniformly withall_goals …or<;>. - If a goal mentions
sorryor?m, an earlier elaboration error is the real cause; fix that first.
decide failed to reduce · tactic, kernel
decide failed to reduce to true/false
decide could not evaluate the Decidable instance to isTrue. Either the proposition is false, the instance is not computable (classical, Real, Set membership, Nat.find, well-founded recursion), or evaluation got stuck on an opaque definition.
- Check the statement is actually true for the concrete values.
- Try
decide +kernelwhen evaluation is merely too slow for the elaborator. - Make the instance computable: state it over
Finset/Fin/Booldata, provideDecidablePred/DecidableRelinstances, or unfold to structural recursion.native_decideis not accepted on nosorry.
Definition must be noncomputable · elaboration
failed to compile definition, consider marking it as 'noncomputable' because it depends on 'Real.sqrt'
The definition uses something without executable code (Classical.choice, Real operations, sInf, Nat.find on a classical predicate), so it cannot be compiled.
- Mark it
noncomputable def, or putnoncomputable sectionat the top of the file. - If you need to compute with it (
decide), redefine it computably and prove it equal to the noncomputable version.
Universe level problems · elaboration
stuck at solving universe constraint max (u_1+1) ?u =?= u+1
Lean cannot reconcile universe levels: a lemma quantified over Type u is applied to a type in another universe, or a statement uses Type* and your proof introduces a different universe name.
- Name universes explicitly (
universe u_1,{α : Type u_1}) to match the reference, and instantiate constants with.{u_1}. - Lift concrete types to the right universe with
ULift.{u_1} (Fin n). - Avoid
Sort*/Type*in helper lemmas that must line up with a given statement.
Cannot synthesize placeholder · elaboration
don't know how to synthesize placeholder for argument 'f'
A _ or an implicit argument could not be inferred from the context, often because the expected type is unknown at that point (e.g. in a have without a type, or Finset.sum_le_sum _).
- Give the type:
have h : T := …, or pass the argument explicitly with(x := …)or@foo _ _ x. - Use
refine foo ?_ ?_to leave real subgoals instead of_.
Invalid field notation · elaboration
invalid field 'foo', the environment does not contain 'Nat.foo'
h.foo was used, but no T.foo exists for the head type T of h, typically because h is a Prop with a different head symbol than you think (¬, ↔, ≤ unfolding), or because the lemma lives in another namespace.
- Call the lemma by its full name:
Nat.le_of_lt_succ hinstead ofh.le_of_lt_succ. - Check the head of the type: for
h : a ∈ swiths : Finset α, the namespace isFinset.Mem/Finset, notSet. {u, v}being read as a structure instance ("is not a field of structure") means theInsertinstance is missing; see the DecidableEq hint.
Ambiguous notation or name · elaboration, syntax
ambiguous, possible interpretations: _root_.foo, Nat.foo
Two opened namespaces provide the same name or notation (e.g. Finset.card and Set.card as #, Nat.sub lemmas in root and Nat, π from Real and Nat.Prime counting).
- Use the fully qualified name (
Finset.sum_comm,_root_.foo). - Narrow the
open:open Finset inonly where needed, or remove a conflictingopen.
Unexpected token (often Lean 3 syntax) · syntax
unexpected token ','; expected '↦', '=>'
The parser hit syntax it does not understand. Typical sources are Lean 3 / mathlib3 idioms: begin … end, λ x, e, assume, from, at h ⊢ written oddly, { } blocks for goals, cases h with x hx, or $.
- Translate to Lean 4:
by+ indentation instead ofbegin … end,fun x => e(orfun x ↦ e),introinstead ofassume,obtain ⟨x, hx⟩ := hinstead ofcases h with x hx,<|instead of$. - Use
·bullets for subgoals and;/newline between tactics; check for a missing:=orby.
Kernel deep recursion · kernel, performance
(kernel) deep recursion detected
The kernel ran out of stack while type-checking, usually in a decide/rfl proof that unfolds a large computation, or in a huge term from simp on big numerals.
- Split the computation into many small
decide +kernellemmas and combine them withrw. - Use binary-friendly representations and
norm_numfor arithmetic on large numbers instead of unary unfolding. - Prove recursion equations (
f (n+1) = …) and rewrite with them instead of evaluatingf 1000byrfl.
ring failed · tactic
ring failed, ring_nf subsidiary goal
The goal is not an identity of commutative (semi)rings as written, often because of ℕ subtraction or division, a hidden definition, or an inequality instead of an equation. ring then falls back to ring_nf and shows the normal form.
- Compare the two normal forms that
ring_nfdisplays to see which term differs. - Eliminate truncated subtraction/division first (
Nat.cast_sub,obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le h), or move to ℤ/ℝ withzify/push_cast. - For fields use
field_simpthenring; for goals with hypotheses uselinear_combination h.
norm_num failed to simplify · tactic
norm_num failed to simplify
norm_num could not close or simplify the goal. It evaluates numerals and decides arithmetic facts like Nat.Prime 1291, but it does not know your definitions.
- Pass the definitions and lemmas:
norm_num [f, Finset.sum_range_succ]. - For finite checks over variables use
interval_cases x <;> norm_num, ordecide. - If the goal contains a variable,
norm_numcan only simplify; finish withomega,linarithorpositivity.
positivity failed · tactic
failed to prove positivity: the expression a - b is not positive
positivity proves only goals of the form 0 < e, 0 ≤ e or e ≠ 0 by syntactic structure. It fails on subtraction (a - b), on atoms without a sign hypothesis it can find, or on goals like a < b.
- Rewrite the goal as
0 < b - a(sub_pos.mpr) and prove it withlinarith/nlinarith. - Supply facts about atoms by
have ha : 0 < a := …first; positivity uses hypotheses only for atoms. - For ℕ subtraction, use
Nat.sub_pos_of_ltoromega.
exact? found nothing · tactic
`exact?` could not close the goal. Try `apply?` to see partial suggestions.
Library search did not find a single lemma closing the goal. Search tactics are fine locally, but they must not stay in a nosorry submission.
- Reformulate the goal into a standard form (
simp onlyfirst,push_neg, move casts), then retryexact?orapply?locally. - Search by name pattern: Mathlib names follow the statement (
Finset.card_le_card,Nat.lt_of_lt_of_le), andrw?/simp?can help. - Replace every
exact?by the term it suggested before submitting.
Termination proof failed · elaboration
fail to show termination for f with errors: failed to prove termination
A recursive definition is not structurally recursive, and Lean could not prove that the well-founded measure decreases.
- Add
termination_by n - i(or another measure) and adecreasing_byblock, proving the decrease withomegaorsimp_wf; omega. - Reformulate with structural recursion on
ℕor withNat.iterate/List.foldl. Such definitions are also easier todecide. partial defis refused on nosorry, so you need a real termination proof.
Unknown tactic · syntax, import
unknown tactic
The tactic name is not available: missing import Mathlib, a Lean 3 tactic name (norm_num1 variants, by_contradiction, cases' used wrongly), or a tactic renamed in recent Mathlib (push_neg vs push Not).
- Make sure the file imports Mathlib (the challenge header does).
- Use Lean 4 names:
by_contra,rcases/obtain,exact_mod_cast,field_simp,positivity,omega,decide.
Instance search ran out of heartbeats · typeclass, performance
(deterministic) timeout at `synthInstance`, maximum number of heartbeats (20000) has been reached
Typeclass synthesis hit its own budget (synthInstance.maxHeartbeats, 20000 by default) before finding an instance. Often a general instance is tried early and starts a long search that fails.
- If the search can succeed but is long, raise the budget for this declaration only:
set_option synthInstance.maxHeartbeats 200000 in, with a comment that says why. - Demote the instance that leads the search astray:
attribute [local instance 20] Foo.toBar(find it withset_option trace.Meta.synthInstance true in). - Provide the instance directly with
haveI/letI, or add a shortcutinstance : C T := inferInstanceonce.
Instance problem too large (synthInstance.maxSize) · typeclass, performance
failed to synthesize Fintype ((m ⊕ n) ⊕ (p ⊕ q)) maximum class-instance resolution size has been reached
The instance terms grew past the size limit, typically with deeply nested index types (sums of sums, products of matrix types) or long chains of structure projections.
- Raise the limit for the one declaration:
set_option synthInstance.maxSize 512 in(the default is 128), with a comment naming the nested types. - Name the nested type with an
abbrevor adefwith its own instances, so the search sees a small term. - Check that the instance exists at all (
#synth), since a missing instance also fails, only later.
Timeout while unifying (definitions being unfolded) · performance, elaboration
(deterministic) timeout at `isDefEq`, maximum number of heartbeats (200000) has been reached
The defeq checker is unfolding definitions such as Finset.sum, Finset.univ or a large construction while comparing two terms, often in exact, rw or apply.
- Seal the definitions for this declaration:
seal Finset.sum Finset.prod Finset.univ inbefore the lemma (orseal myBigDef in). - Elaborate the term before unifying with the goal:
exact (foo h :)instead ofexact foo h. - Make large definitions irreducible after proving their API lemmas:
attribute [irreducible] myDef.
simp loops between a lemma and its reverse · tactic, performance
maximum recursion depth has been reached use `set_option maxRecDepth <num>` to increase limit
A simp set contains a lemma together with a lemma that undoes it (for example foo and ← foo_assoc), or a definition is unfolded and refolded, so simp never terminates.
- Leave one direction out:
simp [-foo, ← foo]or remove the reversed lemma from the list. - Use
simp only [...]with an explicit list, and mark lemmas that must act first as pre-lemmas:simp [↓map_mul]. - If a default simp lemma always misleads, erase it for the file with
attribute [-simp] foo.
Rewrite fails on a different Decidable or Fintype instance · typeclass, tactic
tactic 'rewrite' failed, motive is not type correct
The goal and the lemma carry different (non-defeq) instances, for example the classical DecidableEq against a computing one, or Fintype.ofFinite against Fin n's own instance, so the pattern does not match syntactically.
- Bridge the instances with
convert h using 2,congr!, or a small@[simp]lemma proved bycongr(instances ofDecidable/Fintypeare subsingletons). - Put
open scoped Classical inon the definition instead of the whole file, and addFintype.ofFiniteonly asattribute [local instance low]. - State results with
Nat.cardinstead ofFintype.cardto avoid the instance altogether.