Logic and Discrete Math Lecture notes Predicate Logic

CSE 240 Logic and Discrete Math Lecture notes Predicate Logic Weixiong Zhang Washington University in St. Louis http://www.cse.wustl.edu/~zhang/teach...
Author: Homer French
2 downloads 1 Views 3MB Size
CSE 240

Logic and Discrete Math Lecture notes Predicate Logic Weixiong Zhang Washington University in St. Louis http://www.cse.wustl.edu/~zhang/teaching /cse240/Spring10/index.html 1

Chapter 2.1 All images are copyrighted to their respective copyright holders and reproduced here for academic purposes under the condition of “fair using”.

Today

2

The Big Picture Logic is being used to verify validity of arguments An argument is valid iff its conclusion logically follows from the premises Derivations are used to prove validity Inference rules are used as part of derivations 3

Summary Logical implication/entailment: A entails/logically implies B B follows from A A∴B is a valid argument A is a sufficient condition for B B is a necessary condition for A If A holds then B holds A may be “stronger than” B Formula X=(AB) is a tautology 4

Summary Equivalence: A≡B A holds iff B holds A is a criterion for B, B is a criterion for A A  B, B  A A and B are “equivalently strong” Formula X=(AB) is a tautology

5

Clarification #1 We have used the following expressions synonymously: A entails B A logically implies B (A therefore B) is a valid argument B logically follows from A

In reality there are some subtle differences Technically we mean: “A logically implies B” Every model for A is also a model for B 6

Clarification #2 Can computers generate a derivation/proof given a conclusion and a set of premises? Propositional logic is decidable: the tabular method application of inference rules

Predicate logic is semi-decidable If a proof exists then it can (theoretically) be found by machines If the proof doesn’t exist then the algorithm may not stop 7

Clarification #3 Derivation of a statement: a sequence of statements start with the premises each statement logically follows from the previous statements at some point the conclusion is arrived at

Derivations are annotated with the inference rules used 8

Limitations of Propositional Logic Let’s get back to Socrates “All people are mortal” “Socrates is a man” “Socrates is mortal”

Can we formalize this in propositional logic? Our previous attempt was: “If Socrates is a man then Socrates is mortal” “Socrates is a man” “Socrates is mortal”

Clearly NOT the same! 9

What is the matter? The problem is: We operate with constant objects only We have no domain context and no domain variables We cannot say “all”, “is a”, etc.

Solution? Predicate Logic

10

Predicate Logic Logic objects (constants/variables): P, Q, R, … true, false

Connectives: &, v, , …

Domain objects (constants/variables): Socrates, CSE240

Predicates: Mortal(Socrates) TaughtAtWashU(CSE240) Happened(snow,yesterday)

Quantifiers: For all, Exists Statements/formulae: Atomic, conjunctive, etc. Quantified (universally / existentially) 11

Translation Examples “Every man is mortal” Define man(X), mortal(x) ∀x [man(X)  mortal(x)]

“Socrates is a man” man(Socrates)

“Socrates is mortal” mortal(Socrates) The last statement logically follows from the premises (by universal elimination)

Q: how about define man-mortal(x)? Granularity of the representation unit of objects or concept to present 12

More translations “Ducks fly” Define duck(x), flies(x) ∀x [duck(x)  flies(x)]

“F-16s fly” Define F-16(x) ∀x [F-16(x)  flies(x)]

“F-16s are ducks” ∀x [F-16(x)  duck(x)] The last statement does not logically follow from the premises What if we define duck-flies(x)? 13

Translation Examples “Every person is a Knave or a Knight” define person(x), Knave(x) and Knight(x) This can be translate to IF… THEN… ∀x [person(x)  [Knave(x) v Knight(x)]]

“Every person is a Knave or a Knight but not both” ∀x [person(x)  [Knave(x) v Knight(x)] & ~[Knave(x) & Knight(x)]]

14

Translation Examples “Nothing is better than God” Define better-than(x,y) Different ways to say this … ∀x [~better-than(x,God)] ~[∃x better-than(x,God)]

“A (any) sandwich is better than nothing” Define sandwich(x) ∀x [sandwich(x)  better-than(x,Nothing)]

“A sandwich is better than God” ∀x [sandwich(x)  better-than(x,God)] The last statement does not logically follow from the premises 15

Translation Examples “No man lives forever” First define man(x) and lives-forever(x) Different ways to say this … If a man (any), then will not live forever

