Skip to content

Check that we're working over the same ring in "coefficient" - #4478

Merged
d-torrance merged 7 commits into
Macaulay2:developmentfrom
d-torrance:coefficient
Aug 3, 2026
Merged

Check that we're working over the same ring in "coefficient"#4478
d-torrance merged 7 commits into
Macaulay2:developmentfrom
d-torrance:coefficient

Conversation

@d-torrance

Copy link
Copy Markdown
Member

This is already what the docs say we should do, and it can lead to strange behavior (e.g., over tower rings a la #4452) if we don't check. Also add some unit tests.

Draft for now to test the builds -- this is a slight breaking change.

AI Disclosure

Claude Code helped me diagnose the problem, but I wrote the code myself.

This is already what the docs say we should do, and it can lead to
strange behavior (e.g., over tower rings) if we don't check.
We need both arguments to be in the same ring, so we lift the 2nd
argument to D1.
@d-torrance d-torrance linked an issue Jul 19, 2026 that may be closed by this pull request
@d-torrance d-torrance added the Core Issues involving the Core scripts. label Jul 19, 2026
We're working over both QQ and ZZ/p -- find coefficients over QQ and
sub into ZZ/p later.

Also, simplify the code to use "product" while we're at it.
We now need both arguments of "coefficient" to be in the same ring,
and both t and pol are already in B.  There's no reason to introduce a
new copy of ZZ[t].
We now need both arguments of "coefficient" to be in the same ring,
matching the documentation.
We now need both arguments to be in the same ring, matching the
documentation.
@d-torrance

Copy link
Copy Markdown
Member Author

Alright, finally whack-a-moled all the packages that were using coefficient with arguments from different rings. I'm not sure if I fixed each of them in the most efficient way, but now everything passes.

@d-torrance
d-torrance marked this pull request as ready for review July 20, 2026 01:40
@pzinn

pzinn commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

can you give an example of something that used to work and no longer does with this PR?

@d-torrance

Copy link
Copy Markdown
Member Author

can you give an example of something that used to work and no longer does with this PR?

Sure:

i1 : R = QQ[x,y,z,w];

i2 : f = random(2, R)

     9 2   1      3 2   1      7        2   4      2      8      7 2
o2 = -x  + -x*y + -y  + -x*z + -y*z + 7z  + -x*w + -y*w + -z*w + -w
     2     9      2     5      8            3      9      3      6

o2 : R

i3 : S = ZZ[x,y,z,w];

i4 : coefficient(x^2, f) -- x^2 is in S

     9
o4 = -
     2

o4 : QQ

@pzinn

pzinn commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

weird. definitely shouldn't work!

@d-torrance

d-torrance commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

Tagging authors of packages where we updated coefficient to avoid the new error to make sure that everything looks okay:

-- 2) in general promote(promote(d,B),D) != d.
promote(D,B) := (d,B) -> (
dcoeffs := apply(E_0..E_(n-1), m -> f(coefficient(D1_(m), DtowertoD^-1 d)));
dcoeffs := apply(E_0..E_(n-1), m -> f(coefficient(D1_(m), (DtowertoD^-1 d)^D1)));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this ^D1 doing here? This seems to change the ring.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's lifting the 2nd argument to D1 to match the 1st argument

@MichaelABurr MichaelABurr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mostly looks good to me. There's one change that appears to change the ring, but it seems like this is what the ring should have been originally.

@galettof

Copy link
Copy Markdown
Contributor

Thank you for fixing this in InvariantRing.

@tbrazel

tbrazel commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

This looks good for me, A1BrouwerDegrees still runs as expected

@giovannistagliano

Copy link
Copy Markdown
Contributor

I ran a few quick tests on SparseResultants and everything seems to work as expected. Thanks.

@d-torrance
d-torrance merged commit 68351e7 into Macaulay2:development Aug 3, 2026
5 checks passed
@d-torrance
d-torrance deleted the coefficient branch August 3, 2026 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Core Issues involving the Core scripts.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InvariantRing + coefficient causes crash

7 participants