Live data from Hacker News

Logic Programming is Underrated

swannodette.github.io

1–10 of 28 posts

Re: Logic Programming is Underrated

#2
If we are discussing the benefits of logic programming, I think it's important to include other declarative languages like SQL.

The idea of specifying directly what is computed, and not how it is computed, is very useful, and not limited to abuse mathematical problems.

Re: Logic Programming is Underrated

#4
post #3

I can't understand how you can be happy using ~84,000,000 clock cycles to solve that. Logic programming is a wonderful tool to know about, and armed with that knowledge you can adapt your programming style to the problem in question. http://norvig.com/sudoku.html

I love that Norvig post and it's what inspired me to get the finite domain functionality into core.logic. I don't really understand your point though. Why solve finite domain problems by hand if a library does it for you? The sudoku problem can be solved in many fewer lines of code than Norvig's http://norvig.com/sudopy.shtml with a library and it's just as efficient if not more so, http://gist.github.com/swannodette/5736688

Re: Logic Programming is Underrated

#5
The beauty of logic programming is that you can basically apply your problem solving skills very directly.

However some parts of say Prolog are a little unusual. The typical way of writing OR as multiple clauses directly violates DRY and I usually use the alternative IF-THEN-ELSE notation (->). I also use logical loops (basically foreach)...at the end of the day it's kind of a paradigm mix (arithmetic and write sideffects, too).

Grammars and constraints are pretty fun though. It's a very good tool to have in your toolbox. Prolog is certainly the language that expanded my mind the most after having worked with JAVA/Python before.

Re: Logic Programming is Underrated

#6
"The attractiveness of logic programming, when it was first launched, was that it had a ready-made declarative reading, which was expected to make a big difference for programming. Unfortunately, Prolog also had a bad procedural reading that people struggled with. So, in practice, Prolog programmers spent almost all of their effort on the procedural meaning, and the declarative meaning went out of the window. In the end, Prolog was a good dream, but a bad reality. Coming to classical logic per se, I believe it is ill-fit for describing computer programs or "processes" as you call them. First of all, classical logic doesn't have any well- developed notion of time or dynamics, and it has a nasty existential quantifier which assumes that all things exist once and for all. In computer systems, new things come into being all the time, well beyond the time of the original development or deployment. We know how to write computer programs that deal with that. Classical logic doesn't. (LEJ Brouwer made this criticism a long time ago in the context of mathematics. There it might have been just a philosophical problem. But in Computer Science, it is a practical problem.)

I believe logicians of philosophical inclination are prone to be enamored with what they have and lose sight of what they don't have. For a good part of two millennia, they kept debating Aristotilean syllogisms, without realizing that classical logic was yet to be discovered. Finally, it was left to the mathematicians to formulate classical logic. The logicians of today are similarly enamored with classical logic without much of an understanding of what it lacks. We would be ill-advised to listen to them. Or, we would be stuck for another two millennia, God forbid. [By the way, the Wikipedia page on Classical Logic is in a pitiful state. I hope somebody will pay attention to it.]

Brilliant new things are happening in Logic. - Mathematicians have formulated Toposes (a generalization of Kripke models), which give us a great new variety of models for intuitionistic logic. There are deep mathematical facts buried in them and continue to be discovered. Toposes and intuitionistic logic are appropriate for modeling computer programs, which live in a growing dynamic world rather than a static one. - Girard has formulated Linear Logic, which broadens our idea of what kind of "things" a logic can talk about. David Pym and Peter O'Hearn invented Bunched Implication Logic, extending Linear Logic with a beautiful model-theoretic basis. These logics applied to imperative programming (which go by the name of "Separation Logic") are revolutionizing the development of technology for imperative programs. It is time to leave behind the classical logic. In fact, we should have done it a long time ago."

- Prof Uday Reddy on the types mailing list.

http://lists.seas.upenn.edu/pipermail/types-list/2013/001684...

Re: Logic Programming is Underrated

#7
I think both are wrong ;-)

Even programming languages like Prolog needs an expression of the problem that is not exactly how we think in logical expressions. You can't directly translate a first order logic expression to Prolog, you need to add extra thinking before doing that.

On the other hand generic combinatorics libraries don't work with large sets.

Welcome to SMT (satisfiability modulo theories) where there are state of the art optimizations for specific fields. If you want to see something impressive look at how to solve Sudoku with Z3 (http://z3.codeplex.com/) , it's just expressing the problem in logic terms: http://rise4fun.com/Z3Py/tutorialcontent/guide#h210

Re: Logic Programming is Underrated

#8
post #3

I can't understand how you can be happy using ~84,000,000 clock cycles to solve that. Logic programming is a wonderful tool to know about, and armed with that knowledge you can adapt your programming style to the problem in question. http://norvig.com/sudoku.html

Look at my comment linking to the Z3 sudoku solver: https://news.ycombinator.com/item?id=5846589

Re: Logic Programming is Underrated

#9
post #2

If we are discussing the benefits of logic programming, I think it's important to include other declarative languages like SQL. The idea of specifying directly what is computed, and not how it is computed, is very useful, and not limited to abuse mathematical problems.

That's my hypothesis for why logic-programming's popularity faded somewhat from its initial promise. When it was new, it was one of the few widely available ways of doing declarative programming, and contrasted strongly with procedural programming. But in the years since, lots of other declarative approaches have chipped away at the monopoly of logic programming proper over declarative approaches to programming.

I wrote a bit about that here: http://www.kmjn.org/notes/prolog_lost_steam.html

Re: Logic Programming is Underrated

#10

"The attractiveness of logic programming, when it was first launched, was that it had a ready-made declarative reading, which was expected to make a big difference for programming. Unfortunately, Prolog also had a bad procedural reading that people struggled with. So, in practice, Prolog programmers spent almost all of their effort on the procedural meaning, and the declarative meaning went out of the window. In the…

The rest of that discussion thread is fairly interesting as well: http://www.cs.utexas.edu/users/vl/tag/declarative

Fwiw, answer-set programming is a logic-programming language with a Prolog-derived syntax that has only a declarative reading, and no procedural reading.

Post reply on HN