Sie sind auf Seite 1von 21

DISCRETE MATHEMATICS

Discrete mathematics is the branch of mathematics dealing with objects that can assume only distinct,
separated values. The term "discrete mathematics" is therefore used in contrast with "continuous mathematics,"
which is the branch of mathematics dealing with objects that can vary smoothly (and which includes, for
example, calculus). Whereas discrete objects can often be characterized by integers, continuous objects require real
numbers. The study of how discrete objects combine with one another and the probabilities of various outcomes is
known as combinatorics. Other fields of mathematics that are considered to be part of discrete mathematics
include graph theory and the theory of computation. Topics in number theory such as congruencies and recurrence
relations are also considered part of discrete mathematics. The study of topics in discrete mathematics usually
includes the study of algorithms, their implementations, and efficiencies. Discrete mathematics is the mathematical
language of computer science, and as such, its importance has increased dramatically in recent decades.

Discrete math is essential to college-level mathematics and beyond. Discrete math together with calculus
and abstract algebra is one of the core components of mathematics at the undergraduate level. Students who learn
a significant quantity of discrete math before entering college will be at a significant advantage when taking
undergraduate-level math courses.

Discrete math is the mathematics of computing. The mathematics of modern computer science is built almost
entirely on discrete math, in particular combinatorics and graph theory. This means that in order to learn the
fundamental algorithms used by computer programmers, students will need a solid background in these subjects.
Indeed, at most universities, a undergraduate-level course in discrete mathematics is a required part of pursuing a
computer science/engineering degree.

Discrete math is very much "real world" mathematics. Many students' complaints about traditional math
algebra, geometry, trigonometry, and the likeis "What is this good for?" The somewhat abstract nature of these
subjects often turn off students. By contrast, discrete math, in particular counting and probability, allows students
to very quickly explore non-trivial "real world" problems that are challenging and interesting.

Discrete math teaches mathematical reasoning and proof techniques. Algebra is often taught as a series of
formulas and algorithms for students to memorize (for example, the quadratic formula, solving systems of linear
equations by substitution, etc.), and geometry is often taught as a series of "definition-theorem-proof" exercises
that are often done by rote (for example, the infamous "two-column proof"). While undoubtedly the subject matter
being taught is important, the material (as least at the introductory level) does not lend itself to a great deal of
creative mathematical thinking. By contrast, with discrete mathematics, students will be thinking flexibly and
creatively right out of the box. There are relatively few formulas to memorize; rather, there are a number of
fundamental concepts to be mastered and applied in many different ways.

Discrete math is fun. Many students, especially bright and motivated students, find algebra, geometry, and even
calculus dull and uninspiring. Rarely is this the case with most discrete math topics. When we ask students what the
favorite topic is, most respond either "combinatorics" or "number theory." Simply put, most students find discrete
math more fun than algebra or geometry.

PROPOSITIONAL LOGIC
A proposition is a declarative statement thats either TRUE or FALSE (but not both).
Propositions Not Propositions
3 + 2 = 32 Bring me coffee!
CS173 is Bryans favorite class. CS173 is her favorite class.
Every cow has 4 legs. 3+2
There is other life in the universe. Do you like Cake?

PROPOSITIONAL LOGIC NEGATION


Suppose p is a proposition. The negation of p is written p and has meaning: It is not the case that p.
p p
Ex. CS173 is NOT Bryans favorite class. Truth table for negation: T F
Notice that p is a proposition. F T

PROPOSITIONAL LOGIC CONJUNCTION


Conjunction corresponds to English and. p q is true exactly when p and q p q pq
are both true. T T T
T F F
Ex. Amy is curious AND clever. Truth table for F T F
conjunction F F F
PROPOSITIONAL LOGIC DISJUNCTION
Disjunction corresponds to English or. p q is when p or q (or both) are
true. p q pq
T T T
T F T
Ex. Michael is brave OR nuts. Truth table for F T T
disjunction F F F

PROPOSITIONAL LOGIC IMPLICATION


Implication: p q corresponds to English if p then q, or p implies q.

If it is raining, then it is cloudy. p q pq


If there are 200 people in the room, then I am the Easter Bunny. T T T
If p, then 2+2=4. T F F
F T T
Truth table for implication F F T

PROPOSITIONAL LOGIC LOGICAL EQUIVALENCE


How many different logical connectives could we define? 16
How many different logical connectives do we need?

To answer, we need the notion of logical equivalence. p is logically equivalent to q if their truth tables are the
same.
We write p q.

p q pq p q p q p
Challenge: Try to find a proposition that is T T F T
T q T T
p
equivalent
T to rp Fq,q but
r thatp uses
(q r) only the
F
pq T F pr F (p q) (p Fr)
T T T T T T F T T T
connectives
F , , and T. T T T
T T F F T T F F T T T T
T F F T F F TT T T T
T F F F T T T T
F T T T T T T T
PROPOSITIONAL
F T F LOGICF PROOF FOF 1 FAMOUS T F F
F F T F F F T F
Distributive:
F F F
p (q F r) (p q)F (p r) F F F

PROPOSITIONAL LOGIC SPECIAL DEFINITIONS

Contrapositives: p q and q p Converses: p q and q p Inverses: p


q and p q
Ex. If it is noon, then I am hungry. Ex. If it is noon, then I am hungry. Ex. If it is
noon, then I am hungry.
If I am not hungry, then it is not noon. If I am hungry, then it is noon. If it is not
noon, then I am not hungry.

One of these things is not like the others.


Hint: In one instance, the pair of propositions is equivalent. p q q p

PROPOSITIONAL LOGIC 2 MORE DEFN


