Пример #1
0
Файл: bv1.c Проект: hellok/kint
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;
}
Пример #2
0
literalt boolector_propt::lxor(const bvt &bv)
{
  if(bv.size()==0) return const_literal(false);
  if(bv.size()==1) return bv[0];

  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_xor(boolector_ctx, args[0], args[1]);
    else if (i>1)
      result = boolector_xor(boolector_ctx, result, args[i]);
  }

  boolector_assert(boolector_ctx, boolector_iff(boolector_ctx, boolector_literal(l), result));

  return l;
}
Пример #3
0
void
V3SvrBoolector::add_XOR_Formula(const V3NetId& out, const uint32_t& depth) {
   // Check Output Validation
   assert (validNetId(out)); assert (BV_XOR == _ntk->getGateType(out)); assert (!getVerifyData(out, depth));
   const uint32_t index = getV3NetIndex(out); assert (depth == _ntkData[index].size());
   // Build XOR 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_xor(_Solver, exp1, exp2));
   assert (getVerifyData(out, depth));
}
Пример #4
0
literalt boolector_propt::lxor(literalt a, literalt b)
{
  if(a==const_literal(false)) return b;
  if(b==const_literal(false)) return a;
  if(a==const_literal(true)) return lnot(b);
  if(b==const_literal(true)) return lnot(a);

  literalt l=new_variable();
  BtorExp *result;

  result = boolector_xor(boolector_ctx, boolector_literal(a), boolector_literal(b));
  boolector_assert(boolector_ctx, boolector_iff(boolector_ctx, boolector_literal(l), result));


  return l;
}