Search in sources :

Example 16 with IntegerInterval

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

the class AssignmentsSamplingIteratorTest method testSampleOverTuple.

@Test
public void testSampleOverTuple() {
    updateContextWithIndexAndType("T", new TupleType(new IntegerInterval(1, 10), GrinderUtil.BOOLEAN_TYPE));
    Assert.assertEquals("{T=(6, true)}:{T=(8, true)}:{T=(5, true)}", join(":", newSamplingIterator("T", 3, "true")));
}
Also used : IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) TupleType(com.sri.ai.expresso.type.TupleType) Test(org.junit.Test)

Example 17 with IntegerInterval

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

the class IntersectionIntensionalSetsSimplifierTest method setUp.

@Before
public void setUp() {
    context = new TrueContext(new CompoundTheory(new DifferenceArithmeticTheory(false, false), new TupleTheory()));
    IntegerInterval nType = new IntegerInterval(1, 10);
    context = (Context) GrinderUtil.extendRegistryWith(map("N", nType.toString()), Arrays.asList(nType), context);
    simplifier = new IntersectionIntensionalSetsSimplifier();
}
Also used : DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) IntersectionIntensionalSetsSimplifier(com.sri.ai.grinder.library.set.invsupport.IntersectionIntensionalSetsSimplifier) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) TrueContext(com.sri.ai.grinder.core.TrueContext) TupleTheory(com.sri.ai.grinder.theory.tuple.TupleTheory) Before(org.junit.Before)

Example 18 with IntegerInterval

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

the class IntegerIntervalTest method testIsSuperset.

