If you have any programming experience, you know exactly what a "function" is. But the fact is that the mathematical meaning of this term is quite different from its use in coding; and in this topic you will learn what mathematicians call a function and what a map has to do with it.
What is a function?
A function is a mathematical object, or a "machine", that takes the value as an input and produces a unique value as an output. It's crucial that there exists only one value for for every input value of . This relationship is commonly denoted as . It reads " is equal to of ", where is an input or an argument, and is an output or a value. Sometimes or is called a dependent variable because it depends on the value , and is called an independent variable.
Notice that does not mean " multiplied by ". It means that " is a function of ". You take an input , produce an output according to the rule typically, but not necessarily by performing some calculation, and get an output .
For example:
The most common name for the function is ", but you can give it other names like , , , , etc. Notice that is there to show us where the input goes and what happens to it. Thus, is the same function as , or , or .
Occasionally, a function has no name:
But there is still an input , a relationship (the cube) and an output .
A formal definition
Suppose you have a set of inputs (domain) and a set of possible outputs (codomain). A function is a set of ordered pairs , where , , every element of belongs to some pair, and there can be only one pair with the same value of .
You can say that is a function from to as .
Sometimes instead of the term "function" we call the map or mapping.
The element belonging to the pair is denoted (pronounced " of ") and called the output of for the input , or the value of at , or the image of under .
The set of all values of taken together is called the range of or the image of under . Symbolically,
Thus, the first item in each pair is an element of , the second item is an element of , every element in the domain appears as the first item of one and only one of the pairs and no two pairs have the same first element. It is said that a function is single valued. Note that this topic considers only functions with a single argument.
Examples
We are given a set . To each element in , we assign one and only one element from .
Notice that the domain and the range can contain the same thing (in our example, the number 1) or different things ( and "python").
In this example, the domain is the set of integers 1 to 6, and the range might be the union of the set of integers, the set of letters, or the set of programming languages: and .
In this case, 1 is mapped into , 2 is mapped into , 3 is mapped into 8, 4 is mapped into , 5 is mapped into , 6 is mapped into 1. Thus, the set of ordered pairs is set .
Note that the following relationship is not a function:
"4" and "5" in have no relations in , and "3" is related to more than one value in ("h" in has no relationship, but it does not matter).
Conclusion
The concept of a function is widely used in math, computer science, physics, and other fields. Informally, it is a rule we can use to obtain an output from an input. A more formal definition includes pairs of elements, the first of which belongs to the set of possible inputs (known as domain) and the second belongs to the set of possible outputs (a codomain). As you can see, this concept is quite similar to what programmers use, but in strict form it describes a more general idea.