Rewrite Rules
Recall: a
- b
e
- a
- b
b
- b
- a
- b
b
- e
- b
- a
- b
b
- a
- a
- b
- a
- b
b
- a
- e
b
- a
a
✂e
✄a
For example, for first rewrite, use:
Importance of rewrite rules:
☎Rewrite terms on either side of = to be identical
☎Each step is justified by a rewrite rule like an equation but used only in one direction: makes use of matching
☎computationally efficient: little search
☎common in mathematics
☎can deal with inequalities as well ( )
☎can also deal with propositional equivalence e.g.
✆Terminology: A term with no variables is said to be ground a
✝e
✞a
Equation used from lhs to rhs
Algebraic Simplification
Sample set of rewrite rules lhs
✟rhs
✠ ✠Always used in this direction Example: a
2
✡ ☛5
☞b
☛ ✌a
☛5
☞b
☛Rule 1
✌1
☛5
☞b
☛Rule 3
✌5
☞b
☛Rule 2
✌5
☞Rule 1
✌5
Redexes: match with lhs of a rule and replace with corresponding instance of rhs
There is some choice:
✠which subexpression to rewrite
✠which rule to use Terminology: A redex is a subexpression that can be rewritten
- 1. X
- 2. 1
X
✎X
- 3. X
1
- 4. X
X
There is a search tree
✑in this example, it is AND choice: so does not matter
✑not always AND choice
Multiplication