array1.c
#include "../../include/boolector.h"
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#define ARRAY1_EXAMPLE_VALUE_BW 8
#define ARRAY1_EXAMPLE_INDEX_BW 3
#define ARRAY1_EXAMPLE_ARRAY_SIZE (1 << ARRAY1_EXAMPLE_INDEX_BW)
int
main (void)
{
Btor *btor;
BtorExp *array, *read, *max, *temp, *ugt, *formula, *index;
BtorExp *indices[ARRAY1_EXAMPLE_ARRAY_SIZE];
int i, result;
btor = boolector_new ();
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);
max = boolector_read (btor, array, indices[0]);
for (i = 1; i < ARRAY1_EXAMPLE_ARRAY_SIZE; i++)
{
read = boolector_read (btor, array, indices[i]);
ugt = boolector_ugt (btor, read, max);
temp = boolector_cond (btor, ugt, read, max);
boolector_release (btor, max);
max = temp;
boolector_release (btor, read);
boolector_release (btor, ugt);
}
index = boolector_var (btor, ARRAY1_EXAMPLE_INDEX_BW, NULL);
read = boolector_read (btor, array, index);
formula = boolector_ugt (btor, read, max);
boolector_assert (btor, formula);
result = boolector_sat (btor);
if (result == BOOLECTOR_UNSAT)
printf ("Formula is unsatisfiable\n");
else
abort ();
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;
}