In contrast, a weather prediction service would not be modelled as a function,
because the answer to ‘What will the weather be tomorrow?’ changes from day
to day.
Functions are an important tool, both in mathematics and in computing,
because they provide a mechanism for abstraction. A function is a ‘black box’:
to use it, you need to know the interface, but not the internal details about
how the function is defined.
There are many ways to formalise the function concept. This chapter looks
at the ones that are most important for computer science. We start with one of
the most common mathematical approaches, which treats a function as a special
kind of relation, and then we will consider a more algorithmic way of defining
functions. It is good to remember, however, that the concept of ‘function’ is
abstract, and there are many different formalisms that can be used to define
it.