def is_number(F) { return type(eval_quote(F))==1; } def integral(F,V) { if ( quote_unify(F,`G+H) ) { G1 = integral(G,V); G2 = integral(H,V); return G1+G2; } else if ( quote_unify(F,`G-H) ) { G1 = integral(G,V); G2 = integral(H,V); return G1-G2; } else if ( quote_unify(F,`G*H) ) { if ( is_number(G) ) { H1 = integral(H,V); return G*H1; } else if ( is_number(H) ) { G1 = integral(G,V); return H*G1; } else error("not implemented"); } else if ( quote_unify(F,`G/H) ) { if ( is_number(H) ) { G1 = integral(G,V); return G1/H; } else error("not implemented"); } else if ( quote_unify(F,`G^H) ) { if ( G == V ) { H1 = objtoquote(eval_quote(H)+1); return G^H1/H1; } } else if ( V == F ) { return F^2/2; } else if ( is_number(F) ) { return F*V; } else error("not implemented"); } def apply_rec(F,E) { if ( quote_unify(E,`(G)) ) X = apply_rec(F,G); else if ( quote_unify(E,`-G) ) X = -apply_rec(F,G); else if ( quote_unify(E,`G+H) ) X = apply_rec(F,G)+apply_rec(F,H); else if ( quote_unify(E,`G-H) ) X = apply_rec(F,G)-apply_rec(F,H); else if ( quote_unify(E,`G*H) ) X = apply_rec(F,G)*apply_rec(F,H); else if ( quote_unify(E,`G/H) ) X = apply_rec(F,G)/apply_rec(F,H); else if ( quote_unify(E,`G^H) ) X = apply_rec(F,G)^apply_rec(F,H); else if ( quote_unify(E,`U(V)) ) { X = apply_one(U,[apply_rec(F,V)]); } else if ( quote_unify(E,`U(V,W)) ) X = apply_one(U,[apply_rec(F,V),apply_rec(F,W)]); else X = E; return apply_one(F,[X]); } def apply_one(F,E) { return funargs_to_quote(append([8,F],E)); } end$