A tautology is a proposition thats always TRUE.
A contradiction is a proposition thats always FALSE.
p p p p p p
T F T F
F T T F

PROPOSITIONAL EQUIVALENCES
TAUTOLOGIES, CONTRADICTIONS, CONTINGENCIES
DEF: A compound proposition is called a tautology if no matter what truth values its atomic propositions have, its
own truth value is T.

EG: p p (Law of excluded middle)


The opposite to a tautology, is a compound proposition thats always false a contradiction.

EG: p p
On the other hand, a compound propositions whose truth value isnt constant is called a contingency.

TAUTOLOGIES AND CONTRADICTIONS


The easiest way to see if a compound proposition is a tautology/contradiction is to use a truth table.
p
p p p p
F T T p p
T F T
p
Tautology example (1.2.8.a) Part 1
F T F
Demonstrate that T F F [p (p q )]q is a tautology in
two ways:
1. Using a truth table show that [p (p q )]q is always true
2. Using a proof (will get to this later).

p q p p q p (p q ) [p (p q )]q
T T F T F T
T F F T F T
F T T T T T
F F T F F T

TAUTOLOGIES, CONTRADICTIONS AND PROGRAMMING


Tautologies and contradictions in your code usually correspond to poor programming design.

EG:
while(x <= 3 || x > 3) if(x > y)
x++; if(x == y)
return never got here;

LOGICAL EQUIVALENCES
DEF: Two compound propositions p, q are logically equivalent if their biconditional joining p q is a tautology.
Logical equivalence is denoted by p q.

EG: The contrapositive of a logical implication is the reversal of the implication, while negating both components.
I.e. the contrapositive of p q is q p . As well see next: p q q p

LOGICAL EQUIVALENCE OF CONDITIONAL AND CONTRAPOSITIVE


The easiest way to check for logical equivalence is to see if the truth tables of both variants have identical last
columns:
p q q p qp
Q: whyp does this work q ?
q given definitionp of
T T F F T
T T T
A: p q
T
by definition
F
means that p q is a tautology.
F
T F T F F
Furthermore, the biconditional is true exactly when the F T F T T
F T T
F F T T T
truth Fvalues of p and
F of q are identical.
T So if the last
column of truth tables of p and of q is identical, the biconditional join of both is a tautology.

LOGICAL NON-EQUIVALENCE OF CONDITIONAL AND CONVERSE


The converse of a logical implication is the reversal of the implication. I.e. the converse of p q is q p.
EG: The converse of If Donald is a duck then Donald is a bird. is If Donald is a bird then Donald is a duck.

As well see next: p q and q p is not logically equivalent.

p q p q q p (p q) (q p)
T T T T T
T F F T F
F T T F F
F F T T T

DERIVATIONAL PROOF TECHNIQUES


When compound propositions involve more and more atomic components, the size of the truth table for the
compound propositions increases.

Q1: How many rows are required to construct the truth-table of: ( (q(pr)) ((sr)t)) (qr )?
Q2: How many rows are required to construct the truth-table of a proposition involving n atomic components?
A1: 32 rows, each additional variable doubles the number of rows
A2: In general, 2n rows.

Therefore, as compound propositions grow in complexity, truth tables become more and more unwieldy. Checking
for tautologies/logical equivalences of complex propositions can become a chore, especially if the problem is
obvious.

EG: consider the compound proposition


(p p ) ((sr)t) ) (qr )

Q: Why is this a tautology?


A: Part of it is a tautology (p p ) and the disjunction of True with any other compound proposition is still True:
(p p ) ((sr)t )) (qr )
T ((sr)t )) (qr )
T

Derivational techniques formalize the intuition of this example.

TABLES OF LOGICAL EQUIVALENCES

- Like adding 0
- Like multiplying by 0

- Delete redundancies
- I dont like you, not
- Like x+y = y+x
- Like (x+y)+z = y+(x+z)
- Like (x+y)z = xz+yz

- Excluded middle
- Negating creates opposite
- Definition of implication in terms of Not and Or

DEMORGAN IDENTITIES
DeMorgans identities allow for simplification of negations of complex expressions

Conjunctional negation:
(p1p2pn) (p1p2pn) Its not the case that all are true iff one is false.
Disjunctional negation:
(p1p2pn) (p1p2pn) Its not the case that one is true iff all are false.

Tautology example (1.2.8.a) Part 2


Demonstrate that [p (p q )]q is a tautology in two ways:
1. Using a truth table (did above)
2. Using a proof relying on Tables 5 and 6 of Rosen, section 1.2 to derive True through a series of logical
equivalences

[p (p q )]q
[(p p)(p q)]q Distributive
[ F (p q)]q ULE
[p q ]q Identity
[p q ] q ULE
[(p) q ] q DeMorgan
[p q ] q Double Negation
p [q q ] Associative
p [q q ] Commutative
pT ULE
T Domination
PREDICATE LOGIC
A proposition in the form 5 is an integer may be viewed as having two components. One is an object or individual
and the other is a property which that object or individual is said to possess. We refer to the property as a
predicate. We denote objects and individuals using lower case letters-usually first letter of the name of that object
or individual.

For example f: five


t: fifteen

Predicates are denoted using upper case letters: Z: is an integer


Q: is a rational number.

The propositions: 5 is an integer denoted by Z(f).


Fifteen is a rational number denoted by Q(t).

These propositions may be negated or conjoined: Z(f): Five is not an integer


Q(f)Q(t): Five and Fifteen are rational numbers.
Z(f)Q(f): If five is an integer then five is a rational number.

We may also form the expressions: Z(x): x s an integer.


