TExcelTAD
Home › Pre-Calculus, Geometry & Trigonometry › Exponential and Logarithmic Functions

Exponential and Logarithmic Functions

An exponential function multiplies by the same factor every step; a logarithm asks how many steps it took. They are inverse functions of each other, and between them they describe compound interest, population growth, radioactive decay, algorithm running times and the number of bits in a number.

Exponential functions

f(x)=ax,a>0, a≠1f(x) = a^x, \qquad a > 0,\ a \ne 1

The variable is in the exponent, which is what separates axa^x from a power function like x2x^2.

Property a>1a > 1 (growth) 0<a<10 < a < 1 (decay)
Domain R\mathbb{R} R\mathbb{R}
Range (0,∞)(0, \infty) (0,∞)(0, \infty)
y-intercept (0,1)(0, 1) (0,1)(0, 1)
Behaviour increasing, →∞\to \infty as x→∞x \to \infty decreasing, →0\to 0 as x→∞x \to \infty
Asymptote y=0y = 0 on the left y=0y = 0 on the right

Every exponential with a>1a > 1 eventually outgrows every polynomial: 2x2^x is smaller than x10x^{10} for a long while, but overtakes it near x≈59x \approx 59 and is never caught again.

The natural base e≈2.71828e \approx 2.71828. It is the value of (1+1/n)n(1 + 1/n)^n as nn grows without bound, the result of compounding interest "continuously". exe^x is the one exponential whose slope at every point equals its value, which makes it the default base in calculus and science (exponential and log functions in calculus). Any exponential can be rewritten with base ee: ax=exln⁡aa^x = e^{x \ln a}.

python · try it yourself
import math

for n in (1, 10, 100, 10_000, 1_000_000):
    print(f"(1 + 1/{n})^{n} = {(1 + 1 / n) ** n:.8f}")
print("e               =", round(math.e, 8))

x = next(x for x in range(2, 200) if 2**x > x**10 and all(2**k > k**10 for k in range(x, 200)))
print("2^x > x^10 from x =", x)
(1 + 1/1)^1 = 2.00000000
(1 + 1/10)^10 = 2.59374246
(1 + 1/100)^100 = 2.70481383
(1 + 1/10000)^10000 = 2.71814593
(1 + 1/1000000)^1000000 = 2.71828047
e               = 2.71828183
2^x > x^10 from x = 59

Growth and decay models

A(t)=A0⋅(1+r)tdiscrete growth at rate r per periodA(t)=A0⋅ektcontinuous growth (k>0) or decay (k<0)A(t)=A0⋅(1/2)t/hdecay with half-life h\begin{aligned} A(t) &= A_0 \cdot (1 + r)^t && \text{discrete growth at rate } r \text{ per period} \\ A(t) &= A_0 \cdot e^{kt} && \text{continuous growth } (k > 0) \text{ or decay } (k < 0) \\ A(t) &= A_0 \cdot (1/2)^{t/h} && \text{decay with half-life } h \end{aligned}

Doubling time and half-life depend only on the rate, not on the starting amount: ekte^{kt} doubles when kt=ln⁡2kt = \ln 2, i.e. after t=ln⁡2/k≈0.693/kt = \ln 2 / k \approx 0.693/k. The "rule of 70" (doubling time≈70/percentage rate\text{doubling time} \approx 70 / \text{percentage rate}) comes from this.

Logarithms: the inverse

axa^x is one-to-one, so it has an inverse, the logarithm base aa:

y=log⁡ax  ⟺  ay=x(x>0)log⁡101000=3,log⁡232=5,ln⁡e2=2(ln⁡=log⁡e)\begin{aligned} &y = \log_a x \quad\iff\quad a^y = x && (x > 0) \\ &\log_{10} 1000 = 3, \quad \log_2 32 = 5, \quad \ln e^2 = 2 && (\ln = \log_e) \end{aligned}

The graph of log⁡ax\log_a x is the graph of axa^x reflected in the line y=xy = x (Composition and Inverse Functions). So domain and range swap: domain (0,∞)(0, \infty), range R\mathbb{R}, x-intercept (1,0)(1, 0), vertical asymptote x=0x = 0. Logarithms grow very slowly: log⁡2\log_2 of a billion is only about 30.

Laws of logarithms (from the exponent laws):

log⁡a(xy)=log⁡ax+log⁡aylog⁡a(x/y)=log⁡ax−log⁡aylog⁡a(xp)=p⋅log⁡axlog⁡ax=ln⁡xln⁡a(change of base)\begin{aligned} \log_a(xy) &= \log_a x + \log_a y \\ \log_a(x/y) &= \log_a x - \log_a y \\ \log_a(x^p) &= p \cdot \log_a x \\ \log_a x &= \frac{\ln x}{\ln a} && \text{(change of base)} \end{aligned}

