1 / 17

Formal Models of Computation Part II The Logic Model

Formal Models of Computation Part II The Logic Model. Lecture 2 – Prolog: History and Introduction. Prolog: Origin and History. Prolog = Pro gramming in Log ic (1974) R.A. Kowalski: ‘Predicate logic as a programming language’ :

umed
Télécharger la présentation

Formal Models of Computation Part II The Logic Model

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Formal Models of ComputationPart IIThe Logic Model Lecture 2 – Prolog: History and Introduction

  2. Prolog: Origin and History • Prolog = Programming in Logic • (1974) R.A. Kowalski: ‘Predicate logic as a programming language’ : • First-order predicate logic for the specification of data and relations among data • Computation = logical deduction • (1972) A. Colmerauer, P. Roussel: first Prolog-like interpreter • (1980’s) Adopted as language for Japanese 5th Generation project. formal models of computation

  3. Logic Programming (LP) • R.A. Kowalski (Imperial College): Algorithm = Logic + Control • Imperative languages (Pascal, C++, Java): • data (what) • operations on data (how) • no separation between ‘what’ and ‘how’ formal models of computation

  4. LP: Logic + Control • Logic: What Logical Formulae: x (p(x)  q(x)) • Control: How Logical Deduction: if A  B and A then B formal models of computation

  5. What: Problem Description • Horn clause: A  B1,…,Bn • A,B1,…,Bn are predicates, i.e., p(a1,…,am) • Meaning: • Aistrueif B1, B2,…., and Bnare true • Horn clauses allow us to specify • Facts • Rules • Queries about objects and relations between them. formal models of computation

  6. What: Problem Description • Facts are represented as A  has(john,jaguar)  “john has a jaguar” • Rules are represented as A  B1,…,Bn rich(X)  has(X,jaguar) “if someone has a jag they are rich” • Queries are represented as B1,…,Bn  rich(Y) “who is rich?” • Facts + rules: Knowledge Base(KB) formal models of computation

  7. How: Computing with Logic • Computation as Resolution, a deduction mechanism. • A query starts up a computation which uses rules and facts (KB) to answer the query. • A query is answered as true or false, and its variables are (possibly) assigned values. • Queries may loop! (as in any programming language programs may loop…) formal models of computation

  8. How: Computing with Logic resolution(KB,Query):boolean let Query be  C1,…,Cn fori = 1 to ndo if there is a fact A in KB such that A = Ci then true else if there is a rule A  B1,…,Bnin KB such that A = Ci then resolution(KB, B1,…,Bn) elsefalse if all Ci are true then return true else return false formal models of computation

  9. How: Computing with Logic • Recursive formulation of resolution; • Exhaustive: • in order to say “no” resolution must try all possibilities!! • Simple & general definition of computation formal models of computation

  10. How: Computing with Logic KB={has(john,jaguar) , rich(X)  has(X,jaguar)} • resolution(KB, rich(Y)) • let Query be  rich(Y) • fori = 1 to 1 do • if there is a fact A in KB such that A = rich(Y) • then true • else if there is a ruleA  B1,…,Bnin KB • such thatA=Ci • then resolution(KB, B1,…,Bn) • elsefalse • if all Ciare true then return true • else return false formal models of computation

  11. How: Computing with Logic KB={has(john,jaguar) , rich(X)  has(X,jaguar)} • resolution(KB, rich(Y)) • let Query be  rich(Y) • fori = 1 to 1 do • if there is a factA in KB such thatA = rich(Y) • then true • else if there is a ruleA  B1,…,Bnin KB • such that A = rich(Y) • then resolution(KB, B1,…,Bn) • elsefalse • if all Ciare true then return true • else return false Yes, If X = Y then rich(X)  has(X,jaguar) formal models of computation

  12. How: Computing with Logic KB={has(john,jaguar) , rich(X)  has(X,jaguar)} • resolution(KB, rich(Y)) • let Query be  rich(Y) • fori = 1 to 1 do • if there is a factA in KB such thatA = rich(Y) • then true • else if there is a ruleA  B1,…,Bnin KB • such that A = rich(Y) • then resolution(KB, B1,…,Bn) • elsefalse • if all Ciare true then return true • else return false formal models of computation

  13. How: Computing with Logic KB={has(john,jaguar) , rich(X)  has(X,jaguar)} • resolution(KB, rich(Y)) • let Query be  rich(Y) • fori = 1 to 1 do • if there is a factA in KB such thatA = rich(Y) • then true • else if there is a ruleA  B1,…,Bn in KB • such that A=rich(Y) • then resolution(KB, has(Y,jaguar)) • elsefalse • if all Ciare true then return true • else return false formal models of computation

  14. How: Computing with Logic KB={has(john,jaguar) , rich(X)  has(X,jaguar)} Yes, If Y = john • resolution(KB,  has(Y,jaguar)) • let Query be  has(Y,jaguar) • fori = 1 to 1 do • if there is a fact A in KB such that A = has(Y,jaguar) • then true • else if there is a ruleA  B1,…,Bnin KB • such thatA=Ci • then resolution(KB, B1,…,Bn) • elsefalse • if all Ciare true then return true • else return false formal models of computation

  15. How: Computing with Logic KB={has(john,jaguar) , rich(X)  has(X,jaguar)} • resolution(KB, rich(Y)) • let Query be  rich(Y) • fori = 1 to 1 do • if there is a factA in KB such thatA = rich(Y) • then true • else if there is a ruleA  B1,…,Bn in KB • such that A=rich(Y) • then resolution(KB, has(john,jaguar)) • elsefalse • if all Ciare true then return true • else return false That is, Y = john formal models of computation

  16. How: Computing with Logic KB={has(john,jaguar) , rich(X)  has(X,jaguar)} • resolution(KB, rich(Y)) • let Query be  rich(Y) • fori = 1 to 1 do • if there is a factA in KB such thatA = rich(Y) • then true • else if there is a ruleA  B1,…,Bn in KB • such that A=rich(Y) • then resolution(KB, has(john,jaguar)) • elsefalse • if rich(Y)is true then return true • else return false Yes, and Y = john formal models of computation

  17. How: Computing with Logic resolution(KB,Query):boolean let Query be  C1,…,Cn fori = 1 to ndo if there is a fact A in KB such that A = Ci then true else if there is a rule A  B1,…,Bnin KB such that A = Ci then resolution(KB, B1,…,Bn) elsefalse if all Ci are true then return true else return false non-determinism: If there is more than one, which one to choose? unification: Is it possible to find values of variables that would make A and Ci equal? formal models of computation

More Related