Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Order of variables in partial derivative expressions

I want to sort a set of homogenous partial derivatives lexigraphically , e.g.

d²x dy > dxd²y > d³y

because it is more often differentiated in the first term than in the second, and so on. It is assumed that x > y. I implemented a function which just generates tuples of integers which can be sorted easily, analoguos to term ordering im multivariate polynomials. So the function returns, for the example given, the tuples:

(2,1), (1,2),(0,3)

which can easily be sorted in whatever way I want. When I switched to more complicated expression I stumbled over the follwing problem:

P.<x,y,z, t> = PolynomialRing(QQ, 4, order='lex')
print(x>y>z>t)
u = function("u")(x,y,z,t)
v = function("v")(x,y,z,t)
w = function("w")(x,y,z,t)
d1 = diff(u(x,y,z,t), x, t, t, z)
d2 = diff(v(x,y,z,t), z,z,t,t)
print (pylie.order_of_derivative(d1))
print (pylie.order_of_derivative(d2))
print (u.variables())
print (u)
print (d1)

gives the output (my function is called 'order_of_derivative')

True
[0, 1, 2, 1]
[0, 2, 2, 0]
(t, x, y, z)
u(x, y, z, t)
diff(u(y, z, t, x), z, t, t, x)

So one can see that we have given an order to the variables which seems to work). But the two tuples don't behave like expected: d1 1st index is 0, though I expected 1 because the is a derivaton for x. When I look at the variables I can see the order (t, x, y, z), the function shows u( x, y, z, t), and the derivative shows u(y,z,t,x), which is yet another order. Here is my function:

def order_of_derivative (e):
    opr = e.operator ()
    opd = e.operands ()
    if not isinstance(opr, sage.symbolic.operators.FDerivativeOperator):
        return [0] * len (e.variables())
    res = [opr.parameter_set().count(i) for i in range (len(opd))]
    return res

so the internal sort order seems to be lexicographicallly t,x,y,z. Of course I can build some complex workarounds, but my question is if there is a simple solution for that problem.