I suspect you want to collect wrt. the second partial derivatives of f(x,y,z,t) with respect to x,y,z,t ; evaluated at xp,yp,zp,tp. Those are not the same as the partial second derivatives of f(xp,yp,zp,tp) with respect to (x,y,z,t). If you inspect what derivative(f(xp, yp, zp, tp), x, 2) gives you, you'll see it's a complicated expression. "collecting" relative to it doesn't make sense from first principles and if you try to make the notion precise you'll find there are fundamental ambiguities that prevent it from being a well-defined operation in general.
The operation you probably intend is quite doable, though. You first have to construct the expressions that you want to collect relative to: V=[x,y,z,t] Ds=[derivative(f(x,y,z,t),V[i],V[j])({x:xp,y:yp,z:zp,t:tp}) for j in range(4) for i in range(j+1)] You can inspect the entries in Ds: these are all just purely expressions of the form D[i,j](f), so from the perspective of expression manipulations such as "subs" and "collect" and "coeffient", they are "atomic": they behave as polynomial variables themselves. For instance, we could replace them by actual, named variables to exhibit this. We'll call these variables D00,...,D33: Dvars=[SR.symbol('D{}{}'.format(i,j)) for j in range(4) for i in range(j+1)] We can substitute those: eD=e.subs(dict(zip(Ds,Dvars)));eD D11 + D22 + (D00/sqrt(-v^2/c^2 + 1) - D03*v/(c^2*sqrt(-v^2/c^2 + 1)))/sqrt(-v^2/c^2 + 1) - v*(D03/sqrt(-v^2/c^2 + 1) - D33*v/(c^2*sqrt(-v^2/c^2 + 1)))/(c^2*sqrt(-v^2/c^2 + 1)) - ((D00*v/sqrt(-v^2/c^2 + 1) - D03/sqrt(-v^2/c^2 + 1))*v/sqrt(-v^2/c^2 + 1) - (D03*v/sqrt(-v^2/c^2 + 1) - D33/sqrt(-v^2/c^2 + 1))/sqrt(-v^2/c^2 + 1))/c^2 And we can check this is correct by substituting back and comparing (many CAS packages have rough edges in this area, where they'll allow you to do something but not necessarily do what you thought you would do; so checking is good!) bool(eD.subs(dict(zip(Dvars,Ds))) == e) True Note that multivariate calculus books describe the linear algebra that partial derivatives obey under these kinds of operations. That would allow you to get this expression eD right away. On Friday, January 22, 2021 at 10:46:35 AM UTC-8 cseb...@gmail.com wrote: > > I'm trying to collect all the terms in an expression with the same > second partial derivative but it doesn't seem to be working. > I can't figure out why. > > Here is my code.... > > # ============================================================ > > function("xp yp zp tp f") > var("x y z t v c") > > xp = (x - v * t) / sqrt(1 - v^2 / c^2) > yp = y > zp = z > tp = (t - v * x / c^2) / sqrt(1 - v^2 / c^2) > > e = derivative(f(xp, yp, zp, tp), x, 2) + derivative(f(xp, yp, zp, tp), y, > 2) + derivative(f(xp, yp, zp, tp), z, 2) - derivative(f(xp, yp, zp, tp), t, > 2) / c^2 > > e.collect(derivative(f(xp, yp, zp, tp), x, 2)) > > # ============================================================ > > Here is the output. I added spaces at a subtraction to make it easy to see > there are TWO of those D[0, 0](f) terms (each at the beginning of the > sections). > > (D[0, 0](f)(-(t*v - x)/sqrt(-v^2/c^2 + 1), y, z, (t - > v*x/c^2)/sqrt(-v^2/c^2 + 1))/sqrt(-v^2/c^2 + 1) - v*D[0, 3](f)(-(t*v - > x)/sqrt(-v^2/c^2 + 1), y, z, (t - v*x/c^2)/sqrt(-v^2/c^2 + > 1))/(c^2*sqrt(-v^2/c^2 + 1)))/sqrt(-v^2/c^2 + 1) - v*(D[0, 3](f)(-(t*v - > x)/sqrt(-v^2/c^2 + 1), y, z, (t - v*x/c^2)/sqrt(-v^2/c^2 + > 1))/sqrt(-v^2/c^2 + 1) - v*D[3, 3](f)(-(t*v - x)/sqrt(-v^2/c^2 + 1), y, z, > (t - v*x/c^2)/sqrt(-v^2/c^2 + 1))/(c^2*sqrt(-v^2/c^2 + > 1)))/(c^2*sqrt(-v^2/c^2 + 1)) > > - > > ((v*D[0, 0](f)(-(t*v - x)/sqrt(-v^2/c^2 + 1), y, z, (t - > v*x/c^2)/sqrt(-v^2/c^2 + 1))/sqrt(-v^2/c^2 + 1) - D[0, 3](f)(-(t*v - > x)/sqrt(-v^2/c^2 + 1), y, z, (t - v*x/c^2)/sqrt(-v^2/c^2 + > 1))/sqrt(-v^2/c^2 + 1))*v/sqrt(-v^2/c^2 + 1) - (v*D[0, 3](f)(-(t*v - > x)/sqrt(-v^2/c^2 + 1), y, z, (t - v*x/c^2)/sqrt(-v^2/c^2 + > 1))/sqrt(-v^2/c^2 + 1) - D[3, 3](f)(-(t*v - x)/sqrt(-v^2/c^2 + 1), y, z, (t > - v*x/c^2)/sqrt(-v^2/c^2 + 1))/sqrt(-v^2/c^2 + 1))/sqrt(-v^2/c^2 + 1))/c^2 > + D[1, 1](f)(-(t*v - x)/sqrt(-v^2/c^2 + 1), y, z, (t - > v*x/c^2)/sqrt(-v^2/c^2 + 1)) + D[2, 2](f)(-(t*v - x)/sqrt(-v^2/c^2 + 1), y, > z, (t - v*x/c^2)/sqrt(-v^2/c^2 + 1)) > > > -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/50191e08-64e7-4026-aade-6905a4ba04a9n%40googlegroups.com.