Search in sources :

Example 1 with EQUIVALENCE

use of com.sri.ai.grinder.sgdpllt.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();
    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 : CompleteMultiVariableContext(com.sri.ai.grinder.sgdpllt.core.constraint.CompleteMultiVariableContext) Context(com.sri.ai.grinder.sgdpllt.api.Context) CompleteMultiVariableContext(com.sri.ai.grinder.sgdpllt.core.constraint.CompleteMultiVariableContext) FALSE(com.sri.ai.expresso.helper.Expressions.FALSE) Categorical(com.sri.ai.expresso.type.Categorical) EQUIVALENCE(com.sri.ai.grinder.sgdpllt.library.FunctorConstants.EQUIVALENCE) HashMap(java.util.HashMap) Expression(com.sri.ai.expresso.api.Expression) GrinderUtil.universallyQuantifyFreeVariables(com.sri.ai.grinder.helper.GrinderUtil.universallyQuantifyFreeVariables) Constraint(com.sri.ai.grinder.sgdpllt.api.Constraint) Util.map(com.sri.ai.util.Util.map) SGDPLLTTester(com.sri.ai.grinder.sgdpllt.tester.SGDPLLTTester) Expressions.apply(com.sri.ai.expresso.helper.Expressions.apply) Expressions.parse(com.sri.ai.expresso.helper.Expressions.parse) Map(java.util.Map) CompleteMultiVariableContext(com.sri.ai.grinder.sgdpllt.core.constraint.CompleteMultiVariableContext) And(com.sri.ai.grinder.sgdpllt.library.boole.And) TheoryTestingSupport(com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport) Util.arrayList(com.sri.ai.util.Util.arrayList) Type(com.sri.ai.expresso.api.Type) Simplifier(com.sri.ai.grinder.sgdpllt.rewriter.api.Simplifier) Test(org.junit.Test) EqualityTheory(com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory) Context(com.sri.ai.grinder.sgdpllt.api.Context) Sum(com.sri.ai.grinder.sgdpllt.group.Sum) AbstractTheoryIncludingEqualityTest(com.sri.ai.test.grinder.sgdpllt.theory.base.AbstractTheoryIncludingEqualityTest) Beta(com.google.common.annotations.Beta) Max(com.sri.ai.grinder.sgdpllt.group.Max) SingleVariableEqualityConstraint(com.sri.ai.grinder.sgdpllt.theory.equality.SingleVariableEqualityConstraint) Assert(org.junit.Assert) Constraint(com.sri.ai.grinder.sgdpllt.api.Constraint) SingleVariableEqualityConstraint(com.sri.ai.grinder.sgdpllt.theory.equality.SingleVariableEqualityConstraint) Expression(com.sri.ai.expresso.api.Expression) Simplifier(com.sri.ai.grinder.sgdpllt.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 GrinderUtil.universallyQuantifyFreeVariables (com.sri.ai.grinder.helper.GrinderUtil.universallyQuantifyFreeVariables)1 Constraint (com.sri.ai.grinder.sgdpllt.api.Constraint)1 Context (com.sri.ai.grinder.sgdpllt.api.Context)1 CompleteMultiVariableContext (com.sri.ai.grinder.sgdpllt.core.constraint.CompleteMultiVariableContext)1 Max (com.sri.ai.grinder.sgdpllt.group.Max)1 Sum (com.sri.ai.grinder.sgdpllt.group.Sum)1 EQUIVALENCE (com.sri.ai.grinder.sgdpllt.library.FunctorConstants.EQUIVALENCE)1 And (com.sri.ai.grinder.sgdpllt.library.boole.And)1 Simplifier (com.sri.ai.grinder.sgdpllt.rewriter.api.Simplifier)1 SGDPLLTTester (com.sri.ai.grinder.sgdpllt.tester.SGDPLLTTester)1 TheoryTestingSupport (com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport)1 EqualityTheory (com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory)1 SingleVariableEqualityConstraint (com.sri.ai.grinder.sgdpllt.theory.equality.SingleVariableEqualityConstraint)1