university of aberdeen, computing science cs3511 discrete methods kees van deemter

145
odule #1 - Logic 06/18/22 Michael Frank / Kees van Deemter 1 University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter Slides adapted from Michael P. Slides adapted from Michael P. Frank’s Frank’s Course Based on the Text Course Based on the Text Discrete Mathematics & Its Applications Discrete Mathematics & Its Applications (5 (5 th th Edition) Edition) by Kenneth H. Rosen by Kenneth H. Rosen

Upload: burton-saunders

Post on 01-Jan-2016

24 views

Category:

Documents


2 download

DESCRIPTION

University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter. Slides adapted from Michael P. Frank’s Course Based on the Text Discrete Mathematics & Its Applications (5 th Edition) by Kenneth H. Rosen. Module #1: Part 2: Predicate Logic. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 1

University of Aberdeen, Computing Science

CS3511Discrete Methods

Kees van Deemter

Slides adapted from Michael P. Frank’s Slides adapted from Michael P. Frank’s Course Based on the TextCourse Based on the Text

Discrete Mathematics & Its ApplicationsDiscrete Mathematics & Its Applications (5(5thth Edition) Edition)

by Kenneth H. Rosenby Kenneth H. Rosen

Page 2: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 2

Module #1:Part 2: Predicate Logic

Rosen 5Rosen 5thth ed., §§1.3-1.4 (but much extended) ed., §§1.3-1.4 (but much extended)~135 slides, ~5 lectures~135 slides, ~5 lectures

Page 3: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 3

Predicate Logic (§1.3)

• We can use propositional logic to prove that We can use propositional logic to prove that certain real-life inferences are valid.certain real-life inferences are valid.– If it’s cold then it snows. If it’s cold then it snows. – If it snows there are accidentsIf it snows there are accidents– There are no accidents.There are no accidents. Therefore: Therefore:– It’s not coldIt’s not cold

• In propositional logic:In propositional logic:((c((cs s ssa a a) a) c) c) is a tautologyis a tautology

Topic #3 – Predicate Logic

Page 4: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 4

Predicate Logic (§1.3)

• In propositional logic:In propositional logic:(((c(((cs) s) (s(sa) a) a) a) c) c) is a tautologyis a tautology

• Saying this differently,Saying this differently,It follows by propositional logic fromIt follows by propositional logic from((ccs) s) (s(sa) a) aa (premisse) that (premisse) that cc (conclusion) (conclusion)

Topic #3 – Predicate Logic

Page 5: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 5

Predicate Logic (§1.3)

• But other valid inferences cannot be proven But other valid inferences cannot be proven valid by propositional logicvalid by propositional logic– Some girl is adored by everyone. Some girl is adored by everyone. Therefore:Therefore:– Everyone adores someoneEveryone adores someone

• For inferences like this, we need a more For inferences like this, we need a more expressive logicexpressive logic

• Needed: treatment of `some’ and `every’Needed: treatment of `some’ and `every’(a bit analogous to `or’ and `and’)(a bit analogous to `or’ and `and’)

Topic #3 – Predicate Logic

Page 6: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 6

Predicate Logic (§1.3)

• Predicate logicPredicate logic is an extension of is an extension of propositional logic that permits propositional logic that permits quantification over classes of entities.quantification over classes of entities.

• Propositional logic (recall) treats Propositional logic (recall) treats simple simple propositionspropositions (sentences) as atomic entities. (sentences) as atomic entities.

• In contrast, In contrast, predicate predicate logic distinguishes the logic distinguishes the subjectsubject of a sentence from its of a sentence from its predicate.predicate.

Topic #3 – Predicate Logic

Page 7: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 7

Applications of Predicate Logic

It is one of the most-used formal notations It is one of the most-used formal notations for writing mathematical for writing mathematical definitionsdefinitions, , axiomsaxioms, and , and theoremstheorems. .

For example, in For example, in linear algebralinear algebra, a , a partial partial orderorder is introduced saying that a relation R is introduced saying that a relation R is is reflexivereflexive and and transitivetransitive – and these – and these notions are defined using predicate logic.notions are defined using predicate logic.

Topic #3 – Predicate Logic

Page 8: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 8

Practical Applications of Predicate Logic

• Basis for many Artificial Intelligence systems.Basis for many Artificial Intelligence systems.– E.g.E.g. automatic program verification systems. automatic program verification systems.

• Predicate-logic like statements are supported by Predicate-logic like statements are supported by some of the more sophisticated some of the more sophisticated database query database query enginesengines

• There are also limitations associated with using There are also limitations associated with using predicate logic. – More about that laterpredicate logic. – More about that later

Topic #3 – Predicate Logic

Page 9: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 9

First: A bit of grammar

• In the sentence “The dog is sleeping”:In the sentence “The dog is sleeping”:– The phrase “the dog” denotes the The phrase “the dog” denotes the subjectsubject - -

which the sentence is about.which the sentence is about.– The phrase “is sleeping” denotes the The phrase “is sleeping” denotes the predicatepredicate- -

a property that is true a property that is true ofof the subject. the subject.

• Predicate logic will follow the same pattern. Predicate logic will follow the same pattern.

Topic #3 – Predicate Logic

Page 10: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 10

Formulas of predicate logic (informal)

• We will useWe will use various kinds of individual various kinds of individual constantsconstants thatthat denote individuals/objects: denote individuals/objects: a,b,c,…a,b,c,…

Constants Constants are a bit likeare a bit like names names• Individual variablesIndividual variables over objects: over objects: xx, , yy, , zz , …, …• The The result ofresult of applyingapplying a predicate a predicate PP to a to a

constant constant aa is the proposition is the proposition PP(a)(a)Meaning: the object denoted by Meaning: the object denoted by aa has the property has the property denoted by denoted by PP..

Topic #3 – Predicate Logic

Page 11: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 11

Formulas of predicate logic (informal)

• The The result ofresult of applyingapplying a predicate a predicate PP to a to avariable x is the variable x is the propositional propositional formform P P(x).(x).– E.g.E.g. if if P P = “is a prime number”, then = “is a prime number”, then

PP(x) is the (x) is the propositionalpropositional formform “x is a prime number”. “x is a prime number”.

Topic #3 – Predicate Logic

Page 12: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 12

Predicates/relations with n places

• Predicate logic Predicate logic generalisesgeneralises the notion of a the notion of a predicate to include propositional functions predicate to include propositional functions of of anyany number of arguments. E.g.: number of arguments. E.g.:

R(R(xx,,yy) = “) = “x adores yx adores y””

PP((xx,,y,zy,z) = “) = “x x gavegave y y the gradethe grade z z””

Q(x,y,z,uQ(x,y,z,u)= “ )= “ x*(y+z)=u ”x*(y+z)=u ”

Topic #3 – Predicate Logic

Page 13: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 13

Universes of Discourse (U.D.s)

• Predicate Logic lets you state things about Predicate Logic lets you state things about manymany objects at once.objects at once.

• E.g., let E.g., let PP((xx) = “ () = “ (xx*2) *2) x x ”. We can then say,”. We can then say,““For For anyany number number xx, , PP((xx) is true” instead of) is true” instead of((00*2 *2 00) ) ( (11*2 *2 11)) ( (22*2 *2 22)) ... ...

• The collection of values that a variable The collection of values that a variable xx can take can take is called is called xx’s ’s universe of discourseuniverse of discourse..(u.d. is something outside the formula that helps (u.d. is something outside the formula that helps giving it its intended interpretation.)giving it its intended interpretation.)

Topic #3 – Predicate Logic

Page 14: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 14

Universes of Discourse (U.D.s)

• E.g., let E.g., let PP((xx)=“)=“xx*2 *2 xx”. We can then say,”. We can then say,““For For anyany number number xx, , PP((xx) is true” instead of) is true” instead of((00*2 *2 00) ) ( (11*2 *2 11)) ( (22*2 *2 22)) ... ...

• Applying the notion of an u.d.:Applying the notion of an u.d.:– ““For For anyany number number xx, , PP((xx) is true” is ) is true” is truetrue

when u.d. = when u.d. = NN– ““For For anyany number number xx, , PP((xx) is true” is ) is true” is falsefalse

when u.d. = when u.d. = ZZ

Topic #3 – Predicate Logic

Page 15: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 15

Back to propositional logic

• In propositional logic, we could not simply In propositional logic, we could not simply say whether a formula is TRUE; what we say whether a formula is TRUE; what we could say is whether it is TRUE with could say is whether it is TRUE with respect to a given assignment of respect to a given assignment of TRUE/FALSE to the Atoms in the formulaTRUE/FALSE to the Atoms in the formula

• E.g., E.g., ppq q is TRUE with respect to the is TRUE with respect to the assignment assignment pp=TRUE, =TRUE, qq=TRUE=TRUE

Page 16: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 16

Predicate logic

• In predicate logic, we say that a formula is TRUE In predicate logic, we say that a formula is TRUE (FALSE) with respect to a (FALSE) with respect to a modelmodel

• Model = u.d. plus specification of the “meanings” Model = u.d. plus specification of the “meanings” of the predicates. This can be done e.g.of the predicates. This can be done e.g.– by giving an English equivalent of a predicateby giving an English equivalent of a predicate– by listing explicitly which objects by listing explicitly which objects

the predicate is true ofthe predicate is true of• ... as long the ... as long the extensionextension of the predicate is clear. of the predicate is clear.

(By definition, this is (By definition, this is the set of objects in the u.d. the set of objects in the u.d. for which the predicate holdsfor which the predicate holds.).)

Page 17: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 17

Quantifier Expressions

• QuantifiersQuantifiers provide a notation that allows provide a notation that allows us to us to quantify quantify (count) (count) how manyhow many objects in objects in the u.d. satisfy a given predicate.the u.d. satisfy a given predicate.

• ““” ” is the FORis the FORLL or LL or universaluniversal quantifier. quantifier. ““” is the ” is the XISTS or XISTS or existentialexistential quantifier. quantifier.

• For example, For example, xx PP((xx) and ) and x Px P((xx)) are are propositionspropositions

Topic #3 – Predicate Logic

Page 18: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 18

Meaning of Quantified Expressions

First, informally:First, informally:

xx PP((xx) means ) means for allfor all x in the u.d., x in the u.d., PP holds. holds.

x Px P((xx) means ) means there there exist exist xx in the u.d. (that in the u.d. (that is, 1 or more) is, 1 or more) such thatsuch that PP((xx) is true.) is true.

Topic #3 – Predicate Logic

Page 19: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 19

Example:

Let the u.d. be Let the u.d. be the parking spaces at UFthe parking spaces at UF..Let Let PP((xx) mean “) mean “xx is full.” is full.”Then the Then the existential quantification of Pexistential quantification of P((xx), ), xx PP((xx), is the proposition saying that), is the proposition saying that– ““Some parking spaces at UF are full.”Some parking spaces at UF are full.”– ““There is a parking space at UF that is full.”There is a parking space at UF that is full.”– ““At least one parking space at UF is full.”At least one parking space at UF is full.”

Topic #3 – Predicate Logic

Page 20: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 20

Example:

Let the u.d. be Let the u.d. be parking spaces at UFparking spaces at UF..Let Let PP((xx) be the ) be the prop. formprop. form “ “xx is occupied” is occupied”Then the Then the universal quantification of Puniversal quantification of P((xx), ), xx PP((xx), is the proposition), is the proposition::– ““All parking spaces at UF are occupied.”All parking spaces at UF are occupied.”– ““For each parking space at UF, that space is full.”For each parking space at UF, that space is full.”

Topic #3 – Predicate Logic

Page 21: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 21

Syntax of predicate logic (for 1- and 2-place predicates)

• Variable: x,y,z,… Constants: a,b,c,…Variable: x,y,z,… Constants: a,b,c,…• 1-place predicates: P,Q,…1-place predicates: P,Q,…• 2-place predicates: R,S,…2-place predicates: R,S,…• Atomic formulas: Atomic formulas:

If If is a 1-pace predicate and is a 1-pace predicate and a variable or a variable or constant then constant then (() is an atomic formula.) is an atomic formula.

If If is a 2-pace predicate and is a 2-pace predicate and and and are are variables or constants then variables or constants then ((,,) is an atomic ) is an atomic formula.formula.

Page 22: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 22

Syntax of predicate logic (for 1- and 2-place predicates)

(Wellformed) Formulas: (Wellformed) Formulas:

• All atomic formulas are formulasAll atomic formulas are formulas• If If and and are formulas then are formulas then ,,

( ( ), (), (), (), ( ) are formulas.) are formulas.• If If is a formula then is a formula then x x and and x x

are are formulas. (Likewise, formulas. (Likewise, y y and and yy ,,and so on.)and so on.)

This could be seen as “overgenerating” This could be seen as “overgenerating” wellformed formulas somewhatwellformed formulas somewhat

Page 23: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 23

Syntax of predicate logic (for 1- and 2-place predicates)

Show that these are wellformed formulas:Show that these are wellformed formulas:

xP(x) xP(x) yQ(x) yQ(x) xxy R(x,y) y R(x,y) xP(b)xP(b)

Page 24: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 24

Syntax of predicate logic (for 1- and 2-place predicates)

xP(x) xP(x) yQ(x) yQ(x) xxy R(x,y) y R(x,y) xP(b)xP(b)

• P(x) is a (atomic) formula, hence P(x) is a (atomic) formula, hence xP(x)xP(x) is a formula is a formula

• Q(x) is a (atomic) formula, hence Q(x) is a (atomic) formula, hence yQ(x)yQ(x) is a formula is a formula

• R(x,y) is a (atomic) formula, hence R(x,y) is a (atomic) formula, hence y R(x,y) is a y R(x,y) is a formula, hence formula, hence xxy R(x,y)y R(x,y) is a formula is a formula

• P(b) is a (atomic) formula, hence P(b) is a (atomic) formula, hence xP(b)xP(b) is a formula is a formula

Page 25: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 25

Syntax of predicate logic (for 1- and 2-place predicates)

• Examples: Examples: xP(x)xP(x) and and yQ(x),yQ(x), xx((y Ry R((x,yx,y)), )), xx((x Rx R((x,yx,y)),)), xP(b)xP(b) etc.etc.

• Lots of Lots of pathologicalpathological cases. For example, cases. For example,– It will follow from the meaning of these It will follow from the meaning of these

formulas thatformulas that xP(b)xP(b) is true iff is true iff P(b) P(b) is trueis true– Rule of thumb: a quantifier that does not bind Rule of thumb: a quantifier that does not bind

any variables can be ignoredany variables can be ignored

Page 26: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 26

Free and Bound Variables

• An expression like An expression like PP((xx) is said to have a ) is said to have a free variablefree variable x x (i.e., (i.e., xx is not “defined”). is not “defined”).

• A quantifier (either A quantifier (either or or ) ) operatesoperates on an on an expression having one or more free expression having one or more free variables, and variables, and bindsbinds one or more of those one or more of those variables, to produce an expression having variables, to produce an expression having one or more one or more boundbound variablesvariables..

Topic #3 – Predicate Logic

Page 27: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 27

Example of Binding

• PP((x,yx,y) has 2 free variables, ) has 2 free variables, xx and and yy..xx PP((xx,,yy) has 1 free variable, and one ) has 1 free variable, and one

bound variable. bound variable. [Which is which?][Which is which?]• An expression with An expression with zerozero free variables is a free variables is a

bona-fide (actual) proposition.bona-fide (actual) proposition.• An expression with An expression with one or moreone or more free free

variables is similar to a predicate: variables is similar to a predicate: e.g.e.g. let let QQ((yy) = ) = xx Adore( Adore(xx,,yy))

Topic #3 – Predicate Logic

Page 28: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 28

Free variables, defined formally

• The free-variable occurrences in an The free-variable occurrences in an AtomAtom are: all are: all the variable occurrences in that Atomthe variable occurrences in that Atom

• The free-variable occurrences in The free-variable occurrences in are: the free- are: the free-variable occurrences in variable occurrences in

• The free-variable occurrences in The free-variable occurrences in (( connective connective )) are: the free-variable occurrences are: the free-variable occurrences in in plus the free-variable occurrences in plus the free-variable occurrences in

• The free-variable occurrences in The free-variable occurrences in xx and and xx are: the free-variable occurrences in are: the free-variable occurrences in except for except for all/any occurrences of all/any occurrences of xx..

Topic #3 – Predicate Logic

Page 29: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 29

• Occurrences of variables that are not free are Occurrences of variables that are not free are boundbound..

• Test your understanding: Which (if any) variables Test your understanding: Which (if any) variables are free in are free in x x PP((xx))x x PP((xx))yQ(x)yQ(x)xP(b) (NB, b is a constant)xP(b) (NB, b is a constant)xx((y Ry R((x,yx,y))))

Page 30: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 30

• Occurrences of variables that are not free Occurrences of variables that are not free are are boundbound..

• Check your understanding: Which (if any) Check your understanding: Which (if any) variables are free in variables are free in x x PP((xx) ) [no free variables][no free variables]x x PP((xx) ) [no free variables][no free variables]yQ(x) yQ(x) [x is free][x is free]xP(b) (NB, b is a constant) xP(b) (NB, b is a constant) [no free var.][no free var.]xx((y Ry R((x,yx,y)) )) [no free variables][no free variables]

Page 31: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 31

A more precise definition of the truth/falsity of quantified formulas

• (Formulation is simplified somewhat because (Formulation is simplified somewhat because we assume that every object in the u.d. D has we assume that every object in the u.d. D has a `name` (i.e., a constant referring to it)).a `name` (i.e., a constant referring to it)).

• First some notation: First some notation: ((xx:=:=aa)) is the result of is the result of substituting all substituting all free occurrences of the free occurrences of the variable variable xx in in by the constant by the constant aa

Topic #3 – Predicate Logic

Page 32: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 32

Exercise

Say whatSay what ((xx:=:=aa) ) is, if is, if ==– P(x)P(x)– R(x,y)R(x,y)– P(b)P(b) x x PP((xx)) yQ(x)yQ(x)

Topic #3 – Predicate Logic

Page 33: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 33

Exercise

Say whatSay what ((xx:=:=aa) ) is, if is, if ==– P(x) ..... P(P(x) ..... P(aa))– R(x,y) .... R(R(x,y) .... R(aa,y),y)– P(b) ..... P(b)P(b) ..... P(b) x x PP((xx) ...... ) ...... x x PP((xx)) yQ(x) ...... yQ(x) ...... yQ(yQ(aa))

Topic #3 – Predicate Logic

Page 34: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 34

A more precise definition of the truth/falsity of quantified formulas

• (Formulation is simplified somewhat because (Formulation is simplified somewhat because we assume that every object in the u.d. has we assume that every object in the u.d. has a `name` (i.e., a constant referring to it)).a `name` (i.e., a constant referring to it)).

• Let Let be a formula. Then be a formula. Then xx is true in D is true in D if if at least oneat least one expression of the form expression of the form ((xx:=:=aa) is true in D, and false otherwise. ) is true in D, and false otherwise. ((aa can be any constant) can be any constant)

Topic #3 – Predicate Logic

Page 35: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 35

A more precise definition

• Let Let be a formula. Then be a formula. Then xx is true in D is true in D if if at least oneat least one expression expression ((xx:=:=aa) is true in ) is true in D, and false otherwise.D, and false otherwise.

• A simple example: A simple example: = P(x)= P(x)

P(x) is a formula, hence P(x) is a formula, hence x Px P((xx) is true in D ) is true in D if at least one expression of the form if at least one expression of the form P(a)P(a) is is true in D, and false otherwise.true in D, and false otherwise.

Topic #3 – Predicate Logic

Page 36: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 36

Similarly for

• Let Let be a formula. Then the proposition be a formula. Then the proposition xx is true in D if every expression of the is true in D if every expression of the form form ((xx:=:=aa) is true in D, and false ) is true in D, and false otherwise.otherwise.

• A simple example: A simple example: = = P(x)P(x)

P(x)P(x) is a formula, hence is a formula, hence x Px P((xx) is true in ) is true in D if every expression D if every expression P(a)P(a) is true in D, and is true in D, and false otherwise.false otherwise.

Topic #3 – Predicate Logic

Page 37: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 37

Complex formulas

Example: Let the u.d. of Example: Let the u.d. of xx and and yy be people. be people.

Let Let LL((xx,,yy)=“)=“x x likes likes yy” ” (a predicate w. 2 f.v.’s)(a predicate w. 2 f.v.’s)

Then Then y Ly L((x,yx,y) = “There is someone whom ) = “There is someone whom xx likes.” likes.” (A predicate w. 1 free variable, (A predicate w. 1 free variable, xx))

Then Then xx ( (y Ly L((x,yx,y)) =)) = “Everyone has someone whom they like.” “Everyone has someone whom they like.”

(a real proposition; no free variables left)(a real proposition; no free variables left)

Topic #3 – Predicate Logic

Page 38: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 38

Consequences of Binding (work out for yourself by checking when each formula is true)

xx x Px P((xx)) - - xx is not a free variable in is not a free variable in x Px P((xx), therefore the ), therefore the xx binding binding isn’t used,isn’t used,as it were.as it were.

• ((xx PP((xx)))) Q( Q(xx)) - The variable - The variable xx is outside is outside of the of the scopescope of the of the x x quantifier, and is quantifier, and is therefore free. Not a complete proposition!therefore free. Not a complete proposition!

• ((xx PP((xx)))) ((x x Q(Q(xx)))) – A complete – A complete proposition, and no superfluous quantifiersproposition, and no superfluous quantifiers

Topic #3 – Predicate Logic

Page 39: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 39

Nested quantifiers

Assume Assume S(x,y)S(x,y) means “ means “xx sees sees yy””

u.d.=all peopleu.d.=all people

What does the following formula mean?What does the following formula mean?

xSxS((x,ax,a))

Page 40: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 40

Nested quantifiers

Assume Assume S(x,y)S(x,y) means “ means “xx sees sees yy”. ”.

u.d.=all peopleu.d.=all people

xSxS((x,ax,a) means ) means “For every “For every xx, , xx sees sees aa””

In other words,In other words,“Everyone sees “Everyone sees aa””

Page 41: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 41

Nested quantifiers

What does the following formula mean?What does the following formula mean?

xx((y Sy S((x,yx,y))))

Page 42: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 42

Nested quantifiers

xx((y Sy S((x,yx,y)) means “)) means “For every For every xx, there exists , there exists a a yy such that such that xx sees sees y”y”

In other words: In other words: “Everyone sees someone”“Everyone sees someone”

Page 43: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 43

Quantifier Exercise

If If RR((xx,,yy)=“)=“xx relies upon relies upon yy,” express the ,” express the following in unambiguous English:following in unambiguous English:

xx((y Ry R((x,yx,y))=))=

yy((xx RR((x,yx,y))=))=

xx((y Ry R((x,yx,y))=))=

yy((x Rx R((x,yx,y))=))=

xx((y Ry R((x,yx,y))=))=

Everyone has someone to rely on.

There’s a poor overburdened soul whom everyone relies upon (including himself)!There’s some needy person who relies upon everybody (including himself).

Everyone has someone who relies upon them.

Everyone relies upon everybody, (including themselves)!

Topic #3 – Predicate Logic

Page 44: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 44

Quantifier Exercise

RR((xx,,yy)=“)=“xx relies upon relies upon yy”. Suppose the u.d. is”. Suppose the u.d. isnot empty. Now not empty. Now consider these formulas:consider these formulas: xx((y Ry R((x,yx,y)))) yy((xx RR((x,yx,y)))) xx((y Ry R((x,yx,y))))Which of them is most informative?Which of them is most informative?Which of them is least informative?Which of them is least informative?

Topic #3 – Predicate Logic

Page 45: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 45

Quantifier Exercise

(Recall: the u.d. is (Recall: the u.d. is not emptynot empty. Empty u.d.’s are . Empty u.d.’s are discussed later.)discussed later.)

1.1. xx((y Ry R((x,yx,y)) Least informative)) Least informative2.2. yy((xx RR((x,yx,y))))3.3. xx((y Ry R((x,yx,y)) Most informative)) Most informativeIf 3 is true then 2 must also be true.If 3 is true then 2 must also be true.If 2 is true then 1 must also be true.If 2 is true then 1 must also be true.

We say: 3 is logically We say: 3 is logically stronger stronger than 2 than 1than 2 than 1

Topic #3 – Predicate Logic

Page 46: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 46

“logically stronger than”

• General: General: is logically stronger than is logically stronger than iff iff – it is not possible for it is not possible for to be true and to be true and false false– it is possible for it is possible for to be true and to be true and false false

• E.g. E.g. = John is older than 30, = John is older than 30, = John is older than 20. = John is older than 20.

• We write ‘iff’ for ‘if and only if’We write ‘iff’ for ‘if and only if’

Page 47: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 47

Natural language is ambiguous!

• ““Everybody likes somebody.”Everybody likes somebody.”– For everybody, there is somebody they like,For everybody, there is somebody they like,

xx yy LikesLikes((xx,,yy))

– or, there is somebody (a popular person) whom or, there is somebody (a popular person) whom everyone likes?everyone likes?yy xx LikesLikes((xx,,yy))

[Probably more likely.]

Topic #3 – Predicate Logic

Page 48: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 48

Interactions between quantifiers and connectives

Let the u.d. be Let the u.d. be parking spaces at UFparking spaces at UF..Let Let PP((xx) be “) be “xx is occupied.” is occupied.”Let Q(Let Q(xx) be “) be “xx is free of charge.” is free of charge.” x x ((QQ((xx) ) PP((xx)))) x x ((QQ((xx) ) PP((xx))) ) x x ((QQ((xx) ) PP((xx)))) x x ((QQ((xx) ) PP((xx))))

Page 49: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 49

I. Construct English paraphrases

Let the u.d. be Let the u.d. be parking spaces at UFparking spaces at UF..Let Let PP((xx) be “) be “xx is occupied.” is occupied.”Let Q(Let Q(xx) be “) be “xx is free of charge.” is free of charge.” x x ((QQ((xx) ) PP((xx)))) x x ((QQ((xx) ) PP((xx))) ) x x ((QQ((xx) ) PP((xx)))) x x ((QQ((xx) ) PP((xx))))

Page 50: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 50

I. Construct English paraphrases

1.1. x x ((QQ((xx) ) PP((xx))) Some places are free of ) Some places are free of charge and occupiedcharge and occupied

2.2. x x ((QQ((xx) ) PP((xx))) All places are free of ) All places are free of charge and occupied charge and occupied

3.3. x x ((QQ((xx) ) PP((xx))) All places that are free ) All places that are free of charge are occupiedof charge are occupied

4.4. x x ((QQ((xx) ) PP((xx))) For some places x, if x ) For some places x, if x is free of charge then x is occupied is free of charge then x is occupied

Page 51: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 51

About the last of these

4. 4. x x ((QQ((xx) ) PP((xx))) “For some x, if x is free of ) “For some x, if x is free of charge then x is occupied”charge then x is occupied”

x x ((QQ((xx) ) PP((xx))) ) is true iff, for some place a, is true iff, for some place a, QQ((aa) ) PP((aa) is true.) is true.

QQ((aa) ) PP((aa)) is true iffis true iff QQ((aa) is false ) is false andand//oror PP((aa) is true ) is true (conditional is only false in one row of table!)(conditional is only false in one row of table!)

“Some places are either (not free of charge) “Some places are either (not free of charge) and/or occupied”and/or occupied”

Page 52: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 52

About the last of these

4.4. x x ((QQ((xx) ) PP((xx))) ) When confused by a When confused by a conditional: re-write it using conditional: re-write it using negationnegation and and disjunctiondisjunction::

x x ((QQ((xx) ) PP((xx))) ) (p. 67)(p. 67)

x x QQ((xx)) x Px P((xx)) “Some places are “Some places are not free of charge or some places are not free of charge or some places are occupied” occupied”

Page 53: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 53

• Combinations to remember:Combinations to remember:

1.1. x x ((QQ((xx) ) PP((xx))))

2.2. x x ((QQ((xx) ) PP((xx))))

Page 54: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 54

II. Construct a model where 1 and 4 are true, while 2 and 3 are false

Let the u.d. be Let the u.d. be parking spaces at UFparking spaces at UF..Let Let PP((xx) be “) be “xx is occupied.” is occupied.”Let Q(Let Q(xx) be “) be “xx is free of charge.” is free of charge.” x x ((QQ((xx) ) PP((xx)))) x x ((QQ((xx) ) PP((xx))) ) x x ((QQ((xx) ) PP((xx)))) x x ((QQ((xx) ) PP((xx))))

Page 55: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 55

II. Construct a model where 1 and 4 are true, while 2 and 3 are false

