Logic programming

This is an old revision of this page, as edited by Glenn6502 (talk | contribs) at 17:45, 24 April 2004 (Added examples of logic programming domains to parallel existing examples for constraint programming domains.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.


Logical programming (and the closely related constraint programming) is a programming paradigm in which a set of attributes that a solution should have are specified rather than set of steps to obtain such a solution. A widely used logical programming language is Prolog. Another, more commercial language is Mercury.

Schematically, the process is facts + rules = results. For a different approach, see Inductive logic programming.

The point of logical programming is to bring the style of formal logic to computer programming. Mathematicians and philosophers find logic a successful tool for developing bodies of theory. Many problems are naturally expressed as a theory. To say a problem needs solving is often equivalent to asking if a new hypothesis is consistent with an existing theory. Logic provides a way to prove whether the question is true or false. The process of constructing a proof is well-known, so logic is thought to be a reliable way to answer questions. Logical programming systems automate this process. Artificial Intelligence was an important influence on the development of logical programming.

The monkey and banana problem is a famous problem studied in the community of logical programming. Instead of the programmer explicitly specifying the path for the monkey to reach the banana, the computer actually reasons out a possible way that the monkey reaches the banana.

Logical programming and constraint programming are both Turing-complete (if a computation has an answer, either can find the answer), and any logic program can be translated into an equivalent constraint program. Since a constraint solving program may find an answer be faster than a logic derivation program, it is often desirable to perform this translation before executing a logic program. This does does not make them the same thing. Every English work can be translated into a French work, but that does not make English and French the same language.

The difference between the two is largely in their styles and approaches to modeling the world. Some problems are more natural (this easier) to write as logic programs, while some are more natural to write as constraint programs.

Both logical programming and constraint programming create models that describe the world in which a problem exists. The style of logic programming is to create new statements about its model. The knowledge of the state of the world is expanded each time. A problem is typically stated as a single hypothesis. The logic program solves the problem by attempting to prove whether the hypothesis is actually a theorem about the model.

The style of constraint programming is to search for a state of the world in which a large number of constraints are satisfied at the same time. A problem is typically stated as a state of the world containing a number of unknown variables. The constraint program searches for values for all the variables.

Temporal concurrent constraint programming (TCC) and non-deterministic temporal concurrent constraint programming (NTCC) are variants of constraint programming that can deal with time.

Each of the types of programming targets certain domains. Some popular application domains for logic programming are:

  • Expert systems, where the program generates a recommendation or answer from a large model of the application ___domain.
  • Theorem proving, where the program generates novel theorems to extend some existing body of theory.

Some popular application domains for constraint programming are:

See also