Derivative of logarithm and exponential

From Applied Science

[math]\displaystyle{ f(x) = \ln(x) \iff f'(x) = \frac{1}{x} }[/math]

I'm going to explain a property that is pretty simple and yet often overlooked. Let's write down a short sequence of logarithms in base 2:

[math]\displaystyle{ \log_2{1} = 0 }[/math]
[math]\displaystyle{ \log_2{2} = 1 }[/math]
[math]\displaystyle{ \log_2{4} = 2 }[/math]
[math]\displaystyle{ \log_2{8} = 3 }[/math]
[math]\displaystyle{ \log_2{16} = 4 }[/math]

Now the derivative can be defined in terms of a tangent, a ratio rise / run. We define rise as [math]\displaystyle{ \log(x_2) - \log(x_1) }[/math]. While run is [math]\displaystyle{ x_2 - x_1 }[/math]. Notice that we are increasing rise in steps of one unit. While the input is increasing following a powers of 2 rule. If we write the sequence following the formula [math]\displaystyle{ \frac{\log(x_2) - \log(x_1)}{x_2 - x_1} }[/math] we get:

[math]\displaystyle{ \frac{1}{2^0} }[/math], [math]\displaystyle{ \frac{1}{2^1} }[/math], [math]\displaystyle{ \frac{1}{2^2} }[/math], [math]\displaystyle{ \frac{1}{2^3} }[/math], [math]\displaystyle{ \frac{1}{2^4} }[/math]

Notice that the sequence is decrescent, which means that the derivative of a logarithmic function is a decrescent function. Each term of the sequence is the inverse of the corresponding power of 2. The base doesn't matter, all bases should display the same behaviour. I didn't do calculations with decimal numbers but if we consider mean values in between each step the same behaviour should be expected. It shouldn't come as a surprise because the rate of change of a logarithmic function does decrease over time, approaching zero at infinity.

This intuitive reasoning should explain why deriving the log yields a function that takes the inverse of a number at each point.


[math]\displaystyle{ f(x) = e^x \iff f'(x) = e^x }[/math]

Let's see what happens if we apply [math]\displaystyle{ \frac{2^{x_2} - 2^{x_1}}{x_2 - x_1} }[/math] from 0 to 5:

1, 2, 4, 8, 16

It forms a sequence where each term is a power of 2. Unlike the derivative of a log that yields a decrescent function, deriving an exponential function yields a crescent function which is also an exponential function. It's natural because the rate of change is crescent and does follow a power of 2 rule in this case.

Now if we apply brute force and calculate the derivatives of [math]\displaystyle{ 2^x }[/math], [math]\displaystyle{ (2.1)^x }[/math], ..., [math]\displaystyle{ (2.9)^x }[/math], [math]\displaystyle{ 3^x }[/math] in Wolfram alpha. We are going to notice that the derivatives are of the form [math]\displaystyle{ \log_e{a} \cdot a^x }[/math], with [math]\displaystyle{ \log_e{a} }[/math] being a number close to 1. When does it happen to be exactly 1? When we have [math]\displaystyle{ \log_e{e} = 1 }[/math]. With this reasoning we conclude that there is a certain base for which the derivative of an exponential function happens to be equal to itself.

If we apply the same brute force reasoning in Wolfram for the derivatives of [math]\displaystyle{ \log_2{x}, \log_{2.1}{x} ..., \log_{2.9}{x}, \log_3{x} }[/math] we see that they are all of the form [math]\displaystyle{ 1/(x\log_e{a}) }[/math]. With this reasoning we get that when the base is [math]\displaystyle{ e }[/math], the derivative of the natural logarithm is the inverse of [math]\displaystyle{ x }[/math].

Note: the reasoning above to find the derivatives of exponential and logarithm isn't a formal one. I followed a reasoning similar to what we do with the Bisection method to find roots of equations in numerical methods.

Arbitrary bases for log and exp

When we have [math]\displaystyle{ f(x) = a^x }[/math] with [math]\displaystyle{ a \gt 1 }[/math], differentiating it yields [math]\displaystyle{ f'(x) = a^x \ln(a) }[/math]. All we have to do is to remember that a number can be expressed in the form of a log in any base, in particular the [math]\displaystyle{ e }[/math] base:

[math]\displaystyle{ a = e^{\ln(a)} \iff \log_e(a) = \log_e(a) }[/math]

Multiply both sides by [math]\displaystyle{ 1^x }[/math]:

[math]\displaystyle{ a^x = e^{x\ln(a)} }[/math]

Now the function is [math]\displaystyle{ f(x) = e^{x\ln(a)} }[/math], therefore:

[math]\displaystyle{ f'(x) = e^{x\ln(a)} }[/math] (in case you are confused, [math]\displaystyle{ \ln(a) }[/math] is a constant because the variable is [math]\displaystyle{ x }[/math])

[math]\displaystyle{ f'(x) = \ln(a) e^{x\ln(a)} }[/math] (apply the chain rule to derive [math]\displaystyle{ e^{g(x)} }[/math])

[math]\displaystyle{ f'(x) = \ln(a) \cdot a^x }[/math]


Now for the case of [math]\displaystyle{ f(x) = \log_a(x) }[/math] we rely on the change of base:

[math]\displaystyle{ \log_a(x) = \frac{\ln(x)}{\ln(a)} }[/math]

As seen before [math]\displaystyle{ \ln(a) }[/math] is a constant:

[math]\displaystyle{ \frac{\ln(x)}{\ln(a)} = \ln(x)\frac{1}{\ln(a)} }[/math]

With this the derivative should be immediate:

[math]\displaystyle{ f'(x) = \frac{1}{x} \cdot \frac{1}{\ln(a)} }[/math]


Can a log have functions on both the base and the variable? Yes, it's the case of [math]\displaystyle{ f(x)^{g(x)} }[/math]. To differentiate this we have to rely on the [math]\displaystyle{ \ln(x) }[/math] once again for the same reasons as before:

[math]\displaystyle{ f(x)^{g(x)} = h(x) }[/math]

[math]\displaystyle{ \ln{\left(f(x)^{g(x)}\right)} = \ln{(h(x))} }[/math]

[math]\displaystyle{ g(x) \ln(f(x)) = \ln(h(x)) }[/math] (in case you got lost, recall how we read a log and write exp from it and from exp write the log)

[math]\displaystyle{ e^{g(x) \ln(f(x))} = h(x) }[/math]

Now to compute [math]\displaystyle{ h'(x) }[/math] we proceed as we'd do with [math]\displaystyle{ e^{a(x)} }[/math] and apply the chain rule:

[math]\displaystyle{ h'(x) = [g(x) \ln(f(x))]' \cdot e^{g(x) \ln(f(x))} }[/math] (notice there is also a product rule because of the product of functions)

Note: we have a single variable case here. Don't confuse it with a two variable function as in [math]\displaystyle{ f(x,y) = x^y }[/math]. I used [math]\displaystyle{ h(x) }[/math] just to avoid using [math]\displaystyle{ y }[/math] and maybe creating a confusion between single and two variable functions.