Definition: (1) A computation which takes some arguments or inputs and yields an output. Any particular input yields the same output every time. More formally, a mapping from each element in the domain to an element in the range. (2) A subroutine which returns a value.
Generalization (I am a kind of ...)
Specialization (... is a kind of me.)
boolean function, constant function, unary function, binary function, trinary function, n-ary function, total function.
Aggregate child (... is a part of or used in me.)
See also procedure, predicate.
Note: (1) A relation may map an input to more than one output. Every function is a relation. The inverse of a function, a mapping from the function's outputs to its inputs, may be a relation rather than another function.
Consider √(x). The domain and the range are the nonnegative real numbers, R0+. For instance 4 is mapped to 2. The inverse is the function x², which maps 2 to 4. Cosine is also a function, since every angle has a specific cosine, but its inverse cos-1(x) is a relation, since a cosine value maps to many (for cosine, infinitely many) angles.
A function which takes no arguments is a constant function, or simply, a constant. Since a function must return the same value for each input and the input cannot change (since it has no arguments), it must always return the same value. For instance, if the function one() always returns 1, we can use it instead of the constant 1. This is theoretically convenient because we can always work with functions, rather than with functions and constants.
(2) A subroutine which does not return a value is called a "procedure" in some programming languages.
If you have suggestions, corrections, or comments, please get in touch with Paul Black.
Entry modified 17 December 2004.
HTML page formatted Wed Mar 13 12:42:46 2019.
Cite this as:
Paul E. Black, "function", in Dictionary of Algorithms and Data Structures [online], Paul E. Black, ed. 17 December 2004. (accessed TODAY) Available from: https://www.nist.gov/dads/HTML/function.html