## Re: [Reduce-algebra-developers] An inconsistency in computing derivatives?

 Re: [Reduce-algebra-developers] An inconsistency in computing derivatives? From: Rainer Schöpf - 2011-09-09 18:48:55 On Fri, 9 Sep 2011 at 17:21 +0100, Francis Wright wrote: > > Some more border cases in differentiation: > > > > 1. This one has nothing to do with expanddf and the recent changes: > > > > depend cos(y),x; > > > > df(cos(y),x) => 0 > > > > because df(cos(y),x) simplifies to > > > > -sin(y) * df(y,x) > > > > and y doesn't depend on x. > > > > This looks wrong to me. > > Yes. But the only way that cos(y) can depend on x is if y depends on x, so I > think REDUCE should either regard "depend cos(y),x; " as an error or interpret > it to mean "depend y,x; ". But you can't do this for all functions, because an > arbitrary function f(y) could reasonably have some implicit dependence on other > variables. Off hand, the only way I can see to distinguish the cases would be to > flag known operators in some way. Two ideas: 1. regard "depend cos(y),x;" as an error because there is a diffentiation rule for cos 2. do not apply the diff. rule for cos(y) if there is an implicit (declared) dependency on x. > > 2. With expand set to on: > > > > depend r,x; > > df(f(r,cos(x)),x); > > > > gives > > > > df(f(r,cos(x)),r)*df(r,x) + df(f(r,cos(x)),cos(x))*df(cos(x),x) > > > > > > I believe it is correct, but possibly not what one expects. > > Yes. I would suggest leaving this and waiting for users to complain if it's not > what they expect. (I presume that df(cos(x),x) actually simplifies.) Yes, will do that. I guess there will still be a few pathological cases where the result is not what one would expect. I've put some tests into regression test files: packages/regressions/sep-05-2011-expanddf.tst packages/regressions/sep-05-2011-expanddf.rlg > > BTW, I think there is an error in the procedure diffp, both in the original > one and > > the one in odesolve/odepatch.red: The else clause > > > > else if eqcar(cadr u, 'int) then > > > > is not an alternative to the then clause > > > > if cadr u eq v then > > > > (as the indentation suggests), but part of that then clause, ie there is a > > > > << > > ... > > >> > > > > missing. > > As far as odesolve/odepatch.red is concerned, I clearly missed this problem, > partly because I try not to reformat existing code that I'm modifying. So can > you change odesolve/odepatch.red as well, please, if you change the main code? Will do. However, with there being three redefinitions of diffp (in changevr, odesolve and crack) it might be better to merge all these into the main code, with some global variables or switches to activate the necessary bits. What do you think? Rainer