/** * Number-theory fills — closes gaps left by the existing combinatorics/number-theory * surface (`typed/combinatorics.ts`): continued fractions, Euler numbers, the signed * Stirling numbers of the first kind, discrete logarithm (BSGS), primitive roots, * multiplicative order, the Kronecker symbol, and lexicographic * permutation/combination *enumerators* (the existing `permutations`/`combinations` * only return counts, not the tuples themselves). * * Plain exported functions (not `mathTyped` dispatch) — all take/return `number` * or generic arrays, matching the style of `descriptive-stats.ts`. * * @packageDocumentation */ /** * Simple continued fraction expansion `[a0, a1, a2, ...]` of `x`, where * `a_i = floor(r)` and `r <- 1 / (r - a_i)`. * * Stops after `maxTerms` (default 20) or once the fractional part is smaller * than `1e-12` (the remaining value is effectively an integer). * * @param x - The number to expand * @param maxTerms - Maximum number of terms to compute (default 20) * @returns The sequence of partial-quotient terms * * @example * continuedFraction(3.245, 5) // => [3, 4, 12, 4, ...] */ export declare function continuedFraction(x: number, maxTerms?: number): number[]; /** * Euler numbers `E_0..E_n` (the coefficients in the secant Maclaurin series). * * `E_0 = 1`; all odd-index Euler numbers are 0; for even `m > 0`: * `E_m = -sum_{k=0}^{m/2-1} C(m, 2k) * E_{2k}`. * * @param n - Non-negative integer: compute E_0 through E_n * @returns Array of length `n + 1`: `[E_0, E_1, ..., E_n]` * * @example * eulerNumbers(6) // => [1, 0, -1, 0, 5, 0, -61] */ export declare function eulerNumbers(n: number): number[]; /** * Signed Stirling number of the first kind `s(n, k)`. * * Recurrence: `s(n, k) = s(n-1, k-1) - (n-1)*s(n-1, k)`, with `s(0, 0) = 1` * and `s(n, 0) = 0` for `n > 0`. * * @param n - Non-negative integer * @param k - Non-negative integer, `0 <= k <= n` * @returns The signed Stirling number `s(n, k)` * * @example * stirlingS1(5, 2) // => -50 */ export declare function stirlingS1(n: number, k: number): number; /** * Discrete logarithm via baby-step giant-step: the smallest `x >= 0` such * that `g^x === h (mod p)`, or `-1` if none exists within `[0, p-1]`. * * Uses `BigInt` internally for modular exponentiation/inversion to avoid * overflow. `m = ceil(sqrt(p-1))` baby steps are stored in a map; the giant * steps multiply by `g^(-m) mod p` each round. * * @param g - Base * @param h - Target * @param p - Prime modulus * @returns The smallest non-negative `x` with `g^x === h (mod p)`, or `-1` * * @example * discreteLog(2, 3, 5) // => 3 (2^3 = 8 === 3 mod 5) */ export declare function discreteLog(g: number, h: number, p: number): number; /** * Smallest primitive root modulo a prime `p`. * * For each candidate `g = 2, 3, ...`, `g` is a primitive root iff * `g^((p-1)/q) !== 1 (mod p)` for every prime factor `q` of `p - 1`. * * @param p - An odd prime (p = 2 returns 1 trivially) * @returns The smallest primitive root modulo p * * @example * primitiveRoot(7) // => 3 */ export declare function primitiveRoot(p: number): number; /** * Multiplicative order of `a` modulo `n`: the smallest `k > 0` with * `a^k === 1 (mod n)`. Returns `-1` if `gcd(a, n) !== 1` (no order exists). * * @param a - Integer * @param n - Positive integer modulus * @returns The multiplicative order, or -1 if undefined * * @example * multiplicativeOrder(2, 7) // => 3 */ export declare function multiplicativeOrder(a: number, n: number): number; /** * Kronecker symbol `(a|n)`, generalizing the Jacobi symbol `(a|n)` (odd * positive `n`) to all integers `n`. * * - `(a|0) = 1` if `|a| = 1`, else `0`. * - Sign of `n` is extracted first: `(a|-1) = -1` if `a < 0`, else `1`. * - Factors of 2 are extracted from `n` using `(a|2)`: `0` if `a` even, * `1` if `a === ±1 (mod 8)`, `-1` if `a === ±3 (mod 8)`. * - The remaining odd part is evaluated via the standard Jacobi reciprocity * recursion. * * @param a - Integer * @param n - Integer * @returns -1, 0, or 1 * * @example * kroneckerSymbol(2, 3) // => -1 */ export declare function kroneckerSymbol(a: number, n: number): number; /** * Enumerate all length-`k` combinations of `arr` (index-order subsequences, * i.e. lexicographic order for a sorted input) as an array of tuples. * * @param arr - Source array * @param k - Combination length * @returns All `C(arr.length, k)` combinations, in lexicographic order * * @example * combinationsGen([1, 2, 3], 2) // => [[1,2],[1,3],[2,3]] */ export declare function combinationsGen(arr: readonly T[], k: number): T[][]; /** * Enumerate all length-`k` permutations (ordered arrangements) of `arr` * as an array of tuples, in lexicographic order of index selection. * `k` defaults to `arr.length` (full permutations). * * @param arr - Source array * @param k - Permutation length (default: `arr.length`) * @returns All `n! / (n-k)!` permutations, in lexicographic order * * @example * permutationsGen([1, 2, 3], 2) // => 6 tuples: [1,2],[1,3],[2,1],[2,3],[3,1],[3,2] */ export declare function permutationsGen(arr: readonly T[], k?: number): T[][]; //# sourceMappingURL=extra.d.ts.map