of 20 /20
Discussion #14 1/20 Discussion #14 Discussion #14 Predicate Calculus Predicate Calculus

Discussion #141/20 Discussion #14 Predicate Calculus

Embed Size (px)

Citation preview

Page 1: Discussion #141/20 Discussion #14 Predicate Calculus

Discussion #14 1/20

Discussion #14Discussion #14

Predicate CalculusPredicate Calculus

Page 2: Discussion #141/20 Discussion #14 Predicate Calculus

Discussion #14 2/20

TopicsTopics

• PredicatesPredicates• Variables and instantiationVariables and instantiation• QuantifiersQuantifiers• Logical expressionsLogical expressions• Bound and free variablesBound and free variables

Page 3: Discussion #141/20 Discussion #14 Predicate Calculus

Discussion #14 3/20

CalculusCalculus• What does calculus mean?What does calculus mean?

– Comes from the word “stone”Comes from the word “stone”– Implies a process of calculatingImplies a process of calculating

• Lots of calculus studies …Lots of calculus studies …– Differential calculusDifferential calculus– Integral calculusIntegral calculus– Relational calculusRelational calculus– Propositional calculusPropositional calculus– Predicate calculusPredicate calculus

• Predicate calculus is a generalization of Predicate calculus is a generalization of propositional calculus.propositional calculus.

Page 4: Discussion #141/20 Discussion #14 Predicate Calculus

Discussion #14 4/20

Predicate CalculusPredicate Calculus

• Predicate calculus is also called Predicate calculus is also called Predicate Logic or First-Order LogicPredicate Logic or First-Order Logic

• Predicate calculus contains all the Predicate calculus contains all the components of propositional components of propositional calculus.calculus.

• In addition, predicate calculus has In addition, predicate calculus has predicatespredicates, a , a universe of discorseuniverse of discorse ((UofDUofD), ), terms, terms, and and quantifiersquantifiers..

Page 5: Discussion #141/20 Discussion #14 Predicate Calculus

Discussion #14 5/20

PredicatesPredicates• A A predicatepredicate is a statement that is either true or false is a statement that is either true or false

and has zero or more arguments.and has zero or more arguments.• A predicate has a name followed by a list of arguments A predicate has a name followed by a list of arguments

enclosed in parentheses and is called an enclosed in parentheses and is called an atomic formulaatomic formula..Examples: Examples: Jane is the mother of MaryJane is the mother of Mary

isMother(Jane, Mary)isMother(Jane, Mary)M(j, m)M(j, m)

• Atomic formulas can be combined by logical Atomic formulas can be combined by logical connectives.connectives.Example: Example: isMother(Jane,Mary) isMother(Jane,Mary) isMother(Mary,Jane)isMother(Mary,Jane)

• If all arguments of a predicate are individual constants, If all arguments of a predicate are individual constants, the resulting atomic formula must either be true or the resulting atomic formula must either be true or false.false.Examples:Examples: Jane is the mother of Mary = TJane is the mother of Mary = T

isMother(Jane, Mary) = TisMother(Jane, Mary) = TisMother(Mary, Jane) = FisMother(Mary, Jane) = F

• The number and order of predicate arguments is The number and order of predicate arguments is significant.significant.

• The number of elements in the predicate list is called The number of elements in the predicate list is called the the arityarity of the predicate. of the predicate.

Page 6: Discussion #141/20 Discussion #14 Predicate Calculus

Discussion #14 6/20

UofD, Terms, UofD, Terms, QuantifiersQuantifiers

• The The Universe of DiscorseUniverse of Discorse ( (UofDUofD) is a set of ) is a set of values.values.– The UofD represents all values being considered.The UofD represents all values being considered.– The UofD is sometimes called the domain of interest, The UofD is sometimes called the domain of interest,

or simply the domain.or simply the domain.

• Arguments in predicates can be Arguments in predicates can be constantsconstants (values in the UofD), (values in the UofD), variablesvariables (whose value (whose value assignments come from the UofD), or assignments come from the UofD), or termsterms (expressions that evaluate to values in the UofD).(expressions that evaluate to values in the UofD).

