2 // Testing the rewriting features
6 datatype EXP = num (int)
13 rewrite class Simplify( EXP ) {};
17 case add (num 0, x): x;
18 case add (x, num 0): x;
19 case sub (x, num 0): x;
20 case mul (x, num 0): num(0);
21 case mul (num 0, x): num(0);
22 case mul (x, num 1): x;
23 case mul (num 1, x): x;
24 case mul (x, num 2): add(x,x);
25 case mul (num 2, x): add(x,x);
26 case div (x, num 1): x;
27 case add (num x, num y): num(x + y);
28 case sub (num x, num y): num(x - y);
29 case mul (num x, num y): num(x * y);
30 case div (num x, num y): num(x / y);
37 rewrite class Number (NAT, EXP)
45 case succ(succ(zero)):
46 case succ(succ(succ(succ(X)))):
47 case add (num x, num y): num(x + y);
48 case sub (num x, num y): num(x - y);
49 case mul (num x, num y): num(x * y);
50 case div (num x, num y): num(x / y);