@danielsimonjr/mathts-functions 0.57.0 → 0.58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1144 -300
- package/dist/typed/algebra.d.ts +8 -5
- package/dist/typed/algebra.d.ts.map +1 -1
- package/dist/typed/factorization/finite-field.d.ts +84 -0
- package/dist/typed/factorization/finite-field.d.ts.map +1 -0
- package/dist/typed/factorization/hensel.d.ts +38 -0
- package/dist/typed/factorization/hensel.d.ts.map +1 -0
- package/dist/typed/factorization/index.d.ts +47 -0
- package/dist/typed/factorization/index.d.ts.map +1 -0
- package/dist/typed/factorization/integer-poly.d.ts +82 -0
- package/dist/typed/factorization/integer-poly.d.ts.map +1 -0
- package/dist/typed/factorization/square-free.d.ts +37 -0
- package/dist/typed/factorization/square-free.d.ts.map +1 -0
- package/dist/typed/factorization/zassenhaus.d.ts +36 -0
- package/dist/typed/factorization/zassenhaus.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/typed/algebra.d.ts
CHANGED
|
@@ -218,11 +218,14 @@ export declare function expand(expr: string): string;
|
|
|
218
218
|
* Factor an expression string.
|
|
219
219
|
*
|
|
220
220
|
* **Univariate polynomials** (a single variable, integer coefficients,
|
|
221
|
-
* degree ≥ 2) are factored over
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
* `factor('x^2-1')` → `'(x - 1)*(x + 1)'
|
|
221
|
+
* degree ≥ 2) are factored **completely over ℤ/ℚ** into irreducible factors
|
|
222
|
+
* with multiplicity. Rational linear roots are extracted first (rational-root
|
|
223
|
+
* theorem); any higher-degree remainder — and any polynomial with no rational
|
|
224
|
+
* root — is routed through the Zassenhaus engine
|
|
225
|
+
* ({@link factorPolynomialUnivariate}): `factor('x^2-1')` → `'(x - 1)*(x + 1)'`,
|
|
226
|
+
* `factor('x^4-1')` → `'(x - 1)*(x + 1)*(x^2 + 1)'`,
|
|
227
|
+
* `factor('x^4+3*x^2+2')` → `'(x^2 + 1)*(x^2 + 2)'`. Polynomials irreducible
|
|
228
|
+
* over ℚ (`x^4 + 1`, `x^2 + x + 1`) are returned unchanged.
|
|
226
229
|
*
|
|
227
230
|
* **Multivariate polynomials** get the tractable subset (see
|
|
228
231
|
* {@link factorMultivariate}): integer-content + common-monomial extraction
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"algebra.d.ts","sourceRoot":"","sources":["../../src/typed/algebra.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"algebra.d.ts","sourceRoot":"","sources":["../../src/typed/algebra.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAsBH,KAAK,GAAG,GAAG,MAAM,CAAC;AAkJlB;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,GAAG,GAAG,GAAG,CAOrD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAO1D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAgB1D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,GAAE,MAAU,GAAG,MAAM,EAAE,CAUjE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAgBhE;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAShE;AAED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AED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,CAKrD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CA6BtE;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAmEhF;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOnD;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,GAAG,CAgCvD;AAMD;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0CxB,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dense univariate polynomial arithmetic over the finite field 𝔽_p, backed
|
|
3
|
+
* by the same `bigint[]` representation as `integer-poly.ts` (index =
|
|
4
|
+
* degree). Every coefficient produced by an operation in this module is
|
|
5
|
+
* kept reduced into the canonical range `[0, p)` and trimmed so the
|
|
6
|
+
* highest-degree entry (if any) is nonzero.
|
|
7
|
+
*
|
|
8
|
+
* This module is part of the univariate factorization engine
|
|
9
|
+
* (`functions/src/typed/factorization/`) and is `bigint`-only by design.
|
|
10
|
+
*/
|
|
11
|
+
import { type IntPoly } from './integer-poly.js';
|
|
12
|
+
export type { IntPoly } from './integer-poly.js';
|
|
13
|
+
/**
|
|
14
|
+
* Reduces every coefficient of `a` into `[0, p)`, then trims trailing
|
|
15
|
+
* (highest-degree) zero coefficients. Does not mutate the input.
|
|
16
|
+
*/
|
|
17
|
+
export declare function reduceModP(a: IntPoly, p: bigint): IntPoly;
|
|
18
|
+
/** `a + b` over 𝔽_p, coefficients reduced into `[0, p)`. */
|
|
19
|
+
export declare function addP(a: IntPoly, b: IntPoly, p: bigint): IntPoly;
|
|
20
|
+
/** `a - b` over 𝔽_p, coefficients reduced into `[0, p)`. */
|
|
21
|
+
export declare function subP(a: IntPoly, b: IntPoly, p: bigint): IntPoly;
|
|
22
|
+
/** `a * b` over 𝔽_p via schoolbook convolution, coefficients in `[0, p)`. */
|
|
23
|
+
export declare function mulP(a: IntPoly, b: IntPoly, p: bigint): IntPoly;
|
|
24
|
+
/**
|
|
25
|
+
* Modular inverse of a scalar `a` modulo prime `p`, via the extended
|
|
26
|
+
* Euclidean algorithm. Returns a value in `[1, p)`. Throws if `a ≡ 0 (mod p)`
|
|
27
|
+
* (no inverse exists).
|
|
28
|
+
*/
|
|
29
|
+
export declare function invModP(a: bigint, p: bigint): bigint;
|
|
30
|
+
/**
|
|
31
|
+
* Scales `a` so its leading coefficient becomes 1 (multiplies by
|
|
32
|
+
* `invModP(lc(a), p)`). Returns `[]` unchanged for the zero polynomial.
|
|
33
|
+
*/
|
|
34
|
+
export declare function makeMonicP(a: IntPoly, p: bigint): IntPoly;
|
|
35
|
+
/**
|
|
36
|
+
* Polynomial division over 𝔽_p: `a = q*b + r` with `deg(r) < deg(b)`.
|
|
37
|
+
* `b` must be nonzero. Coefficients of `q` and `r` are reduced into `[0, p)`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function divmodP(a: IntPoly, b: IntPoly, p: bigint): {
|
|
40
|
+
q: IntPoly;
|
|
41
|
+
r: IntPoly;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Monic gcd of `a` and `b` over 𝔽_p via the Euclidean algorithm. Returns
|
|
45
|
+
* `[]` (zero polynomial) only when both inputs are zero; otherwise the
|
|
46
|
+
* result is monic (leading coefficient 1).
|
|
47
|
+
*/
|
|
48
|
+
export declare function gcdP(a: IntPoly, b: IntPoly, p: bigint): IntPoly;
|
|
49
|
+
/**
|
|
50
|
+
* `base^e mod (mod, p)`: modular exponentiation of `base` by non-negative
|
|
51
|
+
* bigint `e`, reducing modulo the polynomial `mod` (via `divmodP`) and
|
|
52
|
+
* modulo `p` at each step, using square-and-multiply. `e` must be >= 0.
|
|
53
|
+
*/
|
|
54
|
+
export declare function powModPolyP(base: IntPoly, e: bigint, mod: IntPoly, p: bigint): IntPoly;
|
|
55
|
+
/**
|
|
56
|
+
* Distinct-degree factorization of a monic, square-free polynomial `f` over
|
|
57
|
+
* 𝔽_p. Returns the distinct-degree decomposition: each entry's `prod` is the
|
|
58
|
+
* product of ALL monic irreducible factors of `f` that have degree exactly
|
|
59
|
+
* `deg`. Uses the standard algorithm built on `x^(p^i) mod f` computed via
|
|
60
|
+
* `powModPolyP`, peeling off `gcd(v, x^(p^i) - x)` at each step and shrinking
|
|
61
|
+
* the working polynomial `v` as factors are removed.
|
|
62
|
+
*
|
|
63
|
+
* Precondition: `f` is monic and square-free over 𝔽_p. The empty array is
|
|
64
|
+
* returned for a constant (degree ≤ 0) input.
|
|
65
|
+
*/
|
|
66
|
+
export declare function distinctDegreeFactor(f: IntPoly, p: bigint): Array<{
|
|
67
|
+
deg: number;
|
|
68
|
+
prod: IntPoly;
|
|
69
|
+
}>;
|
|
70
|
+
/**
|
|
71
|
+
* Equal-degree factorization (Cantor–Zassenhaus): given a monic, square-free
|
|
72
|
+
* `f` that is a product of degree-`d` irreducibles over 𝔽_p, returns those
|
|
73
|
+
* monic irreducible factors. The candidate polynomials are enumerated
|
|
74
|
+
* deterministically (see `trialPolys`), so the factorization is reproducible.
|
|
75
|
+
*/
|
|
76
|
+
export declare function equalDegreeFactor(f: IntPoly, d: number, p: bigint): IntPoly[];
|
|
77
|
+
/**
|
|
78
|
+
* Full factorization of a square-free monic polynomial `f` over 𝔽_p into its
|
|
79
|
+
* monic irreducible factors: distinct-degree decomposition followed by
|
|
80
|
+
* Cantor–Zassenhaus equal-degree splitting of each degree class. Constant
|
|
81
|
+
* (degree ≤ 0) inputs yield the empty array; a linear input yields itself.
|
|
82
|
+
*/
|
|
83
|
+
export declare function factorModP(f: IntPoly, p: bigint): IntPoly[];
|
|
84
|
+
//# sourceMappingURL=finite-field.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finite-field.d.ts","sourceRoot":"","sources":["../../../src/typed/factorization/finite-field.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAA4B,KAAK,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE3E,YAAY,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAQjD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED,6DAA6D;AAC7D,wBAAgB,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAS/D;AAED,6DAA6D;AAC7D,wBAAgB,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAS/D;AAED,8EAA8E;AAC9E,wBAAgB,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAe/D;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAiBpD;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAOzD;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,GAAG;IAAE,CAAC,EAAE,OAAO,CAAC;IAAC,CAAC,EAAE,OAAO,CAAA;CAAE,CAqBrF;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAe/D;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAetF;AAKD;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CAyBjG;AAyED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,EAAE,CAI7E;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,EAAE,CAoB3D"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multifactor Hensel lifting for the univariate factorization engine
|
|
3
|
+
* (`functions/src/typed/factorization/`).
|
|
4
|
+
*
|
|
5
|
+
* Given a MONIC integer polynomial `f` and its MONIC irreducible factors over
|
|
6
|
+
* 𝔽_p (whose product is ≡ f mod p), lift that factorization to a factorization
|
|
7
|
+
* modulo `p^k` whose product is ≡ f (mod p^k), with each lifted factor still
|
|
8
|
+
* ≡ its input factor (mod p). The target modulus `p^k` is chosen by the caller
|
|
9
|
+
* so that `p^k ≥ 2·landauMignotte(f)+1`, i.e. large enough that the true
|
|
10
|
+
* integer factors of `f` are uniquely recovered by symmetric reduction.
|
|
11
|
+
*
|
|
12
|
+
* Strategy: LINEAR (iterated) two-factor Hensel lifting from `p^i` to `p^{i+1}`
|
|
13
|
+
* up to `p^k`, combined with a recursive FACTOR TREE for more than two factors.
|
|
14
|
+
* Bézout cofactors `s, t` with `s·g + t·h ≡ 1 (mod p)` are computed once per
|
|
15
|
+
* two-factor split via the extended Euclidean algorithm over 𝔽_p; because the
|
|
16
|
+
* per-step diophantine correction is solved only mod p, the fixed mod-p
|
|
17
|
+
* cofactors remain valid at every lifting step (the standard property of linear
|
|
18
|
+
* Hensel lifting — see Geddes/Czapor/Labahn §6.4 or von zur Gathen & Gerhard
|
|
19
|
+
* §15). All factors are monic and `f` is monic, so the lifted factors stay
|
|
20
|
+
* monic and no leading-coefficient imposition is required.
|
|
21
|
+
*
|
|
22
|
+
* `bigint`-only by design: float64 loses correctness once `p^k > 2^53`.
|
|
23
|
+
*/
|
|
24
|
+
import { type IntPoly } from './integer-poly.js';
|
|
25
|
+
/**
|
|
26
|
+
* Multifactor Hensel lift. Lifts the mod-`p` factorization `factorsModP` of the
|
|
27
|
+
* monic integer polynomial `f` (with `∏ factorsModP ≡ f mod p`) to monic
|
|
28
|
+
* integer factors whose product is `≡ f (mod targetPk)` and each of which is
|
|
29
|
+
* `≡ its input factor (mod p)`. Coefficients are returned in the symmetric
|
|
30
|
+
* range modulo `targetPk = p^k` (via `modSymmetric`).
|
|
31
|
+
*
|
|
32
|
+
* More than two factors are handled by a recursive factor tree: `factorsModP`
|
|
33
|
+
* is split into two halves, the two half-products are lifted together by
|
|
34
|
+
* `henselLiftTwo`, and each lifted half is recursively split into its own
|
|
35
|
+
* factors.
|
|
36
|
+
*/
|
|
37
|
+
export declare function henselLift(f: IntPoly, factorsModP: IntPoly[], p: bigint, targetPk: bigint): IntPoly[];
|
|
38
|
+
//# sourceMappingURL=hensel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hensel.d.ts","sourceRoot":"","sources":["../../../src/typed/factorization/hensel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAQL,KAAK,OAAO,EACb,MAAM,mBAAmB,CAAC;AA8H3B;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CACxB,CAAC,EAAE,OAAO,EACV,WAAW,EAAE,OAAO,EAAE,EACtB,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,MAAM,GACf,OAAO,EAAE,CAmBX"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public entry point of the univariate factorization engine: parse an
|
|
3
|
+
* expression string into an integer polynomial, run the Zassenhaus pipeline
|
|
4
|
+
* (`factorUnivariateZ`), and render the irreducible factorization back to a
|
|
5
|
+
* string that matches `algebra.ts`'s `factor()` output conventions.
|
|
6
|
+
*
|
|
7
|
+
* This module is deliberately self-contained (it does not import `algebra.ts`)
|
|
8
|
+
* so wiring it into `factor()` introduces no import cycle. It reuses the shared
|
|
9
|
+
* polynomial parser from `../polynomial-ideal.js` and the `bigint` engine from
|
|
10
|
+
* this directory.
|
|
11
|
+
*
|
|
12
|
+
* Part of the univariate factorization engine
|
|
13
|
+
* (`functions/src/typed/factorization/`).
|
|
14
|
+
*/
|
|
15
|
+
import { type IntPoly } from './integer-poly.js';
|
|
16
|
+
/**
|
|
17
|
+
* Render a dense integer-coefficient univariate polynomial as a bare (no outer
|
|
18
|
+
* parentheses) human-readable string with the repo's spacing/`*`/`^` style and
|
|
19
|
+
* unit coefficients elided: `[1,0,1] → "x^2 + 1"`, `[-1,0,2] → "2*x^2 - 1"`.
|
|
20
|
+
* Coefficients are rounded for display; zero terms are omitted. Exported so
|
|
21
|
+
* `algebra.ts` can render an unfactorable higher-degree remainder consistently.
|
|
22
|
+
*/
|
|
23
|
+
export declare function cleanUnivariatePoly(coeffs: number[], v: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Render one irreducible factor: linears via {@link renderLinearFactor},
|
|
26
|
+
* higher via {@link renderIntPoly} (bigint-native — see its doc comment for
|
|
27
|
+
* why this must not go through `Number()`) wrapped in parentheses. Exported
|
|
28
|
+
* for direct unit testing of the bigint-fidelity path.
|
|
29
|
+
*/
|
|
30
|
+
export declare function renderFactor(poly: IntPoly, v: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Factor a univariate integer polynomial given as an expression string into
|
|
33
|
+
* its irreducible factors over ℤ/ℚ, rendered to a `*`-joined string matching
|
|
34
|
+
* `factor()`'s conventions (constant prefix when ≠ 1, degree-1 factors via the
|
|
35
|
+
* linear formatter, degree ≥ 2 factors wrapped in parentheses, repeated factors
|
|
36
|
+
* for multiplicity > 1).
|
|
37
|
+
*
|
|
38
|
+
* Returns `null` when the input is not an integer polynomial in `v` (parse
|
|
39
|
+
* failure, another variable, non-integer coefficients, degree < 1) OR when the
|
|
40
|
+
* polynomial is already irreducible over ℚ (a single primitive factor with
|
|
41
|
+
* multiplicity 1) — in that "nothing gained" case the caller keeps its existing
|
|
42
|
+
* behavior (leaving the expression whole / doing plain content extraction).
|
|
43
|
+
* Factor order is `factorUnivariateZ`'s deterministic (degree, coefficients)
|
|
44
|
+
* order.
|
|
45
|
+
*/
|
|
46
|
+
export declare function factorPolynomialUnivariate(expr: string, v: string): string | null;
|
|
47
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/typed/factorization/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAU,KAAK,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAsBzD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAoBvE;AA8CD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAG7D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CA0BjF"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dense univariate polynomial arithmetic over ℤ, backed by `bigint[]`.
|
|
3
|
+
*
|
|
4
|
+
* Convention: index = degree (coefficient of x^i lives at index i).
|
|
5
|
+
* `[]` denotes the zero polynomial. After `trim`, the last entry (highest
|
|
6
|
+
* degree) is guaranteed nonzero. `degree([])` is -1 by convention.
|
|
7
|
+
*
|
|
8
|
+
* This module is part of the univariate factorization engine
|
|
9
|
+
* (`functions/src/typed/factorization/`) and is `bigint`-only by design:
|
|
10
|
+
* float64 loses correctness once coefficients exceed 2^53 during Hensel
|
|
11
|
+
* lifting to p^k.
|
|
12
|
+
*/
|
|
13
|
+
/** Dense polynomial over ℤ: index i holds the coefficient of x^i. */
|
|
14
|
+
export type IntPoly = bigint[];
|
|
15
|
+
/**
|
|
16
|
+
* Removes trailing (highest-degree) zero coefficients so the last entry
|
|
17
|
+
* (if any) is nonzero. Does not mutate the input.
|
|
18
|
+
*/
|
|
19
|
+
export declare function trim(p: IntPoly): IntPoly;
|
|
20
|
+
/** Degree of `p`; the zero polynomial has degree -1 by convention. */
|
|
21
|
+
export declare function degree(p: IntPoly): number;
|
|
22
|
+
/** Leading coefficient of `p` (0n for the zero polynomial). */
|
|
23
|
+
export declare function lc(p: IntPoly): bigint;
|
|
24
|
+
/** True iff `p` is the zero polynomial (ignoring trailing zero padding). */
|
|
25
|
+
export declare function isZero(p: IntPoly): boolean;
|
|
26
|
+
/** `a + b`, trimmed. */
|
|
27
|
+
export declare function add(a: IntPoly, b: IntPoly): IntPoly;
|
|
28
|
+
/** `a - b`, trimmed. */
|
|
29
|
+
export declare function sub(a: IntPoly, b: IntPoly): IntPoly;
|
|
30
|
+
/** `-a`, trimmed. */
|
|
31
|
+
export declare function neg(a: IntPoly): IntPoly;
|
|
32
|
+
/** `a * b` via the schoolbook convolution, trimmed. */
|
|
33
|
+
export declare function mul(a: IntPoly, b: IntPoly): IntPoly;
|
|
34
|
+
/** `p * k` for a scalar `k: bigint`, trimmed. */
|
|
35
|
+
export declare function scalarMul(p: IntPoly, k: bigint): IntPoly;
|
|
36
|
+
/** Structural equality after trimming (so trailing-zero padding is ignored). */
|
|
37
|
+
export declare function equals(a: IntPoly, b: IntPoly): boolean;
|
|
38
|
+
/** Evaluates `p(x)` at a bigint `x` via Horner's method. */
|
|
39
|
+
export declare function evaluate(p: IntPoly, x: bigint): bigint;
|
|
40
|
+
/** Non-negative gcd of two bigints (gcd(0,0) = 0). */
|
|
41
|
+
export declare function bigintGcd(a: bigint, b: bigint): bigint;
|
|
42
|
+
/** Content of `p`: the non-negative gcd of its (trimmed) coefficients. */
|
|
43
|
+
export declare function content(p: IntPoly): bigint;
|
|
44
|
+
/**
|
|
45
|
+
* Primitive part of `p`: divide out the content, then flip sign so the
|
|
46
|
+
* leading coefficient is positive. The zero polynomial maps to itself.
|
|
47
|
+
*/
|
|
48
|
+
export declare function primitivePart(p: IntPoly): IntPoly;
|
|
49
|
+
/**
|
|
50
|
+
* Exact polynomial quotient `a / b` over ℤ: performs schoolbook long division
|
|
51
|
+
* and returns the quotient only if the remainder is exactly zero AND every
|
|
52
|
+
* intermediate coefficient division was integral (no rounding). Returns
|
|
53
|
+
* `null` whenever `b` does not divide `a` exactly over ℤ. This is the
|
|
54
|
+
* recombination correctness test used by subset factor-recombination —
|
|
55
|
+
* it must never silently round.
|
|
56
|
+
*/
|
|
57
|
+
export declare function exactDivide(a: IntPoly, b: IntPoly): IntPoly | null;
|
|
58
|
+
/** Formal derivative `p'` over ℤ: coefficient i*p[i] at index i-1. */
|
|
59
|
+
export declare function derivative(p: IntPoly): IntPoly;
|
|
60
|
+
/**
|
|
61
|
+
* Gcd of two polynomials over ℤ via the Euclidean pseudo-remainder sequence
|
|
62
|
+
* (stays in ℤ throughout via pseudo-division), returned as a primitive
|
|
63
|
+
* polynomial with positive leading coefficient. `gcd(0, b) = primitivePart(b)`
|
|
64
|
+
* and symmetrically for `gcd(a, 0)`; `gcd(0,0) = []`.
|
|
65
|
+
*/
|
|
66
|
+
export declare function polyGcdZ(a: IntPoly, b: IntPoly): IntPoly;
|
|
67
|
+
/**
|
|
68
|
+
* Landau–Mignotte coefficient bound: any integer factor of `p` has all
|
|
69
|
+
* coefficients bounded in absolute value by this quantity. Uses the
|
|
70
|
+
* generous form `ceil(sqrt(deg+1) * 2^deg * |lc(p)|)`, computed entirely
|
|
71
|
+
* with bigint integer arithmetic (integer sqrt rounded UP so the bound
|
|
72
|
+
* stays safe/over-estimating). Always positive.
|
|
73
|
+
*/
|
|
74
|
+
export declare function landauMignotte(p: IntPoly): bigint;
|
|
75
|
+
/**
|
|
76
|
+
* Reduces every coefficient of `p` into the symmetric residue range
|
|
77
|
+
* `(-m/2, m/2]` modulo `m`. `m` must be a positive modulus. Coefficient
|
|
78
|
+
* count is preserved (no trailing-zero trim) — a coefficient that reduces
|
|
79
|
+
* to 0 mod `m` stays as an explicit 0 at its original index.
|
|
80
|
+
*/
|
|
81
|
+
export declare function modSymmetric(p: IntPoly, m: bigint): IntPoly;
|
|
82
|
+
//# sourceMappingURL=integer-poly.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integer-poly.d.ts","sourceRoot":"","sources":["../../../src/typed/factorization/integer-poly.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,qEAAqE;AACrE,MAAM,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC;AAE/B;;;GAGG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAMxC;AAED,sEAAsE;AACtE,wBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAGzC;AAED,+DAA+D;AAC/D,wBAAgB,EAAE,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAGrC;AAED,4EAA4E;AA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AC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAkBxD;AAmBD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAejD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAa3D"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Yun's square-free decomposition over ℤ.
|
|
3
|
+
*
|
|
4
|
+
* Given a nonzero integer polynomial `f`, decomposes `primitivePart(f)` into
|
|
5
|
+
* pairwise-coprime square-free factors with multiplicities such that
|
|
6
|
+
* `primitivePart(f) = ∏ factorᵢ^multᵢ` (up to sign — each returned `factor`
|
|
7
|
+
* is normalized to have a positive leading coefficient via `primitivePart`).
|
|
8
|
+
*
|
|
9
|
+
* This is the classical characteristic-0 algorithm (valid over any field of
|
|
10
|
+
* characteristic 0, hence over ℤ via `polyGcdZ`/`exactDivide`): let
|
|
11
|
+
* `g = gcd(f, f')`, `c = f/g`, `w = f'/g`. Then repeatedly peel off the
|
|
12
|
+
* square-free part at multiplicity `i` via `y = gcd(c, w)`,
|
|
13
|
+
* `factor = c/y`, `c = y`, `w = w/y - factor'`.
|
|
14
|
+
*
|
|
15
|
+
* Part of the univariate factorization engine
|
|
16
|
+
* (`functions/src/typed/factorization/`) — bigint-only.
|
|
17
|
+
*/
|
|
18
|
+
import { type IntPoly } from './integer-poly.js';
|
|
19
|
+
/** One square-free factor of the input, with its multiplicity in the input. */
|
|
20
|
+
export interface SquareFreeFactor {
|
|
21
|
+
factor: IntPoly;
|
|
22
|
+
mult: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Yun square-free decomposition of `f` over ℤ. `f` must be nonzero (may be
|
|
26
|
+
* non-primitive; the content is discarded — decomposition operates on
|
|
27
|
+
* `primitivePart(f)`). Trivial degree-0 (constant) factors are never
|
|
28
|
+
* included in the output.
|
|
29
|
+
*
|
|
30
|
+
* Recurrence (standard Yun, char 0): with `g = gcd(f, f')`,
|
|
31
|
+
* `b0 = f/g`, `c0 = f'/g`, `d0 = c0 - b0'`. At each step `i = 1, 2, …`
|
|
32
|
+
* (while `deg(b) > 0`): `aᵢ = gcd(b, d)` is the square-free factor of
|
|
33
|
+
* multiplicity `i` (possibly a unit, i.e. degree 0, meaning multiplicity `i`
|
|
34
|
+
* is absent); `b ← b/aᵢ`, `c ← d/aᵢ`, `d ← c - b'` for the next round.
|
|
35
|
+
*/
|
|
36
|
+
export declare function squareFreeDecompose(f: IntPoly): SquareFreeFactor[];
|
|
37
|
+
//# sourceMappingURL=square-free.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"square-free.d.ts","sourceRoot":"","sources":["../../../src/typed/factorization/square-free.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAOL,KAAK,OAAO,EACb,MAAM,mBAAmB,CAAC;AAE3B,+EAA+E;AAC/E,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,OAAO,GAAG,gBAAgB,EAAE,CAkClE"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Univariate polynomial factorization over ℤ — the top-level Zassenhaus
|
|
3
|
+
* pipeline that ties together the factorization engine modules.
|
|
4
|
+
*
|
|
5
|
+
* Pipeline:
|
|
6
|
+
* 1. Strip integer content and sign (constant prefix).
|
|
7
|
+
* 2. Yun square-free decomposition (`squareFreeDecompose`).
|
|
8
|
+
* 3. For each square-free primitive part `g` (possibly non-monic):
|
|
9
|
+
* pick a prime `p` with `p ∤ lc(g)` and image square-free mod p (fewest
|
|
10
|
+
* modular factors among the first candidates), factor `g` mod p, choose
|
|
11
|
+
* `k` with `p^k` large enough (Landau–Mignotte, with the extra leading
|
|
12
|
+
* coefficient factor), build the monic integer associate of `g` mod p^k,
|
|
13
|
+
* Hensel-lift the mod-p factors, then recombine subsets by exact division
|
|
14
|
+
* over ℤ (the leading-coefficient method for non-monic `g`).
|
|
15
|
+
* 4. Emit each irreducible factor with the multiplicity of its square-free
|
|
16
|
+
* level; sort deterministically.
|
|
17
|
+
*
|
|
18
|
+
* Part of the univariate factorization engine
|
|
19
|
+
* (`functions/src/typed/factorization/`) — `bigint`-only by design.
|
|
20
|
+
*/
|
|
21
|
+
import { type IntPoly } from './integer-poly.js';
|
|
22
|
+
/** Result of factoring an integer polynomial: a constant times irreducibles. */
|
|
23
|
+
export type Factorization = {
|
|
24
|
+
constant: bigint;
|
|
25
|
+
factors: Array<{
|
|
26
|
+
poly: IntPoly;
|
|
27
|
+
mult: number;
|
|
28
|
+
}>;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Full univariate factorization of `f` over ℤ into a constant times
|
|
32
|
+
* irreducible primitive factors with multiplicities. Trivial inputs (zero,
|
|
33
|
+
* constant, degree ≤ 1) short-circuit.
|
|
34
|
+
*/
|
|
35
|
+
export declare function factorUnivariateZ(f: IntPoly): Factorization;
|
|
36
|
+
//# sourceMappingURL=zassenhaus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zassenhaus.d.ts","sourceRoot":"","sources":["../../../src/typed/factorization/zassenhaus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAaL,KAAK,OAAO,EACb,MAAM,mBAAmB,CAAC;AAK3B,gFAAgF;AAChF,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACjD,CAAC;AA2NF;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,OAAO,GAAG,aAAa,CA4B3D"}
|
package/package.json
CHANGED