Skip to content

Fix sign-assignment bug in usolve's assign_sign_left + regression tests - #362

Merged
ederc merged 6 commits into
algebraic-solving:masterfrom
mohabsafey:bug-univariate
Sep 18, 2026
Merged

ederc merged 6 commits into
algebraic-solving:masterfrom
mohabsafey:bug-univariate

Conversation

@mohabsafey

Copy link
Copy Markdown
Contributor

Summary

  • Fixes an off-by-bound loop in assign_sign_left (src/usolve/usolve.c): the loop assigning
    signs to positive roots used nbpos directly as the upper bound instead of nbneg + nbpos,
    which could mis-assign or skip sign bits for positive roots and led to failures of several
    different kinds during real root isolation (Issue Bug in real root isolation #358 investigation).
  • Handles the case in refine_root_elim (src/msolve/msolve.c) where a bracket endpoint
    evaluates to exactly 0: the root is now marked exact instead of tripping the
    "BUG in get_values_at_bounds" guard.
  • Adds three regression tests exercising this real-root-isolation code path:
    • univariate-assign-left — a genuinely multivariate system (4 vars) whose rational
      univariate representation stresses assign_sign_left directly.
    • univariate-sgn — a coordinate (y4) that is a root extremely close to 0; checks the
      sign is still determined correctly.
    • issue-310-bivariate — bivariate variant of the Issue Bug in real root isolation #358 cubic (one exact rational
      root, two irrational roots very close together) paired with x=0, checking sign
      determination in the multivariate code path (Issue Segmentation fault with a simple example #310).

Test plan

  • make check passes for all three new tests (diff_univariate-assign-left.sh,
    diff_univariate-sgn.sh, diff_issue-310-bivariate.sh)
  • Verified each new test's expected output is deterministic across -L/-l/-t/--random-seed
    combinations at both -p 128 and -p 1024

🤖 Generated with Claude Code

mohabsafey and others added 5 commits September 17, 2026 15:17
there because I identified another bug)
Pairs the cubic-in-y from univariate-cubic-close-roots.ms (Issue algebraic-solving#358,
one exact rational root plus two irrational roots extremely close
together) with x=0, to check real root isolation determines the sign
of every coordinate correctly in the genuinely multivariate code path.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Multivariate system whose rational univariate representation
stresses usolve's real root isolation via assign_left, which was
fixed in a previous commit and led to several failures of different
kinds.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
One coordinate (y4) is a root extremely close to 0; msolve's real
root isolation should still determine its sign correctly.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Comment thread src/usolve/refine.c Outdated

#ifndef USOLVE
#define USOLVE
#include <stdio.h>

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.

Why do you need this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Stupid mistake from my side... I just removed it. Should affect nothing. Thanks for noticing it.

@ederc ederc 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.

Looks good to me, I just do not understand why you need to include stdio.h in usolve/refine.c (see my comment on this).

@ederc
ederc merged commit 98ef1d6 into algebraic-solving:master Sep 18, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants