Sub topic 10
Solving for time with logarithms
Earlier chapters showed how to find the amount after a given time. This chapter reverses the question: how long until the amount reaches a target? The unknown is now in the exponent, and logarithms are the tool that brings it down.
This chapter assumes you can evaluate a·b^x, convert a percent rate to a factor, and rearrange simple equations. It also assumes you have seen the half-life and compound-interest models.
Why algebra alone is not enough
Suppose 1000 dollars grows 5% per year and you want to know when it reaches 5000. The equation is:
1000 · 1.05^t = 5000Dividing by 1000 gives 1.05^t = 5. No subtraction, division, or root isolates t, because t is the exponent. You need the inverse of exponentiation, which is the logarithm.
What a logarithm does
The logarithm base b of y, written log_b(y), is the exponent that b must be raised to in order to give y. In symbols:
b^x = y means the same as x = log_b(y)Since 2^5 = 32, we have log_2(32) = 5. Two bases are common on calculators and in code:
log(base 10) andln(base e, the natural logarithm from the previous chapter).- In Python,
math.log(x)is the natural logarithm,math.log10(x)is base 10, andmath.log(x, base)takes any base.
The rule that does the work here is the power rule:
ln(b^x) = x · ln(b)Taking the logarithm of both sides of an exponential equation turns the exponent into a factor you can divide out.
| Rule | Statement | Use in this chapter |
|---|---|---|
| Power rule | `ln(b^x) = x·ln(b)` | Moves the unknown out of the exponent |
| Quotient rule | `ln(m/n) = ln(m) - ln(n)` | Rarely needed here, because we usually compute the ratio first |
| Inverse | `ln(e^x) = x` | Solves continuous models |
| Change of base | `log_b(y) = ln(y) / ln(b)` | Evaluates any base with one `ln` button |
| Domain | `log` is defined only for positive inputs | Explains the failure cases below |
The change-of-base rule means you never need a special "log base 1.05" button. You always compute a ratio of two natural logarithms.
The general recipe
For the model f(t) = a·b^t and a target value T:
- Set up
a·b^t = T. - Isolate the exponential part by dividing both sides by
a, which givesb^t = T/a. - Take the logarithm of both sides:
t·ln(b) = ln(T/a). - Divide by
ln(b):t = ln(T/a) / ln(b). - Check the units and the sign, and round only at the end.
Step 2 matters most. If you take the logarithm of 1000 · 1.05^t before dividing by 1000, you must handle ln(1000 · 1.05^t) = ln(1000) + t·ln(1.05). That is valid, but it is easy to mis-apply. Isolating first keeps the algebra short.
Worked example: growth
Find when 1000 dollars at 5% annual growth reaches 5000.
1.05^t = 5
t = ln(5) / ln(1.05)
= 1.6094 / 0.04879
≈ 32.99 yearsYou can confirm the answer by substituting it back: 1000 · 1.05^32.99 is very close to 5000.
Worked example: decay and half-life
The half-life model is N(t) = N0 · (1/2)^(t/h), where h is the half-life. Here the exponent is t/h rather than t, so after taking logarithms you also multiply by h.
For 100 g of a substance with an 8-day half-life, find when 10 g remain:
100 · (1/2)^(t/8) = 10
(1/2)^(t/8) = 0.1
(t/8) · ln(0.5) = ln(0.1)
t = 8 · ln(0.1) / ln(0.5)
≈ 8 · (-2.3026) / (-0.6931)
≈ 26.58 daysBoth logarithms are negative, because both 0.1 and 0.5 are less than 1. A negative divided by a negative is positive, so the time comes out positive. This is the normal pattern for decay toward a smaller target.
The code below reproduces these results:
import math
# Half-life model: N(t) = N0 * (1/2) ** (t / h)
N0, h = 100.0, 8.0 # 100 g with a half-life of 8 days
print(N0 * 0.5 ** (24 / h)) # 12.5 (three half-lives)
# Time until 10 g remain: solve N0 * 0.5 ** (t / h) = 10
t = h * math.log(10 / N0) / math.log(0.5)
print(round(t, 2)) # 26.58
# Doubling time at 5% growth per period
print(round(math.log(2) / math.log(1.05), 2)) # 14.21A reusable function
Every example so far is the same formula, t = ln(T/a) / ln(b), so it is worth writing once. This version also rejects inputs where no real answer exists.
import math
def time_to_reach(a, b, target):
"""Return t such that a * b**t == target."""
if a <= 0 or b <= 0:
raise ValueError("a and b must be positive")
if b == 1:
raise ValueError("b = 1 is constant, so no time reaches a different target")
ratio = target / a
if ratio <= 0:
raise ValueError("target must be positive when a is positive")
return math.log(ratio) / math.log(b)
print(round(time_to_reach(1000, 1.05, 5000), 2)) # 32.99
print(round(time_to_reach(1000, 0.95, 500), 2)) # 13.51
print(round(time_to_reach(1000, math.exp(0.05), 2000), 2)) # 13.86The second call is a value losing 5% per year (b = 0.95) until it falls to half. The third call uses b = e^0.05, which models continuous growth at 5%. Its result of 13.86 is the same as the continuous-compounding answer in the next section.
Doubling time and the effect of the rate
Setting the target to 2a makes a cancel, so the doubling time depends only on b:
t_double = ln(2) / ln(b)For 5% growth this is ln(2)/ln(1.05) ≈ 14.21 periods. Similarly, the time to halve under decay is ln(0.5)/ln(b), which equals ln(2) / -ln(b).
A quick mental estimate is the rule of 70: doubling time is roughly 70 / (percent rate). For 5% it gives 14, close to the exact 14.21. The rule works because ln(1+r) is close to r for small r, and ln(2) is about 0.693. It becomes less accurate for large rates, such as 40% per period.
Compounding more often
For compound interest with n compounding periods per year, the model is P·(1 + r/n)^(n·t). Solving for t follows the same recipe, with the whole exponent n·t as the unknown:
(1 + r/n)^(n·t) = T/P
n·t·ln(1 + r/n) = ln(T/P)
t = ln(T/P) / (n · ln(1 + r/n))The extra factor n in the denominator is easy to forget. To double money at 5% compounded monthly, use n = 12:
import math
r, n = 0.05, 12
monthly = math.log(2) / (n * math.log(1 + r / n))
annual = math.log(2) / math.log(1 + r)
continuous = math.log(2) / r
print(round(annual, 2)) # 14.21
print(round(monthly, 2)) # 13.89
print(round(continuous, 2)) # 13.86More frequent compounding shortens the time, but only slightly. The continuous case is the limit.
Continuous models and the natural logarithm
For A(t) = P·e^(rt), the base is e, so ln(e) = 1 and the formula simplifies:
P · e^(rt) = T
e^(rt) = T/P
r·t = ln(T/P)
t = ln(T/P) / rNo second logarithm appears in the denominator. This is the main reason scientists prefer base e: the rate r appears directly.
Common errors
These mistakes account for most wrong answers on time-to-target problems.
- Taking the logarithm too early. Write
ln(5)/ln(1.05), notln(5/1.05). The logarithm of a quotient is not the quotient of logarithms. - Swapping numerator and denominator. The target ratio goes on top and the base goes on the bottom. If your answer is far too small, check this first.
- Cancelling the logs.
ln(5)/ln(1.05)is not5/1.05. The expression is a ratio of two logarithms, and it cannot be simplified that way. - Forgetting that the exponent has more than
t. In the half-life model the exponent ist/h, and in compound interest it isn·t. Solve for the whole exponent first, then isolatet. - Using
bas the percent rate. For 5% growth,b = 1.05, not 0.05 and not 5. For 5% decay,b = 0.95. - Rounding early.
ln(1.05)is 0.04879. Rounding it to 0.05 before dividing changes 14.21 into 13.86. Keep full precision until the final step.
Edge cases and when no answer exists
The logarithm is defined only for positive numbers, and that limits what targets are reachable.
- Target on the wrong side of the asymptote. An exponential
a·b^twitha > 0never reaches 0 or a negative value. Asking when 1000 dollars at 5% growth reaches -50 has no solution, andmath.lograises aValueError. - Target already passed. If the target is below
aunder growth,tis negative. This is a legitimate answer about the past: the quantity was at that value|t|periods beforet = 0. Whether it makes sense depends on the context. - Decay toward a target above the start. The same logic applies: a decaying quantity never rises, so a target above
agives a negativet. - Factor equal to 1. If
b = 1, thenln(b) = 0and the formula divides by zero. The quantity never changes. - Real-world rounding. A result of 11.98 years does not mean the target is reached at year 11. If interest is paid only at year ends, round up to 12 for "when does the balance first reach the target".
Checking your answer
Substitute the result back into a·b^t. If it is close to the target, the algebra is right. The check below uses the 32.99-year answer from earlier:
a, b, t = 1000, 1.05, 32.99
print(round(a * b ** t)) # 5000Because t was rounded to two decimals, the check matches 5000 only to the nearest whole number. A small gap is expected and is not an error.
Exercise
A quantity follows f(x) = 3·2^x. Solve 3·2^x = 96 for x, first by inspection and then with logarithms. Show that both methods agree.
Show answer
Divide by 3 to get 2^x = 32. By inspection, 2^5 = 32, so x = 5. With logarithms, x = ln(32) / ln(2) = 3.4657 / 0.6931 = 5. Both methods give x = 5.
Exercise
An account holds 2500 dollars and earns 4% per year, compounded annually. How many years until it first reaches 4000 dollars? Give the exact value to two decimals and the number of whole years you would actually wait.
Show answer
Solve 2500·1.04^t = 4000, so 1.04^t = 1.6. Then t = ln(1.6) / ln(1.04) = 0.4700 / 0.03922 ≈ 11.98 years. Because interest is credited once per year, the balance first reaches 4000 at the end of year 12.
Exercise
A drug has a half-life of 6 hours in the body. A dose starts at 200 mg. How long until 25 mg remain? Then explain why both logarithms in your calculation are negative but the answer is positive.
Show answer
25/200 = 0.125 = (1/2)^3, so three half-lives pass: t = 18 hours. With logarithms, t = 6 · ln(0.125) / ln(0.5) = 6 · (-2.0794) / (-0.6931) = 18. Both 0.125 and 0.5 are less than 1, so both natural logarithms are negative, and a negative divided by a negative is positive.
Exercise
At 6% per year compounded continuously, how long does it take money to double? Compare with the rule of 70 and with annual compounding at 6%.
Show answer
Continuous: t = ln(2) / 0.06 = 0.6931 / 0.06 ≈ 11.55 years. Rule of 70: 70 / 6 ≈ 11.67 years. Annual compounding: ln(2) / ln(1.06) = 0.6931 / 0.05827 ≈ 11.90 years. Continuous compounding is slightly faster than annual compounding, and the rule of 70 is close to both.