Download An Introduction to Prolog Programming

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

History of the function concept wikipedia , lookup

Axiom of reducibility wikipedia , lookup

Model theory wikipedia , lookup

Abductive reasoning wikipedia , lookup

Axiom wikipedia , lookup

Structure (mathematical logic) wikipedia , lookup

Ramism wikipedia , lookup

Inquiry wikipedia , lookup

Argument wikipedia , lookup

Foundations of mathematics wikipedia , lookup

Fuzzy logic wikipedia , lookup

Willard Van Orman Quine wikipedia , lookup

Boolean satisfiability problem wikipedia , lookup

Sequent calculus wikipedia , lookup

Jesús Mosterín wikipedia , lookup

Propositional formula wikipedia , lookup

Lorenzo Peña wikipedia , lookup

Modal logic wikipedia , lookup

Quantum logic wikipedia , lookup

Catuṣkoṭi wikipedia , lookup

Syllogism wikipedia , lookup

History of logic wikipedia , lookup

Mathematical logic wikipedia , lookup

Natural deduction wikipedia , lookup

Combinatory logic wikipedia , lookup

Laws of Form wikipedia , lookup

First-order logic wikipedia , lookup

Propositional calculus wikipedia , lookup

Intuitionistic logic wikipedia , lookup

Law of thought wikipedia , lookup

Curry–Howard correspondence wikipedia , lookup

Transcript
Logic and Prolog
LP&ZT 2005
An Introduction to Prolog Programming
Ulle Endriss
Institute for Logic, Language and Computation
University of Amsterdam
Ulle Endriss ([email protected])
1
Logic and Prolog
LP&ZT 2005
Logic and Prolog
In this lecture we are going to see how Prolog programs can be
interpreted as sets of logic formulas. In fact, when processing a
query, Prolog is actually applying the rules of a logical deduction
system (which is called resolution).
Ulle Endriss ([email protected])
2
Logic and Prolog
LP&ZT 2005
Correspondences
Prolog
First-order Logic (FOL)
predicate
predicate
argument
term
variable
universally quantified variable
atom
constant/function/predicate symbol
sequence of subgoals
conjunction
:-
implication (other way round)
Ulle Endriss ([email protected])
3
Logic and Prolog
LP&ZT 2005
Question
What is the logical meaning of this program?
bigger(elephant, horse).
bigger(horse, donkey).
is_bigger(X, Y) :- bigger(X, Y).
is_bigger(X, Y) :- bigger(X, Z), is_bigger(Z, Y).
Ulle Endriss ([email protected])
4
Logic and Prolog
LP&ZT 2005
Answer
The translation of a Prolog program is usually represented as a set
of formulas, with each formula corresponding to one of the clauses
in the program:
{ bigger(elephant, horse),
bigger(horse, donkey),
∀x.∀y.(bigger(x, y) → is bigger(x, y)),
∀x.∀y.∀z.(bigger(x, z) ∧ is bigger(z, y) → is bigger(x, y)) }
Such a set is to be interpreted as the conjunction of all the
formulas in the set.
Ulle Endriss ([email protected])
5
Logic and Prolog
LP&ZT 2005
Translation of Programs
• Predicates remain the same (syntactically).
• Commas separating subgoals become ∧.
• :- becomes → and the order of head and body is changed.
• Every variable is bound by a universal quantifier (∀).
Ulle Endriss ([email protected])
6
Logic and Prolog
LP&ZT 2005
Meaning of Prolog Programs
A Prolog program corresponds to a set of formulas, all of which are
assumed to be true. This restricts the range of possible
interpretations of the predicate and function symbols appearing in
these formulas. The formulas in the translated program may be
thought of as the premises in a proof.
If Prolog gives a positive answer to a given query, this means that
the translation of the query is a logical consequence of these
premises (possibly under the assumption of suitable variable
instantiations). If Prolog gives a negative answer, this means that
the query cannot be true under the assumption that all of the
program formulas are true.
Ulle Endriss ([email protected])
7
Logic and Prolog
LP&ZT 2005
Translation of Queries
Queries are translated like rules; the “empty head” is translated as
⊥ (falsum). This corresponds to the negation of the goal whose
provability we are trying to test when submitting a query to Prolog.
Logically speaking, instead of deriving the goal itself, we try to
prove that adding the negation of the goal to the program would
lead to a contradiction:
P, (A→⊥) ` ⊥ iff
Ulle Endriss ([email protected])
P ` A
8
Logic and Prolog
LP&ZT 2005
Example
The query
?- is_bigger(elephant, X), is_bigger(X, donkey).
corresponds to the following first-order formula:
∀x.(is bigger(elephant, x) ∧ is bigger(x, donkey) → ⊥)
Ulle Endriss ([email protected])
9
Logic and Prolog
LP&ZT 2005
Horn Formulas
The formulas we get when translating all have the same structure:
A1 ∧ A2 ∧ · · · ∧ An → B
Such a formula can be rewritten as follows:
A1 ∧ A2 ∧ · · · ∧ An → B
≡
¬(A1 ∧ A2 ∧ · · · ∧ An ) ∨ B
≡
¬A1 ∨ ¬A2 ∨ · · · ∨ ¬An ∨ B
Hence, formulas obtained from translating Prolog clauses can
always be rewritten as disjunctions of literals with at most one
positive literal. Such formulas are know as Horn formulas.
Ulle Endriss ([email protected])
10
Logic and Prolog
LP&ZT 2005
Resolution
The search tree built up by Prolog when trying to answer a query
corresponds to a logic proof using resolution, which is a very
efficient deduction system for Horn formulas.
A short introduction can be found in the notes; for more details
refer to theoretically oriented books on logic programming.
Ulle Endriss ([email protected])
11
Logic and Prolog
LP&ZT 2005
Summary: Logic Foundations
• Prolog programs correspond to sets of first-order logic (Horn)
formulas.
• During translation, :- becomes an implication (from right to
left), commas between subgoals correspond to conjunctions,
and all variables need to be universally quantified. Queries
become (universally quantified) implications with ⊥ in the
consequent.
• Prolog’s search to satisfy a query corresponds to a logical
proof. In principle, any deduction calculus could be used.
Historically, Prolog is based on resolution, which is particularly
suited as it is tailored to Horn formulas.
Ulle Endriss ([email protected])
12