Search in sources :

Example 21 with CommonTheory

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

the class AssociativeCommutativeGroupOperationApplicationStepSolverTest method numericGroupTest04.

@Test
public void numericGroupTest04() {
    // get method name as string
    String testName = new Object() {
    }.getClass().getEnclosingMethod().getName();
    Theory theory = new CommonTheory();
    String[] symbolsAndTypes = { "X", "0..2", "Y", "0..2" };
    Context context = new TrueContext(theory).extendWithSymbolsAndTypes(symbolsAndTypes);
    Expression[] operandExpressions = { parse("if X = 1 then 2 else 3"), parse("if Y != 2 then 4 else 5") };
    Expression[] expectedResultPerGroup = { parse("if Y != 2 then 4 else 5"), parse("if X = 1 then if Y != 2 then 8 else 10 else if Y != 2 then 12 else 15"), parse("if X = 1 then if Y != 2 then 6 else 7 else if Y != 2 then 7 else 8") };
    repeatTestForEachRespectiveGroup(testName, theory, context, operandExpressions, expectedResultPerGroup, NUMERIC_GROUPS);
    println();
}
Also used : CommonTheory(com.sri.ai.grinder.application.CommonTheory) TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) CommonTheory(com.sri.ai.grinder.application.CommonTheory) Theory(com.sri.ai.grinder.api.Theory) Expression(com.sri.ai.expresso.api.Expression) TrueContext(com.sri.ai.grinder.core.TrueContext) Test(org.junit.Test)

Example 22 with CommonTheory

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

the class AssociativeCommutativeGroupOperationApplicationStepSolverTest method numericGroupTest00.

@Test
public void numericGroupTest00() {
    // get method name as string
    String testName = new Object() {
    }.getClass().getEnclosingMethod().getName();
    Theory theory = new CommonTheory();
    String[] symbolsAndTypes = {};
    Context context = new TrueContext(theory).extendWithSymbolsAndTypes(symbolsAndTypes);
    Expression[] operandExpressions = { parse("sum({{(on I in 1..5) if I != 3 then 30 else 40 }})"), parse("sum({{(on J in 10..13) if J != 5 then J else 40 }})") };
    Expression[] expectedResultPerGroup = { parse("160"), parse("7360"), parse("206") };
    repeatTestForEachRespectiveGroup(testName, theory, context, operandExpressions, expectedResultPerGroup, NUMERIC_GROUPS);
    println();
}
Also used : CommonTheory(com.sri.ai.grinder.application.CommonTheory) TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) CommonTheory(com.sri.ai.grinder.application.CommonTheory) Theory(com.sri.ai.grinder.api.Theory) Expression(com.sri.ai.expresso.api.Expression) TrueContext(com.sri.ai.grinder.core.TrueContext) Test(org.junit.Test)

Example 23 with CommonTheory

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

the class AssociativeCommutativeGroupOperationApplicationStepSolverTest method quantifierBasedGroupTest02.

@Test
public void quantifierBasedGroupTest02() {
    // get method name as string
    String testName = new Object() {
    }.getClass().getEnclosingMethod().getName();
    Theory theory = new CommonTheory();
    String[] symbolsAndTypes = {};
    Context context = new TrueContext(theory).extendWithSymbolsAndTypes(symbolsAndTypes);
    Expression[] operandExpressions = { parse("true"), parse("false") };
    Expression[] expectedResultPerGroup = { parse("false"), parse("true") };
    repeatTestForEachRespectiveGroup(testName, theory, context, operandExpressions, expectedResultPerGroup, QUANTIFIER_BASED_GROUPS);
    println();
}
Also used : CommonTheory(com.sri.ai.grinder.application.CommonTheory) TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) CommonTheory(com.sri.ai.grinder.application.CommonTheory) Theory(com.sri.ai.grinder.api.Theory) Expression(com.sri.ai.expresso.api.Expression) TrueContext(com.sri.ai.grinder.core.TrueContext) Test(org.junit.Test)

