gives the n
harmonic number
.
HarmonicNumber[n,r]
gives the harmonic number
of order r.
HarmonicNumber[n,r,s]
gives the generalized harmonic number
of order r and decoration value s.
HarmonicNumber
gives the n
harmonic number
.
HarmonicNumber[n,r]
gives the harmonic number
of order r.
HarmonicNumber[n,r,s]
gives the generalized harmonic number
of order r and decoration value s.
Details
- Harmonic numbers
are sums of reciprocals of integers. - Mathematical function, suitable for both symbolic and numerical manipulation.
- For positive integers
, the harmonic numbers are given by
with
. - For arbitrary
and
, the numerical value of
is given by Zeta[r]-HurwitzZeta[r,n+1]. - For positive integers
, the harmonic numbers with decoration value
are given by
. - For arbitrary
and
, the numerical value of
is given by PolyLog[r,s]-sn+1LerchPhi[s,r, n+1]. - HarmonicNumber can be evaluated to arbitrary numerical precision.
- HarmonicNumber automatically threads over lists.
- HarmonicNumber can be used with Interval and CenteredInterval objects. »
Examples
open all close allBasic Examples (7)
Table[HarmonicNumber[n], {n, 10}]Plot over a subset of the integers:
DiscretePlot[HarmonicNumber[t], {t, 0, 100}]Plot over a subset of the complexes:
ComplexPlot3D[HarmonicNumber[z], {z, -1 - I, 1 + I}, PlotLegends -> Automatic]Series expansion at the origin:
Series[HarmonicNumber[x], {x, 0, 3}]Series expansion at Infinity:
Series[HarmonicNumber[x], {x, ∞, 6}]Series expansion at a singular point:
Series[HarmonicNumber[x], {x, -2, 2}, Assumptions -> x > 0]//FullSimplifyCarry out sums involving harmonic numbers:
Sum[n^2 HarmonicNumber[n], {n, m}]Scope (41)
Numerical Evaluation (7)
HarmonicNumber[.8, 3]HarmonicNumber[E, 1.]HarmonicNumber[π, 3 / 2, 0.5]N[HarmonicNumber[1 / 17, 5], 50]The precision of the output tracks the precision of the input:
HarmonicNumber[0.33000000000000000000]N[HarmonicNumber[27, 5 - I]]HarmonicNumber[27, 3 / 2, 0.5 + I]HarmonicNumber threads elementwise over lists and arrays:
HarmonicNumber[{2, 3, 5, 7, 11}]HarmonicNumber[{2, 3, 5, 7, 11}, 0.5]HarmonicNumber[{2, 3, 5, 6}, 1 / 2, 0.3]Evaluate efficiently at high precision:
HarmonicNumber[13 / 7, 5`100]//TimingHarmonicNumber[5 / 7, 5`1000];//TimingCompute worst-case guaranteed intervals using Interval and CenteredInterval objects:
HarmonicNumber[0.2, Interval[{2.1, 2.2}]]HarmonicNumber[1 / 2, CenteredInterval[3 / 4, 1 / 1000]]Or compute average-case statistical intervals using Around:
HarmonicNumber[ 3 / 2, Around[2.1, 0.01]]Compute the elementwise values of an array:
HarmonicNumber[2, {{1 / 2, 2}, {2, 1 / 2}}]Or compute the matrix HarmonicNumber function using MatrixFunction:
MatrixFunction[HarmonicNumber[2, #]&, {{1 / 2, 2}, {2, 1 / 2}}]//FullSimplifyMatrixFunction[HarmonicNumber[3, -1, #]&, {{1 / 2, 2}, {2, 1 / 2}}]//FullSimplifySpecific Values (6)
HarmonicNumber[n,a] for symbolic
:
HarmonicNumber[2.6, a]//FunctionExpandHarmonicNumber[n,r,s] for symbolic
:
HarmonicNumber[2.6, a]//FunctionExpandHarmonicNumber[2, 3 / 2, s]HarmonicNumber[n,a] for symbolic
:
HarmonicNumber[n, -1]HarmonicNumber[n, -1, 1 / 2]//FunctionExpandHarmonicNumber[0]Find a value of
for which HarmonicNumber[n]=1.5:
nval = n /. FindRoot[HarmonicNumber[n] == 1.5, {n, 5}]Plot[HarmonicNumber[n], {n, 0, 5}, Epilog -> Style[Point[{nval, HarmonicNumber[nval]}], PointSize[Large], Red]]Express harmonic numbers of fractional arguments in terms of elementary functions:
HarmonicNumber[3 / 4]//FunctionExpandHarmonicNumber[7 / 13]//FunctionExpandVisualization (4)
Plot the HarmonicNumber function:
Plot[HarmonicNumber[x], {x, 0, 100}]Plot the HarmonicNumber function for various orders:
Plot[{HarmonicNumber[3, x], HarmonicNumber[4, x], HarmonicNumber[5, x]}, {x, -4, 1}, PlotRange -> {0, 100}]Plot the HarmonicNumber function for various decoration values:
ReImPlot[HarmonicNumber[3, 0.3, s], {s, -4, 4}]Plot the real part of HarmonicNumber:
ComplexContourPlot[Re[HarmonicNumber[z]], {z, -3 - 4I, 3 + 4I}, IconizedObject[«PLotOptions»]]Plot the imaginary part of HarmonicNumber:
ComplexContourPlot[Im[HarmonicNumber[z]], {z, -3 - 4I, 3 + 4I}, IconizedObject[«PlotOptions»]]Function Properties (10)
Real domain of HarmonicNumber:
FunctionDomain[HarmonicNumber[x], x]FunctionDomain[HarmonicNumber[x, r], x]FunctionDomain[HarmonicNumber[x, r, s], x]FunctionDomain[HarmonicNumber[z], z, Complexes]FunctionDomain[HarmonicNumber[z, r], z, Complexes]FunctionDomain[HarmonicNumber[z, r, s], z, Complexes]Real range of HarmonicNumber:
FunctionRange[HarmonicNumber[x], x, y]HarmonicNumber is not an analytic function:
FunctionAnalytic[HarmonicNumber[x], x]FunctionMeromorphic[HarmonicNumber[x], x]HarmonicNumber is neither non-increasing nor non-decreasing:
FunctionMonotonicity[HarmonicNumber[x], x]HarmonicNumber is not injective:
FunctionInjective[HarmonicNumber[x], x]Plot[{HarmonicNumber[x], -2}, {x, -3, 2}, PlotRange -> 10]HarmonicNumber is surjective:
FunctionSurjective[HarmonicNumber[x], x]Plot[{HarmonicNumber[x], 2}, {x, -3, 2}, PlotRange -> 10]HarmonicNumber is neither non-negative nor non-positive:
FunctionSign[HarmonicNumber[x], x]HarmonicNumber has both singularities and discontinuities for negative integers:
FunctionSingularities[HarmonicNumber[x], x]FunctionDiscontinuities[HarmonicNumber[x], x]HarmonicNumber is neither convex nor concave:
FunctionConvexity[HarmonicNumber[x], x]TraditionalForm formatting:
HarmonicNumber[n] // TraditionalFormHarmonicNumber[n, k] // TraditionalFormHarmonicNumber[n, r, s]//TraditionalFormDifferentiation (5)
First derivative with respect to
:
D[HarmonicNumber[n], n]Higher derivatives with respect to
:
Table[D[HarmonicNumber[n], {n, k}], {k, 1, 3}]//FullSimplifyPlot the higher derivatives with respect to
:
Plot[%, {n, -3, 3}, Rule[...]]Formula for the ![]()
derivative with respect to
:
D[HarmonicNumber[n], {n, k}]// FullSimplifyD[HarmonicNumber[n, r], n]D[HarmonicNumber[n, r, s], n]The first derivative of a harmonic number of order
with respect to
:
D[HarmonicNumber[n, r], n]The first derivative of a harmonic number of order
with decoration value
with respect to
:
D[HarmonicNumber[n, r, s], n]Integration (4)
Compute the indefinite integral using Integrate:
Integrate[HarmonicNumber[n], n]FullSimplify[D[%, n]]Compute the indefinite integral using Integrate:
Integrate[HarmonicNumber[n, r], n]Integrate[HarmonicNumber[n], {n, 0, 5}]Integrate[HarmonicNumber[n]n^2, n]//FullSimplifyIntegrate[n HarmonicNumber[n^2], {n, 0, 5}]//FullSimplifyIntegrate[n HarmonicNumber[n^2, r], {n, 0, 5}]//FullSimplifyIntegrate[n HarmonicNumber[n^2, 0.2], {n, 0, 5}]//FullSimplifySeries Expansions (3)
Find the Taylor expansion using Series:
Series[HarmonicNumber[n], {n, 0, 5}]Plots of the first three approximations around
:
terms = Normal@Table[Series[HarmonicNumber[n], {n, 0, m}], {m, 1, 5, 2}];
Plot[{HarmonicNumber[n], terms}, {n, 0, 10}, PlotRange -> {-30, 30}]Find the Taylor expansion of generalized harmonic numbers:
Series[HarmonicNumber[n, 1 / 3], {n, 0, 5}]Series[HarmonicNumber[n, 1 / 3, 4 / 3], {n, 0, 2}]General term in the series expansion using SeriesCoefficient:
SeriesCoefficient[HarmonicNumber[x], {x, 1, n}]Function Identities and Simplifications (2)
The defining identities for HarmonicNumber:
Underoverscript[∑, k = 1, n]k^-1 == HarmonicNumber[n]Underoverscript[∑, k = 1, n]k^-r == HarmonicNumber[n, r]Underoverscript[∑, k = 1, n]s^kk^-r == HarmonicNumber[n, r, s]HarmonicNumber[z] == HarmonicNumber[z + 1] - 1 / (z + 1)//FullSimplifyHarmonicNumber[z] == HarmonicNumber[z - 1] + 1 / z//FullSimplifyGeneralizations & Extensions (10)
Harmonic Numbers (2)
Series[HarmonicNumber[n], {n, Infinity, 2}]HarmonicNumber can be applied to power series:
HarmonicNumber[1 + x + (x^2/2) + O[x]^3]Harmonic Numbers of Order r (4)
HarmonicNumber[4, r]HarmonicNumber[z, -4]HarmonicNumber[Infinity, 2]Series expansion at any point:
Series[HarmonicNumber[n, r], {n, n0, 2}]Series[HarmonicNumber[n, r], {n, Infinity, 2}]Connection with the ![]()
harmonic number
:
HarmonicNumber[n, 1] === HarmonicNumber[n]Harmonic Numbers of Order r and Decoration Value s (4)
HarmonicNumber[4, r, s]HarmonicNumber[z, -2, s]//FunctionExpandHarmonicNumber[∞, r, s]Series expansion at any point:
Series[HarmonicNumber[n, r, s], {n, n0, 1}]Series[HarmonicNumber[n, r]//FunctionExpand, {n, ∞, 2}]Connection with the ![]()
harmonic number
and
:
HarmonicNumber[n, 1, 1] === HarmonicNumber[n]HarmonicNumber[n, r, 1] === HarmonicNumber[n, r]Applications (4)
The average number of comparisons in Quicksort:
Plot[2(n + 1)(HarmonicNumber[n + 1] - 1), {n, 1, 1000}]Plot3D[Abs[HarmonicNumber[nx + I ny]], {nx, -10, 10}, {ny, -10, 10}]Book stacking with the maximal overhang:
Graphics[{EdgeForm[Gray], Table[Rectangle[-{HarmonicNumber[k] - 1, k / 10}, -{HarmonicNumber[k], (k + 1) / 10}], {k, 10}]}]Pick the best candidate out of
candidates after
evaluated choices [more info]:
startLookingAfter[n_] := Reduce[HarmonicNumber[x - 1] < HarmonicNumber[n] - 1 < HarmonicNumber[x] &&
1 <= x <= n, x, Integers]startLookingAfter[100]Plot as a function of the size of the candidate pool:
ListPlot[Table[{k, startLookingAfter[k][[2]]}, {k, 2, 20}]]Properties & Relations (12)
HarmonicNumber can be expressed in terms of PolyGamma:
FullSimplify[HarmonicNumber[n] == EulerGamma + PolyGamma[n + 1]]HarmonicNumber can be expressed in terms of Zeta and HurwitzZeta:
FullSimplify[HarmonicNumber[n, r] == Zeta[r] - HurwitzZeta[r, n + 1]]Use FullSimplify to simplify expressions containing harmonic numbers:
FullSimplify[HarmonicNumber[-z - 1] - HarmonicNumber[z]]FullSimplify[HarmonicNumber[z] - PolyGamma[0, z + 1]]FunctionExpand[HarmonicNumber[-5 / 2]]Sum[(-1) ^ n HarmonicNumber[n, 2], {n, m}]Sum[HarmonicNumber[n] / n ^ 2, {n, Infinity}]Generate from sums and integrals:
Sum[1 / k, {k, n}]Integrate[(1 - t ^ z) / (1 - t), {t, 0, 1}, Assumptions -> Re[z] > -1]HarmonicNumber can be represented as a DifferenceRoot:
DifferenceRootReduce[HarmonicNumber[k], k]DifferenceRootReduce[HarmonicNumber[2, k], k]General term in the series expansion of HarmonicNumber:
SeriesCoefficient[HarmonicNumber[x], {x, 0, n}]The ordinary generating function for HarmonicNumber:
GeneratingFunction[HarmonicNumber[n], n, x]Series[%, {x, 0, 9}]//FullSimplifyGeneratingFunction[HarmonicNumber[n, r], n, x]Series[%, {x, 0, 9}]//FullSimplifyThe exponential generating function for HarmonicNumber:
ExponentialGeneratingFunction[HarmonicNumber[n], n, x]HyperHarmonicNumber for
is just the HarmonicNumber:
{HyperHarmonicNumber[1, n], HyperHarmonicNumber[1, n, r], HyperHarmonicNumber[1, n, r, s]}Sum of HarmonicNumber leads to HyperHarmonicNumber of level
:
Sum[HarmonicNumber[k], {k, n}]Sum[HarmonicNumber[k, r], {k, n}]Sum[HarmonicNumber[k, r, s], {k, n}]Possible Issues (3)
Large arguments can give results too large to be computed explicitly:
HarmonicNumber[10. ^ 99, 10 ^ 20]Machine-number inputs can give high‐precision results:
HarmonicNumber[2, -10000.0]MachineNumberQ[%]Results are often expressed in terms of PolyGamma instead of HarmonicNumber:
Limit[Zeta[s, z + 1] - (1/s - 1), s -> 1, Assumptions -> z > -1] - EulerGammaFullSimplify[%]Tech Notes
Related Guides
Related Links
History
Introduced in 1999 (4.0) | Updated in 2026 (15.0)
Text
Wolfram Research (1999), HarmonicNumber, Wolfram Language function, https://reference.wolfram.com/language/ref/HarmonicNumber.html (updated 2026).
CMS
Wolfram Language. 1999. "HarmonicNumber." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2026. https://reference.wolfram.com/language/ref/HarmonicNumber.html.
APA
Wolfram Language. (1999). HarmonicNumber. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/HarmonicNumber.html
BibTeX
@misc{reference.wolfram_2026_harmonicnumber, author="Wolfram Research", title="{HarmonicNumber}", year="2026", howpublished="\url{https://reference.wolfram.com/language/ref/HarmonicNumber.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_harmonicnumber, organization={Wolfram Research}, title={HarmonicNumber}, year={2026}, url={https://reference.wolfram.com/language/ref/HarmonicNumber.html}, note=[Accessed: 12-June-2026]}