Live data from Hacker News

The Power of Prolog

metalevel.at

91–100 of 164 posts

Re: The Power of Prolog

#92
post #2

Roughly half the 'power of prolog' comes from the 'power of logic programming' and prolog is by far not the only logic programming language, e.g., - You can do logic programming using minikanren in scheme. (you can also extend the minikanren system if you find a feature missing). - Minikanren was implemented in clojure and called core.logic. - It was also ported to python by Matthew Rocklin I think, called logpy. - T…

Minikanren is not a viable substitute for Prolog. But yes, there are other logic programming languages worth trying. I've never tried it myself but heard good things about Mercury.

Could you expand a little bit on why not? My limited experience with minikanren and core.logic is that non-relational goals from prolog (cuts etc) exist, but are discouraged, and several CLP flavours that provide relational goals with constraints are proposed as alternative (although they are not very exhaustive). You can also project and use normal clojure on grounded variables...

Honest question, I'm trying to learn new things, not trying to sound as an expert!! As I said, limited experience.

Re: The Power of Prolog

#93
post #8

Earlier quoted context omitted.

>Zebra puzzle Interesting puzzle. I copied the puzzle text to a separate text file so that one does not accidentally read anything else in the Wikipedia article. https://pastebin.com/0DWbSSx3

I've worked a bit on it. My solution is not incredible or anything, probably there are far more efficient and/or elegant solutions out there. Mine is not done yet but I'm going to continue with this one later and by then the activity in this thread will be over so I leave this link here now. https://github.com/eriknstr/puzzles/blob/master/zebra/soluti...

Fun problem. My solution doesn't do really any "logic programming", and it takes around 2 minutes to run on my laptop.

https://gist.github.com/philsnow/02e747241d46106b14b60146e58...

The middle huge nested thing (where `some_possible_worlds` is defined) is gross but I'm not great with ruby and I couldn't think of another way to not blow up memory enumerating all the worlds just to eliminate 99% of them.

Re: The Power of Prolog

#95

Something I would like to be able to understand/know/study is how logic programming languages are implemented and how their runtime looks like.

Section 4.4 in Structure and Implementation of Computer Programs [1] presents an implementation of a Prolog-like logic programming language in Scheme. It is very instructive to contrast it to the meta-circular evaluator of Scheme in that same book to see the similarities and differences.

Paradigms of Artificial Programming by Norvig also contains a chapter implementing Prolog in Common Lisp. The code can be found at [2].

[1] https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-29.htm...

[2] http://norvig.com/paip/prolog.lisp

Re: The Power of Prolog

#96
post #62

Earlier quoted context omitted.

It's pretty much Backtracking as a language. So stuff like N Queens, Einstein's Puzzle (the Englishman lives in the red house, the Swede in the blue house, etc.) and so on. Any time you want to write down the rules of a discrete system and ask questions about the properties of that system, Prolog is a great way to do it. One practical application: it's very easy to write the logic for a network firewall in Prolog.

Is it possible to do that kind of stuff (e.g. Einstein's Puzzle) in Haskell/OCaml/F# and how would one approach it?

Yes, it's possible. Most approaches use brute-force search, just like the simpler Prolog variants: http://rosettacode.org/wiki/Zebra_puzzle

Re: The Power of Prolog

#97

Something I would like to be able to understand/know/study is how logic programming languages are implemented and how their runtime looks like.

http://www.amzi.com/articles/prolog_under_the_hood.htm I find this article very helpful when it comes to understanding how Prolog actually works.

http://archive.is/RSzu

Re: The Power of Prolog

#98
post #79

Earlier quoted context omitted.

> Coq, Isabelle are interactive theorem provers or proof assistants, not automatic theorem provers which is a lot harder to do Automatic theorem provers for first-order logic (FOL) have existed for some time [0], but higher-order logic (HOL) is another matter. The difference is that in HOL, predicates can be variables; in FOL they are all constants. HOL allows you to write rules for mathematical induction; for exampl…

There are some automated theorem provers for higher-order logic [0][1], but they are not very good yet compared to their first-order counterpart. There are also some provers specialized in inductive proofs [2][3], although the frontier with proof assistants such as Coq or Isabelle starts getting blurry as you often need the user's intervention to explicitely provide lemmas. I have some hopes that this is going to cha…

Thanks for the info!

Re: The Power of Prolog

#99
post #2

Roughly half the 'power of prolog' comes from the 'power of logic programming' and prolog is by far not the only logic programming language, e.g., - You can do logic programming using minikanren in scheme. (you can also extend the minikanren system if you find a feature missing). - Minikanren was implemented in clojure and called core.logic. - It was also ported to python by Matthew Rocklin I think, called logpy. - T…

> - There is also datalog, with pydatalog it's python equivalent.

Datalog is a strict subset of Prolog that guarantees termination (over finite sets), i.e., it's not turing-complete. This makes it more suitable for knowledge representation tasks than general programming. pydatalog is a specific implementation of a datalog reasoner.

Re: The Power of Prolog

#100
I once wanted to solve a problem that is perfect for Prolog, but I wanted it in Clojure. Turns out there's a great library for that! I don't think it has the full power of Prolog (I only know of Prolog and what it does but I've never used it), but for integer constraint programming it was a joy to work with.

https://github.com/aengelberg/loco

Post reply on HN