L03fol MSR2023

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 58

First Order Logic

(Predicate Calculus)
This Lecture

Last time we talked about propositional logic, a logic on simple statements.

This time we will talk about first order logic, a logic on quantified statements.

First order logic is much more expressive than propositional logic.

The topics on first order logic are:

 Quantifiers

 Negation

 Multiple quantifiers

 Arguments of quantified statements


Limitation of Propositional Logic

Propositional logic – logic of simple statements

How to formulate Pythagoreans’ theorem using propositional logic?

b c

a
How to formulate the statement that there are infinitely many primes?
Predicates
Predicates are propositions (i.e. sentences) with variables
And becomes a statement when specific values are substituted for the variables

Example: P (x,y) ::= x + 2 = y

x = 1 and y = 3: P(1,3) is true

x = 1 and y = 4: P(1,4) is false


P(1,4) is true
More Examples: P(x) ::= x is a student at BUET

Q (x,y) ::= x is a student at y

When there is a variable, we need to specify what to put in the variables.

The domain of a variable is the set of all values


that may be substituted in place of the variable.
Set
To specify the domain, we often need the concept of a set.
Roughly speaking, a set is just a collection of objects.

R Set of all real numbers


Some examples Z Set of all integers
Q Set of all rational numbers

Given a set, the (only) important question is whether an element belongs to it.

means that x is an element of A (pronounce: x in A)

means that x is not an element of A (pronounce: x not in A)

Sets can be defined explicitly: e.g. {1,2,4,8,16,32,…}, {CSE103,CSE105,…}


Truth Set

Sometimes it is inconvenient or impossible to define a set explicitly.

Sets can be defined by a predicate

Given a predicate P(x) and x has domain D, the truth set of


P(x) is the set of all elements of D that make P(x) true.

e.g. Let P(x) be “x is the square of a number”,


and the domain D of x is the set of positive integers.
Then the truth set is the set of all positive integers which are the square of a number.

e.g. Let P(x) be “x is a prime number”,


and the domain D of x is the set of positive integers.
Then the truth set is the set of all positive integers which are prime numbers.
The Universal Quantifier

The universal quantifier x for ALL x

Example: x Z y Z, x + y = y + x.

Pythagorean’s theorem

b c Suppose, a, b, c are the three sides of a triangle


If a, b, c are … then
a
Example: This statement is true if the domain is Z (integers),
but not true if the domain is R (reals).

The truth of a predicate depends on the domain.


Truth and Falsity of Universal Statements

• Let D = {1,2,3,4,5} and consider the


statement: x  D, x2  x. Show this is
true. Method of Exhaustion
12 = 1  1 22 = 4  2 32 = 9  3 42 =16 4 52=25 5
TRUE TRUE TRUE TRUE TRUE
• x  R, x  x. Show that this is false.
2

– Take x = ½ . Clearly x  R
– (½)2 = ¼  ½
Counterexample
– So, this is false
The Existential Quantifier

y There EXISTS some y

e.g.

The truth of a predicate depends on the domain.

x y. x  y
Domain Truth value

integers  T

positive integers + T

negative integers - F Check -1.

negative reals - T
Truth and Falsity of Existential Statements

• m  Z, m2 = m. Show that this is true.


– Take m = 1 . Clearly m  Z
– (1)2 = 1, So, this is true (at least for one
element)
• Let D = {5,6,7,8,9} and consider the
statement: m  D, m2 = m. Show this is
false. Method of Exhaustion
52=255 62=366 72=497 82=648 92=819
FALSE FALSE FALSE FALSE FALSE
Implicit Quantification
• If a number is an integer, then it is a
rational number
– No quantification (for all/each/any)
– But the presence of indefinite article ‘a’ before
the number indicates universal quantification.
– x, xZ  xQ
• The number 24 can be written as a sum of
two even integers
– No quantification (there exists a/some)
–  even integers m and n such that 24 = m+n
Translating Mathematical Theorem

Fermat (1637): If an integer n is greater than 2,

then the equation an + bn = cn has no solutions in non-zero integers a, b, and c.

n  Z, n > 2
Translating Mathematical Theorem

Goldbach’s conjecture: Every even number is the sum of two prime numbers.

Suppose we have a predicate prime(x) to determine if x is a prime number.

How to write prime(p)?


Exercises
Exercise A
• x  R, x2  0
– All real numbers have nonnegative squares.
– Every real number has a nonnegative square.
– Any real number has a nonnegative square.
– x has a nonnegative square, for each real number x.
– The square of any real number is nonnegative.
• x  R, x2  -1
– All real numbers have squares not equal to -1.
– No real numbers have squares equal to -1.
• m  Z, m2 = m
– There is an integer whose square is equal to itself.
– We can find at least one integer equal to its own square.
– m2 = m, for some integer m.
– Some integer equals its own square.
– https://forms.gle/5Fr9ojAgbguziDSW6
Some integers equal their own squares.
Exercises
• All triangles have three sides.
–  triangles t, t has three sides
–  t  T, t has three sides (where T is the set of all
triangles).
• No dogs have wings.
–  dogs d, d does not have wings
–  d  D, d does not have wings (where D is the set of
all dogs)
• Some programs are structured.
–  a program p such that p is structured
–  p  P such that p is structured (where P is the set of
all programs)
Equivalent Forms
• All primes greater than 2 are odd
– x( (Prime(x)  x > 2)  Odd(x) )
– x  D Odd(x)
• Here D consists of all values of the variable x such
that x>2 and Prime(x) is true.
•  x  U, if P(x) then Q(x)
Equivalently we can say:
•  x  D, Q(x);
– Here D consists of all values of the variable x
that makes P(x) true.
 Quantifiers

 Negation

 Multiple quantifiers

 Arguments of quantified statements


Negations of Quantified Statements

Everyone likes football.

What is the negation of this statement? No one likes football.

Not (everyone likes football) = There exists someone who doesn’t like football.

(generalized) DeMorgan’s Law Say the domain has only three values.

The same idea can be used to prove it for any number of variables, by mathematical induction.
Negations of Quantified Statements

There is a plant that can fly.


There is a plant
What is the negation of this statement? that cannot fly.

Not (exists a plant that can fly) = All plants/ Every plant cannot fly.

(generalized) DeMorgan’s Law Say the domain has only three values.

The same idea can be used to prove it for any number of variables, by mathematical induction.
Negation Exercises
•  primes p, p is odd.
–  a prime p such that p is not odd.
•  a triangle T such that the sum of the
angles of T equals 200°
–  triangles T, the sum of the angles of T does
not equal 200°
Informal -> Formal -> Negate
• No politicians are honest
– Formal:  politicians x, x is not honest.
– Negation:  a politician x such that x is
Negate

honest.
– Informal Negation: Some politicians are
honest
• All politicians are honest
Informal Negation: Ambiguity
• All mathematicians wear glasses Depends on the
verbal stress
Informally Negate:
• All mathematicians do not wear glasses
– Meaning 1: There are mathematicians who do
not wear glasses.

– Meaning 2: None of the mathematicians


wears glasses.
Negation of Universal Implications

 (x, P(x)  Q(x))


º x such that  (P(x)  Q(x))
º x such that  ( P(x)  Q(x))
º x such that (P(x)   Q(x))
Example negation:
•  people p, if p is blond then p has blue
eyes
•  a person p such that, p is blond and p
does not have blue eyes
Vacuous Truth
We have 5 black and 5 white balls and a bowl
TRUE/FALSE?
All the balls in the bowl are black

P= All the balls in the bowl are black.


Negation:
There exists a ball in the bowl
 P=
that is not black.
Is there a ball in the bowl that is non-black, i.e., white?
P is FALSE if and only if  P is TRUE
Vacuous Truth
• x  D, P(x)  Q(x) is vacuously true or
true by default if and only if x  D, P(x).
Contrapositive, Converse, Inverse
• x  D, P(x)  Q(x)
• Contrapositive
– x  D,  Q(x)   P(x)
• Converse
– x  D, Q(x)  P(x)
• Inverse
– x  D,  P(x)   Q(x)
Contrapositive, Converse, Inverse
• If a real number is greater than 2, then its
square is greater than 4.
• x  R, x > 2  x2 > 4
• Contrapositive
– x  R, x2 ≯ 4  x ≯ 2
• Converse
– x  R, x2 > 4  x > 2
• Inverse
– x  R, x ≯ 2  x2 ≯ 4
Necessity, Sufficiency, if, Only if


Contrapositive


Contrapositive

 Quantifiers

 Negation

 Multiple quantifiers

 Arguments of quantified statements


Double Quantifiers
•  x  D,  y  E such that P(x, y)
• How to establish the truth of the above?
– For each element x in D
– find an element y in E such that P(x, y)
•  x  D, such that y  E, P (x, y)
• How to establish the truth of the above?
– Find an element x in D for which each
element y in E gives P(x, y)
Exercises: Formal & truth value
https://forms.gle/T5D6e2fEp4TfUtAE6
Exercises: Formal & truth value

1. There is an item that was chosen


by every student.
– This is true; every student chose pie.
2. There is a student who chose
every available item.
– This is false; no student chose all nine
items.
3. There is a student who chose at
least one item from every station.
– This is true; both Uta and Tim chose at
least one item from every station.
4. Every student chose at least one
item from every station.
– This is false; Yuen did not choose a
salad.
1.  an item I such that  students S, S chose I.
2.  a student S such that  items I, S chose I.
3.  a student S such that  stations Z,  an item I in Z such that S chose I.
4.  students S and  stations Z,  an item I in Z such that S chose I.
Order of Quantifiers
There is an anti-virus program killing every computer virus.

How to interpret this sentence?

For every computer virus, there is an anti-virus program that kills it.

There is one (single) anti-virus program that kills all computer viruses.
Order of Quantifiers
There is an anti-virus program killing every computer virus.

How to interpret this sentence?

For every computer virus, there is an anti-virus program that kills it.

• For every attack, I have a defense:


• against MYDOOM, use Defender
• against ILOVEYOU, use Norton
• against BABLAS, use Zonealarm …

 is expensive!
Order of Quantifiers
There is an anti-virus program killing every computer virus.

How to interpret this sentence?

There is one single anti-virus program that kills all computer viruses.

I have one defense good against every attack.

Example: P is CSE-antivirus,
protects against ALL viruses

That’s much better!

Order of quantifiers is very important!


Order of Quantifiers

There is a person supervising every detail of the


production process.

How to interpret this sentence?

There is one single person who supervises all


the details of the production process.

p such that  pp supervise(p, pp)


Order of Quantifiers

There is a person supervising every detail of the


production process.

How to interpret this sentence?


For any particular production detail, there is a
person who supervises that detail
(but there might be different supervisors for different
details.)

 pp, p such that supervise(p, pp)


Order of Quantifiers

There is a person supervising every detail of the


production process.

How to interpret this sentence?

p such that  pp supervise(p, pp)


 pp, p such that supervise(p, pp)

In real life we have this sort of ambiguous situation and depending on


the context we realize which one is actually intended for.
(x y P(x,y)) = x (y P(x,y)) = x y  P(x,y)

(x y P(x,y)) = x (y P(x,y)) = x y  P(x,y)

(x y P(x,y)) = x (y P(x,y)) = x y  P(x,y)

(x y P(x,y)) = x (y P(x,y)) = x y  P(x,y)


More on Negations
There is an anti-virus program killing every computer virus.

What is the negation of this sentence?

For every program, there is some virus that it can not kill.
Exercises

1. There is a smallest positive integer.

2. There is no smallest positive real number.

3. There are infinitely many prime numbers.


Exercise
Exercises

1. There is a smallest positive integer.


(sZ+ xZ+ s  x)
º sZ+ (xZ+ s  x)

B
º sZ+ xZ+ (s  x)
º sZ+ xZ+ s ≰ x
º sZ+ xZ+ x < s
2. There is no smallest positive real number.

3. There are infinitely many prime numbers.


 Quantifiers

 Negation

 Multiple quantifiers

 Arguments of quantified statements


Predicate Calculus Validity

Propositional validity

 A  B    B  A
True no matter what the truth values of A and B are

Predicate calculus validity

z [Q(z)  P(z)] → [x.Q(x)  y.P(y)]

True no matter what


• the Domain is,
• or the predicates are.

That is, logically correct, independent of the specific content.


Predicate Calculus Validity

Propositional validity

 A  B    B  A
True no matter what the truth values of A and B are

A B AB BA (AB)  (BA)


