(a: Expression, b: Expression)
| 101 | * |
| 102 | * E.g. |
| 103 | * - 2x^2 + 3x + 1 |
| 104 | * - 2x^2y^3 + 5x^3y |
| 105 | */ |
| 106 | |
| 107 | export 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); |
nothing calls this directly
no test coverage detected