17 ms·
The Power of Prolog
- triska 9y agoThank you very much for the publicity, I greatly appreciate it! This book has been discussed on HN about one year ago: https://news.ycombinator.com/item?id=14045987 https://news.ycombinator.com/item?id=14045987 Since then, I have added the following new chapters: Prolog Business Cases: https://www.metalevel.at/prolog/business https://www.metalevel.at/prolog/business Sorting and Searching: https://www.metalevel.at/prolog/sorting https://www.metalevel.at/prolog/sorting Cryptography with Prolog: https://www.metalevel.at/prolog/cryptography https://www.metalevel.at/prolog/cryptography Engineering Aspects: https://www.metalevel.at/prolog/engineering https://www.metalevel.at/prolog/engineering Artificial Intelligence with Prolog: https://www.metalevel.at/prolog/ai https://www.metalevel.at/prolog/ai I have also made many improvements and additions to the other chapters. Also, I have made almost everything available in a public git repository so that you can track the book's progress and view it offline: https://github.com/triska/the-power-of-prolog https://github.com/triska/the-power-of-prolog It is my sincere hope that you find this material useful, and I welcome all suggestions and comments. Also, thank you very much to all readers for the extremely constructive feedback that I have received in the past year. Your comments have made this work especially worthwhile. Enjoy!
- steve19 9y agoVery nice book. Do you know what companies are using prolog commercially?
- triska 9y agoThank 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-technology 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 https://dtai.cs.kuleuven.be/CHR/files/Elston_SecuritEase.pdf Oracle uses Prolog in the JVM specification: https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-0-preface7.html https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-0-pr... IBM has used Prolog for natural language processing in Watson: https://www.cs.nmsu.edu/ALP/2011/03/natural-language-processing-with-prolog-in-the-ibm-watson-system/ https://www.cs.nmsu.edu/ALP/2011/03/natural-language-process... RedPrairie uses SICStus Prolog for optimization tasks. Prolog is used for voice processing on the International Space Station.
- pjmlp 9y agoWindows NT used to have a Prolog based system for handling interrupts, not sure how much of it is still relevant on W10.
- sriram_malhar 9y agoThe Rust compiler's semantic rules are being recast internally in a prolog style. http://smallcultfollowing.com/babysteps/blog/2017/01/26/lowering-rust-traits-to-logic/ http://smallcultfollowing.com/babysteps/blog/2017/01/26/lowe...
- smitherfield 9y ago>A third of all airline traffic is handled by systems that run SICStus Prolog But are those systems responsible for all the I.T. problems that are plaguing the industry?[1] (I've been under the impression the issues were primarily with COBOL/mainframe systems, but wasn't aware Prolog was so widely used by airlines). [1] https://www.google.com/search?hl=en&q=airline%20computer%20flights%20grounded https://www.google.com/search?hl=en&q=airline%20computer%20f...
- jaytaylor 9y agoYes Markus does know, and has sprinkled examples throughout the book! One need look no further than the first chapter to find them. One that was new and interesting to me is that gerritcodereview (by Google) is written in Prolog. https://gerrit.googlesource.com/gerrit/+/master/prolog/ https://gerrit.googlesource.com/gerrit/+/master/prolog/
- js2 9y agoIt's written in Java but embeds prolog as a rules engine for deciding when a change may be submitted. https://gerrit-review.googlesource.com/Documentation/prolog-cookbook.html https://gerrit-review.googlesource.com/Documentation/prolog-...
- niklasd 9y agoI know that Negota Logic uses Prolog for the reasoning in their Legal Tech app (which is mainly written in Java). Since the app itself has a terrible user experience and looks like stuck in a ninties dystopia, there might be better examples.
- sorokod 9y agoGerrit (the code review tool) uses Prolog internally * https://gerrit.googlesource.com/prolog-cafe/ https://gerrit.googlesource.com/prolog-cafe/
- segmondy 9y agoI'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
- FractalLP 9y agoWhere do you work? Sounds neat!!
- triska 9y agoThank you for sharing this, I really appreciate you participating in this thread and this awesome anecdote! One related workplace anecdote that a former fellow student told me: He was working on a rule-based medical recommender system, and he recognized that Prolog was an excellent fit for this project. When he first suggested that the team switch to Prolog, they were very skeptical. But someone high up in the chain was a great fan of Prolog and approved this suggestion. A few weeks later, they had completed the implementation, and the Prolog-based solution was running. My colleague told me that, a few months after that, the whole team regarded Prolog as the only viable solution to all further projects from then on!
- jacquesm 9y ago> My colleague told me that, a few months after that, the whole team regarded Prolog as the only viable solution to all further projects from then on! Hm, there is such a thing as the right tool for the job. If all their jobs were very similar that makes sense, otherwise, not so much. Are you aware of the fact that inside every Windows NT installation there was a Prolog engine to help with network configuration? http://web.archive.org/web/20040603192757/research.microsoft.com/research/dtg/davidhov/pap.htm http://web.archive.org/web/20040603192757/research.microsoft...
- Immortalin 9y agoA section on dynamic programming w.r.t. to modern AI techniques would complement it nicely considering the resurgence of the field :D
- triska 9y agoThank you, this sounds like a wonderful addition! In general, the AI chapter is what I am currently working on most. I mean not "only" on the actual content, but on the applications I want to present in this chapter. Anton Kochkov has recently motivated this chapter via a dedicated issue for AI/ML applications of Prolog, and I invite you to track its progress at: https://github.com/triska/the-power-of-prolog/issues/5 https://github.com/triska/the-power-of-prolog/issues/5
- YeGoblynQueenne 9y agoHi 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 different approach to previous ILP systems but much simpler and easier to understand. It should be interesting to anyone who wants to do machine learning with Prolog. ____________ [1] https://github.com/metagol/metagol https://github.com/metagol/metagol
- triska 9y agoThank you very much Stassa! I have added Metagol to the AI chapter, please have a look.
- YeGoblynQueenne 9y agoThat looks great, cheers! :)
- sjg007 9y agoI think that reinforcement learning might be suitable in prolog. Do you have an opinion on that?
- triska 9y agoIn general, my opinion regarding machine learning and, in fact, also other tasks, is that Prolog is no less suitable to implement or teach these approaches than - for example - Python, which is currently often used in these areas. Dedicated libraries for machine learning are available and can be written for Prolog as well as for any other language, and Prolog of course also lets you easily interact with other programs via pipes and sockets. So, yes, I agree: Prolog may well be suitable for this! In practice, for statistics-based methods, the core logic will likely be carried out by dedicated hardware which you may have to program in its own language. Prolog may still play a part also with such approaches, for example to generate test cases and correctness certificates, and as a rule-based safety measure to prevent certain situations from happening.
- guuz 9y agoVery good material. Prolog (or the ideas behind it) really needs a resurgence.
- arca_vorago 9y agoIt's still going strong in the industrial side of things (like SCADA). You just don't hear much about it.
- FractalLP 9y agoI've never heard of Prolog alongside SCADA. Can you be more specific? Like in a plant or what?
- arca_vorago 9y agoYou know, I'm not sure where I got that from. Maybe I was confusing prolog with the ladder logic, or other languages from IEC 61131-3? I'm really not sure... but after some duckduckgoing I've come to the conclusion I was wrong in my previous statement... sorry.
- FractalLP 9y agoNo problem. Ladder logic and C I can definitely see, but SCADA would have blown my mind :)
- pjmlp 9y agoOne of my favorite languages, pity that is has had even harder time than Lisp getting mainstream acceptance.
- tabtab 9y agoLet's face it, procedural is just plain easier to debug because you can more easily split it into digestible and dissect-able chunks: divide-and-conquer. Perhaps functional and logical CAN readily have such features, but nobody either figured how, or have not figured out how to explain how to do dissection to normal people. (This is sometimes a criticism of SQL also, but the added WITH clause helps break up big queries into multiple smaller ones.) For example, with a procedural loop you can stick a debug statement in the middle to look at just about anything: while (x=foo(y,z)) { a = doStuff(x, z); console.write("x={?},y={?},z={?},a={?}", x, y, z, a); }
- tom_mellior 9y agoProlog has print statements you can stick anywhere. (It also has proper debuggers that allow you to go forward and backward and all that.) Also, Prolog code is often "split into digestible chunks". Even more than other languages, in fact, because it's rather hard to write nested loops or nested predicates or nested many other things. If you were ever taught Prolog, it seems that you weren't taught well. You might want to risk a second look.
- YeGoblynQueenne 9y ago>> Also, Prolog code is often "split into digestible chunks". Even more than other languages, in fact, because it's rather hard to write nested loops or nested predicates or nested many other things. I find it very easy to write nested loops in Prolog: findall(A ,findall(B ,findall(D ,findall(...) ,G) ,E) ,C) To paraphrase the old saying, a good Python programmer can write Python in any language.
- 9y ago
- simonraikallen 9y agoIts so nice to hear Prolog is alive and well. While at university I spent quite some time wrangling with it and grew to love it. So much problem solving smarts built into the runtime. Here is my crowning achievement from back then in 1993 - a genetic programming simulator that evolved ants to follow pheromone trails in pure prolog. http://www.cs.cmu.edu/Groups/AI/areas/genetic/gp/systems/gp_pl/gp.pl http://www.cs.cmu.edu/Groups/AI/areas/genetic/gp/systems/gp_... Enjoy.
- w0m 9y agoNerd. In 2005 I used Prolog to a solved pathfinding for competive maps in CS 1.6 based off weighted examples form interviewing a 'professionals' calls, even had a plugin architecture to extend each map, though it only worked well for Dust2 before I had to present. Way more practical. Cough. That was fun. Now I want to find the code...
- pdkl95 9y agoProlog is crazy-making and awesome in all the right ways. For some problems, it can be very concise. https://swish.swi-prolog.org/p/xkcd287.pl https://swish.swi-prolog.org/p/xkcd287.pl
- kccqzy 9y agoOne 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. ?- Vs = [A,B,C,D], Vs ins 1..711, A * B * C * D #= 711000000, A + B + C + D #= 711, A #>= B, B #>= C, C #>= D, labeling([ff, down], Vs). Vs = [316, 150, 125, 120], A = 316, B = 150, C = 125, D = 120 ; false. Another great thing Prolog is good at is type inference. After all, type inference, in its simplest form, is just syntax-directed constraint generation and then using unification to solve constraints—exactly what Prolog gives you by default. You can write a type inference engine for simply typed lambda calculus in Prolog in 10 minutes. Google used to have a project to do type inference for Python written in Prolog, although they've since [switched away](https://github.com/google/pytype https://github.com/google/pytype).
- triska 9y agoHah! I used exactly this example to motivate the arbitrary precision CLP(FD) implementation, published as The Finite Domain Constraint Solver of SWI-Prolog, FLOPS 2012, LNCS 7294: https://www.metalevel.at/swiclpfd.pdf https://www.metalevel.at/swiclpfd.pdf The observations on type inference are also spot on. The project you mentioned was previously discussed on HN, but the page is no longer available: https://news.ycombinator.com/item?id=12108041 https://news.ycombinator.com/item?id=12108041
- kccqzy 9y agoOh you implemented this CLP(FD) and wrote that paper! Thanks a lot! My 7-11 example is probably because I first saw it in your paper then.
- ysleepy 9y agoThis reminds me of a recent HN post about a simple datalog engine being used in the rust borrow checker. https://github.com/frankmcsherry/blog/blob/master/posts/2018-05-19.md https://github.com/frankmcsherry/blog/blob/master/posts/2018... via https://news.ycombinator.com/item?id=17107527 https://news.ycombinator.com/item?id=17107527
- jlarocco 9y agoThis is a nice coincidence. A few weeks back a guy at work gave away a box of old computer books, and I picked up several on Prolog and logic programming. I've been reading through an ancient edition of "Programming Prolog", which is good, but I've had a hard time finding modern code samples. The code in the book mostly works, but I've seen some weird behavior that I suspect is due to language changes. It'll be nice to have these up-to-date examples using modern idioms.
- westoncb 9y agoThe core ideas behind Prolog have the feel of something discovered rather than invented, and I bet we'll see significant new forms of it yet. My first encounter with it was while taking a Principles of Programming Languages course that I hadn't been attending regularly... We had a test on Prolog four days out and I hadn't learned a bit yet. I found a couple books in the library—one of which was excellent—and was soon so absorbed by it that I learned everything I needed out of sheer interest and got a perfect score on the test. Some six years later—the whole time not having touched Prolog or even thought about it that I can recall—I got an idea for a programming language. It would be an attempt to model 'schemas' in the human brain. Programs written in it were supposed to reflect human conceptual structure. Once you defined the concept for something, let's say a chair, you could ask it to generate instances. It was in part going to be a language designed from the ground up for procedural content generation. There were some promising things about it (like a very concise/natural way of defining 'analogy'[0] and other aspects of thought), but ultimately, a couple years after coming up with the idea, I picked up a copy of The Art of Prolog and read the first few chapters (for general edification, and so that I'd be more aware if it were applicable to something I was working on). By that point, I felt pretty convinced that my language idea would only be superficially different from Prolog, and that most of the really interesting ideas were already captured by that language. One up side to the project was that, after coming up with a pretty detailed plan for how the runtime would work, I decided to write this 'abstract visual debugger' to help me build it (the runtime would involve loads of complex data structure interactions that prior experience taught me were much easier to wrangle if visualized). It still seems like a promising project to me, and I work on it when I get free time. Video here: http://symbolflux.com/projects/avd http://symbolflux.com/projects/avd I also still have a bunch of random notes/ideas I took down about the language idea I had. Warning—I was pretty excited and they sound a bit like that ravings of a madman: http://symbolflux.com/IntellAgent-ideas.txt http://symbolflux.com/IntellAgent-ideas.txt I also wrote an ANTLR grammar for it, but that's probably not as entertaining. [0] Analogy: +{original: Type, analogy: Type} -{ Equivalence{Particularization{Generalization{original}}, analogy} } Equivalence etc. are all relation constraints; the run-time would discover a value for 'analogy'. The idea is to generalize whatever the thing is ('increases generality of the attribute Types' —from my notes), fill in values of some params to particularize, and have the constraint held that the discovered analogy is Equivalent to the original (sharing the same structure, which had a definite meaning in the context of the language).
- peter303 9y agoProlog was one of hot A.I. prospects of the 1980s. It could be a way to build an expert system. Japanese fifth generation computers were supposed to,run it fast. Then A.I. boom fizzled. Neither the first or last business cycle.
- enkiv2 9y agoThe fifth generation project didn't actually use prolog, but instead a custom prolog-like language. However, there's still work being done adjacent to 5G using real prolog, by people who thought it was an interesting idea: https://github.com/bitlaw-jp/the-constitution-of-japan https://github.com/bitlaw-jp/the-constitution-of-japan Prolog is still used in the development of expert systems, though when those systems are shipped, they have often been rewritten in an imperative language based on a Prolog prototype. The fifth generation project, from what I understand, died because of a dedication to custom hardware using already-obsolete fabrication tech -- mid-70s flipflops-on-IC tech over late-70s microprocessor-on-IC tech, wire wrap, etc. There was an inability or unwillingness to iterate on original committee designs. By the time it folded in 1998, everything involved looked like stone knives and bearskins. Those boxes wouldn't have been able to run it fast by 1980 standards.
- ausjke 9y agoused prolog many years ago, how is it now? is it evolving? it IS the language for expert systems, curious if it can be the best language for general AI developments. Just installed prolog under ubuntu and vscode has a plugin for it, all look good, will play with this more.
- xvilka 9y agoFrom my experience the hardest part is interaction with other programs and libraries. Still cannot make pipes work in https://github.com/XVilka/r2pipe.prolog/blob/master/r2pipe.pl https://github.com/XVilka/r2pipe.prolog/blob/master/r2pipe.p...
- doublec 9y agoWhat's the problem you're having with it? I think this was discussed on irc recently? This was the example I gave of using process_create which works: process_create('/bin/cat', [], [stdout(pipe(Out)),stdin(pipe(In))]), write(In, "hello"), nl(In), close(In), read_line_to_codes(Out, Codes).
- xvilka 9y agoWell, I need to keep both pipes open during the "session", since usual radare2 session involves hundreds of commands and their output. Opening a new pipe and process every time is a wrong way to go in my opinion.
- doublec 9y agoYou should be able to open the pipes at the beginning of the session, and close them after, passing the pipe variables around as needed. Prolog wouldn't be any different to other programming languages there. What errors are you getting? Maybe post to the swipl mailing list?
- xvilka 9y agoI will send a message to mailing list then, thanks for the suggestion.
- ghosthamlet 9y agoPractical logic programming in Clojure : https://github.com/clojure/core.logic https://github.com/clojure/core.logic A modern logic programming language: https://github.com/mcsoto/cosmos https://github.com/mcsoto/cosmos
- hellofunk 9y agoCore.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.
- andromeduck 9y agoProlog loses a lot of its magic when you realize it's just DFS the language.
- hellofunk 9y agoC loses a lot of its magic when you realize it's just memory but with syntactic sugar.
- triska 9y agoA fun fact that may appear surprising at first: In contrast to Prolog, C is actually not Turing-complete! Here is more information: https://cs.stackexchange.com/questions/60965/is-c-actually-turing-complete https://cs.stackexchange.com/questions/60965/is-c-actually-t... In C, you can only represent an unbounded tape if you assume the existence of an unbounded stream, i.e., in a so-called hosted implementation of C where unbounded streams are available. But unbounded streams cannot be implemented in freestanding C, even if unlimited memory were available!
- tom_mellior 9y ago... plus unification the magic.
- pwaivers 9y agoWhat is DFS?
- unoti 9y agoThey’re referring to Depth First Search
- orionblastar 9y agohttps://en.m.wikipedia.org/wiki/Visual_Prolog https://en.m.wikipedia.org/wiki/Visual_Prolog Turbo Prolog is now known as Visual Prolog. Just for those who wondered what happened to it and might want to ude it.
- restalis 9y agoI hated this language (and I'm saying it knowingly, despite the fact that this is most definitely a Prolog loving group). I found its working model difficult for me and the ROI quite low. I wanted to make my critique a bit constructive though and, before spitting out something of my own, I decided to look if there's already anything available in this regard. I think Andre Vellino puts it quite well (or at least better than I cold) in his "Prolog's Death" blogpost[1]. I invite you to have a look at it. Leaving aside Prolog's language design decisions, logical languages in general may be for now just a bit precocious, something not meant to flourish in our time. However, the computing hardware evolves and with it getting more complex and harder to predict the imperative paradigm being better fit for the underlying physical architecture becomes less and less true with every passing day. Although I can't say I'm thrilled about it, in time the logical languages may become the better offer for the average Joe looking for quick results, something closer to what for now Python is. [1] https://synthese.wordpress.com/2010/08/21/prologs-death/ https://synthese.wordpress.com/2010/08/21/prologs-death/
- lolc 9y agoQuote from the link: "The most confusing thing about Prolog is that, whatever algorithm you implement with it must be on top of the built-in ones, namely depth-first search, and unification (and only using recursion rather than iteration). " When I discovered that during my studies I decided that Prolog is not for me. First it looks neat for toy problems and then you're fighting the solver until you give up.
- pjc50 9y agoProlog: just say no. (To explain the joke, one of the main problems with Prolog is that solutions which cannot be unified just emit a "no" with no further explanation, making large Prolog setups hard to debug)
- tom_mellior 9y agoI think the usual (and funnier) version of that joke is: Q: How many Prolog programmers does it take to change a lightbulb? A: no
- Jedd 9y agoI recall at college in 1989 our lecturer had brought in a chap who'd done an entire airline baggage management suite written in prolog (turbo prolog, to be more accurate). The demo we saw was absolutely gorgeous -- real time updates on-screen to changes in baggage locations elsewhere (in the system). This was on i386-equivalent machines, before anyone gets overly nonchalant. He explained that he'd been up against two competing tenders - one in COBOL, the other in C - both higher priced and longer delivery times. Nonetheless, I still never really properly grokked prolog, as much as I tried. I feel my brain had already been wired away from declarative languages. Perhaps a poor cop-out.
- dontwantai 9y agoI imagine that there must be some system similar to prolog but with a probabilistic model of inference, for example ground rules could be sorted by statistical properties to accelerate inference. Just like machine learning trees select features for classification (perhaps using cross-entropy minimization). Edit: I found Journal of Machine Learning Research 7 (2006) 307–342, Kernels on Prolog Proof Trees: Statistical Learning in the ILP Setting
- enkiv2 9y agoI wrote something like this, based in part on ideas from PLN: https://hackernoon.com/mycroft-a-predicate-logic-language-overview-post-mortem-e357fe80d53 https://hackernoon.com/mycroft-a-predicate-logic-language-ov...