Search in sources :

Example 1 with Recursive

use of com.sri.ai.grinder.sgdpllt.rewriter.core.Recursive in project aic-expresso by aic-sri-international.

the class DifferenceArithmeticTheory method makeEvaluatorStepSolver.

@Override
public ExpressionLiteralSplitterStepSolver makeEvaluatorStepSolver(Expression expression) {
    Rewriter literalExternalizer = new LiteralRewriter(new Recursive(new Exhaustive(getTopRewriter())));
    ExpressionLiteralSplitterStepSolver result = new Recursive(new Exhaustive(new FirstOf(getTopRewriter(), literalExternalizer))).makeStepSolver(expression);
    return result;
}
Also used : Exhaustive(com.sri.ai.grinder.sgdpllt.rewriter.core.Exhaustive) ExpressionLiteralSplitterStepSolver(com.sri.ai.grinder.sgdpllt.api.ExpressionLiteralSplitterStepSolver) Rewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.Rewriter) LiteralRewriter(com.sri.ai.grinder.sgdpllt.library.boole.LiteralRewriter) TopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.TopRewriter) FirstOf(com.sri.ai.grinder.sgdpllt.rewriter.core.FirstOf) LiteralRewriter(com.sri.ai.grinder.sgdpllt.library.boole.LiteralRewriter) Recursive(com.sri.ai.grinder.sgdpllt.rewriter.core.Recursive)

Example 2 with Recursive

use of com.sri.ai.grinder.sgdpllt.rewriter.core.Recursive 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.registerAdditionalSymbolsAndTypes(symbolsAndTypes);
    Rewriter recursive = new Recursive(rewriter);
    Expression solution = recursive.apply(initial, context);
    System.out.println("Solution: " + solution);
    assertEquals(expected, solution);
}
Also used : Context(com.sri.ai.grinder.sgdpllt.api.Context) TrueContext(com.sri.ai.grinder.sgdpllt.core.TrueContext) Expression(com.sri.ai.expresso.api.Expression) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) Rewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.Rewriter) DefaultTopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.core.DefaultTopRewriter) TopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.TopRewriter) PropositionalTheory(com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory) Recursive(com.sri.ai.grinder.sgdpllt.rewriter.core.Recursive) TrueContext(com.sri.ai.grinder.sgdpllt.core.TrueContext)

Example 3 with Recursive

use of com.sri.ai.grinder.sgdpllt.rewriter.core.Recursive in project aic-expresso by aic-sri-international.

the class AbstractTheory method makeEvaluatorStepSolver.

@Override
public ExpressionLiteralSplitterStepSolver makeEvaluatorStepSolver(Expression expression) {
    Rewriter literalExternalizer = new LiteralRewriter(new Recursive(new Exhaustive(getTopRewriter())));
    Recursive completeEvaluator = new Recursive(new Exhaustive(new FirstOf(getTopRewriter(), literalExternalizer)));
    // it is a good idea to leave the literal externalizer at the end,
    // since it is expensive due to duplicating the entire problem at every split
    ExpressionLiteralSplitterStepSolver result = completeEvaluator.makeStepSolver(expression);
    return result;
}
Also used : Exhaustive(com.sri.ai.grinder.sgdpllt.rewriter.core.Exhaustive) ExpressionLiteralSplitterStepSolver(com.sri.ai.grinder.sgdpllt.api.ExpressionLiteralSplitterStepSolver) MaxRewriter(com.sri.ai.grinder.sgdpllt.library.number.MaxRewriter) Rewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.Rewriter) ThereExistsRewriter(com.sri.ai.grinder.sgdpllt.library.boole.ThereExistsRewriter) ForAllRewriter(com.sri.ai.grinder.sgdpllt.library.boole.ForAllRewriter) LiteralRewriter(com.sri.ai.grinder.sgdpllt.library.boole.LiteralRewriter) TopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.TopRewriter) SummationRewriter(com.sri.ai.grinder.sgdpllt.library.number.SummationRewriter) CardinalityTopRewriter(com.sri.ai.grinder.sgdpllt.library.set.CardinalityTopRewriter) ProductRewriter(com.sri.ai.grinder.sgdpllt.library.number.ProductRewriter) FirstOf(com.sri.ai.grinder.sgdpllt.rewriter.core.FirstOf) LiteralRewriter(com.sri.ai.grinder.sgdpllt.library.boole.LiteralRewriter) Recursive(com.sri.ai.grinder.sgdpllt.rewriter.core.Recursive)

Example 4 with Recursive

use of com.sri.ai.grinder.sgdpllt.rewriter.core.Recursive in project aic-expresso by aic-sri-international.

the class AbstractIterativeMultiIndexQuantifierElimination method solve.

