MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / rtFactors

Function rtFactors

src/compute-engine/rubi/rubi-utils.ts:1286–1318  ·  view source on GitHub ↗

flatten Multiply/Divide/Negate into a factor list (denominator factors * become synthetic Power(f, −1) so the RtAux power/odd-exponent logic * sees them)

(u: Expression)

Source from the content-addressed store, hash-verified

1284 return u.ops[0].symbol === x && !u.ops[1].has(x);
1285 if (u.operator === 'Multiply' && u.ops)
1286 return (
1287 u.ops.filter((o) => o.has(x)).length === 1 &&
1288 u.ops.every((o) => !o.has(x) || monomialQ(o, ctx))
1289 );
1290 return false;
1291}
1292
1293// Rubi SimplerQ — integer < fraction < complex < everything; ties by
1294// magnitude; non-numbers by leaf count.
1295function simplerQ(u: Expression, v: Expression): boolean {
1296 if (isLiteralInteger(u)) {
1297 if (!isLiteralInteger(v)) return true;
1298 const a = realNum(u)!;
1299 const b = realNum(v)!;
1300 if (a === b) return false;
1301 if (a === -b) return b < 0;
1302 return Math.abs(a) < Math.abs(b);
1303 }
1304 if (isLiteralInteger(v)) return false;
1305 const ur = ratParts(u);
1306 const vr = ratParts(v);
1307 if (ur) {
1308 if (!vr) return true;
1309 if (ur[1] === vr[1]) return Math.abs(ur[0]) < Math.abs(vr[0]);
1310 return ur[1] < vr[1];
1311 }
1312 if (vr) return false;
1313 return leafCount(u) < leafCount(v);
1314}
1315
1316function leafCount(e: Expression): number {
1317 if (!e.ops) return 1;
1318 return 1 + e.ops.reduce((s, op) => s + leafCount(op), 0);
1319}
1320
1321// ---------------------------------------------------------------------------

Callers 1

rtAuxBodyFunction · 0.85

Calls 1

walkFunction · 0.70

Tested by

no test coverage detected