Logic - My MVNU

advertisement
Discrete Mathematics
Jim Skon
Mount Vernon Nazarene College
Chapter 1
Logic - Elementary Discrete Math
1
Discrete Mathematics
 Discrete - "Consisting of unconnected
parts"
 Discrete/Continuous Math


pieces of ice vs. liquid water
Letter grade vs. gpa
Logic - Elementary Discrete Math
2
Discrete Mathematics
 Applications of discrete
mathematics:








Formal Languages (computer languages)
Compiler Design
Data Structures
Computability
Automata Theory
Algorithm Design
Relational Database Theory
Complexity Theory (counting)
Logic - Elementary Discrete Math
3
Discrete Mathematics
 Example (counting):


The Traveling Salesman Problem
Important in
• circuit design
• many other CS problems
Logic - Elementary Discrete Math
4
The Traveling Salesman Problem
 Given:
 n cities c1 , c2 , . . . , cn
 distance between city i and j, dij
 Find the shortest tour.
3
b
a
5
2
c
7
dab = 3
4
d
Logic - Elementary Discrete Math
5
The Traveling Salesman Problem
 Assume a very fast PC:
 1 flop = 1 nanosecond
= 10 -9 sec.
= 1,000,000,000 ops/sec
= 1 GHz.
Logic - Elementary Discrete Math
6
The Traveling Salesman Problem
 A tour requires n-1 additions. How many
different tours?




Choose the first city n ways,
the second city n-1 ways,
the third city n-2 ways,
etc.
3
b
a
5
2
c
7
Logic - Elementary Discrete Math
4
d
7
The Traveling Salesman Problem
 Total number of tours

n (n-1) (n-2) . . . .(2) (1) = n!
(Combinations)
 Total number of additions

(n-1) n! (Rule of Product)
Logic - Elementary Discrete Math
8
The Traveling Salesman Problem
 If n = 8,

T(n) = 78! = 282,240 flops < 1/3 second.
 HOWEVER
Logic - Elementary Discrete Math
9
The Traveling Salesman Problem
 If n=50,

T(n) = 49  50!
= 1.48  10 66
= 1.49  10 57 seconds
= 2.48  10 55 minutes
= 4.13  10 53 hours
= 1.72  10 52 days
= 2.46  10 51 weeks
= 4.73  10 49 years.
Logic - Elementary Discrete Math
10
The Traveling Salesman Problem
 ...a long time. You’ll be an old person
before it’s finished.
 There are some problems for which we
do not know if efficient algorithms exist
to solve them!
Logic - Elementary Discrete Math
11
Propositions
 An assertion which is either true (or 1) or
false (or 0).








Today is Wednesday.
Some dogs each fish.
4+2=5
There exists a person who can run 100 mph.
The number of hairs on Bill Clinton’s head is
5,543,234,123.
Every natural number can be written as the sum of the
squares of four natural numbers.
The equation xn + yn = zn where n > 2 and x, y, and z
are positive integers has no solutions. (Fermat’s last
Theorem)
Every even number greater then 4 can be written as the
Logic - Elementary Discrete Math
12
sum of two prime
numbers.
Propositions
 Now consider:
• a. Give me my book. (Imperative)
• b. What is my test score? (Interrogative)
• c. Four score and seven years ago (Clause)
Logic - Elementary Discrete Math
13
Logical Connectives
 Consider




I like rock and I like classical.
I’ll either eat at Jody’s or I will go to class.
I did not do my homework today.
I will either ride will Bill or I will walk
tomorrow, but not both.
Logic - Elementary Discrete Math
14
Logical Connectives
 Proposition - Any sentence with a truth
value
 Simple Proposition - No connectives
 Compound Proposition - made up of one or
more simple Propositions linked together
by connectives.
Logic - Elementary Discrete Math
15
Logical Connectives
 Examples:




I like pop music and I like classical music.
I got an A in English or I got an B in
Philosophy.
You did not bring me what I wanted.
If you see my mother, then tell her where I am.
Logic - Elementary Discrete Math
16
Logical Connectives
 4 basic connectives
Connective
not
and
or
if..then..
Notation




