10/17/2015michael frank / kees van deemter1 university of aberdeen, computing science cs3518 lecture...

82
03/22/22 Michael Frank / Kees van Deemter 1 University of Aberdeen, Computing Science CS3518 Lecture on Models and Satisfiability Further details: K.Rosen, Further details: K.Rosen, Discrete Discrete Mathematics & Its Applications Mathematics & Its Applications (any (any edition), chapter on logic edition), chapter on logic

Upload: bathsheba-bell

Post on 01-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

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

University of Aberdeen, Computing Science

CS3518Lecture on

Models and Satisfiability

Further details: K.Rosen, Further details: K.Rosen, Discrete Mathematics & Discrete Mathematics & Its ApplicationsIts Applications (any edition), chapter on logic (any edition), chapter on logic

• These slides are not meant as a general-These slides are not meant as a general-purpose introduction, but as preparation for purpose introduction, but as preparation for – a proof that monadic Predicate Logic is a proof that monadic Predicate Logic is

decidabledecidable– a proof that full Predicate is undecidable a proof that full Predicate is undecidable

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

First Propositional Logic

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

The syntax of propositional logic

• Atoms: p1, p2, p3, ..Atoms: p1, p2, p3, ..

• Formulas:Formulas:– All atoms are formulasAll atoms are formulas– For all For all , if , if is a formula then is a formula then ¬ ¬ is a is a

formulaformula– For all For all and and , if , if and and are formulas then the are formulas then the

following are formulas: (following are formulas: ( ), (), ( ), (), ( ) ) (etc.)(etc.)

CS2013 Univ of Aberdeen 4

Subformulas

• A formula that is a substring of a formula ψ A formula that is a substring of a formula ψ is a subformula of ψis a subformula of ψ

• Example: Example: ((p p qq) has these ) has these subformulas:subformulas:

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

Subformulas

• A formula that is a substring of a formula ψ A formula that is a substring of a formula ψ is a subformula of ψis a subformula of ψ

• Example: Example: ((p p qq) has these ) has these subformulas:subformulas:

((p p qq), (), (p p qq),),pp, , qq, , p, qp, q

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

Tautologies

A A tautologytautology is a compound proposition that is is a compound proposition that is truetrue no matter whatno matter what the truth values of its the truth values of its atomic propositions are!atomic propositions are!

Ex.Ex. p p pp [What is its truth table?][What is its truth table?]

CS2013 Univ of Aberdeen 7

Tautologies

• When every row of the truth table gives When every row of the truth table gives T..

• Example: p Example: p pp T T TT FT FT F F TT TF TF

CS2013 Univ of Aberdeen 8

Contradictions

A A contradiction contradiction is a compound proposition is a compound proposition that is that is falsefalse no matter what! no matter what! Ex.Ex. p p p p [Truth table?][Truth table?]

CS2013 Univ of Aberdeen 9

Contradictions

• When every row of the truth table gives FWhen every row of the truth table gives F

• Example: p Example: p pp T T FF FT FT F F FF TF TF

CS2013 Univ of Aberdeen 10

Propositional Equivalence

Two Two syntacticallysyntactically ( (i.e., i.e., textually) different textually) different compound propositions may be compound propositions may be semantically semantically identical (identical (i.e., i.e., have the same meaning). Here have the same meaning). Here semantically identical means just that they have semantically identical means just that they have the same truth table for input truth values of the the same truth table for input truth values of the propositions.propositions.

We call them We call them logically equivalentlogically equivalent. .

Notation: … Notation: … … …

CS2013 Univ of Aberdeen 11

Logical Equivalence

Compound proposition Compound proposition pp is is logically logically equivalent equivalent to compound proposition to compound proposition qq, , written written ppqq, , IFFIFF pp and and q q contain the same truth values contain the same truth values in in allall rows of their truth tables rows of their truth tables

CS2013 Univ of Aberdeen 12

Ex.Ex. Prove that Prove that ppqq ((p p qq).).

p q pp qq pp qq pp qq ((pp qq))F FF TT FT T

Proving Equivalencevia Truth Tables

FT

TT

T

T

T

TTT

FF

F

F

FFF

F

TT

CS2013 Univ of Aberdeen 13

Shows that OR is equivalent to a combination of NOT and AND.

Logical consequence

• Formula φ has formula ψ as a logical Formula φ has formula ψ as a logical consequence if ψ “follows from φ”consequence if ψ “follows from φ”

• Formally: every assignment of truth values Formally: every assignment of truth values that makes φ true makes ψ true as wellthat makes φ true makes ψ true as well

• Notation: φ |= ψNotation: φ |= ψ

• φ and ψ are logically equivalent iff φ |= ψ φ and ψ are logically equivalent iff φ |= ψ and ψ |= φand ψ |= φ

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

Ex.Ex. Prove that Prove that pp&&qq pp

Example of one-sided logical consequence

CS2013 Univ of Aberdeen 15

Each row that has T for p&q has T for p .

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

First-Order Predicate logic (FOPL)

• An extension of Propositional LogicAn extension of Propositional Logic• Sometimes called Sometimes called quantificationalquantificational logic, because logic, because

it allows us to quantify over objects in a domainit allows us to quantify over objects in a domain• E.g. saying that all/some objects have a propertyE.g. saying that all/some objects have a property

– SomeSome odd numbers are prime odd numbers are prime

• Futher extensions exist, e.g. Futher extensions exist, e.g. second-order second-order logic, logic, which quantifies over properties, e.g.which quantifies over properties, e.g.– 4 and 2+2 share 4 and 2+2 share allall their semantic properties their semantic properties

Topic #3 – Predicate Logic

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

Predicates/relations with n places

• Full FOPL permits predicates of Full FOPL permits predicates of anyany finite finite number of arguments. E.g.:number of arguments. E.g.:

S(S(xx) = ) = ““x is evenx is even”” (1 arg.) (1 arg.)

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

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

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

Topic #3 – Predicate Logic

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

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.

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

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.)

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

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

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

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 is not ““defineddefined””).).

• 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

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

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.• An expression with An expression with zerozero free variables is free variables is

called a sentence.called a sentence.

Topic #3 – Predicate Logic

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

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

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

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).

• Notation: 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

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

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

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

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

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

Predicate logic

• A formula of FOPL is True (False) with respect to A formula of FOPL is True (False) with respect to a a modelmodel

• Model = domain of objects plus specification of Model = domain of objects plus specification of the “meanings” of the predicates, e.g., bythe “meanings” of the predicates, e.g., by– listing explicitly which objects listing explicitly which objects

the predicate is true ofthe predicate is true of

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

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))))

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

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))))

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

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

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

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))))

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

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

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

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

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

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

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

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..

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

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).

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

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

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

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.)

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

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??

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

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

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

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?

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

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

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

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?

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

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

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

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)

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

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)

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

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

Logical Consequence in Predicate Logic(compare Propositional Logic)

• Formula φ has formula ψ as a logical Formula φ has formula ψ as a logical consequence if ψ “follows from φ”consequence if ψ “follows from φ”

• Formally: every model that makes φ true Formally: every model that makes φ true makes ψ true as wellmakes ψ true as well

• Notation: φ |= ψNotation: φ |= ψ

• φ and ψ are logically equivalent iff φ |= ψ φ and ψ are logically equivalent iff φ |= ψ and ψ |= φand ψ |= φ

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

Example

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

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

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

Logical Consequence Example

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

Is trueIs true

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

Is falseIs false

A model of A model of ((x Px P((xx)))) ((x Qx Q((xx)))) that’s not that’s not

a model of a model of x x ((PP((xx) ) QQ((xx))):):

a:P not Q b Q notPa:P not Q b Q notP

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

Satisfiability

• A sentence φ is satisfiable if there is a model M such that M A sentence φ is satisfiable if there is a model M such that M |= φ|= φ

• Examples: Examples: x x ((PP((xx) ) QQ((xx)))) ((x x ((PP((xx) ) QQ((xx)))) )) is satisfiable is satisfiable (you’ve seen a model)(you’ve seen a model)((x x ((PP((xx) ) QQ((xx)))) ((x x ((PP((xx) ) QQ((xx))))))))is also satisfiable. Here’s a model: is also satisfiable. Here’s a model:

a:P Q b Q notPa:P Q b Q notP•

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

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

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) … …

Topic #3 – Predicate Logic

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

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

Optional bonus topics

• This is to give you more insight in the This is to give you more insight in the strengths limitations of FOPLstrengths limitations of FOPL

• None of this is necessary for understanding None of this is necessary for understanding the proof that followthe proof that follow

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

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

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”?

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

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))

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

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”?

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

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)””))

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

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))))

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

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”?

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

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)

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

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”?

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

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)) ))))

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

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 as a formalisation of ‘‘exactly twoexactly two’’??

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

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 as a formalisation of ‘‘exactly twoexactly 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

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

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??

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

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

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

((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) ) … … ))

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

• 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

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

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 (A Prolog program is a set of propositions (““factsfacts””) )

and (and (““rulesrules””) in predicate logic.) in predicate logic.• The input to the program is a The input to the program is a ““queryquery”” proposition. 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.

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

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.

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

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).

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

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)

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

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)

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

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 if so, it returns ““yesyes””, if not, , if not, ““nono”” (!)(!)– 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.

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

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: ...

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

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

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

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.

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

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

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

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, iff it’’s greater than 1 and it isns greater than 1 and it isn’’t 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

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

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

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

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