Function
src/index.ts:1024nerdamer.uSub
nerdamer.uSub(x: ExpressionInput, value: ExpressionInput, map?: SubstitutionMap): USubstitutionResultReplaces one repeated sub-expression with a generated uN symbol.
The generated symbol is chosen so it does not collide with variables already present
in the expression or substitution map. Pass the returned map to later calls when
several substitutions should share one namespace, then use uUnSub to restore
the original expressions.
Parameters
| Name | Type | Description |
|---|---|---|
x | ExpressionInput | Expression in which the substitution will occur. |
value | ExpressionInput | Sub-expression to replace. |
map | SubstitutionMap | Existing substitution map to extend. |
Returns
USubstitutionResult — The substituted expression and the updated substitution map.
Examples
const [substituted, map] = uSub('cos(x)^2+cos(x)+1', 'cos(x)');
substituted.text({ sort: true }); // "u0^2+u0+1"
uUnSub(substituted, map).eq('cos(x)^2+cos(x)+1'); // true