Search in sources :

Example 1 with BooleanFormulaTransformationVisitor

use of org.sosy_lab.java_smt.api.visitors.BooleanFormulaTransformationVisitor in project java-smt by sosy-lab.

the class SolverVisitorTest method testIntegerFormulaQuantifierHandlingUNSAT.

// Same as testBooleanFormulaQuantifierHandling but with Ints
@Test
public void testIntegerFormulaQuantifierHandlingUNSAT() throws Exception {
    requireQuantifiers();
    requireIntegers();
    IntegerFormula x = imgr.makeVariable("x");
    BooleanFormula xEq1 = bmgr.not(imgr.equal(imgr.makeNumber(1), x));
    BooleanFormula constraint = qmgr.forall(ImmutableList.of(x), xEq1);
    assertThatFormula(constraint).isUnsatisfiable();
    BooleanFormula newConstraint = bmgr.visit(constraint, new BooleanFormulaTransformationVisitor(mgr) {
    });
    assertThatFormula(newConstraint).isUnsatisfiable();
}
Also used : IntegerFormula(org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula) BooleanFormulaTransformationVisitor(org.sosy_lab.java_smt.api.visitors.BooleanFormulaTransformationVisitor) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Test(org.junit.Test)

Example 2 with BooleanFormulaTransformationVisitor

use of org.sosy_lab.java_smt.api.visitors.BooleanFormulaTransformationVisitor in project java-smt by sosy-lab.

the class SolverVisitorTest method testIntegerFormulaQuantifierHandlingTrivialUNSAT.

@Test
public void testIntegerFormulaQuantifierHandlingTrivialUNSAT() throws Exception {
    requireQuantifiers();
    requireIntegers();
    IntegerFormula x = imgr.makeVariable("x");
    BooleanFormula notxEqx = bmgr.not(imgr.equal(x, x));
    BooleanFormula constraint = qmgr.forall(ImmutableList.of(x), notxEqx);
    assertThatFormula(constraint).isUnsatisfiable();
    BooleanFormula newConstraint = bmgr.visit(constraint, new BooleanFormulaTransformationVisitor(mgr) {
    });
    assertThatFormula(newConstraint).isUnsatisfiable();
}
Also used : IntegerFormula(org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula) BooleanFormulaTransformationVisitor(org.sosy_lab.java_smt.api.visitors.BooleanFormulaTransformationVisitor) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Test(org.junit.Test)

Example 3 with BooleanFormulaTransformationVisitor

use of org.sosy_lab.java_smt.api.visitors.BooleanFormulaTransformationVisitor in project java-smt by sosy-lab.

the class SolverVisitorTest method testBooleanFormulaQuantifierHandling.

@Test
public void testBooleanFormulaQuantifierHandling() throws Exception {
    requireQuantifiers();
    assume().withMessage("Princess does not support quantifier over boolean variables").that(solverToUse()).isNotEqualTo(Solvers.PRINCESS);
    BooleanFormula x = bmgr.makeVariable("x");
    BooleanFormula constraint = qmgr.forall(ImmutableList.of(x), x);
    assertThatFormula(constraint).isUnsatisfiable();
    BooleanFormula newConstraint = bmgr.visit(constraint, new BooleanFormulaTransformationVisitor(mgr) {
    });
    assertThatFormula(newConstraint).isUnsatisfiable();
}
Also used : BooleanFormulaTransformationVisitor(org.sosy_lab.java_smt.api.visitors.BooleanFormulaTransformationVisitor) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Test(org.junit.Test)

Example 4 with BooleanFormulaTransformationVisitor

use of org.sosy_lab.java_smt.api.visitors.BooleanFormulaTransformationVisitor in project java-smt by sosy-lab.

the class SolverVisitorTest method testTransformationInsideQuantifiers.

