Search in sources :

Example 91 with Expression

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));
}
Also used : Expression(com.sri.ai.expresso.api.Expression) Test(org.junit.Test)

Example 92 with Expression

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));
}
Also used : Expression(com.sri.ai.expresso.api.Expression) Test(org.junit.Test)

Example 93 with Expression

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));
}
Also used : Expression(com.sri.ai.expresso.api.Expression) Test(org.junit.Test)

Example 94 with Expression

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;
}
Also used : Context(com.sri.ai.grinder.sgdpllt.api.Context) TrueContext(com.sri.ai.grinder.sgdpllt.core.TrueContext) Type(com.sri.ai.expresso.api.Type) IntensionalSet(com.sri.ai.expresso.api.IntensionalSet) Rational(com.sri.ai.util.math.Rational) Expression(com.sri.ai.expresso.api.Expression) IndexExpressionsSet(com.sri.ai.expresso.api.IndexExpressionsSet)

Example 95 with Expression

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;
}
Also used : BruteForceCommonInterpreter(com.sri.ai.grinder.sgdpllt.interpreter.BruteForceCommonInterpreter) Expression(com.sri.ai.expresso.api.Expression)

Aggregations

Expression (com.sri.ai.expresso.api.Expression)1392 Test (org.junit.Test)259 ArrayList (java.util.ArrayList)196 Context (com.sri.ai.grinder.api.Context)187 Type (com.sri.ai.expresso.api.Type)124 TrueContext (com.sri.ai.grinder.core.TrueContext)113 IndexExpressionsSet (com.sri.ai.expresso.api.IndexExpressionsSet)100 ExtensionalIndexExpressionsSet (com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet)91 QuantifiedExpression (com.sri.ai.expresso.api.QuantifiedExpression)90 Context (com.sri.ai.grinder.sgdpllt.api.Context)87 Theory (com.sri.ai.grinder.api.Theory)78 Map (java.util.Map)78 LambdaExpression (com.sri.ai.expresso.api.LambdaExpression)71 IntensionalSet (com.sri.ai.expresso.api.IntensionalSet)68 List (java.util.List)68 DefaultLambdaExpression (com.sri.ai.expresso.core.DefaultLambdaExpression)63 CommonTheory (com.sri.ai.grinder.application.CommonTheory)55 LinkedHashMap (java.util.LinkedHashMap)55 LinkedHashSet (java.util.LinkedHashSet)54 Pair (com.sri.ai.util.base.Pair)52