* Numeric **real** roots of a univariate polynomial with numeric coefficients, * via Durand–Kerner. Used as a last-resort fallback for general cubics/quartics * (and higher) that have no rational root, so `solve` returns approximate real * roots instead of nothing. Returns `[]` when the coefficie
( expr: Expression, variable: string, ce: ComputeEngine )
| 2789 | // list as it is (the callers then find it incomplete, as for |
| 2790 | // `sin(200·sin(x)) = 1/3`, which would add about 125 roots). |
| 2791 | if (count > MAX_UNIT_RANGE_SHIFTS) return uRoots; |
| 2792 | |
| 2793 | const out: Expression[] = [...uRoots]; |
| 2794 | for (const { root, kmin, kmax } of ranges) { |
| 2795 | const value = restrictionParts(root)?.value ?? root; |
| 2796 | for (let k = kmin; k <= kmax; k++) { |
| 2797 | if (k === 0) continue; |
| 2798 | const shifted = ce |
| 2799 | .function('Add', [ |
| 2800 | value, |
| 2801 | ce.function('Multiply', [ce.number(k), period]), |
| 2802 | ]) |
| 2803 | .evaluate(); |
| 2804 | const condition = restrictionParts(root)?.condition; |
| 2805 | const member = |
| 2806 | condition !== undefined |
| 2807 | ? ce.function('If', [condition, shifted]) |
| 2808 | : shifted; |
| 2809 | if (!out.some((r) => r.isSame(member))) out.push(member); |
| 2810 | } |
| 2811 | } |
| 2812 | return out; |
| 2813 | } |
no test coverage detected