UniversalNumber~ UniversalNumber

Class representing a universal number in the Prime Framework Stores numbers using their prime factorization (universal coordinates) Provides exact arithmetic operations with no rounding errors Ensures unique canonical representation through strict normalization

Constructor

new UniversalNumber(value)

Create a new UniversalNumber

Parameters:
NameTypeDescription
valuenumber | string | BigInt | Map.<BigInt, BigInt> | UniversalNumber | Object

The value to initialize with

Throws:

If value cannot be converted to a valid UniversalNumber

Type
PrimeMathError

Methods

abs() → {UniversalNumber}

Get the absolute value of this UniversalNumber

Returns:

A new UniversalNumber with the same magnitude but positive sign

Type: 
UniversalNumber

add(other) → {UniversalNumber}

Add another number to this UniversalNumber

Parameters:
NameTypeDescription
othernumber | string | BigInt | UniversalNumber

The number to add

Returns:

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

Parameters:
NameTypeDescription
otherUniversalNumber

The other UniversalNumber

Returns:

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

Returns:

The coherence norm value

Type: 
UniversalNumber

compareTo(other) → {number}

Compare this UniversalNumber with another number

Parameters:
NameTypeDescription
othernumber | string | BigInt | UniversalNumber

The number to compare with

Returns:

-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

Parameters:
NameTypeDescription
othernumber | string | BigInt | UniversalNumber

The divisor

Throws:

If the division is not exact or divisor is zero

Type
PrimeMathError
Returns:

A new UniversalNumber representing the quotient

Type: 
UniversalNumber

equals(other) → {boolean}

Compare this UniversalNumber with another number for equality

Parameters:
NameTypeDescription
othernumber | string | BigInt | UniversalNumber

The number to compare with

Returns:

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

Parameters:
NameTypeAttributesDescription
optionsObject<optional>

Formatting options

Properties
NameTypeAttributesDefaultDescription
precisionnumber<optional>
20

Maximum number of significant digits to include

scientificboolean<optional>
false

Whether to use scientific notation

notationstring<optional>
'standard'

Notation style: 'standard', 'scientific', 'engineering', or 'compact'

basenumber<optional>
10

The base for the output representation (2-36)

groupDigitsboolean<optional>
false

Whether to group digits (e.g., with commas in base 10)

groupSeparatorstring<optional>
','

Character to use as the digit group separator

Returns:

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

Parameters:
NameTypeDescription
othernumber | string | BigInt | UniversalNumber

The other number

Throws:

If both inputs are zero

Type
PrimeMathError
Returns:

A new UniversalNumber representing the GCD

Type: 
UniversalNumber

getCoordinates() → {Coordinates}

Get the universal coordinates (prime factorization and sign)

Returns:

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

Parameters:
NameTypeAttributesDefaultDescription
basenumber<optional>
10

The base to use (2-36)

leastSignificantFirstboolean<optional>
false

Order of digits

Throws:

If the base is invalid

Type
PrimeMathError
Returns:

Array of digits in the specified base

Type: 
Array.<number>

getFactorization() → {Map.<BigInt, BigInt>}

Get the prime factorization of the UniversalNumber

Returns:

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

Parameters:
NameTypeDescription
optionsObject

Options for retrieving graded components

Properties
NameTypeAttributesDefaultDescription
basesArray.<number><optional>
[2,10]

The bases to include in the graded components

referenceFramestring<optional>

Optional reference frame (defaults to active frame)

Returns:

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

Parameters:
NameTypeAttributesDescription
optionsObject<optional>

Options for extracting parts

Properties
NameTypeAttributesDefaultDescription
basenumber<optional>
10

The base for representation

includeExponentboolean<optional>
true

Whether to calculate and include exponent info

significantDigitsnumber<optional>
15

Number of significant digits

getSeparateDigitsboolean<optional>
false

Whether to return digits as separate array entries

Returns:

Object containing number parts (sign, integerPart, fractionalPart, etc.)

Type: 
Object

isDivisibleBy(other) → {boolean}

Check if this number is divisible by another

Parameters:
NameTypeDescription
othernumber | string | BigInt | UniversalNumber

The potential divisor

Throws:

If divisor is zero

Type
PrimeMathError
Returns:

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

Returns:

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

Returns:

True if the number is in minimal-norm form

Type: 
boolean

isOne() → {boolean}

Check if this UniversalNumber is 1

Returns:

True if this number is 1, false otherwise

Type: 
boolean

isZero() → {boolean}

Check if this UniversalNumber is 0

Returns:

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

Parameters:
NameTypeDescription
othernumber | string | BigInt | UniversalNumber

The other number

Throws:

If either input is zero

Type
PrimeMathError
Returns:

A new UniversalNumber representing the LCM

Type: 
UniversalNumber

mod(modulus) → {UniversalNumber}

Compute the modulo (remainder after division)

Parameters:
NameTypeDescription
modulusnumber | string | BigInt | UniversalNumber

The modulus

Throws:

If modulus is not positive

Type
PrimeMathError
Returns:

This value modulo the given modulus

Type: 
UniversalNumber

modInverse(modulus) → {UniversalNumber|null}

Calculate the modular inverse (a^-1 mod m) if it exists

Parameters:
NameTypeDescription
modulusnumber | string | BigInt | UniversalNumber

The modulus

Throws:

If modulus is not positive

Type
PrimeMathError
Returns:

The modular inverse, or null if it doesn't exist

Type: 
UniversalNumber | null

modPow(expValue, modulus) → {UniversalNumber}

Compute modular exponentiation (a^b mod n)

Parameters:
NameTypeDescription
expValuenumber | string | BigInt

The exponent

modulusnumber | string | BigInt | UniversalNumber

The modulus

Throws:

If modulus is not positive

Type
PrimeMathError
Returns:

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)

Parameters:
NameTypeDescription
modulusUniversalNumber | BigInt | number | string

The modulus

Returns:

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

Parameters:
NameTypeDescription
othernumber | string | BigInt | UniversalNumber

The number to multiply by

Returns:

A new UniversalNumber representing the product

Type: 
UniversalNumber

negate() → {UniversalNumber}

Negate this UniversalNumber

Returns:

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

Parameters:
NameTypeDescription
exponentnumber | string | BigInt

The exponent

Throws:

If exponent is negative

Type
PrimeMathError
Returns:

A new UniversalNumber representing the result of the exponentiation

Type: 
UniversalNumber

radical() → {UniversalNumber}

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

Returns:

A new UniversalNumber with all exponents set to 1

Type: 
UniversalNumber

sign() → {number}

Get the sign of this UniversalNumber

Returns:

-1 if negative, 1 if positive

Type: 
number

subtract(other) → {UniversalNumber}

Subtract another number from this UniversalNumber

Parameters:
NameTypeDescription
othernumber | string | BigInt | UniversalNumber

The number to subtract

Returns:

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

Parameters:
NameTypeAttributesDescription
optionsObject<optional>

Options for the approximation

Properties
NameTypeAttributesDefaultDescription
significantDigitsnumber<optional>
15

Number of significant digits to include (max 17)

throwOnOverflowboolean<optional>
false

Whether to throw an error if the exponent overflows

Throws:

If the exponent is too large even for scientific notation and throwOnOverflow is true

Type
PrimeMathError
Returns:

The approximate Number in scientific notation

Type: 
number

toBigInt() → {BigInt}

Convert the UniversalNumber to a BigInt

Returns:

The BigInt representation of the number

Type: 
BigInt

toCompact() → {Object}

Create a compacted representation of this UniversalNumber Memory-optimized representation for very large numbers

Returns:

Compact serializable representation

Type: 
Object

toJSON() → {Object}

Convert the UniversalNumber to a serializable object For use with JSON.stringify

Returns:

Object with type, factors, and sign information

Type: 
Object

toNumber(optionsopt) → {number}

Convert the UniversalNumber to a JavaScript Number

Parameters:
NameTypeAttributesDescription
optionsObject<optional>

Conversion options

Properties
NameTypeAttributesDefaultDescription
allowApproximateboolean<optional>
false

Whether to allow approximate conversion for large values

suppressErrorsboolean<optional>
false

Whether to return Infinity/-Infinity instead of throwing errors

Throws:

If the value is too large to be represented as a Number (unless suppressErrors is true)

Type
PrimeMathError
Returns:

The Number representation of the number

Type: 
number

toString(baseopt) → {string}

Convert the UniversalNumber to a string representation in the given base

Parameters:
NameTypeAttributesDefaultDescription
basenumber<optional>
10

The base for the output representation (2-36)

Throws:

If the base is invalid

Type
PrimeMathError
Returns:

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

Parameters:
NameTypeDescription
targetFramestring

The reference frame to transform to

Throws:

If the target frame doesn't exist

Type
PrimeMathError
Returns:

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

Returns:

The BigInt representation of the number

Type: 
BigInt

(static) factorize(n, optionsopt) → {UniversalNumber}

Factorize a number into its UniversalNumber representation with prime factorization

Parameters:
NameTypeAttributesDescription
nnumber | string | BigInt

The number to factorize

optionsObject<optional>

Options for factorization

Properties
NameTypeAttributesDefaultDescription
advancedboolean<optional>
false

Whether to use advanced factorization algorithms

Returns:

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

Parameters:
NameTypeDescription
aUniversalNumber

First number

bUniversalNumber

Second number

Returns:

Product a × b

Type: 
UniversalNumber

(static) fromBigInt(n) → {UniversalNumber}

Create a UniversalNumber from a BigInt

Parameters:
NameTypeDescription
nBigInt

The BigInt to convert

Returns:

A new UniversalNumber instance

Type: 
UniversalNumber

(static) fromCompact(compact) → {UniversalNumber}

Create a UniversalNumber from a compact representation

Parameters:
NameTypeDescription
compactObject

Compact representation created by toCompact()

Returns:

The reconstructed UniversalNumber

Type: 
UniversalNumber

(static) fromFactors(factors, isNegativeopt) → {UniversalNumber}

Create a UniversalNumber from its prime factorization

Parameters:
NameTypeAttributesDefaultDescription
factorsArray.<{prime: (BigInt|number|string), exponent: (BigInt|number|string)}> | Map.<BigInt, BigInt>

Prime factorization

isNegativeboolean<optional>
false

Whether the number is negative

Throws:

If the factorization is invalid

Type
PrimeMathError
Returns:

A new UniversalNumber instance

Type: 
UniversalNumber

(static) fromJSON(json) → {UniversalNumber}

Create a UniversalNumber from a JSON representation

Parameters:
NameTypeDescription
jsonObject

The JSON object

Throws:

If the JSON is invalid

Type
PrimeMathError
Returns:

A new UniversalNumber

Type: 
UniversalNumber

(static) fromNumber(n) → {UniversalNumber}

Create a UniversalNumber from a regular number

Parameters:
NameTypeDescription
nnumber

The JavaScript Number to convert

Throws:

If n is not a safe integer or is not finite

Type
PrimeMathError
Returns:

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

Parameters:
NameTypeDescription
paramsObject

Parameters for partial factorization

Properties
NameTypeAttributesDefaultDescription
knownFactorsArray.<{prime: (BigInt|number|string), exponent: (BigInt|number|string)}> | Map.<BigInt, BigInt>

Known prime factors

remainingPartBigInt | number | string

The unfactorized part (must be > 1)

isNegativeboolean<optional>
false

Whether the number is negative

Returns:

A new UniversalNumber with partial factorization

Type: 
UniversalNumber

(static) fromString(str, baseopt) → {UniversalNumber}

Create a UniversalNumber from a string representation

Parameters:
NameTypeAttributesDefaultDescription
strstring

The string to parse

basenumber<optional>
10

The base of the input string (configurable, default: 2-36)

Throws:

If str cannot be parsed in the given base

Type
PrimeMathError
Returns:

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

Parameters:
NameTypeDescription
operationsArray.<function()>

Array of functions to compose

initialValueUniversalNumber

Starting value

Returns:

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

Returns:

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

Parameters:
NameTypeDescription
aUniversalNumber

First UniversalNumber

bUniversalNumber

Second UniversalNumber

Returns:

The coherence inner product value

Type: 
UniversalNumber

(static) lazy(operation) → {UniversalNumber}

Create a UniversalNumber with lazy evaluation

Parameters:
NameTypeDescription
operationfunction

Function to execute when the value is needed

Returns:

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

Parameters:
NameTypeDescription
frameReferenceFrame

The reference frame to register

Throws:

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

Parameters:
NameTypeDescription
frameIdstring

The identifier of the reference frame to activate

Throws:

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

Parameters:
NameTypeDescription
valuenumber | string | BigInt

The value to test for round-trip consistency

Returns:

True if conversions are consistent, false otherwise

Type: 
boolean