void cvc_propt::lcnf(const bvt &bv) { if(bv.empty()) return; bvt new_bv; std::set<literalt> s; new_bv.reserve(bv.size()); for(bvt::const_iterator it=bv.begin(); it!=bv.end(); it++) { if(s.insert(*it).second) new_bv.push_back(*it); if(s.find(lnot(*it))!=s.end()) return; // clause satisfied assert(it->var_no()<_no_variables); } assert(!new_bv.empty()); out << "%% lcnf" << std::endl; out << "ASSERT "; for(bvt::const_iterator it=new_bv.begin(); it!=new_bv.end(); it++) { if(it!=new_bv.begin()) out << " OR "; out << cvc_literal(*it); } out << ";" << std::endl << std::endl; }
bvt float_utilst::abs(const bvt &src) { bvt result=src; assert(!src.empty()); result[result.size()-1]=const_literal(false); return result; }
void dplib_propt::lcnf(const bvt &bv) { if(bv.empty()) return; bvt new_bv; std::set<literalt> s; new_bv.reserve(bv.size()); for(bvt::const_iterator it=bv.begin(); it!=bv.end(); it++) { if(s.insert(*it).second) new_bv.push_back(*it); if(s.find(!*it)!=s.end()) return; // clause satisfied assert(it->var_no()<=_no_variables); } assert(!new_bv.empty()); out << "// lcnf\n"; out << "AXIOM "; for(bvt::const_iterator it=new_bv.begin(); it!=new_bv.end(); it++) { if(it!=new_bv.begin()) out << " | "; out << dplib_literal(*it); } out << ";\n\n"; }
literalt bv_utilst::is_one(const bvt &bv) { assert(!bv.empty()); bvt tmp; tmp=bv; tmp.erase(tmp.begin(), tmp.begin()+1); return prop.land(is_zero(tmp), bv[0]); }
literalt float_utilst::is_zero(const bvt &src) { assert(!src.empty()); bvt all_but_sign; all_but_sign=src; all_but_sign.resize(all_but_sign.size()-1); return bv_utils.is_zero(all_but_sign); }
bvt float_utilst::negate(const bvt &src) { bvt result=src; assert(!src.empty()); literalt &sign_bit=result[result.size()-1]; sign_bit=!sign_bit; return result; }
literalt cvc_propt::lxor(const bvt &bv) { if(bv.empty()) return const_literal(false); if(bv.size()==1) return bv[0]; if(bv.size()==2) return lxor(bv[0], bv[1]); literalt literal=const_literal(false); forall_literals(it, bv) literal=lxor(*it, literal); return literal; }
literalt smt1_propt::lxor(const bvt &bv) { if(bv.empty()) return const_literal(false); if(bv.size()==1) return bv[0]; out << "\n"; literalt l=new_variable(); out << ":assumption ; lxor" << "\n"; out << " (iff " << smt1_literal(l) << " (xor"; forall_literals(it, bv) out << " " << smt1_literal(*it); out << "))" << "\n"; return l; }
bvt bv_utilst::extension( const bvt &bv, std::size_t new_size, representationt rep) { std::size_t old_size=bv.size(); bvt result=bv; result.resize(new_size); assert(old_size!=0); literalt extend_with= (rep==SIGNED && !bv.empty())?bv[old_size-1]: const_literal(false); for(std::size_t i=old_size; i<new_size; i++) result[i]=extend_with; return result; }
bool z3_propt::process_clause(const bvt &bv, bvt &dest) { dest.clear(); // empty clause! this is UNSAT if(bv.empty()) return false; std::set<literalt> s; dest.reserve(bv.size()); for(bvt::const_iterator it=bv.begin(); it!=bv.end(); it++) { literalt l=*it; // we never use index 0 assert(l.var_no()!=0); if(l.is_true()) return true; // clause satisfied if(l.is_false()) continue; if(l.var_no()>=_no_variables) std::cout << "l.var_no()=" << l.var_no() << " _no_variables=" << _no_variables << std::endl; assert(l.var_no()<_no_variables); // prevent duplicate literals if(s.insert(l).second) dest.push_back(l); if(s.find(lnot(l))!=s.end()) return true; // clause satisfied } return false; }
void smt1_propt::lcnf(const bvt &bv) { out << std::endl; out << ":assumption ; lcnf" << std::endl; out << " "; if(bv.empty()) out << "false ; the empty clause"; else if(bv.size()==1) out << smt1_literal(bv.front()); else { out << "(or"; for(bvt::const_iterator it=bv.begin(); it!=bv.end(); it++) out << " " << smt1_literal(*it); out << ")"; } out << std::endl; }
void float_utilst::normalization_shift(bvt &fraction, bvt &exponent) { #if 0 // this thing is quadratic! bvt new_fraction=prop.new_variables(fraction.size()); bvt new_exponent=prop.new_variables(exponent.size()); // i is the shift distance for(std::size_t i=0; i<fraction.size(); i++) { bvt equal; // the bits above need to be zero for(std::size_t j=0; j<i; j++) equal.push_back( !fraction[fraction.size()-1-j]); // this one needs to be one equal.push_back(fraction[fraction.size()-1-i]); // iff all of that holds, we shift here! literalt shift=prop.land(equal); // build shifted value bvt shifted_fraction=bv_utils.shift(fraction, bv_utilst::LEFT, i); bv_utils.cond_implies_equal(shift, shifted_fraction, new_fraction); // build new exponent bvt adjustment=bv_utils.build_constant(-i, exponent.size()); bvt added_exponent=bv_utils.add(exponent, adjustment); bv_utils.cond_implies_equal(shift, added_exponent, new_exponent); } // Fraction all zero? It stays zero. // The exponent is undefined in that case. literalt fraction_all_zero=bv_utils.is_zero(fraction); bvt zero_fraction; zero_fraction.resize(fraction.size(), const_literal(false)); bv_utils.cond_implies_equal(fraction_all_zero, zero_fraction, new_fraction); fraction=new_fraction; exponent=new_exponent; #else // n-log-n alignment shifter. // The worst-case shift is the number of fraction // bits minus one, in case the faction is one exactly. assert(!fraction.empty()); unsigned depth=integer2unsigned(address_bits(fraction.size()-1)); if(exponent.size()<depth) exponent=bv_utils.sign_extension(exponent, depth); bvt exponent_delta=bv_utils.zeros(exponent.size()); for(int d=depth-1; d>=0; d--) { std::size_t distance=(1<<d); assert(fraction.size()>distance); // check if first 'distance'-many bits are zeros const bvt prefix=bv_utils.extract_msb(fraction, distance); literalt prefix_is_zero=bv_utils.is_zero(prefix); // If so, shift the zeros out left by 'distance'. // Otherwise, leave as is. const bvt shifted= bv_utils.shift(fraction, bv_utilst::LEFT, distance); fraction= bv_utils.select(prefix_is_zero, shifted, fraction); // add corresponding weight to exponent assert(d<(signed)exponent_delta.size()); exponent_delta[d]=prefix_is_zero; } exponent=bv_utils.sub(exponent, exponent_delta); #endif }