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

Function addOrder

src/compute-engine/boxed-expression/order.ts:103–123  ·  view source on GitHub ↗
(a: Expression, b: Expression)

Source from the content-addressed store, hash-verified

101 *
102 * E.g.
103 * - 2x^2 + 3x + 1
104 * - 2x^2y^3 + 5x^3y
105 */
106
107export function addOrder(a: Expression, b: Expression): number {
108 const aTotalDeg = totalDegree(a);
109 const bTotalDeg = totalDegree(b);
110 if (aTotalDeg !== bTotalDeg) return bTotalDeg - aTotalDeg;
111
112 const aMaxDeg = maxDegree(a);
113 const bMaxDeg = maxDegree(b);
114 if (aMaxDeg !== bMaxDeg) return bMaxDeg - aMaxDeg;
115
116 // Get a lexicographic key of the expression
117 // i.e. `xy^2` -> `x y`
118 const aLex = revlex(a);
119 const bLex = revlex(b);
120 if (aLex || bLex) {
121 if (!aLex) return +1;
122 if (!bLex) return -1;
123 if (aLex < bLex) return -1;
124 if (aLex > bLex) return +1;
125 }
126 return order(a, b);

Callers

nothing calls this directly

Calls 4

totalDegreeFunction · 0.90
maxDegreeFunction · 0.90
revlexFunction · 0.90
orderFunction · 0.70

Tested by

no test coverage detected