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

Function asSignedPower

src/compute-engine/boxed-expression/solve.ts:1625–1649  ·  view source on GitHub ↗

Parse a term as ±cᵉ: returns `[sign, base, exp]` when the term is a power, * optionally negated or carrying a ±1 coefficient; otherwise `null`.

(
  term: Expression
)

Source from the content-addressed store, hash-verified

1623 if (squared.has(variable) === false) return null;
1624 // Solve the sqrt-free polynomial; extraneous roots from squaring are removed
1625 // by the caller's validation against the original equation.
1626 const sqrtFree = squared.simplify();
1627 traceStep(trace, 'solve.square-both-sides', asEquation(sqrtFree, variable));
1628 const child = childStats();
1629 const roots = realRootsOfSquaredEquation(
1630 ce,
1631 variable,
1632 stepUnivariateRoots(sqrtFree, variable, 0, undefined, child)
1633 );
1634 if (roots.length > 0) adoptChildStats(stats, child);
1635 return roots;
1636}
1637
1638/**
1639 * The roots of a polynomial that squaring gave, without the roots that are
1640 * decided not real. A polynomial equation gives all its roots, the complex
1641 * ones included; every other equation gives its real solutions only (see
1642 * `cortexjs.io/docs/compute-engine/85-reference-core.md`, `Solve`). `x·√(x² + 1) = 1` is squared into
1643 * `x⁴ + x² − 1 = 0`, whose root `−√((−1 − √5)/2)` is a root of the original
1644 * equation over the complex numbers (`−1.27i·0.79i = 1`), but not a real
1645 * solution: the check against the original equation keeps it, thus it is
1646 * removed here. A root whose realness is not decided (`isRealRoot()`) is
1647 * kept. When the unknown can take a value that is not real
1648 * (`isComplexUnknown()`), every root is kept.
1649 */
1650function realRootsOfSquaredEquation(
1651 ce: ComputeEngine,
1652 x: string,

Callers 1

reduceSameBasePowerFunction · 0.85

Calls 2

isFunctionFunction · 0.90
isSameMethod · 0.65

Tested by

no test coverage detected