Order of evaluation

When we work with a function defined by some formula, an important role is played by the order in which the formula is evaluated when a number is substituted in. A typical function is formed by combining elementary functions using the four basic operations (addition/subtraction, multiplication and division) and composition. No matter how a complicated such a function gets, we can always capture its structure using a tree. Before we get there, we look at some examples.

Example: Consider the function f (x) = 1/sin(x2 + x − 1). How do we evaluate such a function? A good guide is to imagine that we have a concrete number, put it in for x and try to calculate the value of this expression on a calculator. In which order do we perform the operations?

Since polynomials are considered elementary functions, we can think of evaluating the expression x2 + x − 1 as one step, the first one. Then we press the button for sine, that's the second step, and finally we press the button usually marked "1/x", which concludes the evaluation.

Translated into mathematics, we see that we start by applying the function x2 + x − 1 to the given number, then we apply to the result (which we may call y) the function sin(y), that is, we are using the operation of composition. If we call the resulting expression z, we get the answer by performing 1/z, that is, we are composing the expression sin(x2 + x − 1) with the outer function, the power z−1. We can express it like this:

However, in most applications we want to see it from the other end, in the order "last to first". The best way to draw it is to put x down as a root and let the function grow up from it.

We used variables y and z to emphasize the composition procedure, but in more complicated functions this is not feasible. We will therefore keep using the variable x in individual functions, for instance in this example we would say that we applied sin(x) to the argument (x2 + x − 1).

This seems trivial, we just turned the picture. What is the point of all this? The next example will show some.

Example: Consider the function

Now we start evaluating. Take some concrete x, put it into your calculator and apply x3 to it. Then you apply the tangent to get tan( x3), but suddenly you are in trouble, because in the next step you are supposed to divide this by some number you cannot just put into your calculator, you need to figure it out first. This shows that the expression has (at least) two "roots" that have to be worked out separately and then put together. This suggests that decomposing functions "from the inside", from the first operation performed, is not the best strategy in general, in particular this is true for differentiation.

It is better to start from the "outside", with the operation that is done last when evaluating the expression, which is the logarithm, and then look at what is done before that, the division, which naturally shows two branches going down.

If this all seems simple to you, that's great, it means you should not have any trouble in calculations where the order comes into consideration. Just to be sure, try to decompose and draw a tree for this function (do it on your own, don't peek below):

If you got the same tree as we did, you will be fine.