Chapter 2
Symbolic Logic
1
Section 2-1
Truth, Equivalence and Implication
2
More on Implication
Universal Implication: A statement p implies a
statement q, if q is true in every situation that
makes p true. pq
EX: (x>2) (x>1)
3
More on Implication
Ex:
Show that p ^ q implies p V (¬p ^ q)
4
Def.
A universally true statement is true for each
element of the universe.
Ex:
Universe: Flipping 2 coins.
- if there is exactly one tail then there is exactly
one head.
The above statement is a universally true
statement.
5
Tautology
A tautologically true statement is a statement
that is always true ( it can be written as a
symbolic statement whose truth table has
only Trues in the final column).
Ex: “The result has 2 H’s or the result doesn’t
have 2 H’s” ( p V ¬p)
The statement is always true (tautology).
6
Contradiction
A statement that is always false.
Ex: p ^ ¬ p is always false ( a contradiction).
7
Example
p is the statement: x<=0
q is the statement: x>=10
Universe: R
Show that ¬(p V q) and ¬p ^ ¬q are
equivalent.
8
Section 2.3
Predicate Logic
Propositional logic cannot adequately express
statements in mathematics and natural
language.
Statements involving variables such that:
X>3 , x=y+3 , x+y=z
Computer x is under attack by an intruder
Statements like these are often found in mathematical assertions,
computer programs and system specifications.
9
Propositional Logic
In propositional logic we used symbols to
represent simple statements ( p, q, r, s)
we also used symbols and logical
connectives ( V, ^, , ⊕, ¬ ) to represent
compound statements.
10
Predicate Logic
A predicate is a function that always evaluates to
either true or false.
A predicate has the form:
Predicate-name( List of Arguments).
Ex:
x is a positive number
Predicate: positive number (x)
Positive number (5)= True
Positive number (-5)= False
11
Predicate Logic
Ex:
“ 5 is greater than 2”
We define the predicate greater than as:
Greater than( x, y): x>y
P (x, y): x>y
P(2,5)= False
P(5,2)= True
12
Predicate Logic
1- Uses predicates to represent simple
statements.
2- Uses Logical connectives ( V, ^, , ⊕, ¬ )
3- Quantifiers:
Universal quantifier:
Existential quantifier:
4- Variables: x, y, z….. .
13
Predicate Logic
- Quantifiers are used to express the extent to
which a predicate is true over a range of
elements.
- Domain is important when quantifiers are
used
- and have higher priority than all logical
operators from propositional logic
Ex: x p(x) ∨ q(x) === (x p(x)) ∨ q(x)
14
Predicate Logic
Ex: Consider the statement “ x is greater than 14”.
Predicate: p( x, y): x>y
P( x,14): x>14
- There is a value greater than 14 is represented
as .........
- All values are greater than 14 is represented as
……….
- All values are less than 14 as……………..
15
Predicate Logic
Ex:
Element x belongs to set A.
B (x, A): Element x belongs to set A.
- Every element in A belongs also to B is
represented as: x [ b( x, A) b( x, B)]
16
Free and Bound variables
The variable x is said to be bound by x or
by x if x lies in the scope of the quantifier.
A variable that is not bound by a quantifier is
said to be free.
17
Free and Bound Variables
Ex: Below, describe the scope of each quantifier, and
describe which variables are bound and which are
free.
- x ( p (x) ^ y (t( x, y) ^ r(x)))
No free variables.
- ¬ x (p(x) ^ y (t(x,y)) V r(z))
Z is free.
- ¬ x (p(x) ^ y (t(x,y)) V r(y)).
Y in t(x,y) is bound but the y in r(y) is free.
18
Free and Bound Variables
Ex:
- x [ b( x, A)] b( x, B)
Means: If A is the universe, x belongs to B.
What is the scope of the quantifier?
- x [ b( x, A)] x [b( x, B)]
It means: If A is the universe then B is the
universe.
19
Predicate Logic
Ex:
Assume b(x,A) represents the statement “x belongs to A”.
Represent each of the following in predicate logic:
- 2 belongs to S.
- 1 belongs to A and 2 belongs to B.
- All elements in A are positive.
- There is an element in A that is not in B.
- There is an element in A that is greater then any element in B.
- A is a subset in B.
20
Predicate Logic ( quantifiers)
The statement x s(x) is true iff s is true for
every element in the universe.
The statement x s(x) is true iff s is true for at
least one element in the universe.
21
Predicate Logic (quantifiers)
Ex: Suppose
Universe: the set of +ve integers
s(x) represents “x is an even integer”
p(x) represents “x is a prime integer”
r(x) represents “ x>2”
Which of the following are true and which are false?
- x p(x)
- x p(x)
- x (p(x) ^ s(x))
- x (p(x) ^ s(x) ^ r(x))
- x (s(x) p(x))
- x (p(x) s(x))
- x (p(x) s(x))
- x [(r(x)^s(x))p(x)]
22
Predicate Logic (quantifiers)
Ex: Suppose
Universe: the set of +ve integers
s(x) represents “x is an even integer”
p(x) represents “x is a prime integer”
r(x) represents “ x>2”
Which of the following are true and which are false?
- x p(x) …. True( try x=2)
- x p(x) …. False (try x=4)
- x (p(x) ^ s(x)) … true ( x=2)
- x (p(x) ^ s(x) ^ r(x)) …false
- x (s(x) p(x))…false ( try x=4)
- x (p(x) s(x))…false (try x=3)
- x (p(x) s(x))… true (x=2)
- x [(r(x)^s(x))p(x)] …. true(x=2)
23
Equivalence
Two statements p and q in predicate logic
are equivalent if for any universe and for any
statements about the universe we substitute
for p,q the resulting statements about the
universe are equivalent.
24
Equivalence Rules
The following quantified statements are equivalent.
- x(¬ s (x)) ↔ ¬ x (s (x))
- (x s(x)) ^t(y) ↔ x (s(x) ^t(y))
- (x s(x)) ^t(y) ↔ x (s(x) ^t(y))
- (x s(x)) v t(y) ↔ x (s(x) v t(y))
- (x s(x)) v t(y) ↔ x (s(x) v t(y))
- [x p(x)] ^ [x q(x)] ↔ x [p(x) ^ q(x)]
- [x p(x)] v [z q(z)] ↔ x [p(x) v q(x)]
25
Equivalence
Ex:
- [w p(w)] ^ [w q(w)]
- w [p(w) ^ q(w)]
Are they equivalent? Why?
26
Equivalence
Ex:
- y [x p(x,y)]
- x [y p(x,y)]
Are they equivalent? Why?
27
Equivalence
(negating quantified expressions)
x(¬ s (x)) is equivalent to ¬ x (s (x))
¬ x p(x) is equivalent to x ¬ p(x)
28
Example
Demorgan’s Law for quantifiers
Negation Equivalent When is When
statement negation false?
ture?
¬ x p(x) x ¬p(x) For every x, There is an
p(x) is false x for which
p(x) is true
¬ x p(x) x ¬p(x) There is an P(x) is true
x for which for every x
p(x) is false
29
Example
Show that the following are logically
equivalent:
¬ x (p(x) q(x)) and x (p(x) ^ ¬ q(x))
30
Note
We can distribute over ^ but not vice versa
also we can distribute over v
31
Translating from English into
logical expressions
Express the statements:
1- a. Some students in class have visited Italy
b. What if we are interested in people other than those in class ( different
universe) ?
2- a. Every student in this class has visited
either Austria or Italy
b. Again, what if the domain (universe) consists of all people?
32
Translating from English into
logical expressions
Solution
1- a. x L(x)
b. x (L(x) ^ S(x))
caution: x (S(x) L(x)) is wrong, why?
Hint: think of someone not in class
2- a. x (L(x) v A(x))
b. x (S(x) L(x) v A(x))
Could we use one predicate for visiting Italy or
33 Austria? How?
Using quantifiers in system
specifications
Use predicates and quantifiers to express the
system specifications
1- Every mail message larger than one
megabyte will be compressed
2- If a user is active, at least one network link
will be available
34
Using quantifiers in system
specifications
Solution
1- m (S(m,1) C(m))
2- u A(u) n S(n , available)
35
Exercise
Consider the following statements:
- All lions are fierce
- Some lions do not drink coffee
- Some fierce creatures do not drink coffee
- p(x): x is a lion q(x): x is fierce
r(x): x drinks coffee
Express the given statements using the above
Predicates (Example 26 page 50,51)
36
Programming by Logic (prolog)
Prolog has facts and rules (used to define new predicates using those
already defined)
instructor(chan, math273).
instructor(patel, ee222).
instructor(grossman, cs301).
enrolled(kevin, math273).
enrolled(juana, ee222).
enrolled(juana, cs301).
enrolled(kiko, math273).
enrolled(kiko, cs301).
teaches(P, S) <= instructor(P, C) , enrolled(S, C).
? enrolled(kevin, math273) Produces the response: yes
? enrolled(x , math273) Produces the response: Kevin Kiko
?teaches(x, Juana) Produces the response: Patel Grossman
37
Section 2.2
Proof Methods:
- Direct proof
- Indirect proofs:
a- Contra positive inference
b- Proof by contradiction
38
Converses
The statement qp is the converse of the
statement pq.
If pq is true, it does not mean that qp is
true.
-Ex:
-If n is a positive even integer, then n>1. (pq)
- 5>1, then 5 is a positive even integer
(qp)....false
39
Counter-example
To show that a statement is theorem we give
a proof.
To show that a statement is false (not
theorem), we give a counter-example.
Ex:
“ If n is a positive integer, then n >5”
Counter-example: n=4 (positive and <5)
40
Direct proof or principle of direct
inference (also called modus ponens)
If we know that r is true, and rs is true, we conclude that s is true.
A direct proof has the form:
Statement1
Statement 2
.
.
.
Statement n
Where statement n is the one we want to prove and each other statement
is:
a- a hypothesis
b- an accepted mathematical fact
c- the result of applying direct inference to earlier statements
41
Direct proof
Ex:
Prove that if the integers n and m are each
multiple of 3, then m+n is a multiple of 3.
Note: The word assume precedes the
hypothesis and the words ( therefore, then)
precedes the inference.
42
Contra positive Inference
To show that pq, we show that ¬q¬p
Ex:
Prove that for each number n of the universe of
positive integers, if n2 >100 then n>10.
43
Proof by Contradiction
From p and p^¬q¬p we conclude q.
If assuming that ¬q leads to contradiction,
the q is true.
Ex:
Prove that if x2 +x-2 =0 then x ≠ 0
44
Example
Show that if the following statements are true
p
pq
qr
rs
Then s is also true.
(Prove it by both direct and contradiction).
45
Proof by Contrapositive
Note:
There are plenty of examples of statements which
are hard to prove directly, but whose contrapositive
can easily be proved directly. This is all that proof by
contrapositive does.
It gives a direct proof of the contrapositive of the
implication. This is enough because the
contrapositive is logically equivalent to the original
implication.
Recall that an implication p→q is logically equivalent
46 to its contrapositive ¬q→¬p
Example
Prove:
for all integers a and b, if a+b is odd, then a is odd or b
is odd (but not both).
Note:
The problem with trying a direct proof is that it will be hard to
separate a and b from knowing something about a+b.
On the other hand, if we know something about a and b
separately, then combining them might give us information about
a+b. The contrapositive of the statement we are trying to prove is:
for all integers a and b, if a and b are even, then a+b is even.
47
Proof by contradiction
Note:
There might be statements which really cannot be rephrased as
implications (not easy to prove them by direct proof or by
contrapositive inference(.
If we can prove that ¬p leads to a contradiction, then the only
conclusion is that ¬p is false, so p is true.
Proof by contradiction can be applied to a much broader class of
statements than proof by contraposition, which only works for
implications.
There are proofs of implications by contradiction that cannot be directly
rephrased into proofs by contraposition
The key benefit of proof by contradiction is that you can stop when you
find any contradiction, not only a contradiction directly involving the
48 hypotheses.
Example
Prove:
There are no integers x and y such that
x2=4y+2.
49
Example
Prove:
If x is a multiple of 6 then x is a multiple of 2
50