@Test
public void testTransformationInsideQuantifiers() {
    requireQuantifiers();
    // TODO Maybe rewrite using quantified integer variable to allow testing with Princess
    assume().withMessage("Princess does not support quantifier over boolean variables").that(solverToUse()).isNotEqualTo(Solvers.PRINCESS);
    BooleanFormula[] usedVars = Stream.of("a", "b", "c", "d", "e", "f").map(var -> bmgr.makeVariable(var)).toArray(BooleanFormula[]::new);
    Fuzzer fuzzer = new Fuzzer(mgr, new Random(0));
    List<BooleanFormula> quantifiedVars = ImmutableList.of(bmgr.makeVariable("a"));
    BooleanFormula body = fuzzer.fuzz(30, usedVars);
    BooleanFormula f = qmgr.forall(quantifiedVars, body);
    BooleanFormula transformed = bmgr.transformRecursively(f, new BooleanFormulaTransformationVisitor(mgr) {

        @Override
        public BooleanFormula visitAtom(BooleanFormula pAtom, FunctionDeclaration<BooleanFormula> decl) {
            if (decl.getKind() == FunctionDeclarationKind.VAR) {
                // Uppercase all variables.
                return bmgr.makeVariable(decl.getName().toUpperCase());
            } else {
                return pAtom;
            }
        }
    });
    assertThat(mgr.extractVariables(transformed).keySet().stream().allMatch(pS -> pS.equals(pS.toUpperCase()))).isTrue();
}
Also used : FunctionDeclarationKind(org.sosy_lab.java_smt.api.FunctionDeclarationKind) FloatingPointType(org.sosy_lab.java_smt.api.FormulaType.FloatingPointType) Solvers(org.sosy_lab.java_smt.SolverContextFactory.Solvers) FunctionDeclaration(org.sosy_lab.java_smt.api.FunctionDeclaration) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Random(java.util.Random) TraversalProcess(org.sosy_lab.java_smt.api.visitors.TraversalProcess) ArrayList(java.util.ArrayList) RegexFormula(org.sosy_lab.java_smt.api.RegexFormula) HashSet(java.util.HashSet) IntegerFormula(org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula) Truth(com.google.common.truth.Truth) ImmutableList(com.google.common.collect.ImmutableList) StringFormula(org.sosy_lab.java_smt.api.StringFormula) FloatingPointRoundingMode(org.sosy_lab.java_smt.api.FloatingPointRoundingMode) Map(java.util.Map) BitvectorType(org.sosy_lab.java_smt.api.FormulaType.BitvectorType) FloatingPointFormula(org.sosy_lab.java_smt.api.FloatingPointFormula) LinkedHashSet(java.util.LinkedHashSet) Parameterized(org.junit.runners.Parameterized) Before(org.junit.Before) TruthJUnit.assume(com.google.common.truth.TruthJUnit.assume) BooleanFormulaTransformationVisitor(org.sosy_lab.java_smt.api.visitors.BooleanFormulaTransformationVisitor) FormulaTransformationVisitor(org.sosy_lab.java_smt.api.visitors.FormulaTransformationVisitor) Parameter(org.junit.runners.Parameterized.Parameter) BitvectorFormula(org.sosy_lab.java_smt.api.BitvectorFormula) Collection(java.util.Collection) DefaultFormulaVisitor(org.sosy_lab.java_smt.api.visitors.DefaultFormulaVisitor) Set(java.util.Set) FormulaType(org.sosy_lab.java_smt.api.FormulaType) Test(org.junit.Test) BooleanFormulaVisitor(org.sosy_lab.java_smt.api.visitors.BooleanFormulaVisitor) Truth.assertThat(com.google.common.truth.Truth.assertThat) List(java.util.List) Stream(java.util.stream.Stream) SolverException(org.sosy_lab.java_smt.api.SolverException) DefaultBooleanFormulaVisitor(org.sosy_lab.java_smt.api.visitors.DefaultBooleanFormulaVisitor) Formula(org.sosy_lab.java_smt.api.Formula) FormulaVisitor(org.sosy_lab.java_smt.api.visitors.FormulaVisitor) Random(java.util.Random) BooleanFormulaTransformationVisitor(org.sosy_lab.java_smt.api.visitors.BooleanFormulaTransformationVisitor) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Test(org.junit.Test)

Example 5 with BooleanFormulaTransformationVisitor

use of org.sosy_lab.java_smt.api.visitors.BooleanFormulaTransformationVisitor in project java-smt by sosy-lab.

the class SolverVisitorTest method testNestedIntegerFormulaQuantifierRecursiveHandling.

// Same as testNestedIntegerFormulaQuantifierHandling but with a recursive visitor
@Test
public void testNestedIntegerFormulaQuantifierRecursiveHandling() throws Exception {
    requireQuantifiers();
    requireIntegers();
    // Z3 returns UNKNOWN as its quantifiers can not handle this.
    assume().that(solverToUse()).isNotEqualTo(Solvers.Z3);
    IntegerFormula x = imgr.makeVariable("x");
    BooleanFormula xEq1 = imgr.equal(x, imgr.makeNumber(1));
    BooleanFormula constraint = qmgr.exists(ImmutableList.of(x), qmgr.forall(ImmutableList.of(x), xEq1));
    assertThatFormula(constraint).isUnsatisfiable();
    BooleanFormula newConstraint = bmgr.transformRecursively(constraint, new BooleanFormulaTransformationVisitor(mgr) {
    });
    assertThatFormula(newConstraint).isUnsatisfiable();
}
Also used : IntegerFormula(org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula) BooleanFormulaTransformationVisitor(org.sosy_lab.java_smt.api.visitors.BooleanFormulaTransformationVisitor) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 BooleanFormula (org.sosy_lab.java_smt.api.BooleanFormula)10 BooleanFormulaTransformationVisitor (org.sosy_lab.java_smt.api.visitors.BooleanFormulaTransformationVisitor)10 IntegerFormula (org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula)7 ImmutableList (com.google.common.collect.ImmutableList)1 Truth (com.google.common.truth.Truth)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 TruthJUnit.assume (com.google.common.truth.TruthJUnit.assume)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1 Set (java.util.Set)1 Stream (java.util.stream.Stream)1 Before (org.junit.Before)1 RunWith (org.junit.runner.RunWith)1 Parameterized (org.junit.runners.Parameterized)1