use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.
the class IntersectionIntensionalSetsSimplifierTest method testMultiDomainIntersections.
@Test
public void testMultiDomainIntersections() {
Expression intersection = parse("{{ (on I in 0..10, J in 4..12) J : I > 3 and J > 6}} intersection {{ (on L in 5..20, M in 6..20) M : L > 2 and M > 7 }}");
Assert.assertEquals(parse("{{ ( on I in 0..10, J in 4..12 ) J : (I > 3) and (J > 6) and (J > 7) }}"), simplifier.apply(intersection, context));
intersection = parse("{{ (on I in 0..10, J in 4..12) J : I > 3 and J > 6}} intersection {{ (on L in 5..8, M in 6..11) M : L > 2 and M > 7 }}");
Assert.assertEquals(parse("{{ ( on I in 0..10, J in 4..12 ) J : (I > 3) and (J > 6) and (if J > 7 then J <= 11 else false) }}"), simplifier.apply(intersection, context));
}
use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.
the class IntersectionIntensionalSetsSimplifierTest method testBasicCases.
@Test
public void testBasicCases() {
Expression intersection = parse("{{(on I in 1..10) (I, 2) : I != 5}} intersection {{(on J in 1..10) (J, 2) : J != 4}}");
Assert.assertEquals(parse("{{(on I in 1..10) (I, 2) : I != 5 and I != 4}}"), simplifier.apply(intersection, context));
intersection = parse("{{(on I in 1..10) (I, 2) : I != 5}} intersection {{(on J in 1..10) (J, 3) : J != 4}}");
Assert.assertEquals(parse("{}"), simplifier.apply(intersection, context));
intersection = parse("{{(on I in 1..10) (I, 2) : I != 5}} intersection {{(on J in 1..10) (J, 2) : J != 4}} intersection {{(10, 2)}}");
Assert.assertEquals(parse("{{(on I in 1..10) (I, 2) : I != 5 and I != 4}} intersection {{(10,2)}}"), simplifier.apply(intersection, context));
intersection = parse("{{(on I in 1..10) (I, 2) : I != 5}} intersection {{(on J in 1..10) (J, 2) : J != 4}} intersection {{(on K in 1..10) (K, 2) : K != 3}}");
Assert.assertEquals(parse("{{(on I in 1..10) (I, 2) : I != 5 and I != 4 and I != 3}}"), simplifier.apply(intersection, context));
}
use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.
the class IntersectionIntensionalSetsSimplifierTest method testStandardizeApart.
@Test
public void testStandardizeApart() {
Expression intersection = parse("{{(on I in 1..10) (I, 2) : I != 5}} intersection {{(on I in 1..10) (I, 2) : I != 4}}");
Assert.assertEquals(parse("{{(on I in 1..10) (I, 2) : I != 5 and I != 4}}"), simplifier.apply(intersection, context));
intersection = parse("{{(on I in 1..10) (I, 2) : I != 5}} intersection {{(on I in 1..10) (I, 3) : I != 4}}");
Assert.assertEquals(parse("{}"), simplifier.apply(intersection, context));
intersection = parse("{{(on I in 1..10) (I, 2) : I != 5}} intersection {{(on I in 1..10) (I, 2) : I != 4}} intersection {{(10, 2)}}");
Assert.assertEquals(parse("{{(on I in 1..10) (I, 2) : I != 5 and I != 4}} intersection {{(10,2)}}"), simplifier.apply(intersection, context));
intersection = parse("{{(on I in 1..10) (I, 2) : I != 5}} intersection {{(on I in 1..10) (I, 2) : I != 4}} intersection {{(on I in 1..10) (I, 2) : I != 3}}");
Assert.assertEquals(parse("{{(on I in 1..10) (I, 2) : I != 5 and I != 4 and I != 3}}"), simplifier.apply(intersection, context));
}
use of com.sri.ai.expresso.api.Expression 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.expresso.api.Expression in project aic-expresso by aic-sri-international.
the class SampleCommonInterpreterTest method bruteForceResult.
private Expression bruteForceResult(String expression) {
BruteForceCommonInterpreter bruteForceInterpreter = new BruteForceCommonInterpreter();
Expression result = bruteForceInterpreter.apply(Expressions.parse(expression), context);
return result;
}
Aggregations