Q(y): y is a rational number.

These are not propositions since they cannot be declared true or false. They are called propositional functions.

QUANTIFICATION OF PROPOSITIONAL FUNCTIONS


We denote for all x by x and the proposition. All integers are rational numbers is denoted by x(Z(x)Q(x)). The
symbol is called universal quantifier. The quantified variable x converts the propositional function Z(x)Q(x)
into propositions. There exists at least one x such that x is an integer and x is a rational number. If we denote
there exists at least one x by x, then proposition may be symbolized by x(Z(x)Q(x)).

Examples:
Suppose that predicates and individuals are defined as follows.
S: should be shunned M: is a friend of mine.
U: prone to unruly behavior. d: Danielle.
J: is a friend of Josh. e: Erika.

Symbolize the following:


i. Danielle is a friend of Josh and Erika is a friend of mine.
ii. Some of Josh friends are prone to unruly behavior.
iii. Anyone who is a friend of Josh is not a friend of mine.
iv. If Danielle is a friend of Josh then she is prone to unruly behavior and should be shunned.
v. Some of my friends are friends of Josh and some of Josh friends are prone to unruly behavior.

Solutions:
i. J(d) M(e) iv. ( J(d) U(d) ) S(d)
ii. x ( J(x) U(x) ) v. x ( M(x) J(x) ) x ( J(x) U(x) )
iii. x ( J(x) M(x) )

EXERCISES
EXERCISE 2.1
1. Let P(x) denote the statement x 10. What are the truth values?
a. P(9) d. P(10)
b. P(12) e. P(0)
c. P(-10)

2. Let Q(x) denote the statement x is an integer. What are the truth values?
a. Q(-1) d. Q(-4)
b. Q(0) e. Q(4 )
c. Q(8 / 2)

3. Let P(x,y) denote the statement xy 15. What are the truth values?
a. P(5,3) d. P(-3,-6)
b. P(-3,5) e. P(2,7)
c. P(-3,-5)
EXERCISE 2.2
1. Let P(x) be the statement x spends more than four hours surfing the internet, where the domain for x
consists of all students. Write a statement in English corresponding to the for
a. xP(x) d. xP(x)
b. x P(x) e. xP(x)
c. xP(x)

2. Let Q(x) be the statement x has developed a program in JAVA, where the domain for consists of the
students in ICS. Express each of these quantifications in English.
a. xQ(x) d. xQ(x)
b. x Q(x) e. x Q(x)
c. xQ(x)

EXERCISE 2.3
Let P(x) be the statement x is an integer and Q(x) be a statement x is a rational number, where the domain is
the set of real numbers. Express each of these quantifications in English.
a. P(6) f. xP(x)
b. P(1/2) g. xP(x)
c. Q(0) h. x Q(x)
d. Q(2/3) i. x ( P(x) Q(x) )
e. Q(2 ) j. x ( Q(x) P(x) )

EXERCISE 2.4
1. Let P(x) be the statement x is a positive integer and Q(x) be a statement x is a rational number, where
the domain is the set of all numbers. Express each of these quantifications in English.
a. xP(x) f. xP(x)
b. xP(x) g. xP(x)
c. xQ(x) h. x Q(x)
d. xQ(x) i. x ( P(x) Q(x) )
e. xP(x) j. x ( Q(x) P(x) )

EXERCISE 2.5
Symbolize the following by using quantifiers, predicates and logical connectives.
1. All rational numbers are real numbers.
2. Some rational numbers are integers.
3. Some even numbers are multiple of two, four and five.
4. Some triangles are scalene.
5. Every integer is multiple of 10 if and only if it is a multiple of 5 and 2.
6. Some prime integers are odd integers.
7. Everyone is charitable and compassionate.
8. Some are committee and competent in doing their job.
9. Everyone who studies logic is good in reasoning.
10. Some students are good in mathematics and physics.

EXERCISE 2.6
1. What is the truth value of the quantification xP(x), where the domain of discourse is the set of integers?

a. P(x): x2 +3x+2=0 d. P(x): x+3 x+1

b. P(x): 2 x2 +3x+1=0 e. P(x): x2 2x-1

c. P(x): x+3 4

2. What is the truth value of the quantification xP(x), where the domain of discourse is the set of integers?
a. P(x): 2x-1 x+1 d. P(x): 5x-3 = 2x

b. P(x): 3 x2 +4x+1=0 e. P(x): x2 +1 = 0

c. P(x): x2 +1 = 0

2
d. P(x): x=1
3
UNIVERSE OF DISCOURSE
Given a propositional function P(x), the universe of discourse for the variable x is defined to be the set from which
we may select an object or individual to substitute for x.

RULES OF QUANTIFICATION DENIAL (QD)


Suppose that the universe of discourse is defined to be variable x. Then, for any propositional function Px:
xP(x) is equivalent to xP(x), xP(x) is equivalent to xP(x)

Examples:
1. The proposition No integer is a rational number, i.e. xP(x). The negation of All integers are rational
numbers is There is at least integer that is not a rational number. Hence the proposition which is
equivalent to xP(x) is xP(x).

2. The negation of the existentially quantified proposition Some integers are rational is the proposition that
it is not the case that some integers are rational numbers. i.e. No integer is a rational number. To
paraphrase this For every x in the universe, x is not a rational number and symbolizes it xP(x). Hence
xP(x) is equivalent to xP(x).

TWO-PLACE PREDICATES
Two-place predicates referred to as relational phrases, they express a relation between two components. We can
form propositional function from two-place predicates.

Examples:
is greater than, is taller than, is bigger than, is less than, If Y denotes is younger than. Y(a,b) denotes the
propositional function a is younger than b. Let j denote John. Y(j,b) the expression denotes John is younger than
b.

Two-variable propositional functions can be quantified. xY(x,y) denotes Everyone is younger than y. If we
substitute j for y, we obtain the proposition Everyone is younger than John denoted by xY(x,j).

NESTED QUANTIFIERS
Use of two quantifiers, xyY(x,y), may be read as For all x and for all y, x is younger y or Everyone is younger
than everyone. This is a proposition since it clearly has a truth value false.

Examples:
There are eight propositions which can be formed by quantifying a two variable propositional function. For the
propositional function Lxy x likes y and the universe of people:
1. xyL(x,y) 5. xyL(x,y)
2. yxL(x,y) 6. yxL(x,y)
3. xyL(x,y) 7. xyL(x,y)
4. yxL(x,y) 8. yxL(x,y)

These denotes the following propositions:


1. Everyone likes everyone.
2. For everyone, everyone likes them.
3. Everyone likes someone.
4. There is someone who is liked by everyone.
5. There is someone who like everyone.
6. For everyone, there is someone who likes them.
7. There is someone who likes someone.
8. There is someone who is liked by someone.

Many mathematical statements involve multiple quantifications of propositional functions involving more than one
variable.

Examples:
1. Let P(x,y) be the statement x*y = y*x , where the domain for all variable consists of all real numbers.
The quantification, xyP(x,y) denotes the proposition For all real number x, for all real number y, x*y =
y*x. Also, The quantification, yxP(x,y) denotes the proposition, For all real number y, for all real
number x, x*y = y*x.

2. Let F(x,y) denote x*y = 1 , where the domain for all variable consists of all real numbers. The
quantification, xyP(x,y) denotes the proposition, For all real number x there is a real number y such that
x*y =1.
3. Let P(x,y) be the statement x*(y*z) = (x*y)*z , where the domain for all variable consists of all real
numbers. The quantification, xyzP(x,y,z) denotes the proposition , For all real number x, for all real
number y, for all real number z, x*(y*z) = (x*y)*z

4. Translating the quantified statement xy( (x0)(y0)(xy0) ), where the domain fr all variables consists
of all real numbers. This will read: For all real number x, for all real number y, if x is a positive real number
and y is a negative real number then their product is a negative real number or putting it plainly, The
product of a positive and a negative real numbers is a negative real number.

We define the following:


B(x,y): x belongs to y P(y): y is a person
D(x,y): x detest y a: Anne
C(x): x is a cat b: Benjie
F(x): x is a ferocious c: Charlene

Write the propositions in English sentences:


1. C(b) F(b) B(b,c) 4. xy [ (C(x)F(x))(P(y)D(y,x)) ]
2. x( C(x)D(a,x) ) 5. xy( C(x) F(x) P(y) D(y,x) )
3. x( C(x)F(x) ) B(x,c)

Solution:
1. Benjie is ferocious cat that belongs to Charlene.
2. Anne detest all cats.
3. Some ferocious cat belongs to Charlene.
4. All ferocious cats are detested by everyone.
5. All ferocious cats are detested by someone.

EXERCISE 2.7
1. Let P(x,y) denote the sentence 2x+y=5. What are the truth values of the following where the domain of x
and y is set of all integers?
a. xyP(x,y) c. xyP(x,y)
b. xyP(x,y) d. xyP(x,y)

2. Let P(x,y) denote the sentence x 2+1 x+1 . What are the truth values of the following where the

domain of x and y is set of all integers?


a. xyP(x,y) c. xyP(x,y)
b. xyP(x,y) d. xyP(x,y)

EXERCISE 2.8
Let P(x,y) be the statement student x has taken y, where the domain for x consists of all computer science
students of ICS and for y consists of all mathematical courses. Express each of these quantifications in English.
a. xyP(x,y) e. xyP(x,y)
b. yxP(x,y) f. yxP(x,y)
c. xyP(x,y) g. xyP(x,y)
d. yxP(x,y) h. yxP(x,y)

EXERCISE 2.9
Let P(x,y) be the statement student x has written a program in y, where the domain for x consists of all computer
science students of ICS and for y consists of all programming languages. Express each of these quantifications in
English.
a. xyP(x,y) e. xyP(x,y)
b. yxP(x,y) f. yxP(x,y)
c. xyP(x,y) g. xyP(x,y)
d. yxP(x,y) h. yxP(x,y)
SETS
DEFINING SETS
Definition: A set is an unordered collection of objects.
The objects in a set are called the elements or members of the set S, and we say S contains its elements.

We can define a set by directly listing all its elements.


e.g. S = {2, 3, 5, 7, 11, 13, 17, 19},
S = {CSC1130, CSC2110, ERG2020, MAT2510}

After we define a set, the set is a single mathematical object, and it can be an element of another set.
e.g. S = {{1,2}, {1,3}, {1,4}, {2,3}, {2,4}, {3,4}}

DEFINING SETS BY PROPERTIES


It is inconvenient, and sometimes impossible, to define a set by listing all its elements. Alternatively, we can define

by a set by describing the properties that its elements should satisfy. We use the notation: to { x A| P( x)}
define the set as the set of elements, x, in A such that x satisfies property P.
e.g. {x | x is a real number and -2 < x < 5}
{x | x is a prime number and x < 1000}

Examples of Sets
Well known sets:
the set of all real numbers, R
the set of all complex numbers, C

the set of all integers, Z


+
the set of all positive integers, Z

empty set, ={} , the set with no elements.

