What are the best uses of Logic Programming?
Asked Answered
M

8

35

By Logic Programming I mean the a sub-paradigm of declarative programming languages. Don't confuse this question with "What problems can you solve with if-then-else?"

A language like Prolog is very fascinating, and it's worth learning for the sake of learning, but I have to wonder what class of real-world problems is best expressed and solved by such a language. Are there better languages? Does logic programming exist by another name in more trendy programming languages? Is the cynical version of the answer a variant of the Python Paradox?

Meraree answered 18/10, 2008 at 23:50 Comment(0)
H
22

Prototyping.

Prolog is dynamic and has been for 50 years. The compiler is liberal, the syntax minimalist, and "doing stuff" is easy, fun and efficient. SWI-Prolog has a built-in tracer (debugger!), and even a graphical tracer. You can change the code on the fly, using make/0, you can dynamically load modules, add a few lines of code without leaving the interpreter, or edit the file you're currently running on the fly with edit(1). Do you think you've found a problem with the foobar/2 predicate?

?- edit(foobar).

And as soon as you leave the editor, that thing is going to be re-compiled. Sure, Eclipse does the same thing for Java, but Java isn't exactly a prototyping language.

Apart from the pure prototyping stuff, Prolog is incredibly well suited for translating a piece of logic into code. So, automatic provers and that type of stuff can easily be written in Prolog.

The first Erlang interpreter was written in Prolog - and for a reason, since Prolog is very well suited for parsing, and encoding the logic you find in parse trees. In fact, Prolog comes with a built-in parser! No, not a library, it's in the syntax, namely DCGs.

Prolog is used a lot in NLP, particularly in syntax and computational semantics.

But, Prolog is underused and underappreciated. Unfortunately, it seems to bear an academic or "unusable for any real purpose" stigma. But it can be put to very good use in many real-world applications involving facts and the computation of relations between facts. It is not very well suited for number crunching, but CS is not only about number crunching.

Hitherto answered 19/10, 2008 at 11:31 Comment(0)
S
15

Since Prolog = Syntactic Unification + Backward chaining + REPL,

most places where syntactic unification is used is also a good use for Prolog.

Syntactic unification uses

  • AST transformations
  • Type Inference
  • Term rewriting
  • Theorem proving
  • Natural language processing
  • Pattern matching
  • Combinatorial test case generation
  • Extract sub structures from structured data such as an XML document
  • Symbolic computation i.e. calculus
  • Deductive databases
  • Expert systems
  • Artificial Intelligence
  • Parsing
  • Query languages
Sanders answered 4/4, 2012 at 13:56 Comment(0)
I
11

Constraint Logic Programming (CLP)

Many very good and well-suited use cases of logic programming have already been mentioned. I would like to complement the existing list with several tasks from an extremely important application area of logic programming:

Logic programming blends seamlessly, more seamlessly than other paradigms, with constraints, resulting in a framework called Constraint Logic Programming.

This leads to dedicated constraint solvers for different domains, such as:

  • CLP(FD) for integers
  • CLP(B) for Booleans
  • CLP(Q) for rational numbers
  • CLP(R) for floating point numbers.

These dedicated constraint solvers lead to several important use cases of logic programming that have not yeen been mentioned, some of which I show below.

When choosing a Prolog system, the power and performance of its constraint solvers are often among the deciding factors, especially for commercial users.

CLP(FD) — Reasoning over integers

In practice, CLP(FD) is one of the most imporant applications of logic programming, and is used to solve tasks from the following areas, among others:

  • scheduling
  • resource allocation
  • planning
  • combinatorial optimization

See for more information and several examples.

CLP(B) — Boolean constraints

CLP(B) is often used in connection with:

  • SAT solving
  • circuit verification
  • combinatorial counting

See .

CLP(Q) — Rational numbers

CLP(Q) is used to solve important classes of problems arising in Operations Research:

  • linear programming
  • integer linear programming
  • mixed integer linear programming

See .

Infrasonic answered 17/10, 2016 at 7:55 Comment(0)
D
5

One of the things Prolog gives you for free is a backtracking search algorithm -- you could implement it yourself, but if your problem is best solved by having that algorithm available, then it's nice to use it.

The two things I've seen it be good at is mathematical proofs and natural language understanding.

Desex answered 19/10, 2008 at 1:57 Comment(1)
A rule to explain new idea efficiently to someone who do not understand is to explain with the keywords/ideas that are already understood by someone. This answer uses the keyword 'backtracking search algorithm', which I think is much more ordinary and common compared to 'unification', etc. I get better understanding from this answer.Perigordian
I
5

Prolog is ideal for non-numeric problems. This article gives a few examples of some applications of Prolog and it might help you understand the type of problems that it might solve.

Intradermal answered 21/10, 2008 at 12:42 Comment(0)
W
5

Prolog is great at solving puzzles and the like. That said, in the domain of puzzle-solving it makes easy/medium puzzle-solving easier and complicated puzzle solving harder. Still, writing solvers for grid puzzles and the like such as Hexiom, Sudoku, or Nurikabe is not especially tough.

Wicked answered 21/10, 2008 at 12:49 Comment(2)
I don't see how it makes solving complicated puzzles harder, FWIW.Piss
It is often useful to take a fully imperative approach (complete with state and the like) for at least part of the solution. You can fake it with Prolog, but it's often easier in other languages. Especially when it's time to optimize. A built in search is less helpful once thinks get crazy.Wicked
P
2

One simple answer is "build systems". The language used to build Makefiles (at least, the part to describe dependencies) is essentially a logic programming language, although not really a "pure" logic programming language.

Planoconvex answered 12/11, 2008 at 18:44 Comment(0)
V
0

Yes, Prolog has been around since 1972. It was invented by Alain Colmerauer with Philippe Roussel, based on Robert Kowalski's procedural interpretation of Horn clauses. Alain was a French computer scientist and professor at Aix-Marseille University from 1970 to 1995.

And Alain invented it to analyse Natural Language. Several successful prototypes were created by him and his "followers".

  • His own system Orbis to understand questions in English and French about the solar system. See his personal site.
  • Warren and Pereira's system Chat80 QA on world geography.
  • Today, IBM Watson is a contempory QA based on logic with a huge dose of statistics about real world phrases.

So you can imagine that's where it's strength is.

Retired in 2006, he remained active until he died in 2017. He was named Chevalier de la Legion d’Honneur by the French government in 1986.

Verve answered 24/8, 2020 at 19:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.