mirror of
https://github.com/Z3Prover/z3
synced 2025-05-11 09:44:43 +00:00
parent
e026f96ed4
commit
503bedbc7a
3 changed files with 99 additions and 84 deletions
|
@ -109,15 +109,14 @@ namespace smt {
|
|||
\brief Ensures that all relevant proof steps to explain why the enode is equal to the root of its
|
||||
equivalence class are in the log and up-to-date.
|
||||
*/
|
||||
void log_justification_to_root(std::ostream & log, enode *en, obj_hashtable<enode> &already_visited) {
|
||||
void log_justification_to_root(std::ostream & out, enode *en, obj_hashtable<enode> &visited) {
|
||||
enode* root = en->get_root();
|
||||
for (enode *it = en; it != root; it = it->get_trans_justification().m_target) {
|
||||
if (already_visited.contains(it))
|
||||
break;
|
||||
already_visited.insert(it);
|
||||
for (enode *it = en; it != root && !visited.contains(it); it = it->get_trans_justification().m_target) {
|
||||
|
||||
visited.insert(it);
|
||||
|
||||
if (!it->m_proof_is_logged) {
|
||||
log_single_justification(log, it, already_visited);
|
||||
log_single_justification(out, it, visited);
|
||||
it->m_proof_is_logged = true;
|
||||
}
|
||||
else if (it->get_trans_justification().m_justification.get_kind() == smt::eq_justification::kind::CONGRUENCE) {
|
||||
|
@ -128,14 +127,14 @@ namespace smt {
|
|||
enode *target = it->get_trans_justification().m_target;
|
||||
|
||||
for (unsigned i = 0; i < num_args; ++i) {
|
||||
log_justification_to_root(log, it->get_arg(i), already_visited);
|
||||
log_justification_to_root(log, target->get_arg(i), already_visited);
|
||||
log_justification_to_root(out, it->get_arg(i), visited);
|
||||
log_justification_to_root(out, target->get_arg(i), visited);
|
||||
}
|
||||
SASSERT(it->m_proof_is_logged);
|
||||
}
|
||||
}
|
||||
if (!root->m_proof_is_logged) {
|
||||
log << "[eq-expl] #" << root->get_owner_id() << " root\n";
|
||||
out << "[eq-expl] #" << root->get_owner_id() << " root\n";
|
||||
root->m_proof_is_logged = true;
|
||||
}
|
||||
}
|
||||
|
@ -144,7 +143,7 @@ namespace smt {
|
|||
\brief Logs a single equality explanation step and, if necessary, recursively calls log_justification_to_root to log
|
||||
equalities needed by the step (e.g. argument equalities for congruence steps).
|
||||
*/
|
||||
void log_single_justification(std::ostream & out, enode *en, obj_hashtable<enode> &already_visited) {
|
||||
void log_single_justification(std::ostream & out, enode *en, obj_hashtable<enode> &visited) {
|
||||
smt::literal lit;
|
||||
unsigned num_args;
|
||||
enode *target = en->get_trans_justification().m_target;
|
||||
|
@ -163,8 +162,8 @@ namespace smt {
|
|||
num_args = en->get_num_args();
|
||||
|
||||
for (unsigned i = 0; i < num_args; ++i) {
|
||||
log_justification_to_root(out, en->get_arg(i), already_visited);
|
||||
log_justification_to_root(out, target->get_arg(i), already_visited);
|
||||
log_justification_to_root(out, en->get_arg(i), visited);
|
||||
log_justification_to_root(out, target->get_arg(i), visited);
|
||||
}
|
||||
|
||||
out << "[eq-expl] #" << en->get_owner_id() << " cg";
|
||||
|
@ -193,6 +192,53 @@ namespace smt {
|
|||
}
|
||||
}
|
||||
|
||||
void log_add_instance(
|
||||
fingerprint* f,
|
||||
quantifier * q, app * pat,
|
||||
unsigned num_bindings,
|
||||
enode * const * bindings,
|
||||
vector<std::tuple<enode *, enode *>> & used_enodes) {
|
||||
|
||||
std::ostream & out = trace_stream();
|
||||
|
||||
obj_hashtable<enode> visited;
|
||||
|
||||
// In the term produced by the quantifier instantiation the root of
|
||||
// the equivalence class of the terms bound to the quantified variables
|
||||
// is used. We need to make sure that all of these equalities appear in the log.
|
||||
for (unsigned i = 0; i < num_bindings; ++i) {
|
||||
log_justification_to_root(out, bindings[i], visited);
|
||||
}
|
||||
|
||||
for (auto n : used_enodes) {
|
||||
enode *orig = std::get<0>(n);
|
||||
enode *substituted = std::get<1>(n);
|
||||
if (orig != nullptr) {
|
||||
log_justification_to_root(out, orig, visited);
|
||||
log_justification_to_root(out, substituted, visited);
|
||||
}
|
||||
}
|
||||
|
||||
// At this point all relevant equalities for the match are logged.
|
||||
out << "[new-match] " << static_cast<void*>(f) << " #" << q->get_id() << " #" << pat->get_id();
|
||||
for (unsigned i = 0; i < num_bindings; i++) {
|
||||
// I don't want to use mk_pp because it creates expressions for pretty printing.
|
||||
// This nasty side-effect may change the behavior of Z3.
|
||||
out << " #" << bindings[i]->get_owner_id();
|
||||
}
|
||||
out << " ;";
|
||||
for (auto n : used_enodes) {
|
||||
enode *orig = std::get<0>(n);
|
||||
enode *substituted = std::get<1>(n);
|
||||
if (orig == nullptr)
|
||||
out << " #" << substituted->get_owner_id();
|
||||
else {
|
||||
out << " (#" << orig->get_owner_id() << " #" << substituted->get_owner_id() << ")";
|
||||
}
|
||||
}
|
||||
out << "\n";
|
||||
}
|
||||
|
||||
bool add_instance(quantifier * q, app * pat,
|
||||
unsigned num_bindings,
|
||||
enode * const * bindings,
|
||||
|
@ -209,43 +255,7 @@ namespace smt {
|
|||
fingerprint * f = m_context.add_fingerprint(q, q->get_id(), num_bindings, bindings, def);
|
||||
if (f) {
|
||||
if (has_trace_stream()) {
|
||||
std::ostream & out = trace_stream();
|
||||
|
||||
obj_hashtable<enode> already_visited;
|
||||
|
||||
// In the term produced by the quantifier instantiation the root of the equivalence class of the terms bound to the quantified variables
|
||||
// is used. We need to make sure that all of these equalities appear in the log.
|
||||
for (unsigned i = 0; i < num_bindings; ++i) {
|
||||
log_justification_to_root(out, bindings[i], already_visited);
|
||||
}
|
||||
|
||||
for (auto n : used_enodes) {
|
||||
enode *orig = std::get<0>(n);
|
||||
enode *substituted = std::get<1>(n);
|
||||
if (orig != nullptr) {
|
||||
log_justification_to_root(out, orig, already_visited);
|
||||
log_justification_to_root(out, substituted, already_visited);
|
||||
}
|
||||
}
|
||||
|
||||
// At this point all relevant equalities for the match are logged.
|
||||
out << "[new-match] " << static_cast<void*>(f) << " #" << q->get_id() << " #" << pat->get_id();
|
||||
for (unsigned i = 0; i < num_bindings; i++) {
|
||||
// I don't want to use mk_pp because it creates expressions for pretty printing.
|
||||
// This nasty side-effect may change the behavior of Z3.
|
||||
out << " #" << bindings[i]->get_owner_id();
|
||||
}
|
||||
out << " ;";
|
||||
for (auto n : used_enodes) {
|
||||
enode *orig = std::get<0>(n);
|
||||
enode *substituted = std::get<1>(n);
|
||||
if (orig == nullptr)
|
||||
out << " #" << substituted->get_owner_id();
|
||||
else {
|
||||
out << " (#" << orig->get_owner_id() << " #" << substituted->get_owner_id() << ")";
|
||||
}
|
||||
}
|
||||
out << "\n";
|
||||
log_add_instance(f, q, pat, num_bindings, bindings, used_enodes);
|
||||
}
|
||||
m_qi_queue.insert(f, pat, max_generation, min_top_generation, max_top_generation); // TODO
|
||||
m_num_instances++;
|
||||
|
@ -256,7 +266,7 @@ namespace smt {
|
|||
tout << mk_pp(bindings[i]->get_owner(), m()) << " ";
|
||||
}
|
||||
tout << "\n";
|
||||
tout << "inserted: " << (f != 0) << "\n";
|
||||
tout << "inserted: " << (f != nullptr) << "\n";
|
||||
);
|
||||
|
||||
return f != nullptr;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue