// Manipulation Helper Functions void V3SvrBoolector::setTargetValue(const V3NetId& id, const V3BitVecX& value, const uint32_t& depth, V3SvrDataVec& formula) { // Note : This Function will set formula such that AND(formula) represents (id == value) uint32_t size = value.size(); assert (size == _ntk->getNetWidth(id)); BtorExp* const aExp = getVerifyData(id, depth); assert (aExp); char* bv_value = new char[size + 1]; BtorExp *bExp, *cExp; 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); j = 0; formula.push_back(getPosExp(boolector_eq(_Solver, bExp, cExp))); boolector_release(_Solver, bExp); boolector_release(_Solver, cExp); } } 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); formula.push_back(getPosExp(boolector_eq(_Solver, bExp, cExp))); boolector_release(_Solver, bExp); boolector_release(_Solver, cExp); } delete[] bv_value; }
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; }
void V3SvrBoolector::add_FF_Formula(const V3NetId& out, const uint32_t& depth) { // Check Output Validation assert (validNetId(out)); assert (V3_FF == _ntk->getGateType(out)); assert (!getVerifyData(out, depth)); const uint32_t index = getV3NetIndex(out); assert (depth == _ntkData[index].size()); const uint32_t width = _ntk->getNetWidth(out); assert (width); if (_freeBound) { // Set BtorExp* _ntkData[index].push_back(boolector_var(_Solver, width, NULL)); } else if (depth) { // Build FF I/O Relation const V3NetId in1 = _ntk->getInputNetId(out, 0); assert (validNetId(in1)); BtorExp* const exp1 = getVerifyData(in1, depth - 1); assert (exp1); // Set BtorExp* _ntkData[index].push_back(boolector_copy(_Solver, exp1)); } else { // Set BtorExp* _ntkData[index].push_back(boolector_var(_Solver, width, NULL)); BtorExp* const exp = _ntkData[index].back(); assert (exp); // Build FF Initial State const V3NetId in1 = _ntk->getInputNetId(out, 1); assert (validNetId(in1)); const V3BvNtk* const ntk = dynamic_cast<const V3BvNtk*>(_ntk); if (ntk) { if (BV_CONST == ntk->getGateType(in1)) { const V3BitVecX* const value = ntk->getInputConstValue(in1); assert (value); assert (width == value->size()); char* bv_value = new char[width + 1]; bv_value[width] = '\0'; for (uint32_t i = 0, j = width - 1; i < width; ++i, --j) bv_value[j] = (*value)[i]; BtorExp* const init_exp = boolector_const(_Solver, bv_value); assert (init_exp); _init.push_back(boolector_eq(_Solver, exp, init_exp)); delete[] bv_value; boolector_release(_Solver, init_exp); } else { // Build Initial Circuit BtorExp* const exp1 = getVerifyData(in1, 0); assert (exp1); _init.push_back(boolector_eq(_Solver, exp, exp1)); } } else { if (AIG_FALSE == _ntk->getGateType(in1)) _init.push_back(!isV3NetInverted(in1) ? boolector_not(_Solver, exp) : boolector_copy(_Solver, exp)); else { // Build Initial Circuit BtorExp* const exp1 = getVerifyData(in1, 0); assert (exp1); _init.push_back(boolector_eq(_Solver, exp, exp1)); } } } assert (getVerifyData(out, depth)); }
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); }
void V3SvrBoolector::add_EQUALITY_Formula(const V3NetId& out, const uint32_t& depth) { // Check Output Validation assert (validNetId(out)); assert (BV_EQUALITY == _ntk->getGateType(out)); assert (!getVerifyData(out, depth)); const uint32_t index = getV3NetIndex(out); assert (depth == _ntkData[index].size()); // Build EQUALITY 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_eq(_Solver, exp1, exp2)); assert (getVerifyData(out, depth)); }
int main () { int sat_result; BtorExp *array, *index1, *index2, *read1, *read2, *eq, *ne; Btor *btor; btor = boolector_new (); boolector_enable_inc_usage (btor); array = boolector_array (btor, ARRAY3_EXAMPLE_VALUE_BW, ARRAY3_EXAMPLE_INDEX_BW, NULL); index1 = boolector_var (btor, ARRAY3_EXAMPLE_INDEX_BW, NULL); index2 = boolector_var (btor, ARRAY3_EXAMPLE_INDEX_BW, NULL); read1 = boolector_read (btor, array, index1); read2 = boolector_read (btor, array, index2); eq = boolector_eq (btor, index1, index2); ne = boolector_ne (btor, read1, read2); /* we enforce that index1 is equal to index 2 */ boolector_assert (btor, eq); sat_result = boolector_sat (btor); assert (sat_result == BOOLECTOR_SAT); /* now we additionally assume that the read values differ * the instance is now unsatasfiable as read congruence is violated */ boolector_assume (btor, ne); sat_result = boolector_sat (btor); assert (sat_result == BOOLECTOR_UNSAT); /* after the SAT call the assumptions are gone * the instance is now satisfiable again */ sat_result = boolector_sat (btor); assert (sat_result == BOOLECTOR_SAT); boolector_release (btor, array); boolector_release (btor, index1); boolector_release (btor, index2); boolector_release (btor, read1); boolector_release (btor, read2); boolector_release (btor, eq); boolector_release (btor, ne); boolector_delete (btor); return 0; }
int main (void) { Btor *btor; BoolectorNode *array1, *array2, *zero, *one, *val1, *val2; BoolectorNode *write1, *write2, *formula; char **indices, **values; int result, size, i; btor = boolector_new (); boolector_set_opt (btor, "model_gen", 1); zero = boolector_zero (btor, ARRAY2_EXAMPLE_INDEX_BW); one = boolector_one (btor, ARRAY2_EXAMPLE_INDEX_BW); val1 = boolector_int (btor, 3, ARRAY2_EXAMPLE_VALUE_BW); val2 = boolector_int (btor, 5, ARRAY2_EXAMPLE_VALUE_BW); array1 = boolector_array (btor, ARRAY2_EXAMPLE_VALUE_BW, ARRAY2_EXAMPLE_INDEX_BW, NULL); array2 = boolector_array (btor, ARRAY2_EXAMPLE_VALUE_BW, ARRAY2_EXAMPLE_INDEX_BW, NULL); write1 = boolector_write (btor, array1, zero, val1); write2 = boolector_write (btor, array2, one, val2); /* Note: we compare two arrays for equality ---> needs extensional theory */ formula = boolector_eq (btor, write1, write2); boolector_assert (btor, formula); result = boolector_sat (btor); if (result == BOOLECTOR_SAT) printf ("Formula is satisfiable\n"); else abort (); /* Formula is satisfiable, we can obtain array models: */ boolector_array_assignment (btor, array1, &indices, &values, &size); if (size > 0) { printf ("Array1:\n"); for (i = 0; i < size; i++) printf ("Array1[%s] = %s\n", indices[i], values[i]); boolector_free_array_assignment (btor, indices, values, size); } boolector_array_assignment (btor, array2, &indices, &values, &size); if (size > 0) { printf ("\nArray2:\n"); for (i = 0; i < size; i++) printf ("Array2[%s] = %s\n", indices[i], values[i]); boolector_free_array_assignment (btor, indices, values, size); } boolector_array_assignment (btor, write1, &indices, &values, &size); if (size > 0) { printf ("\nWrite1:\n"); for (i = 0; i < size; i++) printf ("Write1[%s] = %s\n", indices[i], values[i]); boolector_free_array_assignment (btor, indices, values, size); } boolector_array_assignment (btor, write2, &indices, &values, &size); if (size > 0) { printf ("\nWrite2:\n"); for (i = 0; i < size; i++) printf ("Write2[%s] = %s\n", indices[i], values[i]); boolector_free_array_assignment (btor, indices, values, size); } /* clean up */ boolector_release (btor, formula); boolector_release (btor, write1); boolector_release (btor, write2); boolector_release (btor, array1); boolector_release (btor, array2); boolector_release (btor, val1); boolector_release (btor, val2); boolector_release (btor, zero); boolector_release (btor, one); assert (boolector_get_refs (btor) == 0); boolector_delete (btor); return 0; }