Computational Logic
 Fundamentals (of Definite Programs): Syntax and Semantics

## Towards Logic Programming

• Conclusion: resolution is a complete and effective deduction mechanism using:
Horn clauses (related to Definite programs''),
Linear, Input strategy
Breadth-first exploration of the tree (or an equivalent approach)
(possibly ordered clauses, but not required - see Selection rule later)
• Very close to what is generally referred to as SLD-resolution (see later)
• This allows to some extent realizing Greene's dream (within the theoretical limits of the formal method), and efficiently!

## Towards Logic Programming (Contd.)

• Given these results, why not use logic as a general purpose programming language? [Kowalski 74]
• A logic program'' would have two interpretations:
• Declarative (LOGIC''): the logical reading (facts, statements, knowledge)
• Procedural (CONTROL''): what resolution does with the program
• ALGORITHM = LOGIC + CONTROL
• Specify these components separately
• Often, worrying about control is not needed at all (thanks to resolution)
• Control can be effectively provided through the ordering of the literals in the clauses

## Towards Logic Programming: Another (more compact) Clausal Form

• All formulas are transformed into a set of Clauses.
• A clause has the form: tex2html_wrap_inline$conc_1,...,conc_m cond_1,...,cond_n$
where tex2html_wrap_inline$conc_1,...,conc_m_or''$ tex2html_wrap_inline$cond_1,...,cond_n_and''$
are literals, and are the conclusions and conditions of a rule:
tex2html_wrap_inline$conc_1,...,conc_m_conclusions'' cond_1,...,cond_n_conditions''$

• All variables are implicitly universally quantified: (if are the variables)

• More compact than the traditional clausal form:
• no connectives, just commas
• no need to repeat negations: all negated atoms on one side, non-negated ones on the other
• A Horn Clause then has the form:
where can be zero and possibly empty.

## Some Logic Programming Terminology - Syntax'' of Logic Programs

• Definite Program: a set of positive Horn clauses
• The single conclusion is called the head.
• The conditions are called goals'' or procedure calls''.
• goal,...,goal () is called the body''.
• if the clause is called a fact'' (and the arrow is normally deleted)
• Otherwise it is called a rule''
• Query (question): a negative Horn clause (a headless'' clause)
• A procedure is a set of rules and facts in which the heads have the same predicate symbol and arity.
• Terms in a goal are also called arguments''.

## Some Logic Programming Terminology (Contd.)

• Examples:
grandfather(X,Y) father (X,Z), mother(Z,Y).
grandfather(X,Y) .
grandfather(X,Y).
grandfather(X,Y).

## LOGIC: Declarative Reading'' (Informal Semantics)

• A rule (has head and body)

which contains variables can be read as
for all :
head'' is true if goal'' and ... and goal'' are true

• A fact n=0 (has only head)

for all : head'' is true (always)

• A query (the headless clause)

for which are goal'' and ... and goal'' true?

## LOGIC: Declarative Semantics - Herbrand Base and Universe

• Given a first-order language , with a non-empty set of variables, constants, function symbols, relation symbols, connectives, quantifiers, etc. and given a syntactic object ,

i.e. the set of all ground instances'' of .

• Given , (Herbrand universe) is the set of all ground terms of .

• (Herbrand Base) is the set of all ground atoms of .

• Similarly, for the language associated with a given program we define , and .

• Example:

## Herbrand Interpretations and Models

• A Herbrand Interpretation is a subset of , i.e. the set of all Herbrand interpretations .

(Note that forms a complete lattice under - important for fixpoint operations to be introduced later).

• Example:

all subsets of

• A Herbrand Model is a Herbrand interpretation which contains all logical consequences of the program.

• The Minimal Herbrand Model is the smallest Herbrand interpretation which contains all logical consequences of the program. (It is unique.)

• Example:

## Declarative Semantics, Completeness, Correctness

• Declarative semantics of a logic program :
the set of ground facts which are logical consequences of the program (i.e., ).
(Also called the least model'' semantics of ).

• Intended meaning of a logic program :
the set of ground facts that the user expects to be logical consequences of the program.

• A logic program is correct if .

• A logic program is complete if .

• Example:
father(john,peter).
father(john,mary).
mother(mary,mike).
grandfather(X,Y) father(X,Z), father(Z,Y).

with the usual intended meaning is correct but incomplete.

## CONTROL: Linear (Input) Resolution in this Clausal Form

We now turn to the operational semantics of logic programs,
given by a concrete operational procedure: Linear (Input) Resolution.

• Complementary literals:
• in two different clauses

• on different sides of

• unifiable with unifier

father(john,mary)
grandfather(X,Y) father(X,Z), mother(Z,Y)

## CONTROL: Linear (Input) Resolution in this Clausal Form (Contd.)

• Resolution step (linear, input, ...):
• given a clause and a resolvent, we can build a new resolvent which follows from them by:

• renaming apart the clause (standardization apart'' step)

• putting all the conclusions to the left of the

• putting all the conditions to the right of the

• if there are complementary literals (unifying literals at different sides of the arrow in the two clauses), eliminating them and applying to the new resolvent

• LD-Resolution: linear (and input) resolution, applied to definite programs
Note that then all resolvents are negative Horn clauses (like the query).

## Example

• from
father(john,peter)
mother(mary,david)
we can infer
father(john,peter), mother(mary,david)

• from
father(john,mary)
grandfather(X,Y) father(X,Z), mother(Z,Y)
we can infer
grandfather(john,Y') mother(mary,Y')

## CONTROL: A proof using LD-Resolution

• Prove grandfather(john,david) '' using the set of axioms:
1. father(john,peter)
2. father(john,mary)
3. father(peter,mike)
4. mother(mary,david)
5. grandfather(L,M) father (L,N), father(N,M)
6. grandfather(X,Y) father (X,Z), mother(Z,Y)

• We introduce the predicate to prove (negated!)
1. [7.] grandfather(john,david)

• We start resolution: e.g. 6 and 7
1. [8.] father(john,Z), mother(Z,david) X/john, Y/david

• using 2 and 8
1. [9.] mother(mary,david) Z/mary

• using 4 and 9
1. []

## CONTROL: Rules and SLD-Resolution

• Two control-related issues are still left open in LD-resolution.
Given a current resolvent and a set of clauses :
• given a clause in , several of the literals in may unify the non-negated a complementary literal in

• given a literal in , it may unify with complementary literals in several clauses in

• A Computation (or Selection rule) is a function which, given a resolvent (and possibly the proof tree up to that point) returns (selects) a literal from it. This is the goal that will be used next in the resolution process.

• A Search rule is a function which, given a literal and a set of clauses (and possibly the proof tree up to that point), returns a clause from the set. This is the clause that will be used next in the resolution process.

## CONTROL: Rules and SLD-Resolution (Contd.)

• SLD-resolution: Linear resolution for Definite programs with Selection rule.

• An SLD-resolution method is given by the combination of a computation (or selection) rule and a search rule.

• Independence of the computation rule: Completeness does not depend on the choice of the computation rule.

• Example: a left-to-right'' rule (as in ordered resolution) does not impair completeness - this coincides with the completeness result for ordered resolution.

• Fundamental result:
Declarative'' semantics () operational'' semantics (SLD-resolution)
I.e., all the facts in can be deduced using SLD-resolution.

## CONTROL: Procedural reading of a logic program

• Given a rule

it can be seen as a description of the goals the solver (resolution method) has to execute in order to solve head''

• Possible, given computation and search rules.

• In general, In order to solve head', solve goal' and ... and solve goal' ''

• If ordered resolution is used (left-to-right computation rule), then read In order to solve head', first solve goal' and then goal' and then ... and finally solve goal' ''

• Thus the control'' part corresponding to the computation rule is often associated with the order of the goals in the body of a clause

• Another part (corresponding to the search rule) is often associated with the order of clauses

## CONTROL: Procedural reading of a logic program (Contd.)

• Example - read procedurally'':
father(john,peter).
father(john,mary).
father(peter,mike).
father(X,Y) mother(Z,Y), married(X,Z).

## Towards a Fixpoint Semantics for LP - Fixpoint Basics

• A fixpoint for an operator is an element of such that .

• If is a poset, is monotonic if

• If is a complete lattice and is monotonic the set of fixpoints of is also a complete lattice [Tarski]

• The least element of the lattice is the least fixpoint of , denoted

• Powers of a monotonic operator (successive applications):

We abbreviate as

• There is some such that . The sequence is the Kleene sequence for

• In a finite lattice the Kleene sequence for a monotonic operator is finite

## Towards a Fixpoint Semantics for LP - Fixpoint Basics (Contd.)

• A subset of a poset is an (ascending) chain iff

• A complete lattice is ascending chain finite (or Noetherian) if all ascending chains are finite

• In an ascending chain finite lattice the Kleene sequence for a monotonic operator is finite

## A Fixpoint Semantics for Logic Programs, and Equivalences

• The Immediate consequence operator is a mapping: defined by:

(in particular, if , then every element of is in , ).

• is monotonic, so it has a least fixpoint so that , which can be obtained by applying iteratively starting from the bottom element of the lattice (the empty interpretation)

• (Characterization Theorem) [Van Emden and Kowalski]
A program has a Herbrand model such that :
• is the least Herbrand Model of .
• is the least fixpoint of ().
• .

I.e., least model semantics () fixpoint semantics ()

• Because it gives us some intuition on how to build , the least fixpoint semantics can in some cases (e.g., finite models) also be an operational semantics (e.g., in deductive databases).

## A Fixpoint Semantics for Logic Programs: Example

• Example:


}
`

all subsets of

Last modification: Wed Jan 3 19:10:51 CET 2007 <webmaster@clip.dia.fi.upm.es>