use of org.sosy_lab.java_smt.api.visitors.FormulaTransformationVisitor in project java-smt by sosy-lab.
the class SolverVisitorTest method stringInIntegerFormulaVisit.
@Test
public void stringInIntegerFormulaVisit() throws SolverException, InterruptedException {
requireStrings();
StringFormula x = smgr.makeVariable("xVariable");
StringFormula y = smgr.makeVariable("yVariable");
IntegerFormula offset = imgr.makeVariable("offset");
for (IntegerFormula f : ImmutableList.of(smgr.indexOf(x, y, offset), smgr.length(x), smgr.toIntegerFormula(x))) {
mgr.visit(f, new FunctionDeclarationVisitorNoUF());
mgr.visit(f, new FunctionDeclarationVisitorNoOther());
IntegerFormula f2 = mgr.transformRecursively(f, new FormulaTransformationVisitor(mgr) {
});
assertThat(f2).isEqualTo(f);
assertThatFormula(bmgr.not(imgr.equal(f, f2))).isUnsatisfiable();
}
}
use of org.sosy_lab.java_smt.api.visitors.FormulaTransformationVisitor in project java-smt by sosy-lab.
the class SolverVisitorTest method stringInBooleanFormulaIdVisit.
@Test
public void stringInBooleanFormulaIdVisit() throws SolverException, InterruptedException {
requireStrings();
StringFormula x = smgr.makeVariable("xVariable");
StringFormula y = smgr.makeVariable("yVariable");
RegexFormula r = smgr.makeRegex("regex1");
for (BooleanFormula f : ImmutableList.of(smgr.equal(x, y), smgr.contains(x, y), smgr.lessThan(x, y), smgr.lessOrEquals(x, y), smgr.greaterOrEquals(x, y), smgr.greaterThan(x, y), smgr.prefix(x, y), smgr.suffix(x, y), smgr.in(x, r))) {
mgr.visit(f, new FunctionDeclarationVisitorNoUF());
mgr.visit(f, new FunctionDeclarationVisitorNoOther());
BooleanFormula f2 = mgr.transformRecursively(f, new FormulaTransformationVisitor(mgr) {
});
assertThat(f2).isEqualTo(f);
assertThatFormula(f).isEquivalentTo(f2);
}
}
use of org.sosy_lab.java_smt.api.visitors.FormulaTransformationVisitor in project java-smt by sosy-lab.
the class SolverVisitorTest method bitvectorIdVisit.
@Test
public void bitvectorIdVisit() throws SolverException, InterruptedException {
requireBitvectors();
BitvectorType bv8 = FormulaType.getBitvectorTypeWithSize(8);
BitvectorFormula x = bvmgr.makeVariable(bv8, "x");
BitvectorFormula y1 = bvmgr.makeVariable(bv8, "y");
BitvectorFormula y2 = bvmgr.add(y1, bvmgr.makeBitvector(8, 13));
BitvectorFormula y3 = bvmgr.makeBitvector(8, 13);
for (BitvectorFormula y : new BitvectorFormula[] { y1, y2, y3 }) {
for (BooleanFormula f : ImmutableList.of(bvmgr.equal(x, y), bmgr.not(bvmgr.equal(x, y)), bvmgr.lessThan(x, y, true), bvmgr.lessThan(x, y, false), bvmgr.lessOrEquals(x, y, true), bvmgr.lessOrEquals(x, y, false), bvmgr.greaterThan(x, y, true), bvmgr.greaterThan(x, y, false), bvmgr.greaterOrEquals(x, y, true), bvmgr.greaterOrEquals(x, y, false))) {
mgr.visit(f, new FunctionDeclarationVisitorNoUF());
if (Solvers.PRINCESS != solver) {
// Princess models BV theory with intervals, such as "mod_cast(lower, upper , value)".
// The interval function is of FunctionDeclarationKind.OTHER and thus we cannot check it.
mgr.visit(f, new FunctionDeclarationVisitorNoOther());
}
BooleanFormula f2 = mgr.transformRecursively(f, new FormulaTransformationVisitor(mgr) {
});
assertThat(f2).isEqualTo(f);
assertThatFormula(f).isEquivalentTo(f2);
}
for (BitvectorFormula f : ImmutableList.of(bvmgr.add(x, y), bvmgr.subtract(x, y), bvmgr.multiply(x, y), bvmgr.and(x, y), bvmgr.or(x, y), bvmgr.xor(x, y), bvmgr.divide(x, y, true), bvmgr.divide(x, y, false), bvmgr.modulo(x, y, true), bvmgr.modulo(x, y, false), bvmgr.not(x), bvmgr.negate(x), bvmgr.extract(x, 7, 5), bvmgr.extract(x, 7, 5), bvmgr.concat(x, y))) {
mgr.visit(f, new FunctionDeclarationVisitorNoUF());
if (Solvers.PRINCESS != solver) {
// Princess models BV theory with intervals, such as "mod_cast(lower, upper , value)".
// The interval function is of FunctionDeclarationKind.OTHER and thus we cannot check it.
mgr.visit(f, new FunctionDeclarationVisitorNoOther());
}
BitvectorFormula f2 = mgr.transformRecursively(f, new FormulaTransformationVisitor(mgr) {
});
assertThat(f2).isEqualTo(f);
assertThatFormula(bmgr.not(bvmgr.equal(f, f2))).isUnsatisfiable();
}
}
}
use of org.sosy_lab.java_smt.api.visitors.FormulaTransformationVisitor in project java-smt by sosy-lab.
the class SolverVisitorTest method bvVisit.
@Test
public void bvVisit() throws SolverException, InterruptedException {
requireBitvectors();
BitvectorFormula x = bvmgr.makeVariable(5, "x");
for (BitvectorFormula f : ImmutableList.of(bvmgr.extend(x, 10, true), bvmgr.extend(x, 10, false))) {
BitvectorFormula f2 = mgr.transformRecursively(f, new FormulaTransformationVisitor(mgr) {
});
assertThat(f2).isEqualTo(f);
assertThatFormula(bmgr.not(bvmgr.equal(f, f2))).isUnsatisfiable();
}
}
use of org.sosy_lab.java_smt.api.visitors.FormulaTransformationVisitor in project java-smt by sosy-lab.
the class SolverVisitorTest method recursiveTransformationVisitorTest.
@Test
public void recursiveTransformationVisitorTest() throws Exception {
BooleanFormula f = bmgr.or(imgr.equal(imgr.add(imgr.makeVariable("x"), imgr.makeVariable("y")), imgr.makeNumber(1)), imgr.equal(imgr.makeVariable("z"), imgr.makeNumber(10)));
BooleanFormula transformed = mgr.transformRecursively(f, new FormulaTransformationVisitor(mgr) {
@Override
public Formula visitFreeVariable(Formula formula, String name) {
return mgr.makeVariable(mgr.getFormulaType(formula), name + "'");
}
});
assertThatFormula(transformed).isEquivalentTo(bmgr.or(imgr.equal(imgr.add(imgr.makeVariable("x'"), imgr.makeVariable("y'")), imgr.makeNumber(1)), imgr.equal(imgr.makeVariable("z'"), imgr.makeNumber(10))));
}
Aggregations