Content-Type: text/html Wikipedia: Function

[Home]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
  1. functional (that is, associates with every element in X at most one element in Y) and
  2. 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:

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:

  1. an [into function]? if for some y in Y there is no x in X such that f(x) = y,
  2. [onto function]? or surjection? if for every y in Y there is an x in X such that f(x) = y,
  3. [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
  4. bijection if it is both "onto" and "one-to-one," or is both a surjection and an injection.

Examples:

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


HomePage | RecentChanges | Preferences
You can edit this page right now! It's a free, community project
Edit text of this page | View other revisions
Last edited August 8, 2001 9:55 am (diff)
Search: