Live data from Hacker News

The Power of Prolog

metalevel.at

91–100 of 162 posts

Re: The Power of Prolog

#91
post #47

One of the coolest things I've seen is to use Prolog with CLP(FD) to solve the 7-11 problem. The problem basically says the sum of the prices of four items is $7.11, and the product is $7.11 too (no rounding); find the prices of these four items. This can be solved in two lines of code that gives the (unique) solution in a second. Not even my expensive Mathematica can do this! ?- use_module(library(clpfd)). true. ?-…

Ooo! Lemme show off this CLP(FD) solution to the "Zebra Puzzle" https://en.wikipedia.org/wiki/Zebra_Puzzle that I made after reading the "Logic Puzzles with Prolog" chapter:

https://gist.github.com/calroc/603ed919bc814ccee10c1b3df6142...

Re: The Power of Prolog

#93
post #44

Earlier quoted context omitted.

> Debuggers could add conditional expressions, but then they'd be re-inventing WRITE statements anyhow. SWI-Prolog's debugger can be invoked conditionally whenever you want from inside your running application. I've used it many times, and the code is simply: (Condition -> gtrace ; true) It's true that you could stick a write there, but you would have to think about what pieces of data you will need. Your mileage may…

Regarding your last sentence: Yes, I can confirm that this has happened, to a reasonable extent of "learned" in the sense that people went on to write programs using this material. However, I do not know how common this is, since I almost exclusively get feedback from those who found the material suitable. There were definitely complete beginners among them. For instance, here is a discussion that happened a few mont…

Cool, good to see others are finding this useful.

> In my experience, learning Prolog properly requires dedicated guidance, and it would be highly unusual to achieve mastery without it.

There are two readings of this sentence. An unkind spirit might think you are saying that Prolog books cannot make you a master for some inherent reason related to Prolog, independent of any book. Whereas I would say that there is no inherent reason, it's just that currently existing Prolog books cannot make you a master because they are simply not very good. Or in other words, yes, guidance may be needed. But can it really not be guidance from a book?

Re: The Power of Prolog

#94

Earlier quoted context omitted.

> Debuggers could add conditional expressions, but then they'd be re-inventing WRITE statements anyhow. SWI-Prolog's debugger can be invoked conditionally whenever you want from inside your running application. I've used it many times, and the code is simply: (Condition -> gtrace ; true) It's true that you could stick a write there, but you would have to think about what pieces of data you will need. Your mileage may…

>> As I said, in Prolog you cannot nest loops. You cannot nest loops. What do you mean here? My earlier comment was jokular, but you can definitely nest loops in Prolog: ... deconstruct([L|Ls],Acc1,Bind):- deconstruct(L,Acc1,Acc2) ,deconstruct(LS,Acc2,Bind). ... etc. That's a nested loop, right there. Do you mean it in the sense that it's still the same predicate rather than a consecutive change of scopes?

Most concretely I mean it in the context of the common auxiliary-predicate-with-an-accumulator pattern:

    foo_bar(Foo, Bar) :-
        foo_bar_aux(Foo, Bar, 0).

    foo_bar_aux(Foo, Bar, N) :-
        ...
Which in a language like OCaml would be hiding the loop in a recursive function defined inside the main one:

    let foo_bar foo =
        let rec foo_bar_aux n =
            ...
        in
        foo_bar_aux 0
So yes, I think this is what you mean by being the same predicate rather than a "change of scopes".

Of course there are many loop-like things that you can nest. If the arguments align just right, you can also use `maplist(maplist(maplist(baz)), ...)` instead of three auxiliary predicates, but I don't encounter many cases where this is possible or desirable.

Re: The Power of Prolog

#95
post #4
post #3

Earlier quoted context omitted.

Very nice book. Do you know what companies are using prolog commercially?

