(json: Json, ctx: Ctx)
| 559 | /** Rubi SumSimplerAuxQ — recursion over (expanded) sum terms: |
| 560 | * - v a sum: every term of v is rational or aux-simpler wrt u |
| 561 | * - u a sum: some term of u is aux-simpler wrt v |
| 562 | * - both terms: v ≠ 0, same non-numeric factors, and the numeric-factor |
| 563 | * ratio nf(u)/nf(v) < −1/2 (or = −1/2 with nf(u) < 0) */ |
| 564 | function sumSimplerAuxQ(u: Expression, v: Expression): boolean { |
| 565 | if (v.operator === 'Add' && v.ops) |
| 566 | return v.ops.every((t) => isLiteralRational(t) || sumSimplerAuxQ(u, t)); |
| 567 | if (u.operator === 'Add' && u.ops) |
| 568 | return u.ops.some((t) => sumSimplerAuxQ(t, v)); |
| 569 | if (v.isSame(0)) return false; |
| 570 | const su = splitNumericFactor(u); |
| 571 | const sv = splitNumericFactor(v); |
| 572 | if (!su.rest.isSame(sv.rest)) return false; |
| 573 | const q = su.coef / sv.coef; |
| 574 | return q < -0.5 || (q === -0.5 && su.coef < 0); |
| 575 | } |
| 576 | |
| 577 | // --------------------------------------------------------------------------- |
| 578 | // Predicates — FAIL-CLOSED (undecidable ⇒ false) |
| 579 | // --------------------------------------------------------------------------- |
| 580 | |
| 581 | type PredFn = (args: Json[], ctx: Ctx) => boolean; |
| 582 | |
| 583 | export function evalCondition(json: Json, ctx: Ctx): boolean { |
| 584 | if (typeof json === 'string') { |
| 585 | if (json === 'True') return true; |
| 586 | if (json === 'False') return false; |
| 587 | // SimplifyFlag and friends — not in steps mode |
| 588 | return fail(`bare symbol condition '${json}'`); |
no test coverage detected