What is Logic Programming? and what is different from others
The wikipedia entry explains it well: while on the surface it seems like a redundant term since all programming uses logic, in practice it is a term for a well-defined paradigm, such as "functional programming" and "object-oriented programming". In particular,
logical programming, in a narrower sense, in which it is more often understood, is the use of logic as both a declarative and a procedural presentation language. It is based on the fact that back reasoning theorem applied to declarative sentences in Consequence form:
If B1 and … and Bn then H
considers consequences as procedures for eliminating a goal:
to show/solve H, show/solve B1 and … and Bn.
The language Prolog
(in one form or another) is probably still the most popular logic programming language.
a source to share
I usually understand that this means using a prologue. Prolog allows you to define predicates and truth values. The interpreter prolog can then obtain further "truths" using standard logical rules. For example, each of the following lines establishes a relationship between father_child
and mother_children
between the first and second parameters (people mentioned from The Simpsons).
member(X, [X|_]).
member(X, [_|T]) :- member(X,T).
mother_children(marge, [bart, lisa, maggie]).
mother_children(mona, [homer, jay]).
mother_child(X, Y) :- mother_children(X, C), member(Y, C).
father_child(homer, bart).
father_child(homer, lisa).
father_child(homer, maggie).
father_child(abe, homer).
father_child(abe, herb).
father_child(abe, abbie).
sibling(X, Y) :- parent_child(Z, X), parent_child(Z, Y).
parent_child(X, Y) :- father_child(X, Y).
parent_child(X, Y) :- mother_child(X, Y).
If you run this program into the interpreter prologue and then ask it sibling(X,Y)
, it will return all pairs of existing siblings to you. Interestingly, we never say that we say that Bart is Lisa's brother. We are simply defining the relationship between father and mother, but in defining further rules, the prologue uses the usual rules to determine which names fill the rule sibling
.
Prolog was more popular in the 80s, in various AI systems, etc. It's a bit out of fashion these days (not what you know in universities where shit is still hot).
a source to share