Search in sources :

Example 11 with TrueContext

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

the class LambdaBetaReductionSimplifierTest method testNoReduction.

@Test
public void testNoReduction() {
    Type peopleType = new Categorical("People", 4, arrayList(makeSymbol("ann"), makeSymbol("bob"), makeSymbol("tom")));
    Context context = new TrueContext();
    context = context.makeNewContextWithAddedType(peopleType);
    Assert.assertEquals(parse("(lambda X in People : if X = ann then 0 else if X = bob then 0 else 0)()"), simplifier.apply(parse("(lambda X in People : if X = ann then 0 else if X = bob then 0 else 0)()"), context));
    Assert.assertEquals(parse("(lambda X in People, Y in People : if X = ann then 0 else if Y = bob then 0 else 0)(ann)"), simplifier.apply(parse("(lambda X in People, Y in People : if X = ann then 0 else if Y = bob then 0 else 0)(ann)"), context));
    Assert.assertEquals(parse("(lambda X in People, Y in People : if X = ann then 0 else if Y = bob then 0 else 0)(ann, bob, tom)"), simplifier.apply(parse("(lambda X in People, Y in People : if X = ann then 0 else if Y = bob then 0 else 0)(ann, bob, tom)"), context));
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) Type(com.sri.ai.expresso.api.Type) Categorical(com.sri.ai.expresso.type.Categorical) TrueContext(com.sri.ai.grinder.core.TrueContext) Test(org.junit.Test)

Example 12 with TrueContext

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

the class ProceduralAttachmentsTest method test.

@Test
public void test() {
    Context context;
    Expression input;
    Expression expected;
    context = new TrueContext();
    Simplifier replaceBy10 = (e, c) -> makeSymbol(10);
    registerProceduralAttachment(makeSymbol("ten"), replaceBy10, context);
    Simplifier makeHWithFlippedArguments = (e, c) -> apply("h", e.getArguments());
    registerProceduralAttachment(makeSymbol("g"), 2, makeHWithFlippedArguments, context);
    input = parse("ten + 1 + g(1, 2) + g(1)");
    expected = parse("11 + h(1, 2) + g(1)");
    runTest(input, expected, context);
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) CommonSimplifier(com.sri.ai.grinder.library.commonrewriters.CommonSimplifier) Test(org.junit.Test) Expression(com.sri.ai.expresso.api.Expression) CombiningTopRewriter(com.sri.ai.grinder.rewriter.core.CombiningTopRewriter) ProceduralAttachments.registerProceduralAttachment(com.sri.ai.grinder.library.proceduralattachment.ProceduralAttachments.registerProceduralAttachment) ProceduralAttachments.getProceduralAttachmentsTopRewriter(com.sri.ai.grinder.library.proceduralattachment.ProceduralAttachments.getProceduralAttachmentsTopRewriter) Exhaustive(com.sri.ai.grinder.rewriter.core.Exhaustive) Expressions.makeSymbol(com.sri.ai.expresso.helper.Expressions.makeSymbol) Expressions.apply(com.sri.ai.expresso.helper.Expressions.apply) TrueContext(com.sri.ai.grinder.core.TrueContext) Rewriter(com.sri.ai.grinder.rewriter.api.Rewriter) Expressions.parse(com.sri.ai.expresso.helper.Expressions.parse) Simplifier(com.sri.ai.grinder.rewriter.api.Simplifier) TopRewriter(com.sri.ai.grinder.rewriter.api.TopRewriter) Context(com.sri.ai.grinder.api.Context) Util.println(com.sri.ai.util.Util.println) Recursive(com.sri.ai.grinder.rewriter.core.Recursive) Assert.assertEquals(org.junit.Assert.assertEquals) Expression(com.sri.ai.expresso.api.Expression) CommonSimplifier(com.sri.ai.grinder.library.commonrewriters.CommonSimplifier) Simplifier(com.sri.ai.grinder.rewriter.api.Simplifier) TrueContext(com.sri.ai.grinder.core.TrueContext) Test(org.junit.Test)

Example 13 with TrueContext

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

the class IntensionalSetFalseConditionToEmptySetSimplifierTest method setUp.

@Before
public void setUp() {
    context = new TrueContext(new CompoundTheory(new DifferenceArithmeticTheory(false, false), new TupleTheory()));
    IntegerInterval nType = new IntegerInterval(1, 10);
    context = (Context) GrinderUtil.extendRegistryWith(map("N", nType.toString()), Arrays.asList(nType), context);
    simplifier = new IntensionalSetFalseConditionToEmptySetSimplifier();
}
Also used : DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) TrueContext(com.sri.ai.grinder.core.TrueContext) TupleTheory(com.sri.ai.grinder.theory.tuple.TupleTheory) IntensionalSetFalseConditionToEmptySetSimplifier(com.sri.ai.grinder.library.set.IntensionalSetFalseConditionToEmptySetSimplifier) Before(org.junit.Before)

Example 14 with TrueContext

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

the class IntensionalSetToConditionalSimplifierTest method setUp.

@Before
public void setUp() {
    context = new TrueContext(new CompoundTheory(new DifferenceArithmeticTheory(false, false), new TupleTheory()));
    IntegerInterval nType = new IntegerInterval(1, 10);
    context = (Context) GrinderUtil.extendRegistryWith(map("N", nType.toString()), Arrays.asList(nType), context);
    simplifier = new IntensionalSetToConditionalSimplifier();
}
Also used : DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) IntensionalSetToConditionalSimplifier(com.sri.ai.grinder.library.set.invsupport.IntensionalSetToConditionalSimplifier) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) TrueContext(com.sri.ai.grinder.core.TrueContext) TupleTheory(com.sri.ai.grinder.theory.tuple.TupleTheory) Before(org.junit.Before)

Example 15 with TrueContext

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

the class IntersectionExtensionalSetSimplifierTest method setUp.

@Before
public void setUp() {
    context = new TrueContext(new CompoundTheory(new DifferenceArithmeticTheory(false, false), new TupleTheory()));
    IntegerInterval intType = new IntegerInterval(1, 10);
    context = (Context) GrinderUtil.extendRegistryWith(map("M", intType.toString(), "N", intType.toString()), Arrays.asList(intType), context);
    simplifier = new IntersectionExtensionalSetSimplifier();
}
Also used : IntersectionExtensionalSetSimplifier(com.sri.ai.grinder.library.set.invsupport.IntersectionExtensionalSetSimplifier) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) TrueContext(com.sri.ai.grinder.core.TrueContext) TupleTheory(com.sri.ai.grinder.theory.tuple.TupleTheory) Before(org.junit.Before)

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