use of com.sri.ai.grinder.sgdpllt.api.Context 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());
}
use of com.sri.ai.grinder.sgdpllt.api.Context 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());
}
use of com.sri.ai.grinder.sgdpllt.api.Context 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());
}
use of com.sri.ai.grinder.sgdpllt.api.Context in project aic-expresso by aic-sri-international.
the class SwitchTest method testSimpleSwitchRewriter.
@Test
public void testSimpleSwitchRewriter() {
RewriterFromStepMaker baseRewriterSum = (Expression e, Context c) -> {
int argument1 = e.get(0).intValue();
int argument2 = e.get(1).intValue();
Symbol resultValue = DefaultSymbol.createSymbol(argument1 + argument2);
return new Solution(resultValue);
};
RewriterFromStepMaker baseRewriterSubtraction = (Expression e, Context c) -> {
int argument1 = e.get(0).intValue();
int argument2 = e.get(1).intValue();
Symbol resultValue = DefaultSymbol.createSymbol(argument1 - argument2);
return new Solution(resultValue);
};
Switch rewriter = new Switch<String>(e -> e.getFunctor() != null ? e.getFunctor().toString() : "", map("+", baseRewriterSum, "-", baseRewriterSubtraction));
Expression initial;
Expression expected;
initial = parse("7");
expected = parse("7");
runTest(rewriter, initial, expected, map());
initial = parse("10 - 7");
expected = parse("3");
runTest(rewriter, initial, expected, map());
initial = parse("10 + 3");
expected = parse("13");
runTest(rewriter, initial, expected, map());
}
use of com.sri.ai.grinder.sgdpllt.api.Context in project aic-expresso by aic-sri-international.
the class EvaluationTest method testEvaluationOfGroupOperationsOnSets.
@Test
public void testEvaluationOfGroupOperationsOnSets() {
TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new CompoundTheory(new EqualityTheory(false, true), new DifferenceArithmeticTheory(false, true), new PropositionalTheory()));
Map<String, Type> variablesAndTypes = new LinkedHashMap<>(theoryTestingSupport.getVariableNamesAndTypesForTesting());
Type booleanType = variablesAndTypes.get("P");
variablesAndTypes.put("S", booleanType);
variablesAndTypes.put("T", booleanType);
variablesAndTypes.put("U", booleanType);
theoryTestingSupport.setVariableNamesAndTypesForTesting(variablesAndTypes);
Context context = theoryTestingSupport.makeContextWithTestingInformation();
String expressionString;
Expression expected;
expressionString = "sum( {{ (on I in 1..10) 3 : I != 4 and P }} )";
expected = parse("if P then 27 else 0");
runTest(expressionString, expected, context);
expressionString = "sum( {{ (on ) 3 : I != 4 and P }} )";
expected = parse("if I != 4 then if P then 3 else 0 else 0");
runTest(expressionString, expected, context);
expressionString = "sum( {{ (on ) 3 : P and not P }} )";
expected = parse("0");
runTest(expressionString, expected, context);
expressionString = "sum( {{ (on I in 1..10, J in 1..2) 3 : I != 4 }} )";
expected = parse("54");
runTest(expressionString, expected, context);
expressionString = "sum( {{ (on I in 1..10, P in Boolean) 3 : I != 4 }} )";
expected = parse("54");
runTest(expressionString, expected, context);
expressionString = "max( {{ (on I in 1..10) 3 : I != 4 and P }} )";
expected = parse("if P then 3 else -infinity");
runTest(expressionString, expected, context);
expressionString = "max( {{ (on ) 3 : I != 4 and P }} )";
expected = parse("if I != 4 then if P then 3 else -infinity else -infinity");
runTest(expressionString, expected, context);
expressionString = "max( {{ (on ) 3 : P and not P }} )";
expected = parse("-infinity");
runTest(expressionString, expected, context);
expressionString = "max( {{ (on I in 1..10, J in 1..2) 3 : I != 4 }} )";
expected = parse("3");
runTest(expressionString, expected, context);
expressionString = "max( {{ (on I in 1..10, P in Boolean) 3 : I != 4 }} )";
expected = parse("3");
runTest(expressionString, expected, context);
}
Aggregations