Composition of Functions
If the range of a function
is a subset of
the domain Y of a function
, we can compose
the two functions f and g to obtain a function
defined by:
, for all
.
For example, let f be the successor function on the integers,
i.e., f(n) = n+1, and g be the squaring function,
.
Then
whereas
If domain and codomain of a function are identical, it can be composed with itself:
and
Perfect Shuffles
A perfect shuffle of a deck of cards splits the deck in half and then merges the two halves so that no two adjacent cards come from the same half.
The reason we use shuffles on a deck of cards is to mix them up.
So what happens if we do a series of eight consecutive perfect shuffles on a 52 card deck? The example below shows that we end up with the cards in the same order as we started!!!
What this shows is that the composition of eight shuffles gives the identity function:
Why do eight suffice? Observe that (except for the last card),
the shuffle takes position x to position
.
Further,
, so multiplying it eight times is like
multiplying by 1, i.e. the identity function.
Properties of Composed Functions
Recall that the identity function
on a domain A
is defined to be a function from A to A
with
,
for all elements x of the domain A.
Theorem
If f is a function from A to B, then
![]()
and
![]()
Certain properties of functions carry over to their composition.
Theorem
If f is a one-to-one function from A to B and g a one-to-one function from B to C, thenis a one-to-one function from A to C.
If f is an onto function from A to B and g an onto function from B to C, then
is an onto function from A to C.
The Inverse of a Function
If f is a bijective function
from A to B,
its inverse is a function
from B to A,
defined by:
For example, if f is the function on the real numbers,
defined by f(x)=4x-1,
then
, for all real numbers y.
Note that the inverse of a bijective function is also bijective.
The above definition is valid since for a bijective function f the value f(x) is uniquely determined by x. But this is also the case for one-to-one functions.
Can we define an inverse for any one-to-one function f, even if f is not onto?
Yes, but in that case the inverse is a function from the range of f to the domain of f.
Application of Functions: Codes
Let
be the set
and
be the set of all finite sequences,
or strings,
of elements of
.
Let us map characters in
to bitstrings as follows.
We can extend this mapping to a function on
by defining:
For example, the code C(eaabb) is the bitstring
Is the function C one-to-one? Onto?
In general, encoding functions need to be one-to-one, for otherwise decoding may be difficult, or impossible.
Character codes like this (ascii) is how text strings are represented in computers.
Prefix Codes
Now consider a different, variable-length, code:
With this function we can encode eabbe by a shorter bitstring
But can we also decode strings?
No, the code could also represent the string baaabbbaa. In other words, the function is not one-to-one.
Let's look at another variable-length code.
The encoding of eabbe by D' yields
Is this function one-to-one?
The answer is yes, as the function represents a so-called prefix code, that is, no codeword C(x) is a prefix of another codeword C(y), where x and y denote different symbols.
How are bitstrings decoded in this case?