From: trevor_hansen Date: Fri, 3 Feb 2012 14:12:30 +0000 (+0000) Subject: Improvement. Use AIGs to find semantically equivalent but syntactically distinct... X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=6d07e23b18197c56798e55a4b55c6b594235d2f0;p=francis%2Fstp.git Improvement. Use AIGs to find semantically equivalent but syntactically distinct ASTNodes. git-svn-id: https://stp-fast-prover.svn.sourceforge.net/svnroot/stp-fast-prover/trunk/stp@1554 e59a4935-1847-0410-ae03-e826735625c1 --- diff --git a/src/STPManager/STP.cpp b/src/STPManager/STP.cpp index e14d99e..fabb50a 100644 --- a/src/STPManager/STP.cpp +++ b/src/STPManager/STP.cpp @@ -119,11 +119,20 @@ namespace BEEV { /* These nodes have equivalent AIG representations, so even though they have different * word level expressions they are identical semantically. So we pick one of the ASTnodes * and replace the others with it. - * TODO: Currently only for booleans, * TODO: Isn't applied transitively because it infinite loops. * TODO: I replace with the lower id node, sometimes though we replace with much more * difficult looking ASTNodes. */ +#if 0 + ASTNodeMap::iterator it = equivs.begin(); + while (it!=equivs.end()) + { + cerr << it->first.GetNodeNum() << " " << it->second.GetNodeNum() << endl; + cerr << it->first << endl; + cerr << it->second << endl; + it++; + } +#endif ASTNodeMap cache; simplified_solved_InputToSAT = SubstitutionMap::simple_replace(simplified_solved_InputToSAT, fromTo, cache,&nf); bm->ASTNodeStats(bb_message.c_str(), simplified_solved_InputToSAT); diff --git a/src/to-sat/BitBlaster.cpp b/src/to-sat/BitBlaster.cpp index c5cbd18..dc872e7 100644 --- a/src/to-sat/BitBlaster.cpp +++ b/src/to-sat/BitBlaster.cpp @@ -55,7 +55,41 @@ namespace BEEV const bool conjoin_to_top = true; + + template + class BBVecHasher + { + public: + size_t operator()(const vector& n) const + { + int hash =0; + for (int i=0; i < std::min(n.size(),(size_t)6); i++) + hash += n[i].GetNodeNum(); + return hash; + } + }; + + template + class BBVecEquals + { + public: + bool operator()(const vector& n0, const vector& n1) const + { + if (n0.size() != n1.size()) + return false; + + for (int i=0; i < n0.size(); i++) + { + if (!(n0[i] == n1[i])) + return false; + } + return true; + } + }; + + // Look through the maps to see what the bitblaster has discovered (if anything) is constant. +// then looks through for AIGS that are mapped to from different ASTNodes. template void BitBlaster::getConsts(const ASTNode& form, ASTNodeMap& fromTo, ASTNodeMap& equivs) @@ -130,7 +164,6 @@ namespace BEEV simp->UpdateSubstitutionMap(n, r); else fromTo.insert(make_pair(n, r)); - } if (form.GetSTPMgr()->UserFlags.isSet("bb-equiv","0")) @@ -167,8 +200,53 @@ namespace BEEV } } } + + typedef HASHMAP, ASTNode,BBVecHasher , BBVecEquals > M; + if (form.GetSTPMgr()->UserFlags.isSet("bb-equiv", "0")) + { + M lookup; + typename std::map >::iterator it; + for (it = BBTermMemo.begin(); it != BBTermMemo.end(); it++) + { + const ASTNode& n = it->first; + if (n.isConstant()) + continue; + + const vector& x = it->second; + + bool constNode = true; + for (int i = 0; i < (int) x.size(); i++) + { + if (x[i] != BBTrue && x[i] != BBFalse) + { + constNode = false; + break; + } + } + if (!constNode) + continue; + + if (lookup.find(x) == lookup.end()) + { + lookup.insert(make_pair(x, n)); + } + else + { + const ASTNode other = (lookup.find(x))->second; + std::pair p; + if (other.GetNodeNum() > n.GetNodeNum()) + p = make_pair(other, n); + else + p = make_pair(n, other); + + cerr << "EQUIV"; + equivs.insert(p); + } + } + } } + template void BitBlaster::commonCheck(const ASTNode& n)