mirror of
https://github.com/Z3Prover/z3
synced 2025-06-06 06:03:23 +00:00
Move proof dot printing into iuc_proof
This commit is contained in:
parent
45500ff7d3
commit
07ad67ebad
4 changed files with 545 additions and 633 deletions
|
@ -1,9 +1,12 @@
|
||||||
|
#include <unordered_map>
|
||||||
|
#include "ast/ast_pp_dot.h"
|
||||||
|
|
||||||
#include "muz/spacer/spacer_iuc_proof.h"
|
#include "muz/spacer/spacer_iuc_proof.h"
|
||||||
#include "ast/for_each_expr.h"
|
#include "ast/for_each_expr.h"
|
||||||
#include "ast/array_decl_plugin.h"
|
#include "ast/array_decl_plugin.h"
|
||||||
#include "ast/proofs/proof_utils.h"
|
#include "ast/proofs/proof_utils.h"
|
||||||
#include "muz/spacer/spacer_proof_utils.h"
|
#include "muz/spacer/spacer_proof_utils.h"
|
||||||
|
#include "muz/spacer/spacer_util.h"
|
||||||
namespace spacer {
|
namespace spacer {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -191,4 +194,87 @@ void iuc_proof::dump_farkas_stats()
|
||||||
<< "\n total farkas lemmas " << fl_total
|
<< "\n total farkas lemmas " << fl_total
|
||||||
<< " farkas lemmas in lowest cut " << fl_lowcut << "\n";);
|
<< " farkas lemmas in lowest cut " << fl_lowcut << "\n";);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void iuc_proof::display_dot(std::ostream& out) {
|
||||||
|
out << "digraph proof { \n";
|
||||||
|
|
||||||
|
std::unordered_map<unsigned, unsigned> ids;
|
||||||
|
unsigned last_id = 0;
|
||||||
|
|
||||||
|
proof_post_order it(m_pr, m);
|
||||||
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
proof* curr = it.next();
|
||||||
|
|
||||||
|
SASSERT(ids.count(curr->get_id()) == 0);
|
||||||
|
ids.insert(std::make_pair(curr->get_id(), last_id));
|
||||||
|
|
||||||
|
std::string color = "white";
|
||||||
|
if (this->is_a_marked(curr) && !this->is_b_marked(curr))
|
||||||
|
color = "red";
|
||||||
|
else if(!this->is_a_marked(curr) && this->is_b_marked(curr))
|
||||||
|
color = "blue";
|
||||||
|
else if(this->is_a_marked(curr) && this->is_b_marked(curr) )
|
||||||
|
color = "purple";
|
||||||
|
|
||||||
|
// compute node label
|
||||||
|
std::ostringstream label_ostream;
|
||||||
|
label_ostream << mk_epp(m.get_fact(curr), m) << "\n";
|
||||||
|
std::string label = escape_dot(label_ostream.str());
|
||||||
|
|
||||||
|
// compute edge-label
|
||||||
|
std::string edge_label = "";
|
||||||
|
if (m.get_num_parents(curr) == 0) {
|
||||||
|
switch (curr->get_decl_kind())
|
||||||
|
{
|
||||||
|
case PR_ASSERTED:
|
||||||
|
edge_label = "asserted:";
|
||||||
|
break;
|
||||||
|
case PR_HYPOTHESIS:
|
||||||
|
edge_label = "hyp:";
|
||||||
|
color = "grey";
|
||||||
|
break;
|
||||||
|
case PR_TH_LEMMA:
|
||||||
|
if (is_farkas_lemma(m, curr))
|
||||||
|
edge_label = "th_axiom(farkas):";
|
||||||
|
else if (is_arith_lemma(m, curr))
|
||||||
|
edge_label = "th_axiom(arith):";
|
||||||
|
else
|
||||||
|
edge_label = "th_axiom:";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
edge_label = "unknown axiom:";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (curr->get_decl_kind() == PR_LEMMA)
|
||||||
|
edge_label = "lemma:";
|
||||||
|
else if (curr->get_decl_kind() == PR_TH_LEMMA) {
|
||||||
|
if (is_farkas_lemma(m, curr))
|
||||||
|
edge_label = "th_lemma(farkas):";
|
||||||
|
else if (is_arith_lemma(m, curr))
|
||||||
|
edge_label = "th_lemma(arith):";
|
||||||
|
else
|
||||||
|
edge_label = "th_lemma(other):";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// generate entry for node in dot-file
|
||||||
|
out << "node_" << last_id << " " << "["
|
||||||
|
<< "shape=box,style=\"filled\","
|
||||||
|
<< "label=\"" << edge_label << " " << label << "\", "
|
||||||
|
<< "fillcolor=\"" << color << "\"" << "]\n";
|
||||||
|
|
||||||
|
// add entry for each edge to that node
|
||||||
|
for (unsigned i = m.get_num_parents(curr); i > 0 ; --i)
|
||||||
|
{
|
||||||
|
proof* premise = to_app(curr->get_arg(i-1));
|
||||||
|
unsigned pid = ids.at(premise->get_id());
|
||||||
|
out << "node_" << pid << " -> " << "node_" << last_id << ";\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
++last_id;
|
||||||
|
}
|
||||||
|
out << "\n}" << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef IUC_PROOF_H_
|
#ifndef IUC_PROOF_H_
|
||||||
#define IUC_PROOF_H_
|
#define IUC_PROOF_H_
|
||||||
|
|
||||||
|
#include <ostream>
|
||||||
#include "ast/ast.h"
|
#include "ast/ast.h"
|
||||||
|
|
||||||
namespace spacer {
|
namespace spacer {
|
||||||
|
@ -35,6 +36,7 @@ public:
|
||||||
return !is_h_marked (p) && is_core_pure(m.get_fact (p));
|
return !is_h_marked (p) && is_core_pure(m.get_fact (p));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void display_dot(std::ostream &out);
|
||||||
// debug method
|
// debug method
|
||||||
void dump_farkas_stats();
|
void dump_farkas_stats();
|
||||||
private:
|
private:
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -22,67 +22,74 @@ Revision History:
|
||||||
|
|
||||||
namespace spacer {
|
namespace spacer {
|
||||||
|
|
||||||
bool is_arith_lemma(ast_manager& m, proof* pr);
|
bool is_arith_lemma(ast_manager& m, proof* pr);
|
||||||
bool is_farkas_lemma(ast_manager& m, proof* pr);
|
bool is_farkas_lemma(ast_manager& m, proof* pr);
|
||||||
|
|
||||||
/*
|
class theory_axiom_reducer {
|
||||||
* prints the proof pr in dot representation to the file proof.dot
|
public:
|
||||||
* if iuc_pr is not nullptr, then it is queried for coloring partitions
|
theory_axiom_reducer(ast_manager& m) : m(m), m_pinned(m) {}
|
||||||
*/
|
|
||||||
class iuc_proof;
|
|
||||||
void pp_proof_dot(ast_manager& m, proof* pr, iuc_proof* iuc_pr = nullptr);
|
|
||||||
|
|
||||||
class theory_axiom_reducer
|
// reduce theory axioms and return transformed proof
|
||||||
{
|
proof_ref reduce(proof* pr);
|
||||||
public:
|
|
||||||
theory_axiom_reducer(ast_manager& m) : m(m), m_pinned(m) {}
|
|
||||||
|
|
||||||
// reduce theory axioms and return transformed proof
|
private:
|
||||||
proof_ref reduce(proof* pr);
|
ast_manager &m;
|
||||||
|
|
||||||
private:
|
// tracking all created expressions
|
||||||
ast_manager &m;
|
expr_ref_vector m_pinned;
|
||||||
|
|
||||||
// tracking all created expressions
|
// maps each proof of a clause to the transformed subproof of
|
||||||
expr_ref_vector m_pinned;
|
// that clause
|
||||||
|
obj_map<proof, proof*> m_cache;
|
||||||
|
|
||||||
// maps each proof of a clause to the transformed subproof of that clause
|
void reset();
|
||||||
obj_map<proof, proof*> m_cache;
|
};
|
||||||
|
|
||||||
void reset();
|
class hypothesis_reducer
|
||||||
};
|
{
|
||||||
|
public:
|
||||||
|
hypothesis_reducer(ast_manager &m) : m(m), m_pinned(m) {}
|
||||||
|
|
||||||
class hypothesis_reducer
|
// reduce hypothesis and return transformed proof
|
||||||
{
|
proof_ref reduce(proof* pf);
|
||||||
public:
|
|
||||||
hypothesis_reducer(ast_manager &m) : m(m), m_pinned(m) {}
|
|
||||||
|
|
||||||
// reduce hypothesis and return transformed proof
|
private:
|
||||||
proof_ref reduce(proof* pf);
|
typedef obj_hashtable<expr> expr_set;
|
||||||
|
typedef obj_hashtable<proof> proof_set;
|
||||||
|
|
||||||
private:
|
ast_manager &m;
|
||||||
typedef obj_hashtable<expr> expr_set;
|
|
||||||
typedef obj_hashtable<proof> proof_set;
|
|
||||||
|
|
||||||
ast_manager &m;
|
// created expressions
|
||||||
|
expr_ref_vector m_pinned;
|
||||||
|
|
||||||
expr_ref_vector m_pinned; // tracking all created expressions
|
// created sets of active hypothesis
|
||||||
ptr_vector<proof_set> m_pinned_active_hyps; // tracking all created sets of active hypothesis
|
ptr_vector<proof_set> m_pinned_active_hyps;
|
||||||
ptr_vector<expr_set> m_pinned_parent_hyps; // tracking all created sets of parent hypothesis
|
// created sets of parent hypothesis
|
||||||
|
ptr_vector<expr_set> m_pinned_parent_hyps;
|
||||||
|
|
||||||
obj_map<proof, proof*> m_cache; // maps each proof of a clause to the transformed subproof of that clause
|
// maps a proof to the transformed proof
|
||||||
obj_map<expr, proof*> m_units; // maps each unit literal to the subproof of that unit
|
obj_map<proof, proof*> m_cache;
|
||||||
obj_map<proof, proof_set*> m_active_hyps; // maps each proof of a clause to the set of proofs of active hypothesis' of the clause
|
|
||||||
obj_map<proof, expr_set*> m_parent_hyps; // maps each proof of a clause to the hypothesis-fact, which are transitive parents of that clause, needed to avoid creating cycles in the proof.
|
|
||||||
|
|
||||||
void reset();
|
// maps a unit literal to its derivation
|
||||||
void compute_hypsets(proof* pr); // compute active_hyps and parent_hyps for pr
|
obj_map<expr, proof*> m_units;
|
||||||
void collect_units(proof* pr); // compute m_units
|
|
||||||
proof* compute_transformed_proof(proof* pf);
|
|
||||||
|
|
||||||
proof* mk_lemma_core(proof *pf, expr *fact);
|
// maps a proof to the set of proofs of active hypotheses
|
||||||
proof* mk_unit_resolution_core(ptr_buffer<proof>& args);
|
obj_map<proof, proof_set*> m_active_hyps;
|
||||||
proof* mk_step_core(proof* old_step, ptr_buffer<proof>& args);
|
// maps a proof to the hypothesis-fact that are transitive
|
||||||
};
|
// parents of that proof. Used for cycle detection and avoidance.
|
||||||
|
obj_map<proof, expr_set*> m_parent_hyps;
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
// compute active_hyps and parent_hyps for pr
|
||||||
|
void compute_hypsets(proof* pr);
|
||||||
|
// compute m_units
|
||||||
|
void collect_units(proof* pr);
|
||||||
|
proof* compute_transformed_proof(proof* pf);
|
||||||
|
|
||||||
|
proof* mk_lemma_core(proof *pf, expr *fact);
|
||||||
|
proof* mk_unit_resolution_core(ptr_buffer<proof>& args);
|
||||||
|
proof* mk_step_core(proof* old_step, ptr_buffer<proof>& args);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue