Constructor
new UniversalNumber(value)
Create a new UniversalNumber
Name | Type | Description |
---|---|---|
value | number | | The value to initialize with |
- Source
If value cannot be converted to a valid UniversalNumber
- Type
- PrimeMathError
Methods
abs() → {UniversalNumber}
Get the absolute value of this UniversalNumber
- Source
A new UniversalNumber with the same magnitude but positive sign
- Type:
- UniversalNumber
add(other) → {UniversalNumber}
Add another number to this UniversalNumber
Name | Type | Description |
---|---|---|
other | number | | The number to add |
- Source
A new UniversalNumber representing the sum
- Type:
- UniversalNumber
coherenceDistance(other) → {UniversalNumber}
Calculate the coherence distance between this UniversalNumber and another The coherence distance measures how "far apart" two numbers are in the fiber algebra
Name | Type | Description |
---|---|---|
other | UniversalNumber | The other UniversalNumber |
- Source
The coherence distance
- Type:
- UniversalNumber
coherenceNorm() → {UniversalNumber}
Calculate the coherence norm of a UniversalNumber The coherence norm measures how consistent a number's representation is A minimal-norm representation is the canonical form in the Prime Framework
- Source
The coherence norm value
- Type:
- UniversalNumber
compareTo(other) → {number}
Compare this UniversalNumber with another number
Name | Type | Description |
---|---|---|
other | number | | The number to compare with |
- Source
-1 if this < other, 0 if this === other, 1 if this > other
- Type:
- number
divide(other) → {UniversalNumber}
Divide this UniversalNumber by another number Only succeeds if the division is exact (no remainder) For factorized numbers, division is performed by subtracting prime exponents
Name | Type | Description |
---|---|---|
other | number | | The divisor |
- Source
If the division is not exact or divisor is zero
- Type
- PrimeMathError
A new UniversalNumber representing the quotient
- Type:
- UniversalNumber
equals(other) → {boolean}
Compare this UniversalNumber with another number for equality
Name | Type | Description |
---|---|---|
other | number | | The number to compare with |
- Source
True if the numbers are equal, false otherwise
- Type:
- boolean
formatNumber(optionsopt) → {string}
Format the number as a string with configurable formatting options Particularly useful for very large numbers that exceed JavaScript Number limits
Name | Type | Attributes | Description | |||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | Object | <optional> | Formatting options Properties
|
- Source
The formatted string representation
- Type:
- string
gcd(other) → {UniversalNumber}
Find the greatest common divisor (GCD) of this UniversalNumber and another number For factorized numbers, GCD is computed by taking the minimum of each prime's exponents
Name | Type | Description |
---|---|---|
other | number | | The other number |
- Source
If both inputs are zero
- Type
- PrimeMathError
A new UniversalNumber representing the GCD
- Type:
- UniversalNumber
getCoordinates() → {Coordinates}
Get the universal coordinates (prime factorization and sign)
- Source
Object containing the factorization and sign information
- Type:
- Coordinates
getDigits(baseopt, leastSignificantFirstopt) → {Array.<number>}
Get the digit representation of the number in a specific base
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
base | number | <optional> | 10 | The base to use (2-36) |
leastSignificantFirst | boolean | <optional> | false | Order of digits |
- Source
If the base is invalid
- Type
- PrimeMathError
Array of digits in the specified base
- Type:
- Array.<number>
getFactorization() → {Map.<BigInt, BigInt>}
Get the prime factorization of the UniversalNumber
- Source
A Map where keys are prime factors and values are their exponents
- Type:
- Map.<BigInt, BigInt>
getGradedComponents(options) → {Map.<number, Array.<number>>}
Get this number's graded components in the fiber algebra (Clifford algebra) The graded components represent the number's digit expansions in various bases
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | Object | Options for retrieving graded components Properties
|
- Source
Map of base to array of digits
- Type:
- Map.<number, Array.<number>>
getNumberParts(optionsopt) → {Object}
Get parts of the number for custom display formatting Useful for handling very large numbers that exceed JavaScript Number limits
Name | Type | Attributes | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | Object | <optional> | Options for extracting parts Properties
|
- Source
Object containing number parts (sign, integerPart, fractionalPart, etc.)
- Type:
- Object
isDivisibleBy(other) → {boolean}
Check if this number is divisible by another
Name | Type | Description |
---|---|---|
other | number | | The potential divisor |
- Source
If divisor is zero
- Type
- PrimeMathError
True if this number is divisible by other, false otherwise
- Type:
- boolean
isIntrinsicPrime() → {boolean}
Check if the UniversalNumber represents an intrinsic prime A number is intrinsically prime if its prime factorization consists of a single prime with exponent 1
- Source
True if the number is an intrinsic prime, false otherwise
- Type:
- boolean
isMinimalNorm() → {boolean}
Check if this UniversalNumber is in minimal-norm canonical form In the Prime Framework, the minimal-norm representation is the unique canonical form
- Source
True if the number is in minimal-norm form
- Type:
- boolean
isOne() → {boolean}
Check if this UniversalNumber is 1
- Source
True if this number is 1, false otherwise
- Type:
- boolean
isZero() → {boolean}
Check if this UniversalNumber is 0
- Source
True if this number is 0, false otherwise
- Type:
- boolean
lcm(other) → {UniversalNumber}
Find the least common multiple (LCM) of this UniversalNumber and another number For factorized numbers, LCM is computed by taking the maximum of each prime's exponents
Name | Type | Description |
---|---|---|
other | number | | The other number |
- Source
If either input is zero
- Type
- PrimeMathError
A new UniversalNumber representing the LCM
- Type:
- UniversalNumber
mod(modulus) → {UniversalNumber}
Compute the modulo (remainder after division)
Name | Type | Description |
---|---|---|
modulus | number | | The modulus |
- Source
If modulus is not positive
- Type
- PrimeMathError
This value modulo the given modulus
- Type:
- UniversalNumber
modInverse(modulus) → {UniversalNumber|null}
Calculate the modular inverse (a^-1 mod m) if it exists
Name | Type | Description |
---|---|---|
modulus | number | | The modulus |
- Source
If modulus is not positive
- Type
- PrimeMathError
The modular inverse, or null if it doesn't exist
- Type:
- UniversalNumber |
null
modPow(expValue, modulus) → {UniversalNumber}
Compute modular exponentiation (a^b mod n)
Name | Type | Description |
---|---|---|
expValue | number | | The exponent |
modulus | number | | The modulus |
- Source
If modulus is not positive
- Type
- PrimeMathError
Result of (this^expValue) mod modulus
- Type:
- UniversalNumber
modSqrt(modulus) → {UniversalNumber|null}
Calculate modular square root if it exists Finds x such that x^2 ≡ this (mod n)
Name | Type | Description |
---|---|---|
modulus | UniversalNumber | | The modulus |
- Source
The modular square root if it exists, null otherwise
- Type:
- UniversalNumber |
null
multiply(other) → {UniversalNumber}
Multiply this UniversalNumber by another number For factorized numbers, multiplication is performed by combining prime exponents
Name | Type | Description |
---|---|---|
other | number | | The number to multiply by |
- Source
A new UniversalNumber representing the product
- Type:
- UniversalNumber
negate() → {UniversalNumber}
Negate this UniversalNumber
- Source
A new UniversalNumber with the same magnitude but opposite sign
- Type:
- UniversalNumber
pow(exponent) → {UniversalNumber}
Raise this UniversalNumber to a power For factorized numbers, exponentiation is performed by multiplying prime exponents
Name | Type | Description |
---|---|---|
exponent | number | | The exponent |
- Source
If exponent is negative
- Type
- PrimeMathError
A new UniversalNumber representing the result of the exponentiation
- Type:
- UniversalNumber
radical() → {UniversalNumber}
Calculate the radical of the number (product of distinct prime factors)
- Source
A new UniversalNumber with all exponents set to 1
- Type:
- UniversalNumber
sign() → {number}
Get the sign of this UniversalNumber
- Source
-1 if negative, 1 if positive
- Type:
- number
subtract(other) → {UniversalNumber}
Subtract another number from this UniversalNumber
Name | Type | Description |
---|---|---|
other | number | | The number to subtract |
- Source
A new UniversalNumber representing the difference
- Type:
- UniversalNumber
toApproximateNumber(optionsopt) → {number}
Get an approximate JavaScript Number representation with scientific notation This is useful for very large numbers that exceed Number.MAX_SAFE_INTEGER
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | Object | <optional> | Options for the approximation Properties
|
- Source
If the exponent is too large even for scientific notation and throwOnOverflow is true
- Type
- PrimeMathError
The approximate Number in scientific notation
- Type:
- number
toBigInt() → {BigInt}
Convert the UniversalNumber to a BigInt
- Source
The BigInt representation of the number
- Type:
- BigInt
toCompact() → {Object}
Create a compacted representation of this UniversalNumber Memory-optimized representation for very large numbers
- Source
Compact serializable representation
- Type:
- Object
toJSON() → {Object}
Convert the UniversalNumber to a serializable object For use with JSON.stringify
- Source
Object with type, factors, and sign information
- Type:
- Object
toNumber(optionsopt) → {number}
Convert the UniversalNumber to a JavaScript Number
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | Object | <optional> | Conversion options Properties
|
- Source
If the value is too large to be represented as a Number (unless suppressErrors is true)
- Type
- PrimeMathError
The Number representation of the number
- Type:
- number
toString(baseopt) → {string}
Convert the UniversalNumber to a string representation in the given base
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
base | number | <optional> | 10 | The base for the output representation (2-36) |
- Source
If the base is invalid
- Type
- PrimeMathError
The string representation in the specified base
- Type:
- string
transformToFrame(targetFrame) → {UniversalNumber}
Transform this UniversalNumber to a different reference frame Implements symmetry group action (G-action) on the reference manifold
Name | Type | Description |
---|---|---|
targetFrame | string | The reference frame to transform to |
- Source
If the target frame doesn't exist
- Type
- PrimeMathError
The number transformed to the new reference frame
- Type:
- UniversalNumber
valueOf() → {BigInt}
Convert the UniversalNumber to a native JavaScript primitive Used for automatic conversion in expressions
- Source
The BigInt representation of the number
- Type:
- BigInt
(static) factorize(n, optionsopt) → {UniversalNumber}
Factorize a number into its UniversalNumber representation with prime factorization
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
n | number | | The number to factorize | |||||||||||
options | Object | <optional> | Options for factorization Properties
|
- Source
A new UniversalNumber instance
- Type:
- UniversalNumber
(static) fastMultiply(a, b) → {UniversalNumber}
Perform fast multiplication when operands have many small prime factors Optimized for the Prime Framework's universal coordinates
Name | Type | Description |
---|---|---|
a | UniversalNumber | First number |
b | UniversalNumber | Second number |
- Source
Product a × b
- Type:
- UniversalNumber
(static) fromBigInt(n) → {UniversalNumber}
Create a UniversalNumber from a BigInt
Name | Type | Description |
---|---|---|
n | BigInt | The BigInt to convert |
- Source
A new UniversalNumber instance
- Type:
- UniversalNumber
(static) fromCompact(compact) → {UniversalNumber}
Create a UniversalNumber from a compact representation
Name | Type | Description |
---|---|---|
compact | Object | Compact representation created by toCompact() |
- Source
The reconstructed UniversalNumber
- Type:
- UniversalNumber
(static) fromFactors(factors, isNegativeopt) → {UniversalNumber}
Create a UniversalNumber from its prime factorization
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
factors | Array.<{prime: (BigInt|number|string), exponent: (BigInt|number|string)}> | | Prime factorization | ||
isNegative | boolean | <optional> | false | Whether the number is negative |
- Source
If the factorization is invalid
- Type
- PrimeMathError
A new UniversalNumber instance
- Type:
- UniversalNumber
(static) fromJSON(json) → {UniversalNumber}
Create a UniversalNumber from a JSON representation
Name | Type | Description |
---|---|---|
json | Object | The JSON object |
- Source
If the JSON is invalid
- Type
- PrimeMathError
A new UniversalNumber
- Type:
- UniversalNumber
(static) fromNumber(n) → {UniversalNumber}
Create a UniversalNumber from a regular number
Name | Type | Description |
---|---|---|
n | number | The JavaScript Number to convert |
- Source
If n is not a safe integer or is not finite
- Type
- PrimeMathError
A new UniversalNumber instance
- Type:
- UniversalNumber
(static) fromPartialFactorization(params) → {UniversalNumber}
Create a UniversalNumber with partially known factorization Useful for very large numbers where complete factorization is impractical
Name | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params | Object | Parameters for partial factorization Properties
|
- Source
A new UniversalNumber with partial factorization
- Type:
- UniversalNumber
(static) fromString(str, baseopt) → {UniversalNumber}
Create a UniversalNumber from a string representation
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
str | string | The string to parse | ||
base | number | <optional> | 10 | The base of the input string (configurable, default: 2-36) |
- Source
If str cannot be parsed in the given base
- Type
- PrimeMathError
A new UniversalNumber instance
- Type:
- UniversalNumber
(static) fuse(operations, initialValue) → {UniversalNumber}
Apply operation fusion to a sequence of operations This optimizes computation by eliminating intermediate results
Name | Type | Description |
---|---|---|
operations | Array.<function()> | Array of functions to compose |
initialValue | UniversalNumber | Starting value |
- Source
Result of all operations combined
- Type:
- UniversalNumber
(static) getActiveReferenceFrame() → {string}
Get the currently active reference frame in the fiber algebra In the Prime Framework, numbers exist at a point on a smooth manifold M
- Source
The identifier of the active reference frame
- Type:
- string
(static) innerProduct(a, b) → {UniversalNumber}
Calculate the coherence inner product between two UniversalNumber instances The coherence inner product is a positive-definite inner product that measures consistency between different representations of the same abstract number
Name | Type | Description |
---|---|---|
a | UniversalNumber | First UniversalNumber |
b | UniversalNumber | Second UniversalNumber |
- Source
The coherence inner product value
- Type:
- UniversalNumber
(static) lazy(operation) → {UniversalNumber}
Create a UniversalNumber with lazy evaluation
Name | Type | Description |
---|---|---|
operation | function | Function to execute when the value is needed |
- Source
A lazily evaluated UniversalNumber
- Type:
- UniversalNumber
(static) registerReferenceFrame(frame)
Register a new reference frame in the fiber algebra Used for advanced geometric interpretations of the Prime Framework
Name | Type | Description |
---|---|---|
frame | ReferenceFrame | The reference frame to register |
- Source
If the frame is invalid
- Type
- PrimeMathError
(static) setActiveReferenceFrame(frameId)
Set the active reference frame for Prime Framework operations All numbers are interpreted relative to the current reference
Name | Type | Description |
---|---|---|
frameId | string | The identifier of the reference frame to activate |
- Source
If the reference frame doesn't exist
- Type
- PrimeMathError
(static) verifyRoundTrip(value) → {boolean}
Verify round-trip consistency between UniversalNumber and standard number formats This is used to ensure that conversions don't lose information
Name | Type | Description |
---|---|---|
value | number | | The value to test for round-trip consistency |
- Source
True if conversions are consistent, false otherwise
- Type:
- boolean