prolog reading sethi chapter overview predicate calculus
play

Prolog Reading Sethi Chapter Overview Predicate Calculus - PDF document

Prolog Reading Sethi Chapter Overview Predicate Calculus Substitution and Unication Intro duction to Prolog Prolog Inference Rules Programming in Prolog Recursion List


  1. Prolog Reading� Sethi� Chapter ��� Overview � Predicate Calculus � Substitution and Uni�cation � Intro duction to Prolog � Prolog Inference Rules � Programming in Prolog � � Recursion � List Pro cessing � Arithmetic � Higher�o rder p rogramming � Miscellaneous functions Conclusion � �

  2. Prolog Pro gramming Log in ic Idea emerged in ea rly �����s� � most w o rk done at Univ� of Edinburgh� Based on a subset of �rst�o rder logic� � F eed it theo rems and p ose queries� � system do es the rest� main uses� � Originally � mainly fo r natural language � p ro cessing� No w �nding uses in database systems � and even rapid p rotot yping systems of industrial soft w a re� P opula r languages� Prolog� XSB� LDL� � Co ral� Datalog� SQL� �

  3. Logic Programming F ramew o rk Query� Is q�X�� ��� �XN� true� Programming En vironmen t Kno wledge Base� F acts � R ules Pro of Pro cedure Answ er� �Y es�No� � variable bindings �

  4. Decla rative Languages In its purest fo rm� Logic p rogramming is an example of rogramming � decla rative p P opula r in database systems and a rti�cial in� telligence� Decla rative sp eci�cations� Sp ecify what y ou w ant� but not ho w to compute it� Example� Find and such that X Y � X � � Y � � X � Y � � A metho d �p rogram� fo r solving these is ho w to get values fo r and Y � But all w e gave X w as a eci�cation � o r of what w e sp decla ration w ant� Hence the name� �

  5. Examples �Retrieve the telephone numb er of the p er� � son whose name is T om Smith� �easy� �Retrieve the telephone numb er of the p er� � son whose address is �� Black St� �ha rd� �Retrieve the name of the p erson whose � telephone numb er is ��������� �ha rd� Each command sp eci�es w e w ant but what not to get the answ er� A database sys� ho w tem w ould use a di�erent algo rithm fo r each of these cases� Can also return multiple answ ers� �Retrieve the names of p eople who live � all on Oak St�� �

  6. Algo rithm � Logic � Control Users sp ecify �logic� � the algo rithm � what do es � using logical rules and facts� �Control� � ho the algo rithm is to b e im� � w plemented � is built into Prolog� i�e�� Sea rch p ro cedures a re built into Prolog� They apply logical rules in a pa rticula r o rder to answ er user questions� Example� P if Q and Q and ��� and Q � � k can b e read as to deduce P � deduce Q � deduce Q � ��� deduce Q k Users sp ecify what they w ant using classical �rst�o rder logic �p redicate calculus�� �

  7. Classical First�Order Logic The simplest kind of logical statement is an � � � � atomic fo rmula e�g �tom is a man� man�tom� �ma ry is a w oman� woman�mary� married�tom�mary� �tom and ma ry a re ma rried� Mo re complex fo rmulas can b e built up using � � � � � � � � � � � � logical connectives � X � X e�g � smart�tom� dumb�tom� smart�tom� � tall�tom� � dumb�tom� � X married�tom� X� �tom is ma rried to something� � X loves�tom� X� �tom loves everything� � X � � �married�tom� X� female�X� human�X�� �tom is ma rried to a human female� �

  8. Logical Implication rich�tom� � � smart�tom� This implies that if tom is sma rt� then he must b e rich� So� w e often write this as rich�tom� � smart�tom� In general� and a re abb revia� P � Q Q � P tions fo r Q � P � � F o r example� � X ��person�X� � smart�X�� � rich�X�� �every p erson who is sma rt is also rich� � X mother�john�X� �john has a mother� � X �mother�john�X� � � Y mother�john�Y� � Y � X� �john has one mother� exactly �

  9. Ho rn Rules Logic p rogramming is based on fo rmulas called Ho rn rules � These have the fo rm � A � � x ���x � B � B ��� � B � � � k j where �� k � j � F o r example� � X�Y � � �A�X� B�X�Y� C�Y�� � X � �A�X� B�X�� � X �A�X�d� � B�X�e�� A�c�d� � B�d�e� � X A�X� � X A�X�d� A�c�d� Note that atomic fo rmulas a re also Ho rn rules� often called facts � A of Ho rn rules is called a set Logic Program �

  10. Logical Inference with Ho rn Rules Logic Programming is based on a simple idea� F rom rules and facts derive mo re facts Example �� Given the facts D � A� B� C� and these rules� ��� E � A � B ��� F � C � D ��� � � G E F F rom ���� derive E F rom ���� derive F F rom ���� derive G Example �� Given these facts� ��plato is a man�� man�plato� ��so crates is a man�� man�socrates� and this rule� � X � �man�X� mortal�X�� ��all men a re mo rtal�� derive� mortal�plato� � mortal�socrates� � ��

  11. Recursive Inference Example� Given� � X �mortal�X� � mortal�son of�X��� mortal�plato� Derive� mortal�son of�plato�� �using plato � X � mortal�son of�son of�plato��� �using of�plato� � X � son mortal�son of�son of�son of�plato���� �using of�plato�� � X � son of�son ��� This kind of inference simulates recursive p ro� grams �as w e shall see�� ��

  12. Logic Programming Ho rn rules co rresp ond to p rograms� and a fo rm of Ho rn inference co rresp onds to execution� F o r example� consider the follo wing rule� � X�Y p�X� � q�X�Y� � r�X�Y� � s�X�Y� Later� w e shall see that this rule can b e inter� p reted as a p rogram� where is the p rogram name� p a re sub routine names� q�r�s is a pa rameter of the p rogram� and X is a lo cal va riable� Y ��

  13. Non�Ho rn F o rmulas The follo wing fo rmulas a re Ho rn� not A � � B A � B � � A B C � X � �A�X� B�X�� A � �B � C� � X �flag�X� � �red�X� � white�X��� ��every �ag is red o r white�� � X � Y �wife�X� � married�X�Y�� ��every wife is ma rried to someone�� ��

  14. Non�Ho rn Inference Inference with non�Ho rn fo rmulas is mo re com� plex than with Ho rn rules alone� Example� � A B A � C �non�Ho rn� � B C W e can infer A � but must do case analysis� either B or C is true� if B then A if C then A Therefore� A is true in all cases� Non�Ho rn fo rmulas do not co rresp ond to p ro� grams� and non�Ho rn inference do es not co r� resp ond to execution� ��

  15. Logical Equivalence Many non�Ho rn fo rmulas can b e put into Ho rn fo rm using t w o metho ds� ��� logical equivalence ��� sk olemization Example �� Logical Equivalance� � A � � B � � A � � � � B� � � A � B � B � � A �Ho rn� � B � A Logical La ws � �� � A A � � � � A � � �A B� B A � �B � C� � �A � B� � �A � C� A � B � A � � B Example �� Logical Equivalance� A � �B � C� � A � � �B � C� � A � � � B � � C� � �A � � B� � �A � � C� �Ho rn� � �A � B� � �A � C� ��

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend