I have a boundary condition for a problem, which contains around 100 terms! I have no trouble getting Mathematica to compute it, but the terms are sorted in a seemingly random order and I would like to organise them to make it a bit easier to deal with without having to manual.
Consider the following expression:
\begin{align*} & \dfrac{\partial A_{1}}{\partial x}\dfrac{\partial A_{2}}{\partial y}+\dfrac{\partial A_{2}}{\partial x}\dfrac{\partial A_{3}}{\partial z}+\dfrac{\partial A_{3}}{\partial y}\dfrac{\partial A_{1}}{\partial z}\\ & +\dfrac{\partial A_{1}}{\partial x}\dfrac{\partial B_{2}}{\partial y}+\dfrac{\partial A_{2}}{\partial x}\dfrac{\partial B_{3}}{\partial z}+\dfrac{\partial A_{3}}{\partial y}\dfrac{\partial B_{1}}{\partial z}\\ & +\dfrac{\partial B_{1}}{\partial x}\dfrac{\partial C_{2}}{\partial y}+\dfrac{\partial B_{2}}{\partial x}\dfrac{\partial C_{3}}{\partial z}+\dfrac{\partial B_{3}}{\partial y}\dfrac{\partial C_{1}}{\partial z}\\ & +\dfrac{\partial B_{1}}{\partial x}\dfrac{\partial C_{2}}{\partial y}+\dfrac{\partial C_{1}}{\partial x}\dfrac{\partial C_{1}}{\partial z}+\dfrac{\partial C_{1}}{\partial y}\dfrac{\partial C_{1}}{\partial z}\\ & +\dfrac{\partial A_{1}}{\partial x}C_{1}+\dfrac{\partial A_{2}}{\partial y}C_{2}+\dfrac{\partial A_{3}}{\partial z}C_{3} \end{align*}
I am very new to patterns/matching, but could somebody please explain how I can use these to extract all terms from the above expression which contain:
- $\dfrac{\partial A_i}{\partial x_k}\dfrac{\partial A_j}{\partial x_\ell }$
- $\left(\dfrac{\partial A_i}{\partial x_k}\right)^2$
- $C_i\dfrac{\partial A_j}{\partial x_k}$
where $i,j,k,\ell\in\{1,2,3\}$ and $x_1=x,x_2=y,x_3=z$.
Obviously the way I have specified the terms above lends itself to the use of a Table command, but I would like to be able to do this in such a way which is independent of the choice of subscripts, and can be picked up from whatever the expression is. How can I elegantly answer the above questions?