









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










-^
-^
-^
loves(john,mother(john)).
-^
loves(X,mother(john)),
X=john.
-^
loves(john,mother(john)).
-^
-^
? - loves(X,mother(X)),+
X=john.
-^
-^
-^
(29) Only John loves his mother
-^
(29’) Only John
doesn’t
love his mother
-^
loves_not(john,mother(john)).
-^
also, no other facts in the database that would satisfy the query
-^
?- loves_not(X,mother(john)), + X=john.
-^
loves_not(john,mother(john)).
-^
also no other facts in the database that would satisfy the query
-^
?^
-^
-^
-^
-^
suppose there are threebabies...
-^
baby(noah).
-^
baby(merrill).
-^
baby(dani).
all three cried
-^
cried(noah).
-^
cried(merrill).
-^
cried(dani).
only Dani jumped
-^
jumped(dani).
Noah and Dani swam
-^
swam(noah).
-^
swam(dani).
think of quantifiers as“properties-of-properties”
-^
every_baby(P) is a proposition
-^
P: property
-^
every_baby(P)
true
for P=cried
every_baby(P)
false
for P=jumped
and P=swam
how do we define the expression every_baby(P)?
-^
(Montague-style)
-^
every_baby(P) is shorthand for–
for all individuals X, baby(X) -> P(X)
-^
-> :
if-then (implication
: logic symbol
)
written another way (
lambda calculus-style
-^
λP.[
∀X.[baby(X) -> P(X)]]
-^
∀:
for all
( universal quantifier
: logic symbol)
Example
-^
every baby walks
-^
for all individuals X, baby(X) -> walks(X)
-^
more formally
-^
[^ NP
every baby] [
VP
walks]
-^
λP.[
∀X.[baby(X) -> P(X)]](walks)
-^
∀X.[baby(X) ->walks(X)]
-^
how do we define this Prolog-style?
-^
Example
:
-^
every baby walks
-^
[^ NP
every baby] [
VP^
walks]
-^
λP.[
∀X (baby(X) -> P(X))](walks)
-^
∀X (baby(X) ->walks(X))
-^
Possible World (Prolog database):^ –
:- dynamic baby/1.
( allows us to modify the baby database online
)
-^
baby(a).
baby(b).
-^
walks(a).
walks(b).
walks(c).
-^
individual(a).
individual(b). individual(c).
-^
What kind of query would you write?
-^
One Possible Query (
every
means there are
no exceptions
):
-^
?- + (baby(X), + walks(X)).
( NOTE
: need a space between + and ( here)
-^
Yes
(TRUE)
-^
?- baby(X), + walks(X).
-^
No
-^
?- assert(baby(d)).
-^
?- baby(X), + walks(X).
-^
X = d ;
-^
Yes
:^ all Prolog variables
are existentially quantified variables
¬(PvQ)=T only whenboth P and Q are F
∧¬Q=T only when both P and Q are F
Hence, ¬(PvQ) is equivalent to ¬P
∀X (baby(X) -> walks(X))
-^
∀X (¬baby(X) v walks(X))
-^
(since P->Q = ¬PvQ, see truth tables from two slides ago)
X ¬ (¬baby(X) v walks(X))•
(since
∀
X P(X) = ¬
∃X ¬P(X), no exception idea from 3 slides ago)
X (baby(X)
∧
¬walks(X))
-^
(by De Morgan’s rule, see truth table from last slide)
¬(baby(X)
∧
¬walks(X))
-^
(can drop
∃
X since all Prolog variables are basically existentially quantified
variables)
+ (baby(X)
∧
+walks(X))
-^
(+ = Prolog negation symbol)
+ (baby(X), +walks(X))
-^
(, = Prolog conjunction symbol)
how do we define the expression every_baby(P)?
-^
(Montague-style)
-^
every_baby(P) is shorthand for–
λP.[
∀X.baby(X) -> P(X)]
(Barwise & Cooper-style)
-^
think directly in terms of sets
-^
leads to another way of expressing the Prolog query
-^
Example
: every baby walks
{X: baby(X)}
set of all X such that baby(X) is true
{X: walks(X)}
set of all X such that walks(X) is true
Subset relation
{X: baby(X)}
{X: walks(X)}
the “baby” set must be a subset of the “walks” set
(Barwise & Cooper-style)
-^
think directly in terms of sets
-^
leads to another way of expressing the Prolog query
-^
Example
: every baby walks
{X: baby(X)}
{X: walks(X)}
the “baby” set must be a subset of the “walks” set
How to express this as a Prolog query?
-^
Queries:
-^
?- findall(X,baby(X),L1).
L1 is the set of all babies in the database
?- findall(X,walks(X),L2).
L2 is the set of all individuals who walk
Need a Prolog definition of the subset relation. This one, for example:subset([],).subset([X|L1],L2) :- member(X,L2), subset(L1,L2).member(X,[X|]).member(X,[_|L]) :- member(X,L).