• QuantifiersQuantifiers give us a way to evaluate predicate give us a way to evaluate predicate calculus formulas with variables that range over calculus formulas with variables that range over the entire UofD.the entire UofD.

Page 7: Discussion #141/20 Discussion #14 Predicate Calculus

Discussion #14 7/20

Less Than Less Than a Well a Well Known PredicateKnown Predicate

• Examples:Examples:2 < 32 < 3 TrueTrue3 < 23 < 2 FalseFalse<(2, 3)<(2, 3) TrueTrue<(3, 2)<(3, 2) FalseFalse<(x, y)<(x, y) ??

• Predicate evaluationPredicate evaluation– Plug in constants from the UoD.Plug in constants from the UoD.– Sometimes we have pre-agreed meanings.Sometimes we have pre-agreed meanings.– In general, we must specify the result.In general, we must specify the result.

FFFFFF33

TTFFFF22

TTTTFF11

332211<<

UoD = {1, 2, 3}

1st arg

2nd arg

Page 8: Discussion #141/20 Discussion #14 Predicate Calculus

Discussion #14 8/20

Predicate Evaluation Predicate Evaluation (continued…)(continued…)

• Sometimes we know the “meaning” Sometimes we know the “meaning” but we don’t know which but we don’t know which assignments hold until we are told.assignments hold until we are told.

• For example:For example:

TT

FF

FF

TT

SarSaraa

TTFFTTSaraSara

FFFFTTZedZed

FFFFFFSallySally

TTFFFFJimJim

ZedZedSallySallyJimJimsiblingsiblingOfOf

UoD = {Jim, Sally, Sara, Zed}

siblingOf(x,y)

Page 9: Discussion #141/20 Discussion #14 Predicate Calculus

Discussion #14 9/20

Predicate Evaluation Predicate Evaluation (continued…)(continued…)

• Sometimes we don’t know the Sometimes we don’t know the “meaning” but we are “given” the “meaning” but we are “given” the assignments.assignments.

• For example:For example:

FF

TT

TT

cc

FFTTcc

FFFFbb

FFFFaa

bbaaPP

UoD = {a, b, c}

P(x, y)Facts:P(b, c)P(c, a)P(a, c)

• Under a “closed world assumption,” we only need to list the facts (substitutions that evaluate to True). All others are False.

Page 10: Discussion #141/20 Discussion #14 Predicate Calculus

Discussion #14 10/20

InstantiationInstantiation• Instantiation is the substitution of a constant Instantiation is the substitution of a constant

for a variable (or in general, the substitution for a variable (or in general, the substitution of a term, which is an expression that yields of a term, which is an expression that yields a constant.)a constant.)

• SSxxt t A means substitute term t for all variables A means substitute term t for all variables

x in A.x in A.• SSxx

t t A is called an instantiation of A and t is A is called an instantiation of A and t is said to be an instance of x.said to be an instance of x.

• Examples:Examples:SSxx

33 P(x, y) = P(3, y) P(x, y) = P(3, y)

SSxx3+1 3+1 P(x, y, z, x) = P(3+1, y, z, 3+1) = P(4, y, z, 4)P(x, y, z, x) = P(3+1, y, z, 3+1) = P(4, y, z, 4)

Page 11: Discussion #141/20 Discussion #14 Predicate Calculus

Discussion #14 11/20

Universal Universal QuantificationQuantification

• Let A be an expression, and let x be a Let A be an expression, and let x be a variable. If we want to say that P(x) is variable. If we want to say that P(x) is true for all substitutions of values for true for all substitutions of values for x in the UofD, we write x in the UofD, we write xP(x).xP(x).

• The symbol The symbol is pronounced “for all” is pronounced “for all” and is called the universal quantifier.and is called the universal quantifier.

