Search in sources :

Example 1 with TopRewriter

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

the class TupleRewriterTest method testTupleGetSetTopRewriter.

@Test
public void testTupleGetSetTopRewriter() {
    TopRewriter tupleGetSetTopRewriter = new TupleGetSetTopRewriter();
    Assert.assertEquals(parse("if I = 1 then a else if I = 2 then b else c"), tupleGetSetTopRewriter.apply(parse("get((a,b,c),I)"), context));
    Assert.assertEquals(parse("if I = 1 then (e,b,c) else if I = 2 then (a,e,c) else (a,b,e)"), tupleGetSetTopRewriter.apply(parse("set((a,b,c),I,e)"), context));
}
Also used : TupleGetSetTopRewriter(com.sri.ai.grinder.sgdpllt.theory.tuple.rewriter.TupleGetSetTopRewriter) TupleEqualityTopRewriter(com.sri.ai.grinder.sgdpllt.theory.tuple.rewriter.TupleEqualityTopRewriter) TupleGetSetTopRewriter(com.sri.ai.grinder.sgdpllt.theory.tuple.rewriter.TupleGetSetTopRewriter) TopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.TopRewriter) Test(org.junit.Test)

Example 2 with TopRewriter

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

the class TupleRewriterTest method testTupleEqualityTopRewriter.

@Test
public void testTupleEqualityTopRewriter() {
    TopRewriter tupleEqualityTopRewriter = new TupleEqualityTopRewriter();
    Assert.assertEquals(parse("A1 = B1 and A2 = B2 and A3 = B3"), tupleEqualityTopRewriter.apply(parse("(A1, A2, A3) = (B1, B2, B3)"), context));
    Assert.assertEquals(parse("(A1_1, A1_2, A1_3) = (B1_1, B1_2, B1_3) and A2 = B2 and A3 = B3"), tupleEqualityTopRewriter.apply(parse("((A1_1, A1_2, A1_3), A2, A3) = ((B1_1, B1_2, B1_3), B2, B3)"), context));
    Assert.assertEquals(parse("A1 != B1 or A2 != B2 or A3 != B3"), tupleEqualityTopRewriter.apply(parse("(A1, A2, A3) != (B1, B2, B3)"), context));
    Assert.assertEquals(parse("(A1_1, A1_2, A1_3) != (B1_1, B1_2, B1_3) or A2 != B2 or A3 != B3"), tupleEqualityTopRewriter.apply(parse("((A1_1, A1_2, A1_3), A2, A3) != ((B1_1, B1_2, B1_3), B2, B3)"), context));
    Expression expr = parse("(A1, A2) = (B1, B2, B3)");
    Assert.assertTrue(expr == tupleEqualityTopRewriter.apply(expr, context));
    expr = parse("A1 = B1");
    Assert.assertTrue(expr == tupleEqualityTopRewriter.apply(expr, context));
    expr = parse("(A1, A2) != (B1, B2, B3)");
    Assert.assertTrue(expr == tupleEqualityTopRewriter.apply(expr, context));
    expr = parse("A1 != B1");
    Assert.assertTrue(expr == tupleEqualityTopRewriter.apply(expr, context));
}
Also used : TupleEqualityTopRewriter(com.sri.ai.grinder.sgdpllt.theory.tuple.rewriter.TupleEqualityTopRewriter) Expression(com.sri.ai.expresso.api.Expression) TupleEqualityTopRewriter(com.sri.ai.grinder.sgdpllt.theory.tuple.rewriter.TupleEqualityTopRewriter) TupleGetSetTopRewriter(com.sri.ai.grinder.sgdpllt.theory.tuple.rewriter.TupleGetSetTopRewriter) TopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.TopRewriter) Test(org.junit.Test)

Example 3 with TopRewriter

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

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

the class CompoundTheory method getDefaultTopRewriter.

@Override
public TopRewriter getDefaultTopRewriter() {
    List<TopRewriter> subRewriters = mapIntoList(subTheories, t -> t.getTopRewriter());
    TopRewriter topRewriter = TopRewriter.merge(subRewriters);
    return topRewriter;
}
Also used : TopRewriter(com.sri.ai.grinder.sgdpllt.rewriter.api.TopRewriter)

Example 5 with TopRewriter

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

Aggregations

TopRewriter (com.sri.ai.grinder.sgdpllt.rewriter.api.TopRewriter)6 Rewriter (com.sri.ai.grinder.sgdpllt.rewriter.api.Rewriter)3 TupleEqualityTopRewriter (com.sri.ai.grinder.sgdpllt.theory.tuple.rewriter.TupleEqualityTopRewriter)3 Test (org.junit.Test)3 DefaultTopRewriter (com.sri.ai.grinder.sgdpllt.rewriter.core.DefaultTopRewriter)2 Exhaustive (com.sri.ai.grinder.sgdpllt.rewriter.core.Exhaustive)2 FirstOf (com.sri.ai.grinder.sgdpllt.rewriter.core.FirstOf)2 Recursive (com.sri.ai.grinder.sgdpllt.rewriter.core.Recursive)2 TupleGetSetTopRewriter (com.sri.ai.grinder.sgdpllt.theory.tuple.rewriter.TupleGetSetTopRewriter)2 Expression (com.sri.ai.expresso.api.Expression)1 BooleanSimplifier (com.sri.ai.grinder.sgdpllt.library.boole.BooleanSimplifier)1 ForAllRewriter (com.sri.ai.grinder.sgdpllt.library.boole.ForAllRewriter)1 LiteralRewriter (com.sri.ai.grinder.sgdpllt.library.boole.LiteralRewriter)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 Switch (com.sri.ai.grinder.sgdpllt.rewriter.core.Switch)1 RedirectingRewriter (com.sri.ai.grinder.sgdpllt.rewriter.help.RedirectingRewriter)1