10 ms·
The Power of Prolog
- dang 7y agoEarlier versions were discussed in 2018: https://news.ycombinator.com/item?id=17121028 https://news.ycombinator.com/item?id=17121028 and 2017: https://news.ycombinator.com/item?id=14045987 https://news.ycombinator.com/item?id=14045987 (Links are for the curious. Reposts are ok after a year: https://news.ycombinator.com/newsfaq.html https://news.ycombinator.com/newsfaq.html)
- triska 7y agoThank you very much for your interest, I greatly appreciate it! I hope you are all doing reasonably well. Please take care! This book was most recently discussed here in May 2018: https://news.ycombinator.com/item?id=17121028 https://news.ycombinator.com/item?id=17121028 Since then, I have added a new chapter, Logical Foundations of Prolog: https://www.metalevel.at/prolog/logic https://www.metalevel.at/prolog/logic Also, I have made several other additions and improvements. You can see most of the changes since the last discussion in a public git repository: https://github.com/triska/the-power-of-prolog/compare/8a94ed3d0ab73d31d6400ab18b9b341ed56fbad1...master https://github.com/triska/the-power-of-prolog/compare/8a94ed... Currently, I am working on several videos that will eventually form the core of the book. Here are a few previews: https://www.metalevel.at/prolog/videos/logic https://www.metalevel.at/prolog/videos/logic https://www.metalevel.at/prolog/videos/timetabling https://www.metalevel.at/prolog/videos/timetabling https://www.metalevel.at/prolog/videos/sparrows_on_eagles https://www.metalevel.at/prolog/videos/sparrows_on_eagles These videos are all work in progress, and they may be replaced by better versions at any time. Hence, if possible, please use the links above to refer to them: They will always point to the latest versions. Alternatively, please use the following overview page that shows all videos: https://www.metalevel.at/prolog/videos/ https://www.metalevel.at/prolog/videos/ Also, I have published a comprehensive journal paper about my CLP(B) system, i.e., a SAT solver with some nice algebraic properties, seamlessly integrated into Prolog as a specialized form of unification: https://www.metalevel.at/boolean.pdf https://www.metalevel.at/boolean.pdf For Prolog application programmers and system implementors, the paper's appendices may be especially interesting. They formalize a few important concepts that are also a major theme in the book. As of October 2019, the CLP(B) system is also available in Mark Thom's Scryer Prolog. Scryer is a Rust-based Prolog implementation that is freely available, conforms to the Prolog ISO standard, represents strings efficiently as lists of characters, and includes important features for implementing Prolog-based constraint solvers: https://github.com/mthom/scryer-prolog https://github.com/mthom/scryer-prolog As of a few days ago, Scryer Prolog also ships with my implementation of CLP(ℤ), Constraint Logic Programming over integers. This is a very useful declarative paradigm for solving combinatorial tasks, in some ways superior to SAT solving because it allows more convenient modeling, easier experimentation with different formulations, and reasoning at a higher conceptual level. The chapter on declarative integer arithmetic contains more information, and further pointers: https://www.metalevel.at/prolog/clpz https://www.metalevel.at/prolog/clpz For illustration, here is an example page where you can solve timetabling instances with this approach: https://www.metalevel.at/prolog/timetabling/ https://www.metalevel.at/prolog/timetabling/ I welcome all comments and suggestions about the book, these videos, and Prolog in general. Also, I would like to take this opportunity to thank all readers for your thoughtful comments and endorsements. Your feedback and encouragement are making this work especially worthwhile. Enjoy!
- carapace 7y agoI want to say thank you, for your book and for all the work you're doing promoting and improving Prolog.
- triska 7y agoYou are very welcome! I greatly enjoy all your postings about your Prolog-based interpreter for Joy: https://osdn.net/projects/joypy/scm/hg/Joypy/blobs/tip/thun/thun.pl https://osdn.net/projects/joypy/scm/hg/Joypy/blobs/tip/thun/... I impulsively upvote this every time I see it. Thank you for sharing such an interesting project!
- carapace 6y agoYou're very kind. It's unfinished, and I doubt whether it will ever be useful for anything (other than just being kinda neat in and of itself.) I need to deal with compiling loops/recursion/fixpoints. But thanks! I appreciate it. Your advice to use CLP(FD) for the semantics of integer math operations was fantastic!
- mthom 6y agoYou don't mind if I port Thun to Scryer Prolog, do you? With full credit to you, of course. I'd like to include it as an example.
- carapace 6y agoNot at all, that would be awesome. It's GPL'd, have at it. (^_^) I typically use SWI Prolog but I hope the code is mostly portable. The parser uses a couple of DCGs from the "basics" lib but I think those are also portable or at least simple to re-implement. The tricky bit might be the semantics of math (and comparison) ops. I've tried two other sets of semantics, one that attempts to perform math operations (and catch the errors if e.g. an arg is a logic var rather than an int) as you go, and another that just builds expression trees (evaluation is delayed) like so: func(+, [int(A), int(B)|S], [int(A + B)|S]). Just to point out, in SWI Prolog the ints are "BigNums" while in GNU Prolog they're machine words (so modular arithmetic, mod 2^32). You could use Rationals or make up some other semantics. This all gets into Categorical paradigm programming. http://conal.net/papers/compiling-to-categories/ http://conal.net/papers/compiling-to-categories/ The same (point-free) expression can be used to develop concrete programs over various categories: Hardware circuits, partial evaluation, differentiation, dataflow graphs, and so on.
- collyw 7y agoProlog look like it would be the correct tool for the job for a certain class of problems, I wish I had time to learn it. I always wonder why it doesn't get more attention.
- sacado2 7y agoNowadays, ontology-management systems like Protégé and SPARQL can more or less solve all problems prolog can solve, while providing higher-level formalisms and with the guarantee your query will terminate.
- baq 7y agoi've never used prolog seriously despite having a few problems very well suited for declarative solutions - variants of job shop scheduling, rule based workflows, etc. most reasons for why prolog didn't take off in my job are non-technical - it looks weird, it's hard to debug, integration with python isn't obvious and one worry i had (never tested) was that while the idea is to tell the computer about the problem, the real art was placing cuts.
- tejtm 6y agoHmm programs terminating because Protege is guaranteed to slag your machine is a feature had overlooked.
- mmarx 6y agoFor most queries, that might be true. However, the termination guarantees of Description Logic (OWL) reasoning and SPARQL (more precisely: the specific time complexity bounds) immediately imply that Prolog is more expressive. Even if we don't consider such ridiculously long-running queries, there's still limits to what can be expressed in DLs and SPARQL: since OWL doesn't have any variables, you're restricted to tree-shaped queries (indeed, this is a major part of why OWL reasoning is decidable), and SPARQL doesn't allow you to express any constraints on the intermediate nodes in a property path expression. Neither of these restrictions exist in Prolog.
- ben-schaaf 6y ago
- downerending 7y agoI absolutely loved Prolog and CLP(R) back in the day. The one thing I never got past was its difficulty in dealing with large, mutable sets of data. So, for example, given an array of a million or billion elements that are being rapidly modified, even the most trivial sorts of backtracking become infeasable. Maybe there's some elegant way to do it, but I never got it. (And difference lists need to die.)
- tabtab 6y agoI've always had difficulty debugging functional and formula based logic, and others have said similar. Imperative is just easier to "fractal-ly dissect" to me. Debugging seems to be a reoccurring theme of many "high abstraction" techniques that perhaps keep them out of the mainstream. I known many disagree, and this claim often triggers heated debates.
- haolez 6y agoI've found this channel a few months ago and my wife thinks I'm crazy when I'm watching it. "This looks like work, but harder!!". Awesome content! Thanks for posting it :)
- triska 6y agoThank you so much, and you are welcome! That's an awesome slogan! Some things are hard, yet have no pay-off or are even detrimental. On the other hand, things that pay off are often proportionally hard. It is not may goal to make it hard, in fact I am doing everything I can to make it as easy as possible. I am very interested in didactic approaches, and always welcome feedback! I would like to make it worth the effort for viewers, and — beyond that — exceed the required effort in value.
- haolez 6y agoYou do a very good job making it approachable. I'll make a PoC this year using Prolog in a specific application regarding contract generation (LawTech). It's surely thanks to your insights! Now that I know your handle, I'll ping you when I have some news :)
- triska 6y agoThank you a lot, I would greatly appreciate this! There is significant interest in applying logical reasoning and logic programming in the context of legislation and application of laws, in fact especially in Austria, for several reasons both historic and current, and also throughout Europe, for instance to implement cross-border use cases that are mandated by the Single Digital Gateway Regulation (SDG). As one contact point, see for example the Vienna Legal Hackers: http://vie-legalhackers.at/en/home-en/ http://vie-legalhackers.at/en/home-en/ A few weeks ago, I gave a presentation about Logic in the Public Sector in the form of a RuleML webinar, maybe these slides are interesting for your use case, or in future projects in LegalTech: http://ruleml.org/talks/MarkusTriska-LogicInThePublicSector-RuleMLWebinar-2020-03-25.pdf http://ruleml.org/talks/MarkusTriska-LogicInThePublicSector-... See also ruleml.org for more information about RuleML, and further potential opportunities for cooperation! One thing I can say for certain, after discussing this topic with lawyers who are interested in Prolog: In Vienna, opportunities for applying Prolog in concrete projects in LegalTech abound. If you want to use Prolog in a job in the legal sector and are reasonably skilled in the language, you can start working immediately, for instance in the context of EU projects.
- 29athrowaway 6y agoProlog reminds me of Cyc. "Cyc failed to understand a story about a person named Fred shaving in the morning... Its inference engine detected an inconsistency in the story: it knew people do not have electrical parts, but because Fred was holding an electric razor, it believed the entity 'FredWhileShaving' contained electrical parts. It therefore asked whether Fred was still a person while shaving." From "Deep Learning" by Ian Goodfellow, Yoshua Bengio, Aaron Courville.
- imglorp 6y agoI think that's a valid point. Cyc consisted of a set of frames/predicates with real world relations and concepts. And then the logic part on top would try to find inconsistencies, generate new predicates, and of course some kind of unification to answer questions over predicates. They worked on it in isolation for decades, building new frames laboriously by hand, and made a few corporate sales I guess, but withdrew OpenCyc and that's about the last we heard from them. Major bummer. I feel like an open source business model would have allowed the public to use and extend the frames, propelling Cyc to mainstream, while Cycorp would consult and advocate and curate.
- deleted 6y ago[deleted]
- vpribish 6y agohas anyone here ever used prolog in production - like real world, making money, production? How about in real world research where it produced no-kidding actual value? From what I can tell it is only useful these days as a academic example of an alternative type of language. Is there something else that has carried the torch forward?
- hyeomans 6y agoYarn https://yarnpkg.com/features/constraints https://yarnpkg.com/features/constraints
- ctdonath 6y agoI did write a library management program for a large insurance company in Prolog, around 1988.
- ggleason 6y agoTerminusDB is used commercially and most of it is written in prolog, although the underlying storage engine is written in Rust. Datalog is still a good idea imho!
- falsissime 6y agohttps://www.metalevel.at/prolog/business https://www.metalevel.at/prolog/business which is a chapter of the book
- jbrazile 6y agoMy dad wrote a multi-thousand line turbo-prolog expert system to do airline gate assignment at JFK in the 80s https://scholar.google.com/scholar?cluster=7420249792044565299&hl=en&as_sdt=0,5 https://scholar.google.com/scholar?cluster=74202497920445652...
- photon_lines 6y agoIf anyone loves both Prolog and Python, I wrote a mini-prolog interpreter in Python just over a year ago which you can check out here: https://github.com/photonlines/Python-Prolog-Interpreter https://github.com/photonlines/Python-Prolog-Interpreter
- mattsouth 6y agosnap, but mine is in javascript and references a couple of predecessor javascript mini-prolog interpreters: https://github.com/mattsouth/dprolog https://github.com/mattsouth/dprolog. I still need to read that WAM book. But I tell that to myself everytime it comes up here.
- smabie 6y agoIs there a reason why anyone would choose prolog today instead of a library? Like racklog [https://docs.racket-lang.org/racklog/ https://docs.racket-lang.org/racklog/]. All the benefits of prolog, with none of the cost of using a new language and integrating it into your project.
- jxy 6y agoThis is an interesting question, and I hope someone with experiences on both sides could chime in. I would expect an prolog-like implementation in any mature language a possibility and retain language native syntax while garnering all the advantages of prolog.
- triska 6y agoOne of the advantages of Prolog is that there is an ISO standard for it: The standard prescribes, in many ways, which syntax is acceptable, which errors must be generated in which cases, and which results must be produced. The standard ensures portability of Prolog programs between conforming systems, and significantly simplifies legal disputes in case a system does not conform. As I see it, this is one of the advantages one loses when using a Prolog-like implementation as opposed to an actual Prolog system, and especially in commercial settings, this may be a significant drawback of using libraries that lack the strong formal backing and guarantees that an ISO standard ensures. Other advantages of using an actual Prolog system are speed and reliabiliy, and dedicated features such as constraints and built-in grammar mechanisms (DCGs). The availability of expressive and efficient constraints is often an important reason for buying and using a commercial Prolog system. Another important reason is that Prolog syntax and semantics enable declarative debugging approaches such as failure slicing and selective reading. These approaches may not translate to libraries, and also not to other syntactic formalisms.
- PeCaN 6y agoProlog is fun. It's fantastically fun. It's maybe one of the most fun programming languages in existence. I suppose most people who, in production, have to solve the sort of problems that Prolog is really good at are using some sort of logic programming library (or, more realistically, are implementing their own ad hoc, informally-specified, bug-ridden, slow implementation of half of Prolog). I don't think Prolog is a great language for shipping an actual product. But for me the alternatives are just not as satisfying. Choosing Prolog for a random little personal project (that fits what Prolog wants to do) is a good time.
- kitd 6y agoOT, but I was entertained by the fact that, as soon as I went to the page, the "Recursion" link was purple.
- christmm 6y agoprolog should be used as a library DSL, embedded, within programs written in other languages
- jlos 6y agoJust a conjecture, but I think the main drawback of Prolog is its hard to see it having popular support. Recursion, logic programming, and constraint satisfaction are challenging paradigms which doesn't lend well to doing something useful quickly, as opposed to something like Rails. Im just finishing a class using Prolog and CLP(FD) and I've really enjoyed using the language. And while lots of things in programming aren't easy at first, I'm just saying its hard to see wide adoption of prolog for that reason.
- davidgl 6y agoSee also Mercury, FP logic programming like the love child of Prolog and Haskell https://en.wikipedia.org/wiki/Mercury_(programming_language) https://en.wikipedia.org/wiki/Mercury_(programming_language)
- jacobush 6y agoPicoLisp also has a prolog in it.