use of com.sri.ai.grinder.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 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 1..2 -> Boolean, g in 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 1..2 -> Boolean, g in 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 1..2 -> Boolean, g in 1..2 -> Boolean) if f(1) then 2 else 3 }} )";
expected = parse("40");
runTest(expressionString, expected, context);
expressionString = "sum({{ (on f in 1..2 -> Boolean) if f(1) then 2 else 3 }} )";
expected = parse("10");
runTest(expressionString, expected, context);
expressionString = "sum({{ (on f in 1..2 -> 1..2) if f(1) = 1 then 2 else 3 }} )";
expected = parse("10");
runTest(expressionString, expected, context);
expressionString = "sum({{ (on f in 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 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 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 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 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);
}
use of com.sri.ai.grinder.theory.function.BruteForceFunctionTheory in project aic-expresso by aic-sri-international.
the class BasicTest method debug.
public void debug(Expression problem, Expression expectedSolution) {
CompoundTheory theory = new CompoundTheory(new EqualityTheory(false, true), new DifferenceArithmeticTheory(false, false), new LinearRealArithmeticTheory(false, false), new TupleTheory(), new PropositionalTheory(), new BruteForceFunctionTheory());
Context context = new TrueContext(theory);
context = context.makeNewContextWithAddedType(BOOLEAN_TYPE);
context = context.makeCloneWithAdditionalRegisteredSymbolsAndTypes(map(makeSymbol("P"), makeSymbol("Boolean")));
Expression symbolicSolution = theory.evaluate(problem, context);
println(symbolicSolution);
Assert.assertEquals(expectedSolution, symbolicSolution);
}
use of com.sri.ai.grinder.theory.function.BruteForceFunctionTheory in project aic-expresso by aic-sri-international.
the class SymbolicShell method makeTheory.
private static Theory makeTheory() {
Theory theory = new CompoundTheory(new EqualityTheory(false, true), new DifferenceArithmeticTheory(false, false), new LinearRealArithmeticTheory(false, false), new TupleTheory(), new PropositionalTheory(), new BruteForceFunctionTheory());
theory = new BruteForceFallbackTheory(theory);
return theory;
}
Aggregations