(
expr: MathJsonExpression,
s: { [symbol: string]: MathJsonExpression }
)
| 371 | } |
| 372 | |
| 373 | /** |
| 374 | * Apply a substitution to an expression. |
| 375 | */ |
| 376 | export function subs( |
| 377 | expr: MathJsonExpression, |
| 378 | s: { [symbol: string]: MathJsonExpression } |
| 379 | ): MathJsonExpression { |
| 380 | const sym = symbol(expr); |
| 381 | if (sym && s[sym]) return s[sym]; |
| 382 | |
| 383 | const h = operator(expr); |
| 384 | if (h) |
| 385 | return [ |
| 386 | subs(h, s) as MathJsonSymbol, |
| 387 | ...operands(expr).map((x) => subs(x, s)), |
| 388 | ]; |
| 389 | |
| 390 | return expr; |
| 391 | } |