Search in sources :

Example 1 with TraversalProcess

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

the class RecursiveFormulaVisitorImpl method visitFunction.

@Override
public TraversalProcess visitFunction(Formula pF, List<Formula> pArgs, FunctionDeclaration<?> pFunctionDeclaration) {
    TraversalProcess result = delegate.visitFunction(pF, pArgs, pFunctionDeclaration);
    addToQueueIfNecessary(result, pArgs);
    return result;
}
Also used : TraversalProcess(org.sosy_lab.java_smt.api.visitors.TraversalProcess)

Example 2 with TraversalProcess

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

the class RecursiveFormulaVisitorImpl method visitQuantifier.

@Override
public TraversalProcess visitQuantifier(BooleanFormula pF, Quantifier pQuantifier, List<Formula> boundVars, BooleanFormula pBody) {
    TraversalProcess result = delegate.visitQuantifier(pF, pQuantifier, boundVars, pBody);
    addToQueueIfNecessary(result, ImmutableList.of(pBody));
    return result;
}
Also used : TraversalProcess(org.sosy_lab.java_smt.api.visitors.TraversalProcess)

Example 3 with TraversalProcess

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

the class SolverVisitorTest method testVisitingTrue.

@Test
public void testVisitingTrue() {
    // Check that "true" is correctly treated as a constant.
    BooleanFormula t = bmgr.makeBoolean(true);
    final List<Boolean> containsTrue = new ArrayList<>();
    mgr.visitRecursively(t, new DefaultFormulaVisitor<>() {

        @Override
        protected TraversalProcess visitDefault(Formula f) {
            return TraversalProcess.CONTINUE;
        }

        @Override
        public TraversalProcess visitConstant(Formula f, Object o) {
            if (f.equals(bmgr.makeBoolean(true))) {
                containsTrue.add(true);
            }
            return TraversalProcess.CONTINUE;
        }
    });
    assertThat(containsTrue).isNotEmpty();
}
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) ArrayList(java.util.ArrayList) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) TraversalProcess(org.sosy_lab.java_smt.api.visitors.TraversalProcess) Test(org.junit.Test)

Example 4 with TraversalProcess

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

the class SolverVisitorTest method extractionDeclarations.

@Test
public void extractionDeclarations() {
    requireIntegers();
    // Create the variables and uf
    IntegerFormula a = imgr.makeVariable("a");
    IntegerFormula b = imgr.makeVariable("b");
    IntegerFormula ab = imgr.add(a, b);
    BooleanFormula uf1 = fmgr.declareAndCallUF("testFunc", FormulaType.BooleanType, a, b, ab);
    BooleanFormula uf2 = fmgr.declareAndCallUF("testFunc", FormulaType.BooleanType, ab, b, a);
    BooleanFormula f = bmgr.and(uf1, uf2);
    final Collection<Formula> usedArgs = new LinkedHashSet<>();
    final List<FunctionDeclaration<?>> usedDecls = new ArrayList<>();
    FormulaVisitor<TraversalProcess> argCollectingVisitor = new DefaultFormulaVisitor<>() {

        @Override
        public TraversalProcess visitFunction(Formula pF, List<Formula> args, FunctionDeclaration<?> pFunctionDeclaration) {
            usedArgs.addAll(args);
            usedDecls.add(pFunctionDeclaration);
            return visitDefault(pF);
        }

        @Override
        protected TraversalProcess visitDefault(Formula pF) {
            return TraversalProcess.CONTINUE;
        }
    };
    mgr.visitRecursively(f, argCollectingVisitor);
    // check general stuff about variables, copied from above
    assertThat(usedArgs).hasSize(5);
    assertThat(usedArgs).containsExactly(uf1, uf2, a, b, ab);
    Map<String, Formula> vars = mgr.extractVariables(f);
    assertThat(vars).hasSize(2);
    assertThat(vars.keySet()).containsExactly("a", "b");
    Map<String, Formula> varsUfs = mgr.extractVariablesAndUFs(f);
    assertThat(varsUfs).hasSize(3);
    assertThat(varsUfs.keySet()).containsExactly("a", "b", "testFunc");
    // check correct traversal order of the functions
    assertThat(usedDecls).hasSize(4);
    assertThat(usedDecls.get(0).getKind()).isEqualTo(FunctionDeclarationKind.AND);
    assertThat(usedDecls.get(1).getName()).isEqualTo("testFunc");
    assertThat(usedDecls.get(2).getKind()).isEqualTo(FunctionDeclarationKind.ADD);
    assertThat(usedDecls.get(3).getName()).isEqualTo("testFunc");
    // check UF-equality. This check went wrong in CVC4 and was fixed.
    assertThat(usedDecls.get(1)).isEqualTo(usedDecls.get(3));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IntegerFormula(org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula) ArrayList(java.util.ArrayList) TraversalProcess(org.sosy_lab.java_smt.api.visitors.TraversalProcess) DefaultFormulaVisitor(org.sosy_lab.java_smt.api.visitors.DefaultFormulaVisitor) 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) FunctionDeclaration(org.sosy_lab.java_smt.api.FunctionDeclaration) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Test(org.junit.Test)

Example 5 with TraversalProcess

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

the class UfElimination method isQuantified.

private boolean isQuantified(Formula f) {
    AtomicBoolean result = new AtomicBoolean();
    fmgr.visitRecursively(f, new DefaultFormulaVisitor<>() {

        @Override
        protected TraversalProcess visitDefault(Formula pF) {
            return TraversalProcess.CONTINUE;
        }

        @Override
        public TraversalProcess visitQuantifier(BooleanFormula pF, Quantifier pQ, List<Formula> pBoundVariables, BooleanFormula pBody) {
            result.set(true);
            return TraversalProcess.ABORT;
        }
    });
    return result.get();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) NumeralFormula(org.sosy_lab.java_smt.api.NumeralFormula) IntegerFormula(org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula) StringFormula(org.sosy_lab.java_smt.api.StringFormula) ArrayFormula(org.sosy_lab.java_smt.api.ArrayFormula) FloatingPointFormula(org.sosy_lab.java_smt.api.FloatingPointFormula) BitvectorFormula(org.sosy_lab.java_smt.api.BitvectorFormula) Formula(org.sosy_lab.java_smt.api.Formula) Quantifier(org.sosy_lab.java_smt.api.QuantifiedFormulaManager.Quantifier) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) TraversalProcess(org.sosy_lab.java_smt.api.visitors.TraversalProcess)

Aggregations

TraversalProcess (org.sosy_lab.java_smt.api.visitors.TraversalProcess)10 BooleanFormula (org.sosy_lab.java_smt.api.BooleanFormula)8 BitvectorFormula (org.sosy_lab.java_smt.api.BitvectorFormula)7 FloatingPointFormula (org.sosy_lab.java_smt.api.FloatingPointFormula)7 Formula (org.sosy_lab.java_smt.api.Formula)7 IntegerFormula (org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula)7 StringFormula (org.sosy_lab.java_smt.api.StringFormula)7 Test (org.junit.Test)6 RegexFormula (org.sosy_lab.java_smt.api.RegexFormula)6 LinkedHashSet (java.util.LinkedHashSet)4 HashSet (java.util.HashSet)3 ArrayList (java.util.ArrayList)2 ArrayFormula (org.sosy_lab.java_smt.api.ArrayFormula)2 DefaultFormulaVisitor (org.sosy_lab.java_smt.api.visitors.DefaultFormulaVisitor)2 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 FloatingPointRoundingModeFormula (org.sosy_lab.java_smt.api.FloatingPointRoundingModeFormula)1 FunctionDeclaration (org.sosy_lab.java_smt.api.FunctionDeclaration)1 NumeralFormula (org.sosy_lab.java_smt.api.NumeralFormula)1