Prolog is deeply unsuited for work, use Clingo instead.
Try this on 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://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) 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.