∀x [man(x)  ~lives-forever(x)] Different ways to say this … It’s not true that … There is a man and the man lives forever

~[∃x [man(x) & lives-forever(x)]]

16

Translation Examples “Everyone likes CSE240” define WashU-student(x), likes(x,y) ∀x [WashU-student(x)  likes(x,CSE240)]

“Someone likes CSE240” ∃x [WashU-student(x)  likes(x,CSE240)] Is this correct?

∃x [WashU-student(x) & likes(x,CSE240)]

17

Translation Examples “no even number is a prime except 2” define even(x), prime(x) ∀x [even(x)  ~prime(x)] What about except 2? Equal(x,2)

∀x [even(x) & ~equal(x,2)  ~prime(x) ]

18

Predicate Logic Logic objects (constants/variables): P, Q, R, … true, false

Connectives: &, v, , …

Domain objects (constants/variables): Socrates, CSE240

Predicates: Mortal(Socrates) TaughtAtWashU (CSE240) Happened(snow,yesterday)

Quantifiers: For all, Exists Statements/formulae: Atomic, conjunctive, etc. Quantified (universally / existentially) 19

Domain Objects We can now have variables and constants of a non-Boolean nature: Socrates is a constant (a specific member) in the set of all people X is a variable over the set of people i.e., X can be any person We can instantiate X=Socrates

Domain of a variable is the set of values it can take on 20

Predicates In other words: Predicates take domain objects and map them to true/false depending on the properties of the objects Predicate = a property of an object we want test

Thus, a predicate with all its variables instantiated is a statement (i.e., true/false)

Example: BetterThan(v1,v2) BetterThan(Ferrari,nothing)=true 21

Truth Set Suppose P(x) is “x is a factor of 8” So how about the following: P(1) True P(2) True P(0) False

The set of all x such that P(x) holds is called the truth set of P(x) Here it would be {1,2,4,8}

The truth set of some predicate can be infinite 22

Examples Suppose P(x,y,r) is “x2+y2=r2” What is the truth set of P(x,y,5)? Circle with the radius of 5 centered in the origin

Suppose P(n) is “n is an even threedigit prime number” What is the truth set of P(n)? An empty set 23

Propositional Logic? But what about our dearly beloved propositional statements? PvQ

Here P and Q are propositional/Boolean variables/statements They don’t take any domain objects They simply hold or don’t hold How can we have them in the predicate logic? 24

Fear Not! A Boolean variable/constant (e.g., P=true) is simply a 0-arity predicate: P()

So propositional logic is back! Example: propositional Modus Ponens: PQ P Thus, Q

P()  Q() P() Thus, Q() 25

Predicate Formulae Everything from propositional logic Boolean variables become 0-arity predicates…

Additionally: Predicates, e.g.: Mortal(x)

Universally quantified formulae, e.g.: ∀x [man(x)  mortal(x)]

Existentially quantified formulae, e.g.: ∃x [man(x) & likes(x,240)] 26

Recall: interpretation In propositional logic interpretation is a mapping/assignment of all propositional variables to true/false Example: Formula: A v B Interpretation: I I(A)=true I(B)=false I(A v B)=true 27

Extended Interpretations In predicate calculus to specify an interpretation we need to: Select domain sets Assign all domain constants Assign semantics to all predicates

Example: Predicate formula: D=(∀x [likes(x,c240)]) A possible interpretation assigns: Domain set for x : people Domain value for 2nd argument of likes(a,b) : things Domain value for constant c240 : class CSE240 Semantics for predicate likes(a,b) : holds iff person a likes object b 28

Evaluating formulae Predicate formula: D=(∀x [likes(x,cse240)]) A possible interpretation assigns: Domain set for x : people Domain value for 2nd argument of likes(a,b) : things Domain value for constant cse240 : class cse240 Semantics for predicate likes(a,b) : holds iff person a likes object b

So what is the value of formula D given the interpretation? True/false? How can we tell? 29

Evaluating Formula 0-arity predicate : P() Interpretation directly

Predicate with variables : P(x) Use the assignment of x and the semantics of P()

Universally quantified formula : ∀x P(x) Evaluates to true iff P(x) holds on all possible values of x

Existentially quantified formulae : ∃x P(x) Evaluates to true iff P(x) holds on at least one possible value of x 30

Chapter 2.1

Chapter 2.2

Chapter 2.3

All images are copyrighted to their respective copyright holders and reproduced here for academic purposes under the condition of “fair using”.

Today

31

