LetF be a partial function from domainAto rangeBwith the following properties: 1. For every elementainA, there is an elementbin Bsuch that F(a) =b. 2. For everybin B, there is someain Asuch thatF(a) =b.
3. For nobinBare there two elementsa1anda2inAsuch thatF(a1) andF(a2)
are both b.
ThenF is said to be aone-to-one correspondencefromAtoB. The termbijection
is also used for a one-to-one correspondence.
Property (1) says that F is a total function from Ato B. Property (2) is the condition of beingonto: Fis a total function fromAontoB. Some mathematicians use the term surjectionfor a total function that is onto.
Surjection
Properties (2) and (3) together say thatF behaves like a total function from
B toA. A total function with property (3) is sometimes called aninjection.
Injection
A one-to-one correspondence is basically a total function in both directions, but it is important to observe that whetherF is a one-to-one correspondence depends not only on the pairs inF, but on the declared domain and range. For example, we could take any one-to-one correspondence from AtoB and change the domain by
adding toAsome new elementenot mentioned inF. F would not be a one-to-one correspondence fromA∪ {e}to B.
✦
Example 7.24.
The squaring functionS from Zto Zof Example 7.23 is not a one-to-one correspondence. It does satisfy property (1), since for every integerithere is some integer, namely, i2, such that S(i) =i2. However, it fails to satisfy
(2), since there are some b’s inZ— in particular all the negative integers — that are not S(a) for any a. S also fails to satisfy (3), since there are many examples of two distinct a’s for which S(a) equals the same b. For instance, S(3) = 9 and
S(−3) = 9.
For an example of a one-to-one correspondence, consider the total function P
fromZtoZdefined byP(a) =a+1. That is,P adds 1 to any integer. For instance,
P(5) = 6, andP(−5) = −4. An alternative way to look at the situation is that P
consists of the tuples
{ . . . , (−2,−1), (−1,0), (0,1), (1,2), . . .}
or that it has the graph of Fig. 7.17.
We claim thatP is a one-to-one correspondence from integers to integers. First, it is a partial function, since when we add 1 to an integerawe get the unique integer
a+ 1. It satisfies property (1), since for every integera, there is some integera+ 1, which isP(a). Property (2) is also satisfied, since for every integerb there is some integer, namely, b−1, such that P(b−1) = b. Finally, property (3) is satisfied, because for an integer b there cannot be two distinct integers such that when you add 1 to either, the result isb.✦
· · · −2 −1 0 1 2 · · ·
Fig. 7.17. Graph for the relation that is the functionP(a) =a+ 1.
A one-to-one correspondence from A to B is a way of establishing a unique association between the elements of A and B. For example, if we clap our hands together, the left and right thumbs touch, the left and right index fingers touch, and so on. We can think of this association between the set of fingers on the left hand and the fingers on the right hand as a one-to-one correspondence F, defined by
F(“left thumb”) = “right thumb”, F(“left index finger”) = “right index finger”, and so on. We could similarly think of the association as the inverse function, from the right hand to the left. In general, a one-to-one correspondence from A to B
can be inverted by switching the order of components in its pairs, to become a one-to-one correspondence fromB toA.
A consequence of the existence of this one-to-one correspondence between hands is that the number of fingers on each hand is the same. That seems a natural and intuitive notion; two sets have the same number of elements exactly when there is a one-to-one correspondence from one set to the other. However, we shall see in Section 7.11 that when sets are infinite, there are some surprising conclusions we are forced to draw from this definition of “same number of elements.”
SEC.7.8 IMPLEMENTING FUNCTIONS AS DATA 373
EXERCISES
7.7.1: Give an example of setsAandB for whichA×Bis not the same asB×A.
7.7.2: LetR be the relation defined byaRb,bRc,cRd,aRc, andbRd. a) Draw the graph of R.
b) IsR a function?
c) Name two possible domains forR; name two possible ranges.
d) What is the smallest setS such thatRis a relation onS(i.e., the domain and the range can both be S)?
7.7.3: Let T be a tree and let S be the set of nodes of T. LetR be the “child- parent” relation; that is,cRpif and only ifcis a child of p. Answer the following, and justify your answers:
a) IsR a partial function, no matter what treeT is? b) IsR a total function fromS toS no matter whatT is?
c) CanRever be a one-to-one correspondence (i.e., for some treeT)? d) What does the graph forRlook like?
7.7.4: LetRbe the relation on the set of integers{1,2, . . . ,10}defined byaRbifa
andb are distinct and have a common divisor other than 1. For example, 2R4 and 6R9, but not 2R3.
a) Draw the graph forR.
b) IsR a function? Why or why not?
7.7.5*: Although we observed thatS = (A×B)×C and T =A×(B×C) are not the same set, we can show that they are “essentially the same” by exhibiting a natural one-to-one correspondence between them. For each (a, b), c
inS, let
F (a, b), c
= a,(b, c)
Show thatF is a one-to-one correspondence fromS toT.
7.7.6: What do the three statementsF(10) = 20, 10F20, and (10,20) ∈ F have in common?
7.7.7*: Theinverseof a relationRis the set of pairs (b, a) such that (a, b) is inR.
Inverse relation
a) Explain how to get the graph of the inverse ofR from the graph forR. b) If Ris a total function, is the inverse of R necessarily a function? What if R
is a one-to-one correspondence?
7.7.8: Show that a relation is a one-to-one correspondence if and only if it is a total function and its inverse is also a total function.
✦ ✦ ✦
✦
7.8
Implementing Functions as Data
In a programming language, functions are usually implemented by code, but when their domain is small, they can be implemented using techniques quite similar to the ones we used for sets. In this section we shall discuss the use of linked lists, characteristic vectors, and hash tables to implement finite functions.