SlideShare ist ein Scribd-Unternehmen logo
1 von 18
Week 2
   All in prolog
   Instance and queries
   Anonymous Variable
   Arithmetic in Prolog
   Review A Family Tree
Term



     Constant              Compound Term                       Variable
  Names an individual      Names an individual         Stands for an individual
                           that has parts              unable to be named when
                                                       program is written
Atom         Number
                           likes(john, mary)                  X
alpha17         0          book(dickens, Z, cricket)          Gross_pay
gross_pay       1          f(x)                               Diagnosis
john_smith      57         [1, 3, g(a), 7, 9]                 _257
dyspepsia       1.618      -(+(15, 17), t)                    _
+               2.04e-27   15 + 17 - t
=/=             -13.6
’12Q&A’
Program consists of
 Facts
 Rules
 Goals
arithmetic comparisons automatically evaluate expressions

   X   =:= Y            X and Y must both be arithmetic expressions (no variables)
   X   == Y
   X   > Y              ?- 12 =:= 6+6.
   X   >= Y             Yes
   X   < Y
   X   =< Y             ?- X =:= 6+6.
                        ERROR: Arguments are not sufficiently instantiated




       Expr1 =:= Expr2
        True if expression Expr1 evaluates to a
       number equal to Expr2.
   it is sometimes convenient to write functors/predicates as operators

    predefined:         +(2, 3)               2 + 3


    user defined?                 likes(dave, cubs)       dave likes cubs
Find:
pam         tom                 grandfather
                                grandmother
                                grandson
      bob         liz
                                granddaughter
                                brother
ann         pat
                                sister


      jim
Recursive Rules: Predecessor Relation
   Some X is an indirect predecessor of some Z if there is a
    partnership chain of people between X and Z.
    X is a direct predecessor of Z
                                                      X is an indirect predecessor of
predecessor(X, Z) :-                             X    Z     predecessor(X, Z) :-
 parent(X, Z).                                               parent(X, Y1),
                                        parent
                                                             parent(Y1, Y2),
                                                             parent(Y2, Z).
                X                                Y1
    parent                predecessor   parent           predecessor


                Z                                Y2

                                        parent

                                                 Z

                                                                               14
Recursive Rules: Predecessor Relation                        Recursive
                                                predecessor(X, Z) :-
        Predecessor of any depth.               parent(X, Y),
                                                 predecessor(Y, Z).
        Define predecessor relation in terms of itself.
         For all X and Z
             X is a predecessor of Z if
             there is a Y such that
             (1) X is a parent of Y and
             (2) Y is a predecessor of Z.
 predecessor(X, Z) :-
  parent(X, Z).




                                                                         15
Family Program
  parent(pam, bob).
  parent(tom, bob).
                      mother(X, Y) :- parent(X, Y),
  parent(tom, liz).   female(X).
  parent(bob, ann).
  parent(bob, pat).   sister(X, Y) :- parent(Z, X),
  parent(pat, jim).   parent(Z, Y), female(X).
  female(pam).
  female(liz).
  female(ann).
  female(pat).
  male(tom).
  male(bob).
  male(jim).


                                                      16
path(X, Y)=a(X,Y).                                a
           path(X, Y) :- a(X, Z), path(Z, Y).                            b       c
arc                                                  d           e
                                                                             f
a(g, h).                                                 g
a(g, d).                                                             h
a(e, d).
a(h, f).
a(e, f).
a(a, e).
a(a, b).
a(b, f).
a(b, c).                                        ?- path(f, f).
a(f, c).                                        ?- path(a, c).
                                                ?- path(g, e).
                                                ?- path(g, X).
                                                ?- path(X, h).
a           b       c
arc   d           e
                              f
          g           h

Weitere ähnliche Inhalte

Was ist angesagt?

7.7 one to_one_functions_-_inverse_functions
7.7 one to_one_functions_-_inverse_functions7.7 one to_one_functions_-_inverse_functions
7.7 one to_one_functions_-_inverse_functions
arvin gutierrez
 
Inverse Functions
Inverse FunctionsInverse Functions
Inverse Functions
tschmucker
 
4 5 inverse functions
4 5 inverse functions4 5 inverse functions
4 5 inverse functions
hisema01
 
Lesson 3 Nov 16 09
Lesson 3 Nov 16 09Lesson 3 Nov 16 09
Lesson 3 Nov 16 09
ingroy
 
Inverse composite functions
Inverse composite functionsInverse composite functions
Inverse composite functions
Debra Wallace
 
Lesson 15: Inverse Trigonometric Functions
Lesson 15: Inverse Trigonometric FunctionsLesson 15: Inverse Trigonometric Functions
Lesson 15: Inverse Trigonometric Functions
Matthew Leingang
 

Was ist angesagt? (17)

The Yoneda lemma and String diagrams
The Yoneda lemma and String diagramsThe Yoneda lemma and String diagrams
The Yoneda lemma and String diagrams
 
7.7 one to_one_functions_-_inverse_functions
7.7 one to_one_functions_-_inverse_functions7.7 one to_one_functions_-_inverse_functions
7.7 one to_one_functions_-_inverse_functions
 
Inverse Functions
Inverse FunctionsInverse Functions
Inverse Functions
 
Functions
FunctionsFunctions
Functions
 
Inverse functions
Inverse functionsInverse functions
Inverse functions
 
5.5 Injective and surjective functions. A handout.
5.5 Injective and surjective functions. A handout.5.5 Injective and surjective functions. A handout.
5.5 Injective and surjective functions. A handout.
 
4 5 inverse functions
4 5 inverse functions4 5 inverse functions
4 5 inverse functions
 
Lesson 3 Nov 16 09
Lesson 3 Nov 16 09Lesson 3 Nov 16 09
Lesson 3 Nov 16 09
 
Calc 5.3
Calc 5.3Calc 5.3
Calc 5.3
 
Inverse composite functions
Inverse composite functionsInverse composite functions
Inverse composite functions
 
Calculus 45S Slides March 28, 2008
Calculus 45S Slides March 28, 2008Calculus 45S Slides March 28, 2008
Calculus 45S Slides March 28, 2008
 
Lesson 5: Continuity
Lesson 5: ContinuityLesson 5: Continuity
Lesson 5: Continuity
 
ON OPTIMALITY OF THE INDEX OF SUM, PRODUCT, MAXIMUM, AND MINIMUM OF FINITE BA...
ON OPTIMALITY OF THE INDEX OF SUM, PRODUCT, MAXIMUM, AND MINIMUM OF FINITE BA...ON OPTIMALITY OF THE INDEX OF SUM, PRODUCT, MAXIMUM, AND MINIMUM OF FINITE BA...
ON OPTIMALITY OF THE INDEX OF SUM, PRODUCT, MAXIMUM, AND MINIMUM OF FINITE BA...
 
Lesson 5: Continuity
Lesson 5: ContinuityLesson 5: Continuity
Lesson 5: Continuity
 
Lesson 15: Inverse Trigonometric Functions
Lesson 15: Inverse Trigonometric FunctionsLesson 15: Inverse Trigonometric Functions
Lesson 15: Inverse Trigonometric Functions
 
Analysis Solutions CIV
Analysis Solutions CIVAnalysis Solutions CIV
Analysis Solutions CIV
 
Category Theory made easy with (ugly) pictures
Category Theory made easy with (ugly) picturesCategory Theory made easy with (ugly) pictures
Category Theory made easy with (ugly) pictures
 

Andere mochten auch (8)

Bleedblue
BleedblueBleedblue
Bleedblue
 
Resume 2012
Resume 2012Resume 2012
Resume 2012
 
Uma the company story
Uma   the company storyUma   the company story
Uma the company story
 
Tallers
TallersTallers
Tallers
 
Friday (9 dec) Slides
Friday (9 dec) SlidesFriday (9 dec) Slides
Friday (9 dec) Slides
 
Masc legislative action day 20120215
Masc legislative action day 20120215Masc legislative action day 20120215
Masc legislative action day 20120215
 
Construction facts of the EURO 2016 stadiums
Construction facts of the EURO 2016 stadiumsConstruction facts of the EURO 2016 stadiums
Construction facts of the EURO 2016 stadiums
 
Week 4
Week 4Week 4
Week 4
 

Ähnlich wie Prolog Cpt114 - Week 2

Ontology-based Data Access with Existential Rules
Ontology-based Data Access with Existential RulesOntology-based Data Access with Existential Rules
Ontology-based Data Access with Existential Rules
RuleML
 
CVPR2010: higher order models in computer vision: Part 1, 2
CVPR2010: higher order models in computer vision: Part 1, 2CVPR2010: higher order models in computer vision: Part 1, 2
CVPR2010: higher order models in computer vision: Part 1, 2
zukun
 
16 partial derivatives
16 partial derivatives16 partial derivatives
16 partial derivatives
math267
 
09 logic programming
09 logic programming09 logic programming
09 logic programming
saru40
 
Jarrar.lecture notes.aai.2011s.ch9.fol.inference
Jarrar.lecture notes.aai.2011s.ch9.fol.inferenceJarrar.lecture notes.aai.2011s.ch9.fol.inference
Jarrar.lecture notes.aai.2011s.ch9.fol.inference
PalGov
 
Jarrar.lecture notes.aai.2011s.ch9.fol.inference
Jarrar.lecture notes.aai.2011s.ch9.fol.inferenceJarrar.lecture notes.aai.2011s.ch9.fol.inference
Jarrar.lecture notes.aai.2011s.ch9.fol.inference
PalGov
 

Ähnlich wie Prolog Cpt114 - Week 2 (20)

Ontology-based Data Access with Existential Rules
Ontology-based Data Access with Existential RulesOntology-based Data Access with Existential Rules
Ontology-based Data Access with Existential Rules
 
CVPR2010: higher order models in computer vision: Part 1, 2
CVPR2010: higher order models in computer vision: Part 1, 2CVPR2010: higher order models in computer vision: Part 1, 2
CVPR2010: higher order models in computer vision: Part 1, 2
 
FOLBUKCFAIZ.pptx
FOLBUKCFAIZ.pptxFOLBUKCFAIZ.pptx
FOLBUKCFAIZ.pptx
 
Program on Quasi-Monte Carlo and High-Dimensional Sampling Methods for Applie...
Program on Quasi-Monte Carlo and High-Dimensional Sampling Methods for Applie...Program on Quasi-Monte Carlo and High-Dimensional Sampling Methods for Applie...
Program on Quasi-Monte Carlo and High-Dimensional Sampling Methods for Applie...
 
Pl vol1
Pl vol1Pl vol1
Pl vol1
 
L03 ai - knowledge representation using logic
L03 ai - knowledge representation using logicL03 ai - knowledge representation using logic
L03 ai - knowledge representation using logic
 
Introduction to Stochastic calculus
Introduction to Stochastic calculusIntroduction to Stochastic calculus
Introduction to Stochastic calculus
 
Prolog basics
Prolog basicsProlog basics
Prolog basics
 
Fuzzy Morphism
Fuzzy MorphismFuzzy Morphism
Fuzzy Morphism
 
Fol
FolFol
Fol
 
Pl vol1
Pl vol1Pl vol1
Pl vol1
 
Introduction to Calculus of Variations
Introduction to Calculus of VariationsIntroduction to Calculus of Variations
Introduction to Calculus of Variations
 
L04 (1)
L04 (1)L04 (1)
L04 (1)
 
16 partial derivatives
16 partial derivatives16 partial derivatives
16 partial derivatives
 
09 logic programming
09 logic programming09 logic programming
09 logic programming
 
MUMS: Bayesian, Fiducial, and Frequentist Conference - Can a Fiducial Phoenix...
MUMS: Bayesian, Fiducial, and Frequentist Conference - Can a Fiducial Phoenix...MUMS: Bayesian, Fiducial, and Frequentist Conference - Can a Fiducial Phoenix...
MUMS: Bayesian, Fiducial, and Frequentist Conference - Can a Fiducial Phoenix...
 
