Fact Sheet on Logarithms Mathias Winther Madsen
[email protected] January 18, 2014 This document contains a bunch facts about logarithms. Some of this you will probably recognize from high school. Some of it you might not. • Every real number b > 1 is associated with a certain exponential function. For instance, for b = 2, we have a function with values like x 2x
··· ···
−3 1/8
−2 1/4
−1 1/2
0 1
1 2
2 4
3 8
4 16
5 32
··· ···
The inverse of this exponential function is the base b logarithm, logb . For instance, log2 (32) = 5, log 1 = 0, and log2 (1/2) = −1.
Figure 1: 2x (black) and its inverse, log2 x (gray). We sometimes write log x instead of log(x), omitting the parentheses when there is no danger of confusion. 1
• I will use the word “log” to mean the base 2 logarithm when it makes a difference which base we are using. Some values of this function are log 3 ≈ 1.58 and log 5 ≈ 2.32. • The exponential function m = 2n is the answer to a lot of computer science problems: The number of binary strings of length n, the number of leaves on a binary tree of height n, etc. n = log2 m is consequently the answer to the inverse of these problems: The length of a tape that can accomodate m different strings, the height of a binary tree with n leaves, etc. • The most important property of logarithms is that they turn products into sums: log(x · y) = log(x) + log(y). Consequently, they also turn exponentiation into multiplication: log(xk ) = k log(x). Note that this also implies that log(1/x) = − log x. • Logarithms are strictly increasing (recall that we are assuming that b > 1). This means that log x is negative for 0 < x < 1 and positive for 1 < x.
Figure 2: Logarithms are strictly concave. • Logarithms are strictly concave. This means that if you pick two real numbers x1 , x2 > 0 and draw a line between (x1 , log x1 ) and (x2 , log x2 ), the line segment will lie strictly below the graph of the logarithm. 2
• Logarithms are undefined for x ≤ 0, and log x → −∞ for x → 0. • However, 1/x → ∞ at a faster rate than log x → −∞. Consequently, x log x → 0 for x → 0.
Figure 3: 1/x diverges faster than log(1/x) when x → 0. • The logarithm with base b is the only function which – is continunous; – turns products into sums; – satisfies the property f (b) = 1. Logarithms are thus unique in this particular sense. • Differentiating an exponential function only rescales it by a constant: (bx )0 = cbx . The unique base for which there is no rescaling (c = 1) is called e. It is approximately equal to 2.72, and its associated exponential function can be expressed as ex = exp(x) = 1 + x +
x3 x4 x5 xk x2 + + + + ··· + + ··· 2 6 24 120 k!
3
The logarithm which is the inverse of ex is called the natural logarithm, ln(x) = loge (x). It can be computed by means of its Taylor polynomial, ln(x) = (x − 1) −
(x − 1)3 (x − 1)k (x − 1)2 + − · · · + (−1)k+1 + ··· 2 3 k
e can also be approximated by means of the limit n 1 1+ −→ e for n → ∞ n • ln(x) ≤ (x − 1) for all x, and ln(x) < (x − 1) for all x 6= 1. Moreover, ln(x) ≈ (x − 1) is a very good approximation of ln x around x = 1. This fact is also sometimes stated by saying that log(1 + t) ≈ t for t ≈ 0.
Figure 4: ln x is approximated very well by its Taylor polynomial x − 1. • Logarithms with different bases differ only by a constant factor: logc x =
logb x . logb c
In particular, we thus have the conversion formulas log2 x =
ln x ≈ 1.44 ln x, ln 2
and
log2 x =
log10 x ≈ 3.32 log10 x. log10 2
One way to remember the general rule is to think of the 10’s as “cancelling out” in an expression like log2 (10) log10 (x) = log2 (x). 4
Figure 5: The logarithms log2 x (black), ln x (gray), and log10 x (light gray) differ only by a constant factor. • As a consequence of the chain rule of calculus, the derivative of ln x is 1 0 ln (x) = . x This also entails that the anti-derivative of ln x is ˆ ln x = x ln x − x. For logarithms with other bases, these formulas differ by a constant factor of the form 1/ ln b. • The natural logarithm of a factorial, ln(n!) = ln(1 · 2 · 3 · 4 · · · n), can be estimated by means of Stirling’s approximation: ln(n!) ≈ (n ln n − n) +
1 ln(2πn), 2
or by its simplified version, n ln n − n. Both of these are very good approximations: For n = 100, the correct value is about ln(100!) ≈ 363.74, and two approximations give 366.96 and 360.52.
5
Figure 6: The first 60 values of ln(n!) (shown as black crosses), and Stirling’s approximation to these numbers (shown as gray circles).
6