3 ms·
Yes, it is easy to express simple tasks like Sudoku in MiniZinc. However, in terms of sophistication and convenience, Prolog is hard to beat, since it is a full
by triska 5y ago
Yes, it is easy to express simple tasks like Sudoku in MiniZinc. However, in terms of sophistication and convenience, Prolog is hard to beat, since it is a full-fledged programming language that can also be used to fetch, process and transform any available input in any way necessary to make it amenable to all built-in constraint solvers.
Compared to a Prolog program, a MiniZinc model is quite hard to parse and reason about programmatically: Every Prolog program is also a valid Prolog term, and can be reasoned about logically as long as we keep to the pure monotonic core of Prolog, which also includes constraints. Pure Prolog programs can be debugged declaratively by generalizing away goals, whereas for example removing a line of a MiniZinc model may render the model invalid.
In addition, Prolog provides logic variables and therefore allows interesting questions to be asked about the model, such as queries about partially known data. This, in combination with Prolog being a programming language, allows its application in a way that is not readily available, or may not be possible at all, with more special-purpose tools and modeling languages. For instance, David C. Norris is using Scryer Prolog and its integer constraints to model and analyse dose escalation trials as they arise in clinical oncology, exceeding the expressiveness of other modeling languages:
https://github.com/dcnorris/precautionary https://github.com/dcnorris/precautionary
Regarding sophistication, a good example are dedicated placement constraints of SICStus Prolog such as the geost/N family of constraints:
https://sicstus.sics.se/sicstus/docs/latest4/html/sicstus.html/Placement-Constraints.html https://sicstus.sics.se/sicstus/docs/latest4/html/sicstus.ht...
The publication A Geometric Constraint over k-Dimensional Objects and Shapes Subject to Business Rules by Carlsson, Beldiceanu and Martin gives an overview of what is going on behind the scenes when these constraints are posted:
http://contraintes.inria.fr/~jmartin/CBM08cp.pdf http://contraintes.inria.fr/~jmartin/CBM08cp.pdf
Implementing these constraints with the efficiency, generality and correctness that SICStus provides is a huge project.
- jhgb 5y ago> However, in terms of sophistication and convenience, Prolog is hard to beat, since it is a full-fledged programming language that can also be used to fetch, process and transform any available input in any way necessary to make it amenable to all built-in constraint solvers. Surely the same thing could be accomplished in Lisp as well?
- dreamcompiler 5y agoYes but it would take more work. Prolog is tailor-made for solving logic and constraint problems like Sudoku out of the box; Lisp is not. That said, it's relatively easy to write a version of Prolog in Lisp and then just use that to solve the problem. Both pg and Peter Norvig show that in their Lisp books.
- simplify 5y agoIt can indeed! Both lisp and prolog are homoiconic :)
- Tomte 5y agoYes, and commercial Lisp implementations often include a reasonably performant Prolog. If you'd like to see how to do that yourself: https://github.com/norvig/paip-lisp https://github.com/norvig/paip-lisp