Skip to content

fix: mathlib4, reference-manual breakage from nightly-2026-11-24 (lean4#16694) - #282

Merged
TwoFX merged 2 commits into
masterfrom
push-nskwxplzxqwx
Nov 24, 2026
Merged

TwoFX merged 2 commits into
masterfrom
push-nskwxplzxqwx

Conversation

@downstream-lean4

Copy link
Copy Markdown
Contributor

2 of 2 for run 45376637887, with #281 — and master additionally needs the still-open #268, #273, #275 and #279. Verified together; on its own this PR's CI stays red on import-graph until #281 merges.

lean4#16694 renames Nat.repeat to Nat.iterate and generalizes it to Sort u, leaving deprecated abbrevs behind. Both repos here are hit by it, for different reasons.

mathlib4 — f^[n] unfolds the other way round now

Nat.iterate is also the name of Mathlib's own definition, the denotation of f^[n], so it is now 'Nat.iterate' has already been declared and the definition has to go. But the PR's description — "this effectively upstreams Nat.iterate from mathlib" — understates one thing: the two definitions apply the step at opposite ends.

mathlib:  iterate f (n+1) a = iterate f n (f a)   -- `f^[n+1] = f^[n] ∘ f` by rfl
core:     iterate f (n+1) a = f (iterate f n a)   -- `f^[n+1] = f ∘ f^[n]` by rfl

The question for @Rob23oba: was flipping the recursion deliberate? If core's Nat.iterate matched the definition it replaces, the whole mathlib4 half of this PR — 29 files — would be unnecessary, and the statements of iterate_succ/iterate_succ' would keep their current roles. Nothing below is a fix for a bug; it is all bookkeeping that follows from that one flip. Happy to drop it if the direction changes upstream instead.

What the flip costs, in Mathlib/Logic/Function/Iterate.lean first: iterate_succ/iterate_succ_apply are no longer rfl (they get a one-line induction) and iterate_succ'/iterate_succ_apply' now are, so the two swap proofs. Then, in 28 further files:

  • Composition order (19 lemmas). X.iterate proved as Nat.recOn n id fun _ ih ↦ ih.comp h now needs h.comp ih: Injective, Surjective, Monotone, StrictMono, MapsTo, InjOn, SurjOn, BijOn, Continuous, ContinuousAt, ContinuousOn, Differentiable, DifferentiableOn, LipschitzWith, Measurable, MeasurePreserving, QuasiMeasurePreserving, LeftOrdContinuous (and its @[to_dual] twin), Semiconj, Semiconj₂, Tendsto. Where the composite carries extra data, its companion comes along too — MapsTo.iterate for InjOn/DifferentiableOn/ContinuousOn, iterate_fixed for ContinuousAt, pow_succ' instead of pow_succ for LipschitzWith's constant.
  • Proofs that were rfl only through the old unfolding now name Function.iterate_succ_apply: Iterate.rec, agmSequences_succ and two of its inductions, iteratedDerivWithin_succ', PerfectClosure.mk_eq_iff, eq_iterate_verschiebung, iterated_kk, List.iterate_add, birkhoffSum_succ_apply', Equiv.Perm.pow_aux, the Int.sign induction in Imo2006Q5, SetRel.subset_iterate_comp, supportsStmt_move, le_invariants_iterate, Lie.trivial_iff_lower_central_eq_bot, and PicardLindelof.dist_iterate_iterate_next_le_of_lipschitzWith (where the rw that used to line the goal up now has to go).
  • iterate_succ was a dsimp lemma while it was rfl. Three dsimp calls relied on that silently and now name the lemma they want; two rw/simp only [iterate_succ_apply'] cleanups in Imo2006Q5 became dead and would fail --wfail as unused tactics.
  • Mathlib/Tactic/Core.lean reaches the deprecated Nat.repeat through dot notation ((n - pats.size).repeat …), which --wfail makes fatal.

Worth knowing when this recurs: the wave is visible only one layer at a time, because a failing module hides everything that imports it. The run's report named three modules; it took eleven full builds to reach the end of the list.

reference-manual — two deprecated names and a simp set

{docstring Nat.repeat} and {docstring Nat.repeatTR} in Manual/BasicTypes/Nat.lean are errors, since verso refuses to document a deprecated name. In Manual/BasicTypes/Range.lean, simp [Std.PRange.succMany?, Nat.repeat] now unfolds the abbrev instead of supplying Nat.iterate's equations, so the chapter's two succMany? lemmas and the Day instance built on them failed, and the three #eval blocks below them reported the resulting sorry. Renaming the two docstring blocks, one prose reference and three simp/simp_all sets is the whole change; the definition's semantics are unchanged.

Verified

On master@origin 3e38a16 (nightly-2026-11-24), with the open #273 and #279 (mathlib4) and #268 and #275 (reference-manual) applied locally:

  • mathlib4: lake build Mathlib Archive Counterexamples Wanted cache --wfail — 18661 jobs, no warnings; lake test --iofail; lake lint. All green.
  • reference-manual: lake build green (it defines no test or lint driver). Built against elan v4.4.0, so the elanHelp blocks match what CI installs.
  • repl, whose test phase recompiles this Mathlib, is green unchanged: lake build and lake test.

lean4#16694 renamed `Nat.repeat`/`Nat.repeatTR` to
`Nat.iterate`/`Nat.iterateTR`, leaving deprecated `abbrev`s behind.
`{docstring Nat.repeat}` is an error (verso refuses to document a
deprecated name), and `simp [Nat.repeat]` in the `Day` range example
now unfolds the `abbrev` instead of supplying `Nat.iterate`'s
equations, so the `succMany?` lemmas and everything that depended on
them failed.

Rename both docstring blocks, the one prose reference, and the three
`simp`/`simp_all` sets. Semantics are unchanged: the definition only
moved from `Type u` to `Sort u`.
lean4#16694 renames `Nat.repeat` to `Nat.iterate` and generalizes it to
`Sort u`, which is where Mathlib's own `Nat.iterate` — the denotation of
`f^[n]` — used to live. The name now clashes (`'Nat.iterate' has already
been declared`), so the definition goes; but the two differ in which end
the step is applied to:

    mathlib:  iterate f (n+1) a = iterate f n (f a)   -- `f^[n+1] = f^[n] ∘ f`
    core:     iterate f (n+1) a = f (iterate f n a)   -- `f^[n+1] = f ∘ f^[n]`

So `Function.iterate_succ`/`iterate_succ_apply` are no longer `rfl` and
`iterate_succ'`/`iterate_succ_apply'` now are; the file swaps the two.
Everything else follows from that one flip, in 28 further files:

* `X.iterate` lemmas built as `Nat.recOn n id fun _ ih ↦ ih.comp h` need
  `h.comp ih` — 14 of them (`Injective`, `Surjective`, `Monotone`,
  `StrictMono`, `MapsTo`, `InjOn`, `SurjOn`, `BijOn`, `Continuous`,
  `ContinuousAt`, `ContinuousOn`, `Differentiable`, `DifferentiableOn`,
  `LipschitzWith`, `Measurable`, `MeasurePreserving`,
  `QuasiMeasurePreserving`, `LeftOrdContinuous`, `Semiconj`,
  `Semiconj₂`, `Tendsto`). Where the composite's data also flips, the
  companion argument comes along: `MapsTo.iterate` for `InjOn`/
  `DifferentiableOn`/`ContinuousOn`, `iterate_fixed` for `ContinuousAt`,
  `pow_succ'` for `LipschitzWith`'s constant.
* Proofs that were `rfl` only through the old unfolding get
  `Function.iterate_succ_apply` (`Iterate.rec`, `agmSequences_succ`,
  `iteratedDerivWithin_succ'`, `PerfectClosure.mk_eq_iff`,
  `eq_iterate_verschiebung`, `Int.sign`-induction in `Imo2006Q5`,
  `iterated_kk`, `List.iterate_add`, `birkhoffSum_succ_apply'`).
* `iterate_succ` was a *dsimp* lemma while it was `rfl`; three `dsimp`
  calls that relied on that now name the lemma they need, and two
  now-dead `rw`/`simp only [iterate_succ_apply']` cleanups in
  `Imo2006Q5` go away — they would fail `--wfail` as unused tactics.
* `Mathlib/Tactic/Core.lean` uses the deprecated `Nat.repeat` via dot
  notation.

Verified on `master@origin` 3e38a16 with the open #273 and #279
applied: `lake build Mathlib Archive Counterexamples Wanted cache
--wfail` (18661 jobs, no warnings), `lake test --iofail` and `lake lint`
all green.
@downstream-lean4

Copy link
Copy Markdown
Contributor Author

Build report for fix: mathlib4 breakage from nightly-2026-11-24 (lean4#16694)

Stayed red
Repo Critical Build Test Lint
import-graph ✅ ✅ in 2s 🟥 in 4s ⏭️
mathlib4 ✅ 🟥 in 1m 36s ⏭️ ⏭️
reference-manual ✅ 🟥 in 56s ⏭️ ⏭️
cslib 🛑 by mathlib4 ⏭️ ⏭️
repl ✅ in 0s 🟥 in 19s ⏭️
Stayed green
Repo Critical Build Test Lint
aesop ✅ ✅ in 0s ✅ in 4s ⏭️
batteries ✅ ✅ in 0s ✅ in 3s ✅ in 1s
lean4-cli ✅ ✅ in 0s ✅ in 0s ⏭️
plausible ✅ ✅ in 0s ✅ in 2s ⏭️
ProofWidgets4 ✅ ✅ in 1s ✅ in 1s ⏭️
quote4 ✅ ✅ in 0s ✅ in 1s ⏭️
BibtexQuery ✅ in 2s ⏭️ ⏭️
doc-gen4 ✅ in 5s ⏭️ ⏭️
illuminate ✅ in 0s ✅ in 9s ⏭️
lean4-unicode-basic ✅ in 3s ⏭️ ⏭️
lean4export ✅ in 0s ✅ in 5s ⏭️
LeanSearchClient ✅ in 0s ✅ in 0s ⏭️
leansqlite ✅ in 6s ✅ in 16s ⏭️
nerodia ✅ in 0s ✅ in 23s ⏭️
verso ✅ in 1m 15s ✅ in 3m 16s ⏭️
verso-slides ✅ in 16s ✅ in 9s ⏭️
verso-web-components ✅ in 3s ⏭️ ⏭️

View run

@TwoFX
TwoFX merged commit ce54ff6 into master Nov 24, 2026
17 of 23 checks passed
mhuisi added a commit that referenced this pull request Nov 26, 2026
Fixes the `import-graph` breakage from nightly-2026-11-24 (lean4#15218).
Needs a toolchain that contains lean4#16718, that is nightly-2026-11-25
or later.

## `import-graph` — `Lean.SourceInfo.getLeading?` was declared twice

lean4#15218 added the core formatter. Its module `Lean.Fmt.Util.Basic`
declared `Lean.SourceInfo.getLeading?` with the same signature as
`ImportGraph.Lean.Syntax`. Every module that imports both failed:

```
ImportGraphTest.lean:1:0: import Lean.Fmt.Util.Basic failed,
  environment already contains 'Lean.SourceInfo.getLeading?' from ImportGraph.Lean.Syntax
```

lean4#16718 removed `Lean.Fmt.Util.Basic` and moved
`Lean.SourceInfo.getLeading?` into `Init.Prelude`. This PR deletes the
duplicate definition in `ImportGraph.Lean.Syntax`, and
`SourceInfo.getLeading` uses the core function. import-graph does not
import a formatter module.

The `#min_imports` fixtures use `SourceInfo.getLeading`, which stays in
import-graph. Their expected output does not change.

### Merge order

- With nightly-2026-11-24, this PR does not compile, because
`Lean.Syntax` does not give `getLeading?` on that nightly.
- With nightly-2026-11-25 or later, master does not compile without this
PR: `ImportGraph.Lean.Syntax` fails with "`Lean.SourceInfo.getLeading?`
has already been declared".

Thus merge this PR together with the bump to nightly-2026-11-25. #282
needs this PR for a green `import-graph`.

### Verified

`ImportGraph.Lean.Syntax` compiles against a lean4 build that contains
lean4#16718. `lake build` and `lake test` of import-graph did not run
yet. CI runs them after the bump.

<!-- downstream-watch: unattended -->

---------

Co-authored-by: downstream-lean4[bot] <downstream-lean4[bot]@users.noreply.github.com>
Co-authored-by: mhuisi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant