use of com.sri.ai.expresso.type.FunctionType in project aic-expresso by aic-sri-international.
the class UnificationStepSolverTest method advancedEqualityTest.
@Ignore("TODO - context implementation currently does not support these more advanced/indirect comparisons")
@Test
public void advancedEqualityTest() {
TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(seededRandom, new EqualityTheory(false, true));
// NOTE: passing explicit FunctionTypes will prevent the general variables' argument types being randomly changed.
theoryTestingSupport.setVariableNamesAndTypesForTesting(map("X", TESTING_CATEGORICAL_TYPE, "Y", TESTING_CATEGORICAL_TYPE, "Z", TESTING_CATEGORICAL_TYPE, "unary_eq/1", new FunctionType(TESTING_CATEGORICAL_TYPE, TESTING_CATEGORICAL_TYPE), "binary_eq/2", new FunctionType(TESTING_CATEGORICAL_TYPE, TESTING_CATEGORICAL_TYPE, TESTING_CATEGORICAL_TYPE)));
Context rootContext = theoryTestingSupport.makeContextWithTestingInformation();
UnificationStepSolver unificationStepSolver = new UnificationStepSolver(parse("binary_eq(X, unary_eq(X))"), parse("binary_eq(unary_eq(Y), Y)"));
Context localTestContext = rootContext.conjoinWithConjunctiveClause(parse("X = b and Y = a and unary_eq(Y) = b and unary_eq(X) = a"), rootContext);
StepSolver.Step<Boolean> step = unificationStepSolver.step(localTestContext);
Assert.assertEquals(false, step.itDepends());
Assert.assertEquals(true, step.getValue());
localTestContext = rootContext.conjoinWithConjunctiveClause(parse("X = a and Y = a and unary_eq(Y) = b and unary_eq(X) = a"), rootContext);
step = unificationStepSolver.step(localTestContext);
Assert.assertEquals(false, step.itDepends());
Assert.assertEquals(false, step.getValue());
localTestContext = rootContext.conjoinWithConjunctiveClause(parse("X = b and Y = a and unary_eq(a) = b and unary_eq(b) = a"), rootContext);
step = unificationStepSolver.step(localTestContext);
Assert.assertEquals(false, step.itDepends());
Assert.assertEquals(true, step.getValue());
}
use of com.sri.ai.expresso.type.FunctionType in project aic-expresso by aic-sri-international.
the class SetOfArgumentTuplesForFunctionOccurringInExpressionTest method setUp.
@Before
public void setUp() {
fName = parse("f");
fType = new FunctionType(new IntegerInterval("1..5"), new IntegerInterval("1..10"), new IntegerInterval("11..20"));
}
use of com.sri.ai.expresso.type.FunctionType in project aic-expresso by aic-sri-international.
the class InversionSimplifierTest method setUp.
@Before
public void setUp() {
context = new TrueContext(new CompoundTheory(new DifferenceArithmeticTheory(false, false), new TupleTheory()));
FunctionType gFunctionType = new FunctionType(new IntegerInterval("1..10"), new IntegerInterval("1..10"));
context = (Context) GrinderUtil.extendRegistryWith(map("g", gFunctionType.toString()), Arrays.asList(gFunctionType), context);
simplifier = new InversionSimplifier();
}
use of com.sri.ai.expresso.type.FunctionType in project aic-expresso by aic-sri-international.
the class TypeTest method testCardinality.
@Test
public void testCardinality() {
// i.e. 2^3
Assert.assertEquals(parse("8"), new FunctionType(GrinderUtil.BOOLEAN_TYPE, new IntegerInterval(0, 2)).cardinality());
// i.e. 3^(4*2)
Assert.assertEquals(parse("6561"), new FunctionType(new IntegerInterval(1, 3), new IntegerInterval(1, 4), new IntegerInterval(1, 2)).cardinality());
// i.e. 1 - the empty tuple
Assert.assertEquals(parse("1"), new TupleType().cardinality());
// i.e. 2x3x4
Assert.assertEquals(parse("24"), new TupleType(GrinderUtil.BOOLEAN_TYPE, new IntegerInterval(1, 3), new IntegerInterval(1, 4)).cardinality());
}
use of com.sri.ai.expresso.type.FunctionType in project aic-expresso by aic-sri-international.
the class TypeTest method testIterator.
@Test
public void testIterator() {
FunctionType fType;
// i.e. 2
fType = new FunctionType(new IntegerInterval(1, 2));
checkTypeIteration(fType, "lambda : 1", "lambda : 2");
// i.e. 2^2
fType = new FunctionType(new IntegerInterval(1, 2), new Categorical("Car", 2));
checkTypeIteration(fType, "lambda A1 in Car : if A1 = car1 then 1 else 1", "lambda A1 in Car : if A1 = car1 then 2 else 1", "lambda A1 in Car : if A1 = car1 then 1 else 2", "lambda A1 in Car : if A1 = car1 then 2 else 2");
// i.e. 2^(2*2)
fType = new FunctionType(new IntegerInterval(1, 2), new Categorical("Car", 2), new Categorical("Bike", 2));
checkTypeIteration(fType, "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 1 else if (A1 = car2) and (A2 = bike1) then 1 else if (A1 = car1) and (A2 = bike2) then 1 else 1", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 2 else if (A1 = car2) and (A2 = bike1) then 1 else if (A1 = car1) and (A2 = bike2) then 1 else 1", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 1 else if (A1 = car2) and (A2 = bike1) then 2 else if (A1 = car1) and (A2 = bike2) then 1 else 1", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 2 else if (A1 = car2) and (A2 = bike1) then 2 else if (A1 = car1) and (A2 = bike2) then 1 else 1", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 1 else if (A1 = car2) and (A2 = bike1) then 1 else if (A1 = car1) and (A2 = bike2) then 2 else 1", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 2 else if (A1 = car2) and (A2 = bike1) then 1 else if (A1 = car1) and (A2 = bike2) then 2 else 1", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 1 else if (A1 = car2) and (A2 = bike1) then 2 else if (A1 = car1) and (A2 = bike2) then 2 else 1", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 2 else if (A1 = car2) and (A2 = bike1) then 2 else if (A1 = car1) and (A2 = bike2) then 2 else 1", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 1 else if (A1 = car2) and (A2 = bike1) then 1 else if (A1 = car1) and (A2 = bike2) then 1 else 2", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 2 else if (A1 = car2) and (A2 = bike1) then 1 else if (A1 = car1) and (A2 = bike2) then 1 else 2", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 1 else if (A1 = car2) and (A2 = bike1) then 2 else if (A1 = car1) and (A2 = bike2) then 1 else 2", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 2 else if (A1 = car2) and (A2 = bike1) then 2 else if (A1 = car1) and (A2 = bike2) then 1 else 2", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 1 else if (A1 = car2) and (A2 = bike1) then 1 else if (A1 = car1) and (A2 = bike2) then 2 else 2", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 2 else if (A1 = car2) and (A2 = bike1) then 1 else if (A1 = car1) and (A2 = bike2) then 2 else 2", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 1 else if (A1 = car2) and (A2 = bike1) then 2 else if (A1 = car1) and (A2 = bike2) then 2 else 2", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 2 else if (A1 = car2) and (A2 = bike1) then 2 else if (A1 = car1) and (A2 = bike2) then 2 else 2");
// i.e. 0
TupleType tType = new TupleType();
checkTypeIteration(tType, "()");
// i.e. 3
tType = new TupleType(new IntegerInterval(1, 3));
checkTypeIteration(tType, "tuple(1)", "tuple(2)", "tuple(3)");
// i.e. 2x3
tType = new TupleType(GrinderUtil.BOOLEAN_TYPE, new IntegerInterval(1, 3));
checkTypeIteration(tType, "(true, 1)", "(false, 1)", "(true, 2)", "(false, 2)", "(true, 3)", "(false, 3)");
}
Aggregations