Search in sources :

Example 36 with Rational

use of com.sri.ai.util.math.Rational in project aic-expresso by aic-sri-international.

the class DefaultSymbolTest method testDisplayExact.

@Test
public void testDisplayExact() {
    // NOTE: the tearDown method will set us back to the correct default.
    ExpressoConfiguration.setDisplayNumericsExactlyForSymbols(true);
    Assert.assertEquals("0.1", Expressions.makeSymbol(new Rational(1, 10)).toString());
    Assert.assertEquals("1.1", Expressions.makeSymbol(new Rational(11, 10)).toString());
    Assert.assertEquals("2/3", Expressions.makeSymbol(new Rational(2, 3)).toString());
    Assert.assertEquals("0.123456789", Expressions.makeSymbol(new Rational(123456789, 1000000000)).toString());
    Assert.assertEquals("0.999999999999999", Expressions.makeSymbol(new Rational(999999999999999L, 1000000000000000L)).toString());
    Assert.assertEquals("1/3", Expressions.makeSymbol(new Rational(1, 3)).toString());
    Assert.assertEquals("1/7", Expressions.makeSymbol(new Rational(1, 7)).toString());
    Assert.assertEquals("-0.1", Expressions.makeSymbol(new Rational(-1, 10)).toString());
    Assert.assertEquals("-1.1", Expressions.makeSymbol(new Rational(-11, 10)).toString());
    Assert.assertEquals("-2/3", Expressions.makeSymbol(new Rational(-2, 3)).toString());
    Assert.assertEquals("-0.123456789", Expressions.makeSymbol(new Rational(-123456789, 1000000000)).toString());
    Assert.assertEquals("-0.999999999999999", Expressions.makeSymbol(new Rational(-999999999999999L, 1000000000000000L)).toString());
    Assert.assertEquals("-1/3", Expressions.makeSymbol(new Rational(-1, 3)).toString());
    Assert.assertEquals("-1/7", Expressions.makeSymbol(new Rational(-1, 7)).toString());
}
Also used : Rational(com.sri.ai.util.math.Rational) Test(org.junit.Test)

Example 37 with Rational

use of com.sri.ai.util.math.Rational in project aic-expresso by aic-sri-international.

the class MeasureTest method testTupleTypeDomain.

// (element_1, ..., element_n) = measure(element_1) * ... * measure(element_n)
@Test
public void testTupleTypeDomain() {
    Assert.assertEquals(new Rational(6), measure("{{ (on T in (0..2 x Boolean)) T : true }}"));
    Assert.assertEquals(new Rational(12), measure("{{ (on T in (0..2 x [3;7])) T : true }}"));
}
Also used : Rational(com.sri.ai.util.math.Rational) Test(org.junit.Test)

Example 38 with Rational

use of com.sri.ai.util.math.Rational in project aic-expresso by aic-sri-international.

the class MeasureTest method testRealTypeDomain.

@Test
public void testRealTypeDomain() {
    Assert.assertEquals(new Rational(3), measure("{{ (on X in Real) X : X > 4 and X < 7 }}"));
    Assert.assertEquals(new Rational(2), measure("{{ (on X in Real) X : X > 4 and X > 5 and X < 7 }}"));
    Assert.assertEquals(new Rational(0), measure("{{ (on X in Real) X : X > 4 and X > 5 and X < 7 and X < 3 }}"));
}
Also used : Rational(com.sri.ai.util.math.Rational) Test(org.junit.Test)

Example 39 with Rational

use of com.sri.ai.util.math.Rational in project aic-expresso by aic-sri-international.

the class MeasureTest method testCategoricalTypeDomain.

@Test
public void testCategoricalTypeDomain() {
    updateContextWithIndexAndType("N", new Categorical("People", 5, parse("p1"), parse("p2"), parse("p3"), parse("p4"), parse("p5")));
    Assert.assertEquals(new Rational(5), measure("{{(on I in People) I : true}}"));
    Assert.assertEquals(new Rational(4), measure("{{(on I in People) I : I != p1}}"));
    Assert.assertEquals(new Rational(3), measure("{{(on I in People) I : I != p1 and I != p5}}"));
}
Also used : Rational(com.sri.ai.util.math.Rational) Categorical(com.sri.ai.expresso.type.Categorical) Test(org.junit.Test)

Example 40 with Rational

use of com.sri.ai.util.math.Rational in project aic-expresso by aic-sri-international.

the class MeasureTest method testIntegerIntervalTypeDomain.

@Test
public void testIntegerIntervalTypeDomain() {
    Assert.assertEquals(new Rational(5), measure("{{ (on X in 3..7) X : true }}"));
    Assert.assertEquals(new Rational(4), measure("{{ (on X in 3..7) X : X != 5 }}"));
}
Also used : Rational(com.sri.ai.util.math.Rational) Test(org.junit.Test)

Aggregations

Rational (com.sri.ai.util.math.Rational)72 Expression (com.sri.ai.expresso.api.Expression)33 Test (org.junit.Test)26 Monomial (com.sri.ai.grinder.polynomial.api.Monomial)11 ArrayList (java.util.ArrayList)10 Type (com.sri.ai.expresso.api.Type)9 IntensionalSet (com.sri.ai.expresso.api.IntensionalSet)8 IndexExpressionsSet (com.sri.ai.expresso.api.IndexExpressionsSet)7 RealExpressoType (com.sri.ai.expresso.type.RealExpressoType)6 RealInterval (com.sri.ai.expresso.type.RealInterval)6 List (java.util.List)6 ExtensionalIndexExpressionsSet (com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet)5 Symbol (com.sri.ai.expresso.api.Symbol)4 Expressions.makeSymbol (com.sri.ai.expresso.helper.Expressions.makeSymbol)4 Categorical (com.sri.ai.expresso.type.Categorical)4 FunctionType (com.sri.ai.expresso.type.FunctionType)4 TupleType (com.sri.ai.expresso.type.TupleType)4 Polynomial (com.sri.ai.grinder.polynomial.api.Polynomial)4 LambdaExpression (com.sri.ai.expresso.api.LambdaExpression)3 HashMap (java.util.HashMap)3