use of suite.lp.search.ProverBuilder.Finder in project suite by stupidsing.
the class EvaluateUtil method doFcc.
private Node doFcc(Node compileNode, FunCompilerConfig fcc) {
return LogUtil.duration("Code compiled", () -> {
ProverConfig pc = fcc.getProverConfig();
Finder finder = fccFinderFun.apply(Pair.of(pc, compileNode));
return FindUtil.collectSingle(finder, appendLibraries(fcc));
});
}
use of suite.lp.search.ProverBuilder.Finder in project suite by stupidsing.
the class SewingProverBuilder method build.
@Override
public Fun<Node, Finder> build(RuleSet ruleSet) {
ProverFactory sewingProver = new SewingProverImpl(ruleSet);
return goal -> {
Node goal1 = SewingGeneralizerImpl.generalize(goal);
Prove_ pred = sewingProver.prover(goal1);
return (source, sink) -> {
ProverConfig proverConfig1 = new ProverConfig(ruleSet, proverConfig);
proverConfig1.setSource(source);
proverConfig1.setSink(sink);
pred.test(proverConfig1);
};
};
}
use of suite.lp.search.ProverBuilder.Finder in project suite by stupidsing.
the class SewingProverBuilder2 method build.
@Override
public Fun<Node, Finder> build(RuleSet ruleSet) {
boolean isRewrite = !proverConfig.isTrace();
QueryRewriter qr = isRewrite ? new QueryRewriter(Prototype.multimap(ruleSet)) : null;
RuleSet ruleSet1;
if (qr != null) {
ruleSet1 = Suite.newRuleSet();
qr.rules().entries().forEach(p -> ruleSet1.addRule(p.t1));
} else
ruleSet1 = ruleSet;
Fun<Node, Finder> fun = new SewingProverBuilder(proverConfig).build(ruleSet1);
if (qr != null)
return goal -> fun.apply(qr.rewriteClause(goal));
else
return fun;
}
use of suite.lp.search.ProverBuilder.Finder in project suite by stupidsing.
the class SldResolution method resolve.
public List<Node> resolve(Node node) {
RuleSet ruleSet = Suite.newRuleSet(List.of("auto.sl", "pt.sl"));
CompiledProverBuilder builder = CompiledProverBuilder.level1(new ProverConfig());
Finder finder = builder.build(ruleSet).apply(Suite.parse(//
"" + //
"source .n0" + //
", pt-prove0 .n0 .n1" + //
", pt-prove1 .n1 .n2" + //
", pt-prove2 .n2 .n3" + //
", pt-prove3 .n3 .n4" + //
", pt-prove4 .n4 .n5" + //
", pt-prove5 .n5 ()/.n6" + ", sink .n6"));
Node n0 = FindUtil.collectSingle(finder, node);
Map<Node, Source<List<Node>>> orsMap = new HashMap<>();
for (Node n1 : Tree.iter(n0, TermOp.AND___)) {
List<Node> ors = To.list(Tree.iter(n1, TermOp.AND___));
for (int i = 0; i < ors.size(); i++) {
int index = i;
orsMap.put(ors.get(index), () -> List_.concat(ors.subList(0, index), ors.subList(index + 1, ors.size())));
}
}
List<Node> results = new ArrayList<>();
for (Entry<Node, Source<List<Node>>> e : orsMap.entrySet()) {
Source<List<Node>> value0 = e.getValue();
Source<List<Node>> value1 = orsMap.get(negate(e.getKey()));
if (value1 != null)
results.add(Tree.of(TermOp.AND___, List_.concat(value0.source(), value1.source())));
}
return results;
}
use of suite.lp.search.ProverBuilder.Finder in project suite by stupidsing.
the class InterpretFunEager method eager.
public Node eager(Node node) {
Node mode = isLazyify ? Atom.of("LAZY") : Atom.of("EAGER");
Node query = Suite.substitute("source .in, fc-process-function .0 .in .out, sink .out", mode);
RuleSet rs = Suite.newRuleSet(List.of("auto.sl", "fc/fc.sl"));
Finder finder = new SewingProverBuilder2().build(rs).apply(query);
Node parsed = FindUtil.collectSingle(finder, node);
IntrinsicCallback ic = isLazyify ? lazyIntrinsicCallback() : Intrinsics.eagerIntrinsicCallback;
Map<String, Node> df = new HashMap<>();
df.put(TermOp.AND___.name, f2((a, b) -> Tree.of(TermOp.AND___, a, b)));
df.put("+call%i-t1", f1(i -> fn(1, l -> Data.<Intrinsic>get(i).invoke(ic, l))));
df.put("+call%i-t2", f1(i -> fn(2, l -> Data.<Intrinsic>get(i).invoke(ic, l))));
df.put("+call%i-t3", f1(i -> fn(3, l -> Data.<Intrinsic>get(i).invoke(ic, l))));
df.put("+call%i-v1", f1(i -> fn(1, l -> Data.<Intrinsic>get(i).invoke(ic, l))));
df.put("+call%i-v2", f1(i -> fn(2, l -> Data.<Intrinsic>get(i).invoke(ic, l))));
df.put("+call%i-v3", f1(i -> fn(3, l -> Data.<Intrinsic>get(i).invoke(ic, l))));
df.put("+compare", f2((a, b) -> Int.of(Comparer.comparer.compare(a, b))));
df.put("+get%i", f1(a -> new Data<>(Intrinsics.intrinsics.get(((Atom) a).name.split("!")[1]))));
df.put("+is-list", f1(a -> b(Tree.decompose(a) != null)));
df.put("+is-pair", f1(a -> b(Tree.decompose(a) != null)));
df.put("+lcons", f2((a, b) -> Tree.of(TermOp.OR____, a, b)));
df.put("+lhead", f1(a -> Tree.decompose(a).getLeft()));
df.put("+ltail", f1(a -> Tree.decompose(a).getRight()));
df.put("+pcons", f2((a, b) -> Tree.of(TermOp.AND___, a, b)));
df.put("+pleft", f1(a -> Tree.decompose(a).getLeft()));
df.put("+pright", f1(a -> Tree.decompose(a).getRight()));
for (Entry<Operator, IntInt_Bool> e : TreeUtil.boolOperations.entrySet()) {
IntInt_Bool fun = e.getValue();
df.put(e.getKey().getName(), f2((a, b) -> b(fun.apply(compare(a, b), 0))));
}
for (Entry<Operator, IntInt_Int> e : TreeUtil.intOperations.entrySet()) {
IntInt_Int fun = e.getValue();
df.put(e.getKey().getName(), f2((a, b) -> Int.of(fun.apply(i(a), i(b)))));
}
List<String> keys = df.keySet().stream().sorted().collect(Collectors.toList());
Eager_ eager0 = new Eager_(0, IMap.empty());
Frame frame = new Frame(null);
for (String key : keys) {
eager0 = eager0.put(Atom.of(key));
frame.add(df.get(key));
}
return eager0.eager_(parsed).apply(frame);
}
Aggregations