HarmonicNumber
The harmonic number
HarmonicNumber(n)the harmonic number HarmonicNumber(n, r)the generalized harmonic number Details
- At a non-negative integer
(and an integer of either sign, in the two-argument form) the sum is exact: , , , . - Continued off the lattice by the standard digamma identity
(PolyGamma, EulerGamma) and its generalization (Zeta, HurwitzZeta) — both reduce to the same exact values at the integers, so there is one formula, not a case split. - Negative integer
has no sum and is a pole: , in both the one- and two-argument forms — matching Wolfram, which does not extend the sum by the continuation there. - Complex
and complex/non-integer are supported numerically, via PolyGamma's digamma ( absent) and HurwitzZeta ( present). - A non-integer
(or non-integer with present) stays symbolic under plain evaluation even at an otherwise-exact — the sum has no rational value there — and only reduces under N() or a floating-point argument, the same gate every head in this package uses.
Examples
Implementation
referenceengine
notatioThe one-argument digamma identity; exact at the integers too (ψ(n+1) + γ = Hₙ), so it doubles as the oracle at both.
nativeengine
typescriptpackages/analytic/src/harmonic.tsmappedexternal
wolfram / mpmathpackages/oracle/src/mappings.tsHarmonicNumber[n] / HarmonicNumber[n, r]; mpmath.harmonic(n) (one-argument only — mpmath has no generalized order).
See also: PolyGamma, EulerGamma, Zeta, HurwitzZeta