Logarithmic Equations
A logarithmic equation has the unknown inside a logarithm, like . The plan is always the same: combine the logs into one, rewrite the equation in exponential form, solve, and then check every answer, because logarithms only accept positive inputs and the algebra can produce answers that don't fit.
The key move: exponential form
By definition (see what a logarithm is):
So a single log equal to a number turns into an ordinary equation:
The unknown can also be the base: means , so (the base must be positive, so is rejected).
Combining logs first
When there are several logs, use the log laws to merge them into one:
| Law | Use |
|---|---|
| two logs added | |
| two logs subtracted | |
| a number in front |
Example with base-10 logs:
Now check the domain: is undefined, so is an extraneous solution. The only answer is (check: ).
Note: Merging logs widens the domain. is defined for , because , but the original is not. That is how the fake solution sneaks in.
Log equals log
If both sides are single logs of the same base, drop the logs (log is one-to-one), then check:
Solving and checking in code
Let SymPy solve, then filter candidates by plugging them into the original equation. Below, ok tests the domain of every log; that check is what removes extraneous roots.
import math
import sympy as sp
x = sp.symbols("x")
merged = sp.Eq(x * (x - 3), 10) # from log(x) + log(x-3) = 1
candidates = sp.solve(merged, x)
print("candidates:", candidates)
def ok(v):
return v > 0 and v - 3 > 0
for v in candidates:
if ok(v):
print(v, "->", math.log10(v) + math.log10(v - 3))
else:
print(v, "-> rejected (log of a non-positive number)")
print(sp.solve(sp.Eq(sp.log(2*x - 1), 3), x))
print(float((sp.exp(3) + 1) / 2))candidates: [-2, 5]
-2 -> rejected (log of a non-positive number)
5 -> 1.0
[1/2 + exp(3)/2]
10.542768461593834
In software
Logs turn "how many times did we multiply?" into "how far did we add?". Common equations a programmer solves:
- Digits of a number: has decimal digits. Solving gives the range .
- Decibels: a gain of dB means a power ratio with . Solving for the ratio gives . Audio volume sliders and Wi-Fi signal levels (dBm) use this.
- Balanced trees and binary search: a search over sorted items takes about steps. "How many items can 20 steps cover?" means , so (binary search).
- Information: an event with probability carries bits; "which carries 5 bits?" gives .
import math
for n in [7, 999, 1000, 4_096_000]:
print(f"{n:>9} has {math.floor(math.log10(n)) + 1} digits, len(str) = {len(str(n))}")
for gain_db in [3, 10, -6, 20]:
print(f"{gain_db:+} dB -> power x{10 ** (gain_db / 10):.3f}")
print("items covered by 20 halvings:", 2 ** 20) 7 has 1 digits, len(str) = 1
999 has 3 digits, len(str) = 3
1000 has 4 digits, len(str) = 4
4096000 has 7 digits, len(str) = 7
+3 dB -> power x1.995
+10 dB -> power x10.000
-6 dB -> power x0.251
+20 dB -> power x100.000
items covered by 20 halvings: 1048576
Tip: For very large integers, prefer
len(str(n))orn.bit_length()over float logs. A float log of can round to exactly 15.0 and give one digit too many.
The functions behind these equations, their graphs and inverses are covered in exponential and logarithmic functions.
Exercises
Exercise 1: Rewrite and solve
Solve .
Answer
Solution
Check: , and . ✓
Exercise 2: Spot the extraneous root
Solve .
Answer
( is extraneous)
Solution
is undefined, so only survives. Check: . ✓
Exercise 3: Difference of logs
Solve .
Answer
Solution
Check: both and are positive, and . ✓
Exercise 4: Volume slider (code)
A volume slider maps a position from 0 to 100 to a gain of dB (so is 0 dB). Solve for when dB, by hand and with code.
Answer
Solution
import math
s = 100 * 10 ** (-12 / 40)
print(round(s, 2), round(40 * math.log10(s / 100), 6))50.12 -12.0
Test yourself
Solve .
Why must you check solutions of log equations?
- Because logs are slow to compute
- Because merging logs can create solutions that make an original log's input zero or negative
- Because SymPy is unreliable
- Because every log equation has two solutions
(base 10). What is ?
- 25
- 96
- 8