mirror of
https://github.com/Z3Prover/z3
synced 2025-11-06 22:36:03 +00:00
Update theory_finite_set.cpp
This commit is contained in:
parent
4cd6c808ac
commit
a40e4f1cf3
1 changed files with 33 additions and 66 deletions
|
|
@ -41,32 +41,14 @@ namespace smt {
|
||||||
bool theory_finite_set::internalize_atom(app * atom, bool gate_ctx) {
|
bool theory_finite_set::internalize_atom(app * atom, bool gate_ctx) {
|
||||||
TRACE("finite_set", tout << "internalize_atom: " << mk_pp(atom, m) << "\n";);
|
TRACE("finite_set", tout << "internalize_atom: " << mk_pp(atom, m) << "\n";);
|
||||||
|
|
||||||
// Internalize all arguments first
|
itnernalize_term(atom);
|
||||||
for (expr* arg : *atom) {
|
|
||||||
ctx.internalize(arg, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create boolean variable for the atom
|
|
||||||
if (!ctx.b_internalized(atom)) {
|
|
||||||
bool_var bv = ctx.mk_bool_var(atom);
|
|
||||||
ctx.set_var_theory(bv, get_id());
|
|
||||||
ctx.mark_as_relevant(bv);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Track membership atoms (set.in)
|
// Track membership atoms (set.in)
|
||||||
if (u.is_in(atom)) {
|
expr* elem = nullptr, *set = nullptr;
|
||||||
m_membership_atoms.insert(atom);
|
if (u.is_in(atom, elem, set)) {
|
||||||
expr* elem = atom->get_arg(0);
|
// add elem to a list of elements if it not there already.
|
||||||
expr* set = atom->get_arg(1);
|
// ctx.trail().push(insert(m_elems, elem));
|
||||||
|
// ctx.trail().push(push_back_vector(m_elems));
|
||||||
// Map set to its elements
|
|
||||||
if (!m_set_to_elements.contains(set)) {
|
|
||||||
m_set_to_elements.insert(set, ptr_vector<expr>());
|
|
||||||
}
|
|
||||||
ptr_vector<expr>& elems = m_set_to_elements[set];
|
|
||||||
if (!elems.contains(elem)) {
|
|
||||||
elems.push_back(elem);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -76,23 +58,25 @@ namespace smt {
|
||||||
TRACE("finite_set", tout << "internalize_term: " << mk_pp(term, m) << "\n";);
|
TRACE("finite_set", tout << "internalize_term: " << mk_pp(term, m) << "\n";);
|
||||||
|
|
||||||
// Internalize all arguments first
|
// Internalize all arguments first
|
||||||
for (expr* arg : *term) {
|
for (expr* arg : *term)
|
||||||
ctx.internalize(arg, false);
|
ctx.internalize(arg, false);
|
||||||
|
|
||||||
|
// Create boolean variable for Boolean terms
|
||||||
|
if (m.is_bool(term) && !ctx.b_internalized(term)) {
|
||||||
|
bool_var bv = ctx.mk_bool_var(term);
|
||||||
|
ctx.set_var_theory(bv, get_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create enode for the term if needed
|
// Create enode for the term if needed
|
||||||
enode* e = nullptr;
|
enode* e = nullptr;
|
||||||
if (ctx.e_internalized(term)) {
|
if (ctx.e_internalized(term))
|
||||||
e = ctx.get_enode(term);
|
e = ctx.get_enode(term);
|
||||||
} else {
|
else
|
||||||
e = ctx.mk_enode(term, false, m.is_bool(term), true);
|
e = ctx.mk_enode(term, false, m.is_bool(term), true);
|
||||||
}
|
|
||||||
|
|
||||||
// Attach theory variable if this is a set
|
// Attach theory variable if this is a set
|
||||||
if (u.is_finite_set(term) && !is_attached_to_var(e)) {
|
if (!is_attached_to_var(e))
|
||||||
theory_var v = mk_var(e);
|
ctx.attach_th_var(e, this, mk_var(e));
|
||||||
ctx.attach_th_var(e, this, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -112,27 +96,17 @@ namespace smt {
|
||||||
final_check_status theory_finite_set::final_check_eh() {
|
final_check_status theory_finite_set::final_check_eh() {
|
||||||
TRACE("finite_set", tout << "final_check_eh\n";);
|
TRACE("finite_set", tout << "final_check_eh\n";);
|
||||||
|
|
||||||
// Instantiate axioms for all membership atoms
|
bool new_clause = false;
|
||||||
for (expr* atom : m_membership_atoms) {
|
#if 0
|
||||||
if (!u.is_in(atom))
|
for (auto elem : m_elements) {
|
||||||
continue;
|
// walk all parents of elem in congruence table.
|
||||||
|
// if a parent is of the form elem' in S u T, or similar.
|
||||||
app* in_app = to_app(atom);
|
// create clauses for elem = elem' => clause.
|
||||||
expr* elem = in_app->get_arg(0);
|
// if a new clause was added, return FC_CONTINUE
|
||||||
expr* set = in_app->get_arg(1);
|
|
||||||
|
|
||||||
// Get the root of the set in the congruence closure
|
|
||||||
enode* set_node = ctx.get_enode(set);
|
|
||||||
if (!set_node)
|
|
||||||
continue;
|
|
||||||
enode* set_root = set_node->get_root();
|
|
||||||
expr* root_expr = set_root->get_expr();
|
|
||||||
|
|
||||||
// Instantiate axioms based on the structure of the set
|
|
||||||
instantiate_axioms(elem, root_expr);
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return FC_DONE;
|
return new_clause ? FC_CONTINUE : FC_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void theory_finite_set::instantiate_axioms(expr* elem, expr* set) {
|
void theory_finite_set::instantiate_axioms(expr* elem, expr* set) {
|
||||||
|
|
@ -166,6 +140,7 @@ namespace smt {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Instantiate size axioms for singleton sets
|
// Instantiate size axioms for singleton sets
|
||||||
|
// TODO, such axioms don't belong here
|
||||||
if (u.is_singleton(set)) {
|
if (u.is_singleton(set)) {
|
||||||
m_axioms.size_singleton_axiom(set);
|
m_axioms.size_singleton_axiom(set);
|
||||||
}
|
}
|
||||||
|
|
@ -173,18 +148,12 @@ namespace smt {
|
||||||
|
|
||||||
void theory_finite_set::add_clause(expr_ref_vector const& clause) {
|
void theory_finite_set::add_clause(expr_ref_vector const& clause) {
|
||||||
TRACE("finite_set",
|
TRACE("finite_set",
|
||||||
tout << "add_clause: ";
|
tout << "add_clause: " << clause << "\n");
|
||||||
for (expr* e : clause) {
|
|
||||||
tout << mk_pp(e, m) << " ";
|
|
||||||
}
|
|
||||||
tout << "\n";
|
|
||||||
);
|
|
||||||
|
|
||||||
// Convert expressions to literals and assert the clause
|
// Convert expressions to literals and assert the clause
|
||||||
literal_vector lits;
|
literal_vector lits;
|
||||||
for (expr* e : clause) {
|
for (expr* e : clause) {
|
||||||
expr_ref lit_expr(e, m);
|
ctx.internalize(e, false);
|
||||||
ctx.internalize(lit_expr, false);
|
|
||||||
literal lit = ctx.get_literal(lit_expr);
|
literal lit = ctx.get_literal(lit_expr);
|
||||||
lits.push_back(lit);
|
lits.push_back(lit);
|
||||||
}
|
}
|
||||||
|
|
@ -201,8 +170,6 @@ namespace smt {
|
||||||
|
|
||||||
void theory_finite_set::display(std::ostream & out) const {
|
void theory_finite_set::display(std::ostream & out) const {
|
||||||
out << "theory_finite_set:\n";
|
out << "theory_finite_set:\n";
|
||||||
out << " membership_atoms: " << m_membership_atoms.size() << "\n";
|
|
||||||
out << " sets tracked: " << m_set_to_elements.size() << "\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void theory_finite_set::init_model(model_generator & mg) {
|
void theory_finite_set::init_model(model_generator & mg) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue