use of org.sosy_lab.java_smt.api.BitvectorFormula in project java-smt by sosy-lab.
the class AllSatExample method allSatBitvectors.
/**
* For bitvector formulas, we can implement the allsat-loop and collect all models when iterating.
*/
private List<List<ValueAssignment>> allSatBitvectors() throws InterruptedException, SolverException {
bfmgr = context.getFormulaManager().getBooleanFormulaManager();
bvfmgr = context.getFormulaManager().getBitvectorFormulaManager();
// formula ((1 <= a <= 3) && (0 == b) && (p == q)) with 6 models
final int bitsize = 4;
BitvectorFormula a = bvfmgr.makeVariable(bitsize, "c");
BitvectorFormula b = bvfmgr.makeVariable(bitsize, "d");
BooleanFormula p = bfmgr.makeVariable("r");
BooleanFormula q = bfmgr.makeVariable("s");
prover.addConstraint(bvfmgr.lessOrEquals(bv(bitsize, 1), a, true));
prover.addConstraint(bvfmgr.equal(bv(bitsize, 0), b));
prover.addConstraint(bvfmgr.lessOrEquals(a, bv(bitsize, 3), true));
prover.addConstraint(bfmgr.equivalence(p, q));
List<List<ValueAssignment>> models = new ArrayList<>();
// loop over all possible models for "1<=a<=3 AND p=q"
while (!prover.isUnsat()) {
final ImmutableList<ValueAssignment> modelAssignments = prover.getModelAssignments();
models.add(modelAssignments);
final List<BooleanFormula> modelAssignmentsAsFormulas = new ArrayList<>();
for (ValueAssignment va : modelAssignments) {
modelAssignmentsAsFormulas.add(va.getAssignmentAsFormula());
}
// prevent next model from using the same assignment as a previous model
prover.addConstraint(bfmgr.not(bfmgr.and(modelAssignmentsAsFormulas)));
}
return models;
}
use of org.sosy_lab.java_smt.api.BitvectorFormula in project java-smt by sosy-lab.
the class CVC4FormulaCreator method getFormulaType.
@SuppressWarnings("unchecked")
@Override
public <T extends Formula> FormulaType<T> getFormulaType(T pFormula) {
Type t = extractInfo(pFormula).getType();
if (pFormula instanceof BitvectorFormula) {
checkArgument(t.isBitVector(), "BitvectorFormula with actual type %s: %s", t, pFormula);
return (FormulaType<T>) getFormulaType(extractInfo(pFormula));
} else if (pFormula instanceof FloatingPointFormula) {
checkArgument(t.isFloatingPoint(), "FloatingPointFormula with actual type %s: %s", t, pFormula);
edu.stanford.CVC4.FloatingPointType fpType = new edu.stanford.CVC4.FloatingPointType(t);
return (FormulaType<T>) FormulaType.getFloatingPointType((int) fpType.getExponentSize(), // without sign bit
(int) fpType.getSignificandSize() - 1);
} else if (pFormula instanceof ArrayFormula<?, ?>) {
FormulaType<T> arrayIndexType = getArrayFormulaIndexType((ArrayFormula<T, T>) pFormula);
FormulaType<T> arrayElementType = getArrayFormulaElementType((ArrayFormula<T, T>) pFormula);
return (FormulaType<T>) FormulaType.getArrayType(arrayIndexType, arrayElementType);
}
return super.getFormulaType(pFormula);
}
use of org.sosy_lab.java_smt.api.BitvectorFormula in project java-smt by sosy-lab.
the class ArrayFormulaManagerTest method testBvIndexBvValue.
/*
* Test whether or not Bitvector Arrays are possible with bv index
*/
@Test
public void testBvIndexBvValue() throws SolverException, InterruptedException {
requireBitvectors();
// (arr2 = store(arr1, 0100, 0010)) & !(select(arr2, 0100) = 0010)
BitvectorFormula num2 = bvmgr.makeBitvector(4, 2);
BitvectorFormula num4 = bvmgr.makeBitvector(4, 4);
ArrayFormula<BitvectorFormula, BitvectorFormula> arr1 = amgr.makeArray("arr1", getBitvectorTypeWithSize(4), getBitvectorTypeWithSize(4));
ArrayFormula<BitvectorFormula, BitvectorFormula> arr2 = amgr.makeArray("arr2", getBitvectorTypeWithSize(4), getBitvectorTypeWithSize(4));
BooleanFormula query = bmgr.and(amgr.equivalence(arr2, amgr.store(arr1, num4, num2)), bmgr.not(bvmgr.equal(num2, amgr.select(arr2, num4))));
assertThatFormula(query).isUnsatisfiable();
}
use of org.sosy_lab.java_smt.api.BitvectorFormula in project java-smt by sosy-lab.
the class BitvectorFormulaManagerTest method bvBvArray.
@Test
public void bvBvArray() {
requireArrays();
BitvectorFormula bv = bvmgr.makeBitvector(4, 3);
ArrayFormula<BitvectorFormula, BitvectorFormula> arr = amgr.makeArray("arr", bvType4, bvType4);
BitvectorFormula index = bvmgr.makeBitvector(4, 2);
arr = amgr.store(arr, index, bv);
assertThat(mgr.getFormulaType(arr)).isEqualTo(FormulaType.getArrayType(bvType4, bvType4));
}
use of org.sosy_lab.java_smt.api.BitvectorFormula in project java-smt by sosy-lab.
the class BitvectorFormulaManagerTest method bvExtractTooLargeNumStartAltSigned.
@Test
public void bvExtractTooLargeNumStartAltSigned() {
// Use bv > 1 because of Boolector
BitvectorFormula bv = bvmgr.makeBitvector(4, 4);
assertThrows(IllegalArgumentException.class, () -> bvmgr.extract(bv, 3, 4));
}
Aggregations