mathprecalc

exponents + logs

growth that multiplies, and the log that asks how many times.

report a mistake
.md

an exponent counts how many times a number multiplies itself. a log reads that count back from the result.

product
aᵐ · aⁿ = aᵐ⁺ⁿ m factors, then n more
power of a power
(aᵐ)ⁿ = aᵐⁿ m factors, n times over
zero and negative
a⁰ = 1, a⁻ⁿ = 1/aⁿ what keeps the product rule true
roots
a^(1/n) = ⁿ√a n of them multiply to a
log
log₂ 1024 = 10 the exponent, read back
products to sums
log xy = log x + log y the product rule, read backwards
a sum
log(a + b) has no rule. neither does (a + b)ⁿ
reach for it
  • doubling, half-lives, a percent a year
  • reading O(log n) and O(2ⁿ)
  • solving for an exponent
on this page
  1. the idea
  2. explore
  3. try it
  4. the rules
  5. worked examples
  6. the key idea up close
  7. pitfalls
  8. practice
  9. sources

the idea

an exponent counts multiplications. 2102^{10} is ten factors of 2 multiplied together, and it comes to 1,024. that kind of growth is everywhere: a population that doubles, money that earns a percent of itself, a search that halves what’s left. a log asks the question backwards. 1,024 is how many factors of 2? ten. log⁡21024=10\log_2 1024 = 10.

start at 1 and double ten times: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1,024. the first five doublings reach 32. the next five reach 1,024.

an animation: 1 doubled ten times, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1,024, plotted as dots that hug the axis and then shoot up, with the curve y = 2ˣ drawn through them. then the log reads 1,024 back: across to the curve and down to 10 doublings, log₂ 1024 = 10. then a square view where y = 2ˣ folds over the dashed line y = x onto y = log₂ x, and the points (3, 8) and (8, 3) read one fact both ways: 2³ = 8 and log₂ 8 = 3.

explore

change the base. with b>1b > 1, y=bxy = b^x climbs faster and faster, and y=log⁡bxy = \log_b x climbs slower and slower, and the two stay mirror images across y=xy = x. drag the point along bxb^x: its mirror on log⁡bx\log_b x has the same two numbers the other way round. the base can’t be 1, since 1x1^x is 1 for every xx and there would be no exponent to read back.

−202468−202468(2.83, 1.5)(1.5, 2.83)

drag the point along the curve, or tab to it and use the arrow keys

y = 2ˣ
2^1.5 = 2.83
y = log₂ x
log₂ 2.83 = 1.5
y = x
the mirror line

an interactive chart with equal axes from −2 to 8: y = bˣ in cyan, y = log_b x in amber and y = x dashed between them. a slider sets the base b from 1.2 to 4, starting at 2. a point drags along bˣ, starting at x = 1.5, where 2^1.5 = 2.83, and its mirror on the log curve reads log₂ 2.83 = 1.5. the arrow keys move it too.

try it

log₂ 1,024 = ?

pick one.

0 / 0 right

a practice exercise with six kinds of question: a power like 2⁵, an exponent rule applied to numbers, a log read back like log₂ 64, which two whole numbers a log sits between, a log rule, and growth that multiplies: doublings, half-lives and a percent a year.

the rules

exponents

every rule comes from counting factors. ana^n is nn copies of aa multiplied together.

am⋅an=am+na^m \cdot a^n = a^{m+n}

mm factors of aa, then nn more: m+nm + n factors in all.

aman=am−n\frac{a^m}{a^n} = a^{m-n}

nn of the mm factors on top cancel against the nn below.

(am)n=amn(a^m)^n = a^{mn}

a group of mm factors, written out nn times.

(ab)n=anbn(ab)^n = a^n b^n

nn copies of abab, with the aa‘s and the bb‘s sorted into two groups.

a0=1a−n=1ana^0 = 1 \qquad a^{-n} = \frac{1}{a^n}

not a count of factors any more, but the only values that keep the product rule true. an⋅a0a^n \cdot a^0 has to equal ana^n and so a0=1a^0 = 1. and an⋅a−na^n \cdot a^{-n} has to equal a0=1a^0 = 1 too, which makes a−na^{-n} the reciprocal 1/an1 / a^n.