Thank you for the kind words! Regarding companies that use Prolog, here are a few examples: A third of all airline traffic is handled by systems that run SICStus Prolog: https://www.sics.se/projects/sicstus-prolog-leading-prolog-t... A large portion of the New Zealand stock exchange is powered by Prolog: https://dtai.cs.kuleuven.be/CHR/files/Elston_SecuritEase.pdf Oracle uses Prolog in the JVM specification: https://…

The Rust compiler's semantic rules are being recast internally in a prolog style.

http://smallcultfollowing.com/babysteps/blog/2017/01/26/lowe...

Re: The Power of Prolog

#96
post #68

Earlier quoted context omitted.

Hi Markus, thanks for your hard work on this website (also on all the Swi constraint libraries). For your machine learning section, you might want to consider discussing Metagol [1], a modern ILP system that can learn recursive theories and perform predicate invention. The core Metagol implementation is tiny and relies on a meta-interpreter (the technique is called Meta-Interpretive Learning). It is a radically diffe…

Thank you very much Stassa! I have added Metagol to the AI chapter, please have a look.

That looks great, cheers! :)

Re: The Power of Prolog

#97

Earlier quoted context omitted.

>> As I said, in Prolog you cannot nest loops. You cannot nest loops. What do you mean here? My earlier comment was jokular, but you can definitely nest loops in Prolog: ... deconstruct([L|Ls],Acc1,Bind):- deconstruct(L,Acc1,Acc2) ,deconstruct(LS,Acc2,Bind). ... etc. That's a nested loop, right there. Do you mean it in the sense that it's still the same predicate rather than a consecutive change of scopes?

Most concretely I mean it in the context of the common auxiliary-predicate-with-an-accumulator pattern: foo_bar(Foo, Bar) :- foo_bar_aux(Foo, Bar, 0). foo_bar_aux(Foo, Bar, N) :- ... Which in a language like OCaml would be hiding the loop in a recursive function defined inside the main one: let foo_bar foo = let rec foo_bar_aux n = ... in foo_bar_aux 0 So yes, I think this is what you mean by being the same predicate…

I see what you mean, thanks. I think we're talking about the same thing then.

Re: The Power of Prolog

#98
post #23

Earlier quoted context omitted.

I've shared this with anyone who will let me divert the conversation to Prolog. At work we have the Haskell folks, the Lispers who move everything towards Lisp, and I'm the one who moves every conversion towards Prolog, then I send the link to this. :-D

The older Lisp folks often have a Prolog integrated in their system...

PicoLisp has one.

Re: The Power of Prolog

#99
post #47

One of the coolest things I've seen is to use Prolog with CLP(FD) to solve the 7-11 problem. The problem basically says the sum of the prices of four items is $7.11, and the product is $7.11 too (no rounding); find the prices of these four items. This can be solved in two lines of code that gives the (unique) solution in a second. Not even my expensive Mathematica can do this! ?- use_module(library(clpfd)). true. ?-…

Ooo! Lemme show off this CLP(FD) solution to the "Zebra Puzzle" https://en.wikipedia.org/wiki/Zebra_Puzzle that I made after reading the "Logic Puzzles with Prolog" chapter: https://gist.github.com/calroc/603ed919bc814ccee10c1b3df6142...

That makes Prolog look downright useful! I heard from lots of people that it's fun as an esoteric language and some had a homework assignment or two in it, but nobody really uses it in practice. Do you think this might be more useful as a module to solve logic puzzles, rather than as a complete language by itself? I learned the very basics, but not worked with it enough myself to say whether that would be better than keeping it as a stand-alone language.

Re: The Power of Prolog

#100

Practical logic programming in Clojure : https://github.com/clojure/core.logic A modern logic programming language: https://github.com/mcsoto/cosmos

Core.Logic is a miniKanren implementation which is quite different from Prolog (smaller and ultimately less powerful, but cool nonetheless). Many/all miniKanren solutions also work in Prolog, but the vice-versa is not true.
Post reply on HN