Slides for Rosen, 5th editionDiscrete Mathematics & Its
Applications (5th Edition)
by Kenneth H. Rosen
*
*
A word about organization: Since different courses have different
lengths of lecture periods, and different instructors go at
different paces, rather than dividing the material up into
fixed-length lectures, we will divide it up into “modules” which
correspond to major topic areas and will generally take 1-3
lectures to cover. Within modules, we have smaller “topics”. Within
topics are individual slides. The instructor can bring several
modules to each lecture with him, to make sure he has enough
material to fill the lecture, or in case he wants to preview or
review slides from upcoming or recent past lectures.
(c)2001-2002, Michael P. Frank
*
*
In Spring 2003 I spent 7 fifty-minute lecture periods on this
material, but two half-lectures were taken up by team selection and
a quiz, so it really only took 6 lectures.
(c)2001-2002, Michael P. Frank
(§§1.1-1.3, ~3 lectures)
Logika Matematika adalah sebuah tools untuk memahami hubungan yang
terkait dengan kalimat majemuk (compound statements). Meliputi
:
Formal language untuk ekspresi.
Sebagai fondasi untuk ekspresi pembuktian formal pada semua cabang
matematika lainnya.
Discrete Math - Module #1 - Logic
Discrete Math - Module #1 - Logic
*
*
menggunakan Boolean connectives.
Expressing conditions in programs.
Topic #1 – Propositional Logic
*
*
We normally attribute propositional logic to George Boole, who
first formalized it. Actually the particular formal notation we
will present is not precisely Boole’s; he originally spoke of logic
in terms of sets, not propositions, and he also used Boolean
algebra notation such as AB, A+B, rather than the A /\ B, A \/ B
notation we will use. But, he was the first to mathematically
formalize these kinds of concepts in preserved writings. Boole’s
formalization of logic was developed further by the philosopher
Frege.
However, even though logic was not formalized as such until the
1800’s, the basic ideas of it go all the way back to the ancient
Greeks. Aristotle (ca. 384-322 B.C.) developed a detailed system of
logic (though one that was not quite as convenient and powerful as
the modern one), and Chrysippus of Soli (ca. 281-205 B.C.)
introduced a logic centered around logic AND, inclusive and
exclusive OR, NOT, and implication, similarly to Boole’s.
Chrysippus’ logic apparently included all of the key rules that
Boole’s logic had. However, his original works were unfortunately
lost; we only have fragments quoted by other authors.
(c)2001-2002, Michael P. Frank
Definisi dari Proposisi
Definition: Sebuah proposisi (dgn notasi p, q, r, …), secara
sederhananya adalah :
Sebuah statement (i.e., a declarative sentence)
Dengan makna yang jelas tidak bersifat makna ganda atau kabur
(definite meaning, not vague or ambiguous)
Memiliki salah satu nilai kebenaran (truth value), baik itu true
(T) atau false (F)
Tidak keduanya, atau dua-duanya, atau diantara keduanya. Hanya
boleh salah satu.
Pada bidang bahasan lain (probability theory),dimungkinkan adanya
derajat kepastian (degrees of certainty, antara T dan F) pada
sebuah proposisi.
Namun saat ini yang diperhatikan : kepastian terhadap nilai
kebenaran, yaitu True atau False.
Topic #1 – Propositional Logic
*
“Jakarta adalah ibukota Indonesia”
“Siapakah mereka ?” (interrogative, question)
“Kerjakan !” (imperative, command)
“1 + 2” (expression with a non-true/false value)
Topic #1 – Propositional Logic
*
Unary operators, hanya 1 operand (mis: −3);
Binary operators memerlukan 2 operands (mis : 3 4).
Operators / Connectives
*
*
Later in the course, we will see that operators can themselves be
defined in terms of functions. This slide doesn’t define them that
way because we haven’t defined functions yet. But for your
reference, when you come back to study this section after learning
about functions, in general, an n-ary operator O on any set S (the
domain of the operator) is a function O:S^n->S mapping n-tuples
of members of S (the operands) to members of S. “S^n” here denotes
S with n as a superscript, that is, the nth Cartesian power of S.
All this will be defined later when we talk about set theory.
For Boolean operators, the set we are dealing with is
B={True,False}.
A unary Boolean operator U is a function U:B->B, while a binary
Boolean operator T is a function T:(B,B)->B.
Binary operators are conventionally written in between their
operands, while unary operators are usually written in front of
their operands. (One exception is the post-increment and
post-decrement operators in C/C++/Java, which are written after
their operands.)
(c)2001-2002, Michael P. Frank
Formal Name
*
*
*
For fun, try writing down the truth tables for each of the 4
possible unary operators, and each of the 16 possible binary
operators. For each one, try to come up with an English description
of the operator that conveys its meaning. Also, figure out a way to
define it in terms of other operators we already introduced.
(c)2001-2002, Michael P. Frank
*
Sebuah bit adalah biner (base 2) : digit: 0 atau 1.
Bits dapat pula digunakan untuk representasi nilai kebenaran.
Konvensi:
0 representasi “false”; 1 representasi “true”.
Aljabar Boolean adalah sebuah aljabar dengan dasar variabel pada
operasi bit, dimana + artinya “or”, dan X artiya “and”.
Dibahas lebih detail dibagian khusus Ajabar Boolean.
Topic #2 – Bits
*
*
Bits can also be defined in terms of sets, if you like, by the
convention that the empty set {} represents 0, and the set
containing the empty set {{}} represents 1. Or more generally, any
two distinct objects can represent the two bit-values or
truth-values.
(c)2001-2002, Michael P. Frank
Bit Strings
Sebuah Bit string dengan panjang n adalah sebuah urutan (series,
tuple) dari n 0 bits.
Sesuai konvensi, bit strings ditulis/dibaca dari arah kiri ke kanan
(left to right):
Bit pertama dari string “1001101010” adalah 1.
Bila sebuah bit string adalah representasi dari bilangan dasar
2,maka secara konvensi leftmost bit adalah the most significant
bit.
Ex. 11012=8+4+1=13.
Topic #2 – Bits
*
*
We will talk about strings more generally later in the module on
sequences.
(c)2001-2002, Michael P. Frank
Bitwise Operations
Operasi Boolean dapat pula diterapkan pada strings bit atau bit
tunggal.
01 1011 0110
11 0001 1101
Topic #2 – Bits
*
*
The answers are present, but hidden, as white text on a white
background. The slide can be done in class as an exercise, with the
instructor typing in the students’ answers in the space provided.
Then the correct answers can be revealed by selecting the bottom 3
rows and changing their font color unconditionally to black.
(c)2001-2002, Michael P. Frank
*
Propositional Equivalence (§1.2)
Dua buah proposisi secara sintaks (penulisan) bisa jadi adalah dua
bentuk yang berbeda namun secara semantik (makna) dapat memiliki
nilai yang sama. Hal ini dikenal sebagai equivalent.
Topic #1.1 – Propositional Logic: Equivalences
Discrete Math - Module #1 - Logic
Discrete Math - Module #1 - Logic
*
Tautologi
Kontradiksi
Kontingen
*
Sebuah compound proposition p adalah logically equivalent terhadap
proposition q, ditulis pq, IFF bila compound proposition pq adalah
sebuah tautology.
Sebuah compound propositions p dan q adalah logically equivalent
satu dengan yang lain IFF p dan q memuat nilai tabel kebenaran yang
sama untuk setiap baris dari tabel kebenaran.
Topic #1.1 – Propositional Logic: Equivalences
Discrete Math - Module #1 - Logic
Discrete Math - Module #1 - Logic
*
Pembuktian Ekuivelensi
*
Double negation: p p
Associative: (pq)r p(qr)
(pq)r p(qr)
Topic #1.1 – Propositional Logic: Equivalences
Discrete Math - Module #1 - Logic
Discrete Math - Module #1 - Logic
*
p(qr) (pq)(pr)
De Morgan’s:
Topic #1.1 – Propositional Logic: Equivalences
Augustus
*
pq (pq)(qp)
Implies: pq p q
Biconditional: pq (pq) (qp)
pq (pq)
*
Boolean operators:
Equivalences: pq (p q)
Proving equivalences using:
Topic #1 – Propositional Logic
*
Ingat aturan tata bahasan / grammar
Topic #3 – Predicate Logic
*
Adalah notasi formal untuk menuliskan definisi, aksioma, teorema
dari semua bidand matematika.
Dasar bagi bidang mathematical logic
Predicate logic with function symbols, the “=” operator, and a few
proof-building rules is sufficient for defining any conceivable
mathematical system, and for proving anything that can be proved
within that system!
Topic #3 – Predicate Logic
*
Dasar bagi automatic theorem provers dan bidang Artificial
Intelligence systems.
Mis: automatic program verification systems.
Predicate-logic sebagaimana sebuah pernyataan adalah mendukung
implementasi database query engines dan container class
libraries
Topic #3 – Predicate Logic
*
Pada kalimat “The dog is sleeping”:
Phrase “the dog” merujuk pada subject, pelaku utama dari objek pada
kalimat tersebut.
Phrase “is sleeping” merujuk pada predicate, sifat yang menunjukkan
pada aktifitas subject.
Pada predicate logic, predicate dimodelkan sebagai function P(·)
dari objek pada proposisi.
P(x) = “x is sleeping” (where x is any object).
Topic #3 – Predicate Logic
*
Predicates
Konvensi : huruf kecil dari variabel x, y, z... Merujuk pada
objects/entitas; huruf besar variabel variables P, Q, R… merujuk
pada propositional functions (predicates).
Menerapkan predicate P terhadap object x adalah meruakan sebuah
proposition P(x). Tetapi predicate P-nya sendiri bukanlah sebuah
proposisi, Misalnya (P=“is sleeping”).
P(x) = “x is a prime number”,
P(3) is the proposition “3 is a prime number.”
Topic #3 – Predicate Logic
*
Propositional Functions
Predicate logic generalizes the grammatical notion of a predicate
to also include propositional functions of any number of arguments,
each of which may take any grammatical role that a noun can
take.
E.g. let P(x,y,z) = “x gave y the grade z”, then if
x=“Mike”, y=“Mary”, z=“A”, then P(x,y,z) = “Mike gave Mary the
grade A.”
Topic #3 – Predicate Logic
*
Universes of Discourse (U.D.s)
The power of distinguishing objects from predicates is that it lets
you state things about many objects at once.
E.g., let P(x)=“x+1>x”. We can then say,
“For any number x, P(x) is true” instead of
(0+1>0) (1+1>1) (2+1>2) ...
The collection of values that a variable x can take is called x’s
universe of discourse.
Topic #3 – Predicate Logic
*
“” is the FORLL or universal quantifier.
x P(x) means for all x in the universe of disclosure (u.d) P
holds.
“” is the XISTS or existential quantifier.
x P(x) means there exists an x in the u.d. (that is, 1 or more)
such that P(x) is true.
Topic #3 – Predicate Logic
*
Let the u.d. of x be parking spaces at UII.
Let P(x) be the predicate “x is full.”
Then the universal quantification of P(x), x P(x), is the
proposition:
“All parking spaces at UII are full.”
i.e., “Every parking space at UII is full.”
i.e., “For each parking space at UII, that space is full.”
Topic #3 – Predicate Logic
*
(c)2001-2002, Michael P. Frank
Let the u.d. of x be parking spaces at UII.
Let P(x) be the predicate “x is full.”
Then the existential quantification of P(x), x P(x), is the
proposition:
“Some parking space at UII is full.”
“There is a parking space at UII that is full.”
“At least one parking space at UII is full.”
Topic #3 – Predicate Logic
*
Free and Bound Variables
Sebuah ekspresi seperti P(x) dikenal memiliki sebuah free variable
x (maknanya, x is undefined).
Sebuah quantifier (baik atau ) akan menggunakan (operates) satu
atau lebih free variable, dan diantara nya akan berfungsi sebagai
bound variable.
Topic #3 – Predicate Logic
*
P(x,y) memiliki 2 free variables, x dan y.
x P(x,y) memiliki 1 free variable, dan one bound variable. [Which
is which?]
“P(x), where x=3” is another way to bind x.
Topic #3 – Predicate Logic
*
Example: Let the u.d. of x & y be people.
Let L(x,y)=“x likes y” (a predicate with 2 free variable.’s)
Then y L(x,y) = “There is someone whom x likes.” (A predicate with
1 free variable, x)
Then x (y L(x,y)) =
(A __________ with ___ free variables.)
Topic #3 – Predicate Logic
*
Review: Predicate Logic (§1.3)
Objects x, y, z, …
Predicates P, Q, R, … are functions mapping objects x to
propositions P(x).
Multi-argument predicates P(x, y).
[x P(x)] :≡ “There is an x such that P(x).”
Universes of discourse, bound & free vars.
Discrete Math - Module #1 - Logic
Discrete Math - Module #1 - Logic
*
Quantifier Exercise
If R(x,y)=“x relies upon y,” express the following in unambiguous
English:
x(y R(x,y))=
y(x R(x,y))=
x(y R(x,y))=
y(x R(x,y))=
x(y R(x,y))=
Everyone has someone to rely on.
There’s a poor overburdened soul whom everyone relies upon
(including himself)!
There’s some needy person who relies upon everybody (including
himself).
Everyone has someone who relies upon them.
Everyone relies upon everybody, (including themselves)!
Topic #3 – Predicate Logic
*
x y Likes(x,y)
or, there is somebody (a popular person) whom everyone likes?
y x Likes(x,y)
“Somebody likes everybody.”
[Probably more likely.]
*
Game Theoretic Semantics
Thinking in terms of a competitive game can help you tell whether a
proposition with nested quantifiers is true.
The game has two players, both with the same knowledge:
Verifier: Wants to demonstrate that the proposition is true.
Falsifier: Wants to demonstrate that the proposition is
false.
The Rules of the Game “Verify or Falsify”:
Read the quantifiers from left to right, picking values of
variables.
When you see “”, the falsifier gets to select the value.
When you see “”, the verifier gets to select the value.
If the verifier can always win, then the proposition is true.
If the falsifier can always win, then it is false.
Topic #3 – Predicate Logic
*
*
Here is a way of understanding what we mean by nested
quantifiers.
First, “game theory” is a branch of mathematics dealing with ideal
strategies for playing competitive games. It has practical
applications in economics, business, international politics, as
well as in many areas of computer science such as computer
security. In the recent movie “A Beautiful Mind”, John Nash’s work
is related to game theory.
A semantics for a language is the specification how that language
is understood; it gives you the meaning of the language, as opposed
to just giving you its grammar.
So far, I have given you one way of understanding the semantics of
nested quantifiers in predicate logic, through translation to the
English phrases “for all…” and “there exists…such that…”. However,
if you are still fuzzy on the concept, here is another way to
understand it.
Think of determining the truth value of a nested quantifier
expression as being like playing a game following certain rules. In
this game, there are two players, the “verifier” who wants to argue
the case that the proposition is true, and the “falsifier” who
wants to argue the case that the proposition is false. To play the
game, read the nested-quantifier expression from left to right.
Every time you read “FORALL x”, the falsifier gets to take a turn,
and he gets to pick any value of x in the universe of discourse
that he wants to use to demonstrate his case. Every time you read
“EXISTS x”, the verifier gets to take a turn, and he gets to pick
any value of x in the u.d. that he wants to use to demonstrate his
case.
Now, we can say, if there is a winning strategy for the verifier
(if he can plan a way to play the game that guarantees him a win),
then the proposition is true. On the other hand, if there is a
winning strategy for the falsifier, then the proposition is
false.
(c)2001-2002, Michael P. Frank
Let B(x,y) :≡ “x’s birthday is followed within 7 days
by y’s birthday.”
x y B(x,y)
y B(so-and-so,y)
B(so-and-so,such-and-such)
Who wins this game?
quantifiers, and I
*
*
As an example, let “B(x,y)” be the proposition, “y’s birthday falls
within 1 week after x’s birthday.” Then suppose I assert, for the
universe of discourse consisting of students in this class, that
the predicate FORALL x EXISTS y B(x,y) is true. Now, let’s play the
game. I will be the verifier, and you all can play the falsifier.
(This example works well in my class because it’s so large; for
smaller classes you should change the time interval to 1 month
instead.)
The first quantifier is the FORALL quantifier. Since I am claiming
the part after the FORALL is true for all values of x, I shouldn’t
care what value of x is chosen. I’m saying it’s true no matter what
value is picked. So, the falsifier gets to pick x, and try his best
to prove me wrong. So, who in class wants to offer up their
birthday as the value of x here, to see if they can prove me wrong?
Just suggest someone, anyone… You? OK, good. What’s your name? OK,
(so-and-so). What’s your birth date? (Since we’re supposed to have
the same knowledge, you have to tell me.)
Now x is picked as so-and-so, and it’s my job to show that the rest
of the sentence, EXISTS y B(so-and-so, y) is true. It’s my turn to
play since the next quantifier is an EXISTS. EXISTS only claims
there is 1 member of the universe of discourse who satisfies the
predicate, so I get to pick it.
Now, since in this game we’re both supposed to have the same
knowledge, but I don’t actually know all your birthdays, you’re
going to have to have to help me out here. Who has a birthday
within the next 7 days after so-and-so? You? When’s your birthday?
OK, I pick you then.
Now, all the variables are chosen, and we look at the truth value
of the rest of the sentence. Notice it is true. So I win.
This does not yet establish that the sentence is true; for that
we’d have to tabulate everyone’s birthdays, and show that no matter
who you pick for x, I can pick someone for y to make the sentence
true. In a class this large, the sentence may actually be true;
there may be no 1-week periods that have no birthdays in them. (In
a much smaller class, it would most likely be false.)
Now, to show that the order of quantifiers matters, let’s switch
the quantifiers. Now, I (the verifier) have to go first. In this
game, making the first move turns out to be a disadvantage rather
than an advantage. Now, no matter who I pick for y, let’s say you –
what’s your birthday? You guys can easily pick someone for x to
make the sentence false. Thus, the sentence is false.
(c)2001-2002, Michael P. Frank
Sometimes the universe of discourse is restricted within the
quantification, e.g.,
x>0 P(x) is shorthand for
“For all x that are greater than zero, P(x).”
=x (x>0 P(x))
“There is an x greater than zero such that P(x).”
=x (x>0 P(x))
Topic #3 – Predicate Logic
*
x x P(x) - x is not a free variable in
x P(x), therefore the x binding isn’t used.
(x P(x)) Q(x) - The variable x is outside of the scope of the x
quantifier, and is therefore free. Not a complete
proposition!
(x P(x)) (x Q(x)) – This is legal, because there are 2 different
x’s!
Topic #3 – Predicate Logic
*
x P(x) P(a) P(b) P(c) …
x P(x) P(a) P(b) P(c) …
From those, we can prove the laws:
x P(x) x P(x)
x P(x) x P(x)
Which propositional equivalence laws can be used to prove
this?
Topic #3 – Predicate Logic
*
*
(Chalkboard.) Another way to see why the order of quantifiers
matters is to expand out the definitions of FORALL and EXISTS in
terms of AND and OR. For example, suppose the universe of discourse
just consists of two objects a and b. Now, consider some predicate
P(x,y).
Then,
FORALL x EXISTS y P(x,y) (EXISTS y P(a,y)) /\ (EXISTS y
P(b,y))
(P(a,a) \/ P(a,b)) /\ (P(b,a) \/ P(b,b)).
In contrast,
EXISTS y FORALL x P(x,y) (FORALL x P(x,a)) \/ (FORALL x
P(x,b))
(P(a,a) /\ P(b,a)) \/ (P(a,b) /\ P(b,b)).
To see that these two are inequivalent, suppose only P(a,a) and
P(b,b) are true. Then, the first proposition (with the FORALL
first) is true, but, the second proposition (with the EXISTS first)
is true. Students can come up with this counterexample in-class as
an exercise.
(c)2001-2002, Michael P. Frank
x (P(x) Q(x)) (x P(x)) (x Q(x))
x (P(x) Q(x)) (x P(x)) (x Q(x))
Exercise:
What propositional equivalences did you use?
Topic #3 – Predicate Logic
*
Review: Predicate Logic (§1.3)
Objects x, y, z, …
Predicates P, Q, R, … are functions mapping objects x to
propositions P(x).
Multi-argument predicates P(x, y).
(x P(x))=“There is an x such that P(x).”
Topic #3 – Predicate Logic
*
*
These “Review” slides I insert at the point where I am at the
beginning of a lecture, just to quickly review what we’ve been
covering recently. Instructors should feel free to move these
slides around to wherever they are convenient.
(c)2001-2002, Michael P. Frank
parenthesize x P(x) Q(x)
Consecutive quantifiers of the same type can be combined: x y z
P(x,y,z)
x,y,z P(x,y,z) or even xyz P(x,y,z)
All quantified expressions can be reduced
( )
*
Defining New Quantifiers
As per their name, quantifiers can be used to express that a
predicate is true of any given quantity (number) of objects.
Define !x P(x) to mean “P(x) is true of exactly one x in the
universe of discourse.”
!x P(x) x (P(x) y (P(y) y x))
“There is an x such that P(x), where there is no y such that P(y)
and y is other than x.”
Topic #3 – Predicate Logic
*
Let u.d. = the natural numbers 0, 1, 2, …
“A number x is even, E(x), if and only if it is equal to 2 times
some other number.”
x (E(x) (y x=2y))
“A number is prime, P(x), iff it’s greater than 1 and it isn’t the
product of any two non-unity numbers.”
x (P(x) (x>1 yz x=yz y1 z1))
Topic #3 – Predicate Logic
*
*
Note we can even use quantifier expressions to define concepts like
even-ness and prime-ness.
(c)2001-2002, Michael P. Frank
E(x>2): P(p),P(q): p+q = x
or, with more explicit notation:
x [x>2 E(x)] →
“Every even number greater than 2
is the sum of two primes.”
Topic #3 – Predicate Logic
*
*
The notation in the top part may look confusing at first but it is
actually unambiguous. After FORALL we must have the name of a
variable. The following term has 1 free variable x, so we assume
that variable comes after the FORALL. Then, the expression
E(x>2) becomes a predicate that restricts the universe of
discourse. E() is only a predicate if it contains a free variable;
the only free variable within it is x so we translate E(x>2) as
E(x) /\ x>2. This then is the predicate that must be true of an
item in the universe of discourse in order for the rest of the
expression to apply to it. Similarly, P(p) and P(q) translate to
both free variables p and q after the EXISTS and to conjoined
propositions about p and q. Alternatively, the whole expression
could also be written FORALL E(x)>2 EXISTS p+q=x, P(p), P(q). Or
of course in many other equivalent forms.
Due to Goedel’s theorem, as far as we know right now, it is
entirely possible that Goldbach’s conjecture could be perfectly
true for the universe of all natural numbers from 0 to infinity,
yet, there might be absolutely NO finite-length proof of this
conjecture from the basic axioms of number theory. On the other
hand, it might have a proof that is finite but extremely long, or
even possibly a relatively short one that we just haven’t been
lucky enough to discover yet.
(c)2001-2002, Michael P. Frank
Calculus Example
One way of precisely defining the calculus concept of a limit,
using quantifiers:
Topic #3 – Predicate Logic
*
H(x) :≡ “x is human”;
M(x) :≡ “x is mortal”.
Premises:
H(s) Socrates is human. x H(x)M(x) All humans are mortal.
Topic #3 – Predicate Logic
*
H(s)M(s) [Instantiate universal.] If Socrates is human
then he is mortal.
H(s) (H(s) M(s))
(H(s) H(s)) (H(s) M(s)) [Apply distributive law.]
F (H(s) M(s)) [Trivial contradiction.]
H(s) M(s) [Use identity law.]
M(s) Socrates is mortal.
Topic #3 – Predicate Logic
*
M(x) :≡ “x is mortal”; G(x) :≡ “x is a god”
Premises:
x G(x) M(x) (“Gods are immortal”).
Show that x (H(x) G(x))
(“No human is a god.”)
Topic #3 – Predicate Logic
*
x M(x)H(x) [Contrapositive.]
x (G(x) H(x)) [DeMorgan’s law.]
x G(x) H(x) [An equivalence law.]
Topic #3 – Predicate Logic
*
From these sections you should have learned:
Predicate logic notation & conventions
Meaning of quantifiers, equivalences
Simple reasoning with quantifiers
Topic #3 – Predicate Logic
*