Class HarmonicSeries

java.lang.Object
org.episteme.core.mathematics.analysis.series.HarmonicSeries
All Implemented Interfaces:
InfiniteSeries<Real>

public class HarmonicSeries extends Object implements InfiniteSeries<Real>
Harmonic series: Σ 1/n, n=1..∞

The harmonic series is known to diverge, though it grows very slowly. It is useful in many areas of mathematics and computer science.

The partial sum H_n ≈ ln(n) + γ where γ ≈ 0.5772 is the Euler-Mascheroni constant.

Example

HarmonicSeries series = new HarmonicSeries();
Real h10 = series.partialSum(10); // 1 + 1/2 + 1/3 + ... + 1/10
Since:
1.0
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
  • Field Details

    • EULER_MASCHERONI

      public static final Real EULER_MASCHERONI
      Euler-Mascheroni constant γ ≈ 0.5772156649
  • Constructor Details

    • HarmonicSeries

      public HarmonicSeries()
  • Method Details

    • term

      public Real term(int k)
      Description copied from interface: InfiniteSeries
      Returns the k-th term of this series.
      Specified by:
      term in interface InfiniteSeries<Real>
      Parameters:
      k - the term index (k ≥ 0)
      Returns:
      the term a(k)
    • partialSum

      public Real partialSum(int n)
      Description copied from interface: InfiniteSeries
      Computes the partial sum of the first n terms.

      S_n = Σ a(k), k=0..n

      Specified by:
      partialSum in interface InfiniteSeries<Real>
      Parameters:
      n - the number of terms to sum (n ≥ 0)
      Returns:
      the partial sum S_n
    • isConvergent

      public boolean isConvergent()
      Description copied from interface: InfiniteSeries
      Determines if this series is convergent.

      A series converges if lim(n→∞) S_n exists and is finite.

      Specified by:
      isConvergent in interface InfiniteSeries<Real>
      Returns:
      true if convergent, false if divergent
    • limit

      public Real limit()
      Description copied from interface: InfiniteSeries
      Returns the limit of the series if convergent.

      L = lim(n→∞) S_n

      Specified by:
      limit in interface InfiniteSeries<Real>
      Returns:
      the limit L
    • approximateSum

      public Real approximateSum(int n)
      Approximates the n-th harmonic number using the asymptotic formula.

      H_n ≈ ln(n) + γ + 1/(2n) for large n

      Parameters:
      n - the index
      Returns:
      approximate value of H_n
    • increment

      public Real increment(int n)
      Returns the difference between consecutive harmonic numbers.

      H_n - H_{n-1} = 1/n

      Parameters:
      n - the index (n > 0)
      Returns:
      1/n
    • toString

      public String toString()
      Overrides:
      toString in class Object