Solving equations with these laws is covered in Exponential Equations and Logarithmic Equations.

python · try it yourself
import math
import numpy as np
import matplotlib.pyplot as plt

print("log2(32) =", math.log2(32), " log10(1000) =", math.log10(1000), " ln(e^2) =", math.log(math.e**2))
print("change of base log_3(81):", round(math.log(81) / math.log(3), 12), "=", math.log(81, 3))
print("product law:", round(math.log(6 * 7), 12), round(math.log(6) + math.log(7), 12))

x = np.linspace(-3, 3, 300)
xp = np.linspace(0.02, 8, 300)
plt.figure(figsize=(5, 5))
plt.plot(x, 2.0**x, label="2ˣ")
plt.plot(xp, np.log2(xp), label="log₂ x")
plt.plot(x, np.exp(x), label="eˣ", alpha=0.6)
plt.plot(xp, np.log(xp), label="ln x", alpha=0.6)
plt.plot([-3, 8], [-3, 8], "k:", lw=0.8, label="y = x")
plt.xlim(-3, 8); plt.ylim(-3, 8); plt.gca().set_aspect("equal")
plt.legend(); plt.grid(alpha=0.3); plt.title("Exponentials and their inverse logs")
log2(32) = 5.0  log10(1000) = 3.0  ln(e^2) = 2.0
change of base log_3(81): 4.0 = 4.0
product law: 3.737669618283 3.737669618283

In software

  • Logarithms count digits and steps. A number nn needs ⌊log⁡2n⌋+1\lfloor \log_2 n \rfloor + 1 bits; binary search over nn items takes about log⁡2n\log_2 n steps; a balanced tree with nn nodes has height about log⁡2n\log_2 n. That is why O(log⁡n)O(\log n) algorithms feel instant: doubling the input adds one step.
  • Exponential backoff. A client that retries a failed request waits base⋅2k\text{base} \cdot 2^k seconds after the kk-th failure (often capped, with random jitter), so a struggling server is not flooded.
  • Decay. Exponential moving averages, learning-rate decay in ML, and "time decay" in ranking algorithms all multiply by a fixed factor per step.
  • Log scales. Decibels (10log⁡1010 \log_{10} of a power ratio), the Richter scale, and log-scale axes for data spanning many orders of magnitude. In ML, losses are computed with logs of probabilities because multiplying many small probabilities underflows to 0, while adding their logs does not.
python · try it yourself
import math

for n in (1, 255, 256, 1_000_000, 2**40):
    print(f"{n:>14}: bits = {n.bit_length():>2}, floor(log2)+1 = {math.floor(math.log2(n)) + 1:>2}")

def backoff(k, base=0.5, cap=30.0):
    return min(cap, base * 2**k)
print("retry delays (s):", [backoff(k) for k in range(8)])

probs = [0.01] * 400
p = 1.0
for q in probs:
    p *= q
print("product of 400 probabilities:", p, " sum of logs:", round(sum(math.log(q) for q in probs), 4))
             1: bits =  1, floor(log2)+1 =  1
           255: bits =  8, floor(log2)+1 =  8
           256: bits =  9, floor(log2)+1 =  9
       1000000: bits = 20, floor(log2)+1 = 20
 1099511627776: bits = 41, floor(log2)+1 = 41
retry delays (s): [0.5, 1.0, 2.0, 4.0, 8.0, 16.0, 30.0, 30.0]
product of 400 probabilities: 0.0  sum of logs: -1842.0681

Note: For very large integers, math.log2 works on a float approximation and can be off by one near powers of two. int.bit_length() is exact.

Exercises

Exercise 1: Evaluate

Find log⁡264\log_2 64, log⁡5(1/25)\log_5(1/25), log⁡100.001\log_{10} 0.001 and ln⁡(1/e3)\ln(1/e^3) without a calculator.

Answer

6, −2-2, −3-3, −3-3.

Solution
26=64→65−2=1/25→−210−3=0.001→−3e−3=1/e3→−3\begin{aligned} 2^6 &= 64 && \to 6 \\ 5^{-2} &= 1/25 && \to -2 \\ 10^{-3} &= 0.001 && \to -3 \\ e^{-3} &= 1/e^3 && \to -3 \end{aligned}

Exercise 2: Half-life

