Objective
Learning objectives
- Explain a logarithm as "what exponent gets me here"
- Use
math.log to solve for an unknown exponent directly - Verify a logarithm-based answer against manual repeated multiplication
- Solve a real growth scenario for the number of steps using logarithms
Hook
You have $1. It doubles every year. How many times does it have to double before it passes $1,000? Lesson 01 gave you the tools to answer this by brute force — double it, check, double it again, check again — but notice the question is really asking for the exponent: some number n where 2^n first clears 1,000. Is there a way to solve for n directly, the way you'd solve 2x = 10 directly instead of guessing values of x until one works?
See it
Every point on the green exponential curve has a matching point on the red curve, with its coordinates swapped — where the exponential says "input 3 gives output 8," the log curve (same base) says "input 8 gives output 3." That's not a coincidence of this particular pair of curves; it's the defining relationship. A logarithm doesn't compute something new — it reads the exponential relationship backward.
Same fact, read in two directions
"2 to the power of 3 is 8" and "log base 2 of 8 is 3" are the exact same fact about the numbers 2, 3, and 8 — one sentence answers "what do I get?", the other answers "what exponent got me here?" Neither is more fundamental than the other; they're two questions about one relationship.
Name it
A logarithm answers "what exponent do I need?" log_b(x) (read "log base b of x") is the exponent you'd raise b to in order to get x. Formally: log_b(x) = n means exactly the same thing as b^n = x — they're two ways of writing one relationship, not two different facts.
Logarithms come with rules that mirror exponent rules exactly (because they describe the same underlying relationship): log_b(a × c) = log_b(a) + log_b(c) — multiplication inside a log becomes addition outside it. This isn't just algebra trivia: it's the reason log-loss (a common way to score how well an AI model's probabilities matched reality) and information theory both lean on logarithms specifically — turning products of many small probabilities into sums is dramatically easier to compute and reason about. Full treatment of that lives in this platform's AI/ML-focused courses; the fact worth carrying forward from here is just that this connection is real, not decorative.
Code it
import math
# how many doublings of $1 to reach $1,000?
n = math.log(1000, 2)
print(n)
print(math.ceil(n))
9.965784284662087
10
math.log(1000, 2) directly answers "what exponent, applied to base 2, gives 1000?" — the raw answer, 9.97, means 1,000 falls between 2^9 and 2^10, so ceil() rounds up to the first whole doubling that actually clears it: 10. Verify that against brute-force doubling, exactly the approach from Lesson 01:
value = 1
count = 0
while value < 1000:
value *= 2
count += 1
print(count, value)
10 1024
Both approaches agree: 10 doublings, landing on 1,024 — past 1,000, confirming ceil() was the right call rather than truncating. The logarithm didn't just estimate this; it computed the exact real-valued exponent (9.9658...) in one step, without ever looping.
import math
n = math.log(6000, 3)
print(round(n, 4))
print(math.ceil(n))
print(3 ** math.ceil(n))
log_3(6000) asks "what exponent on base 3 gives 6000?" — the real-valued answer is about 7.92, meaning 6,000 sits between 3^7 (2,187) and 3^8 (6,561). Rounding up to the next whole exponent gives 8, and 3^8 = 6561 is indeed the first power of 3 that clears 6,000.