Search in sources :

Example 6 with Rewriter

use of com.sri.ai.grinder.sgdpllt.rewriter.api.Rewriter 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 7 with Rewriter

use of com.sri.ai.grinder.sgdpllt.rewriter.api.Rewriter 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 8 with Rewriter

use of com.sri.ai.grinder.sgdpllt.rewriter.api.Rewriter 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)

Example 9 with Rewriter

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

the class SetDNFRewriter method createBaseRewriter.

private static Rewriter createBaseRewriter() {
    // Original Rewriters		
    TopRewriter topRewriter = new DefaultTopRewriter(new IntensionalUnionToUnionsOfIntensionalSetsOfBaseTypeTopRewriter(), // NOTE: added to simplify expressions like `if true then { (2, 2) } else {  }', which are common in this setup
    new BooleanSimplifier(), new UnionEmptySetTopRewriter(), new IntersectionEmptySetTopRewriter(), new IntensionalSetToConditionalTopRewriter(), new IntersectionIntensionalSetsTopRewriter(), new IntersectionExtensionalSetTopRewriter(), new DistributeIntersectionOverUnionTopRewriter());
    // Rewriters based on UAI 2017 Paper
    //		TopRewriter topRewriter = new DefaultTopRewriter(
    //			new TupleEqualityTopRewriter(),                               // Rule 1		
    //			new ElementOfExtensionalSetTopRewriter(),                     // Rule 2
    //			new ElementOfIntensionalUnionTopRewriter(),                   // Rule 3
    //			new IntensionalUnionEqualToEmptySetTopRewriter(),             // Rule 4
    //			new IntersectionEmptySetTopRewriter(),                        // Rule 5			
    //			new UnionEmptySetTopRewriter(),                               // Rule 6			
    //			new SetIntersectExtensionalSetEqualToEmptySetTopRewriter(),   // Rule 7
    //			new IntensionalUnionIntersectionEqualToEmptySetTopRewriter(), // Rule 8
    //			new DistributeIntersectionOverUnionTopRewriter(),             // Rule 9
    //			new UnionOfSetsEqualEmptySetTopRewriter(),                    // Rule 10
    //			new ExtensionalSetEqualEmptySetTopRewriter(),                 // Rule 11
    //			new BooleanSimplifier() // NOTE: added to simplify expressions like `if true then { (2, 2) } else {  }', which are common in this setup
    //			);		
    Rewriter literalExternalizer = new LiteralRewriter(new Recursive(new Exhaustive(topRewriter)));
    Rewriter result = new Exhaustive(new FirstOf(topRewriter, literalExternalizer));
    return result;
}
Also used : DefaultTopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.core.DefaultTopRewriter) Exhaustive(com.sri.ai.grinder.sgdpllt.rewriter.core.Exhaustive) DefaultTopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.core.DefaultTopRewriter) TupleEqualityTopRewriter(com.sri.ai.grinder.sgdpllt.theory.tuple.rewriter.TupleEqualityTopRewriter) TopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.TopRewriter) BooleanSimplifier(com.sri.ai.grinder.sgdpllt.library.boole.BooleanSimplifier) LiteralRewriter(com.sri.ai.grinder.sgdpllt.library.boole.LiteralRewriter) Rewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.Rewriter) LiteralRewriter(com.sri.ai.grinder.sgdpllt.library.boole.LiteralRewriter) DefaultTopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.core.DefaultTopRewriter) TupleEqualityTopRewriter(com.sri.ai.grinder.sgdpllt.theory.tuple.rewriter.TupleEqualityTopRewriter) TopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.TopRewriter) FirstOf(com.sri.ai.grinder.sgdpllt.rewriter.core.FirstOf) Recursive(com.sri.ai.grinder.sgdpllt.rewriter.core.Recursive)

Example 10 with Rewriter

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

the class Switch method makeStepSolver.

@Override
public ExpressionLiteralSplitterStepSolver makeStepSolver(Expression expression) {
    ExpressionLiteralSplitterStepSolver result;
    T key = keyMaker.apply(expression);
    Rewriter baseRewriter = fromKeyToRewriter.get(key);
    if (baseRewriter != null) {
        result = baseRewriter.makeStepSolver(expression);
    } else {
        result = new ConstantExpressionStepSolver(expression);
    }
    return result;
}
Also used : ExpressionLiteralSplitterStepSolver(com.sri.ai.grinder.sgdpllt.api.ExpressionLiteralSplitterStepSolver) Rewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.Rewriter) TopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.TopRewriter) ConstantExpressionStepSolver(com.sri.ai.grinder.sgdpllt.theory.base.ConstantExpressionStepSolver)

Aggregations

Rewriter (com.sri.ai.grinder.sgdpllt.rewriter.api.Rewriter)16 TopRewriter (com.sri.ai.grinder.sgdpllt.rewriter.api.TopRewriter)10 Expression (com.sri.ai.expresso.api.Expression)9 Context (com.sri.ai.grinder.sgdpllt.api.Context)9 TrueContext (com.sri.ai.grinder.sgdpllt.core.TrueContext)8 Recursive (com.sri.ai.grinder.sgdpllt.rewriter.core.Recursive)8 FirstOf (com.sri.ai.grinder.sgdpllt.rewriter.core.FirstOf)7 ExpressionLiteralSplitterStepSolver (com.sri.ai.grinder.sgdpllt.api.ExpressionLiteralSplitterStepSolver)6 Exhaustive (com.sri.ai.grinder.sgdpllt.rewriter.core.Exhaustive)6 Test (org.junit.Test)6 DefaultTopRewriter (com.sri.ai.grinder.sgdpllt.rewriter.core.DefaultTopRewriter)5 CompoundTheory (com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory)5 DifferenceArithmeticTheory (com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory)5 PropositionalTheory (com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory)5 Solution (com.sri.ai.grinder.sgdpllt.api.ExpressionLiteralSplitterStepSolver.Solution)4 ContextSplitting (com.sri.ai.grinder.sgdpllt.core.constraint.ContextSplitting)3 LiteralRewriter (com.sri.ai.grinder.sgdpllt.library.boole.LiteralRewriter)3 Switch (com.sri.ai.grinder.sgdpllt.rewriter.core.Switch)3 ForAllRewriter (com.sri.ai.grinder.sgdpllt.library.boole.ForAllRewriter)2 ThereExistsRewriter (com.sri.ai.grinder.sgdpllt.library.boole.ThereExistsRewriter)2