a1/n=anam/n=(an)ma^{1/n} = \sqrt[n]{a} \qquad a^{m/n} = \left(\sqrt[n]{a}\right)^m

the power of a power again: (a1/n)n=a1(a^{1/n})^n = a^1, so a1/na^{1/n} is the number whose nnth power is aa. 82/3=(83)2=48^{2/3} = (\sqrt[3]{8})^2 = 4.

growth that multiplies

y=a⋅bxy = a \cdot b^x

aa is the amount at the start and bb the factor each step. b=2b = 2 doubles. b=1/2b = 1/2 halves, and the time one halving takes is the half-life. a rise of rr percent a step is b=1+r/100b = 1 + r/100: 3% a year is b=1.03b = 1.03, and 24 years of it is 1.0324≈2.031.03^{24} \approx 2.03, a little more than double.

e

split a year’s 100% interest into nn payments of 100/n100/n percent each, and one unit of money grows to (1+1/n)n(1 + 1/n)^n by the end of the year. paid once, that’s 2. twice, 2.25. monthly, 2.6130. daily, 2.7146. the number it closes in on is e≈2.718e \approx 2.718, and growth that compounds at every instant is exe^x. it’s the natural base for growth, and the derivatives page says why.

00.20.40.60.8100.511.522.53e = 2.71832.6130years
paid every month
(1 + 1/12)¹² = 2.6130
eˣ
e = 2.7183
short of e by
0.1052

a chart of one unit of money over a year at 100% interest, paid n times: a cyan staircase under the dashed curve eˣ. a slider picks n from 1, 2, 4, 12, 52 and 365 payments a year, starting at 12. the staircase ends at 2, 2.25, 2.4414, 2.6130, 2.6926 and 2.7146, closing in on e = 2.7183.

logs

log⁡bx=y  ⟺  by=x\log_b x = y \iff b^y = x

the log is the exponent. log⁡21024=10\log_2 1024 = 10 because 210=10242^{10} = 1024. log⁡101000=3\log_{10} 1000 = 3. ln⁡e=1\ln e = 1, where ln⁡\ln is log⁡e\log_e. in every base, log⁡b1=0\log_b 1 = 0, since b0=1b^0 = 1, and log⁡bb=1\log_b b = 1.

log⁡b(xy)=log⁡bx+log⁡by\log_b (xy) = \log_b x + \log_b y

write x=bmx = b^m and y=bny = b^n. then xy=bm+nxy = b^{m+n} by the product rule, and the log reads that exponent back: m+nm + n.

log⁡bxy=log⁡bx−log⁡by\log_b \frac{x}{y} = \log_b x - \log_b y

the quotient rule, read the same way: x/y=bm−nx / y = b^{m-n}.

log⁡b(xn)=nlog⁡bx\log_b (x^n) = n \log_b x

xn=(bm)n=bmnx^n = (b^m)^n = b^{mn}: the power of a power.

log⁡bx=log⁡cxlog⁡cb\log_b x = \frac{\log_c x}{\log_c b}

change of base. any log is any other log divided by a constant, so a calculator with only ln⁡\ln or log⁡10\log_{10} does every base: log⁡210=ln⁡10/ln⁡2≈3.32\log_2 10 = \ln 10 / \ln 2 \approx 3.32.

worked examples

how many doublings

a culture of 100 cells doubles every hour. after tt hours it’s 100⋅2t100 \cdot 2^t: 819,200 cells after 13 hours and 1,638,400 after 14. when does it pass a million?

100⋅2t=1,000,000⇒2t=10,000⇒t=log⁡210000≈13.29100 \cdot 2^t = 1{,}000{,}000 \quad\Rightarrow\quad 2^t = 10{,}000 \quad\Rightarrow\quad t = \log_2 10000 \approx 13.29

divide both sides by the start, then read the exponent off with a log.

a half-life

a sample of 80 g has a half-life of 3 days. after tt days there’s 80⋅(1/2)t/380 \cdot (1/2)^{t/3} left: 9 days is three half-lives, 80/8=1080 / 8 = 10 g, and 10 days is 80⋅(1/2)10/3≈7.9480 \cdot (1/2)^{10/3} \approx 7.94 g. when is 5 g left? 80/16=580 / 16 = 5, so after four half-lives: 12 days.

