3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-07-16 03:55:42 +00:00
z3/src/nlsat
Lev Nachmanson 2490e86d3f
nlsat/anum: share mutation-aware merge sort in one helper (#10006)
## Summary

Follow-up to #10001 addressing @NikolajBjorner's review comment:

> isn't this nearly identical AI generated code to the other file? There
has to be some modular approach to deal with sorting vectors?

#10001 introduced two nearly-identical copies of a bounds-safe,
mutation-aware index-permutation merge sort:
- `algebraic_numbers.cpp::merge_sort_roots_perm`
- `nlsat/levelwise.cpp::merge_sort_perm`

Both exist because the comparator (`anum_manager::compare`/`lt`) is
**not pure**: it mutates the algebraic numbers it compares (refining
isolating intervals) and may throw on the resource limit, which makes
`std::sort` undefined behavior (the original SIGSEGV).

## Change

Extract the algorithm into a single shared helper
`util/index_sort_with_mutations.h` (`stable_index_merge_sort`). The long
rationale for why `std::sort` is unsafe and merge sort is safe now lives
in exactly one place. Both call sites become thin wrappers that build
the scratch buffer and forward their local comparator.

No behavioral change: same stable O(n log n) merge sort over an index
permutation.

## Verification

CMake/Ninja Release build:
- `test-z3 /seq algebraic_numbers` — PASS
- `test-z3 /seq algebraic` — PASS
- NRA/NIA smoke solves with `nlsat.lws=true` return expected sat/unsat.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-30 08:40:33 -07:00
..
tactic making try-for tactic exception resilient on cancelation 2026-04-26 15:58:24 -07:00
CMakeLists.txt Merge with branch lws (#8498) 2026-02-04 09:52:02 -08:00
levelwise.cpp nlsat/anum: share mutation-aware merge sort in one helper (#10006) 2026-06-30 08:40:33 -07:00
levelwise.h Nl2lin - integrate a linear under approximation of a CAD cell by Valentin Promies. (#8982) 2026-03-15 06:13:04 -10:00
nlsat_assignment.h Use noexcept more. (#7058) 2023-12-16 12:14:53 +00:00
nlsat_clause.cpp Standardize for-loop increments to prefix form (++i) (#8199) 2026-01-14 19:55:31 -08:00
nlsat_clause.h deal with warnings 2025-07-02 10:59:56 -07:00
nlsat_common.cpp add new polynomials from handle_nullified to m_todo 2026-02-18 10:54:39 -10:00
nlsat_common.h remove dead code in nlsat_explain 2026-03-19 12:02:21 -10:00
nlsat_evaluator.cpp Standardize for-loop increments to prefix form (++i) (#8199) 2026-01-14 19:55:31 -08:00
nlsat_evaluator.h fix build 2024-01-24 08:52:56 -08:00
nlsat_explain.cpp remove dead code in nlsat_explain 2026-03-19 12:02:21 -10:00
nlsat_explain.h remove dead code in nlsat_explain 2026-03-19 12:02:21 -10:00
nlsat_interval_set.cpp fix build warnings 2026-06-22 18:20:23 -07:00
nlsat_interval_set.h Merge with branch lws (#8498) 2026-02-04 09:52:02 -08:00
nlsat_justification.h booyah 2020-07-04 15:56:30 -07:00
nlsat_params.pyg change the default of param lws_subs_witness_disc to true 2026-02-24 15:24:35 -10:00
nlsat_scoped_literal_vector.h Remove copies (#8583) 2026-02-11 18:14:36 +00:00
nlsat_simple_checker.cpp Centralize and document TRACE tags using X-macros (#7657) 2025-05-28 14:31:25 +01:00
nlsat_simple_checker.h use standard name conventions and add file headers 2024-08-12 08:29:06 -10:00
nlsat_simplify.cpp use usize to suppress the data loss warnings 2025-07-02 14:42:55 -07:00
nlsat_simplify.h Nlsat simplify (#7227) 2024-05-14 22:19:33 -07:00
nlsat_solver.cpp revert clear() additions that cause heap corruption 2026-03-30 04:57:08 -10:00
nlsat_solver.h Nl2lin - integrate a linear under approximation of a CAD cell by Valentin Promies. (#8982) 2026-03-15 06:13:04 -10:00
nlsat_types.cpp Standardize for-loop increments to prefix form (++i) (#8199) 2026-01-14 19:55:31 -08:00
nlsat_types.h Merge with branch lws (#8498) 2026-02-04 09:52:02 -08:00
nlsat_variable_ordering_strategy.cpp Standardize for-loop increments to prefix form (++i) (#8199) 2026-01-14 19:55:31 -08:00
nlsat_variable_ordering_strategy.h use standard name conventions and add file headers 2024-08-12 08:29:06 -10:00