Search in sources :

Example 11 with CommonTheory

use of com.sri.ai.grinder.application.CommonTheory in project aic-expresso by aic-sri-international.

the class GrinderTest method testPastBugs.

@Test
public void testPastBugs() {
    Expression expression;
    Expression actual;
    Expression expected;
    Context context;
    // Previously, all equalities were being simplified by linear real arithmetic and different arithmetic theories
    // as if they were literals.
    // In the examples below, this led to (if I > 3 then X else Y) = Y being treated as a literal but then generating an exception
    // (since it does not conform to the properties expected from a literal).
    // This has been fixed by adding a check "isLiteral".
    context = new TrueContext(new CommonTheory());
    context = context.extendWithSymbolsAndTypes("X", "Real", "Y", "Real");
    expression = parse("there exists I in 1..5 : (if I > 3 then X else Y) = Y");
    expected = parse("true");
    actual = context.evaluate(expression);
    assertEquals(expected, actual);
    context = new TrueContext(new CommonTheory());
    context = context.extendWithSymbolsAndTypes("J", "Integer", "K", "Integer");
    expression = parse("there exists I in 1..5 : (if I > 3 then J else K) = K");
    expected = parse("true");
    actual = context.evaluate(expression);
    assertEquals(expected, actual);
    context = new TrueContext(new CommonTheory());
    context = context.extendWithSymbolsAndTypes("I", "Integer", "X", "Real", "Y", "Real");
    expression = parse("(if I > 3 then X else Y) = Y");
    expected = parse("if I > 3 then X = Y else true");
    actual = context.evaluate(expression);
    assertEquals(expected, actual);
    context = new TrueContext(new CommonTheory());
    context = context.extendWithSymbolsAndTypes("I", "Integer", "J", "Integer", "K", "Integer");
    expression = parse("(if I > 3 then J else K) = K");
    expected = parse("if I > 3 then J = K else true");
    actual = context.evaluate(expression);
    assertEquals(expected, actual);
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) CommonTheory(com.sri.ai.grinder.application.CommonTheory) Expression(com.sri.ai.expresso.api.Expression) TrueContext(com.sri.ai.grinder.core.TrueContext) Test(org.junit.Test)

Example 12 with CommonTheory

use of com.sri.ai.grinder.application.CommonTheory in project aic-expresso by aic-sri-international.

the class IfThenElseStepSolverTest method test14.

@Test
public void test14() {
    Expression expression = parse("if (X=0) and (Y=1) then if (Z = 1) then (X + Z) else (Y + Z) else 4");
    String[] symbolsAndTypes = { "X", "0..1", "Y", "0..1", "Z", "0..1" };
    Context context = new TrueContext(new CommonTheory()).extendWithSymbolsAndTypes(symbolsAndTypes);
    Expression expectedResult = parse("if X = 0 then if Y = 1 then if Z = 1 then 1 else 1 + Z else 4 else 4");
    // get method name as string
    String testName = new Object() {
    }.getClass().getEnclosingMethod().getName();
    runIfThenElseStepSolverTest(expression, context, expectedResult, testName);
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) CommonTheory(com.sri.ai.grinder.application.CommonTheory) Expression(com.sri.ai.expresso.api.Expression) TrueContext(com.sri.ai.grinder.core.TrueContext) Test(org.junit.Test)

Example 13 with CommonTheory

use of com.sri.ai.grinder.application.CommonTheory in project aic-expresso by aic-sri-international.

the class IfThenElseStepSolverTest method test03.

@Test
public void test03() {
    Expression expression = parse("if X=1 then 2 else 3");
    String[] symbolsAndTypes = { "X", "1..1" };
    Context context = new TrueContext(new CommonTheory()).extendWithSymbolsAndTypes(symbolsAndTypes);
    Expression expectedResult = parse("2");
    // get method name as string
    String testName = new Object() {
    }.getClass().getEnclosingMethod().getName();
    runIfThenElseStepSolverTest(expression, context, expectedResult, testName);
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) CommonTheory(com.sri.ai.grinder.application.CommonTheory) Expression(com.sri.ai.expresso.api.Expression) TrueContext(com.sri.ai.grinder.core.TrueContext) Test(org.junit.Test)

Example 14 with CommonTheory

use of com.sri.ai.grinder.application.CommonTheory in project aic-expresso by aic-sri-international.

the class IfThenElseStepSolverTest method test07.

@Test
public void test07() {
    Expression expression = parse("if (X=1) or (Y=1) then 2 else 3");
    String[] symbolsAndTypes = { "X", "1..1", "Y", "0..1" };
    Context context = new TrueContext(new CommonTheory()).extendWithSymbolsAndTypes(symbolsAndTypes);
    Expression expectedResult = parse("2");
    // get method name as string
    String testName = new Object() {
    }.getClass().getEnclosingMethod().getName();
    runIfThenElseStepSolverTest(expression, context, expectedResult, testName);
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) CommonTheory(com.sri.ai.grinder.application.CommonTheory) Expression(com.sri.ai.expresso.api.Expression) TrueContext(com.sri.ai.grinder.core.TrueContext) Test(org.junit.Test)

Example 15 with CommonTheory

use of com.sri.ai.grinder.application.CommonTheory in project aic-expresso by aic-sri-international.

the class IfThenElseStepSolverTest method test08.

@Test
public void test08() {
    Expression expression = parse("if (X=1) or (Y=1) then 2 else 3");
    String[] symbolsAndTypes = { "X", "0..0", "Y", "0..1" };
    Context context = new TrueContext(new CommonTheory()).extendWithSymbolsAndTypes(symbolsAndTypes);
    Expression expectedResult = parse("if Y = 1 then 2 else 3");
    // get method name as string
    String testName = new Object() {
    }.getClass().getEnclosingMethod().getName();
    runIfThenElseStepSolverTest(expression, context, expectedResult, testName);
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) CommonTheory(com.sri.ai.grinder.application.CommonTheory) Expression(com.sri.ai.expresso.api.Expression) TrueContext(com.sri.ai.grinder.core.TrueContext) Test(org.junit.Test)

Aggregations

Context (com.sri.ai.grinder.api.Context)58 CommonTheory (com.sri.ai.grinder.application.CommonTheory)58 TrueContext (com.sri.ai.grinder.core.TrueContext)58 Expression (com.sri.ai.expresso.api.Expression)55 Test (org.junit.Test)47 Theory (com.sri.ai.grinder.api.Theory)36 Factor (com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor)13 ExpressionFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor)13 DefaultExpressionFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor)12 ConstantFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor)11 CompoundTheory (com.sri.ai.grinder.theory.compound.CompoundTheory)9 DifferenceArithmeticTheory (com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory)9 EqualityTheory (com.sri.ai.grinder.theory.equality.EqualityTheory)9 LinearRealArithmeticTheory (com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory)9 PropositionalTheory (com.sri.ai.grinder.theory.propositional.PropositionalTheory)9 TupleTheory (com.sri.ai.grinder.theory.tuple.TupleTheory)9 DefaultExpressionVariable (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionVariable)7 ExpressionVariable (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionVariable)5 ExpressionFactorNetwork (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.ExpressionFactorNetwork)4 ArrayList (java.util.ArrayList)3