3.3. Functions

In math the word function is exemplified generically as

Example 3.1. A Generic Function, Math, not JavaScript
y = f(x)

We say y is a function of x. Sometimes the following, slightly less generic, version might be expressed as the linear function

Example 3.2. A Generic Linear Function, Math, not JavaScript
y = ax + b

where a and b are constants, and x is the variable expression.

A more concrete example might be, again a linear function:

Example 3.3. A Specific Linear Function, Math, not JavaScript
y = 2x - 5

If we choose and insert a value for x, do the calculation on the right hand side on the equals sign, = we get a value that is then assigned to y. This is useful because it describes how to calculate the value of y for any chosen x.

This is useful if we want to draw the line described by the function, let us say

Example 3.4. A Coordinate Set of the Linear Function
x = 0
y = 2 * x - 5

Giving us a coordinate set of (-5, 0) ie the chosen x, and the calculated y. Choose another x

Example 3.5. Another Coordinate Set of the Linear Function
x = 4
y = 2 * x - 5

Giving us another coordinate set (3, 4), allowing us to draw the line in a coordinate system.

In mathematics we use functions to specify calculations. A function is the right hand side of a mathematical expression such as in the above examples. As such it is always a one liner. Now we shall turn to computing where a function is used to execute a specified activity. Not necessarily a one liner. Sometimes it is a calculation, but at other times it might be a series of statements necessary to achieve a required purpose.