Skip to content

fix: align Lean/Level.lean and kernel/level.cpp normalization rules - #14356

Open
digama0 wants to merge 2 commits into
leanprover:masterfrom
digama0:fix/level-normalize-parity
Open

digama0 wants to merge 2 commits into
leanprover:masterfrom
digama0:fix/level-normalize-parity

Conversation

@digama0

@digama0 digama0 commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

This PR aligns the Level normalization rules in Lean/Level.lean (stdlib) and kernel/level.cpp (kernel) so that both produce the same normalized Level for the same input.

Specifically, mk_max in src/kernel/level.cpp gains the "one operand is explicit and the other's offset dominates" simplification (e.g. max (succ u_1) 1 → succ u_1, which the stdlib's mkLevelMaxCore already performed), and mkLevelIMaxCore in src/Lean/Level.lean gains the imax 1 u = u case that C++'s mk_imax already had (via is_one(l1)). Both simplifications are semantics-preserving; the goal is only to make the two implementations agree so that downstream expression hashes computed by different tools (elaborator, #reduce, lean4lean, other kernel reimplementations) match on a fixed input.

@digama0
digama0 requested a review from leodemoura as a code owner July 10, 2026 15:06
@digama0 digama0 added the changelog-language Language features and metaprograms label Jul 10, 2026
@digama0 digama0 changed the title fix: align \Lean/Level.lean\ and \kernel/level.cpp\ normalization rules fix: align Lean/Level.lean and kernel/level.cpp normalization rules Jul 10, 2026
This PR aligns the `Level` normalization rules in `Lean/Level.lean` (stdlib) and `kernel/level.cpp` (kernel) so that both produce the same normalized `Level` for the same input.

Specifically, `mk_max` in `src/kernel/level.cpp` gains the "one operand is explicit and the other's offset dominates" simplification (e.g. `max (succ u_1) 1 → succ u_1`, which the stdlib's `mkLevelMaxCore` already performed), and `mkLevelIMaxCore` in `src/Lean/Level.lean` gains the `imax 1 u = u` case that C++'s `mk_imax` already had (via `is_one(l1)`). Both simplifications are semantics-preserving; the goal is only to make the two implementations agree so that downstream expression hashes computed by different tools (elaborator, `#reduce`, `lean4lean`, other kernel reimplementations) match on a fixed input.
@digama0
digama0 force-pushed the fix/level-normalize-parity branch from af1ee70 to 8193825 Compare July 10, 2026 15:09
@github-actions github-actions Bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Jul 10, 2026
@mathlib-lean-pr-testing

mathlib-lean-pr-testing Bot commented Jul 10, 2026

Copy link
Copy Markdown

Mathlib CI status (docs):

  • ❗ Mathlib CI can not be attempted yet, as the nightly-testing-2026-07-10 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Mathlib CI should run now. You can force Mathlib CI using the force-mathlib-ci label. (2026-07-10 16:15:34)
  • 💥 Mathlib branch lean-pr-testing-14356 build failed against this PR. (2026-07-31 20:40:58) View Log

@leanprover-bot

leanprover-bot commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-07-10 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-07-10 16:15:36)
  • ✅ Reference manual branch lean-pr-testing-14356 has successfully built against this PR. (2026-07-31 20:41:48) View Log
  • 🟡 Reference manual branch lean-pr-testing-14356 build against this PR didn't complete normally. (2026-07-31 20:43:49) View Log

The elaborator now normalizes imax 1 u to u when pretty-printing the kernel error, matching the kernel's existing behavior. The kernel mismatch this regression test guards is unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions github-actions Bot added the mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN label Jul 31, 2026
@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Jul 31, 2026
@leanprover-bot leanprover-bot added the builds-manual CI has verified that the Lean Language Reference builds against this PR label Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan builds-manual CI has verified that the Lean Language Reference builds against this PR changelog-language Language features and metaprograms mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants