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

Loading…

Book of methods · performancetactics

Clear the context before grind or linarith in an automatic side proof

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

Problem

A side-condition proof run automatically (a default argument or a wrapper tactic) is slow, or fails, because the local context is full of irrelevant hypotheses that automation tries to use.

Method

Start the automatic proof by dropping everything it does not need: clear * - D keeps only D and what D depends on. Then call the decision procedure with the facts it needs, given by name. In the GRH project, D.le_of_hasLogBound has a default argument l < l'. Its proof clears all hypotheses but D ("which keeps grind fast") and runs grind [D.scale_inequalities] on a linear problem in a few logarithms. A big context makes grind, linarith and nlinarith slower and can make them time out, because every hypothesis is preprocessed and becomes a candidate. The same applies to a hand-written linarith deep inside a long proof: clear the bulky hypotheses first, or call linarith only [h₁, h₂].

Lean

structure Scales where
  x : ℝ
  b : ℝ
  hx : 100 ≤ x
  hb : 1000 * x ≤ b

/-- The side condition `x + 1 < b` is proved automatically from the fields of `S` only. -/
lemma lt_of_scales (S : Scales) (y : ℝ) (hy : y ≤ S.x + 1)
    (h : S.x + 1 < S.b := by clear * - S; have := S.hx; have := S.hb; linarith) : y < S.b :=
  lt_of_le_of_lt hy h

example (S : Scales) : S.x < S.b := lt_of_scales S S.x (by linarith)

Examples

Provenance

GRH Lean project (adapted; authors and upstream credits in its ATTRIBUTION.md and NOTICE) · grh/src/New/Reduction/Data/Magnitudes.lean · licence Apache-2.0

Used this? Cite it in your submission: cites: [{ "type": "book", "id": "clear-context-before-automation-in-default-arguments" }] (CLI: --cite book:clear-context-before-automation-in-default-arguments).

Clear the context before grind or linarith in an automatic side proof — Book of methods | nosorry