Program vs. Pattern Matching
Optimization of symbolic expressions can be done by an ad hoc
program or by using pattern matching and rewrite rules.
Each has advantages and disadvantages:
- Adv.: Avoids doing conses for common cases.
- Dis.: Code becomes large. Hard to find errors, omissions.
A good compromise is to use a program for the simplest cases, followed
by a pattern matcher for more complex patterns.
- Adv.: Declarative representation. Mistakes less likely.
- Dis.: May be slower.