Search in sources :

Example 1 with EQUIVALENCE

use of com.sri.ai.grinder.library.FunctorConstants.EQUIVALENCE 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

Beta (com.google.common.annotations.Beta)1 Expression (com.sri.ai.expresso.api.Expression)1 Type (com.sri.ai.expresso.api.Type)1 FALSE (com.sri.ai.expresso.helper.Expressions.FALSE)1 Expressions.apply (com.sri.ai.expresso.helper.Expressions.apply)1 Expressions.parse (com.sri.ai.expresso.helper.Expressions.parse)1 Categorical (com.sri.ai.expresso.type.Categorical)1 Constraint (com.sri.ai.grinder.api.Constraint)1 Context (com.sri.ai.grinder.api.Context)1 Max (com.sri.ai.grinder.group.Max)1 Sum (com.sri.ai.grinder.group.Sum)1 GrinderUtil.universallyQuantifyFreeVariables (com.sri.ai.grinder.helper.GrinderUtil.universallyQuantifyFreeVariables)1 EQUIVALENCE (com.sri.ai.grinder.library.FunctorConstants.EQUIVALENCE)1 And (com.sri.ai.grinder.library.boole.And)1 Simplifier (com.sri.ai.grinder.rewriter.api.Simplifier)1 SGDPLLTTester (com.sri.ai.grinder.tester.SGDPLLTTester)1 TheoryTestingSupport (com.sri.ai.grinder.tester.TheoryTestingSupport)1 EqualityTheory (com.sri.ai.grinder.theory.equality.EqualityTheory)1 SingleVariableEqualityConstraint (com.sri.ai.grinder.theory.equality.SingleVariableEqualityConstraint)1 AbstractTheoryIncludingEqualityTest (com.sri.ai.test.grinder.theory.base.AbstractTheoryIncludingEqualityTest)1