Sub topic 15
Logarithms in Practice: Decibels, pH, and Algorithm Complexity
Assume you know exponent laws, basic algebra, function notation, and how to use a calculator or basic Python. This chapter applies logarithms to measurements and algorithms rather than developing their laws from the beginning.
Why logarithmic scales are useful
A logarithm compresses a wide range of values. It also measures multiplication as addition. If a quantity changes by a fixed factor, its logarithm changes by a fixed amount.
Decibels measure ratios
The decibel, written dB, compares a measured power \(P\) with a reference power \(P_0\):
\[ L{\mathrm{dB}}=10\log{10}\left(\frac{P}{P_0}\right) \]
The ratio must be dimensionless. A ratio of 1 gives 0 dB. A power ratio of 10 gives 10 dB, and a power ratio of 100 gives 20 dB.
For quantities such as sound pressure or voltage, the corresponding formula is usually
\[ L{\mathrm{dB}}=20\log{10}\left(\frac{A}{A_0}\right) \]
when power is proportional to the square of the amplitude \(A\). This explains why doubling an amplitude adds about 6.02 dB:
\[ 20\log_{10}(2)\approx 6.02 \]
| Power ratio | Decibel change |
|---|---|
| 1 | 0 dB |
| 10 | 10 dB |
| 100 | 20 dB |
A dB value is relative unless a reference is specified. The scale dB SPL, for example, uses a standard reference sound pressure.
pH measures acidity
pH is defined by the hydrogen ion concentration:
\[ \mathrm{pH}=-\log_{10}[\mathrm{H}^+] \]
Here, \([\mathrm{H}^+]\) is measured in moles per liter. The negative sign makes larger pH values represent lower hydrogen ion concentration.
A solution with pH 3 has ten times the hydrogen ion concentration of a solution with pH 4. A difference of two pH units means a factor of \(10^2=100\), not a difference of two ordinary concentration units.
The formula assumes a positive concentration. A concentration of zero cannot be substituted into a logarithm because \(\log(0)\) is undefined.
Logarithms in algorithm complexity
In computer science, \(O(\log n)\) describes an algorithm whose work grows logarithmically with input size \(n\). Binary search is the standard example. Each comparison discards about half of the remaining sorted data.
If there are \(n\) items, the number of halvings needed to reach one item is approximately
\[ \log_2 n \]
For \(n=1{,}000{,}000\), this is about 20 comparisons. Doubling \(n\) adds only one more comparison. This is why logarithmic growth is usually much slower than linear growth \(O(n)\).
import math
power_ratio = 100
decibels = 10 * math.log10(power_ratio)
hydrogen_concentration = 1e-4
ph = -math.log10(hydrogen_concentration)
items = 1_000_000
binary_search_steps = math.ceil(math.log2(items))
print(decibels) # 20.0
print(ph) # 4.0
print(binary_search_steps) # 20Exercise
A signal's power increases by a factor of 1,000. How many decibels does its power level increase?
Show answer
Use 10 log10(1,000) = 10 × 3 = 30 dB.