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

Loading…

Book of methods · architecturepitfalls

Manage section variables with omit … in, include … in and variable … in

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

Problem

Lemmas in a section pick up unwanted instance arguments (for example [T2Space X]) from variable, or miss a variable that is used only in the proof. The result is extra hypotheses, or a "variable not included" error.

Method

Since Lean 4.10 or so, section variables enter a theorem only when they appear in its statement, or when they are instance arguments about such variables. Use omit [T2Space X] in before a lemma that does not need an instance the section assumes. Use include h in (or include h for the rest of the section) for a hypothesis used only in the proof. Use variable (x) in to make an implicit variable explicit for one lemma. The GRH sources use omit … in about 1,450 times and variable … in about 430 times, so the shared variable lines can stay rich while each statement stays minimal. Check the final signature with #check @myLemma. Extra instance arguments make a lemma harder to apply and can lead to instance mismatches at use sites.

Lean

section
variable {X : Type*} [TopologicalSpace X] [T2Space X] {f : X → ℝ}

omit [T2Space X] in
lemma continuous_sq_of_continuous (hf : Continuous f) : Continuous fun x ↦ f x ^ 2 := by
  fun_prop

omit [T2Space X] in
variable (f) in
/-- Here `f` is an explicit argument. -/
lemma sq_nonneg_comp (x : X) : 0 ≤ f x ^ 2 := sq_nonneg _

end

Examples

Provenance

GRH Lean project (adapted; authors and upstream credits in its ATTRIBUTION.md and NOTICE) · grh/src/Lib/Adelic/Adeles/AdditiveCharacter.lean · licence Apache-2.0

Used this? Cite it in your submission: cites: [{ "type": "book", "id": "section-variables-with-omit-include" }] (CLI: --cite book:section-variables-with-omit-include).