Exponential Equations
An exponential equation has the unknown in the exponent, like or . You solve it either by writing both sides as powers of the same base, or by taking a logarithm of both sides. Programmers meet these equations whenever they ask "how many steps until…": doubling times, retry backoff, bits needed to count something.
Method 1: same base
If both sides can be written as powers of one base (, ), the exponents must be equal, because is one-to-one:
This works when the numbers are "nice" powers (2, 4, 8, 16, 32…, or 3, 9, 27, 81…). Fractions and roots fit in too: and (see rational exponents).
Method 2: take logarithms
When no common base exists, apply a logarithm to both sides and use to bring the unknown down (log laws):
Any base of logarithm works, as long as you use the same one on both sides. With the unknown on both sides, collect the terms:
Tip: Isolate the power first. In , subtract 1 and divide by 4 to get , so . Taking logs too early leaves you with , which no law simplifies.
Method 3: a quadratic in disguise
When the same exponential appears with exponents and , substitute :
Because is always positive, any negative is rejected: it gives no real .
Checking with Python
import math
import sympy as sp
print("5^x = 40 :", math.log(40) / math.log(5))
print("check :", 5 ** (math.log(40) / math.log(5)))
x2 = math.log(3) / math.log(1.5)
print("2^x = 3^(x-1):", x2, 2 ** x2, 3 ** (x2 - 1))
x = sp.symbols("x", real=True)
print(sp.solve(sp.Eq(9**x, 27**(x - 1)), x))
print(sp.solve(4**x - 6 * 2**x + 8, x))
sol = sp.solve(sp.Eq(2**x, 3**(x - 1)), x)
print(sol, [float(s) for s in sol])5^x = 40 : 2.292029674220179
check : 40.0
2^x = 3^(x-1): 2.709511291351455 6.5410003487433785 6.541000348743379
[3]
[1, 2]
[-log(3)/(-log(3) + log(2))] [2.709511291351455]
SymPy writes exact answers with log, its name for ln. The two sides of agree to about 15 digits but differ in the last one: floating-point rounding, not a wrong answer. Compare floats with a tolerance (math.isclose), never with ==.
In software
Exponential equations answer "how many repetitions?" questions. The answer is usually not a whole number, so you round up to the next integer step with math.ceil.
| Question | Equation | Solution |
|---|---|---|
| Years for money to double at 5% | ||
| Bits to store different values | ||
| Retries until backoff passes 60 s (0.1 s, doubling) | ||
| Half-lives until 1% of a cache weight remains |
import math
t = math.log(2) / math.log(1.05)
print(f"doubling at 5%: {t:.4f} years -> {math.ceil(t)} whole years")
for n in [10, 256, 1000, 1_000_000]:
print(f"{n:>9} values need {math.ceil(math.log2(n))} bits")
k = math.ceil(math.log2(60 / 0.1))
print("retry delays:", [round(0.1 * 2**i, 1) for i in range(k + 1)])
print("first delay over 60 s is retry", k)doubling at 5%: 14.2067 years -> 15 whole years
10 values need 4 bits
256 values need 8 bits
1000 values need 10 bits
1000000 values need 20 bits
retry delays: [0.1, 0.2, 0.4, 0.8, 1.6, 3.2, 6.4, 12.8, 25.6, 51.2, 102.4]
first delay over 60 s is retry 10
Note: For exact powers of two,
math.log2is exact (), but in general a float log can land a hair above or below a whole number. For integers,(n - 1).bit_length()gives with no rounding risk.
Growth and decay models of this shape are the exponential functions of pre-calculus, and their rates of change are in derivatives of exponentials.
Exercises
Exercise 1: Same base
Solve .
Answer
Solution
Check: and .
Exercise 2: Isolate, then log
Solve exactly and to 4 decimal places.
Answer
Solution
import math
x = math.log(15) / math.log(2)
print(round(x, 4), 3 * 2**x - 5)3.9069 40.00000000000001
Exercise 3: Disguised quadratic
Solve .
Answer
or
Solution
Let , so :
Exercise 4: Loot drop streak (code)
An item drops with probability 3% per kill, independently. The chance of no drop in kills is . Find the smallest whole for which the chance of at least one drop is at least 90%, and confirm with a loop.
Answer
kills ().
Solution
We need , so . Taking ln flips the inequality, because is negative:
import math
print(math.log(0.1) / math.log(0.97))
n = 0
while 1 - 0.97**n < 0.9:
n += 1
print(n, round(0.97**n, 4))75.59569940058392
76 0.0988
Test yourself
Solve .
Which expression solves ?
In , the substitution gives or . What are the solutions?
- only
- and
- and
- No solution