A function is a rule that associates inputs with outputs.
They form the core of many aspects of mathematics and numerous programming languages.
The fundamental explanation of functions comes from Set Theory, in which a function is regarded as the mapping from one set, , to another set, , expressed as:
Functions are commonly denoted using the letters , , , or .
Consider a function, , that maps a set of people's names to their ages:
The set of possible inputs is called the Domain of a Function or :
The set of possible outputs is the co-domain or of the function.
In this case, the co-domain includes all plausible human ages.
Given the input set , the set of possible outputs is . This set is known as the range of the function ( ).
To show a single input-output relationship, we could write:
The output 34 is the function's image, and the corresponding input, , is the pre-image.
Functions are considered a "well-behaved relation". That means that for each input, there must be exactly one output. This example qualifies as a function because each person has a unique, valid age.
We can express functions as the relationship between an input variable and its output. For example, the function to convert temperature in Fahrenheit to Celsius is as follows:
The complete definition of a function should include its domain and co-domain. Since Fahrenheit and Celsius are real numbers, so we would define the function using the Special Infinite Set .
The two parts combined give the complete definition of the function:
In programming languages, mixing the type declaration with the implementation is common. Below is an example of the function in Python. It takes an input as a
float and returns a
float, described using the notation
def f(x: float) -> float:
return (x - 32) * (5/9)
We can create a set of input values and their corresponding outputs, then visualise them geometrically by drawing the inputs and outputs on the x-axis and y-axis, respectively. This visualisation is called a graph of a function.
Here is a plot of the Fahrenheit to Celsius function earlier, plotted across a range of inputs: from -100 to 100.
When the graph is a straight line like this, it's called a Linear Function. There are other names for common function types:
- Linear Function: A function where the output is proportional to the input.
- Quadratic Function: A function where the output is proportional to the square of the input.
- Exponential Function: A function where the output is proportional to a fixed base raised to the power of the input.
- Polynomial Function: A function that we represent as a sum of terms, each consisting of a constant multiplied by a variable raised to a non-negative integer power. Linear and quadratic functions are specific types of polynomial functions.
There are some other important properties of functions:
One-to-one / Injective
We consider a function "one-to-one" or "injective" if each output is associated with exactly one input and no two different inputs have the same image.
Onto / Surjective
A function is "onto" or "surjective" if every element in the co-domain is output for at least one input in the domain.
We call a function Bijective if it is both injective and surjective.
A function is continuous at a point x = c under the following conditions:
- f(c) is defined.
- The limit of f(x) as x approaches c exists.
- The limit of f(x) as x approaches c is equal to f(c).
A function is discontinuous at a point x = c if any of the above conditions are not met.
A function might only have discontinuatities specific internals
Some special cases apply:
- Polynomials are always continuous.
- Rational functions: Continuous when the denominator is not zeo.
- Trig functions: continuous on their domain.
- Exponential and log functions: continuous when defined.