Name of Connective
negation
conjunction
disjunction
conditional, implication
Logic - Elementary Discrete Math
17
Logical Connectives
 Sentence form statements may be translated
to symbolic form:
• If today is Wednesday and the time is 10:30 am then
we should all be in chapel.
P: today is Wednesday
Q: time is 10:30 am
R: We should all be in chapel
(P  Q)  R
Logic - Elementary Discrete Math
18
Logical Connectives
 It is false that roses are red and violets are
blue.


P: roses are red
Q: violets are blue
(p q)
Logic - Elementary Discrete Math
19
Truth Tables:
 Negation


‘not’
Symbol: 
 Example:
Negation
p p
T F
F T
P: I am going to town
P:
I am not going to town;
It is not the case that I am going to town;
I ain’t goin’.
Logic - Elementary Discrete Math
20
Truth Tables:
 Disjunction


inclusive ‘or’
Symbol: 
 Example:



P - ‘I am going to
town’
Q - ‘It is going to rain’
PQ: ‘I am going to
town or it is going to
rain.’
Logic - Elementary Discrete Math
Disjunction
p q pq
T T
T
T F
T
F T
T
F F
F
21
Truth Tables:
 Conjunction


‘and’
Symbol: 
 Example:
P - ‘I am going to town’
Q - ‘It is going to rain’
PQ: ‘I am going to town and it is
going to rain.’
Logic - Elementary Discrete Math
Conjunction
p q pq
T T
T
T F
F
F T
F
F F
F
22
Truth Tables:
 Exclusive OR

Symbol:
 Example:
Exclusive Or
p q pq
T T
F
T F
T
F T
T
F F
F
P - ‘I am going to town’
Q - ‘It is going to rain’
PQ: ‘Either I am going to town or it
is going to rain.’
Logic - Elementary Discrete Math
23
Truth Tables:
 Implication


Implication
‘If...then...’
Symbol: 
p
T
T
F
F
 Example:
P - ‘I am going to town’
Q - ‘It is going to rain’
P Q: ‘If I am going to town then it is
going to rain.’
Logic - Elementary Discrete Math
q
T
F
T
F
pq
T
F
T
T
24
Implication
 Equivalent forms:








Implication
p
If P, then Q
T
P implies Q
T
If P, Q
F
P only if Q
P is a sufficient condition for Q F
Q if P
Q whenever P
Q is a necessary condition for P
q
T
F
T
F
pq
T
F
T
T
 Note: The implication is false only when
P is true and Q is false!
Logic - Elementary Discrete Math
25
Implication
 The implication p  q is the proposition that is
false when p is true and q is false and true
otherwise.
 p is called the hypothesis (or antecedent or
premise)
 q is called the conclusion (or consequence)
Conditional
p q pq
T T
T
T F
F
F T
T
F F
T
Logic - Elementary Discrete Math
26
Implication
 Consider






If it is sunny, class will meet in the grove
If today is Saturday, then we will all play leap
frog.
If x is even then x2 is even
If the moon is made of green cheese then I
have more money than Bill Gates
If the moon is made of green cheese then
I’m on welfare
If 1+1=3 then your grandma wears combat
boots
Logic - Elementary Discrete Math
27
Implication




implication
converse
inverse
contrapositive
PQ
QP
P   Q
QP
QP is the CONVERSE of P Q
QP is the CONTRAPOSITIVE of P Q
Logic - Elementary Discrete Math
28
Implication
implication
converse
inverse
contrapositive
PQ
QP
P   Q
QP
 If it's after 10:00, then I will go to bed.
 If I go to bed, then it is after 10:00.
 If it's not after 10:00 then I will not go to
bed.
 If I do not go to bed, then it is not after
10:00.
Logic - Elementary Discrete Math
29
Implication
 Find the converse and contrapositive of the
