On 3/2/08, Robert Marik <marik at mendelu.cz> wrote:
> defrule(r1, derivace(sin(g)), (print ("sine:
> (sin(",g,"))'=cos(",g,")*(",g,")'"),if g=x then cos(x) else
> cos(g)*derivace(g)));
> defrule(r2, derivace(cos(g)), (print ("cosine:
> (sin(",g,"))'=cos(",g,")*(",g,")'"), if g=x then -sin(x)
> else -sin(g)*derivace(g)));
The rules for specific functions can probably be abbreviated
as follows. Associate function names and their derivatives
via the property list. Then use defrule to match the function
name and retrieve the derivative property when there is a match.
qput (sin, cos, derivace);
qput (cos, lambda ([u], - sin(u)), derivace);
/* etc etc */
matchdeclare (ff, lambda ([e], symbolp (e) and get (e, 'derivace) # false));
matchdeclare (uu, all);
defrule (rf, derivace (ff (uu)), apply (get (ff, 'derivace), [uu]) *
derivace (uu));
apply1 (derivace (sin (x^2)), rf);
=> derivace(x^2)*cos(x^2)
apply1 (derivace (cos (x^2)), rf);
=> -derivace(x^2)*sin(x^2)
apply1 (derivace (tan(x^2)), rf);
=> derivace (tan(x^2) /* since tan does not have the derivace property */
HTH
Robert Dodier