{
  "id": "harmonic-number",
  "title": "Harmonic Number",
  "lang": "en",
  "source_lang": "en",
  "summary": "A harmonic number is a finite sum of reciprocals of consecutive positive integers, forming a sequence that grows logarithmically and appears throughout analysis, number theory, and probability.",
  "category": "mathematics",
  "subcategory": "analysis",
  "type": "concept",
  "aliases": [
    "Ordinary harmonic number"
  ],
  "generated_at": "2026-11-05",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/harmonic-number/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/harmonic-number/",
      "json": "https://aiwiki.page/zh/harmonic-number.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "A harmonic number is a sum of the reciprocals of the first several positive integers. For a positive integer \\(n\\), the \\(n\\)th harmonic number is\n\n\\[H_n=\\sum_{k=1}^{n}\\frac{1}{k} =1+\\frac12+\\frac13+\\cdots+\\frac1n.\\]\n\nThe convention \\(H_0=0\\) is also standard. Harmonic numbers are the partial sums of the harmonic series. Although they grow without bound, their growth is slow: \\(H_n\\) is approximately \\(\\ln n+\\gamma\\), where \\(\\gamma\\) is the Euler–Mascheroni constant. They occur in analysis, number theory, combinatorics, and the analysis of random processes and algorithms."
    },
    {
      "heading": "Definition and elementary properties",
      "text": "The first few values are\n\n\\[H_0=0,\\qquad H_1=1,\\qquad H_2=\\frac32,\\qquad H_3=\\frac{11}{6},\\qquad H_4=\\frac{25}{12},\\qquad H_5=\\frac{137}{60}.\\]\n\nThe defining sum gives the recurrence relation\n\n\\[H_n=H_{n-1}+\\frac1n,\\qquad n\\geq1.\\]\n\nConsequently, the sequence is strictly increasing, but its successive increments decrease to zero.\n\nEvery harmonic number is a rational number. Nevertheless, \\(H_n\\) is not an integer for any \\(n>1\\). To see this, let \\(2^r\\) be the largest power of \\(2\\) not exceeding \\(n\\), and let \\(L\\) be the least common multiple of \\(1,\\ldots,n\\). In the numerator\n\n\\[LH_n=\\sum_{k=1}^{n}\\frac{L}{k},\\]\n\nthe term \\(L/2^r\\) is odd, while every other term is even: \\(2^r\\) is the only integer at most \\(n\\) divisible by \\(2^r\\). Thus \\(LH_n\\) is odd, whereas \\(L\\) is even, so \\(H_n\\) cannot be an integer."
    },
    {
      "heading": "Growth and divergence",
      "text": "Comparison with the integral of \\(1/x\\) gives\n\n\\[\\ln(n+1)\\leq H_n\\leq1+\\ln n \\qquad(n\\geq1),\\]\n\nwhere \\(\\ln\\) denotes the natural logarithm. These inequalities show both that \\(H_n\\) tends to infinity and that\n\n\\[\\lim_{n\\to\\infty}\\frac{H_n}{\\ln n}=1.\\]\n\nAn elementary proof of divergence groups terms between successive powers of two:\n\n\\[H_{2^m} = 1+\\sum_{j=1}^{m} \\sum_{k=2^{j-1}+1}^{2^j}\\frac1k.\\]\n\nEach inner sum contains \\(2^{j-1}\\) terms, all at least \\(1/2^j\\), so\n\n\\[H_{2^m}\\geq1+\\frac m2.\\]\n\nThe lower bound increases without limit. This also illustrates why terms tending to zero do not, by themselves, guarantee convergence of an infinite series.\n\nEuler–Mascheroni constant\n\nThe difference between \\(H_n\\) and \\(\\ln n\\) approaches the Euler–Mascheroni constant:\n\n\\[\\gamma=\\lim_{n\\to\\infty}(H_n-\\ln n) =0.5772156649\\ldots.\\]\n\nIts rationality or irrationality remains unknown.\n\nA more precise asymptotic expansion is\n\n\\[H_n = \\ln n+\\gamma+\\frac{1}{2n} -\\frac{1}{12n^2} +\\frac{1}{120n^4} -\\frac{1}{252n^6} +O(n^{-8}).\\]\n\nHere the remainder is expressed using big-O notation. The expansion follows from the Euler–Maclaurin formula. It is an asymptotic expansion rather than a convergent infinite series: truncating it at a fixed order gives an approximation whose accuracy improves as \\(n\\) increases.\n\nUseful explicit bounds are\n\n\\[\\frac{1}{2(n+1)} < H_n-\\ln n-\\gamma < \\frac{1}{2n}, \\qquad n\\geq1.\\]"
    },
    {
      "heading": "Identities and representations",
      "text": "Finite sums\n\nReversing the order in a finite double sum yields\n\n\\[\\sum_{k=1}^{n}H_k=(n+1)H_n-n.\\]\n\nIndeed, the term \\(1/j\\) occurs in \\(H_j,H_{j+1},\\ldots,H_n\\), so its total contribution is \\((n-j+1)/j\\).\n\nA related identity is\n\n\\[\\sum_{k=1}^{n}\\frac{H_k}{k} = \\frac12\\left(H_n^2+H_n^{(2)}\\right), \\qquad H_n^{(2)}=\\sum_{k=1}^{n}\\frac1{k^2}.\\]\n\nIt follows by separating the diagonal terms from the off-diagonal terms in the square of \\(H_n\\).\n\nHarmonic numbers also have the alternating binomial representation\n\n\\[H_n= \\sum_{k=1}^{n} (-1)^{k+1}\\binom nk\\frac1k,\\]\n\nwhere \\(\\binom nk\\) is a binomial coefficient.\n\nIntegral representation\n\nThe finite geometric series gives\n\n\\[H_n = \\int_0^1\\frac{1-x^n}{1-x}\\,dx.\\]\n\nFor integer \\(n\\), the apparent singularity at \\(x=1\\) is removable because\n\n\\[\\frac{1-x^n}{1-x}=1+x+\\cdots+x^{n-1}.\\]\n\nIntegrating each term produces \\(1+1/2+\\cdots+1/n\\).\n\nGenerating function\n\nThe ordinary generating function is\n\n\\[\\sum_{n=0}^{\\infty}H_nx^n = -\\frac{\\ln(1-x)}{1-x}, \\qquad |x|<1.\\]\n\nFor example, it follows by interchanging two absolutely convergent sums:\n\n\\[\\sum_{n=1}^{\\infty}\\sum_{k=1}^{n}\\frac{x^n}{k} = \\frac{1}{1-x}\\sum_{k=1}^{\\infty}\\frac{x^k}{k}.\\]\n\nGenerating functions turn many identities involving harmonic numbers into algebraic operations on power series."
    },
    {
      "heading": "Generalized harmonic numbers",
      "text": "The generalized harmonic number of order \\(s\\) is\n\n\\[H_n^{(s)}=\\sum_{k=1}^{n}\\frac1{k^s}.\\]\n\nFor complex \\(s\\), the convention is \\(k^{-s}=\\exp(-s\\ln k)\\). Ordinary harmonic numbers are the case \\(s=1\\).\n\nFor real \\(s>1\\), these sums converge as \\(n\\) increases:\n\n\\[\\lim_{n\\to\\infty}H_n^{(s)}=\\zeta(s),\\]\n\nwhere \\(\\zeta\\) is the Riemann zeta function. In particular,\n\n\\[\\lim_{n\\to\\infty}H_n^{(2)}=\\frac{\\pi^2}{6}.\\]\n\nMore generally, convergence holds for complex \\(s\\) with \\(\\operatorname{Re}(s)>1\\). For real \\(s\\leq1\\), the sums diverge to positive infinity.\n\nWhen \\(s=0\\), \\(H_n^{(0)}=n\\). Negative integer orders give sums of positive integer powers, such as\n\n\\[H_n^{(-1)}=\\sum_{k=1}^{n}k=\\frac{n(n+1)}2.\\]\n\nExtension beyond integer indices\n\nThe digamma function \\(\\psi\\), the logarithmic derivative of the gamma function, satisfies\n\n\\[H_n=\\psi(n+1)+\\gamma.\\]\n\nThis motivates the standard extension\n\n\\[H_z=\\psi(z+1)+\\gamma.\\]\n\nIt defines a meromorphic function of a complex variable, with poles at the negative integers, and preserves the recurrence\n\n\\[H_z-H_{z-1}=\\frac1z\\]\n\nwhere both sides are defined. Agreement at nonnegative integers alone does not uniquely determine an extension; the digamma formula specifies the conventional one."
    },
    {
      "heading": "Applications in probability and algorithms",
      "text": "Harmonic numbers frequently arise when a process has successive stages with reciprocal waiting times or success probabilities.\n\nCoupon collection\n\nIn the coupon collector problem, independent draws each produce one of \\(n\\) equally likely coupon types. After \\(k\\) distinct types have appeared, the probability that the next draw gives a new type is \\((n-k)/n\\). The expected number of draws needed to obtain that next new type is therefore \\(n/(n-k)\\).\n\nAdding the stage expectations gives\n\n\\[\\mathbb E[T] = \\sum_{k=0}^{n-1}\\frac{n}{n-k} =nH_n.\\]\n\nThus the expected waiting time to collect every type grows like \\(n\\ln n\\).\n\nRecords in random sequences\n\nSuppose \\(X_1,\\ldots,X_n\\) are independent observations from the same continuous probability distribution. The \\(k\\)th observation is a record high if it exceeds all its predecessors. By symmetry, each of the first \\(k\\) observations is equally likely to be their maximum, so the probability that \\(X_k\\) is a record is \\(1/k\\). Linearity of expectation then gives\n\n\\[\\mathbb E[\\text{number of record highs}]=H_n.\\]\n\nQuicksort\n\nFor randomized quicksort on \\(n\\) distinct keys, with each pivot chosen uniformly from its current subarray and partitioning using one pivot comparison for each other key, the expected comparison count is\n\n\\[\\mathbb E[C_n]=2(n+1)H_n-4n.\\]\n\nThe logarithmic growth of \\(H_n\\) therefore yields a leading term of \\(2n\\ln n\\). This is an average over random pivot choices, not a bound on every execution; highly unbalanced partitions can require a quadratic number of comparisons."
    },
    {
      "heading": "Numerical computation",
      "text": "Direct evaluation requires \\(n\\) reciprocal calculations and additions. For large \\(n\\), the asymptotic expansion is usually more efficient when an approximation rather than an exact fraction is needed.\n\nIn floating-point arithmetic, adding increasingly small terms to a growing total can lose low-order information. Summing from smaller terms toward larger ones, or using compensated summation, reduces this accumulation of rounding error. Exact rational computation avoids rounding but can require large integer numerators and denominators."
    }
  ],
  "links": [
    "integer",
    "harmonic-series",
    "mathematical-analysis",
    "number-theory",
    "combinatorics",
    "recurrence-relation",
    "rational-number",
    "integral",
    "natural-logarithm",
    "infinite-series",
    "euler-mascheroni-constant",
    "asymptotic-expansion",
    "big-o-notation",
    "binomial-coefficient",
    "geometric-series",
    "generating-function",
    "power-series",
    "riemann-zeta-function",
    "digamma-function",
    "gamma-function",
    "expected-value",
    "probability-distribution",
    "quicksort",
    "floating-point-arithmetic"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}