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.getType(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 InversionPerformanceEvaluationTest method computeSize.
private Rational computeSize(Expression functionOnIntensionalSet) {
Rational result = new Rational(1);
result = computeSize(functionOnIntensionalSet, result, context);
return result;
}
use of com.sri.ai.util.math.Rational in project aic-expresso by aic-sri-international.
the class InversionPerformanceEvaluationTest method computeSize.
private Rational computeSize(Expression functionOnIntensionalSet, Rational resultSoFar, Context context) {
IntensionalSet intensionalSet = (IntensionalSet) functionOnIntensionalSet.get(0);
IndexExpressionsSet indexExpressionsSet = intensionalSet.getIndexExpressions();
List<Expression> indices = IndexExpressions.getIndices(indexExpressionsSet);
if (indices.size() != 1) {
throw new UnsupportedOperationException("Currently only support singular indices");
}
Expression index = indices.get(0);
Context intensionalSetContext = context.extendWith(indexExpressionsSet);
Type type = GrinderUtil.getType(index, intensionalSetContext);
Rational result = resultSoFar.multiply(type.cardinality().rationalValue());
Expression head = intensionalSet.getHead();
if (Expressions.isFunctionApplicationWithArguments(head) && Sets.isIntensionalSet(head.get(0))) {
result = computeSize(head, result, intensionalSetContext);
}
return result;
}
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 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 }}"));
}
Aggregations