Content-Type: text/html
Wikipedia: Function
HomePage | RecentChanges | Preferences
You can edit this page right now! It's a free, community project
In mathematics a function (also called map or mapping)
from a set X to a set Y is a binary relation over X and Y that is
- functional (that is, associates with every element in X at most one element in Y) and
- total (that is, associates with every element in X at least one element of Y).
If the binary relation is only functional then it is called a partial function. The set X is called the domain of the function, and the set Y is called the codomain of the function. The subset
of Y that consists of all elements in Y that are associated with
at least one element in X is called the range or image of the function.
If f is a function from X to Y this is written as f : X -> Y. The unique element in Y that is associated by f with x in X is written as f(x).
Examples:
- The relation wght between persons in the United States and their weight.
- The relation sqr between natural numbers n and their square n2
- The relation nlog between positive real numbers x and their natural logarithm ln(x). Note that the relation between real numbers and their natural logarithm is not a function because not every real number has a natural logarithm, that is, this relation is not total and therefore, only a partial function.
- The relation dist between points in the plane R2 and their distance from the origin (0, 0).
- The relation grav between a point in the plane R2 and the vector describing the gravitational force that a certain mass at that point would experience from a certain other mass in the origin (0, 0).
If the domain of a function is a subset of the Cartesian product of n sets then the function is called an n-ary function. For example, the relation dist has the domain R × R and is therefore a binary function. In that case dist((x, y)) is simply written as dist(x, y).
There are 4 basic kinds of functions. Let f be a function from X to
Y then f is:
- an [into function]? if for some y in Y there is no x in X such that f(x) = y,
- [onto function]? or surjection? if for every y in Y there is an x in X such that f(x) = y,
- [one-to-one function]? or injection? if for every y in Y there is one and only one x in X such that f(x) = y, and
- bijection if it is both "onto" and "one-to-one," or is both a surjection and an injection.
Examples:
- The function abs from Z (the set of Integers) to Z defined by abs(x) = | x | where | x | is the absolute value of x, is "into." Since there exists an integer -5 in Z such that there is no integer i in Z such that abs(i) = -5, abs is "into."
- Consider the function abs* from Z to Z* (the set of non-negative integers) that is defined by the same rule as abs. Then abs* is "onto," or a surjection, since for every y in Z*, that is, every non-negative integer, there is at least one x in Z such that abs*(x) = y.
- Consider the function add1 from Z to Z that is specified by the rule add1(x) = x + 1 then add1 is "one-to-one" or an injection, since for every y in Z there is one and only one x in Z such that add1(x) = y.
- Consider the function add1, as defined above. Then add1 is both "onto" and "one-to-one" or a bijection, since it is already "onto" and we can show it is "one-to-one" as well. Thus, given a y in Z, there is only one x in Z such that add1(x) = y, that is, x = y - 1.
Functions can be specified in several ways. Most functions that relate (combinations of) numbers with numbers are specified by one or more equation. For example, the dist function can be specified with
- dist(x, y) = (x2 + y2)1/2
or
- z = (x2 + y2)1/2
where z is called the dependent variable and x and y are called the independent variables. This type of specification is sometimes called specification by intension.
Another way of specifying functions is by specifying the the binary relation (also called the extension of the function) by either enumerating it or specifying it in set theory. The wght function, for example, might be specified by
- wght = { (Larry, 160), (Jimmy, 165), (Ruth, 125), (Ruth, 125), (Cindy, 120), ... }
and sqr might be specified by
- sqr = { (n, m) | n in N and m in N and m = n2 }.
This type of specification is sometimes also called specification by extension.
A third way of specifying functions that is often used in computer science is specification by computation where it is indicated how the result of the function is computed from the arguments. An example of this is [Lambda expression]?s in [Lambda calculus]? where the function max(a, b) with a and b integers might be specified as
- max = λ (a, b) in Z × Z . if a < b then b else a.
In programming a function is a part of a program that can be called with certain arguments (or parameters) from inside the program or elsewhere, and returns a value. Although the term is related to the mathematical term it is less strict; a function may return different results each time, even if it is called with the same arguments, and a function may have side effects, that is, it may cause changes that remain after the call of the function has ended. An exception to this are functions in pure functional programming that return always the same result if called with the same arguments and have no side effects.
A procedure? is similar to a function but has only side effects and does not return a value. In some programming languages such as [ANSI C]? where there are only functions there is often a type such as void
for the result of a function that has no result.
/Talk