590 likes | 1.1k Views
Relations. We talked earlier about the Cartesian product, namely the set of ordered pairs of elements taken from S1 and S2.A relation, in general, is any set of ordered n-tuples chosen from n sets.. Relations. But we will mostly study the simplest case, a binary relation on a set S. This corresp
E N D
1. Relations, Functions and Matrices Relations
Functions
The mod function
Matrices
2. Relations We talked earlier about the Cartesian product, namely the set of ordered pairs of elements taken from S1 and S2.
A relation, in general, is any set of ordered n-tuples chosen from n sets.
3. Relations But we will mostly study the simplest case, a binary relation on a set S. This corresponds to sets of ordered pairs, with each of the elements of an ordered pair coming from the same set, S.
Therefore, a binary relation on set S is defined as a subset of S ? S. For simplicity, we will call these things simply binary relations.
We write (x, y) ? ?, or (more simply) x ? y.
4. Relations It's easy to get lost in the notation. Examples should make things clearer. Consider the set S = {1, 2, 3, 4, 5, 6, 7, 8}. The relation < is the set of ordered pairs {(1, 2), (1, 3), (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (2, 3), (2, 4), (2, 5), (2, 6), (2, 7), (2, 8), (3, 4), (3, 5), (3, 6), (3, 7), (3, 8), (4, 5), (4, 6), (4, 7), (4, 8), (5, 6), (5, 7), (5, 8), (6, 7), (6, 8), (7, 8)}
5. Relations
6. Relations There are a number of important properties by which we characterize relations.
Given two sets S and T,
7. Relations There are a number of important properties by which we characterize relations.
Given two sets S and T,
8. Relations There are a number of important properties by which we characterize relations.
Given two sets S and T,
9. Relations There are a number of important properties by which we characterize relations.
Given two sets S and T,
10. Relations Properties of binary relations.
? is reflexive if every element is related to itself
? is symmetric if whenever s ? t, then t ? s
? is transitive if whenever s ? t and t ? u, then s ? u
These properties hold only if the conditions are true in ALL cases.
11. Relations One other property of binary relations.
? is antisymmetric if every we never have the situation s ? t and t ? s unless s = t.
12. Relations What are some examples of relations that have such properties?
reflexive: =, = , ?, "has the same eye color as"
symmetric: =, "has the same cardinality as"
transitive: every one of the above
not transitive: "is 10 more than"
antisymmetric: = , ?, <
13. Relations The closure of a relation ? with respect to property P is denoted by ?* and satisfies these conditions:
?* has the property P
? ? ?*
?* is the smallest such relation that is a superset of ?.
14. Relations
15. Relations
16. Relations
17. Partial Orderings A relation that is reflexive, antisymmetric and transitive is called a partial ordering .
When a relation on a set is a partial ordering, we call the underlying set a partially ordered set, or poset.
Consider a relation on the set {1, 2, 3, 6, 12, 18}
The above set is a partially ordered set under the relation "divides into".
reflexive: a always divides into itself
antisymmetric: the only way a divides into b and b divides into a is if a = b
transitive: a divides into b, b divides into c, then a divides into c.
18. Partial Orderings Given a partial ordering ?, if x ? y and x ? y then x is said to be a predecessor of y.
If x is a predecessor of y and there is no other element z between x and y, then x is called an immediate predecessor of y.
Similar definitions apply for successor and immediate successor.
19. Partial Orderings If an element in a partially ordered set is "less than" every other element we call it a least element.
If an element has no other element "less than" it, we call it a minimal element
the least element is the absolutely "smallest element" (if it exists).
a minimal element is any of the smallest elements (if more than exists) or the least element if there's only one.
20. Partial Orderings If an element in a partially ordered set is "greater than" every other element we call it a greatest element.
If an element has no other element "greater than" it, we call it a maximal element
the greatest element is the absolutely "biggest element" (if it exists).
a maximal element is any of the biggest elements (if more than exists) or the greatest element if there's only one.
21. Partial Orderings A Hasse diagram shows the nature of posets and partial orderings. In it, the least elements are drawn at the bottom and the greatest elements at the top. In between we draw lines between elements of the set if one element is an immediate predecessor of the other.
An example makes this much more clear
22. Partial Orderings A Hasse Diagram illustrates the nature of a partial ordering.
Consider "divides into" on {1, 2, 3, 6, 12, 18}
23. Partial Orderings A partial ordering in which every element is related to every other element (in one way or the other) is called a total ordering, or chain.
The relation = on the integers is a total ordering.
The previous example (Hasse diagram) is not a total ordering.
24. Equivalence Relations A binary relation that is reflexive, symmetric and transitive is called an equivalence relation
Typically, equivalence relations are relations of things similar or equal. For example:
=
equivalent sets
= mod n
25. Equivalence Relations Equivalence relations do something different to a set than partial orderings.
Equivalence relations subdivide and cover the underlying set.
subdivide: group together a subset containing all elements that are equivalent to each other. No two such sets overlap.
cover: the collection of these subsets covers the entire set. The union of these subsets is the original set.
26. Equivalence Relations This process is called partitioning. Each subset created is called a partition, or equivalence class.
Example: two integers n = m (mod 5) if and only if (n mod 5) = (m mod 5)
there are 5 equivalence classes: all the numbers who are divisible by 5, all the numbers that leave a remainder of 1 when divided by 5, and so on.
27. Equivalence Relations This process is called partitioning. Each subset created is called a partition, or equivalence class.
Example: equals. two integers are equal
there are an infinite number of equivalence classes, since every number is equal to itself and to nothing else.
28. Equivalence Relations This process is called partitioning. Each subset created is called a partition, or equivalence class.
Example: Given the power set of {a, b, c, d, e}
S =T if they have the same cardinality.
How big is the equivalence class containing {a, b, c}?
Remember our counting problems!
29. Functions A function is a special case of a binary relation between sets S and T.
A function is a binary relation on S ? T such that each and every element s in S is related to exactly one element t in T.
The set S is called the domain, the set T is called the codomain, and the subset of T containing all the elements that are mapped to is called the range.
f : S?T
30. Functions What are some examples of functions?
f(x) = x2 + 4x 5
f(S) = the length of string S. What is the domain? What is the codomain?
etc.
31. Properties of functions A function is said to be onto if the range is the same as the codomain; every element of T is mapped to
Onto functions are sometimes called surjections, or are said to be surjective.
An onto function maps to every element in the codomain.
32. Properties of functions Is the function f(x) = 4x 5 onto?
It is if the domain and codomain are both the set of all rationals (?) since every rational number y, the number (y+5)/4 is also rational.
It isn't if the domain and codomain are both the set of (?). For example, no integer maps to 1.
33. Properties of functions A function is said to be one-to-one if no member of the range is mapped to by more than one element of the range.
One-to-one functions are sometimes called injections, or are said to be injective.
Is the function f(x) = x2 + 4x 5 one-to-one?
It is if the domain and codomain are both the set of all natural numbers (?), because every number = 0 maps to a unique value.
It isn't if the domain and codomain are both the set of all integers (?). The values f(-5) = f(1) = 0.
34. Properties of functions Functions that are one-to-one and onto are called bijections, or are said to be bijective.
35. Composition of functions Functions can be combined. Consider the functions f:S ?T and g:T ?U. The composition of these functions, written as g ? f : S ? U represents the combination obtained by applying f to some member of S and then applying g to the result. For any element s in S, g ? f(s) = g(f(s)).
36. Composition of functions What is the composition g ? f of the functions f(x) = x3 and g(x) = x + 3 if the domains and codomains are all the set of all integers?
f(x) = x3. g(x3) = x3 + 3. g ? f (x) = x3 + 3
What is the composition f ? g of the functions f(x) = x3 and g(x) = x + 3 if the domains and codomains are all the set of all integers?
g(x) = x+3. f (x+3) = (x + 3)3 = (x + 3)3 . f ? g (x) = (x + 3)3
37. Inverse functions The inverse of a function is the "reversal" of that function.
An identity function is any function that maps every element to itself.
The inverse function f -1 of function f : S ? T is the function f -1: T ? S such that f -1 ? f : S ? S is the identity function.
The inverse of x + 3 is the function x 3. Note that (x + 3) 3 = x
38. Permutation functions A bijection is sometimes called a permutation function.
Why? Because since the domain and range are identical, we are merely rearranging the elements of the domain.
We sometimes write permutation functions in cycle notation: f = (1, 2, 3) with the understanding that each value maps to the next value in the list and that the last one maps back to the first. We usually leave out cycles of length 1.
39. Permutation functions The cycle notation is merely a listing of all the cycles in the permutation. An example of a cycle is 1 ? 3, 3 ? 6, 6 ? 2, and 2 ? 1. This would be written as (1, 3, 6, 2).
All permutations are merely a collection of cycles
Cycle notation: f = (1, 5, 3, 8)(2, 6, 7)(4)
Writing down cycles with only one element is optional
40. The mod function We have seen the mod function a number of times already.
In review x mod r is the remainder left when dividing x by r.
For example, 93 mod 7 = 2, since 93 when divided by 7 is equal to 13 with a remainder of 2.
41. The mod function In computer science, the mod function raises its ugly head in a number of places.
Two such places are
Hashing
Encryption
42. Hashing Hashing is a method of storing data for very efficient data retrieval. For a million items,
a linear search of the data would require at worst a million comparisons.
A binary search would require at worst about 20 comparisons.
We can do even better.
43. Hashing Hashing is the idea of storing the data to be searched in a large area of storage, hopefully enough space to hold many times the amount of actual data.
Data is placed in a location determined by a hash function.
The hash function is dependant on the data itself and on the size of the storage area
44. Hashing To save space (important!!!) we put data into consecutive locations and use a super large array of pointers.
If done perfectly, each data item will go into a unique location (the hash function is one-one).
Perfection is almost impossible to attain.
Therefore two or more items will collide, and a secondary function called the rehash function must be used.
45. Hashing
46. Hashing How do we minimize the number of collisions?
a hash function that distributes the data evenly throughout the storage.
the hash table size should be a prime number, and the hash function should use the mod function as a determinant in computing the location.
if the size is not prime, data usually clumps together in spots.
47. Hashing Example: Parts in an inventory are identified by a six-character code:
a12c2x
b42f6n
If there are about a million parts in the inventory, let's build a hash table of size 3,000,077 (which is prime).
If there are no more than 100 parts, use a size of 307, for example.
48. Hashing Example: Parts in an inventory are identified by a six-character code:
a12c2x
b42f6n
If there are about a million parts in the inventory, let's build a hash table of size 3,000,077 (which is prime).
If there are no more than 100 parts, use a size of 307, for example.
What should we use as the hash function? How about the sum of the ASCII values of each character times its position in the identifier, mod 307?
49. Hashing a12c2x
(97*1 + 49*2 + 50*3 + 99*4 + 50*5 + 120*6) mod 307
1711 mod 307 = 176
b42f5n
(98*1 + 52*2 + 50*3 + 102*4 + 53*5 + 111*6) mod 307
1691 mod 307 = 156
It's too hard to keep redrawing my figure, so let's pretend that the hash values were 304 and 3.
50. Hashing
51. Hashing Of course this is not a particularly good function. That sort of analysis is beyond this course.
There still can be collisions, and we can resolve a collision by placing the data in the next unused location available.
52. Hashing Since the table size is three times the amount of data, there will be a lot of gaps, which is good! (fewer collisions)
But what about collisions?
suppose part z99d1a mapped to location 305.
suppose part a34e3b mapped to location 304.
53. Hashing
54. Cryptography The simple Caesar cipher:
given key k (some natural number)
Encoding: f(p) = g-1([g(p) + k) mod 26
Decoding: f-1(c) = g-1([g(c) - k) mod 26
For example, with a key of 3,
encoding E: F-G-H. H stands for E
decoding B: A-Z-Y. Y stands for B.
55. Modified Homework 4.5/1, 2, 4, 5, 7-10, 14,15
56. Matrices and operations on them A matrix looks like
57. Matrices and operations on them If r is a numerical value, then scalar multiplication is represented as
58. Matrices and operations on them Matrix addition can only be performed on two matrices of the same shape (same number of rows and same number of columns
59. Matrices and operations on them Matrix multiplication A ? B (or simply AB) can only be performed on two matrices if the number of columns of A is equal to the number of rows of B. An n ? m matrix multiplied by an m ? k matrix yields an n ? k matrix.