| 149 | inExpr: ExpressionInput | null, |
| 150 | variants?: Array<ExprVariant> |
| 151 | ): string { |
| 152 | if (!inExpr) return 'null'; |
| 153 | const ce = |
| 154 | inExpr instanceof _BoxedExpression |
| 155 | ? inExpr.engine |
| 156 | : engine; /* default test engine */ |
| 157 | const precision = ce.precision; |
| 158 | try { |
| 159 | ce.precision = 'auto'; |
| 160 | |
| 161 | variants ??= [ |
| 162 | 'box', |
| 163 | 'canonical', |
| 164 | 'simplify', |
| 165 | 'eval-auto', |
| 166 | 'eval-mach', |
| 167 | 'N-mach', |
| 168 | 'N-auto', |
| 169 | ]; |
| 170 | |
| 171 | const boxed = exprToString(ce.expr(inExpr, { form: 'raw' })); |
| 172 | |
| 173 | const expr = ce.expr(inExpr); |
| 174 | |
| 175 | if (!expr.isValid) return `invalid =${exprToString(expr)}`; |
| 176 | |
| 177 | const canonical = exprToString(expr); |
| 178 | |
| 179 | const simplifyExpr = expr.simplify(); |
| 180 | const simplify = simplifyExpr.toString(); |
| 181 | const evalAuto = expr.evaluate().toString(); |
| 182 | const numEvalAuto = expr.N().toString(); |
| 183 | |
| 184 | ce.precision = 'machine'; |
| 185 | // Re-box at machine precision so internal NumericValue representations |
| 186 | // use MachineNumericValue, not BigNumericValue from the higher-precision parse |
| 187 | const machExpr = ce.expr(expr.json); |
| 188 | const evalMachine = machExpr.evaluate().toString(); |
| 189 | const numEvalMachine = machExpr.N().toString(); |
| 190 | |
| 191 | if ( |
| 192 | boxed === canonical && |
| 193 | simplifyExpr.isSame(expr) && |
| 194 | evalAuto === simplify && |
| 195 | evalAuto === evalMachine && |
| 196 | evalAuto === numEvalAuto && |
| 197 | evalAuto === numEvalMachine |
| 198 | ) { |
| 199 | return boxed; |
| 200 | } |
| 201 | |
| 202 | const result: string[] = []; |
| 203 | if (variants.includes('box')) result.push('box = ' + boxed); |
| 204 | |
| 205 | if (canonical !== boxed && variants.includes('canonical')) |
| 206 | result.push('canonical = ' + canonical); |
| 207 | |
| 208 | if (simplify !== expr.toString() && variants.includes('simplify')) |