Lecture 6: Mathematical Structures and Functions - CSCI 381 Goldberg
Cost of Exhaustive Searching (Brute-Force Method)
Section titled “Cost of Exhaustive Searching (Brute-Force Method)”Here, the Time Complexity equals the size of the search space.
Initially, mathematical structures are stored in un/ordered sets.
Structure 1: Subsets of a Set -
Section titled “Structure 1: Subsets of a Set - 2n2^n2n”How many subsets are there of a given set?
Suppose a set - for elements, and in C/C++ based languages the first index is 0.
A method to encode such a set with its subsets is by using a one-dimensional array/vector:
| 1 | 1 | 0 0 0 | 1 |
Sub/set
Any subset (of a set of size ) can simply be encoded by boolean values stored in the above vector.
For example, subset :
The small 2 after the digits denotes base 2.
So counting the number of subsets is equivalent to determining how many bitstrings (arrays of only 0/1 values) of size there are. As mentioned many times before, this finite string of length can be encoded by natural numbers ranging from (when the vector contains all 0’s) to (when the vector contains all 1’s). So a simple for loop enumerating the natural numbers from to can each be decoded into the binary representation of each such natural number, which automatically represents a unique subset of an initial set of size .
In summary, there are such subsets, which is also where = powerset.
Structure 2: Relations(hips) from a Set to a Set -
Section titled “Structure 2: Relations(hips) from a Set S1S_1S1 to a Set S2S_2S2 - 2mn2^{mn}2mn”Conventionally, and .
S1 S2
A1 B1A2 --> B2Ai .. .Am BnA graph is a “graph”ical representation of a relation. Standard (default) relations have two sets, whereas standard (default) graphs are from one set to itself. But this is only a default convention - relations can be over one set and graphs can be over two sets. A graph from set to a set is called bipartite.
Note: For diagramming purposes, the two sets appear of the same length (size) but mathematically of course of any size. This is indicated by the fact that , , with most probably .
The Cartesian Product is ONE such relationship/mapping but contains the maximum number of connections FROM/TO:
Now, an arbitrary relation from to will be a subset of . has ALL possible connections from to ; a random subset has SOME of the possible connections. SOME is a subset of ALL. Therefore:
Since is one subset of , then ALL relations are ALL subsets of , which is . Based on Structure 1:
In sets, the relation with the most number of connections is the Cartesian Product , and in its corresponding graph, the graph with all possible edges is called Complete, noted by the letter for Komplete. (Complete, but not to be confused with other usages of .) if two sets and if over one set.
Structure 3: Directed Graphs over a Set -
Section titled “Structure 3: Directed Graphs over a Set SSS - 2n22^{n^2}2n2”Graph where is the vertex set (aka nodes) and is the edge set (aka arcs).
(Compare with Structure 2 with as ; here .) In fact, a graph is a “graph”ical representation of a relation.
The conventional defaults for relations and directed graphs are slightly different but they both are “two sides” of the same coin. In the case of relations (Structure 2), the default is a mapping from a set to a set (i.e. two sets involved), but the default for directed graphs is a mapping over a single set . Now the two are the same because there is no restriction on and , and in fact we can have , in which case relations are identically directed graphs. Not just that but that - the elements are the same.
Therefore, we can use Structure 2 to count the number of directed graphs over , . Namely, set and . Then, the number of directed graphs over a single set :
Consider a relatively “small” vertex set with nodes/vertices. The number of different directed graphs over this set (WOW!!!!). (That is larger than the claimed number of molecules in the universe.)
(The number of undirected graphs is left as a homework exercise.)
Structure 4: Partial Mapping from a Set to a Set -
Section titled “Structure 4: Partial Mapping from a Set S1S_1S1 to a Set S2S_2S2 - (n+1)m(n+1)^m(n+1)m”S1 S2
A1 B1A2 --> B2Ai Bj. .Am BnIn a partial mapping, each element has independently possible elements to choose from to map into (though, at most one), but in addition, each element has the extra right to not go at all (this is what causes the mapping to be “partial” or undefined). The partial mapping can only make one of these choices for each element .
Each therefore has choices:
In basic probability theory (and basic analysis of algorithms), the independent choices are multiplied together. The number of partial mappings from a set of size to a set of size equals .
Structure 5: Total Mapping (Function) from a Set to a Set -
Section titled “Structure 5: Total Mapping (Function) from a Set S1S_1S1 to a Set S2S_2S2 - nmn^mnm”S1 S2
A1 B1A2 --> B2Ai Bj. .Am BnIn a total mapping, each element has independently possible elements to choose from to map into, but each element must go to exactly one element . Note that all can go to the same .
Exactly one is not the same as uniquely one (next structure). Exactly one is purely a quantitative issue. Uniquely one is also qualitative.
Total functions that all map to the same element are called Constant Functions. For example .
Each has choices:
In basic probability theory (and basic analysis of algorithms), the independent choices are multiplied together. The number of total mappings from a set of size to a set of size equals .
Structure 6: Injective Mapping (1-1 Function) from a Set to a Set -
Section titled “Structure 6: Injective Mapping (1-1 Function) from a Set S1S_1S1 to a Set S2S_2S2 - n!(n−m)!\frac{n!}{(n-m)!}(n−m)!n!”aka Permutations
S1 S2
A1 B1A2 --> B2. .. .. .Am BnInjective mappings are also Total. Based on the pigeonhole principle, the uniqueness property of 1-1 mappings requires therefore that .
In a 1-1 mapping, each element must uniquely choose one of the remaining possible to map into, and each element must go to some (since 1-1 is also Total).
To see why the number of choices decreases, imagine a waiter at a party carrying a tray of 100 different shaped cakes - each one unique. The first person the waiter approaches has 100 choices and takes one. The second person now only has 99 choices, the third has 98, and so on. Because of the uniqueness requirement, whatever cake a person takes is no longer available to the next person. The same logic applies here: makes its choice first (wlog), which removes one from availability, leaving with choices, and so on.
Each gets fewer choices as prior elements have already claimed a :
In basic probability theory (and basic analysis of algorithms), the independent choices are multiplied together. The number of injective mappings from a set of size to a set of size equals:
This sort of looks like a defective factorial function. So, the literature uses an algebraic trick to count the number of such 1-1 mappings - multiply by 1:
This is ALSO the number of ways to permute a subset of a set. As above, . Thus, we can view the 1-1 mapping as a two-step process:
-
- (Select or) Choose of the elements in set . This is , aka , aka . Note: the convention for combinatorics is that the LARGER size is written first, here (since ), even though in terms of its cousin the 1-1 mapping, the set of size is visited/used first. Likewise for even though we select (“deal with”) first. = Combinations.
- Count the number of permutations of a set of size . How many permutations of size ?
In summary, what we have here is the following:
Thus, a 1-1 mapping is identical to permuting a subset of elements from a larger set.
Structure 7: Surjective Mapping (Onto Function) from a Set to a Set - see below
Section titled “Structure 7: Surjective Mapping (Onto Function) from a Set S1S_1S1 to a Set S2S_2S2 - see below”Every element in is reached.
S1 S2
A1 B1A2 --> B2. .. .. .Am BnOnto mappings are also Total, so no can go to more than one . All elements of are connected to (“reached”) by the elements of set . Therefore, .
No one knows how to directly calculate the number of surjective mappings. Instead, the approach utilized is to count the number of total functions that are NOT onto:
(cf. Structure 5 above.)
The complication that occurs is due to the Inclusion-Exclusion (I-E) principle, which deals with offsetting the possibility of counting the same elements more than once.
Inclusion-Exclusion Principle
Section titled “Inclusion-Exclusion Principle”For example, suppose the math students club and the computer science society decide to have an end of year party (only students allowed). and . Every student attends the party. How many students in total attended the party?
The first glance approach would be students. But this is not necessarily correct, because this ignores the possibility that the same student(s) is a double major. Thus, the correct answer is .
I-E applied:
Pascal’s triangle has an interesting connection to I-E - the combinatorics involved in the I-E principle are the coefficients present in Pascal’s triangle:
These are rows of Pascal’s triangle.
Applying I-E to Count (Non-)Surjective Mappings
Section titled “Applying I-E to Count (Non-)Surjective Mappings”S1 S2
A1 B1A2 --> B2. .. .. .. Bn.Am(Note that .)
How many ways can we prevent the general total mapping from becoming surjective? (wlog means “without loss of generality”: the theorem does not depend on which element(s) we use; we choose the elements simply for the ease of discussing them.)
-
- We will not allow any element to reach (wlog) - (one element)
- We will not allow any element to reach (wlog) or - (two elements)
- We will not allow any element to reach (wlog) - ( elements)
Once we have stopped the total mapping from becoming surjective, the total mapping is then free to map to whichever remaining it wants.
Putting this all together:
- How many ways can we prevent the total mapping from reaching elements of ?
- How many remain after preventing the total mapping from reaching those elements?
- How many total functions are there from (all of the ‘s) to the remaining free elements?
How does the I-E principle apply here? When you prevented the mapping from reaching one element of , this also includes the situation of preventing it from reaching two elements of , as follows:
- (forced) The first of the two elements is prevented because you explicitly prevented it.
- (free) The second of the two elements can also be prevented because the remaining total function had no obligation to go to this second element.
This latter situation is then numerically equivalent to one of the cases where you explicitly prevented the mapping from reaching two of the . Thus, the I-E principle applies and we need to put in the correction factor.
Putting this all together:
where the sum accounts for: Possible NON_ONTO, I-E correction, Choosing ‘s, and .
Therefore:
Structure 8: Partitions and How They Relate to Surjective Mappings -
Section titled “Structure 8: Partitions and How They Relate to Surjective Mappings - ONTO(m,n)n!\frac{\text{ONTO}(m,n)}{n!}n!ONTO(m,n)”A partition of a set is a subdivision into subsets such that with the following conditions:
-
- Each is nonempty - (every box purchased is being used)
- must be a subset of - (no extraneous element crept in) (*)
- - (all original elements have been packed)
- unless - (mutually disjoint)
(*) Assumes is unordered and hence has only unique elements and no duplicates.
The above assumed that a) the owner of the original set decided ahead of time how many boxes (or subsets) to use (here, ). A different scenario is that it is up to b) the packers to decide on their own how many boxes to use. These scenarios get slightly different names in discrete mathematics:
- a) k-partition: - , the number of pieces (subsets) in the partition, is fixed ahead of time.
- b) partition: - no initial restriction is placed on the number of boxes.
Connection Between k-Partitions and ONTO Mappings
Section titled “Connection Between k-Partitions and ONTO Mappings”There is a fascinating connection between k-partitions and ONTO mappings. Consider:
S1 S2
a1 b1a2 b2a3 --> b3a4 b4a5a6a7a8a9a10Here, .
For example, one surjective mapping vs. a second surjective mapping:
Surjective mapping 1:
- reached by
- reached by
- reached by
- reached by
Surjective mapping 2:
- reached by
- reached by
- reached by
- reached by
In terms of ONTO, these are different ONTO mappings. But in terms of partitions, they are the same - since the ORDER of the boxes does not matter, only which elements are packed with which elements. In both cases, the same elements are with the same elements as before. This then becomes the same difference between Combination and Permutation, so that the counting differs by .
Conclusion:
Note: is the number of ways of ordering elements (here the boxes that the elements are packed into). Dividing removes the consideration of order, whereas multiplying by would add in the consideration of order.
The Bell number is the number of partitions for a set of a given size. The above is for k-partitions. So, the Bell number is the summation over all possible :
( are generically called “k-partitions” even though here .)
Structure 9: Bijections - Also Known as 1-1 Correspondence -
Section titled “Structure 9: Bijections - Also Known as 1-1 Correspondence - n!n!n!”A bijection (aka 1-1 correspondence) is a (total) function that is both 1-1 (injective) and onto (surjective). Its importance is that it allows for the definition of an inverse - inverse means that the relation holds true in the other direction as well.
S1 S2
a1 b1a2 --> b2. .Ai Bj. .am bn
m = |S1| n = |S2|Recall that both injective and surjective have constraints on the sizes of the sets:
- Injective:
- Surjective:
- Therefore, Bijective:
Discrete Mathematics then has a theorem that proves that an alternative (but equivalent) definition for bijective can be: 1-1 (injective) and equal sized sets ().
So, recall that the number of injective mappings equals . But here , so the number of bijections equals:
Why Can’t an Injective Mapping Alone Already Have an Inverse?
Section titled “Why Can’t an Injective Mapping Alone Already Have an Inverse?”S1 S2
a1 b1 |a2 --> b2 | (reached by S1). . |am bm | bm+1 . . bn
m = |S1| n = |S2|, m <= nSimply, can’t we argue that the manner in which we mapped from an element in to an element in should provide the exact manner of getting back? Imagine for simplicity . Couldn’t the bijection simply be ?
The official answer is that since can be bigger in size, there will possibly be some extra elements that are not involved in this mapping. This makes the complete mapping of set back to a partial function.
A counter-argument is that the extra elements of were never reached by the elements from and therefore should not be part of our discussion of going back (“inverse”). In numerical analysis, this argument is presented and based on this, the mapping back (the inverse) uses only the subset of elements from that were initially reached by the elements of . This type of inverse is termed a pseudo-inverse.
Partial Calculator
Section titled “Partial Calculator”The faceplate of a scientific calculator illustrates partial functions in practice. Several buttons yield undefined (invalid) results for certain inputs:
| Button | Invalid Input | Windows Response | Note | |
|---|---|---|---|---|
| (a) | Cannot divide by zero | |||
| (b) | Invalid input | Square root function on any negative value | ||
| (c) | Invalid input | Or any negative value - typically natural number base | ||
| (d) | Invalid input | Or any negative value - base | ||
| (e) | Cannot divide by zero | When the denominator is zero () | ||
| (f) | *This is technically wrong (see below) | |||
| (g) | Invalid input | The “inverse sin” function. Not defined for any where | ||
| (h) | Invalid input | The “inverse cos” function. Not defined for any where | ||
| (i) | or | Invalid input | Value is in degrees | |
| (j) | Invalid input | Or any negative value |
*Regarding where , there are two different rules that clash:
-
- raised to any power equals .
- Any number raised to power equals .
Technically, is undefined - and so undefined due to the contradiction that it is called indeterminate. Computer theory needed to define as equal to in order for certain mathematical recursions to work, so Martin Davis (the modern founder of computer theory) chose rule 2 and assigned .