Search in sources :

Example 1 with FirstOf

use of com.sri.ai.grinder.sgdpllt.rewriter.core.FirstOf 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.registerAdditionalSymbolsAndTypes(symbolsAndTypes);
    Rewriter firstOf = new FirstOf(rewriters);
    Expression solution = firstOf.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) PropositionalTheory(com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory) FirstOf(com.sri.ai.grinder.sgdpllt.rewriter.core.FirstOf) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory) TrueContext(com.sri.ai.grinder.sgdpllt.core.TrueContext)

Example 2 with FirstOf

use of com.sri.ai.grinder.sgdpllt.rewriter.core.FirstOf 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 3 with FirstOf

use of com.sri.ai.grinder.sgdpllt.rewriter.core.FirstOf 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 4 with FirstOf

use of com.sri.ai.grinder.sgdpllt.rewriter.core.FirstOf 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 5 with FirstOf

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

the class SwitchTest method testMerge.

@Test
public void testMerge() {
    Switch<String> switch1 = new Switch<>(stringMaker, Util.map("1", new Label("11"), "2", new Label("21")));
    Switch<String> switch2 = new Switch<>(stringMaker, Util.map("1", new Label("12"), "3", new Label("31")));
    Switch<String> switch3 = new Switch<>(stringMaker, Util.map());
    Switch<String> switch4 = new Switch<>(stringMaker, Util.map("4", new Label("41")));
    Switch<String> switch5 = new Switch<>(stringMaker, Util.map("3", new Label("32")));
    Switch<String> expected = new Switch<>(stringMaker, Util.map("1", new FirstOf(list(new Label("11"), new Label("12"))), "2", new Label("21"), "3", new FirstOf(list(new Label("31"), new Label("32"))), "4", new Label("41")));
    Rewriter merged = Switch.merge(list(switch1, switch2, switch3, switch4, switch5));
    assertEquals(expected, merged);
}
Also used : Switch(com.sri.ai.grinder.sgdpllt.rewriter.core.Switch) 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) FirstOf(com.sri.ai.grinder.sgdpllt.rewriter.core.FirstOf) Test(org.junit.Test)

Aggregations

Rewriter (com.sri.ai.grinder.sgdpllt.rewriter.api.Rewriter)6 FirstOf (com.sri.ai.grinder.sgdpllt.rewriter.core.FirstOf)6 TopRewriter (com.sri.ai.grinder.sgdpllt.rewriter.api.TopRewriter)5 LiteralRewriter (com.sri.ai.grinder.sgdpllt.library.boole.LiteralRewriter)3 DefaultTopRewriter (com.sri.ai.grinder.sgdpllt.rewriter.core.DefaultTopRewriter)3 Exhaustive (com.sri.ai.grinder.sgdpllt.rewriter.core.Exhaustive)3 Recursive (com.sri.ai.grinder.sgdpllt.rewriter.core.Recursive)3 ExpressionLiteralSplitterStepSolver (com.sri.ai.grinder.sgdpllt.api.ExpressionLiteralSplitterStepSolver)2 Switch (com.sri.ai.grinder.sgdpllt.rewriter.core.Switch)2 Test (org.junit.Test)2 Expression (com.sri.ai.expresso.api.Expression)1 Context (com.sri.ai.grinder.sgdpllt.api.Context)1 TrueContext (com.sri.ai.grinder.sgdpllt.core.TrueContext)1 BooleanSimplifier (com.sri.ai.grinder.sgdpllt.library.boole.BooleanSimplifier)1 ForAllRewriter (com.sri.ai.grinder.sgdpllt.library.boole.ForAllRewriter)1 ThereExistsRewriter (com.sri.ai.grinder.sgdpllt.library.boole.ThereExistsRewriter)1 MaxRewriter (com.sri.ai.grinder.sgdpllt.library.number.MaxRewriter)1 ProductRewriter (com.sri.ai.grinder.sgdpllt.library.number.ProductRewriter)1 SummationRewriter (com.sri.ai.grinder.sgdpllt.library.number.SummationRewriter)1 CardinalityTopRewriter (com.sri.ai.grinder.sgdpllt.library.set.CardinalityTopRewriter)1