The Plan Up to date we have considered an informal introduction to predicate logic We will introduce predicate logic formally today and dwell on subtle moments

32

Predicate Logic (simplified) Boolean variables P, Q, R, … E.g., P=“5 is a prime number”

can be T/F

Connectives: &, v, , , ~

Domain variables A,B,C,… draw values from a domain sets E.g., j is a variable over integer numbers

Predicates: P(X1,…,XN),… E.g., P(j) = “j is a prime number”

map from domain inputs to T/F

Quantifiers: For all ∀, Exists ∃ E.g., [∀j prime(j)] = “any number is a prime number”

Statements/formulae: Atomic, unit, negated, conjunctive, …, universally/existentially quantified E.g., [∀j [even(j) & ~equal(j,2)  ~prime(j) ]] = “no even numbers are prime except 2” 33

Note Notice that we did away with 0-arity predicates such as P(), etc. Any Boolean variable is a 0-arity predicate so we will just drop the parentheses…

34

Def : Well-formed Formulae A well-formed formula/sentence (wff) is a construction defined recursively: Any Boolean variable is a wff Any predicate is a wff For any wff X, ~(X) is a wff Two wffs parenthesized and connected by v,&,, form a wff. For any wff X and a domain variable k: ∀k (X) is a wff ∃k (X) is a wff Here X is within the scope of ∀k (or ∃k) 35

Find wffs… ∀x [man(X)  mortal(x)] ∀x [sandwich(x)  better-than(x,Nothing)] ∀x [duck(x)  flies(x)] ~[∃x [man(x) & lives-forever(x)]] ∀x [man(x)  ~lives-forever(x)] ∀x [person(x)  [Knave(x) v Knight(x)]] ∀x [person(x)  [Knave(x) v Knight(x)]] & ~[Knave(x) & Knight(x)]

36

Def : Interpretations Interpretation for a wff Φ: Assigns T/F values to all Boolean variables Defines a domain set for each domain variable Defines all predicates

Example: consider wff Φ = (∀j prime(j)) & P A possible interpretation: Boolean variable P=T Domain variable j runs over integer numbers Predicate prime(x) holds iff x is a prime number

37

Interpretation Example Consider wff: ∀x ∃y Likes(x,y)

Does it hold? Depends on the interpretation!

Interpretation: Domain set for x,y is {Angela,Belinda,Jean} Define predicate Likes(liker,liked) as: Likes(Angela,Belinda) Likes(Belinda,Angela) Likes(Jean,Belinda) Likes(Jean,Angela)

Does it hold in this interpretation? Yes 38

Model / Countermodel Formula Φ holds given an interpretation I: Φ is satisfied by I Then Φ is satisfiable Then I is a model for Φ

Formula Φ doesn’t hold given I: Φ is not satisfied (or falsified) by I Then I is a countermodel for Φ 39

Tautologies & Contradictions Formula Φ holds under any interpretation I Φ is valid Φ is a tautology

Formula Φ doesn’t hold under any I Φ is a contradiction Φ is unsatisfiable 40

Example Define Predicate P(X) as “person X drinks beer”

Consider ∃x∀y [P(x)  P(y)] “There exists a person such that if he/she drinks beer then everyone drinks beer”

True or false?

41

Contingencies Φ holds under any interpretation  tautology Φ does NOT hold under any interpretation  contradiction What if Φ holds under some interpretations but not other? Then Φ is a contingency 42

Classify… P & ~P P v ~P P&Q ∀x P(x) ∀x ((P(x)  Q(x)) & P(x))  Q(x) ∀x (P(x) v ~P(x))  (P(x) & ~P(x))

43

Bindings & Scope A variable can be free: Sharp(X)

…or bound to a quantifier ∀x P(x) If variable X is bound to a quantifier then there is a binding between them Then X is said to be in the quantifier’s scope How about: ∀x ∀y (equal(x,y) v P(z) & (∃y B(x,y))) ∀x ∃y P(x) & Q(x,y) v R(y)

CSE240 is case-sensitive! X is not the same as x 44

Free variables Given an interpretation we can evaluate a formula, e.g.: ∀x ∃y Likes(x,y)

Consider the following formula: ∃y Likes(x,y)

Suppose you are given the interpretation I: Domain set for x,y is {Angela,Belinda,Jean} Define predicate Likes(liker,liked) as: Likes(Angela,Belinda) Likes(Jean,Belinda) Likes(Jean,Angela)

Is ∃y Likes(x,y) satisfied by I ? Cannot tell – x is a free variable… 45

