Search in sources :

Example 21 with TrueContext

use of com.sri.ai.grinder.core.TrueContext in project aic-expresso by aic-sri-international.

the class BasicTest method debug.

private void debug(Expression problem) {
    Theory theory = new DifferenceArithmeticTheory(true, true);
    Context context = new TrueContext(theory);
    context = context.putGlobalObject(BRUTE_FORCE_CHECKING_OF_NON_CONDITIONAL_PROBLEMS, "Yes");
    Expression symbolicSolution = theory.evaluate(problem, context);
    println(symbolicSolution);
    BruteForceInterpreter bruteForceInterpreter = new BruteForceCommonInterpreter();
    Expression bruteForceSolution = bruteForceInterpreter.apply(problem, context);
    println(bruteForceSolution);
    Assert.assertEquals(bruteForceSolution, symbolicSolution);
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) BruteForceCommonInterpreter(com.sri.ai.grinder.interpreter.BruteForceCommonInterpreter) Theory(com.sri.ai.grinder.api.Theory) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) Expression(com.sri.ai.expresso.api.Expression) BruteForceInterpreter(com.sri.ai.grinder.interpreter.BruteForceInterpreter) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) TrueContext(com.sri.ai.grinder.core.TrueContext)

Example 22 with TrueContext

use of com.sri.ai.grinder.core.TrueContext in project aic-expresso by aic-sri-international.

the class FirstOfTest method runTest.

private void runTest(List<Rewriter> rewriters, Expression initial, Expression expected, Map<Expression, Expression> symbolsAndTypes) {
    CompoundTheory theory = new CompoundTheory(new PropositionalTheory(), new DifferenceArithmeticTheory(false, true));
    Context context = new TrueContext(theory);
    context = context.makeCloneWithAdditionalRegisteredSymbolsAndTypes(symbolsAndTypes);
    Rewriter firstOf = new FirstOf(rewriters);
    Expression solution = firstOf.apply(initial, context);
    System.out.println("Solution: " + solution);
    assertEquals(expected, solution);
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) Expression(com.sri.ai.expresso.api.Expression) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) Rewriter(com.sri.ai.grinder.rewriter.api.Rewriter) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) FirstOf(com.sri.ai.grinder.rewriter.core.FirstOf) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) TrueContext(com.sri.ai.grinder.core.TrueContext)

Example 23 with TrueContext

use of com.sri.ai.grinder.core.TrueContext in project aic-expresso by aic-sri-international.

the class RecursiveTest method runTest.

private void runTest(Rewriter rewriter, Expression initial, Expression expected, Map<Expression, Expression> symbolsAndTypes) {
    CompoundTheory theory = new CompoundTheory(new PropositionalTheory(), new DifferenceArithmeticTheory(false, true));
    Context context = new TrueContext(theory);
    context = context.makeCloneWithAdditionalRegisteredSymbolsAndTypes(symbolsAndTypes);
    Rewriter recursive = new Recursive(rewriter);
    Expression solution = recursive.apply(initial, context);
    System.out.println("Solution: " + solution);
    assertEquals(expected, solution);
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) Expression(com.sri.ai.expresso.api.Expression) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) Rewriter(com.sri.ai.grinder.rewriter.api.Rewriter) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) Recursive(com.sri.ai.grinder.rewriter.core.Recursive) TrueContext(com.sri.ai.grinder.core.TrueContext)

Example 24 with TrueContext

use of com.sri.ai.grinder.core.TrueContext in project aic-expresso by aic-sri-international.

the class SwitchTest method runTest.

private void runTest(Rewriter rewriter, Expression initial, Expression expected, Map<Expression, Expression> symbolsAndTypes) {
    CompoundTheory theory = new CompoundTheory(new PropositionalTheory(), new DifferenceArithmeticTheory(false, true));
    Context context = new TrueContext(theory);
    context = context.makeCloneWithAdditionalRegisteredSymbolsAndTypes(symbolsAndTypes);
    Rewriter recursive = new Recursive(rewriter);
    Expression solution = recursive.apply(initial, context);
    System.out.println("Solution: " + solution);
    assertEquals(expected, solution);
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) Expression(com.sri.ai.expresso.api.Expression) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) CombiningTopRewriter(com.sri.ai.grinder.rewriter.core.CombiningTopRewriter) Rewriter(com.sri.ai.grinder.rewriter.api.Rewriter) TopRewriter(com.sri.ai.grinder.rewriter.api.TopRewriter) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) Recursive(com.sri.ai.grinder.rewriter.core.Recursive) TrueContext(com.sri.ai.grinder.core.TrueContext)

Example 25 with TrueContext

use of com.sri.ai.grinder.core.TrueContext in project aic-expresso by aic-sri-international.

the class BruteForceFallbackTheoryTest method runTest.

private static void runTest(String expressionString, String expectedString, String... symbolsAndTypes) {
    Theory theory = new BruteForceFallbackTheory(new DifferenceArithmeticTheory(false, true));
    Context context = new TrueContext(theory);
    context = context.extendWithSymbolsAndTypes(symbolsAndTypes);
    Expression expression = parse(expressionString);
    Expression expected = parse(expectedString);
    Expression actual = theory.evaluate(expression, context);
    println(actual);
    assertEquals(expected, actual);
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) BruteForceFallbackTheory(com.sri.ai.grinder.theory.bruteforce.BruteForceFallbackTheory) Theory(com.sri.ai.grinder.api.Theory) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) BruteForceFallbackTheory(com.sri.ai.grinder.theory.bruteforce.BruteForceFallbackTheory) Expression(com.sri.ai.expresso.api.Expression) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) TrueContext(com.sri.ai.grinder.core.TrueContext)

Aggregations

TrueContext (com.sri.ai.grinder.core.TrueContext)39 DifferenceArithmeticTheory (com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory)28 CompoundTheory (com.sri.ai.grinder.theory.compound.CompoundTheory)25 Context (com.sri.ai.grinder.api.Context)24 Expression (com.sri.ai.expresso.api.Expression)20 TupleTheory (com.sri.ai.grinder.theory.tuple.TupleTheory)18 PropositionalTheory (com.sri.ai.grinder.theory.propositional.PropositionalTheory)15 Before (org.junit.Before)12 EqualityTheory (com.sri.ai.grinder.theory.equality.EqualityTheory)11 IntegerInterval (com.sri.ai.expresso.type.IntegerInterval)10 Test (org.junit.Test)10 LinearRealArithmeticTheory (com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory)9 Theory (com.sri.ai.grinder.api.Theory)6 Rewriter (com.sri.ai.grinder.rewriter.api.Rewriter)6 Type (com.sri.ai.expresso.api.Type)3 ExtensionalIndexExpressionsSet (com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet)3 CombiningTopRewriter (com.sri.ai.grinder.rewriter.core.CombiningTopRewriter)3 Exhaustive (com.sri.ai.grinder.rewriter.core.Exhaustive)3 Recursive (com.sri.ai.grinder.rewriter.core.Recursive)3 Random (java.util.Random)3