a percent a year

3% a year is a factor of 1.03 a year. how long until it doubles?

1.03t=2⇒t=log⁡1.032=ln⁡2ln⁡1.03≈23.4 years1.03^t = 2 \quad\Rightarrow\quad t = \log_{1.03} 2 = \frac{\ln 2}{\ln 1.03} \approx 23.4 \text{ years}

the rule of 70 gets close without a calculator: 70/3≈23.370 / 3 \approx 23.3. it works because ln⁡2≈0.69\ln 2 \approx 0.69 and ln⁡(1+r)≈r\ln(1 + r) \approx r for a small rr. at 7% a year it says 10 years, against 10.2 from the log.

solving for the exponent

2x=102^x = 10. the answer sits between 3 and 4, since 23=82^3 = 8 and 24=162^4 = 16. the log gives it exactly:

x=log⁡210=ln⁡10ln⁡2≈3.32x = \log_2 10 = \frac{\ln 10}{\ln 2} \approx 3.32

check: 23.32≈9.992^{3.32} \approx 9.99.

why log n is small

log⁡21,000,000≈19.93\log_2 1{,}000{,}000 \approx 19.93. so a sorted list of a million items takes about 20 halvings to get down to one item, and that’s what binary search does: 20 looks, where a scan can take a million. a thousand items take 10 halvings and a billion take 30. every ×1,000\times 1{,}000 in nn adds about 10, because log⁡21000≈9.97\log_2 1000 \approx 9.97. it’s why O(log n) sits next to O(1) in big o.

0250k500k750k1M051015209.97 at a thousand19.93 at a millionnlog₂ n

a chart of log₂ n against n from 0 to 1,000,000 on plain axes: the curve shoots up at the left and then barely climbs, 9.97 at a thousand and 19.93 at a million.

change of base in javascript

Math.log is ln⁡\ln. dividing two of them does any base, but the division goes through floating point, and the answer can land a hair off a whole number. Math.log10 and Math.log2 give the whole number.1

Math.log(1000) / Math.log(10); // 2.9999999999999996
Math.log10(1000); // 3
Math.log2(1024); // 10
Math.log(Math.E); // 1
Math.log(0); // -Infinity
Math.log(-1); // NaN
64 ** (1 / 3); // 3.9999999999999996
Math.cbrt(64); // 4

python’s math.log(x, base) is the same division, and its docs point to log10 and log2 as the more accurate ones for those bases.2

the key idea up close

a log scale

put each number xx at distance log⁡x\log x from the start of a line. then 1, 10, 100, 1,000 are evenly spaced, and so are 1, 2, 4, 8. the distance from aa to abab is

log⁡(ab)−log⁡a=log⁡b\log(ab) - \log a = \log b

the same length wherever aa is. multiplying by bb is a step of a fixed size, so on a log scale, every step multiplies. that’s the whole trick of a slide rule: lay log⁡a\log a and log⁡b\log b end to end, and the mark under the end reads abab.

the same three numbers on a plain axis

0250k500k750k1M

and on a log scale, where every step to the right is ×10

1101001k10k100k1Mlog a+ log blog b100,000

drag a or b along the log scale, or tab to one and use the arrow keys

a = 100
log₁₀ a = 2.00
b = 1,000
log₁₀ b = 3.00
a · b = 100,000
2.00 + 3.00 = 5.00

two number lines. the top one is plain, 0 to 1,000,000, where a = 100, b = 1,000 and a · b = 100,000 all sit in the left tenth. the bottom one is a log scale, 1 to 1,000,000 with a tick at every power of ten, where a sits at 2, b at 3, and b's length laid after a's lands on a · b at 2 + 3 = 5. drag a or b along the log scale, snapping to the marks 1 to 9 of each decade, or move them with the arrow keys.

the log rules are the exponent rules read backwards

a log is an exponent, so every log rule is an exponent rule with the roles swapped. write x=bmx = b^m and y=bny = b^n, so that m=log⁡bxm = \log_b x and n=log⁡byn = \log_b y:

