Discrete Mathematics for Computer Science

(Romina) #1
Basic Definitions 229

15-- 4-- 4--
12.5--
10- 3--
3-

7.5- 2- 2-

2.5 I --

-4 -2 2 4 -2 -1 1 2 -2 -1 1 2


Sqr, Sqr~lRT- 2,2U Sqrl {-2, -1, 0, 1, 2)

Figure 4.7 Restrictions of SqrR. A. SqrR B. SqrR 1[-2,21 C. SqrR 11-2,-1,0,1,21.

4.1.7 Partial Functions

Think of a computer program as computing or specifying a function from the input of the
program to its output. The input to the function is whatever string of characters is input to
the program. The output is whatever string of characters has been output by the program
after it has finished execution. Anyone who has programmed a computer realizes that many
programs, on some input data, go into infinite loops and, by the definition above, would
produce no output at all. In that case, the program is not computing a function of the input,
since the definition of a function requires that there be one output for every one input. What
a program computes is really what is called a partial function of its input. On each input,
the program, if it produces any output at all, produces only one possible output. Thus, a
partial function can be thought of as a black box into which for each input there is at most
one possible output.
Another sort of partial function is the following: Suppose the amount of postage to
be paid is specified in Table 4.2 (where the range (3-4] kg is understood to mean that the
parcel weighs more than 3 kg but less than or equal to 4 kg). This table gives postage costs
only as a partial function of the weight of the package, since the postage amount is not
specified for anything weighing more than 16 kg.

Table 4.2 Postage Costs
Weight Postage
(0-1] kg $1.00
(1-2] kg $1.98
(2-3] kg $2.56
(3-41 kg $3.11
(4-51 kg $3.99
(5-81 kg $5.00
(8-12] kg $7.00
(12-161 kg $9.00
Free download pdf