2
$\begingroup$

Suppose I have two systems of coordinates:{x1,x2} and {y1,y2}. I want to transform an expression containing $\frac{\partial yi}{\partial xj}$'s to those in terms of $\frac{\partial xj}{\partial yi}$'s. I wrote the following code:

expr = D[y2[x1, x2], {x1, 2}, {x2, 0}] + D[y1[x1, x2], {x1, 0}, {x2, 2}]; expr /. Derivative[n_, m_][y : y1 | y2][x1, x2] -> Nest[(1/D[x2[y1, y2], y1])*D[#1, y1] + (1/D[x2[y1, y2], y2])* D[#1, y2] &, Nest[(1/D[x1[y1, y2], y1])*D[#1, y1] + (1/D[x1[y1, y2], y2])* D[#1, y2] &, 1/D[x1[y1, y2], y], n], m] 

Why is this not working? It seems n,m and y are not recognized in the RHS of my replacement rule.

Edit 1:(Special case of expr where Nest is not evaluated)

The above was a snippet of a bigger problem I have been working on. There expr is a pure function. And then the above rule doesn't evaluate the Nest functions:

expr=Derivative[0, 1][y1][x1, x2]*D[#1, {y1, 1}, {y2, 0}] & expr/.Derivative[n_, m_][y : y1 | y2][x1, x2] :> Nest[(1/D[x2[y1, y2], y1])*D[#1, y1] + (1/D[x2[y1, y2], y2])* D[#1, y2] &, Nest[(1/D[x1[y1, y2], y1])*D[#1, y1] + (1/D[x1[y1, y2], y2])* D[#1, y2] &, 1/D[x1[y1, y2], y], n], m] 

How to force evaluation here?

$\endgroup$
4
  • 2
    $\begingroup$ What tests have you performed to validate your claims that the pattern matching is not working? $\endgroup$ Commented Mar 5, 2018 at 6:44
  • $\begingroup$ Also Ctrl+Shift+I (convert to input form) before copying. $\endgroup$ Commented Mar 5, 2018 at 6:58
  • $\begingroup$ @ m_goldberg Could you look at edit 1 of this post? $\endgroup$ Commented Mar 5, 2018 at 10:17
  • 1
    $\begingroup$ It would be good to have cross-post links between this thread and the related one on Wolfram Community $\endgroup$ Commented Mar 5, 2018 at 16:01

1 Answer 1

2
$\begingroup$

Here is your code expressed in input form. I have made two modifications.

  • I have replaced Rule withe RuleDelayed. This corrects an error on your part.
  • I have requested the output to be shown in input form, which I believe is more readable in this case

expr = D[y2[x1, x2], {x1, 2}, {x2, 0}] + D[y1[x1, x2], {x1, 0}, {x2, 2}]; expr /. Derivative[n_, m_][y : y1 | y2][x1, x2] :> Nest[ (1/D[x2[y1, y2], y1])*D[#1, y1] + (1/D[x2[y1, y2], y2])*D[#1, y2] &, Nest[ (1/D[x1[y1, y2], y1])*D[#1, y1] + (1/D[x1[y1, y2], y2])*D[#1, y2] &, 1/D[x1[y1, y2], y], n], m] // InputForm 

I get the following result.

result

It's messy, but so is your replacement rule. I see no sign that the pattern matching is not working.

$\endgroup$
1
  • $\begingroup$ Thanks for the correction. I had done a similar thing earlier, but that had somehow not worked as well. I will check once again. $\endgroup$ Commented Mar 5, 2018 at 8:38

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.