Example 24 with CommonTheory

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

the class AssociativeCommutativeGroupOperationApplicationStepSolverTest method numericGroupTestMaxOperandsWithFreeVariables.

// @Test
public void numericGroupTestMaxOperandsWithFreeVariables() {
    // get method name as string
    String testName = new Object() {
    }.getClass().getEnclosingMethod().getName();
    Theory theory = new CommonTheory();
    String[] symbolsAndTypes = { "K", "0..5" };
    Context context = new TrueContext(theory).extendWithSymbolsAndTypes(symbolsAndTypes);
    Expression[] operandExpressions = { parse("max({{(on I in 3..5) if I != 4 and K != 2 then X else 1 }})"), parse("max({{(on J in 1..5) if J != 3 then if K != 3 then J else Y else 1 }})"), parse("max({{(on L in 0..2) if K != 0 then if L != 0 then J/L else Z else if L!=0 then 0 else 1 }})") };
    Expression[] expectedResultPerGroup = { parse("if K != 2 then if K != 3 then max(max(max(X, 1), 5), max({{ ( on L in 0..2 ) if K != 0 " + "then if L != 0 then J / L else Z else if L != 0 then 0 else 1 }})) " + "else max(max(max(X, 1), max(max(max(max(Y, Y), 1), Y), Y)), max(max(Z, J), J / 2)) " + "else max(5, max(max(Z, J), J / 2))"), parse("if K != 2 then if K != 3 then max(X, 1) * 5 * max({{ ( on L in 0..2 ) if K != 0 " + "then if L != 0 then J / L else Z else if L != 0 then 0 else 1 }}) else max(X, 1) * " + "max(max(max(max(Y, Y), 1), Y), Y) * max(max(Z, J), J / 2) else 5 * max(max(Z, J), J / 2)"), parse("if K != 2 then if K != 3 then max(X, 1) + 5 + max({{ ( on L in 0..2 ) if K != 0 then if L != 0 " + "then J / L else Z else if L != 0 then 0 else 1 }}) else max(X, 1) + " + "max(max(max(max(Y, Y), 1), Y), Y) + max(max(Z, J), J / 2) else 6 + max(max(Z, J), J / 2)") };
    repeatTestForEachRespectiveGroup(testName, theory, context, operandExpressions, expectedResultPerGroup, NUMERIC_GROUPS);
    println();
}
Also used : CommonTheory(com.sri.ai.grinder.application.CommonTheory) TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) CommonTheory(com.sri.ai.grinder.application.CommonTheory) Theory(com.sri.ai.grinder.api.Theory) Expression(com.sri.ai.expresso.api.Expression) TrueContext(com.sri.ai.grinder.core.TrueContext)

Example 25 with CommonTheory

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

the class AssociativeCommutativeGroupOperationApplicationStepSolverTest method quantifierBasedGroupTest01.

// / QUANTIFIER-BASED GROUP TESTS //////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////////////////////////////
@Test
public void quantifierBasedGroupTest01() {
    // get method name as string
    String testName = new Object() {
    }.getClass().getEnclosingMethod().getName();
    Theory theory = new CommonTheory();
    String[] symbolsAndTypes = {};
    Context context = new TrueContext(theory).extendWithSymbolsAndTypes(symbolsAndTypes);
    Expression[] operandExpressions = { parse("true"), parse("true") };
    Expression[] expectedResultPerGroup = { parse("true"), parse("true") };
    repeatTestForEachRespectiveGroup(testName, theory, context, operandExpressions, expectedResultPerGroup, QUANTIFIER_BASED_GROUPS);
    println();
}
Also used : CommonTheory(com.sri.ai.grinder.application.CommonTheory) TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) CommonTheory(com.sri.ai.grinder.application.CommonTheory) Theory(com.sri.ai.grinder.api.Theory) 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