s:{:[@x;x;r ._f'x]} n:1=4:: r:{if[(+)~x;::[0~y;z;0~z;y;n[y]&n z;y+z;(x;y;z)]] if[(*)~x;::[0~y;0;0~z;0;1~y;z;1~z;y;n[y]&n z;y*z;(x;y;z)]] } s(*;`x;(+;(+;(*;12;0);(+;23;8));`y)) E:{&/x{:[x~_n;1=4:y;x~y]}'y} S:{:[@x;x;R ._f'x]} R:{:[E[(+;0);(x;y)] ;z E[(+;0);(x;z)] ;y E[(*;0);(x;y)] ;0 E[(*;0);(x;z)] ;0 E[(*;1);(x;y)] ;z E[(*;1);(x;z)] ;y E[(*;;);(x;y;z)] ;y*z E[(+;;);(x;y;z)] ;y+z (x;y;z)]} S(*;`x;(+;(+;(*;12;0);(+;23;8));`y)) \ Jon Harrop Challenge Problem -------------------------------------------- Posted by Dr Harrop http://groups.google.co.uk/group/comp.lang.lisp/browse_thread/thread/e69f2854fe5d19b5/a3ba5d7372a05917?lnk=gst&q=nathan+harrop+thieme&rnum=1&hl=en#a3ba5d7372a05917 The problem is to simplify symbolic expressions by applying the following rewrite rules from the leaves up: rational n + rational m -> rational(n + m) rational n * rational m -> rational(n * m) symbol x -> symbol x 0+f -> f f+0 -> f 0*f -> 0 f*0 -> 0 1*f -> f f*1 -> f a+(b+c) -> (a+b)+c a*(b*c) -> (a*b)*c (x * (((12 * 0) + (23 + 8)) + y)) -> (x * (31 + y))