Search in sources :

Example 1 with FunctionType

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());
}
Also used : FunctionType(com.sri.ai.expresso.type.FunctionType) IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) TupleType(com.sri.ai.expresso.type.TupleType) Test(org.junit.Test)

Example 2 with FunctionType

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)");
}
Also used : FunctionType(com.sri.ai.expresso.type.FunctionType) IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) TupleType(com.sri.ai.expresso.type.TupleType) Categorical(com.sri.ai.expresso.type.Categorical) Test(org.junit.Test)

Example 3 with FunctionType

use of com.sri.ai.expresso.type.FunctionType in project aic-expresso by aic-sri-international.

the class GrinderUtilTest method testIsRealIntervalSubtypeOf.

@Test
public void testIsRealIntervalSubtypeOf() {
    RealInterval realInterval = new RealInterval("Real");
    Assert.assertFalse(isTypeSubtypeOf(realInterval, BOOLEAN_TYPE));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, INTEGER_TYPE));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, REAL_TYPE));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("Integer")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("0..4")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("Real")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[-0.5;4.5]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new FunctionType(realInterval)));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new FunctionType(realInterval, realInterval)));
    realInterval = new RealInterval("[0;4]");
    Assert.assertFalse(isTypeSubtypeOf(realInterval, INTEGER_TYPE));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("0..4")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("1..4")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("0..3")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, REAL_TYPE));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("Real")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("[0;4]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("]0;4]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[0;4[")));
    realInterval = new RealInterval("[-infinity;4]");
    Assert.assertFalse(isTypeSubtypeOf(realInterval, INTEGER_TYPE));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("0..4")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("1..4")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("0..3")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("-infinity..5")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, REAL_TYPE));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("Real")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[0;4]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("]0;4]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[0;4[")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("[-infinity;4]")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("]-infinity;4]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[-infinity;4[")));
    realInterval = new RealInterval("[0;infinity]");
    Assert.assertFalse(isTypeSubtypeOf(realInterval, INTEGER_TYPE));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("0..4")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("1..4")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("0..3")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("-1..infinity")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, REAL_TYPE));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("Real")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[0;4]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("]0;4]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[0;4[")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("[0;infinity]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("]0;infinity]")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("[0;infinity[")));
    realInterval = new RealInterval("[-infinity;infinity]");
    Assert.assertFalse(isTypeSubtypeOf(realInterval, INTEGER_TYPE));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("0..4")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("1..4")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new IntegerInterval("0..3")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, REAL_TYPE));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("Real")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[0;4]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("]0;4]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[0;4[")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[-infinity;4]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("]-infinity;4]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[-infinity;4[")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[0;infinity]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("]0;infinity]")));
    Assert.assertFalse(isTypeSubtypeOf(realInterval, new RealInterval("[0;infinity[")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("[-infinity;infinity]")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("]-infinity;infinity]")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("[-infinity;infinity[")));
    Assert.assertTrue(isTypeSubtypeOf(realInterval, new RealInterval("]-infinity;infinity[")));
}
Also used : IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) FunctionType(com.sri.ai.expresso.type.FunctionType) RealInterval(com.sri.ai.expresso.type.RealInterval) Test(org.junit.Test)

Example 4 with FunctionType

use of com.sri.ai.expresso.type.FunctionType in project aic-expresso by aic-sri-international.

the class AssignmentsSamplingIteratorTest method testSampleOverFunction.

@Test
public void testSampleOverFunction() {
    updateContextWithIndexAndType("f", new FunctionType(GrinderUtil.BOOLEAN_TYPE, new IntegerInterval(1, 10)));
    Assert.assertEquals("{f='->'(1..10, Boolean)}:{f='->'(1..10, Boolean)}:{f='->'(1..10, Boolean)}", join(":", newSamplingIterator("f", 3, "true")));
}
Also used : FunctionType(com.sri.ai.expresso.type.FunctionType) IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) Test(org.junit.Test)

Example 5 with FunctionType

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();
}
Also used : InversionSimplifier(com.sri.ai.grinder.sgdpllt.library.set.invsupport.InversionSimplifier) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) FunctionType(com.sri.ai.expresso.type.FunctionType) IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory) TrueContext(com.sri.ai.grinder.sgdpllt.core.TrueContext) TupleTheory(com.sri.ai.grinder.sgdpllt.theory.tuple.TupleTheory) Before(org.junit.Before)

Aggregations

FunctionType (com.sri.ai.expresso.type.FunctionType)34 Test (org.junit.Test)18 Context (com.sri.ai.grinder.sgdpllt.api.Context)15 IntegerInterval (com.sri.ai.expresso.type.IntegerInterval)14 Expression (com.sri.ai.expresso.api.Expression)13 Type (com.sri.ai.expresso.api.Type)12 TheoryTestingSupport (com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport)11 RealInterval (com.sri.ai.expresso.type.RealInterval)10 StepSolver (com.sri.ai.grinder.sgdpllt.api.StepSolver)10 UnificationStepSolver (com.sri.ai.grinder.sgdpllt.theory.base.UnificationStepSolver)10 TupleType (com.sri.ai.expresso.type.TupleType)8 IndexExpressionsSet (com.sri.ai.expresso.api.IndexExpressionsSet)7 RealExpressoType (com.sri.ai.expresso.type.RealExpressoType)7 ArrayList (java.util.ArrayList)7 Categorical (com.sri.ai.expresso.type.Categorical)6 IntegerExpressoType (com.sri.ai.expresso.type.IntegerExpressoType)6 IntensionalSet (com.sri.ai.expresso.api.IntensionalSet)5 ExtensionalIndexExpressionsSet (com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet)5 DifferenceArithmeticTheory (com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory)5 LambdaExpression (com.sri.ai.expresso.api.LambdaExpression)4