Other examples:
The set of all polynomials with degree at most three: {1, x, x 2, x3, 2x+3x2,}.
The set of all n-bit strings: {0000, 0001, , 1111}

The set of all triangles without an obtuse angle: { , , }

The set of all graphs with four nodes: { , , , , }

MEMBERSHIP
Order, number of occurence are not important.
e.g. {a,b,c} = {c,b,a} = {a,a,b,c,b}

The most basic question in set theory is whether an element is in a set.

x A x is an element of A x A x is not an element of A


X is in A x is not in A
2
e.g. Recall that Z is the set of all integers. So 7 Z and Z.
3

Let P be the set of all prime numbers. Then 9 P and 321 P.

Let Q be the set of all rational numbers. Then 0.5 P and 2 Q .

SIZE OF A SET
In this course we mostly focus on finite sets.

Definition: The size of a set S, denoted by |S|, is defined as the number of elements contained in S.

e.g. if S = {2, 3, 5, 7, 11, 13, 17, 19}, then |S|=8.


if S = {CSC1130, CSC2110, ERG2020, MAT2510}, then |S|=4.
if S = {{1,2}, {1,3}, {1,4}, {2,3}, {2,4}, {3,4}}, then |S|=6.

Later we will study how to determine the size of the following sets:
the set of poker hands which are full house.
the set of n-bit strings without three consecutive ones.
the set of valid ways to add n pairs of parentheses
SUBSET
Definition: Given two sets A and B, we say A is a subset of B, denoted by A B , if every element of A is also
an element of B.

If A = {4, 8, 12, 16} and B = {2, 4, 6, 8, 10, 12, 14, 16}, then by A B

but by BA
AA because every element in A is an element of A.

A for any A because the empty set has no elements.

If A is the set of prime numbers and B is the set of odd numbers, then A B

Fact: If A B , then |A| <= |B|.

PROPER SUBSET, EQUALITY


Definition: Given two sets A and B, we say A is a proper subset of B, denoted by A B , if every element of A
is an element of B, but there is an element in B that is not contained in A.

Fact: If A B , then |A| < | B|.

Definition: Given two sets A and B, we say A = B if A B and BA .

Fact: If A = B, then |A| = |B|.

EXERCISES
1. Z R ?

2. {3} {5,7,3}?
3. every set?

4. {1,2} {{1,2}, {2,3}, {3,1}}?


5. {a} = {{a}}?
6. If A B and B C, then A C?

7. If A B and B C, then A C?

BASIC OPERATIONS ON SETS


Let A, B be two subsets of a universal set U (depending on the context U could be R, Z, or other sets).

