Skip to content

Keep the roots sorted in the Zp feasible set of a constraint - #121

Open
ahmed-irfan wants to merge 1 commit into
masterfrom
fix-zp-feasible-set-sorted
Open

ahmed-irfan wants to merge 1 commit into
masterfrom
fix-zp-feasible-set-sorted

Conversation

@ahmed-irfan

@ahmed-irfan ahmed-irfan commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Fixes the cause of SRI-CSL/yices2#700 (wrong sat on a small QF_FFA instance with field size 1019).

What changed

lp_polynomial_constraint_get_feasible_set_Zp (src/polynomial/polynomial.c) wrote the roots from lp_upolynomial_roots_find_Zp directly into result->elements. It did not sort them. feasibility_set_int.h says that the elements are "kept sorted and unique", and lp_feasibility_set_int_find uses binary search.

For a field of size less than 1000, the brute-force root finder returns the roots in ascending order. For a field of size 1000 or more, the Rabin root finder returns them in no fixed order. In the yices2 issue, the set for -y^3 + y^2 - 2y mod 1019 with != 0 held [0, -216, 217]. Thus contains(0) was false and pick_value returned 0, which the constraint excludes.

The function now collects the roots in a local array and builds the set with lp_feasibility_set_int_new_from_integer. That constructor normalizes, sorts and removes duplicates. Then the function destructs and frees the array. The degree-0 branches do not change.

Tests

New test case feasibility_set_int::constraint_Zp_roots in test/poly/test_feasible_int_set.cpp, over Z/1019:

  • -y^3 + y^2 - 2y with != 0 and = 0: the elements are strictly ascending, contains is correct for each root, and pick_value does not return a root.
  • y^2 + 1 (no roots): the = 0 set is empty and the != 0 set is full.

Verification

  • Without the fix, the new test case fails 5 assertions (order, contains, pick_value). With the fix, it passes.
  • ctest passes (16/16) on Debug and Release (Apple clang). Python make check: 329 pass, 0 fail.
  • An independent review built both versions with ASan and UBSan. It compared contains against direct evaluation for each field element, on 603 polynomials over fields from 13 to 7919. With the fix: 0 failures and no sanitizer report. Without the fix: 117 failures.
  • yices2 linked against this branch answers unsat on the issue input for fields 997, 1009, 1019, 1031 and 7919. Before the fix, it answered sat for 1019 and 7919.

The review also found two pre-existing leaks outside this change. lp_feasibility_set_int_destruct frees the element array but does not destruct the elements. The degree-0 returns in this function do not delete upoly. They are filed as #122.

🤖 Generated with Claude Code

lp_polynomial_constraint_get_feasible_set_Zp wrote the roots from
lp_upolynomial_roots_find_Zp directly into the set. For a field of size
1000 or more, the Rabin root finder returns the roots in no fixed order.
lp_feasibility_set_int_find uses binary search, so contains() and
pick_value() could accept a value that the constraint excludes. Yices
then gave a wrong sat answer (SRI-CSL/yices2#700).

Build the set with lp_feasibility_set_int_new_from_integer, which
normalizes, sorts and removes duplicates.
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.

1 participant