Rewriting: Program vs. Pattern Matching
Rewriting of symbolic expressions can be accomplished by an ad hoc
program, or by using pattern matching and rewrite rules.
Each has advantages and disadvantages:
- Adv.: Often is more efficient.
Avoids restrictions that may be present with patterns.
- Dis.: The rewriting program becomes large.
Hard to find errors, omissions.
A good compromise may be to use a pattern matcher in combination
with programs for those cases that are simple or are not easily
handled by patterns.
- Adv.: Declarative representation. Easier to understand.
Mistakes less likely.
- Dis.: May be slower.