# Function

A function is a mapping of every point in the input domain into a corresponding (one and only one) point in the output domain. Saying formally, it is an injective relation, i.e. f ⊂ X×Y is said to be a function, which maps elements of X into elements of Y such that if (x1,y) is in f and (x2,y) is in f then x1 = x2. One writes f(x) = y if (x,y) is in f. The typical notation used to denote this fact is

f: X → Y

or y = f(x) or simply f(x). The elements of input domain, x-es, are called arguments of the function and the target elements, y = f(x), are called the values (or result) of the function. Supplying an argument to the function is called valuation.

## Defining and representing functions

You can plot the functions whose arguments and values are numeric. For instance

 x: -3 -2 -1 0 1 2 3 y: 3 2 1 0 1 2 3

maps argument -3 → value 3, -2→2, .., 2→2 and 3→3. If you mark x values on the horizontal axis and go vertically up the height that corresponds to the numerical value of the function, y, for that x, marking a dot for every (x,y) couple, your dots must be located on the red line plotted on the right.

The function defined by the table is discrete and finite. It maps a finite amount of points. There are also continuous functions, the ones whose domain is countable infinite. You cannot use table to define such a function. The analytic form is used in this case, eg. y = x², for a square function.

## Multivalued input and output

A function may have more than one argument. For instance summation

+: a,b → sum

has two arguments and can be denoted by +(a,b). However, you can treat (a,b) as a single composite object, i.e. a vector. Similarly, you can treat w:multivalued functions: since, strictly speaking, a "well-defined" function associates one and only one output to any particular input, you are in trouble defining e.g. a square root function since, for any number except 0 there are two results, e.g. both +2 and -2 squared give 4. In this case it is convenient to think that the function produces a set, {-2,+2}.

## Vectors

Since you can multiply the function by a scaler, s (in this case the function values will be s times larger/smaller), and add functions together arriving at another function, the functions can be referred to as vectors. Basically vectors and functions are the same things. The only difference is that argument is called index in case of vector and vectors are more often discrete and by dimension of function you mean the amount of arguments it has where as vector dimension is the cardinality of the index range. For instance, vector [1,8,3] is a function that maps 0→1, 1→8 and 2→3.

This is further elaborated in the operator theory, where operators are higher order functions, which means that are functions over functions. For instance, differentiation is an operator, it e.g. translates a function sin(x) → cos(x). The operators are often finitely discrete and represented in matrix form in this case by rectangles whereas vectors are single columns and by, dot product, operator (a function) translates a vector (a function) into another vector (another function).

## Procedures in programming

The algorithms that compute the values of function, provided the arguments, are known as procedures in programming. Look at the function as a black box that maps input to output whereas the procedure in the internals, the real mechanism that implements the mapping. The point is that you may have many different implementations/algorithms of the same function.

Another differentiation between the procedures and functions in programming is that procedures, in contrast to procedures, always return a single value whereas procedures do not return any values -- they modify the visible state variables/files. The modification of states is known as side effects. Accessing the state of the state of the system is prohibited in the pure functions at all. These functions are appreciated in functional programming, which also uses higher order functions (recall operators and functions over functions). Functional purity simplifies the analysis of program behaviour but also makes functions valid mathematical objects, since the fact that result of such functions is independent on the state of the system means that it depends only on the argument, which means that it always produces the same result, for the same arguments. Functional programming admits w:partial application, when one some but not all arguments supplied to the function.