( e: Expression, x: string, xv: number, ce: ComputeEngine )
| 719 | function limitRatioAtPosInf( |
| 720 | num: Expression, |
| 721 | den: Expression, |
| 722 | x: string, |
| 723 | ce: ComputeEngine, |
| 724 | depth: number |
| 725 | ): Expression | undefined { |
| 726 | checkDeadline(ce._deadlineFrame); |
| 727 | // Bail on a numerator/denominator that suffers catastrophic cancellation or |
| 728 | // overflow at the probe points (e.g. e^stuff − eˣ, whose huge terms cancel to |
| 729 | // a far smaller value): neither the asymptotic nor the numeric pass can rank |
| 730 | // it reliably, so defer to the numeric limit (which has its own guard). |
| 731 | if (hasCancellation(num, x, ce) || hasCancellation(den, x, ce)) |
| 732 | return undefined; |
| 733 | |
| 734 | const n = leadingOrder(num, x, ce, depth).simplify(); |
| 735 | const d = leadingOrder(den, x, ce, depth).simplify(); |
| 736 | |
| 737 | // Compare growth *first*. (Simplifying the quotient first can re-expand it |
| 738 | // back into the original product and loop — e.g. x/(1/ln(1+a/x)).) |
| 739 | const cmp = compareGrowth(n, d, x, ce); |
| 740 | if (cmp !== undefined) { |
| 741 | if (cmp < 0) return ce.Zero; // numerator grows slower → 0 |
| 742 | if (cmp > 0) { |
| 743 | const s = leadingSign(n, x, ce) * leadingSign(d, x, ce); |
| 744 | return s < 0 ? ce.NegativeInfinity : ce.PositiveInfinity; |
| 745 | } |
| 746 | // Same growth order → ratio of leading coefficients. |
| 747 | const r = n.div(d).simplify(); |
| 748 | if (!r.has(x)) return r.evaluate(); |
| 749 | return leadingCoefficientRatio(n, d, x, ce); |
| 750 | } |
| 751 | |
| 752 | // Growth comparison inconclusive: a genuine 0/0 or ∞/∞ that the asymptotic |
| 753 | // pass couldn't rank → L'Hôpital (differentiate top and bottom, recurse). |
| 754 | if (depth < MAX_DEPTH) { |
| 755 | const dn = differentiate(n, x); |
| 756 | const dd = differentiate(d, x); |
| 757 | if (dn && dd && !dd.is(0)) { |
no test coverage detected