mathprecalc
exponents + logs
growth that multiplies, and the log that asks how many times.
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)ⁿ
- doubling, half-lives, a percent a year
- reading O(log n) and O(2ⁿ)
- solving for an exponent
on this page
the idea
an exponent counts multiplications. 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. .
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 , climbs faster and faster, and climbs slower and slower, and the two stay mirror images across . drag the point along : its mirror on has the same two numbers the other way round. the base can’t be 1, since is 1 for every and there would be no exponent to read back.
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.
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. is copies of multiplied together.
factors of , then more: factors in all.
of the factors on top cancel against the below.
a group of factors, written out times.
copies of , with the ‘s and the ‘s sorted into two groups.
not a count of factors any more, but the only values that keep the product rule true. has to equal and so . and has to equal too, which makes the reciprocal .
the power of a power again: , so is the number whose th power is . .
growth that multiplies
is the amount at the start and the factor each step. doubles. halves, and the time one halving takes is the half-life. a rise of percent a step is : 3% a year is , and 24 years of it is , a little more than double.
e
split a year’s 100% interest into payments of percent each, and one unit of money grows to 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 , and growth that compounds at every instant is . it’s the natural base for growth, and the derivatives page says why.
- 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
the log is the exponent. because . . , where is . in every base, , since , and .
write and . then by the product rule, and the log reads that exponent back: .
the quotient rule, read the same way: .
: the power of a power.
change of base. any log is any other log divided by a constant, so a calculator with only or does every base: .
worked examples
how many doublings
a culture of 100 cells doubles every hour. after hours it’s : 819,200 cells after 13 hours and 1,638,400 after 14. when does it pass a million?
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 days there’s left: 9 days is three half-lives, g, and 10 days is g. when is 5 g left? , 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?
the rule of 70 gets close without a calculator: . it works because and for a small . at 7% a year it says 10 years, against 10.2 from the log.
solving for the exponent
. the answer sits between 3 and 4, since and . the log gives it exactly:
check: .
why log n is small
. 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 in adds about 10, because . it’s why O(log n) sits next to O(1) in big o.
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 . 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 at distance 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 to is
the same length wherever is. multiplying by 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 and end to end, and the mark under the end reads .
the same three numbers on a plain axis
and on a log scale, where every step to the right is ×10
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 and , so that and :
change of base comes from the power rule in the other base. take of both sides of :
the left side is . so every log is every other log times a constant, which is why big o drops the base: is about for every .
pitfalls
- a sum has no rule. isn’t : , not . and isn’t : , not . the rules are about products and quotients
- is . the exponent binds before the minus, so it’s . is 4. python reads
-2 ** 2as too. javascript refuses it as a syntax error and makes you write the parentheses either way3 - no log of 0 or of a negative number, in the real numbers. is positive for every real , so no exponent reaches 0 or goes below it.
Math.log(0)is-InfinityandMath.log(-1)isNaN. and no base 1: is always 1 - which log is “log”. on a calculator, in most math, in computer science. in javascript
Math.logis . they differ by a constant factor, so it never matters inside a big o - a power can lead for a while. is bigger than for every from 2 to 9: 729 against 512 at . at it’s 1,000 against 1,024, and never looks back. holds out until . growth that multiplies passes every power in the end, which is why O(2ⁿ) is the last row of the table on the big o page
- the float in the root.
64 ** (1 / 3)is 3.9999999999999996:1 / 3is stored a hair under a third, so the power lands a hair under 4.Math.cbrtandMath.sqrtgive 4 and 2 exactly
practice
-
simplify .
answer
add the exponents on top and subtract the one below: .
-
read each log back as an exponent.
answer
each one asks for an exponent. , so . , so . , so .
-
work out and .
answer
root first, then power: . the negative exponent divides: .
-
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: , so 25 g. 12.5 g is one more halving, four in all: 20 hours.
-
solve .
answer
take a log of both sides, in any base: . check it against the powers around it: and , so between 2 and 3 fits.
-
a sorted list holds 4 billion items. how many times does binary search halve it, at most, before one item is left?
answer
, so 32 halvings. 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
-
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.logis the natural logarithm, base e,Math.log10andMath.log2are the base 10 and base 2 logarithms, and for another base mdn says to divideMath.log(x)byMath.log(otherBase). ↩ -
python’s math (opens in a new tab) docs: with two arguments,
math.log(x, base)is calculated aslog(x)/log(base), andmath.log10andmath.log2are usually more accurate thanlog(x, 10)andlog(x, 2). ↩ -
mdn’s exponentiation operator (opens in a new tab) reference page: a unary operator right before the base, as in
-2 ** 2, is aSyntaxErrorin javascript, so the expression can’t be read two ways. the same expression is −4 in python and 4 in bash. ↩