prolog in tro duction prolog programmi ng f acts ab out
play

Prolog In tro duction Prolog programmi ng F acts ab out - PDF document

Prolog In tro duction Prolog programmi ng F acts ab out ob jects ab out ob ject relationships and prop erties Rules ab out ob jects relationships prop erties Questions Prolog


  1. � � Prolog In tro duction Prolog programmi ng� F acts ab out ob jects � ab out ob ject relationships and prop erties Rules � ab out ob jects� relationships� prop erties Questions �

  2. Prolog � ��� F acts Syn tax� Names of relationships and ob jects b egin with a lo w er case letter� � The relationship name is giv en �rst� related ob jects are enclosed in paren� � thesis and separated b y commas� This comma�separated list is the argu� men t of the relationship� F act sen tences end in a PERIOD� � �

  3. Prolog � Seman tics� The pr o gr ammer is resp onsible for deciding up on the meaning asso ciated � with relationships� dog�spot�� Sp ot is a dog father�gerry� deb�� Gerry is the father of Deb pet�spot� cindy�� Sp ot is the p et of Cindy play�john� mary� tennis�� John and Mary pla y tennis Ob jects� spot � cindy � gerry � deb � ��� � Relationships� dog � father � pet � ��� �

  4. Prolog � This means there migh t b e am biguities in the in terpretation of program � results��� Do es older�gerry� brian� mean� � gerry is older than brian � or � brian is older than gerry � By con v en tion� w e usually write relationship descriptions lik e this� relationship�obj�� obj�� means is to�of�for obj� � obj� relationship

  5. Prolog � ��� Questions W e can ask questions ab out facts� Supp ose w e had the database giv en ab o v e� dog�spot�� This is the question yes This is the answer Answ ers ma y only use facts in the database� or facts that ma y b e deduced from the database� Th us� dog�meg�� no No fact de claring me g to b e a do g means answer � not false � NO Pr olo g c annot de duc e an W e can use v ariables� These are indicated b y an upp er case letter� W e can ha v e sev eral v ariables� play�X�Y�Z�� X � john Y � mary Z � tennis Prolog lo oks through the database and determines whether there is a set of assignmen ts to that will mak e true� X� Y� Z play�X� Y� Z� Sometimes there will b e more than one p ossible list� Supp ose w e ha v e the follo wing facts� play�john� mary� tennis�� play�john� mary� baseball�� play�john� bill� basketball�� Ask the same question� play�X�Y�Z�� X � john Y � mary Z � tennis � X � john Y � mary Z � baseball � X � john

  6. Prolog � Y � bill Z � basketball � no There w ere three sets of assignmen ts to X� Y� Z that w ould mak e the ques� tion true� Prolog con tin ues returning these v ariable assignmen ts un til no more remain� W e can restrict our queries� asking who pla ys tennis� play�X�Y�tennis �� X � john Y � mary When Prolog matc hes an ob ject with a v ariable� w e sa y that the v ariable has b een to that v alue� instantiate d ��� Conjunctions W e can construct more complicated questions b y using conjunctions� Supp ose w e use a new database� play�john� mary� tennis�� play�john� mary� baseball�� play�john� bill� basketball�� play�bill� mary� tennis�� play�bill� mary� basketball�� W e w ould lik e to kno w who pla ys John b oth in tennis and in bask etball� play�john�Y�ten nis�� play�john� Y� basketball� � Y � bill Prolog will only return instan tiations for Y that will mak e mak e b oth parts of the question �the goals� true at once� ��� Rules Rules are a con v enien t w a y to state something ab out a collection of ob jects� W e can alw a ys list eac h fact separately for ev ery ob ject� horse�robin�� horse�mac�� horse�secretari at��

  7. Prolog � dog�meg�� dog�spot�� dog�lassie�� animal�robin�� animal�meg�� animal�secretar iat�� animal�mac�� animal�lassie�� animal�spot�� likes�deb�robin �� likes�deb�meg�� likes�deb�secre taria t�� likes�deb�mac�� likes�deb�lassi e�� likes�deb�spot� � Ho w ev er� this gets unreasonably length y � By adding rules ab out relationships b et w een ob jects� w e can signi�can tly cut do wn on the database size� horse�robin�� horse�mac�� horse�secretari at�� dog�meg�� dog�spot�� dog�lassie�� animal�X� �� horse�X�� animal�X� �� dog�X�� likes�deb�X� �� animal�X�� The last three statemen ts are rules� In English� w e w ould sa y� horse�X� � If there is some that is a horse � then that � animal�X� �� X X is an animal � likes�deb�X� �� animal�X� � If there is some X that is a horse � then � that deb lik es that X � Prolog do esn�t care ab out the truth of the rules� they are statemen ts b y the programmer� This rule sa ys that all studen ts lik e studying�

  8. Prolog � likes�X�studyin g� �� student�X� � Rules are also useful for making de�nitions� feathers�tweety �� yellow�tweety�� animal�tweety�� fur�meg�� white�meg�� animal�meg�� barks�meg�� fur�robin�� paint�robin�� animal�robin�� neighs�robin�� bird�X� �� feathers�X�� animal�X� � dog�X� �� fur�X�� barks�X�� animal�X� � horse�X� �� fur�X�� neighs�X�� animal�X� � W e�v e de�ned� A bird as an animal with feathers � A dog as an animal with fur that barks � A horse as an animal with fur that neighs � W e can ask questions� fur�X�� X � meg � X � robin dog�X�� X � meg Rule dep endencies can in tro duce new conditions� Notice that app ear only M� F on the righ t hand side of the rule� �� Family of Queen Victoria �� male�albert�� male�edward�� female�alice��

  9. Prolog � female�victoria �� �� Albert and Victoria are the parents of Edward �� parents�edward� victoria� albert�� parents�alice� victoria� albert�� �� X is the sister of Y if��� �� sisterOf�X� Y� �� female�X�� �� X is female �� parents�X� M� F�� �� parents are the same �� parents�Y� M� F�� �� parents are the same �� �� X is the brother of Y if��� �� brotherOf�X� Y� �� male�X�� �� X is male �� parents�X� M� F�� �� parents are the same �� parents�Y� M� F�� �� parents are the same �� W e can use Prolog rules to �calculate� things� �� Population in millions of people in ���� �� �� pop�X� Y� � �The population of X is Y million people� �� pop�usa������ pop�india������ pop�china������ pop�brazil����� � �� Area in millions of square miles in ���� �� �� area�X� Y� � �The area of X is Y million square miles� �� area�usa���� area�india���� area�china���� area�brazil���� �� Density is population divided by area �� �� density�X� Y� � �The density of X is Y people per square mile� �� density�X� Y� �� pop�X� P�� �� population of X is P �� area�X� A�� �� area of X is A �� Y is P�A � �� density� Y� is population P over area A �� W e can ask questions ab out densit y no w�

Recommend


More recommend