• Examples:Examples:– All cats have tails, All cats have tails, x(cat(x) x(cat(x) hasTail(x)). hasTail(x)).– For every integer x, x+1 > x, For every integer x, x+1 > x, x(>(x+1, x(>(x+1,

x)).x)).

Page 12: Discussion #141/20 Discussion #14 Predicate Calculus

Discussion #14 12/20

Universal Quantification Universal Quantification (continued…)(continued…)

x P(x) is shorthand for:x P(x) is shorthand for: xx P(x) = P(a) P(x) = P(a) P(b) P(b) P(c) P(c)

with UoD = {a, b, c}.with UoD = {a, b, c}. xx P(x) = P(0) P(x) = P(0) P(1) P(1) … …

with UoD = non-negative integers.with UoD = non-negative integers.

xx P(x) = T when P(x) = T for all P(x) = T when P(x) = T for all substitutions from the UoD. (Only need substitutions from the UoD. (Only need one false predicate instantiation to make one false predicate instantiation to make the formula false.)the formula false.)

• Examples:Examples: xx red(x) = T for UoD = red applesred(x) = T for UoD = red apples xx red(x) = F for UoD = applesred(x) = F for UoD = apples

Page 13: Discussion #141/20 Discussion #14 Predicate Calculus

Discussion #14 13/20

Existential Existential QuantificationQuantification

• Let A be an expression, and let x be a Let A be an expression, and let x be a variable. If we want to say that P(x) is variable. If we want to say that P(x) is true for at least one value of x, we write true for at least one value of x, we write xP(x). xP(x).

• The symbol The symbol is pronounced “there exists” is pronounced “there exists” and is called the existential quantifier.and is called the existential quantifier.

• Examples:Examples:– Some people like apples, Some people like apples, x(likesApples(x)).x(likesApples(x)).– There is an integer larger than 10, There is an integer larger than 10, x(>(x, x(>(x,

10)).10)).

Page 14: Discussion #141/20 Discussion #14 Predicate Calculus

Discussion #14 14/20

Existential Existential Quantification Quantification (continued…)(continued…) x is shorthand for:x is shorthand for:

xx P(x) = P(a) P(x) = P(a) P(b) P(b) P(c) P(c)with UoD = {a, b, c}.with UoD = {a, b, c}.

xx P(x) = P(1) P(x) = P(1) P(2) P(2) ……with UoD = non-negative integers.with UoD = non-negative integers.

xx P(x) = T when P(x) = T for one or more P(x) = T when P(x) = T for one or more substitutions from UoD. (Only need one substitutions from UoD. (Only need one true predicate instantiation to make the true predicate instantiation to make the formula true.)formula true.)

• Examples:Examples: xx red(x) = T for UoD = all applesred(x) = T for UoD = all apples xx red(x) = F for UoD = golden delicious applesred(x) = F for UoD = golden delicious apples

Page 15: Discussion #141/20 Discussion #14 Predicate Calculus

Discussion #14 15/20

Expressions with Expressions with QuantifiersQuantifiers• Quantifiers associate right to left.Quantifiers associate right to left.

– Example with UoD = {Ann, Sue, Tim}Example with UoD = {Ann, Sue, Tim}

xxy loves(x, y)y loves(x, y)

= (= (x(x(y(loves(x, y))))y(loves(x, y))))

= = x(loves(x, Ann) x(loves(x, Ann) loves(x, Sue) loves(x, Sue) loves(x, Tim)) loves(x, Tim))

= (= (loves(Ann, Ann) loves(Ann, Ann) loves(Ann, Sue) loves(Ann, Sue) loves(Ann, Tim)) loves(Ann, Tim))

(loves(Sue, Ann) (loves(Sue, Ann) loves(Sue, Sue) loves(Sue, Sue) loves(Sue, Tim)) loves(Sue, Tim))

(loves(Tim, Ann) (loves(Tim, Ann) loves(Tim, Sue) loves(Tim, Sue) loves(Tim, Tim)) loves(Tim, Tim))

