Bug in D (or Derivative) ( Was: Re: DSolve bug)

*To*: mathgroup at smc.vnet.net*Subject*: [mg97919] Bug in D (or Derivative) ( Was: Re: DSolve bug)*From*: schochet123 at gmail.com*Date*: Wed, 25 Mar 2009 05:46:54 -0500 (EST)*References*: <612696379.19321237704569790.JavaMail.root@mmm.inp.demokritos.gr>

The problem is not just that D[u[x][y],x,y] and D[u[y][x],y,x] yield apparently different results but that the results Mathematica gives for both of them are wrong. For example, define usub=u -> (Function[{x}, Function[{y}, E^(a x + b y)]]); Substituting and then differentiating (in either order) gives correct results (as several posters pointed out): D[u[x][y]/.usub,x,y] yields a b E^(a x + b y) However D[u[x][y],x,y]/.usub yields the incorrect answer a^2 E^(a x+ b y) Taking the derivative in the opposite order and then substituting yields an expression that does not even reduce to a specific function of x and y. The source of this bug seems to be the following bug in in D (or Derivative): According to Mathematica, D[u',u] yields u''. However, the correct answer is u''/u' (Homework for Calculus 1: use the chain rule to prove this.) The way Mathematica obtains its incorrect result is quite amusing, As Trace shows, Mathematica evaluates D[u',u] by noting that the FullForm of u' is Derivative[1][u], whose derivative with respect to u is (of course ;) ) Derivative[1]'[u]. Mathematica then decides that Derivative[1]' is Derivative[2], yielding Derivative[2][u], i.e., u''. Steve On Mar 22, 12:50 pm, DrMajorBob <btre... at austin.rr.com> wrote: > More to the point, using Bob's example: > > Clear[f] > f[a_][x_] := Sin[a*x] > D[f[x][y], x, y] - D[f[x][y], y, x] > > 0 > > As you can see, both derivatives ARE the same. Here's a better test, I = > think (since a and x were used symmetrically, above): > > Clear[f] > f[a_][x_] := Sin[a]^x > diff = D[f[x][y], x, y] - D[f[x][y], y, x] > > 0 > > But let's try it Sotirios' way, keeping f symbolic for a bit: > > Clear[f] > raw=D[f[x][y],x,y]-D[f[x][y],y,x]; > Block[{g},g[a_][x_]:=Sin[a]^x;raw/.f->g]//ExpandAll//Simplify > > -(Log[Sin[x]]^2 Sin[x]^#1& (g^\[Prime])[x])[y]+(g^\[Prime]\[Prime])[x][y] > > Now Mathematica can't equate the two derivatives. > > But that's a problem with D, not withDSolve. > > Note that Dt does better, too: > > Clear[f] > raw = Dt[f[x][y], x, y] - Dt[f[x][y], y, x] > > 0 > > DSolve'ssolution IS correct. It's D that may not be all it should be. > > Bobby > > On Sun, 22 Mar 2009 01:49:29 -0500, Sotirios Bonanos > > > > <sbon... at inp.demokritos.gr> wrote: > > > Your example gives two different ways of referring to the same function= > > (Sin[a*x]). But I want to be able to use the arbitrary function in the = > > solution given byDSolve(and its derivatives) in other expressions. > > This I cannot do because the derivatives D[f1[x][y], x, y], D[f1[x][y],= > > y, x] are not equal: > > > Clear[f1, f2] > > > {D[f1[x][y], x, y], D[f1[x][y], y, x]} > > > That's why I claim, if it is not abug, it is an unfortunate choice of = > > representation! > > > Sotirios Bonanos > > > ----- "Bob Hanlon" wrote: > >> It is just an alternate representation > > >> Clear[f1, f2] > > >> f1[a_][x_] := Sin[a*x] > > >> f2[a_, x_] := Sin[a*x] > > >> f1[c][t] == f2[c, t] > > >> True > > >> {Plot3D[f1[a][x], {x, 0, 2 Pi}, {a, 1, 3}], > >> Plot3D[f2[a, x], {x, 0, 2 Pi}, {a, 1, 3}]} > > >> Some people prefer the f[a][x] representation to explicitly separate o= ut > >> parameter(s) from argument(s) > > >> If you prefer > > >>DSolve[D[F[x, y, z], x, y] == 0, F[x, y, z], {x, y, z}] > > >> {{F(x,y,z)->Subscript[c, 1][z][x]+Subscript[c, 2][z][y]}} > > >> % /. f_[arg1_][arg2_] :> f[arg2, arg1] > > >> {{F(x,y,z)->Subscript[c, 1][x,z]+Subscript[c, 2][y,z]}} > > >> Bob Hanlon > > >> On Sat, Mar 21, 2009 at 10:25 AM , Sotirios Bonanos wrote: > > >> > Hello, > >> > I have encountered the followingbuginDSolve: > >> >DSolve[D[F[x, y, z], x, y] == 0, F[x, y, z], {x, y, z}] > >> > gives {{F[x, y, z] -> C[1][z][x] + C[2][z][y]}} > >> > instead of {{F[x, y, z] -> C[1][x, z] + C[2][y, z]}} > >> > I don't know if this has been fixed in Mathematica 7, but it is > >> > present in versions 5 and 6. > >> > S. Bonanoshttp://www.inp.demokritos.gr/~sbonano/ > > -- > DrMajor... at bigfoot.com

**Follow-Ups**:**Re: Bug in D (or Derivative) ( Was: Re: DSolve bug)***From:*Andrzej Kozlowski <akoz@mimuw.edu.pl>