( base: Expression, expo: Expression, x: string, ce: ComputeEngine, depth: number )
| 350 | * cannot be decided does the same. |
| 351 | */ |
| 352 | function substituteAtFinitePoint( |
| 353 | e: Expression, |
| 354 | x: string, |
| 355 | a: Expression, |
| 356 | dir: number, |
| 357 | ce: ComputeEngine |
| 358 | ): Expression | undefined { |
| 359 | // A substitution can land an operand outside a Contract B carrier — at |
| 360 | // `x = 0`, `Ln(1/x²)` substitutes to `Ln(~oo)` (division by zero folds |
| 361 | // to the unsigned pole), which is an incompatible-type Error since the |
| 362 | // complex-extension carrier flips. An invalid substitute is NOT the |
| 363 | // limit's answer: the LIMIT can still exist through the directed |
| 364 | // strategies (the inner limit of `1/x²` is `+∞`, and `Ln(+∞) = +∞`), |
| 365 | // so decline and let the caller fall through to them. |
| 366 | const substituteAndCheck = (expr: Expression): Expression | undefined => { |
| 367 | const at = expr.subs({ [x]: a }).evaluate(); |
| 368 | return at.isValid ? at : undefined; |
| 369 | }; |
| 370 | let current = e; |
| 371 | // Each pass resolves ONE on-jump subterm (innermost first); the rewrite |
| 372 | // can nest, so iterate, capped well above any practical nesting. |
| 373 | for (let pass = 0; pass < 8; pass++) { |
| 374 | if (!current.has(JUMP_FNS)) return substituteAndCheck(current); |
| 375 | let jump: Expression | undefined = undefined; |
| 376 | let offset: Expression | undefined = undefined; |
| 377 | let jumpSize = Infinity; |
| 378 | for (const head of JUMP_FNS) { |
| 379 | for (const sub of current.getSubexpressions(head)) { |
| 380 | const off = jumpOffsetAt(sub, x, a, ce); |
| 381 | if (off === 'unknown') return undefined; |
| 382 | if (off === 'off') continue; |
| 383 | const size = sub.getSubexpressions('').length; |
| 384 | if (size < jumpSize) { |
| 385 | jump = sub; |
| 386 | offset = off; |
| 387 | jumpSize = size; |
| 388 | } |
| 389 | } |
| 390 | } |
| 391 | if (jump === undefined) return substituteAndCheck(current); |
| 392 | if (dir === 0) return undefined; |
| 393 | // The expansion anchor must be EXACT when representable: a machine-float |
| 394 | // point (`0.5` parsed from the limit) mixed with the exact subtrahend of |
| 395 | // the offset leaves an unfoldable `−1/2 + 0.5` constant term in the |
| 396 | // series (machine floats are excluded from canonical `Add` folding), a |
| 397 | // broken datum whose sign read declines. Integers and half-integers — |
| 398 | // the anchors this code's offsets create — exactify losslessly. |
| 399 | let anchor = a; |
| 400 | const ar = a.re; |
no test coverage detected