Search in sources :

Example 1 with BruteForceFunctionTheory

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);
}
Also used : Context(com.sri.ai.grinder.sgdpllt.api.Context) EqualityTheory(com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory) BruteForceFunctionTheory(com.sri.ai.grinder.sgdpllt.theory.function.BruteForceFunctionTheory) Type(com.sri.ai.expresso.api.Type) Expression(com.sri.ai.expresso.api.Expression) TheoryTestingSupport(com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) PropositionalTheory(com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

Expression (com.sri.ai.expresso.api.Expression)1 Type (com.sri.ai.expresso.api.Type)1 Context (com.sri.ai.grinder.sgdpllt.api.Context)1 TheoryTestingSupport (com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport)1 CompoundTheory (com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory)1 DifferenceArithmeticTheory (com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory)1 EqualityTheory (com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory)1 BruteForceFunctionTheory (com.sri.ai.grinder.sgdpllt.theory.function.BruteForceFunctionTheory)1 PropositionalTheory (com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory)1 LinkedHashMap (java.util.LinkedHashMap)1 Test (org.junit.Test)1