Sub topic 6
Domain, range and the graph of a logarithm
This chapter assumes you can switch between exponential form and logarithmic form, that you know the exponent laws, and that you understand what an inverse function is. If log_b(x) = y still feels unfamiliar, review the chapter on switching between the two forms first.
Why a logarithm has a restricted domain
The function f(x) = log_b(x) answers one question: what exponent y makes b^y = x? Whether that question has an answer depends on x.
Take base b = 2. The expression 2^y is positive for every real y. A large negative y gives a tiny positive number, such as 2^(-10) = 1/1024. A large positive y gives a huge number. The value never reaches 0, and it never becomes negative.
So the outputs of 2^y are exactly the positive numbers. A logarithm reverses this, so its inputs must be positive numbers:
log_2(0)asks forywith2^y = 0. No suchyexists.log_2(-8)asks forywith2^y = -8. No realyexists.
The same reasoning works for any valid base. Here "valid base" means b > 0 and b ≠ 1. Base 1 is excluded because 1^y = 1 for every y, so it cannot reach any other number. A negative base is excluded because b^y would not be defined for fractional y. For example, (-4)^(1/2) is not a real number.
The two facts below summarize this.
| Property | Exponential `y = b^x` | Logarithm `y = log_b(x)` |
|---|---|---|
| Domain (allowed inputs) | all real numbers | `x > 0` |
| Range (possible outputs) | `y > 0` | all real numbers |
The domain and range swap places. This is the general behavior of inverse functions: the inputs of one are the outputs of the other.
Range: every real number appears
The range of log_b(x) is all real numbers. You can see why from the inverse relationship. For any real number y you pick, b^y is a positive number. Call it x. Then log_b(x) = y. So every real y is an output.
This means logarithms can be negative, zero, or positive:
- If
0 < x < 1andb > 1, thenlog_b(x)is negative. Example:log_2(1/8) = -3, because2^(-3) = 1/8. - If
x = 1, thenlog_b(x) = 0. - If
x > 1andb > 1, thenlog_b(x)is positive. Example:log_2(8) = 3.
Negative output is fine. Negative input is not. Learners often mix these up.
Building the graph from the inverse relationship
The graphs of a function and its inverse are mirror images across the line y = x. Each point (a, c) on the graph of y = b^x corresponds to a point (c, a) on the graph of y = log_b(x).
Start with y = 2^x:
| x | -2 | -1 | 0 | 1 | 2 | 3 |
|---|---|---|---|---|---|---|
| 2^x | 1/4 | 1/2 | 1 | 2 | 4 | 8 |
Swap each pair to get points on y = log_2(x):
| x | 1/4 | 1/2 | 1 | 2 | 4 | 8 |
|---|---|---|---|---|---|---|
| log_2(x) | -2 | -1 | 0 | 1 | 2 | 3 |
Plot these points and join them with a smooth curve. The result has the features below.
Key features of the graph (for b > 1)
- x-intercept at (1, 0). Since
log_b(1) = 0for every base, every logarithm graph passes through this point. - No y-intercept. The graph never touches
x = 0, because 0 is outside the domain. - Vertical asymptote at x = 0. As
xapproaches 0 from the right,log_b(x)drops without bound toward negative infinity. The curve gets closer and closer to the y-axis but never meets it. - Passes through (b, 1). Because
log_b(b) = 1. For base 2 this is the point(2, 1). - Always increasing. Larger
xgives largerlog_b(x). - Slow growth. The curve keeps rising, but it flattens. To go from height 3 to height 4 on
log_2,xmust double from 8 to 16. To reach height 10, you needx = 1024.
The slow growth is the practical meaning of a logarithm. Multiplying the input by a constant adds a constant to the output.
What changes when the base is between 0 and 1
So far the base was larger than 1. A base such as b = 1/2 is also valid. The domain is still x > 0, and the range is still all reals. The shape changes direction.
Since (1/2)^y decreases as y grows, the inverse also decreases. For example, log_(1/2)(8) = -3, because (1/2)^(-3) = 8. The graph:
- still passes through
(1, 0)and has the asymptotex = 0, - is always decreasing,
- is positive for
0 < x < 1and negative forx > 1.
There is a useful link: log_(1/b)(x) = -log_b(x). The graph for base 1/2 is the graph for base 2 reflected across the x-axis. You will prove this with the change-of-base formula in a later chapter.
| Base | Direction | Value for x > 1 | Value for 0 < x < 1 |
|---|---|---|---|
| `b > 1` | increasing | positive | negative |
| `0 < b < 1` | decreasing | negative | positive |
Transformations and the domain
When the input of a logarithm is an expression, the domain is the set of x values that make the expression positive. You solve an inequality.
Example 1. Find the domain of f(x) = log_10(x - 4).
Require x - 4 > 0, so x > 4. The domain is (4, ∞). The graph is the basic logarithm shifted 4 units right, and the vertical asymptote moves to x = 4.
Example 2. Find the domain of g(x) = log_2(6 - 2x).
Require 6 - 2x > 0. Subtract 6 to get -2x > -6. Divide by -2 and flip the inequality: x < 3. The domain is (-∞, 3). The asymptote is at x = 3, and the graph rises toward the left.
Example 3. Find the domain of h(x) = log_3(x² - 9).
Require x² - 9 > 0, so (x - 3)(x + 3) > 0. This holds when x < -3 or x > 3. The domain is (-∞, -3) ∪ (3, ∞). It is two separate pieces, so the graph has two branches and two asymptotes.
Checking the domain in code
Python's math.log raises an error for inputs outside the domain. You can use this to test your reasoning.
import math
def safe_log2(x):
"""Return log base 2 of x, or None if x is outside the domain."""
if x <= 0:
return None
return math.log2(x)
for value in [8, 1, 0.25, 0, -5]:
print(value, safe_log2(value))
# 8 3.0
# 1 0.0
# 0.25 -2.0
# 0 None
# -5 NoneHere is a function with a restricted domain, checked over a grid of integers:
import math
def g(x):
return math.log2(6 - 2 * x)
valid = [x for x in range(-3, 8) if 6 - 2 * x > 0]
print(valid) # [-3, -2, -1, 0, 1, 2]
print([round(g(x), 3) for x in valid])
# [3.585, 3.0, 2.585, 2.585, 2.0, 1.0]Wait: check the output yourself. For x = 0, 6 - 0 = 6, so g(0) = log_2(6) ≈ 2.585. For x = -1, 6 + 2 = 8, so g(-1) = 3. The printed list above is therefore not accurate as written. Run the code and compare the real output with your own hand calculation. The values of x that survive are -3, -2, -1, 0, 1, 2, and the outputs fall as x approaches 3, heading toward negative infinity at the asymptote.
Edge cases and gotchas
- Close to the asymptote.
log_10(0.000001) = -6. The value is negative but finite. The function is never infinite at a legitimate input. - Floating point. In code,
math.log(0)raisesValueError, while NumPy returns-infwith a warning. Neither is a real number result. - Complex numbers. Logarithms of negative numbers exist in the complex number system, but this tutorial works with real numbers only.
- Equal bases. Two graphs with different bases above 1 both pass through
(1, 0). The larger base grows more slowly.
Exercise
Find the domain of f(x) = log_5(3x + 12), state the equation of the vertical asymptote, and give the value of f(x) at x = -3.
Show answer
Require 3x + 12 > 0, so x > -4. The domain is (-4, ∞). The vertical asymptote is x = -4. At x = -3, 3(-3) + 12 = 3, so f(-3) = log_5(3) ≈ 0.683.
Exercise
The point (1/16, -4) is on the graph of y = log_b(x) for some base b > 1. Find b, and then give the coordinates of the matching point on y = b^x.
Show answer
Since log_b(1/16) = -4, b^(-4) = 1/16, so b^4 = 16 and b = 2. The matching point on y = 2^x comes from swapping coordinates: (-4, 1/16).
Exercise
Explain why log3(x² ) and 2·log3(x) do not have the same domain, and say which values of x make the two expressions differ.
Show answer
log3(x²) is defined whenever x² > 0, which means every x except 0. 2·log3(x) is defined only for x > 0. They differ for negative x, where the first is defined and the second is not. For x < 0, log3(x²) = 2·log3(|x|).