Overview of Prolog Programming Paradigm

Slide Note
Embed
Share

Prolog is a logic programming language that defines relations through facts and rules, allowing recursive rules for powerful computations. It provides a declarative way of expressing programs and offers flexibility in knowledge representation. The language uses clauses, predicates, and variables to represent data and relationships. Prolog answers questions by matching queries with defined rules and facts. The language allows for defining complex relationships like family trees and querying them using variables and conjunctions. The flexibility and symbolic processing capabilities of Prolog make it a valuable tool for various applications.


Uploaded on Nov 27, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Chapter 1 Introduction to Prolog 1.1 Defining relation by facts 1.2 Defining relations by rules 1.3 Recursive rules 1.4 How Prolog answers questions 1.5 Declarative and Procedural Meaning of Programs

  2. AI Languages LISt of Processing 1984 : lisp : 1 - . logic PROgramming in 1970 prolog : 2 - : 3

  3. : Knowledge Representation ( Relations , Rules , : - Facts Frames .) , Knowledge Base Symbolic Processing . . : - 4

  4. Flexibility of Control . : Pascal - C : . 5

  5. clauses: 2 - Facts Rules . goal ( ) . turbo prolog : program declaration goal clauses Data base predicates variables 6

  6. predicates : 2 - Predicate-name(p1,p2, .,pn) . Predicate-name (p1,p2, .,pn) ( ) ( ) 1 : Pupil(name,age) Pupil ( " name " " " " age ) " 7

  7. 2 : Likes(student,activity) Likes student " " " activity " 3 : directory(person ,telephone, birthday) directory person telephone birthday , 8

  8. : clauses facts rules 1 : father(hasan ,nori). 2 : Sister(X,Y)if female(Y)and parent(X,P)and parent(Y,P). Y X Y ) ) X Y ( ( 9

  9. . : if and or - , ; 2 Sister(X,Y):- Female(Y), Parent(X.P), Parent(Y,P). . 10

  10. 1.1 Defining relations by facts Given a whole family tree The tree defined by the Prolog program: tom pam parent( pam, bob). % Pam is a parent of Bob parent( tom, bob). parent( tom, liz). parent( bob, ann). parent( bob, pat). parent( pat, jim). bob liz ann pat jim 11

  11. How to ask Prolog? ?- parent(bob,pat). yes ?-parent(liz,pat). no Using Variables defined as Capital Letter ?-parent(X,liz). X=tom ?-parent(bob,X). X=ann if more than one answer, press ; to get others or press enter to stop X = pat ?-parent(X,Y). Using , to make conjunction (and) Who grandparent of jim? ?- parent(Y,jim), parent(X,Y). Using ; to make disjunction (or) ?-parent(Y,jim);parent(Y,pat).

  12. 1.1 Defining relations by facts Questions: Is Bob a parent of Pat? ?- parent( bob, pat). ?- parent( liz, pat). ?- parent( tom, ben). tom pam bob liz ann pat Who is Liz s parent? ?- parent( X, liz). jim Who are Bob s children? ?- parent( bob, X). 13

  13. 1.1 Defining relations by facts tom pam Questions: Who is a parent of whom? Find X and Y such that X is a parent of Y. ?- parent( X, Y). bob liz ann pat Who is a grandparent of Jim? ?- parent( Y, jim), parent( X, Y). jim X parent grandparent Y parent jim 14

  14. 1.1 Defining relations by facts Questions: Who are Tom s grandchildren? ?- parent( tom, X), parent( X, Y). tom pam bob liz ann pat Do Ann and Pat have a common parent? ?- parent( X, ann), parent( X, pat). jim 15

  15. 1.2 Defining relations by rules Facts: female( pam). % Pam is female female( liz). female( ann). female( pat). male( tom). % Tom is male male( bob). male( jim). tom pam bob liz ann pat Define the offspring( ) relation: Fact: offspring( liz, tom). Rule: offspring( Y, X) :- parent( X, Y). For all X and Y, Y is an offspring of X if X is a parent of Y. jim 16

  16. 1.2 Defining relations by rules Rules have: A condition part (body) the right-hand side of the rule A conclusion part (head) the left-hand side of the rule Example: offspring( Y, X) :- parent( X, Y). The rule is general in the sense that it is applicable to any objects X and Y. A special case of the general rule: offspring( liz, tom) :- parent( tom, liz). ?- offspring( liz, tom). ?- offspring( X, Y). X parent offspring Y 17

  17. 1.2 Defining relations by rules Define the mother relation: mother( X, Y) :- parent( X, Y), female( X). For all X and Y, X is the mother of Y if X is a parent of Y and X is a female. female X parent mother Y 18

  18. 1.2 Defining relations by rules Define the grandparent relation: grandparent( X, Z) :- parent( X, Y), parent( Y, Z). X parent grandparent Y parent Z 19

  19. 1.2 Defining relations by rules Define the sister relation: sister( X, Y) :- parent( Z, X), parent( Z, Y), female(X). For any X and Y, X is a sister of Y if (1) both X and Y have the same parent, and (2) X is female. ?- sister( ann, pat). ?- sister( X, pat). ?- sister( pat, pat). Pat is a sister to herself?! Z parent parent X Y female sister 20

Related


More Related Content