The PrimeMath namespace with static arithmetic and number theory functions Aligns with the Prime Framework by leveraging prime factorization for operations
- Source
Methods
(static) add(a, b) → {BigInt}
Add two numbers Uses regular addition for numeric types and coordinates-based addition for UniversalNumbers
Name | Type | Description |
---|---|---|
a | number | | First number |
b | number | | Second number |
- Source
Sum of a and b
- Type:
- BigInt
(static) areCoherent(a, b) → {boolean}
Check if two numbers are coherent in the Prime Framework This means they represent the same abstract value despite potentially different representations
Name | Type | Description |
---|---|---|
a | number | | First number |
b | number | | Second number |
- Source
True if the numbers are coherent (represent the same value)
- Type:
- boolean
(static) coherenceDistance(a, b) → {BigInt|UniversalNumber}
Compute the distance between two numbers in the Prime Framework's fiber algebra Based on the coherence inner product and norm
Name | Type | Description |
---|---|---|
a | number | | First number |
b | number | | Second number |
- Source
The distance value
- Type:
- BigInt |
UniversalNumber
(static) coherenceInnerProduct(a, b) → {BigInt|UniversalNumber}
Compute the coherence inner product between two numbers This measures their geometric alignment in the Prime Framework's fiber algebra
Name | Type | Description |
---|---|---|
a | number | | First number |
b | number | | Second number |
- Source
The coherence inner product value
- Type:
- BigInt |
UniversalNumber
(static) coherenceNorm(n) → {BigInt|UniversalNumber}
Compute the coherence norm of a number in the Prime Framework Measures the "magnitude" of the number in its universal representation
Name | Type | Description |
---|---|---|
n | number | | The number |
- Source
The coherence norm value
- Type:
- BigInt |
UniversalNumber
(static) discreteLog(g, h, p, optionsopt) → {BigInt|null}
Calculate the discrete logarithm: find the smallest non-negative integer x such that g^x ≡ h (mod p) Uses Shanks' baby-step giant-step algorithm with efficiency improvements
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
g | number | | The base | |||||||||||
h | number | | The target value | |||||||||||
p | number | | The modulus (should be prime for reliable results) | |||||||||||
options | Object | <optional> | Options for the algorithm Properties
|
- Source
If parameters are invalid
- Type
- PrimeMathError
The discrete logarithm, or null if no solution exists
- Type:
- BigInt |
null
(static) divide(a, b) → {BigInt|UniversalNumber}
Perform exact division of one number by another Only succeeds if the division is exact (no remainder) For factorized numbers, division is performed by subtracting prime exponents
Name | Type | Description |
---|---|---|
a | number | | Dividend |
b | number | | Divisor |
- Source
If division is not exact or divisor is zero
- Type
- PrimeMathError
Result of a / b
- Type:
- BigInt |
UniversalNumber
(static) factorize(n, optionsopt) → {Map.<BigInt, BigInt>}
Factorize a number into its prime factors Provides direct access to the factorization functionality
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
n | number | | The number to factorize | |||||||||||
options | Object | <optional> | Options for factorization Properties
|
- Source
A map where keys are prime factors and values are their exponents
- Type:
- Map.<BigInt, BigInt>
(static) fftMultiply(a, b) → {BigInt|UniversalNumber}
Perform a high-performance FFT-based multiplication of two large numbers Optimized for very large numbers beyond standard multiplication capabilities
Name | Type | Description |
---|---|---|
a | number | | First number |
b | number | | Second number |
- Source
Product of a and b
- Type:
- BigInt |
UniversalNumber
(static) fromFactors(factors) → {BigInt|UniversalNumber}
Create a number from its prime factorization
Name | Type | Description |
---|---|---|
factors | Array.<{prime: BigInt, exponent: BigInt}> | | The prime factorization |
- Source
The number represented by the prime factorization
- Type:
- BigInt |
UniversalNumber
(static) gcd(a, b) → {BigInt|UniversalNumber}
Find the greatest common divisor (GCD) of two numbers For factorized numbers, GCD is computed by taking the minimum of each prime's exponents
Name | Type | Description |
---|---|---|
a | number | | First number |
b | number | | Second number |
- Source
The GCD of a and b
- Type:
- BigInt |
UniversalNumber
(static) getDivisors(n) → {Array.<BigInt>|Array.<UniversalNumber>}
Find all divisors of a number Uses the prime factorization to efficiently generate all divisors
Name | Type | Description |
---|---|---|
n | number | | The number to find divisors for |
- Source
If n is not a positive integer
- Type
- PrimeMathError
Array of all divisors of n
- Type:
- Array.<BigInt> |
Array.<UniversalNumber>
(static) isMersennePrime(n) → {boolean}
Check if a number is a Mersenne prime (a prime of form 2^n - 1)
Name | Type | Description |
---|---|---|
n | number | | The number to check |
- Source
True if n is a Mersenne prime, false otherwise
- Type:
- boolean
(static) isPerfectNumber(n) → {boolean}
Check if a number is a perfect number (equal to the sum of its proper divisors)
Name | Type | Description |
---|---|---|
n | number | | The number to check |
- Source
True if n is a perfect number, false otherwise
- Type:
- boolean
(static) isPerfectPower(n) → {Object|null}
Check if a number is a perfect power (a^b for some integers a, b with b > 1)
Name | Type | Description |
---|---|---|
n | number | | The number to check |
- Source
Object with base and exponent if n is a perfect power, null otherwise
- Type:
- Object |
null
(static) isPrime(n, optionsopt) → {boolean}
Check if a number is prime Uses the Miller-Rabin primality test for larger numbers For UniversalNumber, leverages the intrinsic factorization
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
n | number | | The number to check | |||||||||||
options | Object | <optional> | Options for primality testing Properties
|
- Source
True if n is prime, false otherwise
- Type:
- boolean
(static) jacobiSymbol(a, n) → {number}
Compute the Jacobi symbol (a/n) for any integer a and positive odd integer n This is a generalization of the Legendre symbol to composite moduli
Name | Type | Description |
---|---|---|
a | number | | The input number |
n | number | | The modulus (must be odd and positive) |
- Source
If n is not a positive odd integer
- Type
- PrimeMathError
The Jacobi symbol value: 1, -1, or 0
- Type:
- number
(static) lcm(a, b) → {BigInt|UniversalNumber}
Find the least common multiple (LCM) of two numbers For factorized numbers, LCM is computed by taking the maximum of each prime's exponents
Name | Type | Description |
---|---|---|
a | number | | First number |
b | number | | Second number |
- Source
The LCM of a and b
- Type:
- BigInt |
UniversalNumber
(static) legendreSymbol(a, p) → {number}
Compute the Legendre symbol (a/p) for a number and a prime modulus This determines if a is a quadratic residue modulo p
Name | Type | Description |
---|---|---|
a | number | | The input number |
p | number | | The prime modulus |
- Source
If p is not a prime number
- Type
- PrimeMathError
1 if a is a quadratic residue modulo p, -1 if a is a quadratic non-residue, 0 if a is divisible by p
- Type:
- number
(static) modInverse(a, m) → {BigInt|UniversalNumber|null}
Calculate the modular inverse of a number (a^-1 mod m)
Name | Type | Description |
---|---|---|
a | number | | The number to find the inverse for |
m | number | | The modulus |
- Source
If the modulus is not positive
- Type
- PrimeMathError
The modular inverse, or null if it doesn't exist
- Type:
- BigInt |
UniversalNumber | null
(static) modPow(base, exponent, modulus) → {BigInt|UniversalNumber}
Perform modular exponentiation (a^b mod n)
Name | Type | Description |
---|---|---|
base | number | | The base |
exponent | number | | The exponent |
modulus | number | | The modulus |
- Source
If modulus is not positive
- Type
- PrimeMathError
Result of (base^exponent) mod modulus
- Type:
- BigInt |
UniversalNumber
(static) moebius(n) → {BigInt}
Calculate the Möbius function μ(n) value for a number Uses the prime factorization for efficient calculation
Name | Type | Description |
---|---|---|
n | number | | The input number |
- Source
If n is not a positive integer
- Type
- PrimeMathError
The Möbius function value: 1 if n is square-free with even number of prime factors, -1 if n is square-free with odd number of primes, 0 if n has a squared prime factor
- Type:
- BigInt
(static) multiply(a, b) → {BigInt|UniversalNumber}
Multiply two numbers For factorized numbers, multiplication is performed by combining their prime exponent maps
Name | Type | Description |
---|---|---|
a | number | | First number |
b | number | | Second number |
- Source
Product of a and b
- Type:
- BigInt |
UniversalNumber
(static) nextPrime(n) → {BigInt|UniversalNumber}
Find the next prime number after a given number
Name | Type | Description |
---|---|---|
n | number | | The starting number |
- Source
The next prime number after n
- Type:
- BigInt |
UniversalNumber
(static) nthPrime(n) → {BigInt|UniversalNumber}
Return the nth prime number Provides direct access to number theory sequences in the Prime Framework
Name | Type | Description |
---|---|---|
n | number | | The index (1-based) of the prime to retrieve |
- Source
If n is not a positive integer
- Type
- PrimeMathError
The nth prime number
- Type:
- BigInt |
UniversalNumber
(static) optimizeToCanonicalForm(n) → {BigInt|UniversalNumber}
Optimize a number to its canonical form in the Prime Framework Ensures the number has minimal coherence norm for its value
Name | Type | Description |
---|---|---|
n | number | | The number to optimize |
- Source
The canonical form with minimal norm
- Type:
- BigInt |
UniversalNumber
(static) pow(base, exponent) → {BigInt|UniversalNumber}
Raise a number to a power For factorized numbers, exponentiation is performed by multiplying prime exponents
Name | Type | Description |
---|---|---|
base | number | | The base |
exponent | number | | The exponent (must be non-negative) |
- Source
If exponent is negative
- Type
- PrimeMathError
base^exponent
- Type:
- BigInt |
UniversalNumber
(static) primorial(n) → {BigInt|UniversalNumber}
Compute the primorial of n (the product of all primes ≤ n)
Name | Type | Description |
---|---|---|
n | number | | Upper limit |
- Source
The primorial of n
- Type:
- BigInt |
UniversalNumber
(static) radical(n) → {BigInt|UniversalNumber}
Calculate the radical of a number (product of distinct prime factors)
Name | Type | Description |
---|---|---|
n | number | | The number to find the radical for |
- Source
If n is not a positive integer
- Type
- PrimeMathError
The radical of n
- Type:
- BigInt |
UniversalNumber
(static) subtract(a, b) → {BigInt}
Subtract one number from another
Name | Type | Description |
---|---|---|
a | number | | First number (minuend) |
b | number | | Second number (subtrahend) |
- Source
Difference of a - b
- Type:
- BigInt
(static) sumOfDivisors(n, kopt) → {BigInt|UniversalNumber}
Calculate the sum of divisors function σ(n) Uses the prime factorization for efficient calculation
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
n | number | | The number to calculate for | ||
k | number | | <optional> | 1 | The power to raise each divisor to |
- Source
If n is not a positive integer
- Type
- PrimeMathError
The sum of divisors raised to power k
- Type:
- BigInt |
UniversalNumber
(static) totient(n) → {BigInt|UniversalNumber}
Calculate the Euler's totient function φ(n) - the count of numbers <= n that are coprime to n Uses the prime factorization for efficient calculation
Name | Type | Description |
---|---|---|
n | number | | The input number |
- Source
If n is not a positive integer
- Type
- PrimeMathError
The value of φ(n)
- Type:
- BigInt |
UniversalNumber