The set of all allowable values of the independent variables of a function is called the domain of the function. The set of possible values returned by a function is called the codomain. The range of a function is the set of all actual values the function may return corresponding to the domain. Functions are named after their ranges, for example real functions return real numbers and complex functions return complex numbers. An endofunction has a range that is identical to its domain.
The codomain is the type of output that the function was declared to produce. A function may be declared as:
This means that the range of the function is A and the codomain is B. The range is the set of values that the function actually takes on, that is f(A). For example, the function below has a domain and codomain that are in the set of real numbers and a range that is the set of nonnegative real numbers:f: A -> B
The codomain is only a matter of definition; we could declare the function above as:f: R -> R, f(x) = x2
This would define the codomain to be the same as the range. Another example, let:f: R -> f(R)
Here, the domain and codomain are both defined as the set of real numbers. The range is the set of all positive numbers. We could have written the definition of the function above as:g: R -> R, g(x) = e2x
where R+ denotes the set of all positive real numbers. With this function declaration, the codomain and range are the same.h: R -> R+, h(x) = e2x
The domain of a function is all the values of the independent variables for which the algebraic operations are defined. That is, values which would imply division by zero or taking the square root of a negative number may not be in a domain. Consider the function:
_______
f: (-∞, 2] -> R, f(x) = √ 2 - x
This declaration states that the domain is the set of real numbers in the interval
(-∞, 2], and that the codomain is the set of real numbers. The range of this
function would be [0, +∞).
In a computer program, the data types of the arguments to a function and the data type of the return value specify respectively, the domain and codomain of a function. For example, the sine function is declared in the Zeno programming language as:
This declaration states that the argument of the function, the domain, is a floating point number and that the returned value of the function, the codomain, is also a floating point number. This particular function has a range that is in the interval [1, 1].sin( x : real) : real