4 ms·
Prolog is deeply unsuited for work, use Clingo instead. Try this on https://swish.swi-prolog.org/ https://swish.swi-prolog.org/. on(a,b). on(b,c). above(X,Y)
by sgt101 4y ago
Prolog is deeply unsuited for work, use Clingo instead.
Try this on https://swish.swi-prolog.org/ https://swish.swi-prolog.org/.
on(a,b).
on(b,c).
above(X,Y) :- on(X,Y).
above(X,Y) :- on(X,Z), above(Z,Y).
Query above(a,c)
Ok, true - it works! no probs.
now try
on(a,b).
on(b,c).
above(X,Y) :- above(X,Z), on(Z,Y).
above(X,Y) :- on(X,Y).
and query... and it explodes.
So - this kind of bug is very hard to find and extremely easy to introduce.
The good news is that answer set programming is not prone to it. So instead of prolog use Clingo !
https://potassco.org/clingo/ https://potassco.org/clingo/
- triska 4y agoIn your second example, I get an exception (it does not "explode"), and this is also not a "bug". In your second example, the default search strategy is unable to derive whether above(a,c) is a logical consequence of the program. The existence of such cases is expected when using the default execution strategy (SLD resolution), which sacrifices completeness for efficiency. A key advantage of using a declarative programming language such as Prolog is that we can change the execution strategy. For example, I tried your code in Scryer Prolog and added 2 directives as the first two lines to enable an execution strategy called SLG resolution instead of the default strategy: :- use_module(library(tabling)). :- table above/2. on(a,b). on(b,c). above(X,Y) :- above(X,Z), on(Z,Y). above(X,Y) :- on(X,Y). Now I get: ?- above(a,c). true ; ... . So, with a different search strategy, the Prolog system is also able to derive that above(a,c) holds, like Clingo. Note that answer set programming cannot help in any way when I need a program to perform side effects such as initiating a network connection, hosting a web page, parsing a file etc., whereas Prolog is extremely useful and appropriate for such applications. So, the fact that the default execution strategy of Prolog is not adequate to solve this specific example is not a sensible argument for or against Prolog.
- rscho 4y agoProlog and ASP look similar, and have some amount of intersection in their use case. But their sets of use cases are certainly not identical.
- naasking 4y agoI am completely mystified by what the "ASP Language Standard" is. The clingo page references it and the link it cites provides literally no contextual information about it.
- Avshalom 4y agoYou can of course do answer set programming in prologs too. https://ciao-lang.org/playground/scasp.html https://ciao-lang.org/playground/scasp.html
- YeGoblynQueenne 4y agoAnd that is so much better because it's executed top-down, with unification like in Prolog, and so it doesn't have to ground the entire Herbrand base and make little kittens called Skolem cry.
- deleted 4y ago[deleted]
- YeGoblynQueenne 4y agoAs triska says, there are different execution strategies for Prolog and left-recursion is not a problem in practice. To plug my own work, the Inductive Logic Programming (ILP) system I developed during my PhD (https://github.com/stassa/louise https://github.com/stassa/louise) can learn left-recursive Prolog programs thanks to an inductive Prolog meta-interpreter executed with SLG-resolution (a.k.a. tabling). I mean to say that the inductive meta-interpreter itself is tabled, so it can prove left-recursive programs without entering an infinite recursion (it needs to do that because it learns a program by proving its generalisation). And so it can learn left-recursive programs without "going infinite". That used to be a big problem for ILP, but it's now well and truly solved, in theory as well as in practice. And I say "now" but SLG-resolution is old as a a very old thing; Tamaki and Sato described it in 1986, I believe: https://link.springer.com/chapter/10.1007/3-540-16492-8_66 https://link.springer.com/chapter/10.1007/3-540-16492-8_66 But then implementations took a bit to catch up. >> Prolog is deeply unsuited for work, use Clingo instead. Well, that doesn't make sense. ASP doesn't even allow lists, let alone side-effects (you know, like writing to a stream), so what "work" is it that it's better suited for, than Prolog? Also, if I remember correctly, Clingo is not a language but a grounder? It takes a first-order program and grounds the entire Herbrand base into a set of propositions so that a SAT solver can then derive the stable models of the program? Do I have that wrong? Let me say up front that I've never heard a worse idea in my life, and I've heard a few. First of all, that's why ASP can't use lists, or other functions, because then the Herbrand base goes infinite and good luck grounding it. Second, SAT-solving is NP-complete. As I realised recently (https://news.ycombinator.com/item?id=34072923 https://news.ycombinator.com/item?id=34072923) ASP is an elegant framework for dealing with uncertainty in a purely symbolic manner, with negation as failure and axiomatic, classical negation. But then, why go and mess this elegance up with a dumb propositionalisation approach that loses all the good stuff about first order logic, and that's terminally inefficient to boot? That, I still don't get.