Class NumberTheory
java.lang.Object
org.episteme.core.mathematics.numbertheory.NumberTheory
Number theory algorithms and utilities.
Primality testing, GCD, modular arithmetic, and more.
- Since:
- 1.0
- Author:
- Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic NaturalEuler's totient function Æ(n): count of numbers ≤ n coprime to n.static Integer[]extendedGCD(Integer a, Integer b) Extended Euclidean algorithm: finds x, y such that ax + by = gcd(a, b).static NaturalEuclidean algorithm for GCD.static booleanisAKS(BigInteger n) AKS primality test (simplified implementation).static booleanBaillie-PSW primality test.static booleanisProbablePrime(Natural n, int certainty) Probabilistic primality test using Miller-Rabin.static NaturalLeast common multiple.static booleanmillerRabin(BigInteger n, int k) Miller-Rabin primality test.static NaturalmodInverse(Natural a, Natural m) Modular inverse: finds x such that (a * x) ≡ 1 (mod m).static NaturalModular exponentiation: (base^exp) mod m.
-
Constructor Details
-
NumberTheory
public NumberTheory()
-
-
Method Details
-
millerRabin
Miller-Rabin primality test.Probabilistic test with error probability ≤ 4^(-k).
- Parameters:
n- number to testk- number of rounds (higher = more accurate)- Returns:
- true if probably prime
-
gcd
-
lcm
-
extendedGCD
-
modPow
-
modInverse
-
eulerTotient
-
isProbablePrime
Probabilistic primality test using Miller-Rabin.- Parameters:
n- number to testcertainty- number of rounds (higher = more certain)- Returns:
- true if probably prime
-
isBailliePSW
Baillie-PSW primality test.Combines Miller-Rabin with base 2 and a Lucas probable prime test. No known pseudoprimes exist for this test.
- Parameters:
n- number to test- Returns:
- true if probably prime
-
isAKS
AKS primality test (simplified implementation).Deterministic polynomial-time primality test. Due to complexity, uses simplified checks for small numbers and falls back to Miller-Rabin for larger numbers.
- Parameters:
n- number to test- Returns:
- true if definitely prime
-