A review of Prolog - PowerPoint PPT Presentation

About This Presentation
Title:

A review of Prolog

Description:

and many ways to select a candidate clause in the program ... 1: plan_date(Guy, Gal, Food) :- likes(Guy, Food), likes(Gal, Food). 2: likes(tom, sushi) ... – PowerPoint PPT presentation

Number of Views:37
Avg rating:3.0/5.0
Slides: 48
Provided by: brian140
Category:
Tags: prolog | review

less

Transcript and Presenter's Notes

Title: A review of Prolog


1
A review of Prolog
will be our choice of a shell implementation
language because (i) KBS facts and rules
are directly encoded as Prolog statements
(ii) Prolog has built within it an inference
engine Prolog programming in logic a
declarative language program code are
human-oriented descriptions of what is being
computed, and not how it is to be computed -
compare with imperative languages (Pascal,
C,...) which encode the computational
procedure

Note a competitor is Lisp, which is a
functional language
2
Logic
1st order predicate logic a mathematical
theory which models the world with sentences
denoting truth eg. Either it rains or it
does not rain. Every number different
than 0 is the successor of another number.
If Jack is the parent of Fred, then Jack is
the father of Fred, or Jack is
the mother of Fred. If Jack is the
parent of Fred, and Jack is male, then Jack is
the father of Fred.
There exists someone who is a parent of Fred.
predicate logic is concerned with -
formally representing facts with a formal grammar
('Predicate logic") - determining ways
of deducing logical truths from these sentences
"deduction"
3
Logic
Rules for connectives W is true
if and only if W is false W1 W2 is
true if and only if W1 is true and W2 is
true W1 or W2 is true if and only if
either W1 is true or W2 is true W1 if W2 is
false if and only if W1 is false and W2 is
true W1 iff W2 is true if and only if
either both W1 and W2 are true

or both W1 and W2 are false Rules for
Quantifiers ( ? X ) W is true if and only
if W is true for every substitution of a

domain object for X within W ( ? X ) W is
true if and only if W is true for at least one
substitution of a
domain object for X
4
Logic
If a sentence contains quantifiers and
variables, in order to determine the truth of
the sentence, you need to define a domain from
which objects will be selected. eg. (? X
? Y) likes(X, Y) --gt need to determine what X
and Y are representing ie. people? Food?
integers?... whether the sentence is really
true depends on the model you define the pairs
of objects in which "likes(X,Y)" is defined by a
relation a relation is a set of tuples that
are deemed to be true eg. if domain is
john, joe, mary, jane then the relation for
likes in our model might be likes
(john, joe), (mary, john), (jane, jane) So
likes(X,Y) is true for likes(john, joe),
likes(mary, john), likes(jane, jane)
5
Logic
if a given sentence is true for at least one
model, then it is satisfiable otherwise it is
unsatisfiable eg. (? X ? Y) likes (X, Y)
iff likes(X,Y) is unsatisfiable some
sentences are always true tautologies eg.
(? X) p(X) p(X) iff p(X)
existential quantification makes logic complex
there is no automatic means for finding the
object which satisfy an existential equation
- you can have an infinite set of objects to
consider, so it would require exhaustively
searching the set
6
Logical deduction
S1 ? S2 - S2 is a logical consequence
of sentence(s) S1 eg. (? X)
likes(chris, X) ? likes(chris, mum) S1 ?
S2 - S3 is derivable from S1 eg.
(? X,Y) likes(X,Y) or true ?
true the useful part of logic is that it is
possible to apply syntactic transformations
of sentences which preserve their truth in the
model being represented by the
sentence denoted ? P, Q P ? Q iff P ?
Q there are many procedures for deriving
new sentences, and hence new statements of
truth automatic theorem proving is concerned
with proving a sentence is true, by applying
syntactic transformations to it
7
Logical deduction
logic programming technique (a) convert
statements of logic into Horn clauses
(exists an algorithm to do that) (? X's)
p(X's) if q1(X's) ... qn(X's) (? X's)
p(X's) note can have terms as arguments in
predicate tuples (WFF's) logic programming
languages use the following deduction
rule (called modus ponens) A, (A if
B) ? B A, A ? false
this rule preserves soundness ie. truth is
maintained.
8
Logic Programming
logic programming languages use the following
notation (? X's) p(X's) if q1(X's)
... qn(X's) (? X's) p(X's)
p(X's) - q1(X's), ... , qn(X's). lt--
called a "rule" p(X's).
lt-- called a "fact"
This restricted notation is just as
computationally powerful as full predicate
logic
9
Syntax
Constants name specific objects i)
atoms constants or symbolic terms -
constants begin with lower-case letter
eg. bob, x25, aDog, - symbols are
such things as , , ... (might be
predefined in implementation, eg. - ) ii)
integers 0, 25, -5 Variables are generic
place-holders of constants - begin with
upper-case letter - eg. Answer, L,
My_List, A3 - anonymous variable the
underscore _ , used when you don't need
to use that variable anywhere else
10
Syntax (cont)
Structures basic data structure term
constant(arg 1, arg 2, ..., arg k) k
Write a Comment
User Comments (0)
About PowerShow.com