Search in sources :

Example 96 with Expression

use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.

the class SampleCommonInterpreterTest method runTest.

public void runTest(int sampleSizeN, boolean alwaysSample, String expressionString, String expectedString) {
    Expression expected = parse(expectedString);
    Expression actual = run(sampleSizeN, alwaysSample, expressionString);
    Assert.assertEquals(expected, actual);
}
Also used : Expression(com.sri.ai.expresso.api.Expression)

Example 97 with Expression

use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.

the class SampleCommonInterpreterTest method runBoundedTest.

public void runBoundedTest(int sampleSizeN, boolean alwaysSample, String expressionString, String lowerBoundInclusiveString, String upperBoundInclusiveString) {
    Expression lowerBoundInclusive = context.getTheory().evaluate(parse(lowerBoundInclusiveString), context);
    Expression upperBoundInclusive = context.getTheory().evaluate(parse(upperBoundInclusiveString), context);
    Expression actual = run(sampleSizeN, alwaysSample, expressionString);
    System.out.println("upper bound  = " + upperBoundInclusive.doubleValue() + " (as rational=" + toString(upperBoundInclusive) + ")");
    System.out.println("      actual = " + actual.doubleValue() + " (as rational=" + toString(actual) + ")");
    System.out.println("lower bound  = " + lowerBoundInclusive.doubleValue() + " (as rational=" + toString(lowerBoundInclusive) + ")");
    Assert.assertTrue("actual (" + toString(actual) + ") is not >= lower bound (" + toString(lowerBoundInclusive) + ")", actual.compareTo(lowerBoundInclusive) >= 0);
    Assert.assertTrue("actual (" + toString(actual) + ") is not <= upper bound (" + toString(upperBoundInclusive) + ")", actual.compareTo(upperBoundInclusive) <= 0);
}
Also used : Expression(com.sri.ai.expresso.api.Expression)

Example 98 with Expression

use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.

the class IntensionalUnionToUnionsOfIntensionalSetsOfBaseTypeSimplifierTest method testBaseCase.

@Test
public void testBaseCase() {
    Expression baseCase = parse("Union({{(on I in 1..10) {(I, 2)} : I != 5}})");
    Assert.assertEquals(parse("{{(on I in 1..10) (I, 2) : I != 5}}"), simplifier.apply(baseCase, context));
}
Also used : Expression(com.sri.ai.expresso.api.Expression) Test(org.junit.Test)

Example 99 with Expression

use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.

the class IntersectionExtensionalSetSimplifierTest method testExtensionalInExtensonalBasicCases.

@Test
public void testExtensionalInExtensonalBasicCases() {
    Expression intersection = parse("{(2,2),(3,2),(4,2)} intersection {}");
    Assert.assertEquals(parse("{}"), simplifier.apply(intersection, context));
    parse("{} intersection {(2,2),(3,2),(4,2)}");
    Assert.assertEquals(parse("{}"), simplifier.apply(intersection, context));
    intersection = parse("{(2,2),(3,2),(4,2)} intersection {(2,2),(3,2),(5,2),(6,2)}");
    Assert.assertEquals(parse("{(2,2)} union {(3,2)}"), simplifier.apply(intersection, context));
    intersection = parse("{(2,2),(3,2),(4,2)} intersection {(N, 2)}");
    Assert.assertEquals(parse("(if 2 = N then {(2,2)} else {}) union (if 3 = N then {(3,2)} else {}) union (if 4 = N then {(4,2)} else {})"), simplifier.apply(intersection, context));
}
Also used : Expression(com.sri.ai.expresso.api.Expression) Test(org.junit.Test)

Example 100 with Expression

use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.

the class InversionPerformanceEvaluationTest method evaluate.

private Pair<Long, Expression> evaluate(Expression sumProduct, SumProductInterpreter sumProductInterpreter) {
    long start = System.currentTimeMillis();
    Expression evalResult = sumProductInterpreter.apply(sumProduct, context);
    long duration = System.currentTimeMillis() - start;
    Pair<Long, Expression> result = new Pair<>(duration, evalResult);
    return result;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) Pair(com.sri.ai.util.base.Pair)

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