Fix divByMonicAux initial counter off-by-one#124
Fix divByMonicAux initial counter off-by-one#124eliasjudin wants to merge 4 commits intoVerified-zkEVM:masterfrom
Conversation
Start divModByMonicAux with p.size + 1 - q.size so monic long division performs the final reduction step instead of stopping one iteration early.
🤖 Gemini PR SummaryCorrects an off-by-one error in Logic & Functional Changes
Regression TestingValidates quotient and remainder behavior against specific regression examples:
Project Maintenance
Analysis of Changes
Lean Declarations ✏️ **Removed:** 3 declaration(s)
🎨 **Style Guide Adherence**
📄 **Per-File Summaries**
Last updated: 2026-02-27 11:24 UTC. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5cebb11aec
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Switch divModByMonicAux to size-based fuel with an explicit `p.size < q.size` stop condition, and keep regression examples covering the reported remainder behavior. Co-authored-by: Aristotle (Harmonic) <aristotle-harmonic@harmonic.fun>
47e29a8 to
f913dc1
Compare
dhsorens
left a comment
There was a problem hiding this comment.
nice, thank you for fixing this issue! tests are a good touch. if you can just modify the comment I'll go ahead and merge
| We use `p.size` as fuel for the recursion. This is always sufficient because | ||
| each division step strictly decreases the size of the remainder (the leading | ||
| term is cancelled by a monic divisor, and `trim` removes any resulting trailing | ||
| zeros). The guard `p.size < q.size` triggers as soon as the remainder is of | ||
| lower degree than the divisor, so the recursion terminates cleanly even when | ||
| cancellation causes the size to drop by more than one in a single step. -/ |
There was a problem hiding this comment.
I see why these comments are included now, but I don't think they're necessary for the repository. Let's just keep the docstring to one line?
| /-- Regression test for issue #115: `(X^2 - 1) / (X + 1) = X - 1` with zero remainder. -/ | ||
| example : | ||
| divByMonic ((X : CPolynomial.Raw ℚ) ^ 2 - C 1) ((X : CPolynomial.Raw ℚ) + C 1) | ||
| = #[-(1 : ℚ), 1] := by | ||
| native_decide | ||
|
|
There was a problem hiding this comment.
good call to include tests like this, and probably something we want more of. in the long run we won't want these here but let's keep them here right now
Fixes #115.
This PR makes
divModByMonicAuxterminate by size in a mathematically robust way:p.sizeas recursion fuel,p.size < q.size,X^2 - 1overX + 1andX^3overX^2 + 1regression examples.It also updates the
ERR_NUM_LINwatermark forCompPoly/Univariate/Raw.leanso style lint matches the current file length.Local checks:
lake build CompPoly.Univariate.Rawlake build CompPoly.Univariate.Basicpython3 scripts/lint-style.py CompPoly/Univariate/Raw.leanThis PR adds proofs autoformalised by @Aristotle-Harmonic.
Aristotle contributed to the monic-division refinement by providing the size-fuel recursion structure and termination guard that preserve correct long-division behavior.
Co-authored-by: Aristotle (Harmonic) aristotle-harmonic@harmonic.fun