Sub topic 2
Domain, range and the graph of a logarithm
This chapter assumes you know integer, negative and fractional exponents, the laws of exponents, and how to run basic Python. It also assumes you know that $\log_b(x) = y$ means $b^y = x$, for a base $b > 0$ with $b \neq 1$.
Domain and range
The function $f(x) = \log_b(x)$ takes an input $x$ and returns an exponent. For any real exponent $t$, $b^t$ is positive. So no real exponent produces zero or a negative number, and the domain is $x > 0$. The range is all real numbers, because $b^t$ takes every positive value as $t$ varies.
| Base $b$ | Domain | Range | Shape |
|---|---|---|---|
| $b > 1$ | $x > 0$ | all real numbers | rises slowly as $x$ grows |
| $0 < b < 1$ | $x > 0$ | all real numbers | falls as $x$ grows |
The graph always passes through $(1, 0)$, because $b^0 = 1$. The line $x = 0$ is a vertical asymptote. The curve approaches the y-axis but never touches it.
Where the laws come from
Each law follows from an exponent law. Let $m = \logb(x)$ and $n = \logb(y)$, so $x = b^m$ and $y = b^n$.
The product law
Multiplying gives $xy = b^m \cdot b^n = b^{m+n}$. In logarithm form, $\logb(xy) = m + n = \logb(x) + \log_b(y)$.
The quotient law
Dividing gives $x/y = b^m / b^n = b^{m-n}$. So $\logb(x/y) = \logb(x) - \log_b(y)$.
The power law
Raising to a power $k$ gives $x^k = (b^m)^k = b^{mk}$. So $\logb(x^k) = k\,\logb(x)$.
import math
x, y = 8.0, 32.0
print(math.isclose(math.log2(x * y), math.log2(x) + math.log2(y))) # True
print(math.isclose(math.log2(x / y), math.log2(x) - math.log2(y))) # True
print(math.isclose(math.log2(x ** 3), 3 * math.log2(x))) # True
try:
math.log(0)
except ValueError as error:
print("Error:", error) # outside the domainExercise
Why is log_2(0) undefined over the real numbers?
Show answer
No real exponent t makes 2^t equal to 0, because 2^t is always positive. So 0 lies outside the domain of the logarithm.