Class PrimeSequence

java.lang.Object
org.episteme.core.mathematics.analysis.series.PrimeSequence
All Implemented Interfaces:
Function<Natural,Integer>, Function<Natural,Integer>, Relation<Natural,Integer>, IntegerSequence, Sequence<Integer>

public class PrimeSequence extends Object implements IntegerSequence
Prime number sequence: 2, 3, 5, 7, 11, ...

Uses a segmented sieve for efficient generation of large primes. Supports GPU acceleration for batch generation if a compatible backend is provided.

*

Reference:
Prim, R. C. (1957). Shortest connection networks and some generalizations. Bell System Technical Journal, 36(6), 1389-1401.

Since:
1.0
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
  • Constructor Details

    • PrimeSequence

      public PrimeSequence()
  • Method Details

    • get

      public Integer get(Natural n)
      Description copied from interface: Sequence
      Returns the n-th term of the sequence (0-indexed).

      This is the canonical method using Episteme number types.

      Specified by:
      get in interface Sequence<Integer>
      Parameters:
      n - the index (n ≥ 0)
      Returns:
      a(n)
    • get

      public Integer get(int n)
      Convenience method using primitive int.
      Specified by:
      get in interface Sequence<Integer>
      Parameters:
      n - the index
      Returns:
      the n-th prime
    • setBackend

      public void setBackend(ComputeBackend backend)
      Description copied from interface: Function
      Sets the compute backend for this function (e.g., enable GPU).
      Specified by:
      setBackend in interface Function<Natural,Integer>
      Parameters:
      backend - the compute backend
    • getBackend

      public ComputeBackend getBackend()
      Description copied from interface: Function
      Returns the currently set compute backend.
      Specified by:
      getBackend in interface Function<Natural,Integer>
      Returns:
      the compute backend, or null if none is explicitly set or supported.
    • getOEISId

      public String getOEISId()
      Description copied from interface: Sequence
      Returns the OEIS (Online Encyclopedia of Integer Sequences) identifier. For example, "A000045" for Fibonacci numbers.
      Specified by:
      getOEISId in interface Sequence<Integer>
      Returns:
      OEIS ID or null if not catalogued
    • getName

      public String getName()
      Description copied from interface: Sequence
      Returns a human-readable name for this sequence.
      Specified by:
      getName in interface Sequence<Integer>
      Returns:
      sequence name
    • getFormula

      public String getFormula()
      Description copied from interface: Sequence
      Returns a formula or description of how terms are computed.
      Specified by:
      getFormula in interface Sequence<Integer>
      Returns:
      mathematical formula or description