Prolog Reading Sethi Chapter Overview Predicate Calculus - - PDF document

prolog reading sethi chapter overview predicate calculus
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1 Prolog Reading Sethi Chapter
  • Overview
  • Predicate
Calculus
  • Substitution
and Unication
  • Intro
duction to Prolog
  • Prolog
Inference Rules
  • Programming
in Prolog
  • Recursion
  • List
Pro cessing
  • Arithmetic
  • Highero
rder p rogramming
  • Miscellaneous
functions
  • Conclusion
slide-2
SLIDE 2 Prolog Programming in Log ic
  • Idea
emerged in ea rly s most w
  • rk
done at Univ
  • f
Edinburgh
  • Based
  • n
a subset
  • f
rsto rder logic
  • F
eed it theo rems and p
  • se
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
  • f
industrial soft w a re
  • P
  • pula
r languages Prolog XSB LDL Co ral Datalog SQL
slide-3
SLIDE 3 Logic Programming F ramew
  • rk
Answ er Query Programming En vironmen t Is qX
  • XN
true Y esNo
  • variable
bindings Kno wledge Base Pro
  • f
Pro cedure F acts
  • R
ules
slide-4
SLIDE 4 Decla rative Languages In its purest fo rm Logic p rogramming is an example
  • f
decla rative p rogramming P
  • pula
r in database systems and a rticial in telligence Decla rative sp ecications Sp ecify what y
  • u
w ant but not ho w to compute it Example Find X and Y such that
  • X
  • Y
  • X
  • Y
  • A
metho d p rogram fo r solving these is ho w to get values fo r X and Y But all w e gave w as a sp ecication
  • r
decla ration
  • f
what w e w ant Hence the name
slide-5
SLIDE 5 Examples
  • Retrieve
the telephone numb er
  • f
the p er son whose name is T
  • m
Smith easy
  • Retrieve
the telephone numb er
  • f
the p er son whose address is
  • Black
St ha rd
  • Retrieve
the name
  • f
the p erson whose telephone numb er is
  • ha
rd Each command sp ecies what w e w ant but not ho w to get the answ er A database sys tem w
  • uld
use a dierent algo rithm fo r each
  • f
these cases Can also return multiple answ ers
  • Retrieve
the names
  • f
all p eople who live
  • n
Oak St
slide-6
SLIDE 6 Algo rithm
  • Logic
  • Control
  • Users
sp ecify logic
  • what
the algo rithm do es
  • using
logical rules and facts
  • Control
ho w the algo rithm is to b e im plemented
  • is
built into Prolog ie Sea rch p ro cedures a re built into Prolog They apply logical rules in a pa rticula r
  • 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 rsto rder logic p redicate calculus
slide-7
SLIDE 7 Classical FirstOrder Logic
  • The
simplest kind
  • f
logical statement is an atomic fo rmula
  • eg
  • mantom
tom is a man womanmary ma ry is a w
  • man
marriedtommary tom and ma ry a re ma rried
  • Mo
re complex fo rmulas can b e built up using logical connectives
  • X
  • X
  • eg
  • smarttom
  • dumbtom
smarttom
  • talltom
  • dumbtom
X marriedtom X tom is ma rried to something X lovestom X tom loves everything X marriedtom X
  • femaleX
  • humanX
tom is ma rried to a human female
slide-8
SLIDE 8 Logical Implication richtom
  • smarttom
This implies that if tom is sma rt then he must b e rich So w e
  • ften
write this as richtom
  • smarttom
In general P
  • Q
and Q
  • P
a re abb revia tions fo r P
  • Q
F
  • r
example X personX
  • smartX
  • richX
every p erson who is sma rt is also rich X motherjohnX john has a mother X motherjohnX
  • Y
motherjohnY
  • Y
  • X
john has exactly
  • ne
mother
slide-9
SLIDE 9 Ho rn Rules Logic p rogramming is based
  • n
fo rmulas called Ho rn rules
  • These
have the fo rm x
  • x
k A
  • B
  • B
  • B
j
  • where
k
  • j
  • F
  • r
example XY AX
  • BXY
  • CY
X AX
  • BX
X AXd
  • BXe
Acd
  • Bde
X AX X AXd Acd Note that atomic fo rmulas a re also Ho rn rules
  • ften
called facts
  • A
set
  • f
Ho rn rules is called a Logic Program
slide-10
SLIDE 10 Logical Inference with Ho rn Rules Logic Programming is based
  • n
a simple idea F rom rules and facts derive mo re facts Example
  • Given
the facts A B C D 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 manplato plato is a man mansocrates so crates is a man and this rule X manX
  • mortalX
all men a re mo rtal derive mortalplato mortalsocrates
slide-11
SLIDE 11 Recursive Inference Example Given X mortalX
  • mortalson
  • fX
mortalplato Derive mortalson
  • fplato
using X
  • plato
mortalson
  • fson
  • fplato
using X
  • son
  • fplato
mortalson
  • fson
  • fson
  • fplato
using X
  • son
  • fson
  • fplato
  • This
kind
  • f
inference simulates recursive p ro grams as w e shall see
slide-12
SLIDE 12 Logic Programming Ho rn rules co rresp
  • nd
to p rograms and a fo rm
  • f
Ho rn inference co rresp
  • nds
to execution F
  • r
example consider the follo wing rule XY pX
  • qXY
  • rXY
  • sXY
