3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-08-15 02:06:34 +00:00

seq_monadic: replace solve_and with incremental add()/check() API

Replace the batch solve_and(mems) with an incremental interface:
  void add(expr* term, expr* regex, u_dependency* d);
  lbool check();
add() stores each (term, regex, dependency) triple in
m_memberships (vector<tuple<expr_ref, expr_ref, u_dependency*>>); the
dependency is retained for future unsat-core tracking and may be nullptr.
check() decides the accumulated conjunction (the former solve_and body) and
consumes the memberships; an empty conjunction is sat. Update the unit tests
and benchmark to the add()/check() API.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 57b9b87e-950a-49ea-bbb3-ed585646a5a9
This commit is contained in:
Nikolaj Bjorner 2026-07-31 20:31:39 -07:00
parent 022a6505ae
commit 1e09b4e6ae
4 changed files with 57 additions and 39 deletions

View file

@ -420,9 +420,16 @@ lbool seq_monadic::decide_dnf(vector<disjunct> const& dnf) {
return any_undef ? l_undef : l_false;
}
lbool seq_monadic::solve_and(vector<std::pair<expr*, expr*>> const& mems) {
if (mems.empty())
return l_undef;
void seq_monadic::add(expr* term, expr* regex, u_dependency* d) {
m_memberships.push_back({ expr_ref(term, m), expr_ref(regex, m), d });
}
lbool seq_monadic::check() {
m_model.reset();
vector<std::tuple<expr_ref, expr_ref, u_dependency*>> memberships;
memberships.swap(m_memberships); // consume the asserted memberships
if (memberships.empty())
return l_true; // empty conjunction is vacuously true
m_pin.reset();
reset_cofactor_cache();
m_budget = 200000;
@ -434,16 +441,16 @@ lbool seq_monadic::solve_and(vector<std::pair<expr*, expr*>> const& mems) {
vector<disjunct> combined;
combined.push_back(disjunct()); // { true }
const unsigned DNF_CAP = 1u << 14;
for (auto const& tr : mems) {
for (auto const& [term, regex, d] : memberships) {
vector<disjunct> dnf_i;
if (!build_membership_dnf(tr.first, tr.second, dnf_i))
if (!build_membership_dnf(term, regex, dnf_i))
return l_undef;
vector<disjunct> next;
for (disjunct const& d : combined) {
for (disjunct const& cd : combined) {
for (disjunct const& e : dnf_i) {
if (next.size() > DNF_CAP || m_budget == 0) { m_giveup = true; return l_undef; }
--m_budget;
disjunct D(d);
disjunct D(cd);
for (auto const& c : e)
D.push_back(c);
next.push_back(D);