public Expression solve(AssociativeCommutativeGroup group, List<Expression> indices, Expression indicesCondition, Expression body, Context context) {
    Expression result = group.additiveIdentityElement();
    Expression summand = makeSummand(group, indices, indicesCondition, body, context);
    Rewriter rewriter = new Recursive(new Exhaustive(getTopRewriterUsingContextAssignments()));
    Iterator<Map<Expression, Expression>> assignmentsIterator = makeAssignmentsIterator(indices, indicesCondition, context);
    for (Map<Expression, Expression> indicesValues : in(assignmentsIterator)) {
        Context extendedContext = extendAssignments(indicesValues, context);
        Expression bodyEvaluation = rewriter.apply(summand, extendedContext);
        if (group.isAdditiveAbsorbingElement(bodyEvaluation)) {
            return bodyEvaluation;
        }
        result = group.add(result, bodyEvaluation, extendedContext);
    }
    return result;
}
Also used : Context(com.sri.ai.grinder.sgdpllt.api.Context) Expression(com.sri.ai.expresso.api.Expression) Exhaustive(com.sri.ai.grinder.sgdpllt.rewriter.core.Exhaustive) Rewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.Rewriter) TopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.TopRewriter) Recursive(com.sri.ai.grinder.sgdpllt.rewriter.core.Recursive) StackedHashMap(com.sri.ai.util.collect.StackedHashMap) Map(java.util.Map)

Example 5 with Recursive

use of com.sri.ai.grinder.sgdpllt.rewriter.core.Recursive in project aic-expresso by aic-sri-international.

the class AbstractInterpreter method setBaseTopRewriter.

public void setBaseTopRewriter(TopRewriter baseTopRewriter) {
    Rewriter result = new Recursive(new Exhaustive(new TopRewriterUsingQuantifierEliminatorAndContextAssignments(baseTopRewriter)));
    setBaseRewriter(result);
}
Also used : Exhaustive(com.sri.ai.grinder.sgdpllt.rewriter.core.Exhaustive) MaxRewriter(com.sri.ai.grinder.sgdpllt.library.number.MaxRewriter) RedirectingRewriter(com.sri.ai.grinder.sgdpllt.rewriter.help.RedirectingRewriter) SummationRewriter(com.sri.ai.grinder.sgdpllt.library.number.SummationRewriter) Rewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.Rewriter) ThereExistsRewriter(com.sri.ai.grinder.sgdpllt.library.boole.ThereExistsRewriter) ProductRewriter(com.sri.ai.grinder.sgdpllt.library.number.ProductRewriter) ForAllRewriter(com.sri.ai.grinder.sgdpllt.library.boole.ForAllRewriter) TopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.TopRewriter) Recursive(com.sri.ai.grinder.sgdpllt.rewriter.core.Recursive)

Aggregations

Recursive (com.sri.ai.grinder.sgdpllt.rewriter.core.Recursive)9 Rewriter (com.sri.ai.grinder.sgdpllt.rewriter.api.Rewriter)7 Exhaustive (com.sri.ai.grinder.sgdpllt.rewriter.core.Exhaustive)7 TopRewriter (com.sri.ai.grinder.sgdpllt.rewriter.api.TopRewriter)6 Expression (com.sri.ai.expresso.api.Expression)3 Context (com.sri.ai.grinder.sgdpllt.api.Context)3 TrueContext (com.sri.ai.grinder.sgdpllt.core.TrueContext)3 LiteralRewriter (com.sri.ai.grinder.sgdpllt.library.boole.LiteralRewriter)3 FirstOf (com.sri.ai.grinder.sgdpllt.rewriter.core.FirstOf)3 CompoundTheory (com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory)3 DifferenceArithmeticTheory (com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory)3 PropositionalTheory (com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory)3 ExpressionLiteralSplitterStepSolver (com.sri.ai.grinder.sgdpllt.api.ExpressionLiteralSplitterStepSolver)2 ForAllRewriter (com.sri.ai.grinder.sgdpllt.library.boole.ForAllRewriter)2 ThereExistsRewriter (com.sri.ai.grinder.sgdpllt.library.boole.ThereExistsRewriter)2 MaxRewriter (com.sri.ai.grinder.sgdpllt.library.number.MaxRewriter)2 ProductRewriter (com.sri.ai.grinder.sgdpllt.library.number.ProductRewriter)2 SummationRewriter (com.sri.ai.grinder.sgdpllt.library.number.SummationRewriter)2 DefaultTopRewriter (com.sri.ai.grinder.sgdpllt.rewriter.core.DefaultTopRewriter)2 BruteForceCommonInterpreter (com.sri.ai.grinder.sgdpllt.interpreter.BruteForceCommonInterpreter)1