This file records the local proof-golfing style for the RealRooted Lean
project. Treat it as the rulebook for cleanup passes, especially when the task
is to shorten proofs without changing mathematics.
The main sources for these rules are older cleanup PRs by Yael Dillies and
sqrt-of-2, especially the PRs that removed omega, adopted upstream-shaped
derivative APIs, shortened proofs with grind, squeezed identical branches
with <;>, removed redundant constructors, and cleaned unused hypotheses.
- Keep the statement and proof intent clear.
- Prefer small local changes over broad rewrites.
- Reuse existing Mathlib/project APIs instead of introducing wrappers.
- Avoid public API churn unless the signature cleanup is clearly useful.
- Build focused targets, then run full
lake buildbefore pushing Lean edits.
- Replace
:= by exact termwith a direct term proof:or, for declarations with no tactic work:have h : P := lemma_name argstheorem foo : P := lemma_name args
- Replace
apply lemmaplus simple bullets with a direct lemma application:exact lemma_name (by ...) h1 h2 - Collapse repeated branches when the same tactic closes all branches:
rcases h with h1 | h2 <;> simp_all by_cases hp : P <;> simp [hp] refine some_lemma ?_ ?_ ?_ <;> simp_all - Use
grindfor local plumbing: simple contradictions, field projections, equality rewrites, constructor goals, and small algebraic rearrangements. - Use
simp_allwhen hypotheses and local definitions are meant to be consumed together. - Use
liafor linear arithmetic. Do not useomega. - Use
positivityfor routine positivity goals when it is stable and shorter. - Remove redundant
left/rightwhen the remaining tactic can infer the disjunct from local hypotheses:rcases h with hleft | hright · have hscaled := ... lia · have hscaled := ... lia
- Remove unused variables and pattern names:
rcases h with ⟨_, hg, _, _, _, _, hss_eq, hrs_eq, hshape⟩ - Split conjunction hypotheses in private/internal helpers when it removes
repeated
.1/.2projections and makes call sites clearer. - Remove unused private hypotheses from theorem signatures when downstream breakage is small and the proof becomes clearer.
- Prefer upstream-shaped and receiver-style APIs:
rather than project-local compatibility wrappers, when the upstream-shaped API is available.
p.natDegree_derivative h (p.derivative_ne_zero).mpr h hp_pos.derivative h hnn.iterate_derivative n
- Prefer canonical list/interleaving APIs and bridge lemmas already centralized
in
RealRooted/Basic.lean. - Prefer canonical iff/simp lemmas when both directions are useful; derive negated or one-way forms from them.
- Prefer weaker natural hypotheses such as
n ≠ 0over1 ≤ nwhen that is the real condition.
- Do not replace a readable structured proof by opaque automation if the local mathematical argument becomes hard to see.
- Do not add a new helper just to save one or two lines. Add helpers only when they remove real duplication or match a Mathlib-shaped API.
- Do not churn public theorem signatures merely to save projections, unless the change is clearly internal or coordinated with the API direction.
- Do not mix unrelated formatting cleanup with proof changes.
- Do not silence linters as a golfing tactic. Prefer fixing the issue.
- For a touched Lean file, run the focused module build first:
lake build RealRooted.SomeModule
- For cross-module or public API changes, build the downstream target set if it is obvious.
- Before committing or pushing Lean changes, run:
lake build
- Keep
git diff --checkclean. Avoid introducing new long lines or tabs.