Ask Your Question
0

Order of variables in partial derivative expressions

asked 2021-05-07 18:35:11 +0100

tamandua gravatar image

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.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2021-05-07 23:16:37 +0100

rburing gravatar image

Your u variable is a symbolic expression, and the function call syntax with positional/unnamed arguments -- that you use when you write u(x,y,z,t) -- is deprecated, exactly because it is confusing.

You should write instead

d1 = diff(u,x,t,t,z)
d2 = diff(v,z,z,t,t)

Also, you defined x,y,z,t as generators of a polynomial ring, but when you substitute them into a symbolic expression (like your symbolic function) they are coerced to symbolic variables of the same name, so you might as well have defined var('x,y,z,t').

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-05-07 18:35:11 +0100

Seen: 192 times

Last updated: May 07 '21