A **function** (or more strictly, a **well-defined function**) is a rule that assigns to every element in a set $ D $ exactly one element, called the **image**, from another set $ C $ . The set $ D $ is called the **domain**, while the set $ C $ is called the codomain. The subset of the codomain which precisely contains the set of all values that are assigned to some value in the domain is called the **range**

## Definition

When defining a function $ f $ with domain $ D $ and codomain $ C $ , it is common to denote it by $ f:D\to C $ .

For example, the function $ f:\R\to\R $ could be defined by the formula

- $ f(x)=x^2 $

with domain D being the real numbers and the range R being the non-negative real numbers. This function assigns the value 4 in the range to the number −2 in the domain.

- $ f(-2)=4 $

Formally, a relation $ \mapsto $ from a set $ D $ to set $ C $ is said to be a function if it satisfies the following properties:

**Totality**: for each $ d\in D $ , there exists a $ r\in C $ such that $ d\mapsto r $ .**Functionality**: for each $ d\in D $ and any $ r,s\in C $ , if $ d\mapsto r $ and $ d\mapsto s $ , then $ r=s $ .

The first condition asserts that every element in the domain has an image in the codomain, while the second states that such an image is unique. This definition, however, allows the following possibilities for a function:

- Two or more distinct elements in the domain may have the same image;
- One or more element in the codomain may not be the image of any element in the domain.

One may also speak of multi-valued functions, which only satisfy the totality property, and of partially-defined functions, which only satisfy the functional property.

With those possibilities in mind, we may define a function $ f:D\rightarrow C $ to be one of these three types of functions:

**Injection**,**injective function**, or**one-to-one**: for any $ a,b\in D $ , if $ f(a)=f(b) $ then $ a=b $ ;**Surjection**,**surjective function**, or**onto**: for any $ c\in C $ , there exists an $ a\in D $ such that $ f(a)=c $ ;**one-to-one correspondence**,**bijection**,**bijective function**, or**invertible**, if $ f $ is both injective and surjective.

## Notation

As a function $ f $ from a set $ D $ to a set $ C $ is formally a relation, which itself is a subset of the cartesian product $ D\times C $ , the notations $ x\,f\,y $ (viewing $ f $ as a relation), and $ (x,y)\in f $ are valid. However, whenever given an arbitrary $ x\in D $ , it is cumbersome in writing to state that "there exists a unique $ y\in C $ such that $ x\,f\,y $". Therefore, we will define the preferred notation $ f(x) $ to refer to the aforementioned unique $ y\in C $ . Therefore, the following notations are equivalent:

- $ (x,y)\in f $ , when viewing $ f $ as a subset of the Cartesian product $ D\times C $ ;
- $ x\,f\,y $, when viewing $ f $ as a relation from $ D $ to $ C $ ;
- $ f(x)=y $

## Examples

In practice, a function is completely determined through a formula that assigns the variables. For example:

- $ y=f(x)=x^2+1 $

$ y $ is the depending variable and $ x $ is the independent one.