Search in sources :

Example 31 with CommonTheory

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

the class AssociativeCommutativeGroupOperationApplicationStepSolverTest method quantifierBasedGroupTestFreeVariableInsideSummations.

@Test
public void quantifierBasedGroupTestFreeVariableInsideSummations() {
    // get method name as string
    String testName = new Object() {
    }.getClass().getEnclosingMethod().getName();
    Theory theory = new CommonTheory();
    String[] symbolsAndTypes = { "K", "1..5", "X", "1..5" };
    Context context = new TrueContext(theory).extendWithSymbolsAndTypes(symbolsAndTypes);
    Expression[] operandExpressions = { parse("there exists I in Integer : I > 3 and I < K"), parse("for all J in Integer : if J > K and J < 10 then X else Y") };
    Expression[] expectedResultPerGroup = { parse("if 4 < K then X and Y else false"), parse("if 4 < K then true else X and Y") };
    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 32 with CommonTheory

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

the class AssociativeCommutativeGroupOperationApplicationStepSolverTest method numericGroupCombinedTest.

// @Test
public void numericGroupCombinedTest() {
    // 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("sum({{(on I in 3..5) if I != 4 and K != 2 then X else 1 }})"), parse("product({{(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(2 * X + 1, 40), 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(2 * X + 1, Y * Y * Y * Y), max(max(Z, J), J / 2)) else max(40, max(max(Z, J), J / 2))"), parse("if K != 2 then if K != 3 then (2 * X + 1) * 40 * 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 (2 * X + 1) * Y * Y * Y * Y * max(max(Z, J), J / 2) else 120 * max(max(Z, J), J / 2)"), parse("if K != 2 then if K != 3 then 2 * X + 41 + 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 Y ^ 4 + 2 * X + 1 + max(max(Z, J), J / 2) else 43 + 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 33 with CommonTheory

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

the class AssociativeCommutativeGroupOperationApplicationStepSolverTest method numericGroupTestFreeVariableInsideSummations.

// /////////////////////////////////////////////////////////////////////////////////////////////////////////////
// JUNIT TESTS ////////////////////////////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////
// / NUMERIC GROUP TESTS //////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////////////////////
@Test
public void numericGroupTestFreeVariableInsideSummations() {
    // get method name as string
    String testName = new Object() {
    }.getClass().getEnclosingMethod().getName();
    Theory theory = new CommonTheory();
    String[] symbolsAndTypes = { "K", "1..5" };
    Context context = new TrueContext(theory).extendWithSymbolsAndTypes(symbolsAndTypes);
    Expression[] operandExpressions = { parse("sum({{(on I in 1..5) if I != 3 and K != 4 then 30 else 40 }})"), parse("sum({{(on J in 10..13) if J != 5 then if K != 3 then J else 0 else 40 }})") };
    Expression[] expectedResultPerGroup = { parse("if K != 4 then 160 else 200"), parse("if K != 4 then if K != 3 then 7360 else 0 else 9200"), parse("if K != 4 then if K != 3 then 206 else 160 else 246") };
    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 34 with CommonTheory

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

the class AssociativeCommutativeGroupOperationApplicationStepSolverTest method quantifierBasedGroupTest04.

@Test
public void quantifierBasedGroupTest04() {
    // 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("false"), parse("false") };
    Expression[] expectedResultPerGroup = { parse("false"), parse("false") };
    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 35 with CommonTheory

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

the class AssociativeCommutativeGroupOperationApplicationStepSolverTest method numericGroupTestWithMaxOperandsWithFreeVariables.

@Test
public void numericGroupTestWithMaxOperandsWithFreeVariables() {
    // 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("max({{(on I in 0..5) if I < 2 then I*X else Y }})"), parse("max({{(on J in 10..20) if J < 10 then Y else J*Z }})") };
    Expression[] expectedResultPerGroup = { parse("max(max(max(max(max(max(0, X), Y), Y), Y), Y), " + "max(max(max(max(max(max(max(max(max(max(10 * Z, 11 * Z), 12 * Z), 13 * Z), 14 * Z), " + "15 * Z), 16 * Z), 17 * Z), 18 * Z), 19 * Z), 20 * Z))"), parse("max(max(max(max(max(0, X), Y), Y), Y), Y) * " + "max(max(max(max(max(max(max(max(max(max(10 * Z, 11 * Z), 12 * Z), 13 * Z), 14 * Z), " + "15 * Z), 16 * Z), 17 * Z), 18 * Z), 19 * Z), 20 * Z)"), parse("max(max(max(max(max(0, X), Y), Y), Y), Y) + " + "max(max(max(max(max(max(max(max(max(max(10 * Z, 11 * Z), 12 * Z), 13 * Z), 14 * Z), " + "15 * Z), 16 * Z), 17 * Z), 18 * Z), 19 * Z), 20 * Z)") };
    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)

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