Search in sources :

Example 6 with ProverConfig

use of suite.lp.Configuration.ProverConfig 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);
        };
    };
}
Also used : SewingGeneralizerImpl(suite.lp.sewing.impl.SewingGeneralizerImpl) SewingProverImpl(suite.lp.sewing.impl.SewingProverImpl) Finder(suite.lp.search.ProverBuilder.Finder) ProverFactory(suite.lp.doer.ProverFactory) Builder(suite.lp.search.ProverBuilder.Builder) Prove_(suite.lp.doer.ProverFactory.Prove_) RuleSet(suite.lp.kb.RuleSet) Fun(suite.util.FunUtil.Fun) ProverConfig(suite.lp.Configuration.ProverConfig) Node(suite.node.Node) Node(suite.node.Node) ProverConfig(suite.lp.Configuration.ProverConfig) Prove_(suite.lp.doer.ProverFactory.Prove_) ProverFactory(suite.lp.doer.ProverFactory) SewingProverImpl(suite.lp.sewing.impl.SewingProverImpl)

Example 7 with ProverConfig

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

the class LogicCompilerLevel2Test method test0.

// require tail recursion to work
@Test
public void test0() {
    RuleSet rs = Suite.getRuleSet(Suite.parse(// 
    "" + // 
    "member (.e, _) .e #" + // 
    "member (_, .tail) .e :- member .tail .e #" + // 
    "sum .a .b .c :- bound .a, bound .b, let .c (.a - .b) #" + // 
    "sum .a .b .c :- bound .a, bound .c, let .b (.a - .c) #" + // 
    "sum .a .b .c :- bound .b, bound .c, let .a (.b + .c) #"));
    Builder builder = CompiledProverBuilder.level2(new ProverConfig());
    Suite.evaluateLogic(builder, rs, "(), sink ()");
}
Also used : RuleSet(suite.lp.kb.RuleSet) Builder(suite.lp.search.ProverBuilder.Builder) CompiledProverBuilder(suite.lp.search.CompiledProverBuilder) ProverConfig(suite.lp.Configuration.ProverConfig) Test(org.junit.Test)

Example 8 with ProverConfig

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

the class ProverTest method test.

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

Example 9 with ProverConfig

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

the class SewingProverTest method testPerformance.

@Test
public void testPerformance() {
    RuleSet rs = Suite.newRuleSet();
    Atom pred = Atom.of("q");
    Atom tail = Atom.NIL;
    for (int i = 0; i < 65536; i++) rs.addRule(Rule.of(Tree.of(TermOp.IS____, Tree.of(TermOp.TUPLE_, pred, Int.of(i)), tail)));
    ProverFactory sp = new SewingProverImpl(rs);
    ProverConfig pc = new ProverConfig(rs);
    Prove_ test = sp.prover(Suite.parse("q 32768"));
    Source<Stopwatch<Boolean>> trial = () -> Stopwatch.of(() -> {
        boolean isOk = true;
        for (int i = 0; i < 65536; i++) isOk &= test.test(pc);
        assertTrue(isOk);
        return isOk;
    });
    for (int i = 0; i < 8; i++) trial.source();
    Stopwatch<Boolean> sw = trial.source();
    System.out.println(sw.duration);
    assertTrue(sw.duration < 300);
}
Also used : RuleSet(suite.lp.kb.RuleSet) ProverConfig(suite.lp.Configuration.ProverConfig) Stopwatch(suite.os.Stopwatch) Prove_(suite.lp.doer.ProverFactory.Prove_) Atom(suite.node.Atom) ProverFactory(suite.lp.doer.ProverFactory) SewingProverImpl(suite.lp.sewing.impl.SewingProverImpl) Test(org.junit.Test)

Example 10 with ProverConfig

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

the class SewingProverTest method testBacktrack.

@Test
public void testBacktrack() {
    RuleSet rs = Suite.newRuleSet();
    Suite.addRule(rs, "mem (.e, _) .e");
    Suite.addRule(rs, "mem (_, .tail) .e :- mem .tail .e");
    Suite.addRule(rs, "q .c .v :- once (mem (0,) .v), .a/.b/.c = 0/0/0; mem (1,) .v, .a/.b/.c = 1/1/1");
    Suite.addRule(rs, "r .c :- q .c .v, .v = 1");
    ProverFactory sp = new SewingProverImpl(rs);
    ProverConfig pc = new ProverConfig(rs);
    assertTrue(sp.prover(new Generalizer().generalize(Suite.parse("r .c"))).test(pc));
}
Also used : RuleSet(suite.lp.kb.RuleSet) Generalizer(suite.lp.doer.Generalizer) ProverConfig(suite.lp.Configuration.ProverConfig) ProverFactory(suite.lp.doer.ProverFactory) SewingProverImpl(suite.lp.sewing.impl.SewingProverImpl) Test(org.junit.Test)

Aggregations

ProverConfig (suite.lp.Configuration.ProverConfig)21 RuleSet (suite.lp.kb.RuleSet)12 Test (org.junit.Test)10 SewingProverImpl (suite.lp.sewing.impl.SewingProverImpl)9 ProverFactory (suite.lp.doer.ProverFactory)8 Node (suite.node.Node)7 Builder (suite.lp.search.ProverBuilder.Builder)5 Finder (suite.lp.search.ProverBuilder.Finder)5 Fun (suite.util.FunUtil.Fun)4 Prove_ (suite.lp.doer.ProverFactory.Prove_)3 CompiledProverBuilder (suite.lp.search.CompiledProverBuilder)3 Generalizer (suite.lp.doer.Generalizer)2 Prover (suite.lp.doer.Prover)2 InterpretedProverBuilder (suite.lp.search.InterpretedProverBuilder)2 SewingGeneralizerImpl (suite.lp.sewing.impl.SewingGeneralizerImpl)2 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1