Search in sources :

Example 21 with Expression

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

the class SummationOnDifferenceArithmeticAndPolynomialStepSolverTest method simpleBodyTest.

@Test
public void simpleBodyTest() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new DifferenceArithmeticTheory(true, true));
    Context context = theoryTestingSupport.makeContextWithTestingInformation();
    Expression variable;
    String constraintString;
    Expression body;
    Expression expected;
    variable = parse("I");
    body = parse("I");
    constraintString = "true";
    expected = parse("10");
    runTest(variable, constraintString, body, expected, context);
    constraintString = "I != 3";
    expected = parse("7");
    runTest(variable, constraintString, body, expected, context);
    constraintString = "I < 3";
    expected = parse("3");
    runTest(variable, constraintString, body, expected, context);
    constraintString = "false";
    expected = parse("0");
    runTest(variable, constraintString, body, expected, context);
    constraintString = "I > 3 and I < 3";
    expected = parse("0");
    runTest(variable, constraintString, body, expected, context);
    constraintString = "I > 1 and I < 3 and I != 2";
    expected = parse("0");
    runTest(variable, constraintString, body, expected, context);
}
Also used : Context(com.sri.ai.grinder.sgdpllt.api.Context) Expression(com.sri.ai.expresso.api.Expression) TheoryTestingSupport(com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) Test(org.junit.Test)

Example 22 with Expression

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

the class SetDNFRewriterTest method testBasicIntersectionCases.

@Test
public void testBasicIntersectionCases() {
    Expression intersection = parse("{(2,2)} intersection ({(2,2)} union {(3,2)} union {(4,2)}) = {}");
    Assert.assertEquals(parse("{(2,2)} = {}"), rewriter.apply(intersection, context));
    intersection = parse("{(2,2)} intersection ({(3,2)} union {(4,2)}) = {}");
    Assert.assertEquals(parse("true"), rewriter.apply(intersection, context));
    intersection = parse("{(2,2)} intersection {(N,2)} = {}");
    Assert.assertEquals(parse("if 2 = N then { (2, 2) } = {} else true"), rewriter.apply(intersection, context));
    intersection = parse("{(1, 2)} intersection Union({{(on I in 1..10) {(I, 2)} : I != 5}}) = {}");
    Assert.assertEquals(parse("{(1, 2)} = {}"), rewriter.apply(intersection, context));
}
Also used : Expression(com.sri.ai.expresso.api.Expression) Test(org.junit.Test)

Example 23 with Expression

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

the class SetExpressionIsEqualToEmptySetTest method testIntensionalUnionSetBasicCases.

@Test
public void testIntensionalUnionSetBasicCases() {
    Expression setEqualToEmptySet = parse("Union({{(on I in 1..10) {(I, 2)} : I > 10}}) = {}");
    Assert.assertEquals(parse("true"), rewriter.apply(setEqualToEmptySet, context));
    setEqualToEmptySet = parse("Union({{(on I in 1..10) {(I, 2)} : I != 5}}) = {}");
    Assert.assertEquals(parse("false"), rewriter.apply(setEqualToEmptySet, context));
    setEqualToEmptySet = parse("Union({{(on I in 1..10) {(I, 2)} : I != N}}) = {}");
    Assert.assertEquals(parse("false"), rewriter.apply(setEqualToEmptySet, context));
}
Also used : Expression(com.sri.ai.expresso.api.Expression) Test(org.junit.Test)

Example 24 with Expression

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

the class SetExpressionIsEqualToEmptySetTest method testExtensionalSetBasicCases.

@Test
public void testExtensionalSetBasicCases() {
    Expression setEqualToEmptySet = parse("{} = {}");
    Assert.assertEquals(parse("true"), rewriter.apply(setEqualToEmptySet, context));
    setEqualToEmptySet = parse("{(2,2)} = {}");
    Assert.assertEquals(parse("false"), rewriter.apply(setEqualToEmptySet, context));
    setEqualToEmptySet = parse("{(N,2)} = {}");
    Assert.assertEquals(parse("false"), rewriter.apply(setEqualToEmptySet, context));
}
Also used : Expression(com.sri.ai.expresso.api.Expression) Test(org.junit.Test)

Example 25 with Expression

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

the class SetOfArgumentTuplesForFunctionOccurringInExpressionTest method testCase1.

// if E does not contain &fnof;, oc<sub>&fnof;</sub>[E] is &empty;
@Test
public void testCase1() {
    Expression e = parse("a");
    Assert.assertEquals(Sets.EMPTY_SET, getSetOfArgumentTuples(e));
    e = parse("if A = 1 then 4 else 5");
    Assert.assertEquals(Sets.EMPTY_SET, getSetOfArgumentTuples(e));
}
Also used : Expression(com.sri.ai.expresso.api.Expression) SetOfArgumentTuplesForFunctionOccurringInExpression(com.sri.ai.grinder.sgdpllt.library.set.invsupport.SetOfArgumentTuplesForFunctionOccurringInExpression) Test(org.junit.Test)

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