A cache entry's relevance score halves every 6 hours. Starting at 80, what is it after 1 day, and when does it first drop below 1?

Answer

5 after 24 hours; it drops below 1 after about 37.9 hours.

Solution
S(t)=80⋅(1/2)t/6S(24)=80⋅(1/2)4=580⋅(1/2)t/6<1⇒t/6>log⁡280⇒t>6log⁡280≈37.93 h\begin{aligned} S(t) &= 80 \cdot (1/2)^{t/6} \\ S(24) &= 80 \cdot (1/2)^4 = 5 \\ 80 \cdot (1/2)^{t/6} < 1 \quad&\Rightarrow\quad t/6 > \log_2 80 \quad\Rightarrow\quad t > 6 \log_2 80 \approx 37.93\ \text{h} \end{aligned}
python · try it yourself
import math
print(80 * 0.5 ** (24 / 6), round(6 * math.log2(80), 2))
5.0 37.93

Exercise 3: Combine with log laws

Write 2ln⁡x+ln⁡(x+1)−ln⁡32 \ln x + \ln(x + 1) - \ln 3 as a single logarithm, and expand log⁡2(8x3/y)\log_2(8x^3/y).

Answer

ln⁡(x2(x+1)/3)\ln(x^2(x + 1)/3); 3+3log⁡2x−log⁡2y3 + 3 \log_2 x - \log_2 y.

Solution
2ln⁡x+ln⁡(x+1)−ln⁡3=ln⁡x2+ln⁡(x+1)−ln⁡3=ln⁡(x2(x+1)/3)log⁡2(8x3/y)=log⁡28+log⁡2x3−log⁡2y=3+3log⁡2x−log⁡2y\begin{aligned} 2 \ln x + \ln(x + 1) - \ln 3 &= \ln x^2 + \ln(x + 1) - \ln 3 = \ln(x^2(x + 1)/3) \\ \log_2(8x^3/y) &= \log_2 8 + \log_2 x^3 - \log_2 y = 3 + 3 \log_2 x - \log_2 y \end{aligned}

Exercise 4: Doubling time

Users grow 4% per week. Find the exact doubling time, compare with the rule of 70, and find how many weeks until the count first exceeds 10 times today's.

Answer

ln⁡2/ln⁡1.04≈17.67\ln 2 / \ln 1.04 \approx 17.67 weeks (rule of 70: 17.5). Ten-fold after 59 whole weeks (≈58.7\approx 58.7).

Solution
1.04t=2⇒t=ln⁡2/ln⁡1.04≈17.671.04t=10⇒t=ln⁡10/ln⁡1.04≈58.71, so week 59\begin{aligned} 1.04^t = 2 \quad&\Rightarrow\quad t = \ln 2 / \ln 1.04 \approx 17.67 \\ 1.04^t = 10 \quad&\Rightarrow\quad t = \ln 10 / \ln 1.04 \approx 58.71, \text{ so week } 59 \end{aligned}
python · try it yourself
import math
print(round(math.log(2) / math.log(1.04), 2), 70 / 4, round(math.log(10) / math.log(1.04), 2))
17.67 17.5 58.71

Exercise 5: Levels of a tree

A tournament bracket (a complete binary tree) must hold nn players, with nn rounded up to a power of 2. Write rounds(n) returning the number of rounds, ⌈log⁡2n⌉\lceil \log_2 n \rceil, using integer operations only, and print it for n=2,5,16,17,1000n = 2, 5, 16, 17, 1000.

Answer

1, 3, 4, 5, 10.

Solution

For n≥1n \ge 1, ⌈log⁡2n⌉\lceil \log_2 n \rceil = (n - 1).bit_length().

python · try it yourself
def rounds(n):
    return (n - 1).bit_length()

print([rounds(n) for n in (2, 5, 16, 17, 1000)])
[1, 3, 4, 5, 10]

Test yourself

What is the domain of y=log⁡3(x)y = \log_3(x)?

  1. All real numbers
  2. x≥0x \ge 0
  3. x>0x > 0
  4. x>1x > 1

Which law is correct?

  1. log⁡(x+y)=log⁡x+log⁡y\log(x + y) = \log x + \log y
  2. log⁡(xy)=log⁡x⋅log⁡y\log(xy) = \log x \cdot \log y
  3. log⁡(x3)=3log⁡x\log(x^3) = 3 \log x
  4. log⁡(x/y)=log⁡x/log⁡y\log(x/y) = \log x / \log y

Binary search on 1,000,000 sorted items needs at most about how many comparisons?

  1. 20
  2. 1,000
  3. 500,000
  4. 1,000,000