Search in sources :

Example 1 with FormulaTransformationVisitor

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();
    }
}
Also used : BooleanFormulaTransformationVisitor(org.sosy_lab.java_smt.api.visitors.BooleanFormulaTransformationVisitor) FormulaTransformationVisitor(org.sosy_lab.java_smt.api.visitors.FormulaTransformationVisitor) IntegerFormula(org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula) StringFormula(org.sosy_lab.java_smt.api.StringFormula) Test(org.junit.Test)

Example 2 with FormulaTransformationVisitor

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);
    }
}
Also used : BooleanFormulaTransformationVisitor(org.sosy_lab.java_smt.api.visitors.BooleanFormulaTransformationVisitor) FormulaTransformationVisitor(org.sosy_lab.java_smt.api.visitors.FormulaTransformationVisitor) StringFormula(org.sosy_lab.java_smt.api.StringFormula) RegexFormula(org.sosy_lab.java_smt.api.RegexFormula) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Test(org.junit.Test)

Example 3 with FormulaTransformationVisitor

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();
        }
    }
}
Also used : BitvectorFormula(org.sosy_lab.java_smt.api.BitvectorFormula) BitvectorType(org.sosy_lab.java_smt.api.FormulaType.BitvectorType) BooleanFormulaTransformationVisitor(org.sosy_lab.java_smt.api.visitors.BooleanFormulaTransformationVisitor) FormulaTransformationVisitor(org.sosy_lab.java_smt.api.visitors.FormulaTransformationVisitor) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Test(org.junit.Test)

Example 4 with FormulaTransformationVisitor

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();
    }
}
Also used : BitvectorFormula(org.sosy_lab.java_smt.api.BitvectorFormula) BooleanFormulaTransformationVisitor(org.sosy_lab.java_smt.api.visitors.BooleanFormulaTransformationVisitor) FormulaTransformationVisitor(org.sosy_lab.java_smt.api.visitors.FormulaTransformationVisitor) Test(org.junit.Test)

Example 5 with FormulaTransformationVisitor

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))));
}
Also used : BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) RegexFormula(org.sosy_lab.java_smt.api.RegexFormula) IntegerFormula(org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula) StringFormula(org.sosy_lab.java_smt.api.StringFormula) FloatingPointFormula(org.sosy_lab.java_smt.api.FloatingPointFormula) BitvectorFormula(org.sosy_lab.java_smt.api.BitvectorFormula) Formula(org.sosy_lab.java_smt.api.Formula) BooleanFormulaTransformationVisitor(org.sosy_lab.java_smt.api.visitors.BooleanFormulaTransformationVisitor) FormulaTransformationVisitor(org.sosy_lab.java_smt.api.visitors.FormulaTransformationVisitor) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 BooleanFormulaTransformationVisitor (org.sosy_lab.java_smt.api.visitors.BooleanFormulaTransformationVisitor)10 FormulaTransformationVisitor (org.sosy_lab.java_smt.api.visitors.FormulaTransformationVisitor)10 BitvectorFormula (org.sosy_lab.java_smt.api.BitvectorFormula)6 StringFormula (org.sosy_lab.java_smt.api.StringFormula)6 BooleanFormula (org.sosy_lab.java_smt.api.BooleanFormula)5 IntegerFormula (org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula)5 RegexFormula (org.sosy_lab.java_smt.api.RegexFormula)5 FloatingPointFormula (org.sosy_lab.java_smt.api.FloatingPointFormula)3 Formula (org.sosy_lab.java_smt.api.Formula)3 ImmutableList (com.google.common.collect.ImmutableList)2 BitvectorType (org.sosy_lab.java_smt.api.FormulaType.BitvectorType)1 FloatingPointType (org.sosy_lab.java_smt.api.FormulaType.FloatingPointType)1