Substitutions A wff that can be evaluated to T/F given an interpretation is called a statement Formulae with free variables may not be statements That is so because an interpretation doesn’t touch free domain variables

A substitution “complements” an interpretation by assigning (substituting) all free domain variables 46

Example Revisit the formula: ∃y Likes(x,y)

Suppose you are given the interpretation I: Domain set for x,y is {Angela,Belinda,Jean} Define predicate Likes(liker,liked) as: Likes(Angela,Belinda) Likes(Jean,Belinda) Likes(Jean,Angela)

Additionally you have a substitution S: Free domain variable x is set to Angela

Is ∃y Likes(x,y) satisfied by I and S? Yes… 47

Updated Definition Formula Φ holds given an interpretation I and a substitution S: Φ is satisfied by I and S Then Φ is satisfiable Then I and S form a model for Φ

Formula Φ doesn’t hold given I and S : Φ is not satisfied (or falsified) by I and S Then I and S form a countermodel for Φ 48

Updated Definition Formula Φ holds under every interpretation I and substitution S Φ is valid Φ is a tautology Formula Φ doesn’t hold under any I and substitution S Φ is a contradiction Φ is unsatisfiable 49

Updated Definition Φ holds under some interpretations and substitutions but not others?

Then Φ is a contingency

50

Note 1 Many formulae with free variables cannot be tautologies or contradictions Their value depends on the substitution

However, some can: Likes(x,y) v ~Likes(x,y) … is a tautology despite two free variables

51

Implicit Quantifiers If x > 2 then x2 > 4 Textbook: ∀ real numbers x, if x>2 then x2 > 4

More formally:

Implicit quantifiers

∀x [x>2  ∃y square(x,y) & y>4] where predicates square(a,b) and c>d are defined over the set of real numbers 52

Domain Functions Consider the last statement again: ∀ real numbers x, if x>2 then x2 > 4 Is it a wff? No! Why? Well x2 is not a predicate and is not a variable It is a domain function (square)!

We have not formally introduce domain functions But we will use them anyway for the sake of: Simplicity Consistency with the text book 53

Conversion to Predicates The use of domain functions is justified: Because they can be expressed through domain predicates

Example: let function f map numbers to numbers: f(n)=m

Then whenever we see f(x) in our wff We will change it (with some care) to: ∃y Pf(x,y) Where Pf(n,m) holds iff f(n)=m 54

Evaluating Formulae Boolean variables Interpretation directly

Predicate with variables : Likes(x) Use the assignment of x and the semantics of Likes()

Universally quantified formula : ∀x P(x) Evaluates to true iff P(x) holds on all possible values of x

Existentially quantified formulae : ∃x P(x) Evaluates to true iff P(x) holds on at least one possible value of x 55

Examples Consider formula D: ∃x (x2 > x)

Assume the standard algebraic interpretation Suppose the domain set for variable x is {2,3,4} Does D hold or not? Yes : 4>2

Suppose the domain set for variable x is the segment [0,1] Does S hold or not? No : all numbers between 0 and 1 have their squares not greater than the number itself 56

Summary GIVEN a particular interpretation To show that a ∀-quantified formula holds: Exhaust all possibilities – show that all examples satisfy the formula

To show that a ∀-quantified formula does NOT hold: Find a falsifying example

To show that a ∃-quantified formula holds: Find a satisfying example

To show that a ∃-quantified formula does NOT hold: Exhaust all possibilities and show that all examples falsify the formula 57

Summary How about classifying a formula: Tautology / Contradiction / Contingency

Contingencies are, perhaps, the easiest: Need to find a model and a counter-model

Tautologies / contradictions: Need to show that all possible interpretations satisfy/falsify the formula More difficult 58

Restricted ∀-Quantifiers Informal: Any number greater than 2 is positive

Formal: ∀x [x>2  x>0]

Formal shorthand (“syntactic sugar”): ∀x>2 [x>0]

Common mistake: Use of & instead of  ∀x [x>2 & x>0] “Any number is greater than 2 and greater 0” How about 1? 59

Restricted ∃-Quantifiers Informal: There is a positive solution to x2=1

Formal: ∃x [x>0 & x2=1]

Formal shorthand (“syntactic sugar”): ∃x>0 [x2=1]

Common mistake: Use of  instead of & ∃x [x>0  x2=1] “There exists a number such that if it is positive then it is a solution to x2=1” This formula is satisfied by any interpretation that contains 0 among the numbers 60

