use of suite.lp.doer.ProverFactory 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.doer.ProverFactory 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);
}
use of suite.lp.doer.ProverFactory 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));
}
use of suite.lp.doer.ProverFactory in project suite by stupidsing.
the class SewingProverTest method testIf.
@Test
public void testIf() {
RuleSet rs = Suite.newRuleSet();
ProverFactory sp = new SewingProverImpl(rs);
ProverConfig pc = new ProverConfig(rs);
assertTrue(sp.prover(Suite.parse("if () () fail")).test(pc));
assertFalse(sp.prover(Suite.parse("if () fail ()")).test(pc));
assertTrue(sp.prover(Suite.parse("if fail fail ()")).test(pc));
assertFalse(sp.prover(Suite.parse("if fail () fail")).test(pc));
}
use of suite.lp.doer.ProverFactory in project suite by stupidsing.
the class SewingProverTest method test.
@Test
public void test() {
RuleSet rs = Suite.newRuleSet();
Suite.addRule(rs, "yes");
ProverFactory sp = new SewingProverImpl(rs);
ProverConfig pc = new ProverConfig(rs);
assertTrue(sp.prover(Suite.parse("yes")).test(pc));
assertTrue(sp.prover(Suite.parse("fail; yes")).test(pc));
assertTrue(sp.prover(Suite.parse("yes; yes")).test(pc));
assertFalse(sp.prover(Suite.parse("yes, fail")).test(pc));
assertFalse(sp.prover(Suite.parse("!, fail; yes")).test(pc));
assertTrue(sp.prover(new Generalizer().generalize(Suite.parse("(.v = 1; .v = 2), .v = 2"))).test(pc));
assertFalse(sp.prover(new Generalizer().generalize(Suite.parse("once (.v = 1; .v = 2), .v = 2"))).test(pc));
assertFalse(sp.prover(Suite.parse("not yes")).test(pc));
assertTrue(sp.prover(Suite.parse("not fail")).test(pc));
assertTrue(sp.prover(new Generalizer().generalize(Suite.parse(".p = yes, .p"))).test(pc));
}
Aggregations