Repository navigation
The harmonic numbers - #2200
Merged
Merged
The harmonic numbers#2200
Conversation
harmonicnumber(n) and harmonicnumber(n, m) were reserved by name in #2184 and are now Entity.HarmonicNumberf, built by MathS.HarmonicNumber. For a whole n >= 0 they are 1 + 1/2^m + ... + 1/n^m, summed exactly for a rational order: harmonicnumber(4) is 25/12 and harmonicnumber(4, 2) is 205/144. Elsewhere they are zeta(m) - zeta(m, n + 1), as Mathematica's HarmonicNumber is, which is evaluated numerically for a whole m >= 1 through the polygamma function: psi(n + 1) - psi(1) at m = 1, and (-1)^m / (m - 1)! (psi^(m - 1)(1) - psi^(m - 1)(n + 1)) above it. harmonicnumber(1/2) is 2 - 2 ln 2 and agrees with mpmath to 1e-25, as do H(5/2), H(-1/2) and H(1/2, 2). A negative integer n is a pole of the Hurwitz zeta function, and has no value but for a whole order m <= 0, where the harmonic number is a polynomial in n. What is not computed is left as the node. They print as harmonicnumber(n) and harmonicnumber(n, m), draw as \operatorname{H}_{n} and \operatorname{H}_{n}^{(m)}, and export to SymPy's harmonic. Part of #2182. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #2200 +/- ##
==========================================
+ Coverage 86.55% 86.57% +0.02%
==========================================
Files 298 298
Lines 66554 66592 +38
Branches 19308 19319 +11
==========================================
+ Hits 57605 57652 +47
+ Misses 4874 4864 -10
- Partials 4075 4076 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
harmonicnumber(n)andharmonicnumber(n, m)were reserved in #2184 and are now functions. Part of #2182.n>= 01 + 1/2^m + … + 1/n^m, exact for a rationalm:harmonicnumber(4)is25/12ζ(m, n + 1), except for a wholem <= 0ζ(m) − ζ(m, n + 1), as Mathematica'sHarmonicNumberis, evaluated throughpolygammafor a wholem >= 1For
m = 1that isψ(n + 1) − ψ(1), soharmonicnumber(1/2)is2 − 2 ln 2. It agrees with mpmath to 1e-25, and so doH(5/2),H(−1/2)andH(1/2, 2). The tests also checkH(n) − H(n − 1) = 1/nat7/3. LaTeX output is\operatorname{H}_{n}^{(m)}and SymPy output isharmonic."harmonicnumber(4)".ToEntity().Simplify()4 * harmonicnumber25/12"harmonicnumber(n, 2)".ToEntity()UnhandledParseExceptionharmonicnumber(n, 2)🤖 Generated with Claude Code
https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura