use of com.sri.ai.grinder.api.Context in project aic-expresso by aic-sri-international.
the class SamplingProceduralAttachmentSingleQuantifierEliminatorTest method test.
@Test
public void test() {
String intervalString = "0..10";
Context context = new TrueContext(new DifferenceArithmeticTheory(true, true));
MultiQuantifierEliminationProblem problem = new DefaultMultiQuantifierEliminationProblem(new Sum(), list(parse("I")), list(parse(intervalString)), parse("I != 3"), parse("I^2"));
SamplingProceduralAttachmentSingleQuantifierEliminator eliminator = new SamplingProceduralAttachmentSingleQuantifierEliminator(new CommonSimplifier(), new Random());
// SHOULD NOT HAVE TO
context = problem.extend(context);
Expression sampler = eliminator.solve(problem, context);
println(sampler);
Rewriter rewriter = new CombiningTopRewriter(new CommonSimplifier(), ProceduralAttachments.getProceduralAttachmentsTopRewriter(context));
println(rewriter.apply(sampler, context));
println(rewriter.apply(sampler, context));
println(rewriter.apply(sampler, context));
println(rewriter.apply(sampler, context));
println(rewriter.apply(sampler, context));
println(rewriter.apply(sampler, context));
println(rewriter.apply(sampler, context));
println(rewriter.apply(sampler, context));
println(rewriter.apply(sampler, context));
println(rewriter.apply(sampler, context));
println(rewriter.apply(sampler, context));
println(rewriter.apply(sampler, context));
println(rewriter.apply(sampler, context));
println(rewriter.apply(sampler, context));
println(rewriter.apply(sampler, context));
println(rewriter.apply(sampler, context));
println(rewriter.apply(sampler, context));
println(rewriter.apply(sampler, context));
println(rewriter.apply(sampler, context));
println(rewriter.apply(sampler, context));
println(rewriter.apply(sampler, context));
println(rewriter.apply(sampler, context));
println(rewriter.apply(sampler, context));
}
use of com.sri.ai.grinder.api.Context in project aic-expresso by aic-sri-international.
the class LambdaBetaReductionSimplifierTest method testSimpleReduction.
@Test
public void testSimpleReduction() {
Type peopleType = new Categorical("People", 4, arrayList(makeSymbol("ann"), makeSymbol("bob")));
Context context = new TrueContext();
context = context.makeNewContextWithAddedType(peopleType);
Assert.assertEquals(parse("if X = ann then 0 else if X = bob then 0 else 0"), simplifier.apply(parse("(lambda : if X = ann then 0 else if X = bob then 0 else 0)()"), context));
Assert.assertEquals(parse("if ann = ann then 0 else if ann = 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)(ann)"), context));
Assert.assertEquals(parse("if ann = ann then 0 else if bob = bob then 0 else 0"), 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)"), context));
}
use of com.sri.ai.grinder.api.Context 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));
}
use of com.sri.ai.grinder.api.Context 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);
}
use of com.sri.ai.grinder.api.Context in project aic-expresso by aic-sri-international.
the class ExhaustiveTest 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.makeCloneWithAdditionalRegisteredSymbolsAndTypes(symbolsAndTypes);
Rewriter exhaustive = new Exhaustive(rewriter);
Expression solution = exhaustive.apply(initial, context);
System.out.println("Solution: " + solution);
assertEquals(expected, solution);
}
Aggregations