Example #1
0
File: array1.c Project: hellok/kint
int
main (void)
{
  Btor *btor;
  BtorNode *array, *read, *max, *temp, *ugt, *formula, *index;
  BtorNode *indices[ARRAY1_EXAMPLE_ARRAY_SIZE];
  int i, result;

  btor = boolector_new ();
  /* We create all possible constants that are used as read indices */
  for (i = 0; i < ARRAY1_EXAMPLE_ARRAY_SIZE; i++)
    indices[i] = boolector_int (btor, i, ARRAY1_EXAMPLE_INDEX_BW);

  array =
    boolector_array (btor, ARRAY1_EXAMPLE_VALUE_BW, ARRAY1_EXAMPLE_INDEX_BW,
                     NULL);
  /* Current maximum is first element of array */
  max = boolector_read (btor, array, indices[0]);
  /* Symbolic loop unrolling */
  for (i = 1; i < ARRAY1_EXAMPLE_ARRAY_SIZE; i++)
    {
      read = boolector_read (btor, array, indices[i]);
      ugt = boolector_ugt (btor, read, max);
      /* found a new maximum? */
      temp = boolector_cond (btor, ugt, read, max);
      boolector_release (btor, max);
      max = temp;
      boolector_release (btor, read);
      boolector_release (btor, ugt);
    }

  /* Now we show that 'max' is indeed a maximum */
  /* We read at an arbitrary position */
  index = boolector_var (btor, ARRAY1_EXAMPLE_INDEX_BW, NULL);
  read = boolector_read (btor, array, index);

  /* We assume that it is possible that the read value is greater than 'max' */
  formula = boolector_ugt (btor, read, max);

  /* 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 ();

  /* clean up */
  for (i = 0; i < ARRAY1_EXAMPLE_ARRAY_SIZE; i++)
    boolector_release (btor, indices[i]);
  boolector_release (btor, formula);
  boolector_release (btor, read);
  boolector_release (btor, index);
  boolector_release (btor, max);
  boolector_release (btor, array);
  assert (boolector_get_refs (btor) == 0);
  boolector_delete (btor);
  return 0;
}
Example #2
0
void
V3SvrBoolector::add_MUX_Formula(const V3NetId& out, const uint32_t& depth) {
   // Check Output Validation
   assert (validNetId(out)); assert (BV_MUX == _ntk->getGateType(out)); assert (!getVerifyData(out, depth));
   const uint32_t index = getV3NetIndex(out); assert (depth == _ntkData[index].size());
   // Build MUX I/O Relation
   const V3NetId fIn = _ntk->getInputNetId(out, 0); assert (validNetId(fIn));
   const V3NetId tIn = _ntk->getInputNetId(out, 1); assert (validNetId(tIn));
   const V3NetId sIn = _ntk->getInputNetId(out, 2); assert (validNetId(sIn));
   BtorExp* const fExp = getVerifyData(fIn, depth); assert (fExp);
   BtorExp* const tExp = getVerifyData(tIn, depth); assert (tExp);
   BtorExp* const sExp = getVerifyData(sIn, depth); assert (sExp);
   // Set BtorExp*
   _ntkData[index].push_back(boolector_cond(_Solver, sExp, tExp, fExp));
   assert (getVerifyData(out, depth));
}
Example #3
0
literalt boolector_propt::lselect(literalt a, literalt b, literalt c)
{
  if(a==const_literal(true)) return b;
  if(a==const_literal(false)) return c;
  if(b==c) return 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_cond(boolector_ctx, boolector_literal(a), boolector_literal(b), boolector_literal(c));
  boolector_assert(boolector_ctx, boolector_iff(boolector_ctx, boolector_literal(l), result));

  return l;
}