/** * Extended Combinatorics Functions * * Provides combinatorial number sequences and factorial variants: * - fibonacci: nth Fibonacci number (fast doubling, O(log n)) * - lucas: nth Lucas number * - doubleFactorial: n!! = n * (n-2) * (n-4) * ... * - risingFactorial: Pochhammer symbol x^(n) = x(x+1)...(x+n-1) * - fallingFactorial: x_(n) = x(x-1)...(x-n+1) * - subfactorial: !n = number of derangements * * Uses mathTyped for type dispatch on numeric arguments. * * @packageDocumentation */ /** * Compute the nth Fibonacci number using the fast doubling method. * * Fast doubling uses the identities: * F(2k) = F(k) * [2*F(k+1) - F(k)] * F(2k+1) = F(k)^2 + F(k+1)^2 * * Time complexity: O(log n) * * @param n - Non-negative integer index * @returns The nth Fibonacci number * * @example * fibonacci(0) // => 0 * fibonacci(1) // => 1 * fibonacci(10) // => 55 * fibonacci(20) // => 6765 */ export declare const fibonacci: import("@danielsimonjr/mathts-core").TypedFunction; /** * Compute the nth Lucas number. * * Lucas numbers follow the same recurrence as Fibonacci but with * L(0) = 2, L(1) = 1. Related to Fibonacci by L(n) = F(n-1) + F(n+1). * * Uses the fast doubling identities: * L(2k) = L(k)^2 - 2*(-1)^k * L(2k+1) = L(k)*L(k+1) - (-1)^k * ... (via Fibonacci relation) * * @param n - Non-negative integer index * @returns The nth Lucas number * * @example * lucas(0) // => 2 * lucas(1) // => 1 * lucas(10) // => 123 */ export declare const lucas: import("@danielsimonjr/mathts-core").TypedFunction; /** * Compute the double factorial n!!. * * n!! = n * (n-2) * (n-4) * ... * (2 or 1) * * For odd n: n!! = n * (n-2) * ... * 3 * 1 * For even n: n!! = n * (n-2) * ... * 4 * 2 * * Special cases: 0!! = 1, (-1)!! = 1 * * @param n - Non-negative integer (or -1) * @returns The double factorial * * @example * doubleFactorial(7) // => 105 (7*5*3*1) * doubleFactorial(6) // => 48 (6*4*2) * doubleFactorial(0) // => 1 */ export declare const doubleFactorial: import("@danielsimonjr/mathts-core").TypedFunction; /** * Compute the rising factorial (Pochhammer symbol). * * x^(n) = x * (x+1) * (x+2) * ... * (x+n-1) * * Also written as (x)_n in some notations. * Rising factorial of 0 terms is 1 by convention. * * @param x - Base value * @param n - Number of terms (non-negative integer) * @returns The rising factorial * * @example * risingFactorial(3, 4) // => 3*4*5*6 = 360 * risingFactorial(1, 5) // => 1*2*3*4*5 = 120 = 5! */ export declare const risingFactorial: import("@danielsimonjr/mathts-core").TypedFunction; /** * Compute the falling factorial. * * x_(n) = x * (x-1) * (x-2) * ... * (x-n+1) * * Falling factorial of 0 terms is 1 by convention. * * @param x - Base value * @param n - Number of terms (non-negative integer) * @returns The falling factorial * * @example * fallingFactorial(5, 3) // => 5*4*3 = 60 * fallingFactorial(5, 5) // => 5*4*3*2*1 = 120 = 5! */ export declare const fallingFactorial: import("@danielsimonjr/mathts-core").TypedFunction; /** * Compute the subfactorial (number of derangements). * * !n = n! * sum_{k=0}^{n} (-1)^k / k! * * A derangement is a permutation where no element appears in its original position. * * @param n - Non-negative integer * @returns The number of derangements of n elements * * @example * subfactorial(0) // => 1 * subfactorial(1) // => 0 * subfactorial(2) // => 1 * subfactorial(5) // => 44 */ export declare const subfactorial: import("@danielsimonjr/mathts-core").TypedFunction; /** * Return the nth prime number (1-indexed). * * Uses a sieve-based approach. For n <= 6, returns from lookup. * For larger n, estimates an upper bound and sieves. * * @param n - Positive integer index (1-indexed) * @returns The nth prime number * * @example * prime(1) // => 2 * prime(4) // => 7 * prime(10) // => 29 */ export declare const prime: import("@danielsimonjr/mathts-core").TypedFunction; /** * Return the smallest prime number strictly greater than n. * * @param n - Non-negative number * @returns Smallest prime > n * * @example * nextPrime(4) // => 5 * nextPrime(7) // => 11 * nextPrime(10) // => 11 */ export declare const nextPrime: import("@danielsimonjr/mathts-core").TypedFunction; /** * Prime counting function pi(n): number of primes <= n. * * @param n - Non-negative integer * @returns Number of primes not exceeding n * * @example * primePi(10) // => 4 (primes: 2, 3, 5, 7) * primePi(1) // => 0 */ export declare const primePi: import("@danielsimonjr/mathts-core").TypedFunction; /** * Return the prime factorization of n as an array of prime factors * (with repetition, sorted ascending). * * @param n - Positive integer >= 2 * @returns Array of prime factors * * @example * primeFactors(12) // => [2, 2, 3] * primeFactors(60) // => [2, 2, 3, 5] * primeFactors(7) // => [7] */ export declare const primeFactors: import("@danielsimonjr/mathts-core").TypedFunction; /** * Return all positive divisors of n, sorted ascending. * * @param n - Positive integer * @returns Sorted array of divisors * * @example * divisors(12) // => [1, 2, 3, 4, 6, 12] * divisors(7) // => [1, 7] */ export declare const divisors: import("@danielsimonjr/mathts-core").TypedFunction; /** * Euler's totient function phi(n): count of integers 1..n coprime to n. * * @param n - Positive integer * @returns phi(n) * * @example * eulerPhi(1) // => 1 * eulerPhi(10) // => 4 (1, 3, 7, 9) * eulerPhi(12) // => 4 (1, 5, 7, 11) */ export declare const eulerPhi: import("@danielsimonjr/mathts-core").TypedFunction; /** * Sum of the kth powers of divisors of n: sigma_k(n). * * sigma_0(n) = number of divisors * sigma_1(n) = sum of divisors * * @param n - Positive integer * @param k - Power (non-negative integer, default 1) * @returns sigma_k(n) * * @example * divisorSigma(12) // => 28 (1+2+3+4+6+12) * divisorSigma(12, 0) // => 6 (number of divisors) * divisorSigma(12, 2) // => 210 */ export declare const divisorSigma: import("@danielsimonjr/mathts-core").TypedFunction; /** * Carmichael function lambda(n): smallest positive integer m such that * a^m === 1 (mod n) for all a coprime to n. * * @param n - Positive integer * @returns lambda(n) * * @example * carmichaelLambda(1) // => 1 * carmichaelLambda(8) // => 2 * carmichaelLambda(15) // => 4 */ export declare const carmichaelLambda: import("@danielsimonjr/mathts-core").TypedFunction; /** * Mobius function mu(n). * * mu(1) = 1 * mu(n) = 0 if n has a squared prime factor * mu(n) = (-1)^k if n is a product of k distinct primes * * @param n - Positive integer * @returns mu(n): -1, 0, or 1 * * @example * moebiusMu(1) // => 1 * moebiusMu(6) // => 1 (6 = 2*3, two distinct primes) * moebiusMu(4) // => 0 (4 = 2^2, squared factor) * moebiusMu(30) // => -1 (30 = 2*3*5, three distinct primes) */ export declare const moebiusMu: import("@danielsimonjr/mathts-core").TypedFunction; /** * Jacobi symbol (a/n), a generalization of the Legendre symbol. * * n must be a positive odd integer. * * @param a - Integer * @param n - Positive odd integer * @returns -1, 0, or 1 * * @example * jacobiSymbol(2, 7) // => 1 * jacobiSymbol(5, 21) // => 1 * jacobiSymbol(7, 15) // => -1 */ export declare const jacobiSymbol: import("@danielsimonjr/mathts-core").TypedFunction; /** * Solve a system of simultaneous congruences using the Chinese Remainder Theorem. * * Find x such that x === remainders[i] (mod moduli[i]) for all i. * Moduli must be pairwise coprime. * * @param remainders - Array of remainders * @param moduli - Array of moduli (pairwise coprime) * @returns Solution x (smallest non-negative) * * @example * chineseRemainder([2, 3, 2], [3, 5, 7]) // => 23 * // x === 2 (mod 3), x === 3 (mod 5), x === 2 (mod 7) */ export declare const chineseRemainder: import("@danielsimonjr/mathts-core").TypedFunction; /** * Compute the nth Lucas number L(n). * * This is a standalone implementation using iterative computation. * L(0) = 2, L(1) = 1, L(n) = L(n-1) + L(n-2). * * Note: the `lucas` export above uses a Fibonacci-based approach. * This provides a direct iterative alternative. * * @param n - Non-negative integer * @returns L(n) * * @example * lucasL(0) // => 2 * lucasL(5) // => 11 * lucasL(10) // => 123 */ export declare const lucasL: import("@danielsimonjr/mathts-core").TypedFunction; /** * Number of integer partitions of n. * * A partition of n is a way to write n as a sum of positive integers * (order doesn't matter). * * Uses dynamic programming. * * @param n - Non-negative integer * @returns p(n) * * @example * partitions(0) // => 1 * partitions(4) // => 5 (4, 3+1, 2+2, 2+1+1, 1+1+1+1) * partitions(5) // => 7 */ export declare const partitions: import("@danielsimonjr/mathts-core").TypedFunction; /** * Compute the nth harmonic number H(n) = 1 + 1/2 + 1/3 + ... + 1/n. * * @param n - Positive integer * @returns H(n) * * @example * harmonicNumber(1) // => 1 * harmonicNumber(4) // => 2.0833... (1 + 1/2 + 1/3 + 1/4) */ export declare const harmonicNumber: import("@danielsimonjr/mathts-core").TypedFunction; /** * Return the digits of n in the given base as an array (most significant first). * * @param n - Non-negative integer * @param base - Base (integer >= 2, default 10) * @returns Array of digits * * @example * integerDigits(123) // => [1, 2, 3] * integerDigits(255, 16) // => [15, 15] * integerDigits(10, 2) // => [1, 0, 1, 0] * integerDigits(0) // => [0] */ export declare const integerDigits: import("@danielsimonjr/mathts-core").TypedFunction; //# sourceMappingURL=combinatorics.d.ts.map