Factorization module for the UOR Math-JS library Contains algorithms for converting integers into their prime factorization (universal coordinates) Enhanced with Prime Framework optimizations for performance and efficiency
- Source
Members
(inner, constant) factorizationCache
Prime Framework-specific factorization optimizations and utilities Provides specialized methods for the Prime Framework
- Source
Methods
(inner) ellipticCurveMethod(n, optionsopt) → {BigInt}
Lenstra's Elliptic Curve Method (ECM) for factorization Optimized for finding medium-sized factors of large numbers Enhanced with Prime Framework optimizations for universal coordinates
This implementation uses configurable parameters for number of curves, bounds, and memory limits. All limits can be set either through the options parameter or via the global configuration system in config.factorization.ecm.
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
n | BigInt | The number to factor | |||||||||||||||||||||
options | Object | <optional> | Algorithm options Properties
|
- Source
If input is not a positive composite number
- Type
- PrimeMathError
A non-trivial factor of n, or n if no factor is found
- Type:
- BigInt
(inner) factorArrayToMap(factorArray) → {Map.<BigInt, BigInt>}
Convert array of {prime, exponent} objects to factorization map
Name | Type | Description |
---|---|---|
factorArray | Array.<PrimeFactor> | Array of prime-exponent objects |
- Source
Map of prime factors
- Type:
- Map.<BigInt, BigInt>
(inner) factorMapToArray(factorMap) → {Array.<PrimeFactor>}
Convert factorization map to array of {prime, exponent} objects
Name | Type | Description |
---|---|---|
factorMap | Map.<BigInt, BigInt> | Map of prime factors |
- Source
Array of prime-exponent objects
- Type:
- Array.<PrimeFactor>
(inner) factorize(n) → {Map.<BigInt, BigInt>}
Factorize a number using trial division Implements Algorithm 1 from the specification for prime factorization
Name | Type | Description |
---|---|---|
n | number | | The number to factorize |
- Source
If n is not a positive integer
- Type
- PrimeMathError
A map where keys are prime factors and values are their exponents
- Type:
- Map.<BigInt, BigInt>
(inner) factorizeOptimal(n, optionsopt) → {Map.<BigInt, BigInt>}
Factorize a number using the most appropriate algorithm based on its size and properties Enhanced with Prime Framework optimizations for better performance and precision Implements the Prime Framework's requirements for unique factorization and canonical form Uses configurable thresholds from config.factorization.thresholds to dynamically select the most efficient factorization algorithm based on number characteristics
Name | Type | Attributes | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
n | number | | The number to factorize | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
options | Object | <optional> | Factorization options Properties
|
- Source
If n is not a positive integer
- Type
- PrimeMathError
A map where keys are prime factors and values are their exponents
- Type:
- Map.<BigInt, BigInt>
(inner) factorizeParallel(n, optionsopt) → {Map.<BigInt, BigInt>}
Implements parallel factorization using worker threads when available Falls back to sequential factorization in environments without worker thread support
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
n | number | | The number to factorize | ||||||||||||||||
options | Object | <optional> | Factorization options Properties
|
- Source
If n is not a positive integer
- Type
- PrimeMathError
A map where keys are prime factors and values are their exponents
- Type:
- Map.<BigInt, BigInt>
(inner) factorizePollardsRho(n, optionsopt) → {Map.<BigInt, BigInt>}
Factorize a large number using enhanced Pollard's Rho algorithm Improved with Prime Framework optimizations for performance
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
n | number | | The number to factorize | ||||||||||||||||
options | Object | <optional> | Factorization options Properties
|
- Source
If n is not a positive integer
- Type
- PrimeMathError
A map where keys are prime factors and values are their exponents
- Type:
- Map.<BigInt, BigInt>
(inner) factorizeWithPrimes(n) → {Map.<BigInt, BigInt>}
Factorize a number using optimized trial division with precomputed primes This is more efficient for moderately sized numbers
Name | Type | Description |
---|---|---|
n | number | | The number to factorize |
- Source
If n is not a positive integer
- Type
- PrimeMathError
A map where keys are prime factors and values are their exponents
- Type:
- Map.<BigInt, BigInt>
(inner) findFactorsPollardRho(n, factors, optionsopt) → {Map.<BigInt, BigInt>}
Recursively find factors using enhanced factorization algorithms Optimized with Prime Framework techniques for finding factors Implements a sophisticated approach that selects the most efficient algorithm for each phase of the factorization, following the Prime Framework requirements
Name | Type | Attributes | Description |
---|---|---|---|
n | BigInt | The number to factorize | |
factors | Map.<BigInt, BigInt> | The current factor map | |
options | Object | <optional> | Algorithm options |
- Source
Updated factor map
- Type:
- Map.<BigInt, BigInt>
(inner) fromPrimeFactors(factors, optionsopt) → {BigInt}
Create a number from its prime factorization Implements the Prime Framework's universal coordinate system conversion
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
factors | Array.<PrimeFactor> | | Array of {prime, exponent} objects or Map of prime->exponent | ||||||||||||||||
options | Object | <optional> | Conversion options Properties
|
- Source
If any of the factors is not a prime number or has a non-positive exponent
- Type
- PrimeMathError
The number represented by the given prime factorization
- Type:
- BigInt
(inner) getErrorMessage(error) → {string}
Helper function to safely extract error message Non-recursive implementation to avoid stack overflows
Name | Type | Description |
---|---|---|
error | unknown | Any error value |
- Source
The error message
- Type:
- string
(inner) getPrimeFactors(n) → {Array.<BigInt>}
Get unique prime factors of a number (without exponents)
Name | Type | Description |
---|---|---|
n | number | | The number to get prime factors for |
- Source
Array of prime factors (without repetition)
- Type:
- Array.<BigInt>
(inner) getPrimeSignature(n) → {BigInt}
Find the prime signature of a number (product of (p_i - 1)(p_i^e_i - 1)) Used in various number theory contexts
Name | Type | Description |
---|---|---|
n | number | | The number to find the signature for |
- Source
The prime signature
- Type:
- BigInt
(inner) getRadical(n) → {BigInt}
Find the radical of a number (product of distinct prime factors)
Name | Type | Description |
---|---|---|
n | number | | The number to find the radical for |
- Source
The radical of n
- Type:
- BigInt
(inner) isFactorizationComplete(factors, original) → {boolean}
Check if the factorization of a number is complete
Name | Type | Description |
---|---|---|
factors | Map.<BigInt, BigInt> | The factorization to check |
original | BigInt | The original number |
- Source
True if the factorization is complete, false otherwise
- Type:
- boolean
(inner) millerRabinTest(n, k) → {boolean}
Miller-Rabin primality test for larger numbers
Name | Type | Default | Description |
---|---|---|---|
n | BigInt | The number to test for primality | |
k | number | 25 | Number of iterations for accuracy (higher is more accurate) |
- Source
True if n is probably prime, false if definitely composite
- Type:
- boolean
(inner) modularFastExp(base, exponent, modulus) → {BigInt}
Fast modular exponentiation for Miller-Rabin test
Name | Type | Description |
---|---|---|
base | BigInt | Base value |
exponent | BigInt | Exponent value |
modulus | BigInt | Modulus for the operation |
- Source
Result of (base^exponent) % modulus
- Type:
- BigInt
(inner) pollardRho(n, optionsopt) → {BigInt}
Enhanced Pollard's Rho algorithm with cycle detection Optimized for the Prime Framework's factorization requirements
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
n | BigInt | The number to factor | |||||||||||||||||||||
options | Object | <optional> | Algorithm options Properties
|
- Source
A non-trivial factor of n, or n if no factor is found
- Type:
- BigInt
(inner) quadraticSieve(n, optionsopt) → {BigInt}
Quadratic Sieve implementation for factoring large numbers Implements a complete and efficient factorization algorithm aligned with the Prime Framework
Name | Type | Attributes | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
n | BigInt | The number to factor | ||||||||||||||||||||||||||
options | Object | <optional> | Algorithm options Properties
|
- Source
If input is not a positive composite number
- Type
- PrimeMathError
A non-trivial factor of n, or n if no factor is found
- Type:
- BigInt
Type Definitions
FactorizationResult
- Object
Name | Type | Attributes | Description |
---|---|---|---|
factors | Map.<BigInt, BigInt> | Map of prime factors where key is the prime and value is the exponent | |
isComplete | boolean | Indicates if the factorization is complete (true) or partial (false) | |
confidence | number | <optional> | Confidence level for primality testing (0-1) |
- Source
PrimeFactor
- Object
Name | Type | Description |
---|---|---|
prime | BigInt | The prime number |
exponent | BigInt | The exponent (power) of the prime |
- Source
WorkerConfig
- Object
Name | Type | Attributes | Description |
---|---|---|---|
threadCount | number | <optional> | Number of worker threads to use |
enableWorkStealing | boolean | <optional> | Whether to enable work stealing |
chunkSize | number | <optional> | Size of work chunks for distribution |
- Source