Options
All
  • Public
  • Public/Protected
  • All
Menu

Module Algebra

Algebraic manipulations.

preferred

Index

Functions

factor

  • factor(n: number): Generator<number, void, unknown>
  • Returns a generator with a number's factors. Uses a pre-computed sieve up to 16K, then Brent's algorithm, which has a small chance of failing

    Parameters

    • n: number

      The number to be factored.

    Returns Generator<number, void, unknown>

gcd

  • gcd(a: number, b: number): number
  • gcd(a: bigint, b: bigint): bigint
  • GCD, for either two numbers or two BigInts.

    Parameters

    • a: number
    • b: number

    Returns number

  • Parameters

    • a: bigint
    • b: bigint

    Returns bigint

Const isComposite

  • isComposite(n: number): boolean
  • The Miller Rabin algorithm. The opposite of [isPrime].

    For the moment, due to lack of universal BigInt support and unlikeliness of need, we accept that it will be inaccurate on platforms w/o BigInt (e.g. Safari) above 94906265 (Math.floor(Math.sqrt(Number.MAX_SAFE_INTEGER)).

    arg

    n the number to be tested for primality.

    Parameters

    • n: number

    Returns boolean

    true if n is prime, else returns false

Const isPrime

  • isPrime(n: number): boolean
  • The Miller Rabin algorithm.

    For the moment, due to lack of universal BigInt support and unlikeliness of need, we accept that it will be inaccurate on platforms w/o BigInt (e.g. Safari) above 94906265 (Math.floor(Math.sqrt(Number.MAX_SAFE_INTEGER)).

    arg

    n the number to be tested for primality.

    Parameters

    • n: number

    Returns boolean

    true if n is prime, else returns false

sieve

  • sieve(lim: number): Generator<number, void, unknown>
  • Parameters

    • lim: number

    Returns Generator<number, void, unknown>

xgcd

  • xgcd(a: number, b: number): [number, number, number]
  • xgcd(a: bigint, b: bigint): [bigint, bigint, bigint]
  • Extended GCD

    Parameters

    • a: number
    • b: number

    Returns [number, number, number]

    such that gcdfactor_a = a, gcdfactor_b = b.

  • Parameters

    • a: bigint
    • b: bigint

    Returns [bigint, bigint, bigint]

Generated using TypeDoc