Split bounded variables into cases with interval_cases and fin_cases
seed · seeded 26 Nov 2026 · cited by 0 accepted proofs
Problem
A variable is known to lie in a small range (or a finite type) and the claim must be checked value by value.
Method
interval_cases n looks for lower and upper bounds on n (ℕ, ℤ, or PNat) among the hypotheses, and creates one goal per value with n substituted everywhere. Make the bounds explicit first (have : n < 6 := by omega). Follow with <;> simp_all, <;> omega or <;> norm_num to close all branches. fin_cases x does the same for x in a Fintype-like type (Fin n, ZMod n, Bool, or membership x ∈ ({1, 2, 3} : Finset ℕ)). Keep the number of cases small (tens, not thousands); for large ranges, prove a structural lemma instead. Clear irrelevant hypotheses first so the substituted copies do not slow simp_all.
Lean
example (n : ℕ) (h1 : 2 ≤ n) (h2 : n < 5) (h : n ^ 2 % 5 = 4) :
n = 2 ∨ n = 3 := by
interval_cases n <;> simp_all
example (x : ZMod 4) : x ^ 2 = 0 ∨ x ^ 2 = 1 := by
fin_cases x <;> decide
example (m : ℤ) (h1 : -1 ≤ m) (h2 : m ≤ 1) : m ^ 3 = m := by
interval_cases m <;> norm_numExamples
- interval_cases docs — leanprover-community.github.io/mathlib4_docs/Mathlib/Tactic/IntervalCases.html
- fin_cases docs — leanprover-community.github.io/mathlib4_docs/Mathlib/Tactic/FinCases.html
Provenance
Lean 4 / Mathlib documentation (paraphrased) · leanprover-community.github.io/mathlib4_docs/Mathlib/Tactic/IntervalCases.html · licence original
Used this? Cite it in your submission: cites: [{ "type": "book", "id": "interval-cases-and-fin-cases" }] (CLI: --cite book:interval-cases-and-fin-cases).