The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Winson (32) [Avatar] Offline
At right hand side of figure 2.1, why the codomain did not contain fractional number so that the function f(x) = x/2 has corresponding element in the codomain?
Pierre-Yves Saumont (183) [Avatar] Offline

As indicated in the legend at the bottom right of the figure, this is arbitrary. A function is an application from one set to an other set. To qualify as a function, this application must conform to the rules. From this, it results that the same application can be a function from set A to set B and not from set A to set C, nor from set D to set B.

This is what is illustrated in the figure. F-1(x) is an application from N to N, but it is not a function. It would be a function from the set of even numbers to N. It would also be a function form N to Q. The intent (when not choosing Q as the target set) was to show that what looks like the same application may or may not be a function depending what source set and/or target set you chose.

The term "partial function" is sometimes used to qualify an application that would be a function if the source set was restricted or if the target set was extended. Partial functions often break programs. f(x) = 1/x is a partial function (which means it is not a function) form Z (signed integers including 0) to Q (fractional numbers). It is a function from Z* (Z without 0) to Q. It is also a function from Z to (Q + error).

Making programs safe is often a matter of changing partial functions into total ones, which means dealing with errors in the return value, and not as a side effect, like throwing exceptions. This is what chapter 6 is all about.