mirror of
https://github.com/Z3Prover/z3
synced 2025-06-19 12:23:38 +00:00
fix labels bug in duality
This commit is contained in:
parent
b27abc501e
commit
ee4b9d46f1
4 changed files with 74 additions and 7 deletions
|
@ -676,7 +676,7 @@ namespace Duality {
|
||||||
|
|
||||||
void GetLabels(Edge *e, std::vector<symbol> &labels);
|
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:
|
private:
|
||||||
|
|
||||||
|
@ -767,6 +767,8 @@ namespace Duality {
|
||||||
|
|
||||||
Term ModelValueAsConstraint(const Term &t);
|
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. */
|
/** RPFP solver base class. */
|
||||||
|
|
|
@ -809,6 +809,13 @@ namespace Duality {
|
||||||
goto done;
|
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);
|
expr bv = dualModel.eval(f);
|
||||||
if(bv.is_app() && bv.decl().get_decl_kind() == Equal &&
|
if(bv.is_app() && bv.decl().get_decl_kind() == Equal &&
|
||||||
|
@ -843,6 +850,7 @@ namespace Duality {
|
||||||
ands and, or, not. Returns result in memo.
|
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){
|
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()){
|
if(memo[labpos].find(f) != memo[labpos].end()){
|
||||||
return memo[labpos][f];
|
return memo[labpos][f];
|
||||||
|
@ -918,13 +926,72 @@ namespace Duality {
|
||||||
memo[labpos][f] = res;
|
memo[labpos][f] = res;
|
||||||
return 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){
|
void RPFP::GetLabels(Edge *e, std::vector<symbol> &labels){
|
||||||
if(!e->map || e->map->labeled.null())
|
if(!e->map || e->map->labeled.null())
|
||||||
return;
|
return;
|
||||||
Term tl = Localize(e, e->map->labeled);
|
Term tl = Localize(e, e->map->labeled);
|
||||||
hash_map<ast,int> memo[2];
|
hash_map<ast,int> memo;
|
||||||
GetLabelsRec(memo,tl,labels,true);
|
hash_set<ast> done[2];
|
||||||
|
GetLabelsRec(memo,tl,labels,done,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef Z3OPS
|
#ifdef Z3OPS
|
||||||
|
|
|
@ -30,9 +30,6 @@ Revision History:
|
||||||
namespace Duality {
|
namespace Duality {
|
||||||
|
|
||||||
solver::solver(Duality::context& c) : object(c), the_model(c) {
|
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;
|
params_ref p;
|
||||||
p.set_bool("proof", true); // this is currently useless
|
p.set_bool("proof", true); // this is currently useless
|
||||||
p.set_bool("model", true);
|
p.set_bool("model", true);
|
||||||
|
|
|
@ -118,6 +118,7 @@ void dl_interface::check_reset() {
|
||||||
|
|
||||||
|
|
||||||
lbool dl_interface::query(::expr * query) {
|
lbool dl_interface::query(::expr * query) {
|
||||||
|
|
||||||
// TODO: you can only call this once!
|
// TODO: you can only call this once!
|
||||||
// we restore the initial state in the datalog context
|
// we restore the initial state in the datalog context
|
||||||
m_ctx.ensure_opened();
|
m_ctx.ensure_opened();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue