use of com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory in project aic-expresso by aic-sri-international.
the class BasicTest method debug.
private void debug(Expression problem) {
Theory theory = new DifferenceArithmeticTheory(true, true);
Context context = new TrueContext(theory);
context = context.putGlobalObject(BRUTE_FORCE_CHECKING_OF_NON_CONDITIONAL_PROBLEMS, "Yes");
Expression symbolicSolution = theory.evaluate(problem, context);
println(symbolicSolution);
BruteForceInterpreter bruteForceInterpreter = new BruteForceCommonInterpreter();
Expression bruteForceSolution = bruteForceInterpreter.apply(problem, context);
println(bruteForceSolution);
Assert.assertEquals(bruteForceSolution, symbolicSolution);
}
use of com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory in project aic-expresso by aic-sri-international.
the class BasicTest method runIsLiteralTest.
private void runIsLiteralTest(Expression expression, boolean expected, Context context) {
DifferenceArithmeticTheory theory = new DifferenceArithmeticTheory(false, true);
boolean isLiteral = theory.isLiteral(expression, context);
assertEquals(expected, isLiteral);
}
use of com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory in project aic-expresso by aic-sri-international.
the class SummationOnDifferenceArithmeticAndPolynomialStepSolverTest method simpleBodyTest.
@Test
public void simpleBodyTest() {
TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new DifferenceArithmeticTheory(true, true));
Context context = theoryTestingSupport.makeContextWithTestingInformation();
Expression variable;
String constraintString;
Expression body;
Expression expected;
variable = parse("I");
body = parse("I");
constraintString = "true";
expected = parse("10");
runTest(variable, constraintString, body, expected, context);
constraintString = "I != 3";
expected = parse("7");
runTest(variable, constraintString, body, expected, context);
constraintString = "I < 3";
expected = parse("3");
runTest(variable, constraintString, body, expected, context);
constraintString = "false";
expected = parse("0");
runTest(variable, constraintString, body, expected, context);
constraintString = "I > 3 and I < 3";
expected = parse("0");
runTest(variable, constraintString, body, expected, context);
constraintString = "I > 1 and I < 3 and I != 2";
expected = parse("0");
runTest(variable, constraintString, body, expected, context);
}
use of com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory in project aic-expresso by aic-sri-international.
the class SummationOnDifferenceArithmeticAndPolynomialStepSolverTest method polynomialBodyTest.
@Test
public void polynomialBodyTest() {
TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new DifferenceArithmeticTheory(true, true));
Context context = theoryTestingSupport.makeContextWithTestingInformation();
Expression variable;
String constraintString;
Expression body;
Expression expected;
variable = parse("I");
body = parse("I^2 - I + 1");
constraintString = "true";
expected = parse("25");
runTest(variable, constraintString, body, expected, context);
constraintString = "I != 3";
expected = parse("18");
runTest(variable, constraintString, body, expected, context);
constraintString = "I < 3";
expected = parse("5");
runTest(variable, constraintString, body, expected, context);
constraintString = "false";
expected = parse("0");
runTest(variable, constraintString, body, expected, context);
constraintString = "I > 3 and I < 3";
expected = parse("0");
runTest(variable, constraintString, body, expected, context);
constraintString = "I > 1 and I < 3 and I != 2";
expected = parse("0");
runTest(variable, constraintString, body, expected, context);
}
use of com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory in project aic-expresso by aic-sri-international.
the class ValuesOfSingleVariableDifferenceArithmeticConstraintStepSolverTest method test.
@Test
public void test() {
TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new DifferenceArithmeticTheory(true, true));
theoryTestingSupport.setVariableNamesAndTypesForTesting(map("I", new IntegerInterval(0, 4), "J", new IntegerInterval(0, 4), "K", new IntegerInterval(0, 4)));
Context context = theoryTestingSupport.makeContextWithTestingInformation();
Expression variable;
String constraintString;
Expression expected;
variable = parse("I");
constraintString = "true";
expected = parse("aboveAndUpTo(-1, 4)");
runTest(variable, constraintString, expected, context);
variable = parse("I");
constraintString = "false";
expected = parse("{}");
runTest(variable, constraintString, expected, context);
variable = parse("I");
constraintString = "I < 3 and J > I";
expected = parse("if 3 > J then if 0 < J then aboveAndUpTo(-1, J - 1) else {} else aboveAndUpTo(-1, 2)");
runTest(variable, constraintString, expected, context);
variable = parse("I");
constraintString = "I < 3 and J > I and I != 2";
expected = parse("if 3 > J then if 0 < J then aboveAndUpTo(-1, J - 1) else {} else aboveAndUpTo(-1, 2) - { 2 }");
runTest(variable, constraintString, expected, context);
variable = parse("I");
constraintString = "I < 3 and J > I and I != 2 and I != K";
expected = parse("if 3 > J then if 0 < J then if K + 1 <= J then aboveAndUpTo(-1, J - 1) - { K } else aboveAndUpTo(-1, J - 1) else {} else if K <= 2 then if 2 = K then aboveAndUpTo(-1, 2) - { K } else aboveAndUpTo(-1, 2) - { 2, K } else aboveAndUpTo(-1, 2) - { 2 }");
runTest(variable, constraintString, expected, context);
}
Aggregations