Understanding the harmonic number calculator — concept and principle
This calculator finds the harmonic number Hₙ = 1 + 1/2 + 1/3 + … + 1/n, as an exact fraction for small n, together with the approximation ln n + γ + 1/(2n), the gap Hₙ − ln n and the average term. It also finds the smallest n for which Hₙ reaches a target. Use it in calculus (the harmonic series), algorithm analysis and probability puzzles such as the coupon collector.
How it is calculated
Hₙ = Σ_(k=1)^n 1/k
Approximation: Hₙ ≈ ln n + γ + 1/(2n) − 1/(12n²) + …, with γ ≈ 0.5772156649
- Terms are added exactly for n ≤ 1,000; the asymptotic series is used beyond, so n can be as large as 10¹⁵.
- The exact fraction is shown for n ≤ 20.
The principle
Each term 1/k is the area of a strip of width 1 and height 1/k, and these strips sit just above the curve y = 1/x. The area under that curve from 1 to n is ln n, so Hₙ grows like ln n, slowly but without limit: the harmonic series diverges. The leftover pieces between the strips and the curve add up to a fixed amount, the Euler–Mascheroni constant γ, which is why Hₙ − ln n approaches 0.5772.
Worked example
Default inputs: n = 10, target 5.
- H₁₀ = 1 + 1/2 + … + 1/10 = 7381/2520 = 2.928968254.
- Approximation: ln 10 + 0.5772157 + 1/20 = 2.302585 + 0.577216 + 0.05 = 2.929800758.
- H₁₀ − ln 10 = 0.626383161, on its way down toward γ.
- Average of the terms = 2.928968254 ÷ 10 = 0.2928968254.
- Smallest n with Hₙ ≥ 5 = 83.
How to read the result
Growth is extremely slow: it takes 83 terms to pass 5 and about 12,367 to pass 10. In the coupon-collector problem, collecting all n different coupons takes on average n·Hₙ draws; for 10 coupons that is about 29.3 draws.
Common mistakes
- Assuming the harmonic series converges because its terms go to zero.
- Using ln n alone, which is off by about 0.58.
- Confusing Hₙ with the harmonic mean.
- Expecting Hₙ to be a whole number; for n > 1 it never is.
Frequently asked questions
Does the harmonic series converge?
No, it grows without bound, roughly like ln n.
What is H₁₀?
7381/2520 ≈ 2.929.
What is the Euler–Mascheroni constant?
The limit of Hₙ − ln n, about 0.5772.
Sources: E. W. Weisstein, "Harmonic Number", Wolfram MathWorld