Sub topic 2
What a logarithm is
Prerequisites and scope
This chapter assumes you are comfortable with integer, negative and fractional exponents, and with the laws of exponents. You should also be able to solve a simple linear equation and know what an inverse function is. The chapter defines the logarithm and shows how to read and evaluate it. The product, quotient and power laws, change of base, and equation solving come in later chapters.
The question a logarithm answers
An exponential expression such as 2^5 = 32 takes a base (2) and an exponent (5) and produces a value (32). A logarithm runs this in reverse. You are given the base and the value, and you ask which exponent connects them.
The logarithm of a value x to the base b, written log_b(x), is the exponent to which b must be raised to give x.
Some examples:
- log_2(32) = 5, because 2^5 = 32.
- log_10(1000) = 3, because 10^3 = 1000.
- log_3(81) = 4, because 3^4 = 81.
- log_5(1/25) = -2, because 5^(-2) = 1/25.
- log_9(3) = 1/2, because 9^(1/2) = 3.
The last two show that a logarithm can be negative or fractional. Any exponent you learned about in the exponent review can appear as the answer.
The formal definition
For a base b with b > 0 and b ≠ 1, and for x > 0:
log_b(x) = y exactly when b^y = x.
Each condition has a reason.
- b > 0. A negative base produces values that alternate in sign and are undefined for fractional exponents, so the exponent question has no consistent answer.
- b ≠ 1. Every power of 1 equals 1. The equation 1^y = 7 has no solution, and 1^y = 1 is satisfied by every y. So log_1 would not give a single answer.
- x > 0. A positive base raised to any real power gives a positive result. No exponent produces zero or a negative value, so logb(0) and logb(-4) do not exist as real numbers.
Exponential form and logarithmic form
The definition is a statement that two equations say the same thing. Moving between them is the most useful skill in this chapter.
| Exponential form | Logarithmic form |
|---|---|
| 2^5 = 32 | log_2(32) = 5 |
| 10^(-2) = 0.01 | log_10(0.01) = -2 |
| 4^(1/2) = 2 | log_4(2) = 1/2 |
| b^y = x | log_b(x) = y |
The base stays the base. The exponent becomes the value of the logarithm. The result of the power becomes the argument, which is the number inside the logarithm.
Evaluating a logarithm by rewriting it
To evaluate log_b(x), set it equal to y, rewrite it in exponential form, and solve for y.
Example: find log_4(64).
- Let y = log_4(64).
- Rewrite: 4^y = 64.
- Since 64 = 4^3, y = 3.
Example: find log8(2). Let y = log8(2), so 8^y = 2. Since 8 = 2^3, we have 2^(3y) = 2^1, so 3y = 1 and y = 1/3.
When the argument is not an exact power of the base, the answer is an irrational number, such as log_2(10) ≈ 3.3219. You then use a calculator or code, which the change-of-base chapter covers.
Logarithms and exponentials as inverses
Because the definition links the two operations, applying one after the other undoes it. For b > 0 and b ≠ 1:
- log_b(b^y) = y for every real y.
- b^(log_b(x)) = x for every x > 0.
The first line says that asking "what exponent gives b^y?" returns y, because y is the exponent you used. The second says that raising b to the exponent that produces x gives x back. Both follow directly from the definition, and they are the formal statement that the functions f(x) = b^x and g(x) = log_b(x) are inverses.
Here is a check in Python using base 2.
import math
y = 7.0
x = 50.0
print(math.log2(2 ** y)) # 7.0
print(2 ** math.log2(x)) # 50.0 (may print 50.00000000000001 due to rounding)
print(math.isclose(2 ** math.log2(x), x)) # TrueSpecial values every logarithm shares
Two values hold for every valid base b, and they come straight from the definition.
- log_b(1) = 0, because b^0 = 1 for every nonzero b.
- log_b(b) = 1, because b^1 = b.
Related values follow from the inverse identities. For example, logb(b^3) = 3 and logb(1/b) = log_b(b^(-1)) = -1.
These values are useful for sanity checks. If you compute a logarithm of 1 and do not get 0, something is wrong.
Common bases
Any positive base other than 1 is allowed, but three bases are used far more than the rest.
| Base | Name | Common notation | Typical use |
|---|---|---|---|
| 10 | Common logarithm | log(x) or log_10(x) | Scientific notation, decibels, pH |
| e ≈ 2.71828 | Natural logarithm | ln(x) | Calculus, continuous growth |
| 2 | Binary logarithm | log_2(x) or lg(x) | Computer science, bits, halving |
Notation varies by context, so check what "log" means in the source you are reading. On most scientific calculators, log means base 10 and ln means base e. In Python, math.log(x) is the natural logarithm, math.log10(x) is base 10 and math.log2(x) is base 2. In many mathematics and computer science texts, log with no base can mean the natural logarithm or the binary logarithm.
import math
print(math.log10(1000)) # 3.0
print(math.log(math.e)) # 1.0
print(math.log2(1024)) # 10.0
print(math.log(100, 10)) # 2.0The two-argument form math.log(x, base) accepts any base. The floating-point result can be slightly off for some inputs, for example math.log(1000, 10) returns 2.9999999999999996 in CPython. For base 10 and base 2, prefer math.log10 and math.log2, which are more accurate.
Domain and range: what you can put in and get out
From the definition, the argument must be positive. The logarithm itself can be any real number.
- Domain of log_b(x): all x > 0.
- Range of log_b(x): all real numbers.
Python enforces the domain.
import math
try:
math.log10(-5)
except ValueError as err:
print(err) # math domain errorThe shape of the graph
For b > 1, the graph of y = log_b(x) has these features:
- It passes through (1, 0), because log_b(1) = 0.
- It passes through (b, 1), because log_b(b) = 1.
- It increases, but more and more slowly. Each time x is multiplied by b, the output goes up by exactly 1.
- It approaches the vertical line x = 0 (the y-axis) without touching it. As x gets close to 0 from the right, the output becomes a large negative number.
The graph is the reflection of y = b^x across the line y = x, which is what being an inverse looks like. The exponential has a horizontal asymptote at y = 0, and the logarithm has a vertical asymptote at x = 0.
For 0 < b < 1, the graph is reversed. It decreases from left to right, but it still passes through (1, 0) and has the same domain and range.
A worked example from start to finish
Evaluate log2(1/8) + log5(25) - log_7(1).
- log_2(1/8): 2^y = 1/8 = 2^(-3), so y = -3.
- log_5(25): 5^y = 25 = 5^2, so y = 2.
- log_7(1) = 0, by the special value.
- Total: -3 + 2 - 0 = -1.
import math
total = math.log2(1 / 8) + math.log(25, 5) - math.log(1, 7)
print(round(total, 10)) # -1.0Summary of the key ideas
- log_b(x) is the exponent that b needs to reach x.
- log_b(x) = y and b^y = x are two ways of writing the same fact.
- The base must be positive and not 1, and the argument must be positive.
- logb(1) = 0 and logb(b) = 1 for every valid base.
- Bases 10, e and 2 have their own names and notation, and the meaning of "log" depends on the field.
Exercise
Evaluate log3(1/27) and log16(4). Then write 7^2 = 49 in logarithmic form.
Show answer
For log3(1/27), solve 3^y = 1/27 = 3^(-3), so y = -3. For log16(4), solve 16^y = 4. Since 16 = 4^2, 4^(2y) = 4^1, so 2y = 1 and y = 1/2. In logarithmic form, 7^2 = 49 is log_7(49) = 2.
Exercise
Explain why logb(0) is undefined for every valid base b, and state what logb(b^x) equals for any real x.
Show answer
logb(0) = y would mean b^y = 0. A positive base raised to any real power is positive, so no y satisfies this. The expression logb(b^x) equals x, because x is the exponent that b needs to reach b^x.