Search in sources :

Example 26 with CommonTheory

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

the class AssociativeCommutativeGroupOperationApplicationStepSolverTest method quantifierBasedGroupTest00.

@Test
public void quantifierBasedGroupTest00() {
    // 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("there exists I in Integer : I > 3 and I < 10"), parse("for all I in Integer : if I > 3 and I < 10 then true else 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 27 with CommonTheory

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

the class IfThenElseStepSolverTest method test12.

@Test
public void test12() {
    Expression expression = parse("if (X=1) or (Y=1) then (X=1) and (Y=1) else (X=1) or (Y=1)");
    String[] symbolsAndTypes = { "X", "0..1", "Y", "0..1" };
    Context context = new TrueContext(new CommonTheory()).extendWithSymbolsAndTypes(symbolsAndTypes);
    Expression expectedResult = parse("if X = 1 then Y = 1 else false");
    // 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 28 with CommonTheory

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

the class OptimizationWithBOBYQA method numberOfVariablesInExpression.

public int numberOfVariablesInExpression() {
    Theory theory = new CommonTheory();
    Context context = new TrueContext(theory);
    Set<Expression> variablesInExpression = Expressions.freeVariables(expressionToOptimize, context);
    return variablesInExpression.size();
}
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 29 with CommonTheory

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

the class AssociativeCommutativeGroupOperationApplicationStepSolverTest method numericGroupTestProductOperandsWithFreeVariables.

// @Test
public void numericGroupTestProductOperandsWithFreeVariables() {
    // 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("product({{(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 }})") };
    Expression[] expectedResultPerGroup = { parse("if K != 2 then if K != 3 then max(X ^ 2, 40) else max(X ^ 2, Y * Y * Y * Y) else 40"), parse("if K != 2 then if K != 3 then X ^ 2 * 40 else X ^ 2 * Y * Y * Y * Y else 40"), parse("if K != 2 then if K != 3 then X ^ 2 + 40 else Y ^ 4 + X ^ 2 else 41") };
    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 30 with CommonTheory

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

the class AssociativeCommutativeGroupOperationApplicationStepSolverTest method quantifierBasedGroupTest03.

@Test
public void quantifierBasedGroupTest03() {
    // 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("true") };
    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)

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