following statement:
R: ‘Raining tomorrow is a sufficient condition
for my not going to town.’
Logic - Elementary Discrete Math
30
Implication
Step 1: Assign propositional variables to
component propositions
P: It will rain tomorrow
Q: I will not go to town
Logic - Elementary Discrete Math
31
Implication
Step 2: Symbolize the assertion
R: PQ
Step 3: Symbolize the converse
QP
Logic - Elementary Discrete Math
32
Implication
Step 4: Convert the symbols back into
words
‘If I don’t go to town then it will rain tomorrow’
or
‘Raining tomorrow is a necessary condition
for my not going to town.’
or
‘My not going to town is a sufficient condition
for it raining tomorrow.’
Logic - Elementary Discrete Math
33
Implication
p
T
T
F
F
q
T
F
T
F
p
F
F
T
T
implication
q
pq
F
T
T
F
F
T
T
T
converse inverse
qp pq
T
T
T
T
F
F
T
T
contrapositive
qp
T
F
T
T
 Therefore:
p  q   q   p, implication  contrapositive
q  p   p   q,
converse  inverse
Logic - Elementary Discrete Math
34
Examples
 Make a truth table for:





pq
(p   q)  r
(p  q)  r
(p  q)  (r   q)
pq
Logic - Elementary Discrete Math
35
Logical Connectives
 Put in symbolic form:





I am not a mathematician.
I am not a mathematician and 2 + 2 = 5.
If I am not a mathematician then 2 + 2 = 5.
If it is raining, then I will not go to the store,
and if it is not raining, then I will go to the
store.
Either Frank love Mary, or Mary loves Frank,
but not both.
Logic - Elementary Discrete Math
36
Examples
1. MVNC is in Mt. Vernon or Mt. Vernon is in
Russia.
2. MVNC is in Ohio and Lake Erie is in Florida.
3. If MVNC is in Ohio then Mt. Vernon is in Ohio.
4. If MVNC is in Ohio then Mt. Vernon is made of
cheese.
5. If MVNC is a military school then Mt. Vernon is
in Ohio.
6. If MVNC is a military school then Mt. Vernon is
made of cheese.
Logic - Elementary Discrete Math
37
Examples
 Let p = True, q = False, r = True.




pq
( p   q)  r
(p  q)  ( p  q)
(p  q)  (r   p)
Logic - Elementary Discrete Math
38
Logical Equivalence
 How about:
If x = 2, then x2 = 4
2
 If x is positive and x = 4,
then x = 2
2
 If n is odd, then n is odd

Logic - Elementary Discrete Math
39
Implication











p  q may be stated as:
"if p then q"
"p only if q"
"p is a sufficient condition for q"
"q is a necessary condition for p"
"a necessary condition for p is q"
"a sufficient condition for q is p"
"q if p"
"q follows from p"
"q is a logical consequence of p"
"q whenever p"
Logic - Elementary Discrete Math
40
Translating English Sentences
 You cannot take CS II if you have not taken
CS or have not passed a c proficiency exam
 Try 1.1:problem 5
Logic - Elementary Discrete Math
41
Propositional Variables
 A proposition can also be represented as a
variable.
• Use lower case for numeric variables.
• Use upper case for propositional variables.
• Example:
– Let p be “Today is Wednesday.”
– Let p be “I like to eat in the MVNC cafeteria.”
– Let p be “1 = 3”
Logic - Elementary Discrete Math
42
Biconditional
 Let p and q be propositions.
 The biconditional p  q is the proposition that is
true when p and q have the same truth values, and
false otherwise.
 It is BOTH the implication AND its converse
 Ex: “I will eat in the cafeteria if and only if they
have pizza.”
biconditional
p q pq
T T T
T F F
F T F
F Discrete
T Math
LogicF
- Elementary
43
Translating to English sentences
 p: you like eating candy
 q: you lose your teeth
pq
 p  q
 (p  q)  p  q

Logic - Elementary Discrete Math
44
Logic and Bit Operations
 bit - two values: 0 or 1
 bit can be used to store truth values


0 = false
1 = true
 Thus logic operators can apply
Logic - Elementary Discrete Math
45
Bit operation Truth Tables:
Negation
p p
1 0
0 1
Disjunction
p q pq
1 1
1
1 0
1
0 1
1
0 0
0
Conjunction
p q pq
1 1
1
1 0
0
0 1
0
0 0
0
Exclusive OR
p q pq
1 1
0
1 0
1
0 1
1
0 0
0
Logic - Elementary Discrete Math
46
Bit Strings
 A bit string is a sequence of zero or more