xy=bmbn=bm+n⇒log⁡b(xy)=m+nxy=bm−n⇒log⁡bxy=m−nxk=(bm)k=bmk⇒log⁡b(xk)=km\begin{aligned} xy &= b^m b^n = b^{m+n} &&\Rightarrow& \log_b(xy) &= m + n \\[2pt] \frac{x}{y} &= b^{m-n} &&\Rightarrow& \log_b\frac{x}{y} &= m - n \\[2pt] x^k &= (b^m)^k = b^{mk} &&\Rightarrow& \log_b(x^k) &= km \end{aligned}

change of base comes from the power rule in the other base. take log⁡c\log_c of both sides of x=bmx = b^m:

log⁡cx=mlog⁡cb⇒m=log⁡cxlog⁡cb\log_c x = m \log_c b \quad\Rightarrow\quad m = \frac{\log_c x}{\log_c b}

the left side is log⁡bx\log_b x. so every log is every other log times a constant, which is why big o drops the base: log⁡2n\log_2 n is about 3.32log⁡10n3.32 \log_{10} n for every nn.

pitfalls

practice

  1. simplify 27⋅2324\frac{2^7 \cdot 2^3}{2^4}.

    answer

    add the exponents on top and subtract the one below: 27+3−4=26=642^{7 + 3 - 4} = 2^6 = 64.

  2. read each log back as an exponent.

    log⁡381log⁡100.001log⁡218\log_3 81 \qquad \log_{10} 0.001 \qquad \log_2 \frac{1}{8}
    answer

    each one asks for an exponent. 34=813^4 = 81, so log⁡381=4\log_3 81 = 4. 10−3=0.00110^{-3} = 0.001, so log⁡100.001=−3\log_{10} 0.001 = -3. 2−3=1/82^{-3} = 1/8, so log⁡2(1/8)=−3\log_2 (1/8) = -3.

  3. work out 82/38^{2/3} and 16−1/216^{-1/2}.

    answer

    root first, then power: 82/3=(83)2=22=48^{2/3} = (\sqrt[3]{8})^2 = 2^2 = 4. the negative exponent divides: 16−1/2=1/16=1/416^{-1/2} = 1 / \sqrt{16} = 1/4.

  4. a sample of 200 g has a half-life of 5 hours. how much is left after 15 hours, and when is 12.5 g left?

    answer

    15 hours is three half-lives: 200→100→50→25200 \to 100 \to 50 \to 25, so 25 g. 12.5 g is one more halving, four in all: 20 hours.

  5. solve 5x=1005^x = 100.

    answer

    take a log of both sides, in any base: x=log⁡5100=ln⁡100ln⁡5≈2.86x = \log_5 100 = \frac{\ln 100}{\ln 5} \approx 2.86. check it against the powers around it: 52=255^2 = 25 and 53=1255^3 = 125, so xx between 2 and 3 fits.

  6. a sorted list holds 4 billion items. how many times does binary search halve it, at most, before one item is left?

    answer

    log⁡24,000,000,000≈31.9\log_2 4{,}000{,}000{,}000 \approx 31.9, so 32 halvings. 232=4,294,967,2962^{32} = 4{,}294{,}967{,}296 is the first power of 2 past 4 billion. a million took 20, and the extra factor of 4,000 cost about 12 more.

sources

  1. mdn’s Math.log (opens in a new tab), Math.log10 (opens in a new tab) and Math.log2 (opens in a new tab) reference pages: Math.log is the natural logarithm, base e, Math.log10 and Math.log2 are the base 10 and base 2 logarithms, and for another base mdn says to divide Math.log(x) by Math.log(otherBase). ↩

  2. python’s math (opens in a new tab) docs: with two arguments, math.log(x, base) is calculated as log(x)/log(base), and math.log10 and math.log2 are usually more accurate than log(x, 10) and log(x, 2). ↩

  3. mdn’s exponentiation operator (opens in a new tab) reference page: a unary operator right before the base, as in -2 ** 2, is a SyntaxError in javascript, so the expression can’t be read two ways. the same expression is −4 in python and 4 in bash. ↩