• We say, for every We say, for every xx, there exists a , there exists a yy such that such that xx loves loves yy. (Everybody loves somebody.). (Everybody loves somebody.)

Page 16: Discussion #141/20 Discussion #14 Predicate Calculus

Discussion #14 16/20

Expressions with Expressions with Quantificates Quantificates (continued…)(continued…)

• What about What about yyx loves(x, y)?x loves(x, y)?– There exists a y such that for every x, x loves y. There exists a y such that for every x, x loves y. – Somebody is loved by everybody.Somebody is loved by everybody.– Not the same as everybody loves somebody.Not the same as everybody loves somebody.

• What about What about xxy loves(x, y)?y loves(x, y)?– There exists an x such that for every y, x loves y.There exists an x such that for every y, x loves y.– Somebody loves everybody.Somebody loves everybody.

• What about What about yyx loves(x, y)?x loves(x, y)?– For every y there exists an x such that x loves y.For every y there exists an x such that x loves y.– Everybody is loved by somebody.Everybody is loved by somebody.

• Order matters.Order matters.

Page 17: Discussion #141/20 Discussion #14 Predicate Calculus

Discussion #14 17/20

PrecedencePrecedenceQuantifiers have the highest precedence:Quantifiers have the highest precedence:

(unary operators)(unary operators)

yyx P(x, y) x P(x, y) Q(x) Q(x) x R(x, y, z)x R(x, y, z)y (y (x P(x, y)) x P(x, y)) Q(x) Q(x) ((x R(x, y, z))x R(x, y, z))((y (y (x P(x, y))) x P(x, y))) Q(x) Q(x) ( (((x R(x, y, z)))x R(x, y, z)))((y (y (x P(x, y))) x P(x, y))) (Q(x) (Q(x) ( (((x R(x, y, z))))x R(x, y, z))))((((y (y (x P(x, y))) x P(x, y))) (Q(x) (Q(x) ( (((x R(x, y, z)))))x R(x, y, z)))))

Page 18: Discussion #141/20 Discussion #14 Predicate Calculus

Discussion #14 18/20

Scope, Bound, and Scope, Bound, and FreeFree

• ScopeScope defines extent. Parentheses define scope, defines extent. Parentheses define scope, and precedence dictates how to insert parentheses.and precedence dictates how to insert parentheses.

• BoundBound variables define “sameness”. variables define “sameness”.– A variable is bound if it “is introduced by” a quantifier.A variable is bound if it “is introduced by” a quantifier.– A variable remains bound throughout the scope of the A variable remains bound throughout the scope of the

quantifier unless rebound by another quantifier in a quantifier unless rebound by another quantifier in a nested sub formula.nested sub formula.

• Any variable that is not bound is said to beAny variable that is not bound is said to be free. free.• We can consider bound variables to be local to the We can consider bound variables to be local to the

scope of the quantifier, just as parameters and scope of the quantifier, just as parameters and locally declared variables in procedures are local to locally declared variables in procedures are local to the procedure in which they are declared.the procedure in which they are declared.

• If several quantifiers use the same bound variable If several quantifiers use the same bound variable for quantification, then all those variables are local for quantification, then all those variables are local to their scope and are distinct.to their scope and are distinct.

Page 19: Discussion #141/20 Discussion #14 Predicate Calculus

Discussion #14 19/20

Scope, Bound, and Free Scope, Bound, and Free (continued…)(continued…)

Which variables are bound and which Which variables are bound and which are free?are free?

y y x (P(x, y) x (P(x, y) (Q(x) (Q(x) x R(x, y, z)))x R(x, y, z)))

Page 20: Discussion #141/20 Discussion #14 Predicate Calculus

Discussion #14 20/20

Scope, Bound, and Free Scope, Bound, and Free (continued…)(continued…)

Which variables are bound and which Which variables are bound and which are free?are free?

y y x (P(x, y) x (P(x, y) (Q(x) (Q(x) x R(x, y, z)))x R(x, y, z)))

y is bound

x is bound x is bound

z is freedifferent x’s