Live data from Hacker News

Introduction to logic programming with Prolog

matchilling.com

71–80 of 93 posts

Re: Introduction to logic programming with Prolog

#71

Earlier quoted context omitted.

are modern prolog just a layer on top of the old semantics or somehow an incompatible paradigm ?

The 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.h... http://www.swi-prolog.org/pldoc/man?section=clp and "Constraint Handling Rules(CHR): http://www.swi-prolog.org…

In 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.

Re: Introduction to logic programming with Prolog

#72
Aja Hammerly[0] have a talk[1] at RubyConf this year titled “4 Programming Paradigms in 45 Minutes”, and she used Prolog as her declarative language. She implements a simple cash register in OO (Ruby), Functional (Racket), Declarative (Prolog) and Procedural (Assembly). The Prolog one turned out to be the shortest. It was really interesting!

[0] https://github.com/thagomizer [1] https://confreaks.tv/videos/rubyconf2017-4-programming-parad...

Re: Introduction to logic programming with Prolog

#73
post #55

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/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!

are modern prolog just a layer on top of the old semantics or somehow an incompatible paradigm ?

In fact, the "old semantics" actually included language constructs that are only now becoming available (again) in Prolog systems.

An example of such a construct is dif/2, which is a constraint that was provided in even the very first Prolog system, sometimes called Prolog 0, several decades ago. However, it was not widely available in Prolog systems until much more recently, even though professional Prolog systems such as SICStus have provided it for longer. Also arithmetic constraints were available in early implementations such as Prolog IV. So, in a sense, we are now going "back to the roots" of Prolog by making very old features widely available.

In my personal view, calling modern Prolog an "incompatible paradigm" with the way that Prolog is still being taught is not completely fitting, yet still more right than wrong: The new features are not meant to be used "on top" of old features, but instead! When using modern Prolog features to their fullest extent, you can completely eschew those language constructs that traditionally cause the worst problems for beginners.

Moded arithmetic is a prime example for this, which can be replaced completely by arithmetic constraints in modern Prolog systems. dif/2 is also a good example, which lets you avoid (\+)/1 in many cases by using a more general predicate instead.

Due to their operational semantics that is very hard to explain and understand, rather limited constructs often take significant room in many Prolog courses, and replacing them by more modern alternatives will entail a paradigm shift towards better methods and also make room for even more new material that can be covered instead. This is because on top of being more general, the new language constructs are often also easier to understand for beginners.

Re: Introduction to logic programming with Prolog

#74

Earlier quoted context omitted.

The point of Prolog as a practical logic programming language really is that it is portable accross Prolog implementations based on ISO Prolog (and maybe prolog-commons API compatibility). If you're using a Prologish tool (a Java framework, say) that is not quite Prolog, then you're loosing the compatibility for very little gain IMHO. Applications domains I've used Prolog for: discrete planning, game logic, limited/r…

> The point of Prolog as a practical logic programming language really is that it is portable accross Prolog implementations based on ISO Prolog (and maybe prolog-commons API compatibility). If you're using a Prologish tool (a Java framework, say) that is not quite Prolog, then you're loosing the compatibility for very little gain IMHO. I feel like I might be missing something obvious, but I'm not getting what the "c…

If you replace Prolog with SQL - does it make more sense?

Re: Introduction to logic programming with Prolog

#75

When writing a Prolog program a while ago I stumbled across an old mailing list where someone posted the following joke. Q. "How many Prolog Programmers does it take to change a lightbulb?" A. No.

Can't resist, I will add https://en.wikipedia.org/wiki/Answer_set_programming programming on this. Q. How many Answerset programmers does it take to change a lightbulb? A. {1}, {1,2}, {1,2,3}, {2,1}, {2,1,3}, {2,3,1}

... {3,1}, {1,3}

Re: Introduction to logic programming with Prolog

#76
Back in 2006, I studied Prolong in my college as a pre-up course for A.I. From my experience then, Prolog was easy for programming small tasks. I ended up building a card game with some intelligence as a final project. Even then, I spent most of the time designing cards to show up in console than time on actual coding for game play/intelligence.

It could be fun to retry Prolog now.

Re: Introduction to logic programming with Prolog

#77
post #55

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/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!

Are 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.

Re: Introduction to logic programming with Prolog

#78
post #77
post #55

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/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!

Are 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 .

Please 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.

Re: Introduction to logic programming with Prolog

#79
post #24

For those looking to gentle introduction to logic programming, Tarski's World was a very good book. https://ggweb.gradegrinder.net/tarskisworld https://web.stanford.edu/group/cslipublications/cslipublicat... Might help, instead of jumping straight into Prolog.

oh you reminded me of a program we used in college named the same. It was about model theory and valid logic clauses (blurry memories)..

Yep, showed up in a First Order Logic course for me. IIRC, it was bundled with a book?

Edit - this one: https://web.stanford.edu/group/cslipublications/cslipublicat...

Re: Introduction to logic programming with Prolog

#80
post #68
post #66

How does Prolog relate to ML systems? It seems they work in a similar way. Input some learning data and then the system produces output based on these.

Eh, they are quite different under the hood. To put it real simple (and probably quite sloppy): Prolog determines the output by applying logic. ML uses mathematics to analyze the input and "guesses" the output, based on the training set. As a corollary: Prolog will negate anything that can't be proven true from the rules you give it. A ML algorithm will always give you some answer, though the quality depends on the l…

I think he meant ML as the family of meta programming languages?

He did say systems though so you are probably right

Post reply on HN