Class PrimePiSequence
java.lang.Object
org.episteme.core.mathematics.analysis.series.PrimePiSequence
- All Implemented Interfaces:
Function<Natural,Integer>, Function<Natural, Integer>, Relation<Natural, Integer>, IntegerSequence, Sequence<Integer>
Prime counting function À(n) (OEIS A000720).
À(n) gives the number of primes less than or equal to n. For example:
- À(1) = 0: no primes ≤ 1
- À(2) = 1: {2}
- À(10) = 4: {2, 3, 5, 7}
- À(100) = 25
- À(1000) = 168
Asymptotic Behavior
The Prime Number Theorem states that:
À(n) ~ n / ln(n)More precisely, Legendre's approximation:
À(n) ≈ n / (ln(n) - 1.08366)
Implementation
This implementation uses:
- Sieve of Eratosthenes for small n (invalid input: '<' 10^6)
- Miller-Rabin primality test for large n
- Caching for performance
OEIS Reference
A000720References
- Gauss, C. F. (1849). Letter to Encke
- Hadamard, J. invalid input: '&' de la Vallée Poussin, C. (1896). "Prime Number Theorem"
- Riemann, B. (1859). "On the Number of Primes Less Than a Given Magnitude"
- Since:
- 1.0
- Author:
- Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubleapproximatePi(long n) Approximates À(n) using the Prime Number Theorem.intcountPrimes(long n) Counts the number of primes ≤ n.Returns the n-th term of the sequence (0-indexed).int[]getFirstN(int count) Returns À(n) for the first n values.Returns the OEIS (Online Encyclopedia of Integer Sequences) identifier.getPrimesUpTo(long n) Returns all primes up to n.toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Function
andThen, compose, contains, evaluate, getBackend, isContinuous, isDifferentiable, setBackendMethods inherited from interface IntegerSequence
getLong, getLongMethods inherited from interface Relation
getCodomain
-
Constructor Details
-
PrimePiSequence
public PrimePiSequence()
-
-
Method Details
-
get
-
countPrimes
public int countPrimes(long n) Counts the number of primes ≤ n.- Parameters:
n- the upper bound- Returns:
- À(n)
-
approximatePi
public double approximatePi(long n) Approximates À(n) using the Prime Number Theorem.- Parameters:
n- the value- Returns:
- approximation of À(n)
-
getPrimesUpTo
-
getOEISId
-
getFirstN
public int[] getFirstN(int count) Returns À(n) for the first n values.- Parameters:
count- number of terms- Returns:
- array [À(0), À(1), ..., À(count-1)]
-
toString
-