Skip to content

The harmonic numbers - #2200

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
the-harmonic-numbers
Oct 29, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
the-harmonic-numbers

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

harmonicnumber(n) and harmonicnumber(n, m) were reserved in #2184 and are now functions. Part of #2182.

n value
whole, >= 0 1 + 1/2^m + … + 1/n^m, exact for a rational m: harmonicnumber(4) is 25/12
a negative integer no value, at a pole of ζ(m, n + 1), except for a whole m <= 0
any other ζ(m) − ζ(m, n + 1), as Mathematica's HarmonicNumber is, evaluated through polygamma for a whole m >= 1

For m = 1 that is ψ(n + 1) − ψ(1), so harmonicnumber(1/2) is 2 − 2 ln 2. It agrees with mpmath to 1e-25, and so do H(5/2), H(−1/2) and H(1/2, 2). The tests also check H(n) − H(n − 1) = 1/n at 7/3. LaTeX output is \operatorname{H}_{n}^{(m)} and SymPy output is harmonic.

Input Was (2.6.0) Now
"harmonicnumber(4)".ToEntity().Simplify() 4 * harmonicnumber 25/12
"harmonicnumber(n, 2)".ToEntity() throws UnhandledParseException harmonicnumber(n, 2)

🤖 Generated with Claude Code

https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura

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

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.41100% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.57%. Comparing base (533ee4f) to head (767737f).

Files with missing lines Patch % Lines
...nuous/Evaluation.Continuous.Arithmetics.Classes.cs 80.00% 2 Missing and 2 partials ⚠️
.../Continuous/Entity.Continuous.Factorial.Classes.cs 66.66% 2 Missing ⚠️
...nuous/Solvers/EquationSolver/InvertNode.Classes.cs 0.00% 1 Missing ⚠️
...AngouriMath/Functions/TreeAnalyzer/Sort.Classes.cs 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            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     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.13% <97.41%> (+0.02%) ⬆️
fsharp 32.97% <ø> (ø)
interactive 40.72% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
Sources/AngouriMath/Convenience/MathS.cs 90.37% <100.00%> (+0.06%) ⬆️
Sources/AngouriMath/Core/Antlr/AngouriMathLexer.cs 99.21% <100.00%> (-0.01%) ⬇️
...ources/AngouriMath/Core/Antlr/AngouriMathParser.cs 87.75% <100.00%> (+0.02%) ⬆️
Sources/AngouriMath/Core/Domains.Classes.cs 100.00% <100.00%> (ø)
...Math/Core/Transformations/Matching/MatchPattern.cs 86.33% <100.00%> (+0.02%) ⬆️
...unctions/Output/Latex/Latex.Arithmetics.Classes.cs 97.69% <100.00%> (+0.01%) ⬆️
...ns/Output/ToString/ToString.Arithmetics.Classes.cs 100.00% <100.00%> (ø)
...ions/Output/ToSympy/ToSympy.Arithmetics.Classes.cs 76.56% <100.00%> (+0.37%) ⬆️
Sources/AngouriMath/Functions/Substitute.cs 84.40% <100.00%> (+0.08%) ⬆️
...nuous/Solvers/EquationSolver/InvertNode.Classes.cs 60.23% <0.00%> (-0.24%) ⬇️
... and 3 more

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Rafael-SOWNet
Rafael-SOWNet merged commit 282157a into master Oct 29, 2026
36 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in AngouriMath Oct 29, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the the-harmonic-numbers branch October 29, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant