3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-15 05:18:44 +00:00

fix labels bug in duality

This commit is contained in:
Ken McMillan 2013-05-27 19:22:47 -07:00
parent b27abc501e
commit ee4b9d46f1
4 changed files with 74 additions and 7 deletions

View file

@ -676,7 +676,7 @@ namespace Duality {
void GetLabels(Edge *e, std::vector<symbol> &labels);
int GetLabelsRec(hash_map<ast,int> *memo, const Term &f, std::vector<symbol> &labels, bool labpos);
// int GetLabelsRec(hash_map<ast,int> *memo, const Term &f, std::vector<symbol> &labels, bool labpos);
private:
@ -767,6 +767,8 @@ namespace Duality {
Term ModelValueAsConstraint(const Term &t);
void GetLabelsRec(hash_map<ast,int> &memo, const Term &f, std::vector<symbol> &labels,
hash_set<ast> *done, bool truth);
};
/** RPFP solver base class. */

View file

@ -809,6 +809,13 @@ namespace Duality {
goto done;
}
}
{
bool pos; std::vector<symbol> names;
if(f.is_label(pos,names)){
res = SubtermTruth(memo,f.arg(0));
goto done;
}
}
{
expr bv = dualModel.eval(f);
if(bv.is_app() && bv.decl().get_decl_kind() == Equal &&
@ -843,6 +850,7 @@ namespace Duality {
ands and, or, not. Returns result in memo.
*/
#if 0
int RPFP::GetLabelsRec(hash_map<ast,int> *memo, const Term &f, std::vector<symbol> &labels, bool labpos){
if(memo[labpos].find(f) != memo[labpos].end()){
return memo[labpos][f];
@ -918,13 +926,72 @@ namespace Duality {
memo[labpos][f] = res;
return res;
}
#endif
void RPFP::GetLabelsRec(hash_map<ast,int> &memo, const Term &f, std::vector<symbol> &labels,
hash_set<ast> *done, bool truth){
if(done[truth].find(f) != done[truth].end())
return; /* already processed */
if(f.is_app()){
int nargs = f.num_args();
decl_kind k = f.decl().get_decl_kind();
if(k == Implies){
GetLabelsRec(memo,f.arg(1) || !f.arg(0) ,labels,done,truth);
goto done;
}
if(k == Iff){
int b = SubtermTruth(memo,f.arg(0));
if(b == 2)
throw "disaster in GetLabelsRec";
GetLabelsRec(memo,f.arg(1),labels,done,truth ? b : !b);
goto done;
}
if(truth ? k == And : k == Or) {
for(int i = 0; i < nargs; i++)
GetLabelsRec(memo,f.arg(i),labels,done,truth);
goto done;
}
if(truth ? k == Or : k == And) {
for(int i = 0; i < nargs; i++){
Term a = f.arg(i);
timer_start("SubtermTruth");
int b = SubtermTruth(memo,a);
timer_stop("SubtermTruth");
if(truth ? (b == 1) : (b == 0)){
GetLabelsRec(memo,a,labels,done,truth);
goto done;
}
}
/* Unreachable! */
throw "error in RPFP::GetLabelsRec";
goto done;
}
else if(k == Not) {
GetLabelsRec(memo,f.arg(0),labels,done,!truth);
goto done;
}
else {
bool pos; std::vector<symbol> names;
if(f.is_label(pos,names)){
GetLabelsRec(memo,f.arg(0), labels, done, truth);
if(pos == truth)
for(unsigned i = 0; i < names.size(); i++)
labels.push_back(names[i]);
goto done;
}
}
}
done:
done[truth].insert(f);
}
void RPFP::GetLabels(Edge *e, std::vector<symbol> &labels){
if(!e->map || e->map->labeled.null())
return;
Term tl = Localize(e, e->map->labeled);
hash_map<ast,int> memo[2];
GetLabelsRec(memo,tl,labels,true);
hash_map<ast,int> memo;
hash_set<ast> done[2];
GetLabelsRec(memo,tl,labels,done,true);
}
#ifdef Z3OPS

View file

@ -30,9 +30,6 @@ Revision History:
namespace Duality {
solver::solver(Duality::context& c) : object(c), the_model(c) {
// TODO: the following is a HACK to enable proofs in the old smt solver
// When we stop using that solver, this hack can be removed
m().toggle_proof_mode(PGM_FINE);
params_ref p;
p.set_bool("proof", true); // this is currently useless
p.set_bool("model", true);

View file

@ -117,7 +117,8 @@ void dl_interface::check_reset() {
#endif
lbool dl_interface::query(::expr * query) {
lbool dl_interface::query(::expr * query) {
// TODO: you can only call this once!
// we restore the initial state in the datalog context
m_ctx.ensure_opened();