صفحه 1:
Summary
صفحه 2:
Prolog: Facts
Queries
?- likes(jerry,cheeze).
yes
?-likes(X,john).
X=mary;
X=tom;
no
صفحه 3:
SS با
Rules
X is brother of Y if
X is a male and
X and Y have the same parents.
In Prolog
is_brother_of(X,Y):-male(X),
parents(X, Father, Mother),
parents(Y, Father, Mother).
صفحه 4:
a
Backtracking
population(us,275).
population(china,1262).
?- concen(X,Y).
population(nz,4). X= us
Population(india, 1000). Y = 91.6667 ;
land(us,3000). X =china
land(china,4000). = .
land(nz,250). Yr SES
land(india,3288). eine
concen(X,Y):- Y= 16;
population(X,P), X = india
land(X,L), Y = 304.136 ;
Y is P*1000/L.
No
صفحه 5:
max(X,Y,Y) :- Y>X, !.
max(X,Y,X).
?- max(1,2,X).
X=2;
No
9
max(X,Y,Y) :- Y>X.
max(X,Y,X).
?- max(1,2,X).
X=2;
8-1
No
De
صفحه 6:
SS ۲
Lists ][
[a,b,c,d,e]
[5,8,3,9,7]
[the, boy, run]
ist can be split into a head and a tail: [H
grades(john, [70,87,90,58]).
?- grades(john, [H|T]).
H=70
T= [87,90,58]
Recursion and Lists
member(X,[X| _ ]).
member(X, [ _ | Y]) :-
member(X, Y).
?- member(1, [3,4,5,8,1,9]).
Yes
صفحه 7:
1/0
put(Ch).
get(Ch).
get0(Ch).
tab(X).
nl.
read(X).
write(X).
File /O
tell(Filename)
telling(X)
told
see(Filename)
seeing(X)
seen
صفحه 8:
fifidall(X,Term, List). =e ee
male(andrew). X= andrew; X= mary;
oes X= john; ennifer;
male(george). X= george; X= eve;
male(greg). xe :
male(adam). a greg;
female(mary). X= adam;
female(jennifer). 2
Perera تك adam, eve).
۲ parents(john,george,ma B= ا 27
۳ X= andrew;
parents(greg,adam,eve).
parents(jennifer, ?- findall(X, male(X), List).
adam,eve). List= [andrew, john, george, greg, ada
parents(andrew, ?- findall(X, female(X), List).
adam,eve). List= [mary, jennifer, eve]
?- findall(X, parents(X,adam,eve), List).
List= [greg, jennifer, andrew]
صفحه 9:
۹۹۰۰۰۰
nctor(Term, Functor, Arity)
2
2 ۱ ۲ ۲ arg(N,Term, Value)
functor(likes(mary,john),Fun,Arity).
Fun = likes ?- arg(2,likes(mary,john),X).
Arity = 2 X = john
Yes Yes
9 ?- arg(2,likes(mary,X),john).
X=likes(mary john) functor(% Func A د عد john
rity).
X = likes(mary, john)
Func = likes
Yes
0
arg(3,parents(john,george,X),Val)
Arity = 2
pe X= _G346
functor(parents(adamjohnmary)E, | (= y-o0°
N). Yes
F = parents e
arg(3,parents(john,george,victori دع ور
a),Val).
Yes
Re eg
صفحه 10:
SS با
Games
Robot control
Natural language
processing
Expert systems
Image processing
Parsing of context-free
languages
Compiler writing
VLSI Design
Relational database
کت Dat Syn Bere مت خی
صفحه 11:
SS
A ‘simple grammar for expressioris
expr ::= term | term addop
expr
term ::= factor | factor
multop term
factor ::= ‘x’ | ‘y’ | lbr
expr rbr
addop ::= ‘+’ | ~’
multop ::= ‘*’ | ‘/’
Tbr es ‘(’
صفحه 12:
expr --> term.
expr --> term, addop, expr.
term --> factor. ?- phrase(expr, Ly, '*', '(', x,
term --> factor, multop, t'+', x, ')'])
factor -->[x]. Yes
factor -->[y]. ?- phrase(factor, [y])
۷99
factor --> lbr, expr, rbr.
addop ->['+']. ی yy)
addop -->['-']. ?- phrase(factor, [y , '*', x])
multop -->['*"']. No
multop -->['/']. ?- phrase(expr, [y, '*', x]) .
Ibr -->['(‘]. eS:
rbr -->[')']. ?- phrase(factor, ['(y, *',
xy).
صفحه 13:
SS
A Grammar for a very small fragment of
F sentence --> noun_phrase, verb_phrase.
noun_phrase --> determiner, noun.
noun_phrase --> proper_noun.
determiner -->[the].
determiner -->[a].
proper _noun -->[pedro].
noun -->[man].
noun -->[apple].
verb_phrase --> verb, noun_phrase.
verb_phrase --> verb.
verb -->[eats].
verb -->[sings].
صفحه 14:
Oppivaicns
Explanation
Facility
Working
Memory
Domain Expert(S) 5 _
Knowledge
User Interface
Inference
Engine
Base
Knowledge
5 owledge
ngineer
Formalized
Knowledeg
صفحه 15:
bora Chess
Ocehatica: @ Wore couse is a couse wilh ot cost vor postive
titer.
0 Wore chouse therePore betas to vor oP Pour coteqories:
Fh oe eons ttre crm tera
© ride bar the Porn:
۳0-9 0 ...۵ ~PROQ@
تس logically equivocal 7
۳0۸66۶ ... ۸۲ << 6
hus, کرت مرن ما ون cay ovecber oP couric but
Cxavples:
~arra(X) O wort), ل ل ان at)
عسي ۵ را ۲ص 0 (۷ سس 1:(
PC is paredt oP YY! aed ۲ و وه و LD thea وه وا oP TD.
صفحه 16:
(xavples:
wani(svorutes)
poreu(eizabeth,chorles)",
© veqnted qo | O postive tierub, uf bust | cequtve tera,
اوه با خن ماو سل the oexaied yoo ,وا واه وا ان امن اه امش و
Wo be proved
Dre wl clawe: O postive vod O cexniive liercds. @ppeus voy oF
the ead oP ممم و
صفحه 17:
٠" 2227ل
roby
* is desiqned to represen Word chee,
¢ does backward chaiciagy val,
* جز a Pal Durdeg equivded كوادك بو ور
اه ره ارو وس موه كمه رععصسيوهها
رتور hrogquage cod. Oodera Proloy
iwpleweutativas kave (BO Pontes, Past
صفحه 18:
Prolog Grammer
Program ::= Clause... Query | Query
Clause ::= Predicate . | Predicate :- PredicateList .
PredicateList ::= Predicate | PredicateList , Predicate
Predicate Atom | Atom( TermList )
TermList ::= Term | TermList , Term
Term ::= Numeral | Atom | Variable | Structure
Structure ::= Atom ( TermList )
Query ::= ?- PredicateList .
Numeral an integer or real number
Atom ::= string of characters beginning with a lowercase letter or
enclosed in apostrophes.
Variable ::= string of characters beginning with an uppercase
letter or underscore
Terminals = {Numeral, Atom, Variable, :
comma, period, left and
صفحه 19:
۹۹۰۰۰۰
Comparing Prolog and Haskell Syntax
In Prolog:
* functions are not evaluated - they are like data
constructors
* the language is untyped
* variables begin with upper-case letters or an
underscore
* predicate and function symbols begin with a
lower-case letter
* the list constructor functor is [ | ], not :
صفحه 20:
Prolog
relations
variable; indicated with jn
ending
start with upper case
start with lower case
separated by commas
. (when body is needed)
separated by semi-colons
full stop
| (always inside brackets)
Haskell
functions
fixed; if fewer arguments, then return a
function
start with lower case
start with upper case
separated by spaces
= (after possible alternatives)
preceded by | (or can use iftthen-else)
off-side rule (or semi-colon)
(inside parens when potentially ambiguous)
اي —_
Kinds of objects
Arity (number of
parameters)
Variables
Values
Clause parameters
‘Head-body separator
Alternatives
Clause ending
List constructor
صفحه 21:
SS با
۲۵7۵۲96 ][ =[]
reverse (h:t) = (reverse t) +
+ [h]
reverse([], []).
reverse([H|T], R) :-
reverse(T, RT), append(RT,
[H], R).