Download presentation
Presentation is loading. Please wait.
Published byJemima Webster Modified over 9 years ago
1
CS4026 Formal Models of Computation Part II The Logic Model Lecture 2 – Prolog: History and Introduction
2
formal models of computation 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.
3
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’
4
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
5
formal models of computation 5 What: Problem Description Horn clause: A B 1,…,B n A,B 1,…,B n are predicates, i.e., p(a 1,…,a m ) Meaning: –A is true if B 1, B 2,…., and B n are true Horn clauses allow us to specify –Facts –Rules –Queries about objects and relations between them.
6
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 B 1,…,B n rich(X) has(X,jaguar) “if someone has a jag they are rich” Queries are represented as B 1,…,B n rich(Y) “who is rich?” Facts + rules: Knowledge Base (KB)
7
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…)
8
formal models of computation 8 How: Computing with Logic resolution(KB,Query):boolean let Query be C 1,…,C n for i = 1 to n do if there is a fact A in KB such that A = C i then true else if there is a rule A B 1,…,B n in KB such that A = C i then resolution(KB, B 1,…,B n ) else false if all C i are true then return true else return false
9
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
10
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) for i = 1 to 1 do if there is a fact A in KB such that A = rich(Y) then true else if there is a rule A B 1,…,B n in KB such that A = C i then resolution(KB, B 1,…,B n ) else false if all C i are true then return true else return false
11
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) for i = 1 to 1 do if there is a fact A in KB such that A = rich(Y) then true else if there is a rule A B 1,…,B n in KB such that A = rich(Y) then resolution(KB, B 1,…,B n ) else false if all C i are true then return true else return false Yes, If X = Y then rich(X) has(X,jaguar)
12
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) for i = 1 to 1 do if there is a fact A in KB such that A = rich(Y) then true else if there is a rule A B 1,…,B n in KB such that A = rich(Y) then resolution(KB, B 1,…,B n ) else false if all C i are true then return true else return false
13
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) for i = 1 to 1 do if there is a fact A in KB such that A = rich(Y) then true else if there is a rule A B 1,…,B n in KB such that A = rich(Y) then resolution(KB, has(Y,jaguar)) else false if all C i are true then return true else return false
14
formal models of computation 14 How: Computing with Logic KB={has(john,jaguar) , rich(X) has(X,jaguar)} resolution(KB, has(Y,jaguar)) let Query be has(Y,jaguar) for i = 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 rule A B 1,…,B n in KB such that A = C i then resolution(KB, B 1,…,B n ) else false if all C i are true then return true else return false Yes, If Y = john
15
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) for i = 1 to 1 do if there is a fact A in KB such that A = rich(Y) then true else if there is a rule A B 1,…,B n in KB such that A = rich(Y) then resolution(KB, has(john,jaguar)) else false if all C i are true then return true else return false That is, Y = john
16
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) for i = 1 to 1 do if there is a fact A in KB such that A = rich(Y) then true else if there is a rule A B 1,…,B n in KB such that A = rich(Y) then resolution(KB, has(john,jaguar)) else false if rich(Y) is true then return true else return false Yes, and Y = john
17
formal models of computation 17 How: Computing with Logic resolution(KB,Query):boolean let Query be C 1,…,C n for i = 1 to n do if there is a fact A in KB such that A = C i then true else if there is a rule A B 1,…,B n in KB such that A = C i then resolution(KB, B 1,…,B n ) else false if all C i 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 C i equal?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.