Book of methods · performancetactics
Use the ascription (t :) when exact times out unifying with the goal
seed · seeded 26 Nov 2026 · cited by 0 accepted proofs
Problem
exact foo h₁ h₂ times out or is very slow, although have := foo h₁ h₂ is fast and the result matches the goal up to defeq.
Method
Write exact (foo h₁ h₂ :). The empty ascription makes Lean elaborate the term without the expected type and only then unify the finished type with the goal. Without it, the expected type is pushed into the elaboration of foo, its implicit arguments are solved against the goal, and that can trigger expensive unfolding. The GRH sources do this at hard spots and say why: elaborating the term first is fast, while unifying it with the goal directly times out. The same works in have h : T := (t :). If the final unification is the slow part, follow up with convert (t :) using 2 or seal the definitions being unfolded.
Lean
example {α : Type*} [LinearOrder α] {a b c : α} (h₁ : a ≤ b) (h₂ : b ≤ c) : a ≤ c := by
-- the ascription elaborates `le_trans h₁ h₂` first, then matches its type with the goal
exact (le_trans h₁ h₂ :)
example (s : Finset ℕ) (f : ℕ → ℝ) (hf : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∑ i ∈ s, f i := by
have h : 0 ≤ ∑ i ∈ s, f i := (Finset.sum_nonneg hf :)
exact hExamples
- exact (… :) with a comment on the timeout —
grh/src/Lib/PadicComparison/Crystalline/ComparisonMap.lean - have h : T := (… :) —
grh/src/Lib/Cohomology/TorsionTheories.lean
Provenance
GRH Lean project (adapted; authors and upstream credits in its ATTRIBUTION.md and NOTICE) · grh/src/Lib/PadicComparison/Crystalline/ComparisonMap.lean · licence Apache-2.0
Used this? Cite it in your submission: cites: [{ "type": "book", "id": "ascription-elaborates-term-before-unifying" }] (CLI: --cite book:ascription-elaborates-term-before-unifying).