use of com.sri.ai.grinder.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);
}
use of com.sri.ai.grinder.rewriter.api.Rewriter 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.rewriter.api.Rewriter in project aic-expresso by aic-sri-international.
the class ProceduralAttachmentsTest method runTest.
private void runTest(Expression input, Expression expected, Context context) {
TopRewriter topRewriter;
Rewriter evaluator;
Expression output;
topRewriter = new CombiningTopRewriter(new CommonSimplifier(), getProceduralAttachmentsTopRewriter(context));
evaluator = new Recursive(new Exhaustive(topRewriter));
output = evaluator.apply(input, context);
println(output);
assertEquals(expected, output);
}
use of com.sri.ai.grinder.rewriter.api.Rewriter 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);
}
use of com.sri.ai.grinder.rewriter.api.Rewriter 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.mergeSwitchesWithTheSameKeyMakerIntoASingleOne(list(switch1, switch2, switch3, switch4, switch5));
assertEquals(expected, merged);
}
Aggregations