intersection: A B={ x U| x Ax B

Definition: Two sets are said to be disjoint if their intersection is an empty set.
e.g. Let A be the set of odd numbers, and B be the set of even numbers. Then A and B are disjoint.

union: A B={ x U| x Ax B

Fact: | A B|=| A|+|B| A B

difference: AB={ x U| x Ax B

Fact: | AB|=| A| A B

complement:
A c ={ x U| x A }
A=
e.g. Let U = Z and A be the set of odd numbers.
Then A is the set of even numbers.

Fact: If A B , then B A

Examples
A = {1, 3, 6, 8, 10} B = {2, 4, 6, 7, 10}
A B = {6, 10}, A B = {1, 2, 3, 4, 6, 7, 8, 10} A-B = {1, 3, 8}

Let U = {x Z | 1 <= x <= 100}.

A = {x U | x is divisible by 3}, B = {x U | x is divisible by 5}

A B = {x U | x is divisible by 15}

A B = {x U | x is divisible by 3 or is divisible by 5 (or both)}

A B = {x U | x is divisible by 3 but is not divisible by 5}

Exercise: compute |A|, |B|, |A B|, |A B|, |A B|.

PARTITIONS OF SETS
Two sets are disjoint if their intersection is empty.

A collection of nonempty sets {A 1, A2, , An} is a partition of a set A if and only if A= A 1 A 2 An A1, A2,

, An are mutually disjoint (or pairwise disjoint).


e.g. Let A be the set of integers. Let A 1 be the set of negative integers. Let A 2 be the set of positive integers. Then
{A1, A2} is not a partition of A, because A A1 A2 as 0 is contained in A but not contained in A1 A 2

e.g. Let A be the set of integers divisible by 6. A 1 be the set of integers divisible by 2. A 2 be the set of integers
divisible by 3. Then {A1, A2} is not a partition of A, because A1 and A2 are not disjoint, and also A A 1
A 2 (so
both conditions are not satisfied).

e.g. Let A be the set of integers.


A1 = {x A | x = 3k+1 for some integer k}

A2 = {x A | x = 3k+2 for some integer k}

A3 = {x A | x = 3k for some integer k}


Then {A1, A2, A3} is a partition of A

POWER SETS
power set: pow ( A ) { S|S A }

In words, the power set pow(A) of a set A contains all the subsets of A as members.

pow({a,b}) = { , {a}, {b}, {a,b}}

pow({a,b,c}) = { , {a}, {b}, {c}, {a,b}, {a,c}, {b,c}, {a,b,c}}

pow({a,b,c,d}) = { , {a}, {b}, {c}, {d}, {a,b}, {a,c}, {b,c}, {a,d}, {b,d}, {c,d}, {a,b,c}, {a,b,d}, {a,c,d},
{b,c,d}, {a,b,c,d}}

Fact: If A has n elements, then pow(A) has 2n elements.

CARTESIAN PRODUCTS
Definition: Given two sets A and B, the Cartesian product A x B is the set of all ordered pairs (a,b), where a is in

A and b is in B. Formally, A x B= { ( a , b )|a Ab B

Ordered pairs means the ordering is important, e.g. (1,2) (2,1)

e.g. Let A be the set of letters, i.e. {a,b,c,,x,y,z}. Let B be the set of digits, i.e. {0,1,,9}. A x A is just the set of
strings with two letters. B x B is just the set of strings with two digits. A x B is the set of strings where the first
character is a letter and the second character is a digit.

The definition can be generalized to any number of sets, e.g.


A x B x C={ ( a , b , c )|a Ab Bc C

Using the above examples, A x A x A is the set of strings with three letters. Our ID card number has one letter and
then six digits, so the set of ID card numbers is the set A x B x B x B x B x B x B.
Fact: If |A| = n and |B| = m, then |A x B| = mn.
Fact: If |A| = n and |B| = m and |C| = l, then |A x B x C| = mnl.
Fact: |A1 x A2 x x Ak| = |A1| x |A2| x x |Ak|.

Exercises
1. Let A be the set of prime numbers, and let B be the set of even numbers. What is A B and |A
B|?
2. Is |A B| > |A| > |A B| always true?
3. Let A be the set of all n-bit binary strings, A i be the set of all n-bit strings with i ones. Is (A 1, A2, , Ai, ,
An) a partition of A?
4. Why the name Cartesian product?
5. Let A = {x, y}. What is pow(A) x pow(A) and |pow(A) x pow(A)|?
SET IDENTITIES
Some basic properties of sets, which are true for all sets.
A B A
A A C

If A BB C , then A C

A A=
A
A=
A B=( AB) ( B A) ( A B)

Distributive Law:
1 A ( B C )=(A B)( A C) (1)
(2)

2 A ( B C )=( A B)( A C)

Distributive Law: A ( B C )=( A B)( A C)


We can also verify this law more carefully

L.H.S
A=S 1 S 2 S 4 S 5
B C=S 4 S6
A (B C )=S1 S2 S 4 S5 S 6

R.H.S.
( A B)=S1 S 2 S 3 S4 S 5 S6
( A C )=S1 S2 S 4 S5 S 6 S7
( A B ) ( A C)=S 1 S 2 S4 S 5 S6

De Morgans Law:

A B= A B

A B= B
A

DISPROOF
( AB ) ( BC ) =AC ?

A B A B
1 2 3
2 3
1 C
C
4 5 6
5 6
4 7
7

L.H.S R.H.S

We can easily construct a counterexample to the equality, by putting a number in each region in the figure. Let A
= {1,2,4,5}, B = {2,3,5,6}, C = {4,5,6,7}. Then we see that L.H.S = {1,2,3,4} and R.H.S = {1,2}.

ALGEBRAIC PROOF
Sometimes when we know some rules, we can use them to prove new rules without drawing figures.


(A B)=A
B
e.g. we can prove without drawing figures.


(A B)=
A B
by using DeMorgans rule on A and B

A B

( B ) C
?
( ( A C ) B C )) =( A
(
( ( A C ) B C ))

( A C ) ( B C) by DeMorgans law on A U C and B U C

( A (B C)
C) by DeMorgans law on the first half

C)
( A ( B C)

by DeMorgans law on the second half

B)
( A C
by Distributive law

B)
( A C
Exercises
A ( A B ) =AB ?
( A B)C=( AC )(BC)?
C)= A
( A B B
C
?

RUSSELLS PARADOX
Let W
={S SetsS S }
In words, W is the set that contains all the sets that dont contain themselves.

Is W in W?
If W is in W, then W contains itself. But W contains only those sets that dont contain themselves. So W is not in W. If
W is not in W, then W does not contain itself. But W contains those sets that dont contain themselves. So W is in W.
Whats wrong???

BARBERS PARADOX
There is a male barber who shaves all those men, and only those men, who do not shave themselves.

Does the barber shave himself?


Suppose the barber shaves himself. But the barber only shaves those men who dont shave themselves. Since the
barber shaves himself, he does not shave himself. Suppose the barber does not shave himself. But the barber
shaves those men who dont shave themselves. Since the barber does not shave himself, he shaves himself. Whats
wrong???

SOLUTION TO RUSSELS PARADOX


A man either shaves himself or not shaves himself. A barber neither shaves himself nor not shaves himself. Perhaps
such a barber does not exist? Actually thats the way out of this paradox. Going back to the barbers paradox, we
conclude that W cannot be a set, because every set is either contains itself or not, but either case cannot happen
for W. This paradox tells us that not everything we define is a set. Later on mathematicians define sets more
carefully, e.g. using sets that we already know.

HALTING PROBLEM
Now we mention one of the most famous problems in computer science.

The halting problem: Can we write a program which detects infinite loop?
We want a program H that given any program P and input I:
H(P,I) returns halt if P will terminate given input I;
H(P,I) returns loop forever if P will not terminate given input I.
And H itself must terminate in finite time.

The halting problem: Does such a program H exist? NO


The reasoning used in solving the halting problem is very similar to that of Russells paradox.

BASIC COUNTING
SUM RULE
|S|: the number of elements in a set S.

If sets A and B are disjoint, then |A B| = |A| + |B|


A BB
Class has 43 women, 54 men, so total enrollment = 43 + 54 = 97
26 lower case letters, 26 upper case letters, and 10 digits, so total characters = 26+26+10 = 62

PRODUCT RULE

Recall that, given two sets A and B, the Cartesian product: A X B={ ( a , b )| a Ab B }

Fact: If |A| = n and |B| = m, then |AxB| = mn.


A = {a, b, c, d}, B = {1, 2, 3}
A B = {(a,1), (a,2), (a,3), (b,1), (b,2), (b,3), (c,1), (c,2), (c,3), (d,1), (d,2), (d,3) }

Example: If there are 4 men and 3 women, there are possible married couples.
Fact: If |A| = n and |B| = m, then |AxB| = mn.

In general let A = {a1, a2, a3, , am} and B = {b1, b2, , bn}. We can arrange the elements into a table as follows.

A B = {(a1,b1), (a1,b2) ,, (a1,bn), (a2,b1), (a2,b2),, (a2,bn), (a3,b1), (a3,b2),, (a3,bn), , (am,b1), (am,b2),, (am,bn)}

There are m rows, and each row has n elements, and so there are a total of mn elements.

Fact: |A1xA2xxAk| = |A1|x|A2|xx|Ak|.


The formal proof uses mathematical induction. But the proof idea is not difficult. We think of A 1xA2xxAk as (
((A1xA2)xA3)xAk). That is, we first construct A1xA2, and it is a set of size |A 1|x|A2|. Then, we construct (A1xA2)xA3,
the product of A1xA2 and A3, and it is a set of size (|A 1|x|A2|)x|A3| by the product rule on two sets. Repeating the
argument, we can see that |A1xA2xxAk| = |A1|x|A2|xx|Ak|.

EXAMPLE: COUNTING STRINGS


What is the number of 10-bit strings?

Let B={0,1} the set of 2-bit strings is just BxB. The set of 10-bit strings is just BxBxBxBxBxBxBxBxBxB, denoted by
B10.

By the product rule, |BxB| = |B|x|B| = 2x2 = 4, and |B 10| = |B|x|B|x|B|x|B|x|B|x|B|x|B|x|B|x|B|x|B| = |B| 10 = 210 =
1024.

EXAMPLE: IP ADDRESSES
What is the number of IP addresses?

An IP address is of the form 192.168.0.123. There are four numbers, each is between 0 and 255.
Let B={0,1,,255}. Then the set of IP addresses is just B 4. By the product rule, |B4| = |B|4 = 2564 = 4294967296.

EXAMPLE: PRODUCT RULE


In general, we have:

The number of length-n strings from an alphabet of size m is |Bn| = |B|n.

e.g. the number of length-n binary strings is 2n


the number of length-n strings formed by capital letters is 26 n

EXAMPLE: COUNTING PASSWORDS


How many passwords satisfy the following requirements?
Between 6 & 8-character long, starts with a letter, case sensitive, other characters: digits or letters

First we define the set of letters and the set of digits.


L = {a,b,,z,A,B,,Z}
D = {0,1,,9}

We first count the number of passwords with a specific length.

Let Pn be the set of passwords with length n.


P6=L x ( L D ) x ( L D ) x ( L D ) x ( LD ) x ( LD )

L x ( LD )5

Pn
=length n passwords

L x ( LD )n1

L Dn1
|L x ( L D )n1|=| L| by product rule
|L|+ D

by sum rule
|L|
n1
56 62

The set of Passwords: Counting by Partitioning


P=P6 P 7 P8 This is a common technique.

P P6|+ P7|+ P8 Divide the set into disjoint subsets.


5 6 7
56 62 +56 62 +56 62 Count each subset and add the answers.

186125210680448
19 1014

EXAMPLE: AT LEAST ONE SEVEN


How many # 4-digit numbers with at least one 7?

Method 1
count by 1st occurrence of 7:
7xxx + o7xx + oo7x + ooo7
where x represents any digit from 0 to 9,
The set of 4-digit while o represents any digit from 0 to 9 except 7.
numbers with 7 in Clearly, each number containing at least one 7 is in
the first digit. one of the above sets, and these sets are disjoint.
The set of 4-digit numbers Therefore, the answer to the question is:
with 7 in the second digit, but 103 + 9102 + 9210 + 93 = 3439

(counting by partitioning)
How many # 4-digit numbers with at least one 7?

Method 2
|4-digit numbers with at least one 7| = |4-digit numbers| - |those with no 7s|
= 104 94
= 3439
(counting the complement)

Counting the complement is a useful technique.

DEFECTIVE DOLLARS
A dollar is defective if some digit appears more than once in the 6-digit serial number.

How common are non-defective dollars?

10 possible choices for the first digit, 9 possible choices for the second digit, and so onSo, there are
10x9x8x7x6x5 = 151200 serial numbers with all its digit different. There are totally 10 6 = 1000000 serial numbers.
So, only about 15% of dollars are non-defective.

GENERALIZED PRODUCT RULE


Q a set of length-k sequences. If there are:
n1 possible 1st elements in sequences,
n2 possible 2nd elements for each first entry,
n3 possible 3rd elements for each 1st & 2nd,

then, |Q|=n1 n2 n3 n k
PERMUTATIONS
Definition: A permutation of a set S is a sequence that contains every element of S exactly once.

For example, here are all six permutations of the set {a, b, c}:
(a, b, c) (a, c, b) (b, a, c)
(b, c, a) (c, a, b) (c, b, a)

Ordering is important here.

How many permutations of an n-element set are there?


You can think of a permutation as a ranking of the elements.
So the above question is asking how many rankings of an n-element set.

There are n choices for the first element. For each of these, there are n 1 remaining choices for the second
element. For every combination of the first two elements, there are n 2 ways to choose the third element, and so
forth. Thus, there are a total of n (n 1) (n 2) 3 2 1 = n! permutations of an n-element set.

n
e
Stirlings formula:

n ! 2 n

EXAMPLE: PERMUTATION
Suppose each digit is an element in {1,2,3,4,5,6,7,8,9}. How many 9-digit numbers are there where each nonzero
digit appears once?

Each such number corresponds to a permutation of 123456789, and each permutation corresponds to such a
number. So the numbers of such numbers is equal to the number of permutations of {1,2,3,4,5,6,7,8,9}. Hence
there are exactly 9! such numbers. Alternatively, one can use the generalized product rule directly to obtain the
same result.

COMBINATIONS
How many subsets of size k of an n-element set?

Consider the set {1,2,3,4,5} where n=5.

If k=2, then there are 10 possible subsets of size 2,


i.e. {1,2}, {1,3}, {1,4}, {1,5}, {2,3}, {2,4}, {2,5}, {3,4}, {3,5}, {4,5}.

If k=3, then there are also 10 possible subsets of size 3,


i.e. {1,2,3}, {1,2,4}, {1,2,5}, {1,3,4}, {1,3,5}
{1,4,5}, {2,3,4}, {2,3,5}, {2,4,5}, {3,4,5}

Ordering is NOT important here.

There are n choices for the first element.


For each of these, there are n 1 remaining choices for the second element.
There is n k + 1 remaining choices for the last element.
Thus, there are a total of n (n 1) (n 2) (n k + 1) to choose k elements.

So far we counted the number of ways to choose k elements, when the ordering is important.
e.g. {1,2,3}, {1,3,2}, {2,1,3}, {2,3,1}, {3,1,2}, {3,2,1} will be counted as 6 different ways.

How many different ordering of k elements are (over)-counted?

e.g. If we are forming subsets of size 3, then (1,2,3), (1,3,2), (2,1,3), (2,3,1), (3,1,2), (3,2,1) are counted as 6
different ways if the ordering is important.

In general, each subset of size k has k! different orderings, and so each subset is counted k! times in the above way
of choosing k elements.

Each subset is counted, but is counted k! times, because each subset contributes k! different orderings to
the above.
So, when the ordering is not important, the answer is:

This is the shorthand for n choose k


EXAMPLE: TEAM FORMATION
There are m boys and n girls. How many ways are there to form a team with 3 boys and 3 girls?

There m are choices of 3 boys n and choices for 3 girls.
3 3

So by the product rule m n there are choices of such a team.
3 3
If m < 3 or n < 3, then the answer should be zero. Dont worry. We dont like to trick you this way.

EXAMPLE: BIT STRINGS WITH K ZEROS


How many n-bit sequences contain k zeros and (n k) ones?

We can think of this problem as choosing k positions (out of the n possible positions) and set them to zeroes and set
the remaining positions to ones. So the above question is asking the number of possible positions of the k zeros,

and the answer is: (n )


k

EXAMPLE: UNBALANCED BIT STRINGS


We say a bit string is unbalanced if there are more ones than zeroes or more zeros than ones. How many n-bit
strings are unbalanced?

If n is odd, then every n-bit string is unbalanced, and the answer is 2n.
n
If n is even, then the number of balanced strings is ( by choosing n/2 positions to zeroes.
n/2

So the number of unbalanced n-bit strings is equal to the number of all n-bit strings minus the number of balanced
n
strings, and so the answer is 2n - (
n/ 2

(counting the complement)

POKER HANDS
There are 52 cards in a deck. Each card has a suit and a value.

4 suits ( )
13 values (2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A)

Five-Card Draw is a card game in which each player is initially dealt a hand, a subset of 5 cards.

How many different hands? (525)=2598960


EXAMPLE 1: FOUR OF A KIND
A Four-of-a-Kind is a set of four cards with the same value. {8, 8, Q, 8 8}
{A, 2, Q, 2, 8}
How many different hands contain a Four-of-a-Kind?

One way to do this is to first map the problem into a problem of counting sequences.

A hand with a Four-of-a-Kind is completely described by a sequence specifying:


1. The value of the four cards. (8, Q, ) {8, 8, 8, 8, Q}
2. The value of the extra card. (2, A, ) {2, 2, 2, 8, A}
3. The suit of the extra card.
There are 13 choices for (1), 12 choices for (2), and 4 choices for (3). By generalized product rule, there are
13x12x4 = 624 hands.
Only 1 hand in about 4165 has a Four-of-a-Kind!

EXAMPLE 2: FULL HOUSE


A Full House is a hand with three cards of one value and two cards of another
value.

How many different hands contain a Full House?

There is a bijection between Full Houses and sequences specifying:


1. The value of the triple, which can be chosen in 13 ways.
2. The suits of the triple, which can be selected in (4 3) ways.
3. The value of the pair, which can be chosen in 12 ways.
4. The suits of the pair, which can be selected in (4 2) ways.

By generalized product rule, there are

Only 1 hand in about 634 has a Full House!

EXAMPLE 3: TWO PAIRS


How many hands have Two Pairs; that is, two cards of one value, two cards of another value, and one card of a third
value?

1. The value of the first pair, which can be chosen in 13 ways.


2. The suits of the first pair, which can be selected (4 2) ways.
3. The value of the second pair, which can be chosen in 12 ways.
4. The suits of the second pair, which can be selected in (4 2) ways
5. The value of the extra card, which can be chosen in 11 ways.
6. The suit of the extra card, which can be selected in 4 ways.

Number of Two pairs =

Double Count!

So the answer is

EXAMPLE 4: EVERY SUIT


How many hands contain at least one card from every suit?

1. The value of each suit, which can be selected in 13x13x13x13 ways.


2. The suit of the extra card, which can be selected in 4 ways.
3. The value of the extra card, which can be selected in 12 ways.

Double count!

So the answer is 134 x 4 x 12/2 = 685464

Das könnte Ihnen auch gefallen