صفحه 1:
Applications
Lecture 21 More Built-in
Predicates
صفحه 2:
Games
Robot control
Natural language
processing
Expert systems
Image processing
Parsing of context-free
languages
Compiler writing
VLSI Design
Relational database
applications
Other AI applications
Lecture 21 More Built-in
Predicates
صفحه 3:
سس را ۱
سس وج ae قث
۳
ممصصرة امع اي ۳ 1
ت ا
تفت
صفحه 4:
Games
Tic Tac Toe
Lec! al re Built-in
redicates
صفحه 5:
var(X) Succeeds if X is an unbound variable.
nonvar(X) Succeeds if X is not an unbound variable.
?- var(a).
No
?- nonvar(a). ?- var([X,Y,Z]).
Yes No
?- var(X). ?- nonvar([X,Y,Z]).
X= _G179 X = _G233
Yes Y = _G236
?- var(likes(X,Y)). 2- -9
No Yes
2 ?- nonvar(likes).
Yes
Lecture 21 More Built-in 5
Predicates
صفحه 6:
Succeeds if X is bound toa
?- compound("this is a string").
Yes
?- compound(‘this is a string’).
No
?- compound(X).
No
5
X=parents(adam,john,mary),compo
und(X).
X = parents(adam, john, mary)
Yes
?- compound(967).
No
?- compound(1.25).
No
; ?- compound(compound).
2: 0
compound(X)
compound term.
1- Cumpounuray.
No
a
compound(likes(john,mary)).
Yes
?- compound(likes(X,Y)).
X= 3
Y= G264
Yes
?- compound(likes(X,Y):-
likes(Y,X)).
X= _G335
Y= G336
Yes
?- compound([1,2,3,4]).
Yes
صفحه 7:
functor(Term, Functor, Arity)
Succeeds if Term is aterm with functor
“Functor” and number of arguments ۰
?- functor(likes(mary,john),Fun,Arity). 7-
Fun = likes functor(parents(adam,john,mary)
Arity = 2 ۳, (
Yes F = parents
2 N=3
X=likes(mary, john), functor(X,Func,Ar
ity). Yes
X = likes(mary, john) 2- functor(Xlikes,2).
عم - kes X = likes(_G303, _G304)
Arity = 2
a Yes
Lecture 21 More Built-in 7
Predicates
صفحه 8:
When “Term” is bound toa
integer between 1
arguments of
with
?- arg(3,[1,2,3],Val).
No
?- arg(2,Y,X).
ERROR: arg/3: Arguments
are not
sufficiently
instantiated
2
X=likes(mary,john),arg(2,X,
Y);
X = likes(mary, john)
ttes Y = john
arg(N,Term, Value)
term and N to an
and the number of
Term, Value is unified
the N-th armument af Tarm
?- arg(2,likes(mary,john),X).
X = john
Yes
?- arg(2,likes(mary,X),john).
X = john
Yes
25
arg(3,parents(john,george,X),Val)
X= _G346
Val = _G346
Yes
as
arg(3,parents(john, george, victori
a),Val)
صفحه 9:
n Example (Clocksin and Mellish)
Tic-Tac-Toe ae
3 X 3 board (9 squares on the board) ¥
0
ie [a
4 XO
7] = 5
x
Representing the game board ۱
cross
board(Sq1,Sq2,Sq3,Sq4, Sq5, Sq6, Sq7,
Sq8, Sq9)
board(o, Sq2, Sq3, Sq4, x, 0, Sq7, Sq8, x)
board([Sq1,Sq2,Sq3,Sq4,Sq5,Sq6,Sq7,Sq
8,Sq9]).
board([o,Sq2,Sq3,Sq4,x,0,Sq7,Sq8,x]).
9 یندید باتوی
Predicates
صفحه 10:
forced_move(Board,Sq):- _aline(Squares),
threatening(Squares,Board,Sq),
1
aline([1,2,3]).
aline([4,5,6]).
aline([7,8,9]).
aline([1,4,7]).
aline([2,5,8]).
aline([3,6,9]).
aline([1,5,9]).
aline([3,5,7]).
areatening([X,Y,Z], B, X)
nreatening([X,Y,Z], B, Y
areatening([X,Y,Z], B,
:- empty(X,B), cross(Y,B), cross(Z,B).
- empty(Y,B), cross(X,B), cross(Z,B).
):- empty(Z,B), cross(X,B), cross(Y,B).
mpty(Sq,Board):- arg(Sq, Board, Val), var(Val).
ross(Sq,Board):- arg(Sq, Board, Val), nonvar(Val), Val= x.
ought(Sq,Board):- arg(Sq, Board, Val), nonvar(Val), Val= o.
Lecture 21 More Built-in 10
Predicates