1.1. x x ((QQ((xx) ) PP((xx))) (true for place a below)) (true for place a below)2.2. x x ((QQ((xx) ) PP((xx))) (false for places b below)) (false for places b below)3.3. x x ((QQ((xx) ) PP((xx))) (false for place b below)) (false for place b below)4.4. x x ((QQ((xx) ) PP((xx))) (true for place a below)) (true for place a below)One solutionOne solution: a model with exactly two objects in it. : a model with exactly two objects in it.

One object has the property Q and the property One object has the property Q and the property P; the other object has the property Q but not the P; the other object has the property Q but not the property P. In a diagram: property P. In a diagram:

a: Q P b: Q not-Pa: Q P b: Q not-P

Page 56: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 56

III. Construct a model where 1 and 3 and 4 are true, but 2 is false

1.1. x x ((QQ((xx) ) PP((xx))) ) 2.2. x x ((QQ((xx) ) PP((xx))) ) 3.3. x x ((QQ((xx) ) PP((xx))) ) 4.4. x x ((QQ((xx) ) PP((xx))))

Here is such a model (using a diagram). It has just Here is such a model (using a diagram). It has just two objects in its u.d., called a and b:two objects in its u.d., called a and b:

a: Q P b: not-Q Pa: Q P b: not-Q P

Page 57: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 57

Quantifier Equivalence Laws

• Expanding quantifiers: If u.d.=a,b,c,… Expanding quantifiers: If u.d.=a,b,c,… x Px P((xx) ) PP(a) (a) PP(b) (b) PP(c) (c) … … x Px P((xx) ) PP(a) (a) PP(b) (b) PP(c) (c) … …

• From those, we can “prove” the laws:From those, we can “prove” the laws:x Px P((xx) ) x x PP((xx))x Px P((xx) ) x x PP((xx))

• Which Which propositionalpropositional equivalence laws can equivalence laws can be used to prove this? be used to prove this?

Topic #3 – Predicate Logic

Page 58: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 58

Remember

• In propositional logic, we can In propositional logic, we can strictly strictly speakingspeaking only build formulas of finite size. only build formulas of finite size.

• E.g., we can write E.g., we can write PP(a) (a) PP(b) (b) PP(a) (a) PP(b) (b) PP(c) (c) PP(a) (a) PP(b) (b) PP(c) (c) PP(d) , etc.(d) , etc.

• But this way, we could never say that all But this way, we could never say that all natural numbers have Pnatural numbers have P

Page 59: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 59

Formulas of infinite length?

• In predicate logic, you can say this easily:In predicate logic, you can say this easily: xPxP((xx))

• It’s sometimes useful to pretend that It’s sometimes useful to pretend that propositional logic allows infinitely long propositional logic allows infinitely long formulas, but in the “official” version this is formulas, but in the “official” version this is not possible.not possible.

Page 60: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 60

More Equivalence Laws

x x y Py P((xx,,yy) ) y y x Px P((xx,,yy))x x y Py P((xx,,yy) ) y y x Px P((xx,,yy))

x x ((PP((xx) ) QQ((xx)))) ((x Px P((xx)))) ((x Qx Q((xx))))x x ((PP((xx) ) QQ((xx)))) ((x Px P((xx)))) ((x Qx Q((xx))))

Topic #3 – Predicate Logic

Page 61: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 61

More Equivalence Laws

x x y Py P((xx,,yy) ) y y x Px P((xx,,yy))x x y Py P((xx,,yy) ) y y x Px P((xx,,yy))

x x ((PP((xx) ) QQ((xx)))) ((x Px P((xx)))) ((x Qx Q((xx))))x x ((PP((xx) ) QQ((xx)))) ((x Px P((xx)))) ((x Qx Q((xx))))

• Let’s prove the last of these equivalences Let’s prove the last of these equivalences using the definition of the truth of a formula using the definition of the truth of a formula of the form of the form x x φφ

Topic #3 – Predicate Logic

Page 62: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 62

A Pred. Log. equivalence proven

x x ((PP((xx) ) QQ((xx)))) ((x Px P((xx)))) ((x Qx Q((xx))))Proof: Proof: Suppose x x ((PP((xx) ) QQ((xx)))) is true. So, there is a is true. So, there is a constantconstant a a such that ( such that (P(x) P(x) QQ((xx)) )) (x:=a)(x:=a) is true. is true. So, for that So, for that aa, the formula , the formula PP(a) Q(a) is true. is true. One One possibilitypossibility is that is that P(a)P(a) is true. In this case, is true. In this case, P(x)P(x)(x:=a)(x:=a) is true. So, is true. So, x Px P((xx)) is true, so (x Px P((xx)) )) ((x Qx Q((xx)) is true. )) is true. The other possibilityThe other possibility is that is that Q(a)Q(a) is true. In this case, is true. In this case, Q(x)(x:=a)Q(x)(x:=a) is true. is true. So, So, x Qx Q((xx)) is true, so (x Px P((xx)) )) ( (x Qx Q((xx))))is true. is true.

Topic #3 – Predicate Logic

Page 63: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 63

A Pred. Log. equivalence proven

x x ((PP((xx) ) QQ((xx)))) ((x Px P((xx)))) ((x Qx Q((xx))))Proof: Proof: Suppose ((x Px P((xx)))) ((x Qx Q((xx)))) is true. is true. One One possibilitypossibility is that is that x Px P((xx) is true. This would mean ) is true. This would mean that there is an a such that that there is an a such that P(x) (x:=a)P(x) (x:=a) is true. So, is true. So, for that constant for that constant aa, , PP(a) is true.Therefore, is true.Therefore, P(a) P(a) Q(a) Q(a) would also be true. Hence, would also be true. Hence, (P(x) (P(x) Q(x))(x:=a) Q(x))(x:=a) would be true. Hence, would be true. Hence, x x ((PP((xx) ) QQ((xx)))) would be true. would be true. The other The other possibilitypossibility is that is that x Qx Q((xx). From this, ). From this, x x ((PP((xx) ) QQ((xx)))) is proven in the same way is proven in the same way QEDQED

Topic #3 – Predicate Logic

Page 64: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 64

More Equivalence Laws

x x y Py P((xx,,yy) ) y y x Px P((xx,,yy))x x y Py P((xx,,yy) ) y y x Px P((xx,,yy))

x x ((PP((xx) ) QQ((xx)))) ((x Px P((xx)))) ((x Qx Q((xx))))x x ((PP((xx) ) QQ((xx)))) ((x Px P((xx)))) ((x Qx Q((xx))))

• How about this one?How about this one?

x x ((PP((xx) ) QQ((xx)))) ((x Px P((xx)))) ((x Qx Q((xx)))?)?

Topic #3 – Predicate Logic

Page 65: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 65

More Equivalence Laws

• How about this one?How about this one?

x x ((PP((xx) ) QQ((xx)))) ((x Px P((xx)))) ((x Qx Q((xx))) ?) ?• This equivalence statement is false.This equivalence statement is false.

Counterexample Counterexample (i.e. model making this false):(i.e. model making this false):

• P(x): x’s birthday is on 30 AprilP(x): x’s birthday is on 30 AprilQ(x): x’s birthday is on 20 December Q(x): x’s birthday is on 20 December

Topic #3 – Predicate Logic

Page 66: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 66

Cases to think carefully about

Let’s discuss some specific casesLet’s discuss some specific cases

These might seem unusual, but it’s These might seem unusual, but it’s important not to loose your way when important not to loose your way when they occurthey occur

1.1. Quantifiers that don’t bind any variablesQuantifiers that don’t bind any variables

2.2. Quantification in an empty u.d.Quantification in an empty u.d.

3.3. x x ((QQ((xx) ) PP((xx))) ) whenwhen yQyQ((yy))

Page 67: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 67

1. Quantifiers that do not bind: xP(b)

• Recall definition:Recall definition: Let Let be a formula. be a formula. Then Then xx is true in D if every expression is true in D if every expression (x:=(x:=aa) is true in D, and false otherwise.) is true in D, and false otherwise.

xP(b) xP(b) is true in D if every expression of is true in D if every expression of the form the form P(b)P(b)(x:=(x:=aa) is true in D, and false ) is true in D, and false otherwise.otherwise.

• What is the set of all the What is the set of all the expression of the expression of the form form P(b)P(b)(x:=(x:=aa)?)?

Page 68: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 68

Consider xP(b)

• What is the set of all the What is the set of all the expression of the expression of the form form P(b)P(b)(x:=(x:=aa)?)?

• That’s the singleton set {P(b)} ! So, That’s the singleton set {P(b)} ! So,

xP(b) xP(b) is true in D if P(b) is true, is true in D if P(b) is true, and false otherwise.and false otherwise.

• So, So, xP(b) xP(b) means just P(b) means just P(b)

Page 69: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 69

2. Empty u.d.: We defined

• Let Let be a formula. Then the proposition be a formula. Then the proposition xx is true in D if is true in D if every expression every expression ((xx:=:=aa)) is true in D, and false otherwise.is true in D, and false otherwise.

This is read as follows:This is read as follows:

• Let Let be a formula. Then the proposition be a formula. Then the proposition xx is false in D if at least one expression is false in D if at least one expression ((xx:=:=aa) is false in D, and true otherwise.) is false in D, and true otherwise.

Page 70: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 70

could have been defined differently. For example,

• Let Let be a formula. Then the proposition be a formula. Then the proposition xx is true in D if is true in D if D is nonempty andD is nonempty and every every expression expression (x:=(x:=aa) is true in D, and false ) is true in D, and false otherwise.otherwise.– Under this definition, Under this definition, xx PP((xx) would have been ) would have been

false whenever D is empty (e.g., when there are false whenever D is empty (e.g., when there are no parking spaces at U.F., and P = “occupied”)no parking spaces at U.F., and P = “occupied”)

