use of com.sri.ai.util.math.Rational in project aic-expresso by aic-sri-international.
the class DefaultSymbolTest method testDisplayLargeExact.
@Test
public void testDisplayLargeExact() {
// NOTE: the tearDown method will set us back to the correct default.
ExpressoConfiguration.setDisplayNumericsExactlyForSymbols(true);
Rational largeRational = new Rational(3).pow(100000);
Assert.assertEquals("1.334971414230401469458914390489782E47712", Expressions.makeSymbol(largeRational).toString());
largeRational = new Rational(3).pow(100000).divide(new Rational(7).pow(100));
Assert.assertEquals("1.334971414230401469458914390489782E+47661/3234476509624757991344647769100217", Expressions.makeSymbol(largeRational).toString());
}
use of com.sri.ai.util.math.Rational in project aic-expresso by aic-sri-international.
the class MeasureTest method testFunctionTypeDomain.
// measure(co-domain)^measure(domain)
@Test
public void testFunctionTypeDomain() {
Assert.assertEquals(new Rational(8), measure("{{ (on f in 0..2 -> Boolean) f : true }}"));
Assert.assertEquals(new Rational(64), measure("{{ (on f in 0..2 -> [3;7]) f : true }}"));
}
use of com.sri.ai.util.math.Rational in project aic-expresso by aic-sri-international.
the class MeasureTest method measure.
private Rational measure(String testIntensionalSetString) {
Expression testIntensionalSetExpression = parse(testIntensionalSetString);
Expression properlyConditionedIntensionalSetExpression = testIntensionalSetExpression;
if (Sets.isIntensionalSet(testIntensionalSetExpression)) {
IntensionalSet intensionalSet = (IntensionalSet) testIntensionalSetExpression;
List<Expression> indices = IndexExpressions.getIndices(intensionalSet.getIndexExpressions());
if (indices.size() == 1) {
Expression index = indices.get(0);
Context intensionalSetContext = context.extendWith(intensionalSet.getIndexExpressions());
Type type = GrinderUtil.getTypeOfExpression(index, intensionalSetContext);
if (type instanceof RealExpressoType || type instanceof RealInterval) {
SingleVariableLinearRealArithmeticConstraint singleVariableConstraint = new SingleVariableLinearRealArithmeticConstraint(index, true, context.getTheory());
singleVariableConstraint = (SingleVariableLinearRealArithmeticConstraint) singleVariableConstraint.conjoin(intensionalSet.getCondition(), intensionalSetContext);
properlyConditionedIntensionalSetExpression = IntensionalSet.make(Sets.isMultiSet(intensionalSet) ? IntensionalSet.MULTI_SET_LABEL : IntensionalSet.UNI_SET_LABEL, intensionalSet.getIndexExpressions(), intensionalSet.getHead(), singleVariableConstraint);
}
}
}
Rational result = Measure.get(properlyConditionedIntensionalSetExpression, context);
return result;
}
use of com.sri.ai.util.math.Rational in project aic-expresso by aic-sri-international.
the class MeasureTest method testRealIntervalTypeDomain.
@Test
public void testRealIntervalTypeDomain() {
Assert.assertEquals(new Rational(4), measure("{{ (on X in [3;7]) X : true }}"));
Assert.assertEquals(new Rational(4), measure("{{ (on X in [3;7]) X : X != 5 }}"));
}
use of com.sri.ai.util.math.Rational in project aic-expresso by aic-sri-international.
the class Expressions method getExpressionBeingMultipliedByMinusOneInNumberOrNull.
private static Expression getExpressionBeingMultipliedByMinusOneInNumberOrNull(Expression expression) {
Expression result;
Rational value = expression.rationalValue();
if (value.isNegative()) {
result = makeSymbol(value.negate());
} else {
result = null;
}
return result;
}
Aggregations