Later w e shall see that this rule can b e inter p reted as a p rogram where p is the p rogram name qrs a re sub routine names X is a pa rameter
  • f
the p rogram and Y is a lo cal va riable
slide-13
SLIDE 13 NonHo rn F
  • rmulas
The follo wing fo rmulas a re not Ho rn A
  • B
A
  • B
A
  • B
  • C
X AX
  • BX
A
  • B
  • C
X flagX
  • redX
  • whiteX
every ag is red
  • r
white X Y wifeX
  • marriedXY
every wife is ma rried to someone
slide-14
SLIDE 14 NonHo rn Inference Inference with nonHo rn fo rmulas is mo re com plex than with Ho rn rules alone Example A
  • B
A
  • C
B
  • C
nonHo rn W e can infer A but must do case analysis either B
  • r
C is true if B then A if C then A Therefore A is true in all cases NonHo rn fo rmulas do not co rresp
  • nd
to p ro grams and nonHo rn inference do es not co r resp
  • nd
to execution
slide-15
SLIDE 15 Logical Equivalence Many nonHo rn fo rmulas can b e put into Ho rn fo rm using t w
  • metho
ds
  • logical
equivalence
  • sk
  • lemization
Example
  • Logical
Equivalance A
  • B
  • A
  • B
  • A
  • B
  • B
  • A
Ho rn
  • B
  • A
Logical La ws
  • A
  • A
  • A
  • B
  • A
  • 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
slide-16
SLIDE 16 Example
  • Logical
Equivalence A
  • B
  • C
  • A
  • B
  • C
  • A
  • B
  • C
  • A
  • B
  • C
  • A
  • B
  • C
  • A
  • B
  • A
  • C
non Ho rn
  • A
  • B
  • A
  • C
In general rules
  • f
the follo wing fo rm cannot b e converted into Ho rn fo rm xA
  • A
n
  • B
  • B
m
  • F
  • r
example A
  • B
  • C
  • D
A
  • B
  • C
A
  • B
X AX
  • Bx
  • CX
  • DX
ie if it is p
  • ssible
to infer a nontrivial dis junction from a set
  • f
fo rmulas then the set is inherently nonHo rn A rule lik e p
  • q
  • q
infers a trivial dis junction since the rule is a logical tautology
  • Such
rules can simply b e igno red
slide-17
SLIDE 17 Sk
  • lemization
NonHo rn fo rmulas lik e x Ax can b e con verted to Ho rn fo rm Example
  • Replace
  • X
motherjohnX nonHo rn with
  • motherjohnm
Ho rn Here m is a new constant symb
  • l
called a sk
  • lem
constant
  • that
stands fo r the unkno wn mother
  • f
john Note
  • but
they sa y almost the same thing In pa rticula r
  • can
sometimes b e replaced b y
  • during
inference as w e shall see
slide-18
SLIDE 18 Sk
  • lemization
Contd Example
  • A
nonHo rn fo rmula
  • X
personX
  • Y
motherXY every p erson has a mother Let mx stand fo r the unkno wn mother
  • f
X Then w e can replace
  • b
y a Ho rn rule
  • X
personX
  • motherXmX
mX is called a sk
  • lem
function It is an a rticial name w e have created eg
  • mmary
denotes the mother
  • f
ma ry
  • mtom
denotes the mother
  • f
tom mjfk denotes the mother
  • f
jfk So w e
  • nly
need X b ecause w e dont have a name fo r X By creating a rtical names sk
  • lem
symb
  • ls
w e can eliminate many s and convert many fo rmulas to Ho rn rules which Prolog can then use Sk
  • lemization
is a technical device fo r doing inference
slide-19
SLIDE 19 Inference with Sk
  • lemization
  • X
manX
  • personX
every man is a p erson
  • X
Y personX
  • motherXY
every p erson has a mothernon Ho rn
  • XY
motherXY
  • lovesYX
every mother loves her children
  • manplato
plato is a man Question
  • Y
lovesYplato do es someone love plato Step
  • Sk
  • lemize
  • to
get a Ho rn rule
  • X
personX
  • motherX
mX Step
  • Use
Ho rn inference personplato from
  • motherplatomplato
from
  • lovesmplatoplato
from
  • Thus
  • Y
lovesYplato ie Y
  • mplato
So answ er is YES
slide-20
SLIDE 20 Sk
  • lem
Dep endencies
  • X
Y pXY sk
  • lemizes
to Y paY where a is a sk
  • lem
constant
  • Y
X pXY sk
  • lemizes
to Y pbYY where b is a sk
  • lem
function ie in
  • X
dep ends
  • n
Y But in
  • X
is indep endent
  • f
Y
  • X
Y Z qXYZ sk
  • lemizes
to X Y qXYcXY where c is a sk
  • lem
function
  • f
b
  • th
X and Y ie in
  • Z
dep ends
  • n
b
  • th
X and Y
slide-21
SLIDE 21 Sk
  • lem
Dep endencies
  • Concrete
Examples X Y lovesXY someone loves everyb
  • dy
  • Y
lovespY p loves everyb
  • dy
X Y motherXY every
  • ne
has a mother
  • X
motherXmX mX is the mother
  • f
X X Y Z
  • wnsXY
  • documentZXY
if X
  • wns
Y then there is a do cument Z sa ying that X
  • wns
Y
  • X
Y
  • wnsXY
  • documentdXYXY
dXY is a do cument sa ying that X
  • wns
Y