next up previous
Next: Syntax of KL1 Up: Concepts of DeepForest Previous: DeepForest: a tool as

What is logic programming?

In the case of KL1, clauses in a program have the following form.


\begin{displaymath}predicate(argument,\cdots)\ :-\ guard\ \vert\ body,
\end{displaymath} (1.1)

where predicate is literally a predicate representing a relation among arguments. For example, predicate plus(2,3,5) represents the relation that 2 plus 3 is 5 [Sterling and Shapiro, 1986]. Generally speaking, logic programming languages have somewhat different and simple form:


\begin{displaymath}predicate(argument,\cdots)\ :-\ body,
\end{displaymath} (1.2)

that is, they have no guard part. For example, the following program is one of the most typical programs in prolog.



append([],O,O).
append([M|I1],I2,[M|O]) :- append(I1,I2,O).



Each line can be interpreted as an axiom in first-order predicate logic. It means that ``if the right hand is true for symbol :-, the left hand is true'' (symbol :- means ``is implies'' or $\leftarrow$). If the right hand is empty like the first line, the left hand is always true. They can be rewritten as logic formulae:


 \begin{displaymath}\forall o A([],o,o)
\end{displaymath} (1.3)


 \begin{displaymath}\forall m,i_1,i_2,o A(i_1,i_2,o) \rightarrow A([m\vert i_1],i_2,[m\vert o])
\end{displaymath} (1.4)

The formula 1.3 means that ``for all o, A([],o,o) is held to be true''. Or if one wants, one might say that ``Anything joined with empty list is itself''. The formula 1.4 means that ``for all m,i1,i2,and o, if A(i1,i2,o) is true, A([m|i1],i2,[m|o]) is true''. One might say that ``if i1 and i2 are joined to cause o, [m|i1] and i2 are joined to cause [m|o].''

Therefore, the above program joins two of any list, and the concatenated list is given as the third argument of predicate append.

In corresponding clauses in logic programming languages with axiom, a process in execution of a program can be considered as proof of a given proposition. Consider the following program.



main :- append([1,2],[3,4,5],L).



This can be interpreted as a logic formula:


 \begin{displaymath}\forall l \neg A([1,2],[3,4,5],l) \rightarrow A([m\vert i_1],i_2,[m\vert o])
\end{displaymath} (1.5)

which means that ``for all l, A([1,2],[3,4,5],l) is not true. '' In other words, it means that there is no list such that [1,2] and [3,4,5] are joined. Execution of the program in logic programming languages is a process to prove that this proposition is false.

If we want to prove that a proposition is false, it is enough to find a counterexample. Actually, computation in logic programming is to find the counterexample, which is a result of the computation. In the case of predicate append, it is enough to find a counterexample of $\forall l \neg
A([1,2],[3,4,5],l)$, that is, to find l which satisfies $\exists l
A([1,2],[3,4,5],l)$. This is nothing but computation to find a concatenated list joining [1,2] and [3,4,5].

The process of the proof is as follows:

1.
According to axiom 1.4, if there is an x which satisfies


 
A([2],[3,4,5],x), (1.6)

l=[1|x] is a counterexample of the axiom 1.5. An x which satisfies axiom 1.6 is searched.

2.
According to axiom 1.4, if there is a y which satisfies


 
A([],[3,4,5],y), (1.7)

x=[2|y] is a counterexample of the axiom 1.6. A y which satisfies axiom 1.7 is searched.

3.
According to axiom 1.3, y=[3,4,5] satisfies axiom 1.7.

Therefore, l=[1|x]=[1,2|y]=[1,2,3,4,5] is the counterexample of axiom 1.5, and this is the result.


next up previous
Next: Syntax of KL1 Up: Concepts of DeepForest Previous: DeepForest: a tool as
Satoshi OOta
1999-03-06