0 0 1 1 1 Tautology
0 1 1 0 1
1 0 0 1 1
1 1 1 1 1
Predicate Calculus Validity
Predicate calculus validity

z [Q(z)  P(z)] → [x.Q(x)  y.P(y)]

True no matter what


Similar to Tautology
• the Domain is,
Of Propositional logic
• or the predicates are.

That is, logically correct, independent of the specific content.

• If hypothesis is false, the whole statement is true


• What happens, if the hypothesis is true?
– In this case, for each Z, Q(Z) and P(Z) must be individually true.
– So, the conclusion follows
– So the statement is true
Arguments with Quantified Statements

Universal instantiation:

Universal modus ponens:

Universal modus tollens:


Arguments with Quantified Statements

Universal instantiation: All men are mortal.


Socrates is a man.
 Socrates is mortal.

• Simplify rk+1  r 1 & UI

• rk+1  r = rk+1  r1 = rk+1+1 = rk+2

2 & UI

• We know from math:


1. For all real numbers x and all integers m and n, xm 
xn = xm+n
2. For all real numbers x, x = x1.
Arguments with Quantified Statements
Universal modus ponens:

If a number is even, then its square is even.


k is a particular number that is even.
(We could say: 6 is even, i.e., k =6)
 k2 is even.
( 62 = 36 is even)
E(x) S(x)

x, if x is even then x2 is even.

Formally
x, E(x)  S(x)
E(6)
 S(6)
Arguments with Quantified Statements
Universal modus tollens:

All human beings are mortal.


Zeus is not mortal.
 Zeus is not human.

H(x) M(x)

x, if x is human then x is mortal.

Formally
x, H(x)  M(x)
M(Zeus)
  H(Zeus)
All professors are absent-minded
1 c
Sohel Rahman is not absent-minded
Calculate c.
1
Conclusion:???
Are you using any argument we taught?
Sohel Rahman is not a professor.
x professor(x)  absent-minded(x)
~absent-minded(Sohel)
 ~professor(Sohel)

All criminals frequently go to that room

Sohel frequently goes to that room

Conclusion: Sohel is a criminal


Valid Argument?
x criminal(x)  room(x) NO
room(Sohel)
 criminal(Sohel)
Universal Generalization

valid rule

Informally, if we could prove that R(c) is true for an arbitrary c


(in a sense, c is a “variable”), then we could prove the for all statement.

e.g. given any number c, 2c is an even number

=> for all x, 2x is an even number.

Remark: Universal generalization is often difficult to prove, we will


introduce mathematical induction to prove the validity of for all statements.
Argument Validity
• To say that an argument form is valid
means the following:
– No matter what particular predicates are
substituted for the predicate symbols in its
premises, if the resulting premise statements
are all true, then the conclusion is also true.
• An argument is called valid if, and only if,
its form is valid
Recall from Proposition…
Valid Rule?
z [Q(z)  P(z)] → [x.Q(x)  y.P(y)]

Proof: Give countermodel, where


z [Q(z)  P(z)] is true, Find a domain,
and a predicate.
but x.Q(x)  y.P(y) is false.

In this example, let domain be integers,


Q(z) be true if z is an even number, i.e. Q(z)=even(z)
P(z) be true if z is an odd number, i.e. P(z)=odd(z)

Then z [Q(z)  P(z)] is true, because every number is either even or odd.
But x.Q(x) is not true, since not every number is an even number.

Similarly y.P(y) is not true, and so x.Q(x)  y.P(y) is not true.


Valid Rule?

z D [Q(z)  P(z)] → [x D Q(x)  y D P(y)]

Proof: Assume z [Q(z)P(z)].


So Q(z)P(z) holds for all z in the domain D.
Now let c be some element in the domain D.
So Q(c)P(c) holds (by instantiation), and therefore Q(c) by itself holds.
But c could have been any element of the domain D.
So we conclude x.Q(x). (by generalization)
We conclude y.P(y) similarly (by generalization). Therefore,
x.Q(x)  y.P(y) QED.
Summary

This finishes the introduction to logic, half of the first part.

In the other half we will use logic to do mathematical proofs.

At this point, you should be able to:

• Express (quantified) statements using logic formula

• Use simple logic rules (e.g. DeMorgan, contrapositive, etc)

• Fluent with arguments and logical equivalence

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy