asc-community / asc-community/AngouriMath
A sum over the roots of a polynomial, so that a rational function with an irreducible denominator can be integrated
- Dominant language
- C#
- Stars
- 831
- Forks
- 79
- Avg merge
- 3h 23m
- Merged PRs (30d)
- 309
Description
## The integral
```
integral sqrt(x)/(1 + x + x^4) dx
```
is elementary, and this library declines it. Under `u = sqrt(x)` it is `2u^2/(1 + u^2 + u^8)`, a rational function whose denominator is irreducible over the rationals, is not a biquadratic and is not a binomial — so none of the three splits the rational integrator has can take it apart, and it comes back unevaluated. Wolfram Alpha gives
```
sum_({ω: ω^8 + ω^2 + 1 = 0}) (ω log(sqrt(x) - ω))/(4 ω^6 + 1) + constant
```
which is the general form: a sum over the roots of a polynomial, with a logarithm at each root. It was the pinned boundary of `PowerSubstitutionIntegralTest.WhereTheChainStops` in #1284, and the review there is right that a boundary this library cannot represent an answer for should be an issue rather than a test (https://github.com/asc-community/AngouriMath/pull/1284#issuecomment-5637025001).
## What the answer is
For `P/Q` with `deg P < deg Q` and `Q` squarefree, the antiderivative is
```
sum over roots r of Q of (P(r)/Q'(r)) * ln(x - r)
```
exactly — the residue at each simple pole times the logarithm there. That is what the Rothstein–Trager theorem states; the Lazard–Rioboo–Trager refinement writes the same sum over the roots of the *resultant* `R(t) = res_x(P - t Q', Q)` rather than of `Q`, which groups the roots that share a residue and keeps the algebraic extension as small as it can be. Every computer algebra system that answers this integral answers it in that form. `IntegrateAPolynomialOverABinomial` (#1284) is the special case where `Q = a x^n + b`, whose roots are known in closed form and pair off into real logarithms and arctangents; this issue is the general case, where they are not.
## What is missing is a node, not a rule
The rule is two lines once the answer can be written down. What cannot be written down today is *a sum over the roots of a polynomial* when those roots have no closed form. Three shapes to consider:
1. **A `RootSum(polynomial, variable, expression)` node** — the way Maxima's `rootsum`, Maple's `RootOf`/`sum`, and SymPy's `RootSum(Poly, Lambda)` do it. Evaluates numerically by finding the roots; simplifies when the polynomial factors; differentiates termwise under the sum, so the differentiate-back check still applies. Prints as the sum above.
2. **A `RootOf(polynomial, index)` node** and an ordinary `Sumf` over indices — finer, since a single root is then a value in its own right (a quintic's roots could be spoken of), but the index has to mean something stable, and ordering complex roots is exactly the mess every system with `RootOf` has to document.
3. **Decline**, and record the reason in the answer — which is what happens now, without the reason.
The first is the smallest change that makes the integral answerable, and it is also what a sum over roots *is*. It touches the printers, `Evaled`/`EvalNumerical`, `Differentiate`, `Substitute` and the parser, which is why it is an issue and not a PR.
## What it would answer
Rubi's test suite has these by the dozen: every `P/Q` whose `Q` is irreducible of degree three or more and not a binomial. In the 463-problem sample run here, `1/(x^3 + x + 1)` is the smallest, and `x/(1 + x + x^5)`, `(x^2 + 1)/(x^4 + x + 1)` and the like sit behind it. With the node, the rational integrator is complete for squarefree denominators; a repeated factor is then the Hermite reduction on top of it, which is a rule again.
Part of #718.
Contributor guide
Research direction
Start by tracing the rational integrator and the existing Evaled/EvalNumerical, Differentiate, Substitute, printer, and parser paths mentioned in the issue. Compare the proposed RootSum design with the existing Sumf behavior and the integration tests described. Done means a root-sum representation can express these rational antiderivatives and remains supported across evaluation, differentiation, substitution, printing, and parsing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100