use of com.sri.ai.grinder.sgdpllt.theory.function.BruteForceFunctionTheory in project aic-expresso by aic-sri-international.
the class EvaluationTest method testEvaluationOfQuantifiersOverFunctions.
@Test
public void testEvaluationOfQuantifiersOverFunctions() {
TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new CompoundTheory(new EqualityTheory(false, true), new DifferenceArithmeticTheory(false, true), new PropositionalTheory(), new BruteForceFunctionTheory()));
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 f in '->'(x(0..2), Boolean)) if f(0) and f(1) then 2 else 3 : f(2) }} )";
// 2+3+3+3
expected = parse("11");
runTest(expressionString, expected, context);
expressionString = "sum({{ (on f in '->'(x(1..2), Boolean), g in '->'(x(1..2), Boolean)) if f(1) and g(2) then 2 else 3 : f(2) }} )";
expected = parse("22");
runTest(expressionString, expected, context);
expressionString = "sum({{ (on f in '->'(x(1..2), Boolean), g in '->'(x(1..2), Boolean)) if f(1) and g(2) then 2 else 3 }} )";
expected = parse("44");
runTest(expressionString, expected, context);
expressionString = "sum({{ (on f in '->'(x(1..2), Boolean), g in '->'(x(1..2), Boolean)) if f(1) then 2 else 3 }} )";
expected = parse("40");
runTest(expressionString, expected, context);
expressionString = "sum({{ (on f in '->'(x(1..2), Boolean)) if f(1) then 2 else 3 }} )";
expected = parse("10");
runTest(expressionString, expected, context);
expressionString = "sum({{ (on f in '->'(x(1..2), 1..2)) if f(1) = 1 then 2 else 3 }} )";
expected = parse("10");
runTest(expressionString, expected, context);
expressionString = "sum({{ (on f in '->'(x(1..2), 1..2)) f(1) }} )";
expected = parse("6");
runTest(expressionString, expected, context);
expressionString = "sum({{ (on f in '->'(1..2)) f() }} )";
expected = parse("3");
runTest(expressionString, expected, context);
expressionString = "sum({{ (on f in '->'(1..2)) f }} )";
expected = parse("(lambda : 1) + (lambda : 2)");
runTest(expressionString, expected, context);
expressionString = "product( {{ (on f in '->'(x(0..2), Boolean)) if f(0) and f(1) then 2 else 3 : f(2) }} )";
// 2*3*3*3
expected = parse("54");
runTest(expressionString, expected, context);
expressionString = "max( {{ (on f in '->'(x(0..2), Boolean)) if f(0) and f(1) then 2 else 3 : f(2) }} )";
expected = parse("3");
runTest(expressionString, expected, context);
expressionString = "| f in '->'(0..2, Boolean) : f(0) |";
expected = parse("4");
runTest(expressionString, expected, context);
expressionString = "| f in '->'(x(0..2), Boolean) : f(0) |";
expected = parse("4");
runTest(expressionString, expected, context);
expressionString = "| f in 0..2 -> Boolean : f(0) |";
expected = parse("4");
runTest(expressionString, expected, context);
expressionString = "| f in '->'(x(0..2, 0..2), Boolean) : f(0, 0) |";
expected = parse("256");
runTest(expressionString, expected, context);
expressionString = "| f in 0..2 x 0..2 -> Boolean : f(0, 0) |";
expected = parse("256");
runTest(expressionString, expected, context);
expressionString = "for all f in '->'(x(0..2), Boolean) : f(0)";
expected = parse("false");
runTest(expressionString, expected, context);
expressionString = "for all f in '->'(x(0..2), Boolean) : (f(0) or not f(0)) and P";
expected = parse("P");
runTest(expressionString, expected, context);
expressionString = "there exists f in '->'(x(0..2), Boolean) : f(0)";
expected = parse("true");
runTest(expressionString, expected, context);
}
Aggregations