Search in sources :

Example 6 with CompleteMultiVariableContext

use of com.sri.ai.grinder.core.constraint.CompleteMultiVariableContext 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();
    Constraint constraint = new CompleteMultiVariableContext(theoryTestingSupport.getTheory(), context);
    for (Expression literal : And.getConjuncts(parse(conjunction))) {
        constraint = constraint.conjoin(literal, context);
        if (constraint.isContradiction()) {
            break;
        }
    }
    if (expected == null && !constraint.isContradiction()) {
        throw new AssertionError("Expected null but was <" + constraint + ">");
    } else if (expected != null && constraint.isContradiction()) {
        throw new AssertionError("Expected <" + expected + "> but was null");
    } else if (expected != null && !constraint.isContradiction() && !expected.equals(constraint)) {
        Simplifier interpreter = (e, c) -> theoryTestingSupport.getTheory().evaluate(e, c);
        // Simplifier interpreter = new Evaluator(theoryTestingSupport.getTheory());
        Expression equivalenceDefinition = apply(EQUIVALENCE, expected, constraint);
        Expression universallyQuantified = universallyQuantifyFreeVariables(equivalenceDefinition, context);
        Expression equivalent = interpreter.apply(universallyQuantified, context);
        if (equivalent.equals(FALSE)) {
            throw new Error("Expected <" + expected + "> but got <" + constraint + ">, which is not equivalent either");
        }
    }
}
Also used : Context(com.sri.ai.grinder.api.Context) CompleteMultiVariableContext(com.sri.ai.grinder.core.constraint.CompleteMultiVariableContext) CompleteMultiVariableContext(com.sri.ai.grinder.core.constraint.CompleteMultiVariableContext) 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) CompleteMultiVariableContext(com.sri.ai.grinder.core.constraint.CompleteMultiVariableContext) 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) SingleVariableEqualityConstraint(com.sri.ai.grinder.theory.equality.SingleVariableEqualityConstraint) Constraint(com.sri.ai.grinder.api.Constraint) Expression(com.sri.ai.expresso.api.Expression) Simplifier(com.sri.ai.grinder.rewriter.api.Simplifier)

Aggregations

Expression (com.sri.ai.expresso.api.Expression)6 Constraint (com.sri.ai.grinder.api.Constraint)6 Context (com.sri.ai.grinder.api.Context)6 CompleteMultiVariableContext (com.sri.ai.grinder.core.constraint.CompleteMultiVariableContext)6 TheoryTestingSupport (com.sri.ai.grinder.tester.TheoryTestingSupport)5 TrueContext (com.sri.ai.grinder.core.TrueContext)4 AbstractTheoryTestingSupport (com.sri.ai.grinder.core.constraint.AbstractTheoryTestingSupport)4 EqualityTheory (com.sri.ai.grinder.theory.equality.EqualityTheory)4 PropositionalTheory (com.sri.ai.grinder.theory.propositional.PropositionalTheory)3 Beta (com.google.common.annotations.Beta)2 Type (com.sri.ai.expresso.api.Type)2 Expressions.parse (com.sri.ai.expresso.helper.Expressions.parse)2 And (com.sri.ai.grinder.library.boole.And)2 Simplifier (com.sri.ai.grinder.rewriter.api.Simplifier)2 AbstractTheoryTest (com.sri.ai.test.grinder.theory.base.AbstractTheoryTest)2 Test (org.junit.Test)2 QuantifiedExpression (com.sri.ai.expresso.api.QuantifiedExpression)1 FALSE (com.sri.ai.expresso.helper.Expressions.FALSE)1 TRUE (com.sri.ai.expresso.helper.Expressions.TRUE)1 ZERO (com.sri.ai.expresso.helper.Expressions.ZERO)1