literalt aig_prop_baset::land(literalt a, literalt b) { if(a.is_true()) return b; if(b.is_true()) return a; if(a.is_false()) return a; if(b.is_false()) return b; if(a==neg(b)) return const_literal(false); if(a==b) return a; return dest.new_and_node(a, b); }
literalt aig_prop_baset::lxor(literalt a, literalt b) { if(a.is_false()) return b; if(b.is_false()) return a; if(a.is_true()) return neg(b); if(b.is_true()) return neg(a); if(a==b) return const_literal(false); if(a==neg(b)) return const_literal(true); // This produces up to three nodes! // See convert_node for where this overhead is removed return lor(land(a, neg(b)), land(neg(a), b)); }
tvt cvc_convt::l_get(literalt l) const { if(l.is_true()) return tvt(true); if(l.is_false()) return tvt(false); assert(l.var_no()<boolean_assignment.size()); return tvt(boolean_assignment[l.var_no()]^l.sign()); }
tvt z3_propt::l_get(literalt a) const { tvt result=tvt(false); std::string literal; Z3_ast z3_literal; size_t found; if(a.is_true()) return tvt(true); else if(a.is_false()) return tvt(false); literal = "l"+i2string(a.var_no()); map_prop_varst::const_iterator cache_result=map_prop_vars.find(literal.c_str()); if(cache_result!=map_prop_vars.end()) { //std::cout << "Cache hit on " << cache_result->first << "\n"; z3_literal = cache_result->second; Z3_app app = Z3_to_app(z3_ctx, z3_literal); Z3_func_decl d = Z3_get_app_decl(z3_ctx, app); literal = Z3_func_decl_to_string(z3_ctx, d); found=literal.find("true"); if (found!=std::string::npos) result=tvt(true); else result=tvt(false); } if (a.sign()) result=!result; return result; }
tvt satcheck_minisat2_baset<T>::l_get(literalt a) const { if(a.is_true()) return tvt(true); else if(a.is_false()) return tvt(false); tvt result; if(a.var_no()>=(unsigned)solver->model.size()) return tvt(tvt::TV_UNKNOWN); using Minisat::lbool; if(solver->model[a.var_no()]==l_True) result=tvt(true); else if(solver->model[a.var_no()]==l_False) result=tvt(false); else return tvt(tvt::TV_UNKNOWN); if(a.sign()) result=!result; return result; }
tvt satcheck_booleforce_baset::l_get(literalt a) const { assert(status==SAT); if(a.is_true()) return tvt(true); else if(a.is_false()) return tvt(false); tvt result; unsigned v=a.var_no(); assert(v<no_variables()); int r=booleforce_deref(v); if(r>0) result=tvt(true); else if(r<0) result=tvt(false); else result=tvt(tvt::tv_enumt::TV_UNKNOWN); if(a.sign()) result=!result; return result; }
tvt boolector_propt::l_get(literalt a) const { tvt result=tvt(false); std::string literal; BtorExp *boolector_literal; size_t found; if(a.is_true()) return tvt(true); else if(a.is_false()) return tvt(false); literal_cachet::const_iterator cache_result=literal_cache.find(a.var_no()); if(cache_result!=literal_cache.end()) boolector_literal = cache_result->second; else return tvt(tvt::TV_UNKNOWN); literal = boolector_bv_assignment(boolector_ctx, boolector_literal); found=literal.find("1"); if (found!=std::string::npos) result=tvt(true); else result=tvt(false); if (a.sign()) result=!result; return result; }
void smt1_propt::set_assignment(literalt literal, bool value) { if(literal.is_true() || literal.is_false()) return; unsigned v=literal.var_no(); assert(v<assignment.size()); assignment[v]=tvt(value); }
tvt smt1_propt::l_get(literalt literal) const { if(literal.is_true()) return tvt(true); if(literal.is_false()) return tvt(false); unsigned v=literal.var_no(); if(v>=assignment.size()) return tvt(tvt::TV_UNKNOWN); tvt r=assignment[v]; return literal.sign()?!r:r; }
literalt aig_prop_baset::lselect(literalt a, literalt b, literalt c) { // a?b:c = (a AND b) OR (/a AND c) if(a.is_true()) return b; if(a.is_false()) return c; if(b==c) return b; // This produces unnecessary clauses and variables // See convert_node for where this overhead is removed return lor(land(a, b), land(neg(a), c)); }
tvt qbf_squolem_coret::l_get(literalt a) const { if(a.is_true()) return tvt(tvt::TV_TRUE); else if(a.is_false()) return tvt(tvt::TV_FALSE); else if(squolem->modelIsTrue(a.var_no())) return tvt(tvt::TV_TRUE); else if(squolem->modelIsFalse(a.var_no()) || squolem->modelIsDontCare(a.var_no())) return tvt(tvt::TV_FALSE); else return tvt(tvt::TV_UNKNOWN); }
void aigt::output_dot_edge( std::ostream& out, nodest::size_type v, literalt l) const { if(l.is_true()) { out << "TRUE -> " << v; } else if(l.is_false()) { out << "TRUE -> " << v; out << " [arrowhead=odiamond]"; } else { out << l.var_no() << " -> " << v; if(l.sign()) out << " [arrowhead=odiamond]"; } out << "\n"; }
tvt satcheck_smvsatt::l_get(literalt a) const { assert(status==SAT); if(a.is_true()) return tvt(true); else if(a.is_false()) return tvt(false); tvt result; unsigned v=a.var_no(); switch(sat_instance_value(satsolver, v)) { case 0: result=tvt(false); break; case 1: result=tvt(true); break; default: result=tvt(tvt::tv_enumt::TV_UNKNOWN); break; } if(a.sign()) result=!result; return result; }
tvt satcheck_minisat1_baset::l_get(literalt a) const { if(a.is_true()) return tvt(true); else if(a.is_false()) return tvt(false); tvt result; assert(a.var_no()!=0); assert(a.var_no()<(unsigned)solver->model.size()); if(solver->model[a.var_no()]==l_True) result=tvt(true); else if(solver->model[a.var_no()]==l_False) result=tvt(false); else result=tvt(tvt::TV_UNKNOWN); if(a.sign()) result=!result; return result; }
literalt bv_utilst::full_adder( const literalt a, const literalt b, const literalt carry_in, literalt &carry_out) { #ifdef OPTIMAL_FULL_ADDER if(prop.has_set_to() && prop.cnf_handled_well()) { literalt x; literalt y; int constantProp = -1; if(a.is_constant()) { x = b; y = carry_in; constantProp = (a.is_true()) ? 1 : 0; } else if(b.is_constant()) { x = a; y = carry_in; constantProp = (b.is_true()) ? 1 : 0; } else if(carry_in.is_constant()) { x = a; y = b; constantProp = (carry_in.is_true()) ? 1 : 0; } literalt sum; // Rely on prop.l* to do further constant propagation if(constantProp == 1) { // At least one input bit is 1 carry_out = prop.lor(x, y); sum = prop.lequal(x, y); } else if(constantProp == 0) { // At least one input bit is 0 carry_out = prop.land(x, y); sum = prop.lxor(x, y); } else { carry_out = prop.new_variable(); sum = prop.new_variable(); // Any two inputs 1 will set the carry_out to 1 prop.lcnf(!a, !b, carry_out); prop.lcnf(!a, !carry_in, carry_out); prop.lcnf(!b, !carry_in, carry_out); // Any two inputs 0 will set the carry_out to 0 prop.lcnf(a, b, !carry_out); prop.lcnf(a, carry_in, !carry_out); prop.lcnf(b, carry_in, !carry_out); // If both carry out and sum are 1 then all inputs are 1 prop.lcnf(a, !sum, !carry_out); prop.lcnf(b, !sum, !carry_out); prop.lcnf(carry_in, !sum, !carry_out); // If both carry out and sum are 0 then all inputs are 0 prop.lcnf(!a, sum, carry_out); prop.lcnf(!b, sum, carry_out); prop.lcnf(!carry_in, sum, carry_out); // If all of the inputs are 1 or all are 0 it sets the sum prop.lcnf(!a, !b, !carry_in, sum); prop.lcnf(a, b, carry_in, !sum); } return sum; } else // NOLINT(readability/braces) #endif // OPTIMAL_FULL_ADDER { // trivial encoding carry_out=carry(a, b, carry_in); return prop.lxor(prop.lxor(a, b), carry_in); } }