@Test
public void testIsSuperset() {
    IntegerInterval intInterval = new IntegerInterval("Integer");
    Assert.assertTrue(intInterval.isSuperset(parse("-infinity"), parse("infinity")));
    Assert.assertTrue(intInterval.isSuperset(parse("-infinity"), parse("-infinity")));
    Assert.assertTrue(intInterval.isSuperset(parse("infinity"), parse("infinity")));
    Assert.assertTrue(intInterval.isSuperset(parse("-infinity"), parse("3")));
    Assert.assertTrue(intInterval.isSuperset(parse("-infinity"), parse("4")));
    Assert.assertTrue(intInterval.isSuperset(parse("-infinity"), parse("5")));
    Assert.assertTrue(intInterval.isSuperset(parse("-1"), parse("infinity")));
    Assert.assertTrue(intInterval.isSuperset(parse("0"), parse("infinity")));
    Assert.assertTrue(intInterval.isSuperset(parse("1"), parse("infinity")));
    Assert.assertTrue(intInterval.isSuperset(parse("0"), parse("4")));
    Assert.assertFalse(intInterval.isSuperset(parse("0.5"), parse("4")));
    Assert.assertFalse(intInterval.isSuperset(parse("0"), parse("3.5")));
    intInterval = new IntegerInterval("-infinity..4");
    Assert.assertFalse(intInterval.isSuperset(parse("-infinity"), parse("infinity")));
    Assert.assertTrue(intInterval.isSuperset(parse("-infinity"), parse("-infinity")));
    Assert.assertFalse(intInterval.isSuperset(parse("infinity"), parse("infinity")));
    Assert.assertTrue(intInterval.isSuperset(parse("-infinity"), parse("3")));
    Assert.assertTrue(intInterval.isSuperset(parse("-infinity"), parse("4")));
    Assert.assertFalse(intInterval.isSuperset(parse("-infinity"), parse("5")));
    Assert.assertFalse(intInterval.isSuperset(parse("-1"), parse("infinity")));
    Assert.assertFalse(intInterval.isSuperset(parse("0"), parse("infinity")));
    Assert.assertFalse(intInterval.isSuperset(parse("1"), parse("infinity")));
    Assert.assertTrue(intInterval.isSuperset(parse("0"), parse("4")));
    Assert.assertTrue(intInterval.isSuperset(parse("1"), parse("3")));
    Assert.assertTrue(intInterval.isSuperset(parse("-1"), parse("3")));
    Assert.assertFalse(intInterval.isSuperset(parse("0"), parse("5")));
    Assert.assertFalse(intInterval.isSuperset(parse("0.5"), parse("4")));
    Assert.assertFalse(intInterval.isSuperset(parse("0"), parse("3.5")));
    intInterval = new IntegerInterval("0..infinity");
    Assert.assertFalse(intInterval.isSuperset(parse("-infinity"), parse("infinity")));
    Assert.assertFalse(intInterval.isSuperset(parse("-infinity"), parse("-infinity")));
    Assert.assertTrue(intInterval.isSuperset(parse("infinity"), parse("infinity")));
    Assert.assertFalse(intInterval.isSuperset(parse("-infinity"), parse("3")));
    Assert.assertFalse(intInterval.isSuperset(parse("-infinity"), parse("4")));
    Assert.assertFalse(intInterval.isSuperset(parse("-infinity"), parse("5")));
    Assert.assertFalse(intInterval.isSuperset(parse("-1"), parse("infinity")));
    Assert.assertTrue(intInterval.isSuperset(parse("0"), parse("infinity")));
    Assert.assertTrue(intInterval.isSuperset(parse("1"), parse("infinity")));
    Assert.assertTrue(intInterval.isSuperset(parse("0"), parse("4")));
    Assert.assertTrue(intInterval.isSuperset(parse("1"), parse("3")));
    Assert.assertFalse(intInterval.isSuperset(parse("-1"), parse("3")));
    Assert.assertTrue(intInterval.isSuperset(parse("0"), parse("5")));
    Assert.assertFalse(intInterval.isSuperset(parse("0.5"), parse("4")));
    Assert.assertFalse(intInterval.isSuperset(parse("0"), parse("3.5")));
    intInterval = new IntegerInterval("0..4");
    Assert.assertFalse(intInterval.isSuperset(parse("-infinity"), parse("infinity")));
    Assert.assertFalse(intInterval.isSuperset(parse("-infinity"), parse("-infinity")));
    Assert.assertFalse(intInterval.isSuperset(parse("infinity"), parse("infinity")));
    Assert.assertFalse(intInterval.isSuperset(parse("-infinity"), parse("3")));
    Assert.assertFalse(intInterval.isSuperset(parse("-infinity"), parse("4")));
    Assert.assertFalse(intInterval.isSuperset(parse("-infinity"), parse("5")));
    Assert.assertFalse(intInterval.isSuperset(parse("-1"), parse("infinity")));
    Assert.assertFalse(intInterval.isSuperset(parse("0"), parse("infinity")));
    Assert.assertFalse(intInterval.isSuperset(parse("1"), parse("infinity")));
    Assert.assertTrue(intInterval.isSuperset(parse("0"), parse("4")));
    Assert.assertTrue(intInterval.isSuperset(parse("1"), parse("3")));
    Assert.assertFalse(intInterval.isSuperset(parse("-1"), parse("3")));
    Assert.assertFalse(intInterval.isSuperset(parse("0"), parse("5")));
    Assert.assertFalse(intInterval.isSuperset(parse("0.5"), parse("4")));
    Assert.assertFalse(intInterval.isSuperset(parse("0"), parse("3.5")));
}
Also used : IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) Test(org.junit.Test)

Example 19 with IntegerInterval

use of com.sri.ai.expresso.type.IntegerInterval 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 20 with IntegerInterval

use of com.sri.ai.expresso.type.IntegerInterval 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)

Aggregations

IntegerInterval (com.sri.ai.expresso.type.IntegerInterval)62 Expression (com.sri.ai.expresso.api.Expression)24 Before (org.junit.Before)20 FunctionType (com.sri.ai.expresso.type.FunctionType)18 Test (org.junit.Test)18 Type (com.sri.ai.expresso.api.Type)16 DifferenceArithmeticTheory (com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory)15 DifferenceArithmeticTheory (com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory)15 RealInterval (com.sri.ai.expresso.type.RealInterval)14 TrueContext (com.sri.ai.grinder.core.TrueContext)14 IntegerExpressoType (com.sri.ai.expresso.type.IntegerExpressoType)13 CompoundTheory (com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory)13 Categorical (com.sri.ai.expresso.type.Categorical)12 TupleType (com.sri.ai.expresso.type.TupleType)12 TrueContext (com.sri.ai.grinder.sgdpllt.core.TrueContext)12 CompoundTheory (com.sri.ai.grinder.theory.compound.CompoundTheory)12 RealExpressoType (com.sri.ai.expresso.type.RealExpressoType)10 TupleTheory (com.sri.ai.grinder.theory.tuple.TupleTheory)10 TupleTheory (com.sri.ai.grinder.sgdpllt.theory.tuple.TupleTheory)8 Context (com.sri.ai.grinder.api.Context)7