10.11 Rewrite Rules

The a r (calc-rewrite) [rewrite] command makes substitutions in a formula according to a specified pattern or patterns known as rewrite rules. Whereas a b (calc-substitute) matches literally, so that substituting ‘sin(x)’ with ‘cos(x)’ matches only the sin function applied to the variable x, rewrite rules match general kinds of formulas; rewriting using the rule ‘sin(x) := cos(x)’ matches sin of any argument and replaces it with cos of that same argument. The only significance of the name x is that the same name is used on both sides of the rule.

Rewrite rules rearrange formulas already in Calc’s memory. See Syntax Tables, to read about syntax rules, which are similar to algebraic rewrite rules but operate when new algebraic entries are being parsed, converting strings of characters into Calc formulas.