– But that’s But that’s not how it’s donenot how it’s done! !

Page 71: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 71

Suppose D is empty

Suppose the u.d. is empty. ConsiderSuppose the u.d. is empty. Consider

xx PP((xx) (e.g., ) (e.g., PP((xx) means “) means “xx is occupied.”) is occupied.”)

This counts as true. (Sometimes called This counts as true. (Sometimes called “vacuously true”)“vacuously true”)

For the same reason,For the same reason,

xx PP((xx) is also true) is also true

Page 72: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 72

Consequences of the standard position

Two logical equivalences in Predicate Logic:Two logical equivalences in Predicate Logic:x Px P((xx) ) x x PP((xx) ) (“no counterexample against P”)(“no counterexample against P”)

x Px P((xx) ) x x PP((xx))

So, one of the two quantifiers suffices So, one of the two quantifiers suffices (cf., functional completeness of a set of (cf., functional completeness of a set of connectives in propositional logic)connectives in propositional logic)

We’ll return to these equivalences later.We’ll return to these equivalences later.

Page 73: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 73

3. x (Q(x) P(x)) when yQ(y)

Page 74: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 74

When many implications are combined

• ConsiderConsider the formula the formula rr = = x x ((QQ((xx) ) PP((xx)))) with respect to a with respect to a nonempty u.d.nonempty u.d.

• Suppose Suppose yQyQ((yy))

• (For example, Q might mean “being more (For example, Q might mean “being more than 4 meters tall”)than 4 meters tall”)

• Can you work out whether Can you work out whether rr is true? is true?

Page 75: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 75

When many implications are combined

• ConsiderConsider x x ((QQ((xx) ) PP((xx))) ) in a nonempty u.d.in a nonempty u.d.• Suppose, however, Suppose, however, yQyQ((yy))• Then Then QQ((aa) ) PP((aa)) is true for every is true for every a a

(since Q(a) is false for every a) (since Q(a) is false for every a) • Consequently Consequently x x ((QQ((xx) ) PP((xx))) is true) is true• Once again, we sometimes say: it is Once again, we sometimes say: it is vacuouslyvacuously

true (because the antecedent is always false, so true (because the antecedent is always false, so you can never use the formula to conclude that you can never use the formula to conclude that PP holds of something).holds of something).

Page 76: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 76

Vacuous truth

• Example 1: Think of a tax form: Example 1: Think of a tax form: “Have you sent “Have you sent us details about all your children?”us details about all your children?” No children No children You’ve complied (without doing anything) You’ve complied (without doing anything)

• Example 2: Think of our definition of Example 2: Think of our definition of (x:=(x:=aa)) as as “the result of substituting “the result of substituting allall free occurrences of x in free occurrences of x in by a”by a”No occurrences No occurrences don’t do anything (after don’t do anything (after which it’s true that all occurrences have been which it’s true that all occurrences have been substituted)substituted)

Page 77: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 77

Some consequences of these definitions

• Sometimes, predicate logic is taught very Sometimes, predicate logic is taught very informallyinformally

• This makes it easy to understand simple formulasThis makes it easy to understand simple formulas• But each more complex case has to be explained But each more complex case has to be explained

separately, as if it was an exceptionseparately, as if it was an exception• By defining things properly once, complex By defining things properly once, complex

formulas fall out as special casesformulas fall out as special cases• One example: quantifier nestingOne example: quantifier nesting

Page 78: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 78

Back to Quantifier Exercise

RR((xx,,yy)=“)=“xx relies upon relies upon yy”. Suppose the u.d. is”. Suppose the u.d. isemptyempty. Now . Now consider these formulas:consider these formulas: xx((y Ry R((x,yx,y)))) yy((xx RR((x,yx,y)))) xx((y Ry R((x,yx,y))))Which of them is most informative?Which of them is most informative?Which of them is least informative?Which of them is least informative?

Topic #3 – Predicate Logic

Page 79: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 79

Back to our Quantifier Exercise

Now that the u.d. isNow that the u.d. is empty,empty,1.1. xx((y Ry R((x,yx,y)) is uninformative)) is uninformative2.2. yy((xx RR((x,yx,y)) is false!)) is false!3.3. xx((y Ry R((x,yx,y)) is uninformative)) is uninformativex(P(x))x(P(x)) is true if P is true if P(a)(a) is true for all is true for all aa.. If no If no xx exist then this makes exist then this makes x(P(x))x(P(x))

(“vacuously”) true(“vacuously”) truex(P(x))x(P(x)) is true if is true if P(a)P(a) is true for some is true for some aa.. If no If no xx exist then this makes exist then this makes x(P(x))x(P(x)) false. false.

Topic #3 – Predicate Logic

Page 80: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 80

Back to models: Look at the old formula 3 again

3. 3. x x ((QQ((xx) ) PP((xx))) Consider this model:) Consider this model:

a: a: Q P b: Q P b: QQPP

c:c:Q P d: Q P d: QQP P

Is the proposition true or false in the model?Is the proposition true or false in the model?

Page 81: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 81

Look at formula number 3 again

3. 3. x x ((QQ((xx) ) PP((xx))) is true in this model:) is true in this model:

a: a: Q P b: Q P b: QQPP

c:c:Q P d: Q P d: QQP P

(3) Is true iff each of these is true:(3) Is true iff each of these is true: x x ((QQ((aa) ) PP((aa)))) x x ((QQ(b) (b) PP(b)(b))) x x ((QQ(c) (c) PP(c)(c))) x x ((QQ(d) (d) PP(d)(d)))

Page 82: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 82

Look at formula number 3 again

3. 3. x x ((QQ((xx) ) PP((xx))) is true in this model:) is true in this model:

a: a: Q P b: Q P b: QQPP

c:c:Q P d: Q P d: QQP P

(3) Is true because each of these is true:(3) Is true because each of these is true: QQ((aa) ) PP((aa)) … F T, hence … F T, hence TT QQ(b) (b) PP(b) (b) … F F, hence … F F, hence TT QQ(c) (c) PP(c) (c) … F T, hence … F T, hence TT QQ(d) (d) PP(d) (d) … F F, hence … F F, hence TT

Page 83: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 83

Predicate Logic essentials

• Predicates of different arity (one-place, Predicates of different arity (one-place, two-place, etc.)two-place, etc.)

• Quantifiers: [Quantifiers: [xx PP((xx)] :)] :≡≡ “For all “For all xx, , PP((xx).” ).” [[x Px P((xx)] :)] :≡ ≡ “There is/are “There is/are xx such that such that PP((xx).”).”

• Universes of discourse, bound & free vars.Universes of discourse, bound & free vars.

• The rest followsThe rest follows: empty domains, quantified : empty domains, quantified implications, quantifier nestingimplications, quantifier nesting

Page 84: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 84

Some common shorthands

• Sometimes the universe of discourse is Sometimes the universe of discourse is restricted within the quantification, restricted within the quantification, e.g.e.g.,, x>x>0 0 PP((xx) is shorthand for) is shorthand for

“For all “For all xx that are greater than zero, that are greater than zero, PP((xx).”).”

• How would you write this in formal How would you write this in formal notation?notation?

Topic #3 – Predicate Logic

Page 85: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 85

Some common shorthands

• Sometimes the universe of discourse is Sometimes the universe of discourse is restricted within the quantification, restricted within the quantification, e.g.e.g.,, x>x>0 0 PP((xx) is shorthand for) is shorthand for

“For all “For all xx that are greater than zero, that are greater than zero, PP((xx).”).”

==x x ((x>x>0 0 PP((xx))))

Topic #3 – Predicate Logic

Page 86: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 86

Some common shorthands

• Sometimes the universe of discourse is Sometimes the universe of discourse is restricted within the quantification, restricted within the quantification, e.g.e.g.,, x>x>0 0 PP((xx) is shorthand for) is shorthand for

“For all “For all xx that are greater than zero, that are greater than zero, PP((xx).”).”

==x x ((x>x>0 0 PP((xx)))) x>x>0 0 PP((xx) is shorthand for) is shorthand for

“There is an “There is an x x greater than zero such that greater than zero such that PP((xx).”).”

==x x ((x>x>0 0 PP((xx))))

Topic #3 – Predicate Logic

Page 87: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 87

Some common shorthands

• Consecutive quantifiers of the same type Consecutive quantifiers of the same type can be combined:can be combined: xyz Pxyz P((xx,,yy,,zz) ) defdef x x y y z Pz P((xx,,yy,,zz) )

xyz Pxyz P((xx,,yy,,zz) ) defdef x x y y z Pz P((xx,,yy,,zz) )

Topic #3 – Predicate Logic

Page 88: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 88

Theorems about logic

• WeWe are studying logical languages/calculi to are studying logical languages/calculi to allow you to use them (better)allow you to use them (better)

• LogiciansLogicians study logical languages/calculi to study logical languages/calculi to understand their limitationsunderstand their limitations

• Meta-theorems can, e.g., say things like “… Meta-theorems can, e.g., say things like “… cannot be expressed in predicate logic”cannot be expressed in predicate logic”

Page 89: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 89

Theorems about logic

• About propositional logic, we asked “What types About propositional logic, we asked “What types of things can we express?” How many connectives of things can we express?” How many connectives do we need?do we need?

• About predicate logic, logicians ask similar About predicate logic, logicians ask similar questions. For example, are these two quantifiers questions. For example, are these two quantifiers enough to be able to ‘say everything’?enough to be able to ‘say everything’?

• This is a question about the This is a question about the expressive powerexpressive power of of predicate logicpredicate logic

Page 90: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 90

Example: one

• As per their name, quantifiers can be used As per their name, quantifiers can be used to express that a predicate is true of a given to express that a predicate is true of a given quantityquantity (number) of objects. (number) of objects.

