File: [local] / OpenXM / src / asir-contrib / testing / noro / integral.rr (download)
Revision 1.1, Fri Sep 30 06:41:07 2005 UTC (18 years, 11 months ago) by noro
Branch: MAIN
CVS Tags: R_1_3_1-2, RELEASE_1_3_1_13b, RELEASE_1_2_3_12, KNOPPIX_2006, HEAD, DEB_REL_1_2_3-9
Added test files for term rewriting and simplification.
|
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$