Skip to content

Use numerator when calling "roots" on element of fraction field#4450

Open
d-torrance wants to merge 2 commits into
Macaulay2:developmentfrom
d-torrance:roots
Open

Use numerator when calling "roots" on element of fraction field#4450
d-torrance wants to merge 2 commits into
Macaulay2:developmentfrom
d-torrance:roots

Conversation

@d-torrance

Copy link
Copy Markdown
Member

This used to segfault. Also add some unit tests.

Before

i1 : R = QQ[x];

i2 : roots((x - 1)/x)
-- SIGSEGV
-* stack trace, pid: 103461
 0# profiler_stacktrace(std::ostream&, int) at /usr/src/macaulay2-1.26.06+git202606141309-0ppa202606152342~ubuntu24.04.1/M2/Macaulay2/d/main.cpp:128
 1# segv_handler at /usr/src/macaulay2-1.26.06+git202606141309-0ppa202606152342~ubuntu24.04.1/M2/Macaulay2/d/main.cpp:244
 2# 0x000079654F245330 in /lib/x86_64-linux-gnu/libc.so.6
 3# rawRoots at interface/polyroots.cpp:30
 4# interface_rawRoots at /usr/src/macaulay2-1.26.06+git202606141309-0ppa202606152342~ubuntu24.04.1/M2/Macaulay2/d/interface.dd:1517
 5# evaluate_evalraw at /usr/src/macaulay2-1.26.06+git202606141309-0ppa202606152342~ubuntu24.04.1/M2/Macaulay2/d/evaluate.d:1662
 6# evaluate_evalSequence at /usr/src/macaulay2-1.26.06+git202606141309-0ppa202606152342~ubuntu24.04.1/M2/Macaulay2/d/evaluate.d:457
...

After

i1 : R = QQ[x];

i2 : roots((x - 1)/x)

o2 = {1}

o2 : List

AI Disclosure

Claude helped with the C++ code

@d-torrance d-torrance added the Engine Macaulay2/e label Jun 17, 2026

@andrew-tawfeek andrew-tawfeek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two comments on this, after investigating how it touches other files:

  • In polyroots.cpp, could we move P->getMonoid() after the P == nullptr check? Non-polynomial inputs can still segfault before the error message.
  • In roots.m2, maybe its worth making this a tolerance-based check instead of an exact equality (referring to assert Equation(roots f_(frac R), Z)) between two numerical root lists to avoid possible ordering/rounding errors.

@d-torrance

Copy link
Copy Markdown
Member Author

Thanks for the review! I believe I've addressed both comments:

  • The check that P is nonull has been added in a new commit since it's not directly related to the other commit.
  • I amended the original commit updating the test file with the recommended changes.

@d-torrance d-torrance requested a review from andrew-tawfeek July 9, 2026 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Engine Macaulay2/e

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants