What is a function

Kapitoly: What is a function, Functions of multiple parameters, Folding functions, Graph a function

A function is an absolutely fundamental concept in mathematics that you should fully understand. Mathematics is riddled with functions, and any symbol you know from primary school is actually a function.

The analogy of a function

Have you ever seen a coffee machine? What is typical of such a machine? You insert coins, and it dispenses coffee. If you add more coins, the machine responds by providing better coffee.

The function is akin to a mathematical coffee machine. You insert input (coins) into the function, and it returns an output (coffee). That's the basic principle of a function.

The job of the function is to take some input, a number, process it internally, modify it, and then return the new number as the output.

Basic concepts

Every function has a name that identifies it. The most common name for a function is the letter "f". For a function to operate, we need a rule that specifies how it should work - similar to how a machine processes the input to produce coffee. Initially, we can visualize a function as a table with two columns. The first column will contain our input (in the example of the machine, this would be the value of the coins) and the second will contain the output of the function (the coffee).

$$\begin{array}{|c|c|} \hline \mbox{ Access }&\mbox{ Exit }\\ \hline 1&2\\ 2&4\\ 3&6\\ 4&8\\ 5&10\\ \hline \end{array}$$

We can see that the output is always twice as large as the input, but that doesn't necessarily have to be the rule. We can also have a table like this:

$$\begin{array}{|c|c|} \hline \mbox{ Access }&\mbox{ Exit }\\ \hline 0&22\\ 122&74\\ -3&1\\ 42&-45\\ 8&84\\ \hline \end{array}$$

However, the first, regular table will suffice for a start. We can say that this table defines the function f. What does the function do? We input some data into the function, and it looks up that data in the first column of the table, then returns the corresponding output from the same row. If we were looking for the output of the function for the number three, we would write it like this:

$$ f(3) = 6 $$

We found a row where the input was equal to three, and on the same row the output was equal to six. Further, f(1) = 2, f(2) = 4, f(4) = 8 and f(5) = 10 would apply. Writing all the functions using tables may seem straightforward for a few numbers, but it becomes extremely impractical when working with multiple numbers. Therefore, we need a different form of notation. We can specify it with a function rule. In our table, the output is twice the input. We could write this using a functional prescription as follows:

$$ f(x) = 2 \cdot x $$

This is a simple linear function, but that doesn't matter for now. What does this expression tell us? The letter f denotes the name of the function, we already know that. The expression in parentheses, the letter x, denotes the function parameter. In the slot machine analogy, it would represent the notion of "the value of a coin toss". A function parameter is a variable into which the value we pass is stored. If we were to throw twenty crowns into the automaton (function), the function would indicate x = 20. The automaton or function would then process that value accordingly.

Next is the equation, and following the equation is the rule itself, which instructs us on how to handle the value x. We can see that the function will multiply the given value of x by two. That's it.

More examples of functions

This right-hand side can be virtually any mathematical expression. It can include other functions or conditions that refine the definition. For example, we could define a function verbally as follows: "If the input is an even number, return zero; if the input is an odd number, return one." This would be a function that only returns one and zero.

The important thing to understand is that a function can be defined in almost any way. Of course, even a function has rules, but those aren't so important right now—plus, one of the rules is mentioned in the very next chapter. The definition of a function doesn't have to make sense at first glance, nor does it need to follow any order. A function may always return a double value, except when the input is seven. Then it will return a nine. This might seem nonsensical, but it is still a function.

We can consider many of the operations we perform outside of mathematics as functions. For example, if you calculate the length of the word "mammoth", it can be said that you invoked a function named "word length" and passed it the word "mammoth" as an argument. The function counted the letters in the word and returned the number five as output.

Do you need to calculate the compound interest you will pay on a loan or mortgage? A function can do that too. Simply define the function to calculate the amount of interest after, say, ten years. Do you need to find out how many more kilometres a car will travel given a certain amount of petrol? Define a function! If a car travels, on average, 11 kilometres per litre of petrol, then we can define a function that calculates how many more kilometres it will travel as follows:

$$ ujedeme(x) = 11 \cdot x $$

If we only have 17 liters of petrol left, we calculate the distance by calling the function as follows:

$$ ujedeme(17) = 11 \cdot 17 = 187 $$

In short, a function is anything that takes an input and returns a number. For example, it could calculate the air distance from Opava to a certain city, determine the length of the longest song on a given album, count the number of hairs on a person's head, or establish the number of legs on a specified animal, etc.

Basic feature of the function

An extremely important condition for the function, as we return to the table, is that no value in the first column corresponding to the input is repeated. If the table looked like this:

$$\begin{array}{|c|c|} \hline \mbox{ Access }&\mbox{ Exit }\\ \hline 1&2\\ 1&4\\ 1&6\\ 4&8\\ 5&10\\ \hline \end{array}$$

we would not be able to determine what the function should return if we input one:

$$ f(1) = ? $$

The function must be clearly defined; it cannot return two different results for the same input—that's simply not possible. We require a function to always yield the same output for the same input. Note that this requirement does not apply to the second column, the output. The outputs may well be identical; we don't mind. This table would be valid:

$$\begin{array}{|c|c|} \hline \mbox{ Access }&\mbox{ Exit }\\ \hline 1&2\\ 2&2\\ 3&2\\ 4&2\\ 5&10\\ \hline \end{array}$$

Evaluate function

We already know what each part of the function is called and how to define the function approximately. Now we'll explain step by step how function evaluation is conducted. Consider the function f(x) = 2x. What happens if we substitute a 3 into the function? To substitute a three, it means we have to replace the function's parameter with three. Since the parameter is x, we substitute three for every x:

$$ f(3) = 2 \cdot 3 $$

We can already see that the function outputs a six, just as the table did a moment ago. However, that was limited to only five numbers; our new definition can accommodate other numbers as well:

$$\begin{eqnarray} f(10)&=& 2\cdot10=20\\ f(54)&=& 2\cdot54=108\\ f(-7)&=& -14 \end{eqnarray}$$

We refer to the process of substituting specific values for the x variable as function evaluation, function call, or function application. Thus, when we say "call the function f with argument 5", we mean to compute the value of f(5), which in this instance is f(5) = 2 · 5 = 10.

Two more concepts to remember: what we call the function with (what we put after x) is called the function argument. It may seem a little confusing, but if we have a function f(x) and we call it with a value of three f(3), then x is the function parameter and 3 is the function argument. The argument is the actual value used to call the function, while the parameter is the original variable with which the function is defined. It's more of a technicality.

The other term is function value, which is the value that the function returns in the output. The previous function returned the number six when called with the number three. Therefore, the number six is the function value in this case. In a complete sentence, we would say "the function f has a function value of six at point three". The term "point" in this context usually refers to a function argument.

Functions in ordinary mathematics

There are many functions in ordinary mathematics that are written in such a unique way that they do not even resemble functions. For example, the previously mentioned absolute value is simply a function. It takes a number as input and returns either the same number or its negative counterpart as output.

I'm sure you recognize the symbol for the square root: $\sqrt{}$. This too is a function. It takes an argument as input and returns the square root as output. Similarly, the square power x2 is a function. It takes a number as input and returns the square of that number as output.

It's quite important to note that most such magic symbols are really nothing more complicated than some ordinary functions. Don't look at the $\sqrt{}$ symbol as a strange curved patch, but rather as a function.

Because, especially for a beginner, it can be confusing to encounter an expression filled with numerous mathematical symbols that the beginner barely understands, which may in reality represent just a couple of compound functions. Consider this example:

$$ \sqrt{|x^2|}! $$

A math layman looking at this will scratch his head and not have much idea what to do with it. Yet there are four fairly simple functions in that expression, which are successively applied to the variable x. You could break it down using named and nested functions like this:

$$ \mbox{ Factorial }(\mbox{ square root }(\mbox{abs}(\mbox{na2}(x)))) $$

The notation is longer, but likely clearer for someone not familiar with symbols. At the same time, the sequence in which the functions are called is also very clear.

A summary of the function notation

A function has a name, which can be almost anything. The most common name for a generic function is f. Each function has a given number of parameters, which we write in parentheses after the name. If our function f had two parameters, we would write it like this: f(x, y) or f(a, b). The naming of the parameters generally doesn't matter.

Some frequently used functions have their own symbols. For example, the square root is denoted by $\sqrt{}$. Similarly, sin or sin(x) represents the sine function, |x| denotes the absolute value function, and x! indicates the factorial function.

If a function has one parameter, we sometimes omit the parentheses, which can make the notation clearer or more confusing. Thus, sin(x) and sin x are valid notations for the sine function.

When we talk about the parameter of a function, we refer to the x in the notation f(x). The argument is the value with which we call the function, which we insert for x. Often, these two concepts merge. The function value is the result we obtain when we call the function. We denote it as the function name, followed by parentheses containing the argument. If we have a function f(x) = 2x and we substitute the argument x = 4 for the parameter x, then we say that we called the function with the argument x = 4 and the resulting function value f(4) equals eight.