Restricted ∃-Quantifiers Another example of… Common mistake: use of  instead of & “There exists an immortal man”

Correct: ∃x [man(x) & ~mortal(x)]

Incorrect: ∃x [man(x)  ~mortal(x)] “There exists something such that if it is a man then it is immortal”

The latter formula is satisfied by any interpretation that allows x to run over non-man objects E.g., x can be a duck satisfying the formula 61

Limitations It is Ok to use the shorthand with: Algebraic predicates: e.g., x>0 Set membership: e.g., x∈D

Why? Because it is clear that your quantifiers is applied to the variable which follows it immediately: ∃x>0 [x2=1]

It is not Ok to use such shorthands with other predicates: E.g., ∃P(x) [x2=1] 62

Special cases : finite domains Suppose you have a formula over a single variable x If the domain of variable x is finite: {x1,…,xN}

Then ∀x P(x) is equivalent to: P(x1) & … & P(xN)

And ∃x P(x) is equivalent to: P(x1) v … v P(xN) 63

Satisfying ∀/∃ statements To show that ∀x P(x) we need to: Prove that every x satisfies P(x)

To show that ∃x P(x) we need to: Prove that there exists at least one x that satisfies P(x)

64

De Morgan again… To show that ~(∀x P(x)) we need to: Prove that not every x satisfies P(x) In other words, we need to find at least one x that does not satisfy P(X) But that is the same as proving that ∃x ~P(x)

Therefore: ~(∀x P(x)) ∃x (~P(x))

are logically equivalent De Morgan’s law for quantifiers 65

And again… To show that ~(∃x P(x)) we need to: Prove that there does not exists a single x satisfies P(x) In other words, we need to show that all x do not satisfy P(X) But that is the same as proving that ∀x ~P(x)

Therefore: ~(∃x P(x)) ∀x (~P(x))

are logically equivalent De Morgan’s law for quantifiers 66

Examples Statement: “Everyone snoozes in CSE240”

Negation: “Not every one snoozes in CSE240” “There is someone who doesn’t snooze in CSE240”

A common mistake: “Everyone does NOT snooze in CSE240”

67

Examples Statement: “Professors don’t make much money”

Negation: “There is a professor who makes a lot of money”

A common mistake: “Professors make much money” 68

Examples Statement: There is a secret agent who appeals to all women

Negation: For every secret agent there is a woman that the agent doesn’t appeal to

A common mistake: There is a secret agent who doesn’t appeal to all women 69

In the nutshell… When negating a quantified formula: Quantifier1 x1… QuantifierN xN P(x1,..,xN)

Do this: Change all ∃ to ∀ Change all ∀ to ∃ Negate the innermost formula P(…)

Be careful with scoping and connectives! 70

Vacuous Truth of UQs Suppose I say: “Presently, all men on the moon are happy”

Is it true or false? Think of it this way: ∀x [OnTheMoon(x)  Happy(x)]

So, is it true or false? The internal implication is always vacuously true for there is presently no man on the Moon Thus, the entire statement holds for any x

The entire statement holds 71

Logical Implication In propositional logic formula A logically implies formula B iff: Every interpretation that satisfies A also satisfies B

In predicate logic? The same!

72

Validity of Arguments Hence validity of arguments is defined in the same way The difference is: in predicate logic it is not always possible to go through all interpretations to prove that A logically implies B

Why? The number of interpretations can be infinite 73

Inference Rules Thus, proving arguments with inference rules becomes the (only) method of choice We can also derive new inference rules for our toolbox

74

Universal Instantiation Consider a universally quantified statement: ∀x∈D [P(x)]

Suppose you have a particular x0∈D What can you say about P(x0)? It holds!

Why? Because predicate P(…) holds for all members of set D Example: “mortal Socrates” argument 75

Universal Modus Ponens Propositional modus ponens PQ P Thus, Q

Universal modus ponens ∀x [P(x)Q(x)] P(a) Thus, Q(a) 76

Diagrams for Validity mortal Diagrams can sometimes be used to:

support a validity of an argument human or, show that an argument is invalid

Diagrams are not a formal proof! Socrates pneumonia Use them to illustrate your reasoning ONLY fever Examples: Valid : Modus Ponens Invalid : abduction

patient 77

Summary predicate logic Everything from propositional logic Domain variables, objects Universal/existential quantifiers WFF – grammar to write sentences Scope of a quantifer Representation Every student takes CSE240 Someone takes CSE240

De morgan’s law on negation with quantifiers 78