Telechargé par mail

searchTree

publicité
Logic Programming in Prolog
• Search Trees
– voter
– farm buildings
• Remark
– I use _ to distinguish free variables: X, _X, __X, ___X etc.
– it may be easier to number: X, X , X , X etc.
CSI2120: Programming Paradigms
Example from slides
voter(Y)
Y=X
name(joe).
name(X), citizen(X),
adult(X)
name(jane).
citizen(jane).
X=joe
X=jane
citizen(joe).
citizen(joe), adult(joe)
adult(jane).
citizen(jane), adult(jane)
voter(X):name(X),
citizen(X),
adult(jane)
adult(joe)
adult(X).
?- voter(Y).
CSI2120: Programming Paradigms
Example discussed on the board
Building categories:
parent(building,farmbuilding).
parent(farmbuilding,barn).
parent(farmbuilding,silo).
parent(farmbuilding,house).
parent(barn,horsebarn).
parent(barn,cowbarn).
typeof(X,Y):- parent(Z,X),typeof(Z,Y).
typeof(X,Y):- parent(Y,X).
?- typeof(cowbarn,A).
CSI2120: Programming Paradigms
typeof(cowbarn, A)
_______X=cowbarn, ______Y = A
X=cowbarn, Y=A
parent(Z,cowbarn),typeof(Z,A)
parent( A, cowbarn)
Z=barn
A=barn
typeof(barn,A)
_X=barn, _Y = A
parent(_Z,barn),typeof(_Z,A)
_Z=farmbuilding
______X=barn, _____Y = A
parent( A, barn)
A = farmbuilding
typeof(farmbuilding,A)
__X=farmbuidling, __Y = A
parent(__Z,farmbuilding),typeof(__Z,A)
_____X=farmbuilding, ____Y = A
parent(A, farmbuilding)
A = building
__Z=building
typeof(building,A)
___X=building, __Y = A
____X=building, ___Y = A
parent(A, building)
parent(___Z,building),typeof(___Z,A)
CSI2120: Programming Paradigms
Téléchargement
Random flashcards
Commune de paris

0 Cartes Edune

Ce que beaucoup devaient savoir

0 Cartes Jule EDOH

Le lapin

5 Cartes Christine Tourangeau

aaaaaaaaaaaaaaaa

4 Cartes Beniani Ilyes

Créer des cartes mémoire