3
$\begingroup$

I'm new to Mathematica and I have a question about modifying derivative expressions. I have two mathematical conditions

$$ \displaystyle \frac{\partial g}{\partial y} = -\frac{\partial f}{\partial x}$$

$$ \displaystyle \frac{\partial f}{\partial y} = \frac{\partial g}{\partial x}$$

Given any derivative

$$ \displaystyle \frac{\partial^{n+m} f}{\partial x^n \partial y^m} $$

How can I make the substitutions above programmatically?

I tried the following

ruleA = Derivative[dx_, dy_][g][x, y] -> -Derivative[dx + 1, dy - 1][f][x, y];
ruleB = Derivative[dx_, dy_][f][x, y] -> Derivative[dx + 1, dy - 1][g][x, y];
myRules = Dispatch[{ruleA,ruleB}];

then apply the rule to an expression using the /. notation. It works, but I get negative derivatives. Also, it looks like it only applies the rules once. So this doesn't achieve what I'm looking for, but not having an experience with Mathematica, I'm not sure what the approach should be.

As a more explicit example of what I'm looking to accomplish, assume $n = 1, m = 2$, which gives

$$ \displaystyle \frac{\partial^{3} f}{\partial x \partial y^2} $$

After one application of the rules, it should equal

$$ \displaystyle \frac{\partial^{3} g}{\partial x^2 \partial y} $$

There is one more substitution to make, giving

$$ \displaystyle - \frac{\partial^{3} f}{\partial x^3} $$

$\endgroup$
0

1 Answer 1

2
$\begingroup$

OK...I think I got it, but maybe not the most efficient way. Need to add a conditional /; dy-1 >= 0 before the rule

ruleA = Derivative[dx_, dy_][g][x, y] /; dy-1 >= 0 -> -Derivative[dx + 1, dy - 1][f][x, y];
ruleB = Derivative[dx_, dy_][f][x, y] /; dy-1 >= 0  -> Derivative[dx + 1, dy - 1][g][x, y];
myRules = Dispatch[{ruleA,ruleB}];

Then invoke the rule with //. for recursive application.

$\endgroup$
1
  • $\begingroup$ Looks good. You can also put the condition right after the pattern dy_ if you prefer. $\endgroup$
    – user293787
    Oct 5, 2022 at 5:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.