From: Rainer S. <rai...@gm...> - 2013-05-15 19:27:52
|
On Wed, 15 May 2013 at 08:10 +0930, Tony Roberts wrote: > the following code causes me grief with derivatives and dependencies, > and looks like an error that needs fixing. > operator x; operator pp; > % for j:=1:2 do depend pp,x(j); % why is this not needed? > let df(pp,x(~j))=>pp(j); > thisIsOK:=df(pp^2,x(1)); > shouldBeZero:=df(pp^2,t); > end; > > On my Reduce it generates > thisisok := 2*pp(1)*pp > shouldbezero := 2*df(pp,t)*pp > and the second is certainly not what I want, and causes me grief. > Further, why is the "depend pp,x(j)" statement not needed? When you add a rule for differentiation, a suitable dependency is added automatically, ie. let df(pp,x) => something; effectively adds depend pp,x; The exception is the case of differentiation w.r.t. a free variable, eg., let df(pp,~y) => x(y); since a dependency on a free variable doesn't make sense. What happens here is that your rule defines differentation w.r.t. an expression containing a free variable. Unfortunately, this general case is not checked, and you end up with a dependency of pp on x(~j). Now, when you enter df(pp,t); Reduce checks whether x depends on t; if that happens to be the case, the correct answer would either be df(pp,t); (if the switch expanddf is off), or df(pp,x)*df(x,t); if the switch expanddf is on. In your case it checks whether x(~j) depends on t. A free variable may be replaced by an arbitrary expression, and therefore x(~j) is treated as being dependent on anything. I'll test a correction in the next few days. Rainer |