• Example:Example: Can predicate logic say “there Can predicate logic say “there exists at most one object with property P”? exists at most one object with property P”?

Page 91: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 91

Example: at most one

• Example:Example: Can predicate logic say “there Can predicate logic say “there exists at most one object with property P”? exists at most one object with property P”?

Yes (provided we have equality):Yes (provided we have equality):

xxy y ((((PP((x)x) PP((yy)) )) x= yx= y))

Page 92: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 92

Example: one

• Can predicate logic say “there exists exactly Can predicate logic say “there exists exactly one object with property P”? one object with property P”?

Page 93: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 93

Example: one

• Can predicate logic say “there exists exactly Can predicate logic say “there exists exactly one object with property P”? one object with property P”? xPxP((xx) ) xxyy((((PP((x)x) PP((yy))))x= y)x= y)

• ““There exist x such that P(x)” There exist x such that P(x)” andand“There exists at most one x such that P(x)”“There exists at most one x such that P(x)”

• Abbreviation: Abbreviation: !!xx PP((xx))(“there exists exactly one x such that P(x)”)(“there exists exactly one x such that P(x)”)

Page 94: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 94

Example: one

• Another way to write this:Another way to write this:

x x ((PP((xx) ) y y ((PP((yy) ) y y x x))))“There is an “There is an xx such that such that PP((xx), such that there ), such that there is no is no yy such that P( such that P(yy) and ) and yy xx.”.”

x x binds binds xx throughout the conjunction: throughout the conjunction:

xx ((PP((xx) ) y y ((PP((yy) ) y y xx))))

Page 95: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 95

At least two

• Can predicate logic say “there exist at least Can predicate logic say “there exist at least two objects with property P”? two objects with property P”?

Page 96: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 96

At least two

• Can predicate logic say “there exist at least Can predicate logic say “there exist at least two objects with property P”? two objects with property P”?

• Yes:Yes:xx y y ((((PP((xx) ) PP((yy)) )) xx y y))

• Incorrect would beIncorrect would be xxPP((xx) ) y(Py(P((yy) ) x x y), y),(where (where xx occurs free, and which occurs free, and whichtherefore does not express a proposition)therefore does not express a proposition)

Page 97: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 97

Exactly two

• Can predicate logic say “there exist exactly Can predicate logic say “there exist exactly two objects with property P”?two objects with property P”?

Page 98: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 98

Exactly wo

• Can predicate logic say “there exist exactly Can predicate logic say “there exist exactly two objects with property P”?two objects with property P”?

• Yes:Yes:

• x x y y ((PP((xx) ) PP((yy) ) xx y y z z ((PP((zz) ) ( (z= x z= x z= y z= y)) ))))

Page 99: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 99

What’s wrong with

x x y y ((PP((xx) ) PP((yy) ) x x y) y) z z ((PP((zz) ) ( (z= x z= x z= y z= y ))))as a formalisation of ‘exactly two’?as a formalisation of ‘exactly two’?

Page 100: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 100

What’s wrong with

x x y y ((PP((xx) ) PP((yy) ) x x y) y) z z ((PP((zz) ) ( (z= x z= x z= y z= y ))))as a formalisation of ‘exactly two’?as a formalisation of ‘exactly two’?

• This is a conjunction of two separate This is a conjunction of two separate propositions. As a result, propositions. As a result, xx and and yy are not are not boundbound, so this is not even a proposition, so this is not even a proposition

Page 101: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 101

infinitely many

• Can predicate logic say “there exist Can predicate logic say “there exist infinitely manyinfinitely many objects with property P”? objects with property P”?

• No! [This follows from the so-called No! [This follows from the so-called Compactness Theorem: Compactness Theorem: “An infinite set S of “An infinite set S of formulas has a model iff every finite subset formulas has a model iff every finite subset of S has a model”of S has a model”]]

• How aboutHow about finitely manyfinitely many??

Page 102: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 102

finitely many

• How aboutHow about finitely manyfinitely many??• Suppose there existed a formula Suppose there existed a formula = =

“there exist only finitely many x such that “there exist only finitely many x such that so and so”so and so”

• Then Then = = “there exist infinitely many x “there exist infinitely many x such that so and so”such that so and so”

• We know that such a formula does not existWe know that such a formula does not exist• So, also So, also does not exist does not exist

Page 103: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 103

((Of course if we allow infinite conjunctions Of course if we allow infinite conjunctions then all this then all this cancan be expressed: be expressed:

!!xx PP((xx) ) 22!!xx PP((xx) ) 33!!xx PP((xx) ) … … ))

Page 104: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 104

• Can predicate logic say “Can predicate logic say “mostmost objects have objects have property P”? property P”?

• No! [This follows from the Compactness No! [This follows from the Compactness Theorem as well. Again, this is unless we Theorem as well. Again, this is unless we allow infinitely long disjunctions.]allow infinitely long disjunctions.]

• Can predicate logic say “Can predicate logic say “manymany objects have objects have property P”? property P”?

• No, only precisely defined quantitiesNo, only precisely defined quantities

Page 105: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 105

Decidability

• We’ve shown you two ways of checking We’ve shown you two ways of checking propositional-logic equivalencies:propositional-logic equivalencies:

1.1. Checking truth tablesChecking truth tables2.2. Using equivalence lawsUsing equivalence laws

• You’ve seen how (1) can be done You’ve seen how (1) can be done algorithmically.algorithmically.

• This shows that checking propositional This shows that checking propositional logic equivalence is logic equivalence is decidabledecidable

Page 106: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 106

Decidability

• Checking proplog equivalence is Checking proplog equivalence is decidabledecidable• Checking predlog equivalence is Checking predlog equivalence is not decidablenot decidable

Therefore, theorem proving will always remain Therefore, theorem proving will always remain an art (for both computers and humans)an art (for both computers and humans)

• Some “fragments” of predlog are decidable. One Some “fragments” of predlog are decidable. One application: PROLOGapplication: PROLOG

Page 107: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 107

Bonus Topic: Logic Programming

• Some programming languages are based entirely Some programming languages are based entirely on (a part of) predicate logicon (a part of) predicate logic

• The most famous one is called The most famous one is called PrologProlog..• A Prolog program is a set of propositions (“facts”) A Prolog program is a set of propositions (“facts”)

and (“rules”) in predicate logic.and (“rules”) in predicate logic.• The input to the program is a “query” proposition.The input to the program is a “query” proposition.

– Want to know if it is true or false.Want to know if it is true or false.• The Prolog interpreter does some automated The Prolog interpreter does some automated

deduction to determine whether the query follows deduction to determine whether the query follows from the facts.from the facts.

Page 108: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 108

Facts in Prolog

• A fact in Prolog represents a simple, non-A fact in Prolog represents a simple, non-compound proposition in predicate logic.compound proposition in predicate logic.– E.g., E.g., likes(john,mary)likes(john,mary)– Lowercase symbols are used for constants and Lowercase symbols are used for constants and

predicates, uppercase is used for variables.predicates, uppercase is used for variables.

Page 109: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 109

Rules in Prolog

• A A rulerule in Prolog represents a universally in Prolog represents a universally quantified proposition of the general form quantified proposition of the general form

xxyy ( (PP((xx,,yy)→)→QQ((xx)),)),where where xx and and yy are variables, are variables, P P a possibly a possibly compound predicate, and compound predicate, and QQ an atomic proposition. an atomic proposition.

• In Prolog: In Prolog: q(X) :- p(X,Y).q(X) :- p(X,Y).i.e.i.e., the , the ,, quantifiers are implicit. quantifiers are implicit.

• Example: Example: likable(X) :- likes(Y,X).likable(X) :- likes(Y,X).

Page 110: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 110

Rules in Prolog

