Search in sources :

Example 11 with TheoryTestingSupport

use of com.sri.ai.grinder.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.

the class UnificationStepSolverTest method advancedCompositeTest.

@Ignore("TODO - context implementation currently does not support these more advanced/indirect comparisons")
@Test
public void advancedCompositeTest() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(seededRandom, new CompoundTheory(new EqualityTheory(false, true), new DifferenceArithmeticTheory(false, true), new LinearRealArithmeticTheory(false, true), new PropositionalTheory()));
    // NOTE: passing explicit FunctionTypes will prevent the general variables' argument types being randomly changed.
    theoryTestingSupport.setVariableNamesAndTypesForTesting(map("P", BOOLEAN_TYPE, "Q", BOOLEAN_TYPE, "R", BOOLEAN_TYPE, "unary_prop/1", new FunctionType(BOOLEAN_TYPE, BOOLEAN_TYPE), "binary_prop/2", new FunctionType(BOOLEAN_TYPE, BOOLEAN_TYPE, BOOLEAN_TYPE), "S", TESTING_CATEGORICAL_TYPE, "T", TESTING_CATEGORICAL_TYPE, "U", TESTING_CATEGORICAL_TYPE, "unary_eq/1", new FunctionType(TESTING_CATEGORICAL_TYPE, TESTING_CATEGORICAL_TYPE), "binary_eq/2", new FunctionType(TESTING_CATEGORICAL_TYPE, TESTING_CATEGORICAL_TYPE, TESTING_CATEGORICAL_TYPE), "I", TESTING_INTEGER_INTERVAL_TYPE, "J", TESTING_INTEGER_INTERVAL_TYPE, "K", TESTING_INTEGER_INTERVAL_TYPE, "unary_dar/1", new FunctionType(TESTING_INTEGER_INTERVAL_TYPE, TESTING_INTEGER_INTERVAL_TYPE), "binary_dar/2", new FunctionType(TESTING_INTEGER_INTERVAL_TYPE, TESTING_INTEGER_INTERVAL_TYPE, TESTING_INTEGER_INTERVAL_TYPE), "X", TESTING_REAL_INTERVAL_TYPE, "Y", TESTING_REAL_INTERVAL_TYPE, "Z", TESTING_REAL_INTERVAL_TYPE, "unary_lra/1", new FunctionType(TESTING_REAL_INTERVAL_TYPE, TESTING_REAL_INTERVAL_TYPE), "binary_lra/2", new FunctionType(TESTING_REAL_INTERVAL_TYPE, TESTING_REAL_INTERVAL_TYPE, TESTING_REAL_INTERVAL_TYPE)));
    Context rootContext = theoryTestingSupport.makeContextWithTestingInformation();
    UnificationStepSolver unificationStepSolver = new UnificationStepSolver(parse("binary_prop(P, unary_prop(P))"), parse("binary_prop(unary_prop(Q), Q)"));
    Context localTestContext = rootContext.conjoinWithConjunctiveClause(parse("not P and Q and not unary_prop(Q) and unary_prop(P)"), rootContext);
    StepSolver.Step<Boolean> step = unificationStepSolver.step(localTestContext);
    Assert.assertEquals(false, step.itDepends());
    Assert.assertEquals(true, step.getValue());
    localTestContext = rootContext.conjoinWithConjunctiveClause(parse("P and Q and not unary_prop(Q) and unary_prop(P)"), rootContext);
    step = unificationStepSolver.step(localTestContext);
    Assert.assertEquals(false, step.itDepends());
    Assert.assertEquals(false, step.getValue());
}
Also used : Context(com.sri.ai.grinder.api.Context) EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) FunctionType(com.sri.ai.expresso.type.FunctionType) LinearRealArithmeticTheory(com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) StepSolver(com.sri.ai.grinder.api.StepSolver) UnificationStepSolver(com.sri.ai.grinder.theory.base.UnificationStepSolver) UnificationStepSolver(com.sri.ai.grinder.theory.base.UnificationStepSolver) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 12 with TheoryTestingSupport

use of com.sri.ai.grinder.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.

the class UnificationStepSolverTest method advancedPropositionalTest.

@Ignore("TODO - context implementation currently does not support these more advanced/indirect comparisons")
@Test
public void advancedPropositionalTest() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(seededRandom, new PropositionalTheory());
    // NOTE: passing explicit FunctionTypes will prevent the general variables' argument types being randomly changed.
    theoryTestingSupport.setVariableNamesAndTypesForTesting(map("P", BOOLEAN_TYPE, "Q", BOOLEAN_TYPE, "R", BOOLEAN_TYPE, "unary_prop/1", new FunctionType(BOOLEAN_TYPE, BOOLEAN_TYPE), "binary_prop/2", new FunctionType(BOOLEAN_TYPE, BOOLEAN_TYPE, BOOLEAN_TYPE)));
    Context rootContext = theoryTestingSupport.makeContextWithTestingInformation();
    UnificationStepSolver unificationStepSolver = new UnificationStepSolver(parse("binary_prop(P, unary_prop(P))"), parse("binary_prop(unary_prop(Q), Q)"));
    Context localTestContext = rootContext.conjoinWithConjunctiveClause(parse("not P and Q and not unary_prop(true) and unary_prop(false)"), rootContext);
    StepSolver.Step<Boolean> step = unificationStepSolver.step(localTestContext);
    Assert.assertEquals(false, step.itDepends());
    Assert.assertEquals(true, step.getValue());
}
Also used : Context(com.sri.ai.grinder.api.Context) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) FunctionType(com.sri.ai.expresso.type.FunctionType) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) StepSolver(com.sri.ai.grinder.api.StepSolver) UnificationStepSolver(com.sri.ai.grinder.theory.base.UnificationStepSolver) UnificationStepSolver(com.sri.ai.grinder.theory.base.UnificationStepSolver) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 13 with TheoryTestingSupport

use of com.sri.ai.grinder.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.

the class UnificationStepSolverTest method advancedLinearRealArithmeticTest.

@Ignore("TODO - context implementation currently does not support these more advanced/indirect comparisons")
@Test
public void advancedLinearRealArithmeticTest() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(seededRandom, new LinearRealArithmeticTheory(true, true));
    // NOTE: passing explicit FunctionTypes will prevent the general variables' argument types being randomly changed.
    theoryTestingSupport.setVariableNamesAndTypesForTesting(map("X", TESTING_REAL_INTERVAL_TYPE, "Y", TESTING_REAL_INTERVAL_TYPE, "Z", TESTING_REAL_INTERVAL_TYPE, "unary_lra/1", new FunctionType(TESTING_REAL_INTERVAL_TYPE, TESTING_REAL_INTERVAL_TYPE), "binary_lra/2", new FunctionType(TESTING_REAL_INTERVAL_TYPE, TESTING_REAL_INTERVAL_TYPE, TESTING_REAL_INTERVAL_TYPE)));
    Context rootContext = theoryTestingSupport.makeContextWithTestingInformation();
    UnificationStepSolver unificationStepSolver = new UnificationStepSolver(parse("binary_lra(X, unary_lra(X))"), parse("binary_lra(unary_lra(Y), Y)"));
    Context localTestContext = rootContext.conjoinWithConjunctiveClause(parse("X = 0 and Y = 1 and unary_lra(Y) = 0 and unary_lra(X) = 1"), rootContext);
    StepSolver.Step<Boolean> step = unificationStepSolver.step(localTestContext);
    Assert.assertEquals(false, step.itDepends());
    Assert.assertEquals(true, step.getValue());
    localTestContext = rootContext.conjoinWithConjunctiveClause(parse("X = 1 and Y = 1 and unary_lra(Y) = 0 and unary_lra(X) = 1"), rootContext);
    step = unificationStepSolver.step(localTestContext);
    Assert.assertEquals(false, step.itDepends());
    Assert.assertEquals(false, step.getValue());
    localTestContext = rootContext.conjoinWithConjunctiveClause(parse("X = 0 and Y = 1 and unary_lra(1) = 0 and unary_lra(0) = 1"), rootContext);
    step = unificationStepSolver.step(localTestContext);
    Assert.assertEquals(false, step.itDepends());
    Assert.assertEquals(true, step.getValue());
}
Also used : Context(com.sri.ai.grinder.api.Context) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) FunctionType(com.sri.ai.expresso.type.FunctionType) LinearRealArithmeticTheory(com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory) StepSolver(com.sri.ai.grinder.api.StepSolver) UnificationStepSolver(com.sri.ai.grinder.theory.base.UnificationStepSolver) UnificationStepSolver(com.sri.ai.grinder.theory.base.UnificationStepSolver) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 14 with TheoryTestingSupport

use of com.sri.ai.grinder.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.

the class UnificationStepSolverTest method advancedDifferenceArithmeticTest.

@Ignore("TODO - context implementation currently does not support these more advanced/indirect comparisons")
@Test
public void advancedDifferenceArithmeticTest() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(seededRandom, new DifferenceArithmeticTheory(true, true));
    // NOTE: passing explicit FunctionTypes will prevent the general variables' argument types being randomly changed.
    theoryTestingSupport.setVariableNamesAndTypesForTesting(map("I", TESTING_INTEGER_INTERVAL_TYPE, "J", TESTING_INTEGER_INTERVAL_TYPE, "K", TESTING_INTEGER_INTERVAL_TYPE, "unary_dar/1", new FunctionType(TESTING_INTEGER_INTERVAL_TYPE, TESTING_INTEGER_INTERVAL_TYPE), "binary_dar/2", new FunctionType(TESTING_INTEGER_INTERVAL_TYPE, TESTING_INTEGER_INTERVAL_TYPE, TESTING_INTEGER_INTERVAL_TYPE)));
    Context rootContext = theoryTestingSupport.makeContextWithTestingInformation();
    UnificationStepSolver unificationStepSolver = new UnificationStepSolver(parse("binary_dar(I, unary_dar(I))"), parse("binary_dar(unary_dar(J), J)"));
    Context localTestContext = rootContext.conjoinWithConjunctiveClause(parse("I = 0 and J = 1 and unary_dar(J) = 0 and unary_dar(I) = 1"), rootContext);
    StepSolver.Step<Boolean> step = unificationStepSolver.step(localTestContext);
    Assert.assertEquals(false, step.itDepends());
    Assert.assertEquals(true, step.getValue());
    localTestContext = rootContext.conjoinWithConjunctiveClause(parse("I = 1 and J = 1 and unary_dar(J) = 0 and unary_dar(I) = 1"), rootContext);
    step = unificationStepSolver.step(localTestContext);
    Assert.assertEquals(false, step.itDepends());
    Assert.assertEquals(false, step.getValue());
    localTestContext = rootContext.conjoinWithConjunctiveClause(parse("I = 0 and J = 1 and unary_dar(1) = 0 and unary_dar(0) = 1"), rootContext);
    step = unificationStepSolver.step(localTestContext);
    Assert.assertEquals(false, step.itDepends());
    Assert.assertEquals(true, step.getValue());
}
Also used : Context(com.sri.ai.grinder.api.Context) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) FunctionType(com.sri.ai.expresso.type.FunctionType) StepSolver(com.sri.ai.grinder.api.StepSolver) UnificationStepSolver(com.sri.ai.grinder.theory.base.UnificationStepSolver) UnificationStepSolver(com.sri.ai.grinder.theory.base.UnificationStepSolver) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 15 with TheoryTestingSupport

use of com.sri.ai.grinder.tester.TheoryTestingSupport in project aic-expresso by aic-sri-international.

the class CompoundTheoryWithDifferenceArithmeticTest method runCompleteSatisfiabilityTest.

/**
 * @param conjunction
 * @param expected
 */
private void runCompleteSatisfiabilityTest(String conjunction, Expression expected, Map<String, Type> variableNamesAndTypesForTesting) {
    TheoryTestingSupport equalityTheoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new EqualityTheory(true, true));
    equalityTheoryTestingSupport.setVariableNamesAndTypesForTesting(variableNamesAndTypesForTesting);
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), equalityTheoryTestingSupport, TheoryTestingSupport.make(makeRandom(), new PropositionalTheory()));
    Context context = theoryTestingSupport.makeContextWithTestingInformation();
    Constraint constraint = new CompleteMultiVariableContext(theoryTestingSupport.getTheory(), context);
    for (Expression literal : And.getConjuncts(parse(conjunction))) {
        constraint = constraint.conjoin(literal, context);
    }
    assertEquals(expected, constraint);
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) CompleteMultiVariableContext(com.sri.ai.grinder.core.constraint.CompleteMultiVariableContext) CompleteMultiVariableContext(com.sri.ai.grinder.core.constraint.CompleteMultiVariableContext) EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) Constraint(com.sri.ai.grinder.api.Constraint) Expression(com.sri.ai.expresso.api.Expression) AbstractTheoryTestingSupport(com.sri.ai.grinder.core.constraint.AbstractTheoryTestingSupport) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory)

Aggregations

TheoryTestingSupport (com.sri.ai.grinder.tester.TheoryTestingSupport)49 Test (org.junit.Test)42 Context (com.sri.ai.grinder.api.Context)36 Expression (com.sri.ai.expresso.api.Expression)26 DifferenceArithmeticTheory (com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory)22 EqualityTheory (com.sri.ai.grinder.theory.equality.EqualityTheory)20 PropositionalTheory (com.sri.ai.grinder.theory.propositional.PropositionalTheory)17 FunctionType (com.sri.ai.expresso.type.FunctionType)13 Type (com.sri.ai.expresso.api.Type)12 CompoundTheory (com.sri.ai.grinder.theory.compound.CompoundTheory)11 StepSolver (com.sri.ai.grinder.api.StepSolver)10 UnificationStepSolver (com.sri.ai.grinder.theory.base.UnificationStepSolver)10 AbstractTheoryTestingSupport (com.sri.ai.grinder.core.constraint.AbstractTheoryTestingSupport)9 LinearRealArithmeticTheory (com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory)9 LinkedHashMap (java.util.LinkedHashMap)7 Constraint (com.sri.ai.grinder.api.Constraint)6 CompleteMultiVariableContext (com.sri.ai.grinder.core.constraint.CompleteMultiVariableContext)6 Ignore (org.junit.Ignore)5 Categorical (com.sri.ai.expresso.type.Categorical)4 TrueContext (com.sri.ai.grinder.core.TrueContext)4