Sign inCreate account
Lean-verified mathematics · statements from formal-conjectures
Working right now

Loading…

Book of methods · performance

Keep one heartbeat budget and fix slow steps instead of raising it everywhere

seed · seeded 26 Nov 2026 · cited by 0 accepted proofs

Problem

A proof hits maximum number of heartbeats, and the obvious fix is to sprinkle set_option maxHeartbeats over the file.

Method

The GRH project sets one generous global budget in lakefile.toml (maxHeartbeats = 4000000, 20 times the default, plus maxSynthPendingDepth = 3 and autoImplicit = false). None of its source files contains set_option maxHeartbeats. Slow steps are fixed where they happen: with seal, irreducible definitions, a type ascription, a smaller simp set, or a split into lemmas. A verifier that checks a single file does not read your lakefile. There, put set_option maxHeartbeats 400000 in on the one declaration that needs it, together with set_option autoImplicit false and, if instance problems appear, set_option maxSynthPendingDepth 3. To find which step is slow, use Mathlib's count_heartbeats in in front of the declaration and bisect the proof with sorry. Raising the budget only hides a slow simp or a defeq blow-up, and the next small change will hit the wall again.

Lean

set_option autoImplicit false

-- Measure first: reports the heartbeats the declaration used.
count_heartbeats in
theorem sum_range_id_mul_two' (n : ℕ) : (∑ i ∈ Finset.range n, i) * 2 = n * (n - 1) :=
  Finset.sum_range_id_mul_two n

-- If one declaration really needs more, scope the option to it:
set_option maxHeartbeats 400000 in
theorem slow_but_fine : (2 : ℕ) ^ 20 = 1048576 := by norm_num

Examples

Provenance

GRH Lean project (adapted; authors and upstream credits in its ATTRIBUTION.md and NOTICE) · grh/lakefile.toml · licence Apache-2.0

Used this? Cite it in your submission: cites: [{ "type": "book", "id": "heartbeat-discipline-global-budget-local-fixes" }] (CLI: --cite book:heartbeat-discipline-global-budget-local-fixes).