0’s and 1’s
 Example





0100010010
00111011
1111111111111
00100100000010101
0
Logic - Elementary Discrete Math
47
Bit Strings
 Bit operations can be extended to bit strings
 example:
01000101
00111101
00000101 bitwise and
01111101 bitwise or
01111000 bitwise xor
Logic - Elementary Discrete Math
48
Propositional Equivalences
 Tautology - true for any values assigned to
it's variables
 Contradiction - never true, irregardless of
values of variables.
 Consider


I will either get a new car, or I won’t get a new
car.
I will come tomorrow and I won’t come
tomorrow
Logic - Elementary Discrete Math
49
Propositional Equivalences
Examples
p p
F T
T F
p  p
T
p  p
F
T
Tautology
F
Contradiction
Logic - Elementary Discrete Math
50
Propositional Equivalences
 Tautologies are logically true.
 Contradictions are logically false.
 Such statements are true or false because of
it's structure rather then because of it's
variables truth values.
Logic - Elementary Discrete Math
51
Propositional Equivalences
 Consider:
p  (q  p)
(p  q)   (p  q)
Logic - Elementary Discrete Math
52
Logical Equivalence
 Two compound statements are logically
equivalent if they always have the same
truth value.
 Two compound statements are logically
equivalent if they have the same truth
tables.
 If p and q are logically equivalent, then:
pq
Logic - Elementary Discrete Math
53
Logical Equivalence
 Consider:
 (p  q)  (p  q)
Logic - Elementary Discrete Math
54
Logical Equivalence
 Logical Identities


Useful properties of logic
Similar to the properties of Algebra
Logic - Elementary Discrete Math
55
Logical Equivalence
 Properties of Identity and Dominance:
pFp , pTp
pTT, pFF
 The idempotent properties:
ppp , ppp
Logic - Elementary Discrete Math
56
Logical Equivalence
 The commutative properties:
pqqp
pqqp
 The associative properties:
p  (q  r)  (p  q)  r
p  (q  r)  (p  q)  r
Logic - Elementary Discrete Math
57
Logical Equivalence
 The distributive properties:
p  (q  r)  (p  q)  (p  r)
p  (q  r)  (p  q)  (p  r)
Logic - Elementary Discrete Math
58
Logical Equivalence
 properties of Complement:
T  F , F  T
p  p  T , p  p  F
 (p)  p
Logic - Elementary Discrete Math
59
Logical Equivalence
 Demorgan's laws:
(p  q)  p  q
(p  q)  p  q
Logic - Elementary Discrete Math
60
Logical Equivalence
 Implication
p  q  p  q
 Negation of Implication
(p q)  p  q
Logic - Elementary Discrete Math
61
Logical Equivalence
 If and only if
p  q  (p  q)  (q  p)
Logic - Elementary Discrete Math
62
Logical Equivalence
 By Demorgan's law the negation of

I don’t like to eat apples
and I don’t like to walk.
 becomes

It's not true that I like to eat
apples or I don't like to
walk.
Logic - Elementary Discrete Math
63
Logical Equivalence
 Examples:

Try 1.2: 7, 9, 11, 13, 15, 17, 19
Logic - Elementary Discrete Math
64
Logical Equivalence
 Notice that:
p  q  (p q)  (q  p)
 In order to prove a biconditional statement P
 Q, we must only prove the statement
p  q,
and it's converse
q  p.
(Or perhaps by proving the inverse and the contrapositive).
Logic - Elementary Discrete Math
65
Propositions
 Free Variables


A proposition may contain variable - values not
yet assigned.
Variables must be assigned values before the
truth value can be assessed.
 Examples




x + y = 11
Car m the faster then car n.
There are x people in this room.
I have h hairs on my head.
Logic - Elementary Discrete Math
66
Propositions as Functions
 A proposition with variables can be written
as a function:




x2 > 4
x + 3y2 + 8 = y + 2x2 - 15
x is the mother of y
Student a is in the b class
and lives in apartment c.
P(x)
Q(x, y)
M(x, y)
S(a, b, c)
 How would we write:



32 > 4
Sally is Bill's mother
3 + 3(2)2 + 8 = 5 + 2(3)2 - 15
Logic - Elementary Discrete Math
67
Existential Quantification
 Consider the proposition:

There is a person in this class with a
January birthday.
 Existentially quantified expression:

$x : (x is in this class and x has a January
birthday)
Logic - Elementary Discrete Math
68
Existential Quantification
 Consider again:

There is a person in this class with a
January birthday.
 Existentially quantified expression:
$x : ( C(x)  JBD(x) )
 Read "There exists an x such that C(x) and
JBD(x) are true.
Logic - Elementary Discrete Math
69
Existential Quantification
 $ - existential quantifier
 $x : - x is a bound variable
 $x : P - existentially quantified
proposition
Logic - Elementary Discrete Math
70
Existential Quantification
 To show that an existentially quantified
proposition $x : P is true, you must only
find a single example of x which makes P
true.
 To show that an existentially quantified
proposition $x : P is false, you must show
that x possible values of x makes P false.
Logic - Elementary Discrete Math
71
Universal Quantification
 Consider the proposition:

Every student eating in the MVNC
cafeteria must either have a meal
ticket, or have paid at the door.
 Universal quantified expression:

"s : if s is eating in the cafeteria
s has a meal ticket or s paid at the
door.
Logic - Elementary Discrete Math
72
Universal Quantification
 Consider again:

Every student eating in the MVNC
cafeteria must either have a meal
ticket, or have paid at the door.
 Functions:



s eating in the cafeteria
s has a meal ticket
s paid at the door
C(s)
MT(s)
PAID(s)
 Existentially quantified expression
"s : (C(s)  (MT(s)  PAID(s) ) )
Logic - Elementary Discrete Math
73
Universal Quantification
 Every student eating in the MVNC
cafeteria must either have a meal
ticket, or have paid at the door.
 Universally quantified expression
"s : (C(s)  (MT(s)  PAID(s) ) )
 Read "For every student s, if s is eating in
the cafeteria then s has a meal ticket or s has
paid at the door.
Logic - Elementary Discrete Math
74
Universal Quantification
 " - universal quantifier
 "x : - x is a bound variable
 "x : P(x) - universally
quantified proposition
Logic - Elementary Discrete Math
75
Universal Quantification
 To show that an universally quantified
proposition "x : P is true, you must show
that P holds for all values of x .
 To show that an universally quantified
proposition "x : P is false, you must only
show at least one x for which P is false (a
counter example)
Logic - Elementary Discrete Math
76
Quantification
 Consider:








For every x, x2 > 4 if and only if x > 2 or x < -2.
There exists a number that equals it own square
For every number x > 1, there exists a number y
where x < y < 2x.
There exists a number x such that for every y, y2 > x.
Everybody has a mother and a father.
Tom and Harry have the same mother.
Nobody is their own mother.
Peter has no children.
Logic - Elementary Discrete Math
77
Universal Quantification
 The following ranger over the real numbers:
$x:"y: x + y = y.
"x:$y: x + y = y.
"x:"y: x + y = y.
$x:$y: x + y = y.

Logic - Elementary Discrete Math
78
Universal Quantification
 The following range over the integers:
"x:"y:
=
x = -y).
$x:$y: (x = y  x > y).
"x:$y: (x = y  x > y).
2
(x
2
y 
Logic - Elementary Discrete Math
79
Negations of Quantified
Propositions
 Let P be a proposition. Then:
"x:P  $x:P
$x:P  "x:P
Logic - Elementary Discrete Math
80
Negations of Quantified
Propositions
 Consider:

There is a student in this class with a January
birthday.
$x: JB(x)

It is not true that there is a a student in this class
with a January birthday.
$x: JB(x)  "x: JB(x)
Logic - Elementary Discrete Math
81
Negations of Quantified
Propositions

Expand domain to include all students:
$x: CL(x)  JB(x)
 "x:  (CL(x)  JB(x) )
 "x: CL(x)  JB(x)
Logic - Elementary Discrete Math
82
  
Logic - Elementary Discrete Math
83
Download