Ejemplo n.º 1
0
Archivo: array1.c Proyecto: 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;
}
Ejemplo n.º 2
0
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;
}