use of com.sri.ai.grinder.theory.compound.CompoundTheory in project aic-expresso by aic-sri-international.
the class CompoundTheoryWithDifferenceArithmeticTest method makeTheoryTestingSupport.
@Override
protected TheoryTestingSupport makeTheoryTestingSupport() {
TheoryTestingSupport result = TheoryTestingSupport.make(makeRandom(), new CompoundTheory(new EqualityTheory(false, true), new DifferenceArithmeticTheory(false, true), new PropositionalTheory()));
// using different testing variables and types to test distribution of testing information
// to sub constraint theories.
Categorical booleanType = BOOLEAN_TYPE;
Categorical dogsType = new Categorical("Dogs", 4, arrayList(parse("fido"), parse("rex")));
IntegerInterval oneTwoThree = new IntegerInterval(1, 3);
Map<String, Type> variablesAndTypes = map("F", booleanType, "G", booleanType, "R", dogsType, "S", dogsType, "T", oneTwoThree, "U", oneTwoThree);
result.setVariableNamesAndTypesForTesting(variablesAndTypes);
return result;
}
use of com.sri.ai.grinder.theory.compound.CompoundTheory in project aic-expresso by aic-sri-international.
the class FirstOfTest method runTest.
private void runTest(List<Rewriter> rewriters, Expression initial, Expression expected, Map<Expression, Expression> symbolsAndTypes) {
CompoundTheory theory = new CompoundTheory(new PropositionalTheory(), new DifferenceArithmeticTheory(false, true));
Context context = new TrueContext(theory);
context = context.makeCloneWithAdditionalRegisteredSymbolsAndTypes(symbolsAndTypes);
Rewriter firstOf = new FirstOf(rewriters);
Expression solution = firstOf.apply(initial, context);
System.out.println("Solution: " + solution);
assertEquals(expected, solution);
}
use of com.sri.ai.grinder.theory.compound.CompoundTheory in project aic-expresso by aic-sri-international.
the class RecursiveTest method runTest.
private void runTest(Rewriter rewriter, Expression initial, Expression expected, Map<Expression, Expression> symbolsAndTypes) {
CompoundTheory theory = new CompoundTheory(new PropositionalTheory(), new DifferenceArithmeticTheory(false, true));
Context context = new TrueContext(theory);
context = context.makeCloneWithAdditionalRegisteredSymbolsAndTypes(symbolsAndTypes);
Rewriter recursive = new Recursive(rewriter);
Expression solution = recursive.apply(initial, context);
System.out.println("Solution: " + solution);
assertEquals(expected, solution);
}
use of com.sri.ai.grinder.theory.compound.CompoundTheory in project aic-expresso by aic-sri-international.
the class SwitchTest method runTest.
private void runTest(Rewriter rewriter, Expression initial, Expression expected, Map<Expression, Expression> symbolsAndTypes) {
CompoundTheory theory = new CompoundTheory(new PropositionalTheory(), new DifferenceArithmeticTheory(false, true));
Context context = new TrueContext(theory);
context = context.makeCloneWithAdditionalRegisteredSymbolsAndTypes(symbolsAndTypes);
Rewriter recursive = new Recursive(rewriter);
Expression solution = recursive.apply(initial, context);
System.out.println("Solution: " + solution);
assertEquals(expected, solution);
}
use of com.sri.ai.grinder.theory.compound.CompoundTheory in project aic-expresso by aic-sri-international.
the class EvaluationTest method testEvaluationOfCardinalityExpressions.
@Test
public void testEvaluationOfCardinalityExpressions() {
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 = "| {{ (on I in 1..10) 3 : I != 4 and P }} |";
expected = parse("if P then 9 else 0");
runTest(expressionString, expected, context);
expressionString = "| I in 1..10 : I != 4 and P |";
expected = parse("if P then 9 else 0");
runTest(expressionString, expected, context);
expressionString = "| {{ (on ) 3 : I != 4 and P }} |";
expected = parse("if I != 4 then if P then 1 else 0 else 0");
runTest(expressionString, expected, context);
expressionString = "| : I != 4 and P |";
expected = parse("if I != 4 then if P then 1 else 0 else 0");
runTest(expressionString, expected, context);
expressionString = "| {{ (on ) 3 : P and not P }} |";
expected = parse("0");
runTest(expressionString, expected, context);
expressionString = "| : P and not P |";
expected = parse("0");
runTest(expressionString, expected, context);
expressionString = "| {{ (on I in 1..10, J in 1..2) 3 : I != 4 }} |";
expected = parse("18");
runTest(expressionString, expected, context);
expressionString = "| I in 1..10, J in 1..2 : I != 4 |";
expected = parse("18");
runTest(expressionString, expected, context);
expressionString = "| {{ (on I in 1..10, P in Boolean) 3 : I != 4 }} |";
expected = parse("18");
runTest(expressionString, expected, context);
expressionString = "| I in 1..10, P in Boolean: I != 4 |";
expected = parse("18");
runTest(expressionString, expected, context);
}
Aggregations