Skip to content

fix: handle numerals in non-tail positions of cutsat polynomials#13199

Closed
kim-em wants to merge 3 commits intoleanprover:masterfrom
kim-em:fix/lia-numeral-non-tail
Closed

fix: handle numerals in non-tail positions of cutsat polynomials#13199
kim-em wants to merge 3 commits intoleanprover:masterfrom
kim-em:fix/lia-numeral-non-tail

Conversation

@kim-em
Copy link
Copy Markdown
Collaborator

@kim-em kim-em commented Mar 31, 2026

This PR fixes a lia regression introduced by #13166. After that PR, the canonicalizer normalizes Nat arithmetic in type positions (e.g. n + 1 + 1 becomes n + 2 in Fin) but leaves value-level expressions unchanged. When cutsat's toPoly processes ↑n + 1 + 1 (in Int), the middle 1 appears as a numeral in a non-tail position of the polynomial being built, and addMonomial falls back to treating it as a variable.

The fix uses the existing Poly.addConst to fold the numeral into the polynomial's constant term regardless of position, instead of the previous logic that only accepted numerals at the tail and reported an issue otherwise.

🤖 Prepared with Claude Code

After leanprover#13166, the canonicalizer normalizes Nat arithmetic in type positions
(e.g. `n + 1 + 1` → `n + 2` in `Fin`) but leaves value-level expressions
unchanged. When `toPoly` processes `↑n + 1 + 1` (in Int), the middle `1`
appears as a numeral in a non-tail position and `addMonomial` would fall
back to treating it as a variable.

Fix: use `Poly.addConst` (which already exists in `Init.Data.Int.Linear`)
to fold the numeral into the polynomial's constant term, regardless of
position.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@kim-em kim-em requested a review from leodemoura as a code owner March 31, 2026 00:25
kim-em and others added 2 commits March 31, 2026 00:36
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@kim-em kim-em force-pushed the fix/lia-numeral-non-tail branch from 94c6d1b to ad8ae7e Compare March 31, 2026 00:55
@kim-em kim-em added the changelog-tactics User facing tactics label Mar 31, 2026
@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 Mar 31, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase f395593ffce1b94cdd025ba51c23aa5eeef7e353 --onto 4786e082dca22873d14d2a5b9b7c8843380c6e78. You can force Mathlib CI using the force-mathlib-ci label. (2026-03-31 01:47:25)

@leanprover-bot
Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase f395593ffce1b94cdd025ba51c23aa5eeef7e353 --onto cfa8c5a036d6990635c6ec50b02d0e806995cec3. You can force reference manual CI using the force-manual-ci label. (2026-03-31 01:47:26)

@kim-em
Copy link
Copy Markdown
Collaborator Author

kim-em commented Apr 11, 2026

Leo is going to solve this via a different approach.

@kim-em kim-em closed this Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-tactics User facing tactics 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