Jarrar.lecture notes.aai.2011s.ch9.fol.inference
Jarrar.lecture notes.aai.2011s.ch9.fol.inferenceJarrar.lecture notes.aai.2011s.ch9.fol.inference
Jarrar.lecture notes.aai.2011s.ch9.fol.inference
 
Jarrar.lecture notes.aai.2011s.ch9.fol.inference
Jarrar.lecture notes.aai.2011s.ch9.fol.inferenceJarrar.lecture notes.aai.2011s.ch9.fol.inference
Jarrar.lecture notes.aai.2011s.ch9.fol.inference
 
Pre-Cal 40S March 3, 2009
Pre-Cal 40S March 3, 2009Pre-Cal 40S March 3, 2009
Pre-Cal 40S March 3, 2009
 
Lecture11
Lecture11Lecture11
Lecture11
 

Kürzlich hochgeladen

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Kürzlich hochgeladen (20)

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 

Prolog Cpt114 - Week 2

  • 2. All in prolog  Instance and queries  Anonymous Variable  Arithmetic in Prolog  Review A Family Tree
  • 3. Term Constant Compound Term Variable Names an individual Names an individual Stands for an individual that has parts unable to be named when program is written Atom Number likes(john, mary) X alpha17 0 book(dickens, Z, cricket) Gross_pay gross_pay 1 f(x) Diagnosis john_smith 57 [1, 3, g(a), 7, 9] _257 dyspepsia 1.618 -(+(15, 17), t) _ + 2.04e-27 15 + 17 - t =/= -13.6 ’12Q&A’
  • 4. Program consists of  Facts  Rules  Goals
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11. arithmetic comparisons automatically evaluate expressions X =:= Y X and Y must both be arithmetic expressions (no variables) X == Y X > Y ?- 12 =:= 6+6. X >= Y Yes X < Y X =< Y ?- X =:= 6+6. ERROR: Arguments are not sufficiently instantiated Expr1 =:= Expr2 True if expression Expr1 evaluates to a number equal to Expr2.
  • 12. it is sometimes convenient to write functors/predicates as operators predefined: +(2, 3)  2 + 3 user defined? likes(dave, cubs)  dave likes cubs
  • 13. Find: pam tom grandfather grandmother grandson bob liz granddaughter brother ann pat sister jim
  • 14. Recursive Rules: Predecessor Relation  Some X is an indirect predecessor of some Z if there is a partnership chain of people between X and Z. X is a direct predecessor of Z X is an indirect predecessor of predecessor(X, Z) :- X Z predecessor(X, Z) :- parent(X, Z). parent(X, Y1), parent parent(Y1, Y2), parent(Y2, Z). X Y1 parent predecessor parent predecessor Z Y2 parent Z 14
  • 15. Recursive Rules: Predecessor Relation Recursive predecessor(X, Z) :-  Predecessor of any depth. parent(X, Y), predecessor(Y, Z).  Define predecessor relation in terms of itself. For all X and Z X is a predecessor of Z if there is a Y such that (1) X is a parent of Y and (2) Y is a predecessor of Z. predecessor(X, Z) :- parent(X, Z). 15
  • 16. Family Program parent(pam, bob). parent(tom, bob). mother(X, Y) :- parent(X, Y), parent(tom, liz). female(X). parent(bob, ann). parent(bob, pat). sister(X, Y) :- parent(Z, X), parent(pat, jim). parent(Z, Y), female(X). female(pam). female(liz). female(ann). female(pat). male(tom). male(bob). male(jim). 16
  • 17. path(X, Y)=a(X,Y). a path(X, Y) :- a(X, Z), path(Z, Y). b c arc d e f a(g, h). g a(g, d). h a(e, d). a(h, f). a(e, f). a(a, e). a(a, b). a(b, f). a(b, c). ?- path(f, f). a(f, c). ?- path(a, c). ?- path(g, e). ?- path(g, X). ?- path(X, h).
  • 18. a b c arc d e f g h