Search in sources :

Example 11 with Simplifier

use of com.sri.ai.grinder.rewriter.api.Simplifier in project aic-expresso by aic-sri-international.

the class AbstractEqualityConstraintTest method runCompleteSatisfiabilityTest.

/**
 * @param conjunction
 * @param expected
 */
private void runCompleteSatisfiabilityTest(String conjunction, Expression expected, TheoryTestingSupport theoryTestingSupport) {
    Context context = theoryTestingSupport.makeContextWithTestingInformation();
    for (Expression literal : And.getConjuncts(parse(conjunction))) {
        context = context.conjoin(literal, context);
        if (context.isContradiction()) {
            break;
        }
    }
    if (expected == null && !context.isContradiction()) {
        throw new AssertionError("Expected null but was <" + context + ">");
    } else if (expected != null && context.isContradiction()) {
        throw new AssertionError("Expected <" + expected + "> but was null");
    } else if (expected != null && !context.isContradiction() && !expected.equals(context)) {
        Simplifier interpreter = (e, c) -> theoryTestingSupport.getTheory().evaluate(e, c);
        // Simplifier interpreter = new Evaluator(theoryTestingSupport.getTheory());
        Expression equivalenceDefinition = apply(EQUIVALENCE, expected, context);
        Expression universallyQuantified = universallyQuantifyFreeVariables(equivalenceDefinition, context);
        Expression equivalent = interpreter.apply(universallyQuantified, context);
        if (equivalent.equals(FALSE)) {
            throw new Error("Expected <" + expected + "> but got <" + context + ">, which is not equivalent either");
        }
    }
}
Also used : Context(com.sri.ai.grinder.api.Context) FALSE(com.sri.ai.expresso.helper.Expressions.FALSE) Categorical(com.sri.ai.expresso.type.Categorical) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) HashMap(java.util.HashMap) Expression(com.sri.ai.expresso.api.Expression) GrinderUtil.universallyQuantifyFreeVariables(com.sri.ai.grinder.helper.GrinderUtil.universallyQuantifyFreeVariables) SGDPLLTTester(com.sri.ai.grinder.tester.SGDPLLTTester) And(com.sri.ai.grinder.library.boole.And) Util.map(com.sri.ai.util.Util.map) Expressions.apply(com.sri.ai.expresso.helper.Expressions.apply) SingleVariableEqualityConstraint(com.sri.ai.grinder.theory.equality.SingleVariableEqualityConstraint) Expressions.parse(com.sri.ai.expresso.helper.Expressions.parse) Map(java.util.Map) Context(com.sri.ai.grinder.api.Context) AbstractTheoryIncludingEqualityTest(com.sri.ai.test.grinder.theory.base.AbstractTheoryIncludingEqualityTest) Util.arrayList(com.sri.ai.util.Util.arrayList) Max(com.sri.ai.grinder.group.Max) EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) Type(com.sri.ai.expresso.api.Type) EQUIVALENCE(com.sri.ai.grinder.library.FunctorConstants.EQUIVALENCE) Test(org.junit.Test) Beta(com.google.common.annotations.Beta) Sum(com.sri.ai.grinder.group.Sum) Simplifier(com.sri.ai.grinder.rewriter.api.Simplifier) Assert(org.junit.Assert) Constraint(com.sri.ai.grinder.api.Constraint) Expression(com.sri.ai.expresso.api.Expression) Simplifier(com.sri.ai.grinder.rewriter.api.Simplifier)

Aggregations

Simplifier (com.sri.ai.grinder.rewriter.api.Simplifier)11 Expression (com.sri.ai.expresso.api.Expression)10 Test (org.junit.Test)8 Expressions.parse (com.sri.ai.expresso.helper.Expressions.parse)5 Context (com.sri.ai.grinder.api.Context)5 TupleDisequalitySimplifier (com.sri.ai.grinder.theory.tuple.rewriter.TupleDisequalitySimplifier)5 TupleEqualitySimplifier (com.sri.ai.grinder.theory.tuple.rewriter.TupleEqualitySimplifier)5 TupleGetSimplifier (com.sri.ai.grinder.theory.tuple.rewriter.TupleGetSimplifier)5 TupleQuantifierSimplifier (com.sri.ai.grinder.theory.tuple.rewriter.TupleQuantifierSimplifier)5 TupleSetSimplifier (com.sri.ai.grinder.theory.tuple.rewriter.TupleSetSimplifier)5 TupleValuedFreeVariablesSimplifier (com.sri.ai.grinder.theory.tuple.rewriter.TupleValuedFreeVariablesSimplifier)5 Beta (com.google.common.annotations.Beta)4 Expressions.makeSymbol (com.sri.ai.expresso.helper.Expressions.makeSymbol)4 Type (com.sri.ai.expresso.api.Type)3 Constraint (com.sri.ai.grinder.api.Constraint)3 SingleVariableConstraint (com.sri.ai.grinder.api.SingleVariableConstraint)3 Theory (com.sri.ai.grinder.api.Theory)3 DefaultSingleQuantifierEliminationProblem (com.sri.ai.grinder.core.solver.DefaultSingleQuantifierEliminationProblem)3 And (com.sri.ai.grinder.library.boole.And)3 BinaryFunction (com.sri.ai.util.base.BinaryFunction)3