5 ms·
The Prolog Story (2010)
- gumby 8y ago> I used Prolog in a production system a few years ago, Nice pun!
- okket 8y agoPrevious discussion from 2010: https://news.ycombinator.com/item?id=1363680 https://news.ycombinator.com/item?id=1363680 (60 comments)
- rurban 8y agoI recently used prolog for a complicated binary reverse-engineering task: bit packing. Likewise prolog is perfect for compilation. https://savannah.gnu.org/forum/forum.php?forum_id=9203 https://savannah.gnu.org/forum/forum.php?forum_id=9203 In fact it's a better prolog, picat, which also allows pretty straightforward statements, like loops, and has solver support. http://picat-lang.org/ http://picat-lang.org/
- progman 8y agoWow, thanks for sharing!
- mark_l_watson 8y agoI agree with the other commenter’s Wow! Picat also supports satisfiability apps like MiniZinc does. Thanks for posting that link!
- rurban 8y agoInitially I choose MiniZinc, but then was turned off by its baroque syntax. Straight prolog syntax and picat syntax was much easier in the end. writing prolog is mostly about writing in the most natural and readable syntax possible. using haskell-like types put me off.
- tannhaeuser 8y agoA big point of using Prolog for the commercial projects fitting its niche (1) is that it's based on an ISO standard, though, and implementations are (theoretically) interchangeable. To make Prolog programs actually portable across major Prolog implementations, there's been the Prolog Commons initiative for an extended standard predicate lib. 1) personally I think Prolog is much more broadly applicable in all kinds of apps rather than just type inference, policy languages, games; but with the recent rise of Datalog as actual query and inference language (and not just in academic database literature), it seems Prolog's time has finally come [2]: http://www.prolog-commons.org/ http://www.prolog-commons.org/
- 3rdAccount 8y agoWhat types of problems does one use constraint programming for? Large optimization problems require something like CPLEX usually.
- YeGoblynQueenne 8y agoConstraint logic programming is generally proposed as a more natural alternative for arithmetic, in Prolog, than Prolog's native arithmetic functions. It's a biig discussion and I'm not the one to make the argument for CLP, but, for example, in straight-up Prolog arithmetic is implemented using the is/2 predicate, which looks a bit like this: A is 1 + 2. Where A is the result of the addition of 1 and 2. In CLP on the other hand, particularly in the CLP library for reasoning over integers, CLP(FD), the addition above looks like this: X #= 1+2. Note that here, "#=/2" ("equals") is a constraint, so the statement above is true, iff the expression on the left-hand side of the #= is equal to the right-hand side of it. Which lets you do things like this: ?- 3 #= Y+2. Y = 1. Where trying to do the same thing with is/2 will give you an error (because Y is not sufficiently instantiated). And because of how constraint programming works, you can also do arithmetic with ranges, like so: ?- X #= A + B, A in 1..3, B in 4..6. X in 5..9, A+B#=X, A in 1..3, B in 4..6. In fact, what comes out the other end of the query above (the bit after the query prompt, "?") is a set of new constraints, where the result of adding A in [1,3] and B in [4,6] is a number, X, in [5,9]. You can find more information in the CLP(FD) library documentation, here: http://www.swi-prolog.org/man/clpfd.html http://www.swi-prolog.org/man/clpfd.html Or, if Markus Triska (the author of the library) is around, he can probably elucidate its use a bit better than I can :)
- deleted 8y ago[deleted]
- rurban 8y agoSources: https://github.com/LibreDWG/libredwg/blob/master/examples/ACAD_EVALUATION_GRAPH.pi https://github.com/LibreDWG/libredwg/blob/master/examples/AC... for some generated sample data and https://github.com/LibreDWG/libredwg/blob/master/examples/unknown.pi https://github.com/LibreDWG/libredwg/blob/master/examples/un... for the logic.
- mark_l_watson 8y agoI have used Lisp languages far more often than Prolog, but I do have my own Prolog success story: I had just used ExperLisp on the Macintosh to write a little app ExperOPS5 for the company who wrote and marketed ExperLisp and ExperProlog. After this I was given an internal research grant to write a complete simulation environment in ExperLisp as part of trying to win a large contract. Given familiarity with the tools I was using, a good prototype took about 100 hours to write. I had time left over and talked with my management about doing a parallel implementation in ExperProlog. Using a declarative approach, I had a parallel system, with interactive UI and graphics done in about 40 hours - and I had a learning curve with ExperProlog. I have also used SwiProlog and occasionally Amzi Prolog also since then. SwiProlog’s semantic Web library was the basis for all my early work and experience with semantic Web and linked data. I definitely suggest trying Prolog on a few small projects and add it to your tool set.
- Eli_P 8y agoHave you been feeling dire expressing your code while having only (Subject, Predicate, Object) first order logic? What kind of requests your app could manage and how large was DB (how many triplets)?
- hardwaresofton 8y agoProlog looks like the exact right language for at least some part of Netflix's OPA[0] -- I wonder why they didn't use it or why it wasn't a good fit (if someone considered it). I often want to reach for prolog when I face a problem like this, but I just don't know enough about how it degrades/breaks and of course don't want to use it to do any of the rest of the program stuff (web server, DB access), etc. [0]: http://www.openpolicyagent.org/ http://www.openpolicyagent.org/
- tsandall 8y ago(OPA co-founder here.) The semantics of OPA's policy language are based on Datalog, a non-Turing complete subset of Prolog. This means that all policy queries in OPA are guaranteed to terminate (which makes it a good fit for problems like authorization.) Beyond regular Datalog, OPA adds first-class support for querying complex/nested data structures like JSON. As a side note, OPA was not developed at Netflix, but they were one of the early adopters and continue to use it today.
- hardwaresofton 8y agoThanks so much for the answer -- I thoroughly enjoyed the OPA talks I've seen[0][1]. I apologize for mistaking OPA as a netflix product, I think one of the first times I saw it was as it was being used by Netflix so I assumed it was one of their F/OSS projects or built by someone there. Did you guys build your own engine? I took a quick look at the repo but don't see anything that looks like a datalog library in your glide package list. Last but not least, thanks for making and open sourcing such an awesome tool! Will definitely be passing the word on about Styra[2], I had no idea there was a whole company/more efforts behind OPA. I plan on using OPA in a bunch of upcoming projects -- it looks like a fantastic, stable addition to the toolbox of people looking to build robust programs/services. [0]: https://www.youtube.com/watch?v=XEHeexPpgrA https://www.youtube.com/watch?v=XEHeexPpgrA [1]: https://www.youtube.com/watch?v=4mBJSIhs2xQ https://www.youtube.com/watch?v=4mBJSIhs2xQ [2]: https://www.styra.com/ https://www.styra.com/
- tsandall 8y ago
- rntz 8y agoI would like to know what Prolog implementation the author used. In particular, the article claims: 1. > An initial analysis found that we would need to implement a complex depth/breadth search algorithm either in the client application or in SQL. 2. The Prolog runtime would efficiently solve this problem given rules that naively described it. I am skeptical, as this is emphatically not my experience with Prolog. In my experience, for any problem requiring a complex search strategy, Prolog is not your friend. Most Prologs do something approximating a naive depth-first search with unification, and on complex search problems this approach rapidly blows up. This can _sometimes_ be fixed by: 1. Making careful use of cut (`!`) or other non-declarative operators to change the search order. 2. Using tabling, essentially an advanced form of memoization. But only some Prologs support tabling, and it's useful only for some sorts of problem. However, the author mentions none of these. Are they glossing over something, or is my (probably more limited) Prolog experience uncharacteristic? Are there "smart" Prologs out there I'm unaware of?
- rntz 8y agoOn rereading, it seems like what may be happening is simply that the problem isn't very large (10-100,000 rows) and doesn't need to be solved very fast (a few minutes), and so the standard Prolog search strategy may have worked just fine. A good example of avoiding unnecessary over-engineering. Without knowing the details of the problem it's hard to be sure, of course. Combinatorial explosion can make even searches involving a rather small number of choices take impractically long to finish. But that depends on the structure of the search problem. Edit: The author says in the comments on the original post that he used SWI Prolog, which I believe doesn't do anything special in its search strategy, although it does have support for CLP.
- segmondy 8y agoPart of searching is knowing how to reduce your search space. This is not just a prolog problem but a CS problem. Knowing your data, using cut, swiprolog might not have tabling support but it's easy to memorize with assertz. I've used prolog on production systems, there's odbc drivers, he could have connected directly to the DB and ran his rules. Checkout the swiprolog libs, they are quite extensive
- kylecordes 8y agoHey, this is me! This is some serious latency between recording and writing a thing, and is appearing on hacker news. I will go through here and try to answer various questions etc.
- xvilka 8y agoThere is a modern book about Prolog - Power of Prolog [1]. [1] https://www.metalevel.at/prolog https://www.metalevel.at/prolog
- nickdrozd 8y agoSummary: They needed to do some complex queries on data in a SQL database, queries that were clearly better suited for Prolog. So they 1) queried for the relevant data from SQL, 2) formatted the data into the form of Prolog terms and dumped it into a file, 3) fired up the Prolog interpreter and loaded the data along with a small amount of Prolog query code, 4) ran the Prolog queries, 5) formatted the results into CSV and dumped it into a file, and finally 6) imported the results back into SQL. While it has some hacky elements, this approach took just one day to implement, as opposed to the projected months it would have taken to do it without Prolog. If I understand it right, Prolog is being used kind of like a more powerful version of Awk / Perl. The Power of Prolog [1] describes a somewhat similar use of Prolog: storing server logs as Prolog terms and then running complex queries directly on the log files. [1] https://www.metalevel.at/prolog/business https://www.metalevel.at/prolog/business
- deckar01 8y ago> Prolog is being used kind of like a more powerful version of Awk / Perl I have limited experience with Prolog, but it is not just a quick and dirty scripting language (how I view Perl). They were able to build the system so fast, because they only needed to translate the customer's requirements into Prolog declarations, and the Prolog engine is powerful enough to solve the constraints. In my experience, imperative code rarely has a 1-to-1 relationship with the requirements like this.
- nickdrozd 8y agoMaybe it would be clearer if I said Prolog was being used like a "much" more powerful version of Awk / Perl. Consider the server log case I mentioned. A question you might ask of a server log is: Are there any client requests that were not served? That query is an easy one-liner. You can go a little further and say: Give me the IPs of all the client requests that were not served. That query is also easy, maybe just another line or two. It would be a lot harder to get that information with Awk etc, but the spirit is the same: you have a bunch of data, and you want to extract some particular information, and you want to do so without a lot of pomp.
- Subi 8y agoLove seeing a good Prolog story surface. I was blown away by how productive it was to use back in university along with XPCE for UI. Became the first language I expertised in and it has paid off in terms of opening up a lot of other avenues like being able to easily learn Erlang and Elixir. There isn't always a good reason to use it for many situations nowadays but it the way you deal with graphs and trees and such is fantastic. Though fun fact Allegrograph has a Prolog rules interface
- carapace 8y agoI recently went through what I'm calling a "conversion experience" with Prolog. I was writing a compiler and a link to Warren's 1980 paper "Logic Programming and Compiler Writing" went by here on HN ( https://news.ycombinator.com/item?id=17674859 https://news.ycombinator.com/item?id=17674859 .) After a brief learning curve I now have a much more powerful compiler in about 1/5th of the code. There are a few problems that don't fit well with Prolog, but not many. For everything else, if you're not using Prolog you're probably working too hard. Consider that achieving feature parity with 1/5th the code means 1/5th the bugs, right off the top. But often Prolog code is more useful than some equivalent imperative code, for example, a Sudoku relation defined in Prolog serves to solve puzzles, but it can also generate new puzzles and verify partial puzzles (count the solutions and assert that there's only one.) https://swish.swi-prolog.org/p/Boring%20Sudoku.swinb https://swish.swi-prolog.org/p/Boring%20Sudoku.swinb Prolog is also old. I keep thinking, "What about FOO?", only to find that FOO has been explored years ago by a group of researchers, and often there is working code off-the-shelf and ready to go to solve whatever problem. Anyhow, TL;DR: For goodness' sake please check out Prolog. It's like time-traveling into the future.