• Note that Note that xxyy ( (PP((xx,,yy)→)→QQ((xx))))is equivalent to is equivalent to xx((((yy PP((xx,,yy)→)→QQ((xx))))

• In other wordsIn other words, , Q(x)Q(x) holds if you can find a holds if you can find a yy such that such that P(x,y)P(x,y)

Page 111: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 111

Conjunction and Disjunction

• Logical conjunction is encoded using Logical conjunction is encoded using multiple comma-separated terms in a rule.multiple comma-separated terms in a rule.

• Logical disjunction is encoded using Logical disjunction is encoded using multiple rules.multiple rules.

• E.g.E.g., , xx (( ((PP((xx))QQ((xx))))RR((xx))→))→SS((xx)) can be rendered in Prolog as:can be rendered in Prolog as:s(X) :- p(X),q(X)s(X) :- p(X),q(X)s(X) :- r(X)s(X) :- r(X)

Page 112: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 112

Deduction in Prolog

• When a query is input to the Prolog When a query is input to the Prolog interpreter, interpreter, – it searches its database to determine if the query it searches its database to determine if the query

can be proven true from the available facts.can be proven true from the available facts.– if so, it returns “yes”, if not, “no” if so, it returns “yes”, if not, “no” (!)(!)– If the query contains any variables, all values If the query contains any variables, all values

that make the query true are printed.that make the query true are printed.

Page 113: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 113

Simple Prolog Example

• An example input program:An example input program:likes(john,mary).likes(john,mary).

likes(mary,fred).likes(mary,fred).

likes(fred,mary).likes(fred,mary).

likable(X) :- likes(Y,X).likable(X) :- likes(Y,X).

• An example query: An example query: ? likable(Z)? likable(Z)returns: ...returns: ...

Page 114: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 114

Simple Prolog Example

• An example input program:An example input program:likes(john,mary).likes(john,mary).

likes(mary,fred).likes(mary,fred).

likes(fred,mary).likes(fred,mary).

likable(X) :- likes(Y,X).likable(X) :- likes(Y,X).

• An example query: An example query: ? likable(Z)? likable(Z)returns: returns: mary fredmary fred

Page 115: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 115

Relation between PROLOG and Predicate Logic

• PROLOG cannot use all predicate logic PROLOG cannot use all predicate logic formulas. (It covers a decidable “fragment” formulas. (It covers a decidable “fragment” of predicate logic.)of predicate logic.)

• It uses ‘negation as failure’It uses ‘negation as failure’• Based on these limitations, PROLOG-based Based on these limitations, PROLOG-based

deduction is decidable.deduction is decidable.• PROLOG is more than just logic PROLOG is more than just logic

(I/O, cut!), but logic is its hard core.(I/O, cut!), but logic is its hard core.

Page 116: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 116

Deduction Example (as appetiser for the next lecture)

• Premises:Premises:1.1. xx HH((xx) ) MM((xx) ) (e.g. “Humans are mortal”)(e.g. “Humans are mortal”)

2.2. xx GG((xx) ) MM((xx) ) (“Gods are immortal”).(“Gods are immortal”).

1.1. Suppose you need to prove the Suppose you need to prove the Conclusion Conclusion x x ((HH((xx) ) GG((xx))))

(“No human is a god.”)(“No human is a god.”)

Topic #3 – Predicate Logic

Page 117: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 117

A ‘semantic’ proof in informal style

x (H(x) x (H(x) M(x)) (“Humans are mortal”) and M(x)) (“Humans are mortal”) andx (G(x) x (G(x) M(x)) (“Gods are immortal”).M(x)) (“Gods are immortal”).Suppose Suppose x (H(x) x (H(x) G(x)). G(x)). For example, For example,H(a) H(a) G(a). Then G(a). ThenBy the first premisse, we have M(a).By the first premisse, we have M(a).By the second premisse, we have By the second premisse, we have M(a).M(a).Contradiction! Therefore, it follows thatContradiction! Therefore, it follows thatx (H(x) x (H(x) G(x)) G(x)) (“No human is a god.”) (“No human is a god.”)

Topic #3 – Predicate Logic

Page 118: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 118

Alternative proof, using equivalences

xx ( (HH((xx))MM((xx)) )) andand xx ( (GG((xx))MM((xx)).)).xx ( (MM((xx))HH((xx)) )) [Contrapositive.][Contrapositive.]xx ([ ([GG((xx))MM((xx)] )] [ [MM((xx))HH((xx)]))])xx ( (GG((xx))HH((xx)) )) [Transitivity of [Transitivity of .].]xx ( (GG((xx) ) HH((xx)) )) [Definition of [Definition of .].]xx ((GG((xx) ) HH((xx)) )) [DeMorgan’s law.][DeMorgan’s law.]xx ( (GG((xx) ) HH((xx)) )) [An equivalence law.][An equivalence law.]

Topic #3 – Predicate Logic

Page 119: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 119

Bonus: Number Theory Examples

Let u.d. = the Let u.d. = the natural numbersnatural numbers 0, 1, 2, … 0, 1, 2, …

What do the following mean?What do the following mean?x x ((EE((xx) ) ( (y x=y x=22yy))))

x x ((PP((xx) )

((xx>1 >1 yz xyz x==yzyz yy1 1 zz11))))

Topic #3 – Predicate Logic

Page 120: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 120

Bonus: more Number Theory Examples

• Let u.d. = the Let u.d. = the natural numbersnatural numbers 0, 1, 2, … 0, 1, 2, … • ““A number A number xx has the property E if and only if it is has the property E if and only if it is

equal to 2 times some other number.” equal to 2 times some other number.” (even!)(even!)

x x ((EE((xx) ) ( (y x=y x=22yy))))• ““A number has A number has PP, iff it’s greater than 1 and it isn’t , iff it’s greater than 1 and it isn’t

the product of any non-unity numbers.” the product of any non-unity numbers.” (prime!)(prime!)

x x ((PP((xx) ) ((xx>1 >1 yz xyz x==yzyz yy1 1 zz11))))

Topic #3 – Predicate Logic

Page 121: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 121

Goldbach’s Conjecture (unproven)

Using Using EE((xx) and ) and PP((xx) from previous slide,) from previous slide,

x(x( [ [xx>2 >2 EE((xx)] )] → →

pp q Pq P((pp) ) PP((qq) ) pp++qq = = x)x)..

Topic #3 – Predicate Logic

Page 122: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 122

Goldbach’s Conjecture (unproven)

Using Using EE((xx) and ) and PP((xx) from previous slide,) from previous slide,

x(x( [ [xx>2 >2 EE((xx)] )] → →

pp q Pq P((pp) ) PP((qq) ) pp++qq = = x)x)..

““Every even number greater than 2 Every even number greater than 2 is the sum of two primes.”is the sum of two primes.”

Topic #3 – Predicate Logic

Page 123: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 123

Game Theoretic Semantics

• Thinking in terms of a competitive game can help you tell Thinking in terms of a competitive game can help you tell whether a proposition with nested quantifiers is true.whether a proposition with nested quantifiers is true.

• The game has two players, The game has two players, both with the same knowledgeboth with the same knowledge::– Verifier: Wants to demonstrate that the proposition is true.Verifier: Wants to demonstrate that the proposition is true.– Falsifier: Wants to demonstrate that the proposition is false.Falsifier: Wants to demonstrate that the proposition is false.

• The Rules of the Game “Verify or Falsify”:The Rules of the Game “Verify or Falsify”:– Read the quantifiers from Read the quantifiers from left to rightleft to right, picking values of variables., picking values of variables.– When you see “When you see “”, the falsifier gets to select the value.”, the falsifier gets to select the value.– When you see “When you see “”, the verifier gets to select the value.”, the verifier gets to select the value.

• If the verifier If the verifier can always wincan always win, then the proposition is true., then the proposition is true.• Otherwise it is false.Otherwise it is false.

Topic #3 – Predicate Logic

Page 124: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 124

Let’s Play, “Verify or Falsify!”

Let B(x,y) :≡ “x’s birthday is followed within 14 days by y’s birthday.”

Suppose I claim that among you: x y B(x,y)

Your turn, as falsifier: You pick any x → (so-and-so)

y B(so-and-so,y)My turn, as verifier: I pick any y → (such-and-such)

B(so-and-so,such-and-such)

Topic #3 – Predicate Logic

Page 125: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 125

Summing up ‘strict’ Predicate Logic without extensions and simplified notations

Syntax definitionSyntax definition• Variable: x,y,z,… Constants: a,b,c,…Variable: x,y,z,… Constants: a,b,c,…• 1-place predicates: P,Q,…1-place predicates: P,Q,…• 2-place predicates: R,S,…2-place predicates: R,S,…Atomic formulas: Atomic formulas:

If If is a 1-pace predicate and is a 1-pace predicate and a variable or a variable or constant then constant then (() is an atomic formula.) is an atomic formula.

If If is a 2-pace predicate and is a 2-pace predicate and and and are are variables or constants then variables or constants then ((,,) is an atomic ) is an atomic formula. formula. [and so on for 3-place, etc.][and so on for 3-place, etc.]

Topic #3 – Predicate Logic

Page 126: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 126

Syntax of predicate logic (for 1- and 2-place predicates)

(Wellformed) Formulas: (Wellformed) Formulas: – All atomic formulas are formulasAll atomic formulas are formulas– If If and and are formulas then are formulas then ,,

( ( ), (), (), (), ( ) are formulas.) are formulas.– If If is a formula then is a formula then x x and and y y

are are formulas.formulas.

Page 127: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 127

Semantics of predicate logic(this time using models)

• The truth conditions for propositional logic The truth conditions for propositional logic connectives are as specified in their truth-table connectives are as specified in their truth-table definitionsdefinitions

xx is true with respect to a model if is true with respect to a model if at least oneat least one expression expression (x:=(x:=aa) is true with respect to the ) is true with respect to the model, and false otherwise.model, and false otherwise.

xx is true with respect to a model if is true with respect to a model if everyevery expression expression (x:=(x:=aa) is true with respect to the ) is true with respect to the model, and false otherwisemodel, and false otherwise

Page 128: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 128

Semantics of predicate logic(using models in a more precise way)

• ObserveObserve: Effectively, the meaning of : Effectively, the meaning of formulas is defined via rules of the form formulas is defined via rules of the form “... is true iff ...”. This is called a “... is true iff ...”. This is called a truth truth definition.definition.

• For those of you who like a formal For those of you who like a formal treatment of truth definitions, in which the treatment of truth definitions, in which the role of models is made mathematically role of models is made mathematically more explicit, here goes ... more explicit, here goes ...

Page 129: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 129

Formally what is a model?

• A model A model MM is a pair < is a pair <D,ID,I> where > where DD is a set (an is a set (an u.d.), and u.d.), and II is a suitable ‘interpretation’ function. is a suitable ‘interpretation’ function. Informally speaking, a given Informally speaking, a given MM defines one way defines one way of giving a concrete ‘meaning’ to the symbols of giving a concrete ‘meaning’ to the symbols (other than (other than ) in your formulas.) in your formulas.

• If a is an individual constant then If a is an individual constant then II(a)(a)DD• If P is a 1-place predicate then If P is a 1-place predicate then II(P)(P)DD • If R is a 2-place predicate then If R is a 2-place predicate then II(P) is a set (P) is a set

of pairs (of pairs (,,) such that ) such that DD, and , and DD

Page 130: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 130

(This way to specify the meaning of a 2-place (This way to specify the meaning of a 2-place predicate will become clearer after the lectures predicate will become clearer after the lectures about relations. An example might help: ) about relations. An example might help: )

Page 131: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 131

An example of a model

• Suppose Suppose M M = (= (D,ID,I) where ) where DD={John,Mary,Bill} and ={John,Mary,Bill} and

II(j)=John, (j)=John, II(m)=Mary, (m)=Mary, II(b)=Bill, (b)=Bill, II(B)={John,Bill}(B)={John,Bill}II(G)={Mary}(G)={Mary}II(A)={(John,Mary),(Bill,Mary)}(A)={(John,Mary),(Bill,Mary)}

• Note: Note: JohnJohn is a person is a person (i.e., a part of the world)(i.e., a part of the world)jj is an individual constant is an individual constant (i.e., a part of the (i.e., a part of the language of predicate logic).language of predicate logic). jj “names” “names” JohnJohn..

Page 132: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 132

Formally (where M = <D,I>) atomic formulas

Here is the start of the new truth definition:Here is the start of the new truth definition:

• A formula of the form P(a) is true A formula of the form P(a) is true with respect to M iff with respect to M iff I(a) I(a) I(P). I(P).

• A formula of the form R(a,b) is true A formula of the form R(a,b) is true with respect to M iff with respect to M iff ((I(a),I(b)I(a),I(b)) ) I(R). I(R).

Page 133: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 133

Formally (where M = <D,I>) formulas with propositional connectives

• A formula of the form A formula of the form is true wrt M iff is true wrt M iff is false wrt M is false wrt M

• A formula of the form A formula of the form is true wrt M iff is true wrt M iff is true wrt M or is true wrt M or is true wrt M or both is true wrt M or both

• A formula of the form A formula of the form is true wrt M iff is true wrt M iff is true wrt M and is true wrt M and is true wrt M is true wrt M

• A formula of the form A formula of the form is true wrt M iff is true wrt M iff is false wrt M or is false wrt M or is true wrt M or both is true wrt M or both

Page 134: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 134

Formally (where M = <D,I>) quantified formulas

• A formula of the form A formula of the form xx is true wrt M is true wrt M iff iff at least one expression at least one expression (x:=(x:=aa) ) is true wrt M. is true wrt M. (More precisely: there is an a such that ...)(More precisely: there is an a such that ...)

• A formula of the form A formula of the form xx is true wrt M is true wrt M iff iff all expressions all expressions (x:=(x:=aa) ) are true wrt M. are true wrt M. (More precisely: for all a, ...)(More precisely: for all a, ...)

• (End of truth definition.)(End of truth definition.)

Page 135: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 135

models: some illustrations

• Suppose Suppose MM= (= (D,ID,I) , where ) , where DD={John,Mary,Bill}, and={John,Mary,Bill}, and II(j)=John, (j)=John, II(m)=Mary, (m)=Mary, II(b)=Bill, and(b)=Bill, andII(B)={John,Bill}(B)={John,Bill}II(G)={Mary}(G)={Mary}II(A)={(John,Mary),(Bill,Mary)}(A)={(John,Mary),(Bill,Mary)}

• Is B(j) true wrt Is B(j) true wrt MM??

Page 136: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 136

models: some illustrations

• Suppose Suppose MM=( =( D,ID,I) , where ) , where DD={John,Mary,Bill}, and={John,Mary,Bill}, and II(j)=John, (j)=John, II(m)=Mary, (m)=Mary, II(b)=Bill, and(b)=Bill, andII(B)={John,Bill}(B)={John,Bill}II(G)={Mary}(G)={Mary}II(A)={(John,Mary),(Bill,Mary)}(A)={(John,Mary),(Bill,Mary)}

• Is B(j) true wrt Is B(j) true wrt MM? ? YesYes

Page 137: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 137

models: some illustrations

• Suppose M=(D,I), where D={John,Mary,Bill}, andSuppose M=(D,I), where D={John,Mary,Bill}, and I(j)=John, I(m)=Mary, I(b)=Bill, andI(j)=John, I(m)=Mary, I(b)=Bill, andI(B)={John,Bill}I(B)={John,Bill}I(G)={Mary}I(G)={Mary}I(A)={(John,Mary),(Bill,Mary)}I(A)={(John,Mary),(Bill,Mary)}

• Is B(j) true wrt M? Is B(j) true wrt M? YesYes • Is B(j)Is B(j)B(b)B(b)A(m,m) true wrt M? A(m,m) true wrt M?

Page 138: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 138

models: some illustrations

• Suppose M=(D,I), where D={John,Mary,Bill}, andSuppose M=(D,I), where D={John,Mary,Bill}, and I(j)=John, I(m)=Mary, I(b)=Bill, andI(j)=John, I(m)=Mary, I(b)=Bill, andI(B)={John,Bill}I(B)={John,Bill}I(G)={Mary}I(G)={Mary}I(A)={(John,Mary),(Bill,Mary)}I(A)={(John,Mary),(Bill,Mary)}

• Is B(j) true wrt M? Is B(j) true wrt M? YesYes • Is B(j)Is B(j)B(b)B(b)A(m,m) true wrt M? A(m,m) true wrt M? NoNo

Page 139: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 139

models: some illustrations

• Suppose M=(D,I), where D={John,Mary,Bill}, andSuppose M=(D,I), where D={John,Mary,Bill}, and I(j)=John, I(m)=Mary, I(b)=Bill, andI(j)=John, I(m)=Mary, I(b)=Bill, andI(B)={John,Bill}I(B)={John,Bill}I(G)={Mary}I(G)={Mary}I(A)={(John,Mary),(Bill,Mary)}I(A)={(John,Mary),(Bill,Mary)}

• Is B(j) true wrt M? Is B(j) true wrt M? YesYes • Is B(j)Is B(j)B(b)B(b)A(m,m) true wrt M? A(m,m) true wrt M? NoNo• Is Is x(B(x)x(B(x)A(x,m)) true wrt M?A(x,m)) true wrt M?

Page 140: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 140

models: some illustrations

• Suppose M=(D,I), where D={John,Mary,Bill}, andSuppose M=(D,I), where D={John,Mary,Bill}, and I(j)=John, I(m)=Mary, I(b)=Bill, andI(j)=John, I(m)=Mary, I(b)=Bill, andI(B)={John,Bill}I(B)={John,Bill}I(G)={Mary}I(G)={Mary}I(A)={(John,Mary),(Bill,Mary)}I(A)={(John,Mary),(Bill,Mary)}

• Is B(j) true wrt M? Is B(j) true wrt M? YesYes • Is B(j)Is B(j)B(b)B(b)A(m,m) true wrt M? A(m,m) true wrt M? NoNo• Is Is x(B(x)x(B(x)A(x,m)) true wrt M? A(x,m)) true wrt M? YesYes

Page 141: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 141

models: some illustrations

x(B(x)x(B(x)A(x,m)) true wrt M iffA(x,m)) true wrt M iff

all expressions B(a) all expressions B(a) A(a,m)A(a,m) are true wrt M. are true wrt M.

TheseThese are the following: are the following:

B(j) B(j) A(j,m)A(j,m)

B(b) B(b) A(b,m)A(b,m)

B(m) B(m) A(m,m)A(m,m)

Page 142: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 142

why is the latter formula true?

x(B(x)x(B(x)A(x,m)) true wrt M iffA(x,m)) true wrt M iff

all expressions B(a) all expressions B(a) A(a,m)A(a,m) are true wrt M. are true wrt M.

TheseThese are the following: are the following:

B(j) B(j) A(j,m) A(j,m) true wrt Mtrue wrt M

B(b) B(b) A(b,m) A(b,m) true wrt Mtrue wrt M

B(m) B(m) A(m,m)A(m,m)

Page 143: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 143

why is the latter formula true?

x(B(x)x(B(x)A(x,m)) true wrt M iffA(x,m)) true wrt M iffall expressions B(a) all expressions B(a) A(a,m)A(a,m) are true wrt M. are true wrt M.TheseThese are the following: are the following:B(j) B(j) A(j,m) A(j,m) true wrt Mtrue wrt MB(b) B(b) A(b,m) A(b,m) true wrt Mtrue wrt MB(m) B(m) A(m,m) A(m,m) true wrt Mtrue wrt M (antecedent false!) (antecedent false!)

Consequently Consequently x(B(x)x(B(x)A(x,m)) is true wrt M A(x,m)) is true wrt M

Page 144: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 144

Predicate logic: optional extensions

• This completes the strict version of predicate logicThis completes the strict version of predicate logic• In addition, we have introduced a number of In addition, we have introduced a number of

simplifications and extensions:simplifications and extensions:• BracketsBrackets

– all outermost brackets can be omittedall outermost brackets can be omitted

– brackets that are superfluous because of associativity brackets that are superfluous because of associativity can be omitted, e.g., pcan be omitted, e.g., pqqr instead of (pr instead of (pq)q)r r

– we sometimes add extra brackets for clarity, or [..] we sometimes add extra brackets for clarity, or [..] rather than (..), to show which brackets matchrather than (..), to show which brackets match

Page 145: University of Aberdeen, Computing Science CS3511 Discrete Methods Kees van Deemter

Module #1 - Logic

04/19/23 Michael Frank / Kees van Deemter 145

Predicate logic: optional extensions

• QuantifiersQuantifiers– we sometimes write we sometimes write xyzxyz instead of instead of

xxyyz, z, oror xyz xyz instead ofinstead of xxyyzz !!xx PP((xx), ), 22!!xx PP((xx), etc. for exact numbers), etc. for exact numbers– restricted quantification: e.g., restricted quantification: e.g., x>0x>0 instead ofinstead of

x(x>0x(x>0)) or or x>0x>0 instead ofinstead of x(x>0x(x>0))

• OtherOther– we sometimes write we sometimes write instead of instead of – we sometimes allow ourselves to suggest infinitely long we sometimes allow ourselves to suggest infinitely long

formulas using dots, e.g. pformulas using dots, e.g. p1 1 p p2 2 ... ...