Search in sources :

Example 1 with ProverCfg

use of suite.lp.Configuration.ProverCfg in project suite by stupidsing.

the class CompileProverImpl method prover.

@Override
public Prove_ prover(Node node) {
    var rt = f.input();
    Fun<FunExpr, ProveRt> cf = cps -> FunCreator.of(ProveRt.class, false).create(rt_ -> cps).apply(Map.ofEntries());
    var compiled = new Object() {

        private FunExpr compile_(Node node, FunExpr cps) {
            return new // 
            SwitchNode<FunExpr>(// 
            node).matchArray(".0, .1", m -> {
                return compile_(m[0], compile_(m[1], cps));
            }).matchArray(".0; .1", m -> {
                FunExpr cps1;
                if (Boolean.TRUE) {
                    var proveRt_ = cf.apply(cps);
                    cps1 = f.object(proveRt_).invoke("test", rt);
                } else
                    cps1 = cps;
                FunExpr f0 = compile_(m[0], cps1);
                FunExpr f1 = compile_(m[1], cps1);
                return f.seq(f0, f1);
            }).matchArray("fail", m -> {
                return f._void();
            }).matchArray("yes", m -> {
                return cps;
            }).nonNullResult();
        }
    }.compile_(node, rt.fieldSet("ok", ok));
    var proveRt = cf.apply(compiled);
    return proverCfg -> {
        var rt_ = new Runtime_();
        rt_.proverCfg = proverCfg;
        proveRt.test(rt_);
        return rt_.ok;
    };
}
Also used : Map(java.util.Map) Fun(primal.fp.Funs.Fun) FunCreator(suite.jdk.gen.FunCreator) ProverFactory(suite.lp.doer.ProverFactory) SwitchNode(suite.node.io.SwitchNode) FunExpr(suite.jdk.gen.FunExpression.FunExpr) ProverCfg(suite.lp.Configuration.ProverCfg) FunFactory(suite.jdk.gen.FunFactory) Node(suite.node.Node) SwitchNode(suite.node.io.SwitchNode) Node(suite.node.Node) SwitchNode(suite.node.io.SwitchNode) FunExpr(suite.jdk.gen.FunExpression.FunExpr)

Example 2 with ProverCfg

use of suite.lp.Configuration.ProverCfg in project suite by stupidsing.

the class ProverTest method test.

private boolean test(RuleSet rs, String lp) {
    var pc = new ProverCfg();
    var b0 = Suite.proveLogic(new InterpretedProverBuilder(pc), rs, lp);
    var b1 = Suite.proveLogic(new SewingProverBuilder2(pc), rs, lp);
    if (b0 == b1)
        return b0;
    else
        return fail("different prove result");
}
Also used : ProverCfg(suite.lp.Configuration.ProverCfg) InterpretedProverBuilder(suite.lp.search.InterpretedProverBuilder) SewingProverBuilder2(suite.lp.search.SewingProverBuilder2)

Example 3 with ProverCfg

use of suite.lp.Configuration.ProverCfg in project suite by stupidsing.

the class SldResolution method resolve.

public List<Node> resolve(Node node) {
    var ruleSet = Suite.newRuleSet(List.of("auto.sl", "pt.sl"));
    var builder = CompiledProverBuilder.level1(new ProverCfg());
    var 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"));
    var n0 = finder.collectSingle(node);
    var orsMap = new HashMap<Node, Source<List<Node>>>();
    for (var n1 : Tree.read(n0)) {
        var ors = Tree.read(n1).toList();
        for (var index = 0; index < ors.size(); index++) {
            var i = index;
            orsMap.put(ors.get(i), () -> Concat.lists(ors.subList(0, i), ors.subList(i + 1, ors.size())));
        }
    }
    var results = new ArrayList<Node>();
    for (var e : orsMap.entrySet()) {
        var value0 = e.getValue();
        var value1 = orsMap.get(negate(e.getKey()));
        if (value1 != null)
            results.add(TreeUtil.buildUp(BaseOp.AND___, Concat.lists(value0.g(), value1.g())));
    }
    return results;
}
Also used : ProverCfg(suite.lp.Configuration.ProverCfg) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with ProverCfg

use of suite.lp.Configuration.ProverCfg in project suite by stupidsing.

the class InterpretedProverBuilder method build.

@Override
public Fun<Node, Finder> build(RuleSet ruleSet) {
    return goal -> {
        var goal1 = SewingGeneralizerImpl.generalize(goal);
        return (source, sink) -> {
            var proverCfg1 = new ProverCfg(ruleSet, proverCfg);
            proverCfg1.setSource(source);
            proverCfg1.setSink(sink);
            new Prover(proverCfg1).elaborate(goal1);
        };
    };
}
Also used : Prover(suite.lp.doer.Prover) SewingGeneralizerImpl(suite.lp.sewing.impl.SewingGeneralizerImpl) Fun(primal.fp.Funs.Fun) Finder(suite.lp.search.ProverBuilder.Finder) ProverCfg(suite.lp.Configuration.ProverCfg) Builder(suite.lp.search.ProverBuilder.Builder) RuleSet(suite.lp.kb.RuleSet) Node(suite.node.Node) ProverCfg(suite.lp.Configuration.ProverCfg) Prover(suite.lp.doer.Prover)

Aggregations

ProverCfg (suite.lp.Configuration.ProverCfg)4 Fun (primal.fp.Funs.Fun)2 Node (suite.node.Node)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 FunCreator (suite.jdk.gen.FunCreator)1 FunExpr (suite.jdk.gen.FunExpression.FunExpr)1 FunFactory (suite.jdk.gen.FunFactory)1 Prover (suite.lp.doer.Prover)1 ProverFactory (suite.lp.doer.ProverFactory)1 RuleSet (suite.lp.kb.RuleSet)1 InterpretedProverBuilder (suite.lp.search.InterpretedProverBuilder)1 Builder (suite.lp.search.ProverBuilder.Builder)1 Finder (suite.lp.search.ProverBuilder.Finder)1 SewingProverBuilder2 (suite.lp.search.SewingProverBuilder2)1 SewingGeneralizerImpl (suite.lp.sewing.impl.SewingGeneralizerImpl)1 SwitchNode (suite.node.io.SwitchNode)1