Logical Programming

    Programming that uses a form of symbolic logic as a programming language is often called logic programming, and languages based on symbolic logic are called logic programming language.

    The basis for logic programming languages is predicate calculus, predicate calculus can be used for automatic theorem proving system by resolution principle.

    Logic programming languages are called declarative languages because programs written in them consist of declarations rather than assignments and control flow statements. These declaration are actually statements, or propositions, in symbolic logic. One of the essential characteristics of logic programming languages is their semantics,(declarative semantics): there is a simple way to determine the meaning of each statement, and it does not depend on how the statement might be used to solve a problem. It is considerably simpler than the semantics of the imperative languages.

    Programming in logic programming languages is nonprocedual. Programs in such language don't state exactly how a result is to be computed but rather describe the form of the result. The difference is that we assume the computer system can somehow determine how the result is to be gotten. We just supply the computer with both the relevant information and a method of inference for computing described results.

    For example, the sorting problem, in imperative languages like C, you need to explain all of the details of some sorting algorithm to a computer.

    In logic language, it is necessary only to describe the characteristics of the sorted list: it is some permutation of the given list such that for each pair of adjacent elements, a given relationship holds between the two elements.

    One of the mostly used logic programming languages is prolog. A prolog program consists of collections of statements. There are two kinds of statements: fact and rule, these two statement forms correspond to the headless and headed horn clauses of predicate calculus.

For example:
    fact: male(bill)
    rule: grandparent(X,Z) :- parent(X,Y), parent(Y,Z)

a simple prolog program:
    parent(Mike,bill)
    parent(bill,Curt)
    rule: grandparent(X,Z) :- parent(X,Y), parent(Y,Z)
 
        -> grandparent(Mike,Curt)

Closed world assumption:

    Prolog has no knowledge of the world other than its database, any query about which there is insufficient information in the database to prove absolutely is assumed to be false.

For example:
    fish(trout)
    likes(bob,Y) :- fish(Y)
    -> likes(bob,trout)

    if fish(salmon) is not in database, when I query likes(bob,salmon)? then prolog can't give you right     answer.
 

Evaluation:

Prolog has the following advantages:
1) Prolog is based on logic, prolog programs are likely to be more logically organized and written, which should lead to fewer errors and less maintenance.
2) Prolog processing is naturally parallel, making prolog interpreters particularly able to take advantage of multiple process machines.
3) Because of the conciseness of prolog programs, development time is decreased, making it a good tool for prototyping.

   One of the problem of Prolog is efficiency, that means prolog programs run very slower compared to imperative languages. Like sorting problem, it has no idea of how to sort, other than simply enumerate all permutations of the given list until it happens to create one that has the list in sorted order.

  Many computer scientists are skeptical of prolog's usefulness outside a few small areas of AI.