HarmonicNumber
The harmonic number , exact at a non-negative integer ; with a second argument, the generalized . Continued off the integers by . Provided by @enumeratio/analytic.
✓ checked against that system · ! checked, with disagreements (hover a chip)Fungrim
HarmonicNumber✓Fungrim entry00c02a✓f50c74Wolfram LanguageHarmonicNumber!HarmonicNumber(n)the harmonic number .SageMath
harmonic_number(n)SymPyharmonic(n)mpmathharmonic(n)Juliaenumeratio_ball(x -> digamma(x + 1) + const_euler(RR), n)Rustharmonic(n)HarmonicNumber(n, r)the generalized harmonic number .SageMath
harmonic_number(n, r)SymPyharmonic(n, r)Juliaenumeratio_ball((n, r) -> r == 1 ? digamma(n + 1) + const_euler(RR) : zeta(r) - zeta(r, n + 1), n, r)Rustgeneralized_harmonic(n, r)Typed signatures
| Type | Package | Applies |
|---|---|---|
(number, number?) -> number | analytic | always |
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.
- Order is the one place that generalization can't be used directly: is itself a pole, at every , even though is perfectly finite. HarmonicNumber(z, 1) is routed straight to the one-argument instead.
- 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.
- Differs from Wolfram: reduces to its closed form on evaluation; Wolfram keeps
HarmonicNumber[1/4]untilFunctionExpand. Both agree as identities.
Plot
Examples
25 more kept as data, checked against the oraclesBasic #
Scope #
Order off the integers is plain : — routed to the one-argument form directly rather than through , which is a pole at every
live ↗InOut
Properties #
Possible issues #
About
| Examples | 48 |
|---|---|
| Checked against | Wolfram Language 46 agree2 differSageMath 41 agree3 differ2 unevaluatedSymPy 44 agree2 differ1 unevaluatedmpmath 39 agree1 unevaluated4 errorJulia 38 agree1 unevaluated5 errorRust 12 agree3 differ1 unevaluated20 error |
| Crosswalk | FungrimFungrim entry ×2Wolfram LanguageSageMath ×2SymPy ×2mpmathJulia ×2Rust ×2 |
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/symbols/analysis/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).
mapped
sympypackages/oracle/src/mappings.tsmapped
sympypackages/oracle/src/mappings.tsmapped
mpmathpackages/oracle/src/mappings.tsmapped
mpmathpackages/oracle/src/mappings.tsH(n, r) = ζ(r) − ζ(r, n + 1), the plain harmonic number at r = 1.
mapped
sagepackages/oracle/src/mappings.tsmapped
sagepackages/oracle/src/mappings.tsmapped
juliapackages/oracle/src/mappings.tsmapped
juliapackages/oracle/src/mappings.tsmapped
rustpackages/oracle/src/mappings.tsNon-negative integer orders only.
mapped
rustpackages/oracle/src/mappings.tsA non-negative integer order only.
See also: PolyGamma, EulerGamma, Zeta, HurwitzZeta