@danielsimonjr/mathts-functions 0.58.0 → 0.60.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/cas/rational-integrate.d.ts +142 -0
- package/dist/cas/rational-integrate.d.ts.map +1 -0
- package/dist/cas-integration.d.ts +7 -2
- package/dist/cas-integration.d.ts.map +1 -1
- package/dist/index.js +1060 -136
- package/dist/typed/algebra.d.ts +14 -6
- package/dist/typed/algebra.d.ts.map +1 -1
- package/dist/typed/factorization/index.d.ts +25 -0
- package/dist/typed/factorization/index.d.ts.map +1 -1
- package/dist/typed/factorization/kronecker-factor.d.ts +48 -0
- package/dist/typed/factorization/kronecker-factor.d.ts.map +1 -0
- package/dist/typed/factorization/kronecker.d.ts +65 -0
- package/dist/typed/factorization/kronecker.d.ts.map +1 -0
- package/dist/typed/factorization/multi-poly.d.ts +107 -0
- package/dist/typed/factorization/multi-poly.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Layer 1 rational-function symbolic integration — Task 1: parse a
|
|
3
|
+
* single-variable rational-function expression into exact integer
|
|
4
|
+
* numerator/denominator polynomials, split off the polynomial part via
|
|
5
|
+
* exact-ℚ long division, and integrate a polynomial termwise (power rule).
|
|
6
|
+
*
|
|
7
|
+
* Reuses the univariate expression parser (`polyFromExpression`, from the
|
|
8
|
+
* Gröbner-basis module) for parsing and the bigint dense-polynomial
|
|
9
|
+
* convention (`IntPoly`, index = degree) from the #7 factorization engine
|
|
10
|
+
* for the integer representation.
|
|
11
|
+
*
|
|
12
|
+
* See docs/superpowers/plans/2026-07-20-risch-layer1-rational-integration.md
|
|
13
|
+
* (Task 1). Later tasks build denominator factorization, exact-ℚ partial
|
|
14
|
+
* fractions, and per-factor closed-form integration on top of this module.
|
|
15
|
+
*/
|
|
16
|
+
import { type IntPoly } from '../typed/factorization/integer-poly.js';
|
|
17
|
+
/** Exact rational number, always normalized to lowest terms with a positive denominator. */
|
|
18
|
+
export interface Rat {
|
|
19
|
+
num: bigint;
|
|
20
|
+
den: bigint;
|
|
21
|
+
}
|
|
22
|
+
/** A rational function `numer(x)/denom(x)` with integer dense (`IntPoly`) coefficients. */
|
|
23
|
+
export interface RatFunc {
|
|
24
|
+
numer: IntPoly;
|
|
25
|
+
denom: IntPoly;
|
|
26
|
+
}
|
|
27
|
+
export declare function ratAdd(a: Rat, b: Rat): Rat;
|
|
28
|
+
export declare function ratSub(a: Rat, b: Rat): Rat;
|
|
29
|
+
export declare function ratMul(a: Rat, b: Rat): Rat;
|
|
30
|
+
export declare function ratDiv(a: Rat, b: Rat): Rat;
|
|
31
|
+
export declare function ratFromBigint(n: bigint): Rat;
|
|
32
|
+
/**
|
|
33
|
+
* Parses a single-variable expression `numerExpr/denomExpr` (or a bare
|
|
34
|
+
* polynomial, denominator `[1n]`) into integer numerator/denominator dense
|
|
35
|
+
* polynomials. Rational coefficients are cleared by the LCM of their
|
|
36
|
+
* denominators (numerator and denominator are each cleared independently,
|
|
37
|
+
* then cross-scaled by the other's factor so the represented ratio
|
|
38
|
+
* `numer(x)/denom(x)` is unchanged).
|
|
39
|
+
*
|
|
40
|
+
* Returns `null` when `expr` is not a rational function of `v`: it contains
|
|
41
|
+
* a transcendental call (`sin`/`exp`/... — any identifier other than `v`),
|
|
42
|
+
* more than one variable, a zero denominator, or coefficients that cannot be
|
|
43
|
+
* cleared to integers.
|
|
44
|
+
*/
|
|
45
|
+
export declare function parseRationalFunction(expr: string, v: string): RatFunc | null;
|
|
46
|
+
/**
|
|
47
|
+
* Exact-ℚ polynomial long division of `rf.numer` by `rf.denom`:
|
|
48
|
+
* `numer = quotient·denom + remainder`, `deg(remainder) < deg(denom)`.
|
|
49
|
+
* Division is performed over ℚ (so a non-monic denominator is handled
|
|
50
|
+
* correctly); the result is converted back to `bigint` coefficients, which
|
|
51
|
+
* requires every intermediate `Rat` to reduce to an integer denominator —
|
|
52
|
+
* true whenever the division is itself exact-integer, as it is for a
|
|
53
|
+
* genuine rational-function reduction. Throws if it is not (a caller that
|
|
54
|
+
* expects a non-integer quotient/remainder is out of this module's scope).
|
|
55
|
+
*/
|
|
56
|
+
export declare function polynomialPart(rf: RatFunc): {
|
|
57
|
+
quotient: IntPoly;
|
|
58
|
+
remainder: IntPoly;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Termwise power rule: the coefficient `c` at degree `n` in `p` integrates
|
|
62
|
+
* to `c/(n+1) · v^(n+1)`. Renders a readable (not contractual beyond
|
|
63
|
+
* containing the expected power) string, e.g. `x^2/2`, `2*x`.
|
|
64
|
+
*/
|
|
65
|
+
export declare function integratePolynomial(p: IntPoly, v: string): string;
|
|
66
|
+
/**
|
|
67
|
+
* An irreducible factor of a rational function's denominator, classified by
|
|
68
|
+
* degree for Layer 1 closed-form integration: degree 1 ("linear") integrates
|
|
69
|
+
* to a `log`, degree 2 ("quadratic") to a `log` + `atan` pair. Degree ≥ 3
|
|
70
|
+
* irreducible factors are outside Layer 1's scope (see `factorDenominator`).
|
|
71
|
+
*/
|
|
72
|
+
export interface DenFactor {
|
|
73
|
+
poly: IntPoly;
|
|
74
|
+
mult: number;
|
|
75
|
+
kind: 'linear' | 'quadratic';
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Factors `denom` completely over ℤ/ℚ via the #7 factorization engine
|
|
79
|
+
* (`factorUnivariateZ`) and classifies each irreducible factor by degree.
|
|
80
|
+
*
|
|
81
|
+
* A degree-1 factor is `'linear'`; a degree-2 factor is `'quadratic'` — and,
|
|
82
|
+
* having survived complete factorization over ℚ, necessarily irreducible
|
|
83
|
+
* (any rational root would already have split it into two linear factors,
|
|
84
|
+
* i.e. it has negative discriminant).
|
|
85
|
+
*
|
|
86
|
+
* Returns `null` when any irreducible factor has degree ≥ 3: Layer 1 only
|
|
87
|
+
* handles linear + irreducible-quadratic denominators, so a higher-degree
|
|
88
|
+
* irreducible factor is out of scope and the caller falls back to the
|
|
89
|
+
* `integral(...)` marker (Layer 2/Rothstein–Trager territory).
|
|
90
|
+
*/
|
|
91
|
+
export declare function factorDenominator(denom: IntPoly): DenFactor[] | null;
|
|
92
|
+
/**
|
|
93
|
+
* A single partial-fraction term `numer(x) / factor(x)^power`. `numer` is a
|
|
94
|
+
* `Rat[]` of fixed length `deg(factor)` (index = degree, ascending — the same
|
|
95
|
+
* convention as `IntPoly`): length 1 (a constant) over a linear factor,
|
|
96
|
+
* length 2 (`[E, D]` meaning `D*x + E`) over a quadratic factor.
|
|
97
|
+
*/
|
|
98
|
+
export interface PFTerm {
|
|
99
|
+
factor: IntPoly;
|
|
100
|
+
power: number;
|
|
101
|
+
numer: Rat[];
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Exact-ℚ partial-fraction decomposition of `remainder(x) / ∏ factorᵢ(x)^multᵢ`
|
|
105
|
+
* (`deg(remainder) < deg(∏ factorᵢ^multᵢ)`, as produced by `polynomialPart`)
|
|
106
|
+
* into the standard form: for each irreducible factor `qᵢ` with multiplicity
|
|
107
|
+
* `mᵢ`, terms `A_{i,k}(x) / qᵢ(x)^k` for `k = 1..mᵢ`, `deg A_{i,k} < deg qᵢ`.
|
|
108
|
+
*
|
|
109
|
+
* Solved by clearing denominators: multiplying the ansatz by the full
|
|
110
|
+
* denominator `D = ∏ factorⱼ^multⱼ` turns each unknown numerator coefficient
|
|
111
|
+
* into a linear unknown whose column is the polynomial
|
|
112
|
+
* `x^j · qᵢ(x)^{mᵢ−k} · ∏_{j≠i} factorⱼ(x)^multⱼ` (a plain integer polynomial
|
|
113
|
+
* product — no division is ever needed, since `mᵢ−k ≥ 0`). Equating
|
|
114
|
+
* coefficients of `remainder(x)` on both sides gives a square (`deg D` ×
|
|
115
|
+
* `deg D`) rational linear system, solved exactly via `solveLinearSystemRat`.
|
|
116
|
+
*/
|
|
117
|
+
export declare function partialFractions(remainder: IntPoly, factors: DenFactor[]): PFTerm[];
|
|
118
|
+
/**
|
|
119
|
+
* Integrates a single partial-fraction term in closed form. Dispatches on the
|
|
120
|
+
* degree of `term.factor`: degree 1 → `log` (+ rational part for a repeated
|
|
121
|
+
* factor); degree 2 (irreducible, disc < 0) → `log`/rational part + `atan`.
|
|
122
|
+
* The produced string is evaluable by the expression engine (`log`, `atan`,
|
|
123
|
+
* `sqrt`, `abs`, `^`, `*`); its exact form is not contractual — correctness is
|
|
124
|
+
* verified by differentiation. Throws on any other factor degree (unreachable
|
|
125
|
+
* for a `factorDenominator`-classified factor).
|
|
126
|
+
*/
|
|
127
|
+
export declare function integratePFTerm(term: PFTerm, v: string): string;
|
|
128
|
+
/**
|
|
129
|
+
* Full Layer-1 rational-function integration pipeline. Parses `expr` into an
|
|
130
|
+
* exact integer rational function, splits off and integrates the polynomial
|
|
131
|
+
* part, factors the denominator into linear + irreducible-quadratic factors,
|
|
132
|
+
* decomposes into exact-ℚ partial fractions, and integrates each term in
|
|
133
|
+
* closed form (rational part + `log` + `atan`).
|
|
134
|
+
*
|
|
135
|
+
* Returns `null` when `expr` is not a rational function of `v`
|
|
136
|
+
* (`parseRationalFunction` declines), when the denominator has a degree-≥3
|
|
137
|
+
* irreducible factor (`factorDenominator` declines — Layer 2 territory), or
|
|
138
|
+
* when any internal step throws (e.g. a non-integer polynomial-part division),
|
|
139
|
+
* so callers get a clean decline rather than an exception.
|
|
140
|
+
*/
|
|
141
|
+
export declare function integrateRationalFunction(expr: string, v: string): string | null;
|
|
142
|
+
//# sourceMappingURL=rational-integrate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rational-integrate.d.ts","sourceRoot":"","sources":["../../src/cas/rational-integrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAKL,KAAK,OAAO,EACb,MAAM,wCAAwC,CAAC;AAGhD,4FAA4F;AAC5F,MAAM,WAAW,GAAG;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC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KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,GAAG,EAAE,CAAC;CACd;AA0DD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,CA4EnF;AAkLD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAU/D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CA+ChF"}
|
|
@@ -4,12 +4,17 @@
|
|
|
4
4
|
* integrand is outside the supported subset, returns `integral(expr, variable)`.
|
|
5
5
|
*
|
|
6
6
|
* The direct recursion is tried first; on failure, partial-fraction integration
|
|
7
|
-
* (for rational integrands)
|
|
8
|
-
* polynomial·{exp,sin,cos})
|
|
7
|
+
* (for distinct-rational-root integrands), tabular integration by parts (for
|
|
8
|
+
* polynomial·{exp,sin,cos}), and full rational-function integration (Risch
|
|
9
|
+
* Layer 1) are attempted before giving up with the marker. Rational functions
|
|
10
|
+
* with irreducible-quadratic and repeated factors are now integrated (rational
|
|
11
|
+
* part + `log` + `arctan`); degree-≥3 irreducible denominators and transcendental
|
|
12
|
+
* Risch remain out of scope (marker).
|
|
9
13
|
*
|
|
10
14
|
* @example symbolicIntegral('x^3') // 'x^4 / 4'
|
|
11
15
|
* @example symbolicIntegral('cos(3*x + 1)') // 'sin(3 * x + 1) / 3'
|
|
12
16
|
* @example symbolicIntegral('1/(x^2 - 1)') // partial fractions → sum of logs
|
|
17
|
+
* @example symbolicIntegral('1/(x^2 + 1)') // Risch Layer 1 → 'atan(...)'
|
|
13
18
|
* @example symbolicIntegral('x * sin(x)') // by parts → 'sin(x) - x*cos(x)'
|
|
14
19
|
*/
|
|
15
20
|
export declare function symbolicIntegral(expr: string, variable?: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cas-integration.d.ts","sourceRoot":"","sources":["../src/cas-integration.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cas-integration.d.ts","sourceRoot":"","sources":["../src/cas-integration.ts"],"names":[],"mappings":"AA2WA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,SAAM,GAAG,MAAM,CAYrE"}
|