Index Ai Academy
Foundation · Foundation mathAlgebra

Logarithms: the power question

About 45 minLooking ahead: some prerequisites aren't done yet

Why this matters

A logarithm answers one question: to what power? log₁₀(1,000) asks "10 to what power gives 1,000?", and the answer is 3. Logs undo exponentials, and they turn multiplying into adding, which is why they're everywhere in machine learning. Multiply a hundred small probabilities and a computer rounds the answer to zero; add their logs and nothing is lost. The loss most models are trained on is built from a log. This lesson defines logs by that question first, then the three laws that follow from it, and the one mistake almost everyone makes with them.

  • Read a logarithm as the answer to "to what power?", in base 10, base 2 and base e
  • Use the three laws of logs, and solve an equation like 2ˣ = 1,000
  • Compute logs in Python with math.log, math.log10 and math.log2, and test each law with numbers
  • Add logs instead of multiplying tiny probabilities, and read −log(p) as a measure of surprise
Quick check
Have a guess before you start. 10 to what power gives 1,000?

The math: to what power?

Purpose. Undo an exponential, and tame numbers of hugely different sizes.

A logarithm answers "to what power?":

log⁡a(y)=xmeansax=y\log_a(y) = x \quad\text{means}\quad a^x = y

In plain words: log base a of y is the power you raise a to, to get y.

So log₁₀(100) = 2, because 10² = 100, and log₂(8) = 3, because 2³ = 8. Three bases are common: log₁₀ (base 10, "orders of magnitude" from lesson 11), log₂ (base 2, doublings), and ln, the natural log, base e. log of 1 is 0 in every base, since anything to the power 0 is 1.