CS 236 – Discrete Mathematics
Download
Report
Transcript CS 236 – Discrete Mathematics
Relations: Operations & Properties
Power Sets
• Set of all subsets of a set A.
– A = {1,2}
– P(A) = 2A = { {}, {1}, {2}, {1,2} }
• We note that each element of A is either present (1) or not
present (0). If we treat the elements of A as a sequence, we
get a bit-string that represents the set.
– If A = {a,b,c,d}, we can order the elements in a sequence <a,b,c,d>.
– Then, we can let the bit-string say which elements are present: e.g.
0110 means {b,c}.
– We can represent all the subsets of A, from = 0000 to U = 1111.
• This bit-string notation also helps us know the number of
subsets in the powerset (just count in binary)
– 2#A, 2|A| = 2 · 2 · … · 2
(|A| times)
– This motivates the notation 2A for the power set.
Bit-String Operations on Power Sets
• With bit string representations
–
–
–
–
Set intersection: = pairwise
Set union: = pairwise
Set complement: ~ = bit complement
Set minus: – = mask out using 1’s = complement 2nd
operand and do pairwise
• E.g. using {a,b,c,d}
–
–
–
–
1011 1101 = 1001
1011 1101 = 1111
~1011 = 0100
1010 – 1100 = 0010
i.e. {a,c,d} {a,b,d} = {a,d}
i.e. {a,c,d} {a,b,d} = {a,b,c,d}
i.e. ~{a,c,d} = {b}
i.e. {a,c} – {a,b} = {c}
Binary Relations
• Sets of ordered 2-tuples (pairs) with values selected from
domains (sets)
• Formally, a relation R from set A to set B is a set of pairs (x,y)
such that x A and y B. We may write R:A B to express
this.
– R AB
– If (x,y) R, we say that x is R-related to y; we may also write xRy.
– Example:
• <: NN (where N is the set of natural numbers)
• (2,3) < or 2<3
– Predicates also define relations
<:{0,1,2}{1,0,1,2}
= {(x,y) | x {0,1,2} y {1,0,1,2} x < y}
= { (0,1), (0,2), (1,2) }
Representations for Binary Relations
Tables
Matrices
-1
0
1
2
0
0
0
1
1
1
0
0
0
1
2
0
0
0
0
<
-1
0
1
2
0
0
0
1
1
1
0
0
0
1
2
0
0
0
0
Graphs
- directed graph or digraph
- directed arcs
0
1
2
-1
0
1
2
Domains and Ranges for Binary Relations
Let R = {(0,1), (0,2), (1,2)}, then
• Domain of R = dom R = dom(R) = {x | y((x,y) R)}
– i.e. {0,1}
– like XR
• Range of R = ran R = ran(R) = {y | x((x,y) R)}
– i.e. {1,2}
– like YR
Domain
0
1
Domain Space
2
-1
Range Space
0
1
2
Range
Inverse
• If R: AB, then the inverse of R is R~: BA.
• R-1 is also a common notation
• R~ is defined by {(y,x) | (x,y) R}.
– If R = {(a,b), (a,c)}, then R~ = {(b,a), (c,a)}
– > is the inverse of < on the reals
• Note that R~ ~R
– The complement of < is
– But the inverse of < is >
Set Operations
• Since relations are sets, set operations apply
(just like relational algebra).
• The arity must be the same indeed, the
sets for the domain space and range space
must be the same (just like in relational
algebra).
Restriction & Extension
• Restriction decreases the domain space or range space.
Example: Let < be the relation {(1,2), (1,3), (2,3)}. The restriction of
the domain space to {1} restricts < to {(1,2), (1,3)}.
• Extensions increase the domain space or range space.
Example: Let < be the relation {(1,2), (1,3), (2,3)}. The extension of
both the domain space and range space to {1,2,3,4} extends < to
{(1,2), (1,3), (1,4), (2,3), (2,4), (3,4)}
• Extensions and restrictions need not change the relation.
– Suppose {M1, M2, M3} are three males and {F1, F2, F3} are three
females and married_to is {(M1,F3), (M2,F2)}.
– Removing the unmarried male M3 or the unmarried female F1 does
nothing to the relation, and adding the unmarried male M4 or the
unmarried female F4 does nothing to the relation.
Composition
• Let R:AB and S:BC be two relations. The composition of R and S,
denoted by RS, contains the pairs (x,z) if and only if there is an
intermediate object y such that (x,y) is in R and (y,z) is in S.
• Given R:AB and S:BC, with A = {1,2,3,4}, B = {1,2,3,4,5}, C =
{1,2,3,4}, and R = {(1,3), (4,2), (1,1)} and S = {(3,4), (2,1), (4,2)}, we
have:
RS = {(1,4), (4,1)}
SR = {(3,2), (2,3), (2,1)}
(i.e. not commutative)
R(SR) = {(1,2), (4,3), (4,1)}
(RS)R = {(1,2), (4,3), (4,1)} (i.e. is associative)
Graphically:
S
R
1
2
3
4
1
2
3
4
5
1
2
3
4
Composition & Matrix Multiplication
• Relation matrices only contain 0’s and 1’s.
• For relational matrix multiplication, use
for *, for +, with 1=T and 0=F.
R
RS
S
1
2
3
4
5
1
1
0
1
0
0
2
0
0
0
0
0
3
0
0
0
0
0
4
0
1
0
0
0
1
2
3
4
1
0
0
0
0
2
1
0
0
0
3
0
0
0
1
4
0
1
0
0
5
0
0
0
0
=
1
2
3
4
1
0
0
0
1
2
0
0
0
0
3
0
0
0
0
4
1
0
0
0
RS(1,1) = (10)(01)(10)(00)(00) = 0
RS = {(1,4), (4,1)}
Combined Operations
• All operations we have discussed can be combined
so long as the compatibility requirements are met.
• Example:
R: A B S: B A
A = {1,2,3}
R = {(1,1), (3,1), (1,2)}
B = {1,2,3}
S = {(1,1), (2,3)}
(R S)~ R
= {(1,1), (3,1), (1,2), (2,3)}~ R
= {(1,1), (1,3), (2,1), (3,2)} R
= {(1,1), (1,2), (2,1), (2,2)}
Properties of Binary Relations
• Properties of binary relations on a set R: AA help
us with lots of things groupings, orderings, …
• Because there is only one set A:
– matrices are square |A| |A|
– graphs can be drawn with only one set of nodes
R = {(1,3), (4,2), (3,3), (3,4)}
1
2
3
4
1
0
0
1
0
2
0
0
0
0
3
0
0
1
1
4
0
1
0
0
1
2
3
4
Reflexivity
• Reflexive: x(xRx)
=, , “is in same major as”, etc.
Reflexive
1
1
2
2
3
1
1
1
3
Note:
Irreflexive
1
1
2
3
2
Neither
3
1
0
1
0
e.g., <
0
2
3
2
3
0
1
e.g., “loves”
1
Symmetry
• Symmetric: xy(xRy yRx)
• Antisymmetric: xy(xRy yRx x = y)
“sibling” is symmetric
, are antisymmetric (if ab and ba, then a=b)
= is symmetric and antisymmetric
“loves” is neither symmetric nor antisymmetric
1
(always both ways)
(never both ways)
(but to self is ok)
1
2
3
0
1
2
0
1
3
1
1
1
2
3
1
0
Note: antisymmetry is
2
1
NOT asymmetry
3
1
0
Transitivity
• Transitive: xyz(xRy yRz xRz)
“taller” is transitive
< is transitive
x<y<z
“ancestor” is transitive
“brother-in-law” is not transitive
• Transitive: “If I can get there in two, then I
can get there in one.”
and
if
x
y
then
z
(for every x, y, z)
Transitivity (cont’d)
• Note: xRy yRz corresponds to xRRz, which is
equivalent to xR×Rz = xR2z; thus we can define
transitivity as:
xyz(xR2z xRz)
“If I can get there in two, then I can get there in one.”
• For transitivity:
– if reachable through an intermediate, then reachable
directly is required.
– if (x,z)R2, then (x,z)R
(x,z)R2 (x,z)R
R2 R (recall our def. of subset: xA xB, then AB)
Transitivity (cont’d)
1
2
1
2
3
1
0
1
1
2
0
0
1
3
0
0
1
3
2
3
Not Transitive
2
3
1
0
1
1
2
0
0
1
3
0
0
1
1
2
3
1
0
1
0
2
0
0
1
3
0
0
0
R
=
1
2
3
1
0
0
1
2
0
0
1
3
0
0
1
R2 R
R
R
Transitive
1
1
1
2
3
1
0
1
0
2
0
0
1
3
0
0
0
R
=
1
2
3
1
0
0
1
2
0
0
0
3
0
0
0
R2 R
Closures & Equivalence Relations
Closure
Closure means adding something until done.
– Normally adding as little as possible until some
condition is satisfied
– Least fixed point similarities
Reflexive Closure
Reflexive closure of a relation: R(r)
– smallest reflexive relation that contains R (i.e.
fewest pairs added)
– R(r) = R IA (R is a relation on a set A, and IA
is the identity relation 1’s on
the diagonal and 0’s elsewhere.)
R=
1
2
3
1
0
1
0
2
0
0
1
3
1
1
1
R(r) =
1
2
3
1
1
1
0
2
0
1
1
3
1
1
1
x (xRx)
Symmetric Closure
Symmetric closure of a relation: R(s)
– smallest symmetric relation that contains R (i.e.
fewest pairs added)
– R(s) = R R~
(R~ is R inverse)
R=
1
2
3
1
0
1
0
2
0
0
1
3
1
1
1
R~
=
1
2
3
1
0
0
1
2
1
0
1
3
0
1
1
R
R~
=
1
2
3
1
0
1
1
2
1
0
1
3
1
1
1
xy(xRy yRx)
Transitive Closure
Transitive closure of a relation: R(t) = R+
– smallest transitive relation that contains R (i.e.
fewest pairs added)
– for each path of length i, there must be a direct
path. (This follows from xy, yz xz;
since, if we also have vx, we must have vz,
a path of length 3.)
– R(t) = R R2 R3 … R|A|. (No path can
be longer than |A|, the number of elements in
A.)
Transitive Closure – Example 1
1
2
3
1
0
1
0
2
0
0
1
3
1
1
1
1
2
3
1
0
0
1
2
1
1
1
3
1
1
1
1
2
3
1
1
1
1
R3
2
1
1
1
=
3
1
1
1
R=
R2
R×R2
=
RR2R3
=
=
1
2
3
1
1
1
1
2
1
1
1
3
1
1
1
1
2
All paths of
length 1
3
1
2
All paths of
length 2
3
1
2
All paths of
length 3
3
Transitive Closure – Example 2
R=
R2
R×R2
=
=
R3
=
RR2R3
=
1
2
3
1
0
0
0
2
0
0
1
3
0
1
0
1
2
3
1
0
0
0
2
0
1
0
3
0
0
1
1
2
3
1
0
0
0
2
0
0
1
3
0
1
0
1
2
3
1
0
0
0
2
0
1
1
3
0
1
1
1
All paths of
length 1
2
3
1
All paths of
length 2
2
3
1
2
3
All paths of
length 3
1
Paths of
any length
2
3
Reflexive Transitive Closure
• Reflexive transitive closure of a relation: R*
– smallest reflexive and transitive relation that contains R
– R* = IA R+ = R0 R+ = R0 R1 R2 …R|A|
• Example:
IA =
R0
=
1
2
3
1
1
0
0
2
0
1
0
3
0
0
1
R0 R1 R2 R3 =
R1
1
2
3
1
1
0
0
2
0
1
1
3
0
1
1
R2
R3
=
1
2
3
1
2
3
1
0
0
0
2
0
1
1
3
0
1
1
Equivalence Relations
A relation R on a set A is an equivalence relation if R
is reflexive, symmetric, and transitive.
– Equivalence relations are about “equivalence”
– Examples:
• = for integers x = x
reflexive
x=yy=x
symmetric
x=y y=z x=z
transitive
• = for sets
A=A
reflexive
A=BB=A
symmetric
A=B B=C A=C
transitive
• Let R be “has same major as” for college students
xRx reflexive: same major as self
xRy yRx symmetric: same major as each other
xRy yRz xRz transitive: same as, same as same as
Partitions
•
A partition of a set S is
–
–
•
•
a set of subsets Si=1,2,…n of S
such that ni=1 Si = S, Sj Sk = for j k.
Each Si is called a block (also called an equivalence class)
Example:
–
Suppose we form teams (e.g. for a doubles tennis tournament)
from the set:
{Abe, Kay, Jim, Nan, Pat, Zed}
then teams could be:
{ {Abe, Nan}, {Kay, Jim}, {Pat, Zed} }
•
Note: “on same team as” is reflexive, symmetric,
transitive an equivalence relation. Equivalence
relations and partitions are the same thing (two sides of
the same coin).
Partitions (cont’d)
• Since individual elements can only appear in one
block (Sj Sk = for j k), blocks can be
represented by any element within the block.
e.g.
Nan’s Team
Jimmer’s 2011 sweet-16 team
• Formally, [x] = set of all elements related to x and
y [x] iff xRy
e.g.
[Nan] represents {Abe, Nan}, Nan’s team
[Abe] represents {Abe, Nan}, Abe’s team
[Jimmer] represents the set of players who
played on BYU’s 2011 sweet-16 team
Partitions & Equivalence Relations
Example:
• The mod function partitions the natural numbers into equivalence classes.
–
–
–
–
–
–
–
–
0 mod 3 = 0 so 0 forms a class [0]
1 mod 3 = 1 so 1 forms new class [1]
2 mod 3 = 2 so 2 forms new class [2]
3 mod 3 = 0 so 3 belongs to [0]
4 mod 3 = 1 so 4 belongs to [1]
5 mod 3 = 2 so 5 belongs to [2]
6 mod 3 = 0 so 6 belongs to [0]
…
• Thus, the mod function partitions the natural numbers into equivalence
classes.
– [0] = {0, 3, 6, …}
– [1] = {1, 4, 7,…}
– [2] = {2, 5, 8, …}
Partitions Equivalence Relations
Theorem: If {S1, …, Sn} is a partition of S, then R:SS is an
equivalence relation, where R is “in same block as.”
Note: to prove that R is an equivalence relation, we must prove that
R is reflexive, symmetric, and transitive.
Proof: Reflexive: since every element is in the same block as itself.
Symmetric: since if x is in the same block as y, y is in the same
block as x. Transitive: since if x and y are in the same block and y
and z are in the same block, x and z are in the same block.
Equivalence Relations Partitions
Theorem: If R:SS is an equivalence relation and [x] = { y | xRy },
then { [x] | x S } is a partition P of S.
Note: to prove that we have a partition, we must prove (1) that every
element of S is in a block of P, and (2) that for every pair of distinct
blocks Sj and Sk (jk) of P, Sj Sk = .
Proof: (1) Since R is reflexive, xRx, every element of S is at least in
its own block and thus in some block of P. (2) Suppose Sj Sk
for distinct blocks Sj and Sk of P. Then, at least one element y is in
both Sj and Sk. Let Sj = {y, x1, … xn} and Sk = {y, z1, … zm}, then
yRxi, i=1, 2, …, n, and yRzp, p=1, 2, …, m. Since R is symmetric,
xiRy, and since R is transitive xiRzp. But now, since the elements of Sj
are R-related to the elements of Sk, x1, …, xn, y, z1, …, zm are together
in a block of P and thus Si and Sk are not distinct blocks of P.
Partial Orders
Partial Orders
• Total orderings: single sequence of elements
• Partial orderings: some elements may come
before/after others, but some need not be ordered
• Examples of partial orderings:
“set inclusion, ”
“must be completed before”
foundation
{a, b, c}
framing
plumbing
wiring
finishing
{a, b}
{a, c}
{b, c}
{a}
{b}
{c}
Partial Order Definitions
(Poset Definitions)
• A relation R: SS is called
a (weak) partial order if it is
reflexive, antisymmetric,
and transitive.
e.g. on the integers
• A relation R: SS is called
a strict partial order if it is
irreflexive, antisymmetric,
and transitive.
e.g. < on the integers
1
2
3
1
2
3
Total Order
• A total ordering is a partial ordering in which every
element is related to every other element. (This forces
a linear order or chain.)
1
• Examples:
R: on {1, 2, 3, 4, 5} is total.
Pick any two; they’re related one way
or the other with respect to .
R: on {{a, b}, {a}, {b}, } is not total.
We can find a pair not related one way
or the other with respect to .
{a} & {b}: neither {a} {b} nor {b} {a}
2
3
4
5
{a,b}
{b}
{a}
Hasse Diagrams
We produce Hasse Diagrams from directed graphs of
relations by doing a transitive reduction plus a
reflexive reduction (if weak) and (usually) dropping
arrowheads (using, instead, “above” to give direction)
1) Transitive reduction discard all arcs except those that
“directly cover” an element.
2) Reflexive reduction discard all self loops.
For
we write:
{a, b}
{a, b}
{a}
{b}
{a}
{b}
Upper and Lower Bounds
• If a poset is built from relation R on set A, then any
x A satisfying xRy is an upper bound of y, and any
x A satisfying yRx is a lower bound of y.
• Examples: If A = {a, b, c} and R is , then {a, c}
- is an upper bound of {a}, {c}, and .
- is also an upper bound of {a, c} (weak poset).
- is a lower bound of {a, b, c}.
- is also a lower bound of {a, c} (weak poset).
Maximal and Minimal Elements
• If a poset is built from relation R on set A, then y A is a
maximal element if there is no x such that xRy, and x A
is a minimal element if there is no y such that xRy.
(Note: We either need the poset to be strict or x y.)
• In a Hasse diagram, every element with no element
“above” it is a maximal element, whereas every element
with no element “below” it is a minimal element.
Maximal elements
Minimal elements
Least Upper and Greatest Lower Bounds
• A least upper bound of two elements x and y is a
minimal element in the intersection of the upper
bounds of x and y.
• A greatest lower bound is a maximal element in
the intersection of the lower bounds of x and y.
• Examples:
– For , {a, c} is a least upper bound of {a} and {c},
is a greatest lower bound of {a} and {b, c}, and
{a} is a least upper bound of {a} and .
– For the following strict poset, lub(x,y) = {a,b}, lub(y,y)
= {a,b,c}, lub(a,y) = , glb(a,b) = {x,y}, glb(a,c) = {y}
a
b
x
y
c
Functions
Function Definition
• A function is a special kind of binary
relation.
• A binary relation f A B is a function if
for each a A there is a unique b B
y
1
α
2
β
3
γ
x
NOT Functions
1
α
2
β
3
γ
f = {(1, α), (2, β)}
“For each” violated
y
Some x’s do not have
corresponding y’s
x
NOT Functions
1
α
2
β
3
γ
f = {(1, α), (2, β), (3, β), (3, γ)}
uniqueness violated for 3
appears twice
y
Uniqueness violated for some
x’s
x
Functions
with N-Dimensional Domains
An (n+1)-ary relation f A1 A2 …
An B is a function if for each < a1, a2,
…, an> A1 A2 … An there is a
unique b B.
<1,1>
α
<1,2>
β
<1,3>
γ
Notation for Functions
• We can use various notation for functions: for
f = {(1, α),(2, β),(3, β)}
Notation
(x, y) f
f : x→y
y = f(x)
Example
(2, β) f
f : 2→β
β = f(2)
• In the notation, x is the argument or preimage
and y is the image. We can also have the
image of a set of arguments.
• For functions with n-ary domains, use <x0, x1,
…, xn> in place of x.
Function Domain and Range
• f:A→B
– A is the domain space
• same as the domain (since all elements participate)
• dom f, dom(f), or domain(f)
– B is the range space
• may or may not be the same as the range, which is:
– {y | x(y=f(x))}
– All rhs values in pairs (all that get “hit”)
– Bf
• ran f, ran(f), range(f)
• f : D1 D2 … Dn → Z
• f : Dn → Z (when all domains are the same)
Partial Functions
Remove the requirement that each a A must
participate. Retain the uniqueness requirement.
Partial Function:
<1,1>
α
<1,2>
β
<1,3>
γ
NOT a Partial Function:
<1,1>
α
<1,2>
β
<1,3>
γ
Partial Function: (A
Total Function is also a
Partial Function.)
<1,1>
α
<1,2>
β
<1,3>
γ
f = {(<1,2>, β),(<1,3>, β),(<1,3>, γ)}
<1,3> not unique
Special Functions
• Identity Function
– IA : A → A
– IA = {(x, x) | x A}
• Constant Function
–C:A→B
– C = {(x, c) | x A c B }
– Often A and B are the same
• C:A→A
• C= {(x, c) | x A c A}
Overloading
• The same name can be used for different
functions depending on the domain.
• Examples
a–b
• Means number subtraction if a and b are numbers
• Means set subtraction if a and b are sets
a+b
• Implemented differently for integers and reals
• Could potentially be overridden and implemented by
a programmer for very long integers
Composition of Functions
a
f
1
2
b
3
g(2) = α
g(f(a)) = α
g°f(a) =
α
f(b) = 2
g(2) = α
g(f(b)) = α
g°f(b) =
α
f(c) = 4
α
β
4
c
f(a) = 2
g
g(4) = β
g(f(c)) = β
• Composition is written
“°”
• Range space of f =
domain space of g
Injection
Injection: “one-to-one” or “1-1”
– xy(f(x) = f(y) x = y)
– For f : A → B, the elements in B are “hit” at most once
Injective
NOT Injective
1
a
1
b
b
2
3
a
2
c
d
3
c
d
y
y
x
x
Surjection
Surjection: “onto”
– yx(y = f(x))
– For f : A → B, the elements in B are all “hit” at least once
Surjective
NOT Surjective
1
2
3
4
a
1
2
b
3
4
c
a
b
c
y
y
x
{
not
“hit”
x
Bijection
Bijection: “one-to-one and onto” or “1-1 correspondence”
– xy(f(x) = f(y) x = y) yx(y = f(x))
– For f : A → B, every B element is “hit” once and only once
Bijective
NOT Bijective
1
2
a
1
2
b
3
3
4
c
NOT Surjective
NOT injective
a
b
c
y
y
x
x
Notes on Bijection
1. |A| = |B|
–
–
An “extra” B cannot be “hit” (not a surjection)
An “extra” A requires that at least one B must be
“hit” twice (not an injection)
2. If f is a bijection, swapping the elements of the
ordered pairs is a function
–
–
–
–
Called the inverse
Denoted f-1
Is also a bijection
f-1(f(x)) is the identity function, i.e. f-1(f(x)) = x.
Notes on Bijection (cont’d)
3. The inverse of an injection is a partial function.
If f : A →B is an injection, then f-1 is a partial function
f
1
f-1
a
a
b
b
2
c
d
3
c
d
4. Restricting the range space of an injective
function to the range yields a bijection
Remove b
1
2
3
Which is bigger? N or R[0..1]?
Assume |N| = |R[0..1]|, then there exists a
bijection:
1 0.34234…
2 0.34987…
diagonalization
3 0.00040…
But now there exists a number in R[0..1] such that
d1 = not 3, d2 = not 4, d3 = not 0, … . Hence, not
surjective and thus not bijective.
Which is bigger? N or Z?
f(x) =
g(y) =
{
{
x odd: (x+1)/−2
x even: x/2
y negative: −2x−1
y positive: 2x
x
0
1
2
3
4
y
0
−1
1
−2
2
Since g = f−1, there is a bijection from N to Z and thus |N| = |Z|.
Countable if same cardinality as some subset of N.
Alternatively, a set S is countable if there exists an injective
function from S to N.