const size_t V3SvrBoolector::setTargetValue(const V3NetId& id, const V3BitVecX& value, const uint32_t& depth, const size_t& prev) { // Construct formula y = b0 & b1' & b3 & ... & bn', and return expr y if (prev) assert (!isNegFormula(prev)); // Constrain input prev expr should NOT be negative! uint32_t size = value.size(); assert (size == _ntk->getNetWidth(id)); BtorExp* const aExp = getVerifyData(id, depth); assert (aExp); BtorExp* pExp = (prev) ? boolector_copy(_Solver, getOriExp(prev)) : 0, *bExp, *cExp, *eExp; char* bv_value = new char[size + 1]; uint32_t i = size, j = 0; while (i--) { if ('1' == value[i]) bv_value[j++] = '1'; else if ('0' == value[i]) bv_value[j++] = '0'; else if (j) { bv_value[j] = '\0'; bExp = boolector_slice(_Solver, aExp, i + j, i + 1); cExp = boolector_const(_Solver, bv_value); eExp = boolector_eq(_Solver, bExp, cExp); boolector_release(_Solver, bExp); boolector_release(_Solver, cExp); if (pExp) { bExp = boolector_and(_Solver, pExp, eExp); boolector_release(_Solver, pExp); boolector_release(_Solver, eExp); pExp = bExp; } else pExp = eExp; j = 0; } } if (j) { bv_value[j] = '\0'; if (j == size) bExp = boolector_copy(_Solver, aExp); else bExp = boolector_slice(_Solver, aExp, j - 1, 0); cExp = boolector_const(_Solver, bv_value); eExp = boolector_eq(_Solver, bExp, cExp); boolector_release(_Solver, bExp); boolector_release(_Solver, cExp); if (pExp) { bExp = boolector_and(_Solver, pExp, eExp); boolector_release(_Solver, pExp); boolector_release(_Solver, eExp); pExp = bExp; } else pExp = eExp; } delete[] bv_value; assert (!isNegFormula(getPosExp(pExp))); return getPosExp(pExp); }
int main (void) { Btor *btor; BtorNode *x, *y, *temp, *old_x, *old_y, *eq1, *eq2, *and, *formula; int result; btor = boolector_new (); x = boolector_var (btor, BV1_EXAMPLE_NUM_BITS, NULL); y = boolector_var (btor, BV1_EXAMPLE_NUM_BITS, NULL); /* remember initial values of x and y */ old_x = boolector_copy (btor, x); old_y = boolector_copy (btor, y); /* x = x ^ y */ temp = boolector_xor (btor, x, y); boolector_release (btor, x); x = temp; /* y = x ^ y */ temp = boolector_xor (btor, x, y); boolector_release (btor, y); y = temp; /* x = x ^ y */ temp = boolector_xor (btor, x, y); boolector_release (btor, x); x = temp; /* Now, we have to show that old_x = y and old_y = x */ eq1 = boolector_eq (btor, old_x, y); eq2 = boolector_eq (btor, old_y, x); and = boolector_and (btor, eq1, eq2); /* In order to prove that this is a theorem, we negate the whole * formula and show that the negation is unsatisfiable */ formula = boolector_not (btor, and); /* We assert the formula and call Boolector */ boolector_assert (btor, formula); result = boolector_sat (btor); if (result == BOOLECTOR_UNSAT) printf ("Formula is unsatisfiable\n"); else abort (); /* cleanup */ boolector_release (btor, x); boolector_release (btor, old_x); boolector_release (btor, y); boolector_release (btor, old_y); boolector_release (btor, eq1); boolector_release (btor, eq2); boolector_release (btor, and); boolector_release (btor, formula); assert (boolector_get_refs (btor) == 0); boolector_delete (btor); return 0; }
literalt boolector_propt::land(const bvt &bv) { literalt l=new_variable(); u_int size=bv.size()+1; BtorExp *args[size], *result; for(unsigned int i=0; i<bv.size(); i++) { args[i] = boolector_literal(bv[i]); if (i==1) result = boolector_and(boolector_ctx, args[0], args[1]); else if (i>1) result = boolector_and(boolector_ctx, result, args[i]); } boolector_assert(boolector_ctx, boolector_iff(boolector_ctx, boolector_literal(l), result)); return l; }
void V3SvrBoolector::add_AND_Formula(const V3NetId& out, const uint32_t& depth) { // Check Output Validation assert (validNetId(out)); assert (!getVerifyData(out, depth)); assert ((AIG_NODE == _ntk->getGateType(out)) || (BV_AND == _ntk->getGateType(out))); const uint32_t index = getV3NetIndex(out); assert (depth == _ntkData[index].size()); // Build AND I/O Relation const V3NetId in1 = _ntk->getInputNetId(out, 0); assert (validNetId(in1)); const V3NetId in2 = _ntk->getInputNetId(out, 1); assert (validNetId(in2)); BtorExp* const exp1 = getVerifyData(in1, depth); assert (exp1); BtorExp* const exp2 = getVerifyData(in2, depth); assert (exp2); // Set BtorExp* _ntkData[index].push_back(boolector_and(_Solver, exp1, exp2)); assert (getVerifyData(out, depth)); }
literalt boolector_propt::land(literalt a, literalt b) { if(a==const_literal(true)) return b; if(b==const_literal(true)) return a; if(a==const_literal(false)) return const_literal(false); if(b==const_literal(false)) return const_literal(false); if(a==b) return a; literalt l=new_variable(); BtorExp *result; result = boolector_and(boolector_ctx, boolector_literal(a), boolector_literal(b)); boolector_assert(boolector_ctx, boolector_iff(boolector_ctx, boolector_literal(l), result)); return l; }
const size_t V3SvrBoolector::setImplyIntersection(const V3SvrDataVec& Exps) { if (Exps.size() == 0) return 0; vector<size_t>::const_iterator it = Exps.begin(); assert (*it); BtorExp *aExp = (isNegFormula(*it) ? boolector_not(_Solver, getOriExp(*it)) : boolector_copy(_Solver, getOriExp(*it))); BtorExp *bExp, *oExp; ++it; for (; it != Exps.end(); ++it) { assert (*it); assert (aExp); bExp = (isNegFormula(*it) ? boolector_not(_Solver, getOriExp(*it)) : boolector_copy(_Solver, getOriExp(*it))); oExp = boolector_and(_Solver, aExp, bExp); assert (oExp); boolector_release(_Solver, aExp); boolector_release(_Solver, bExp); aExp = oExp; } bExp = boolector_var(_Solver, 1, NULL); oExp = boolector_implies(_Solver, bExp, aExp); boolector_assert(_Solver, oExp); boolector_release(_Solver, oExp); boolector_release(_Solver, aExp); assert (!isNegFormula(getPosExp(bExp))); assert (bExp); return getPosExp(bExp); }
int main (void) { Btor *btor; BtorNode *v1, *v2, *add, *zero, *vars_sgt_zero, *impl; BtorNode *v1_sgt_zero, *v2_sgt_zero, *add_sgt_zero, *formula; char *assignments[10]; int result, i; btor = boolector_new (); boolector_enable_model_gen (btor); v1 = boolector_var (btor, BV2_EXAMPLE_NUM_BITS, NULL); v2 = boolector_var (btor, BV2_EXAMPLE_NUM_BITS, NULL); zero = boolector_zero (btor, BV2_EXAMPLE_NUM_BITS); v1_sgt_zero = boolector_sgt (btor, v1, zero); v2_sgt_zero = boolector_sgt (btor, v2, zero); vars_sgt_zero = boolector_and (btor, v1_sgt_zero, v2_sgt_zero); add = boolector_add (btor, v1, v2); add_sgt_zero = boolector_sgt (btor, add, zero); impl = boolector_implies (btor, vars_sgt_zero, add_sgt_zero); /* We negate the formula and try to show that the negation is unsatisfiable */ formula = boolector_not (btor, impl); /* We assert the formula and call Boolector */ boolector_assert (btor, formula); result = boolector_sat (btor); if (result == BOOLECTOR_SAT) printf ("Instance is satisfiable"); else abort (); /* The formula is not valid, we have found a counter-example. * Now, we are able to obtain assignments to arbitrary expressions */ i = 0; assignments[i++] = boolector_bv_assignment (btor, zero); assignments[i++] = boolector_bv_assignment (btor, v1); assignments[i++] = boolector_bv_assignment (btor, v2); assignments[i++] = boolector_bv_assignment (btor, add); assignments[i++] = boolector_bv_assignment (btor, v1_sgt_zero); assignments[i++] = boolector_bv_assignment (btor, v2_sgt_zero); assignments[i++] = boolector_bv_assignment (btor, vars_sgt_zero); assignments[i++] = boolector_bv_assignment (btor, add_sgt_zero); assignments[i++] = boolector_bv_assignment (btor, impl); assignments[i++] = boolector_bv_assignment (btor, formula); i = 0; printf ("Assignment to 0: %s\n", assignments[i++]); printf ("Assignment to v1: %s\n", assignments[i++]); printf ("Assignment to v2: %s\n", assignments[i++]); printf ("Assignment to v1 + v2: %s\n", assignments[i++]); printf ("Assignment to v1 > 0: %s\n", assignments[i++]); printf ("Assignment to v2 > 0: %s\n", assignments[i++]); printf ("Assignment to v1 > 0 & v2 > 0: %s\n", assignments[i++]); printf ("Assignment to v1 + v2 > 0: %s\n", assignments[i++]); printf ("Assignment to v1 > 0 & v2 > 0 => v1 + v2 > 0: %s\n", assignments[i++]); printf ("Assignment to !(v1 > 0 & v2 > 0 => v1 + v2 > 0): %s\n", assignments[i++]); for (i = 0; i < 10; i++) boolector_free_bv_assignment (btor, assignments[i]); /* cleanup */ boolector_release (btor, zero); boolector_release (btor, v1); boolector_release (btor, v2); boolector_release (btor, add); boolector_release (btor, impl); boolector_release (btor, formula); boolector_release (btor, v1_sgt_zero); boolector_release (btor, v2_sgt_zero); boolector_release (btor, vars_sgt_zero); boolector_release (btor, add_sgt_zero); assert (boolector_get_refs (btor) == 0); boolector_delete (btor); return 0; }