PrimeMath~ PrimeMath

The PrimeMath namespace with static arithmetic and number theory functions Aligns with the Prime Framework by leveraging prime factorization for operations

Methods

(static) add(a, b) → {BigInt}

Add two numbers Uses regular addition for numeric types and coordinates-based addition for UniversalNumbers

Parameters:
NameTypeDescription
anumber | string | BigInt | UniversalNumber

First number

bnumber | string | BigInt | UniversalNumber

Second number

Returns:

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

Parameters:
NameTypeDescription
anumber | string | BigInt | UniversalNumber

First number

bnumber | string | BigInt | UniversalNumber

Second number

Returns:

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

Parameters:
NameTypeDescription
anumber | string | BigInt | UniversalNumber

First number

bnumber | string | BigInt | UniversalNumber

Second number

Returns:

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

Parameters:
NameTypeDescription
anumber | string | BigInt | UniversalNumber

First number

bnumber | string | BigInt | UniversalNumber

Second number

Returns:

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

Parameters:
NameTypeDescription
nnumber | string | BigInt | UniversalNumber

The number

Returns:

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

Parameters:
NameTypeAttributesDescription
gnumber | string | BigInt | UniversalNumber

The base

hnumber | string | BigInt | UniversalNumber

The target value

pnumber | string | BigInt | UniversalNumber

The modulus (should be prime for reliable results)

optionsObject<optional>

Options for the algorithm

Properties
NameTypeAttributesDefaultDescription
verifyboolean<optional>
true

Whether to verify the result

Throws:

If parameters are invalid

Type
PrimeMathError
Returns:

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

Parameters:
NameTypeDescription
anumber | string | BigInt | UniversalNumber

Dividend

bnumber | string | BigInt | UniversalNumber

Divisor

Throws:

If division is not exact or divisor is zero

Type
PrimeMathError
Returns:

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

Parameters:
NameTypeAttributesDescription
nnumber | string | BigInt | UniversalNumber

The number to factorize

optionsObject<optional>

Options for factorization

Properties
NameTypeAttributesDefaultDescription
advancedboolean<optional>
false

Whether to use advanced factorization for large numbers

Returns:

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

Parameters:
NameTypeDescription
anumber | string | BigInt | UniversalNumber

First number

bnumber | string | BigInt | UniversalNumber

Second number

Returns:

Product of a and b

Type: 
BigInt | UniversalNumber

(static) fromFactors(factors) → {BigInt|UniversalNumber}

Create a number from its prime factorization

Parameters:
NameTypeDescription
factorsArray.<{prime: BigInt, exponent: BigInt}> | Map.<BigInt, BigInt>

The prime factorization

Returns:

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

Parameters:
NameTypeDescription
anumber | string | BigInt | UniversalNumber

First number

bnumber | string | BigInt | UniversalNumber

Second number

Returns:

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

Parameters:
NameTypeDescription
nnumber | string | BigInt | UniversalNumber

The number to find divisors for

Throws:

If n is not a positive integer

Type
PrimeMathError
Returns:

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)

Parameters:
NameTypeDescription
nnumber | string | BigInt | UniversalNumber

The number to check

Returns:

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)

Parameters:
NameTypeDescription
nnumber | string | BigInt | UniversalNumber

The number to check

Returns:

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)

Parameters:
NameTypeDescription
nnumber | string | BigInt | UniversalNumber

The number to check

Returns:

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

Parameters:
NameTypeAttributesDescription
nnumber | string | BigInt | UniversalNumber

The number to check

optionsObject<optional>

Options for primality testing

Properties
NameTypeAttributesDefaultDescription
advancedboolean<optional>
true

Use advanced primality testing for large numbers

Returns:

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

Parameters:
NameTypeDescription
anumber | string | BigInt | UniversalNumber

The input number

nnumber | string | BigInt | UniversalNumber

The modulus (must be odd and positive)

Throws:

If n is not a positive odd integer

Type
PrimeMathError
Returns:

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

Parameters:
NameTypeDescription
anumber | string | BigInt | UniversalNumber

First number

bnumber | string | BigInt | UniversalNumber

Second number

Returns:

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

Parameters:
NameTypeDescription
anumber | string | BigInt | UniversalNumber

The input number

pnumber | string | BigInt | UniversalNumber

The prime modulus

Throws:

If p is not a prime number

Type
PrimeMathError
Returns:

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)

Parameters:
NameTypeDescription
anumber | string | BigInt | UniversalNumber

The number to find the inverse for

mnumber | string | BigInt | UniversalNumber

The modulus

Throws:

If the modulus is not positive

Type
PrimeMathError
Returns:

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)

Parameters:
NameTypeDescription
basenumber | string | BigInt | UniversalNumber

The base

exponentnumber | string | BigInt | UniversalNumber

The exponent

modulusnumber | string | BigInt | UniversalNumber

The modulus

Throws:

If modulus is not positive

Type
PrimeMathError
Returns:

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

Parameters:
NameTypeDescription
nnumber | string | BigInt | UniversalNumber

The input number

Throws:

If n is not a positive integer

Type
PrimeMathError
Returns:

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

Parameters:
NameTypeDescription
anumber | string | BigInt | UniversalNumber

First number

bnumber | string | BigInt | UniversalNumber

Second number

Returns:

Product of a and b

Type: 
BigInt | UniversalNumber

(static) nextPrime(n) → {BigInt|UniversalNumber}

Find the next prime number after a given number

Parameters:
NameTypeDescription
nnumber | string | BigInt | UniversalNumber

The starting number

Returns:

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

Parameters:
NameTypeDescription
nnumber | string | BigInt

The index (1-based) of the prime to retrieve

Throws:

If n is not a positive integer

Type
PrimeMathError
Returns:

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

Parameters:
NameTypeDescription
nnumber | string | BigInt | UniversalNumber

The number to optimize

Returns:

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

Parameters:
NameTypeDescription
basenumber | string | BigInt | UniversalNumber

The base

exponentnumber | string | BigInt

The exponent (must be non-negative)

Throws:

If exponent is negative

Type
PrimeMathError
Returns:

base^exponent

Type: 
BigInt | UniversalNumber

(static) primorial(n) → {BigInt|UniversalNumber}

Compute the primorial of n (the product of all primes ≤ n)

Parameters:
NameTypeDescription
nnumber | string | BigInt | UniversalNumber

Upper limit

Returns:

The primorial of n

Type: 
BigInt | UniversalNumber

(static) radical(n) → {BigInt|UniversalNumber}

Calculate the radical of a number (product of distinct prime factors)

Parameters:
NameTypeDescription
nnumber | string | BigInt | UniversalNumber

The number to find the radical for

Throws:

If n is not a positive integer

Type
PrimeMathError
Returns:

The radical of n

Type: 
BigInt | UniversalNumber

(static) subtract(a, b) → {BigInt}

Subtract one number from another

Parameters:
NameTypeDescription
anumber | string | BigInt | UniversalNumber

First number (minuend)

bnumber | string | BigInt | UniversalNumber

Second number (subtrahend)

Returns:

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

Parameters:
NameTypeAttributesDefaultDescription
nnumber | string | BigInt | UniversalNumber

The number to calculate for

knumber | string | BigInt<optional>
1

The power to raise each divisor to

Throws:

If n is not a positive integer

Type
PrimeMathError
Returns:

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

Parameters:
NameTypeDescription
nnumber | string | BigInt | UniversalNumber

The input number

Throws:

If n is not a positive integer

Type
PrimeMathError
Returns:

The value of φ(n)

Type: 
BigInt | UniversalNumber