5 ms·
I agree with what Sylvain Soliman said about this on Reddit: It's a nice tutorial for the 80's parts of the language: https://www.reddit.com/r/programming/comm
by zmonx 9y ago
I agree with what Sylvain Soliman said about this on Reddit: It's a nice tutorial for the 80's parts of the language:
https://www.reddit.com/r/programming/comments/7hp2xw/introduction_to_logic_programming_with_prolog/dqspj4p/ https://www.reddit.com/r/programming/comments/7hp2xw/introdu...
In modern Prolog systems, you would use more declarative features such as constraints to model combinatorial tasks like map coloring.
Make sure to check out modern Prolog features if you are interested in learning the language seriously!
- kccqzy 9y agoAre there any good materials (articles, books) for this kind of modern Prolog? I’m afraid my only experience with Prolog is those 80s features of Prolog and I’m not sure what you mean by constraints.
- zmonx 9y agoPlease see my profile page: It contains links that I find relevant for learning modern Prolog features. Every predicate you impose on the set of solutions can be regarded as a constraint, because it can at most restrict the set of solutions, never increase it. So, in fact, every Prolog goal you invoke is a constraint. When reasoning over Herbrand terms, the only constraints are equality and disequality of terms, which are implemented by the predicates (=)/2 and dif/2, respectively. In addition to these basic constraints over terms, modern Prolog systems also provide constraints over more specialized domains, such as constraints on integers, rational numbers and Boolean values. For combinatorial tasks such as map coloring, constraints over integers are especially useful. For example, here is a constraint on integers, using GNU Prolog: | ?- 3 #= 1+Y. Y = 2 In this case, the system has correctly deduced that Y can only be 2 subject to the constraint that 3 is equal to the result of the arithmetic integer expression 1+Y, where Y is constrained to integral values. Constraints implement relations between their arguments and can be used in all directions. This is the reason why Prolog predicates are typically more general than functions in other languages. However, to truly benefit from this, you must consistently use these comparatively new language features instead of lower-level ones. I say comparatively because these language features have been available for several decades by now in professional Prolog systems such as SICStus.
- jononor 9y agoHow does using constraints in Prolog relate to using a (finite domain) constraint solver?
- zmonx 9y agoThe beauty of this is that a constraint solver (over finite domains, Boolean values, sets etc.) blends in completely seamlessly into the way Prolog works. From the perspective of Prolog and its users, a constraint solver is simply available just like any other predicate! All the internal reasoning a constraint solver performs is completely abstracted away. The only interface is typically a few Prolog predicates that let you access the features of the solver by stating what must hold about the involved variables. So, to use a constraint solver in Prolog, you simply use the predicates it provides, just as you would use any other Prolog predicate. In the example above, I am using the constraint (#=)/2, which is a predicate that is true iff its arguments evaluate to the same integer. From the perspective of implementors, Prolog is a great implementation language for constraint solvers due to its built-in search and backtracking mechanisms. It also allows you to use the standardized Prolog syntax that many users are already familiar with, instead of having to devise yet another modeling language on top of your solver. Thus, I would describe the relation as a natural symbiosis: It is natural to use constraint solvers in Prolog, and natural to implement them in Prolog.
- agumonkey 9y agoare modern prolog just a layer on top of the old semantics or somehow an incompatible paradigm ?
- fusiongyro 9y agoA modern Prolog like SWI with CLPFD allows you to apply Prolog's semantics to arithmetic expressions in a way that you never were able to in classic Prolog. Instead of using `is/2`, you use `#=` and some other operators, Prolog can find solutions for expressions that would be very difficult to do in either classic Prolog or any other system.
- giardini 9y agoThe OP is likely speaking of "Constraint Logic Programming(CLP)". The set of CLP languages is generally implemented as a superset or add-on package(s) to a Prolog implementation. For example, SICStus Prolog and SWI-Prolog have CLP modules, e.g.: https://sicstus.sics.se/sicstus/docs/3.7.1/html/sicstus_32.html https://sicstus.sics.se/sicstus/docs/3.7.1/html/sicstus_32.h... http://www.swi-prolog.org/pldoc/man?section=clp http://www.swi-prolog.org/pldoc/man?section=clp and "Constraint Handling Rules(CHR): http://www.swi-prolog.org/pldoc/man?section=chr http://www.swi-prolog.org/pldoc/man?section=chr To the best of my knowledge the modules are written in Prolog. A look at those links will give you an idea of how CLP is used. There are modules available for CLP(X) where X is one of: B = boolean, Z = integers, Q = rational numbers, R = real(floating point) numbers, FD = finite domains (see "CLP(FD) Constraint Logic Programming over Finite Domains" http://www.pathwayslms.com/swipltuts/clpfd/clpfd.html http://www.pathwayslms.com/swipltuts/clpfd/clpfd.html ) etc. One can understand how constraining the domain of interest (reducing the search space) to say, the integers, might make search more efficient.
- zmonx 9y agoIn a sense, yes, these modules are written in Prolog. However, that is not the full story: CLP requires special interface predicates that the underlying Prolog system must provide. You cannot implement CLP "on top" of just any Prolog system with reasonable performance and correctness. Devising and implementing such suitable interface predicates is quite hard, and only a very small number of Prolog systems have succeeded with this so far. For example, the SWI interface for CLP is too limited in practice, and its constraint solvers have elementary mistakes also because of the limitations of the interface predicates it provides. In contrast, SICStus Prolog provides a much more general interface to attributed variables that supports all widely used constraint solvers (finite domains, Boolean variables, rational numbers etc.) with good performance and no known mistakes. The tutorial you link to has several rather severe shortcomings, and I cannot recommend it for learning CLP(FD). Please see my profile page if you are interested in Prolog resources.