The title will be clearer with the examples below:
expr1 = \!\(
\*SubsuperscriptBox[\(\[Sum]\), \(i = 1\), \(2\)]\(
\*SubsuperscriptBox[\(\[Sum]\), \(j = 1\), \(3\)]
\*SubscriptBox[\(x\), \(i\)]
\*SubscriptBox[\(y\), \(j\)]\)\) + xy
expr2= \!\(
\*SubsuperscriptBox[\(\[Sum]\), \(i = 1\), \(3\)]\ \(
\*SubsuperscriptBox[\(\[Product]\), \(j = 1\), \(2\)]\((
\*SubscriptBox[\(x\), \(i\)] - \
\*SubscriptBox[\(y\), \(j\)])\)\(\ \ \)\)\) + (x-y)
I want to keep in expr1 all the terms whose subscripts are not identical.
I can obtain this with
Cases[expr1 /. Plus -> List,
Times[Subscript[_, a_], Subscript[_, b_]] /; a != b] /. List -> Plus
With expr2 same objective but I have now more than one Plus in the FullForm of this expression and I do not know the method to extend the Cases I coded before. I know the existence of TreeForm but not how it can help here.(if it does)
I would like to get;
(Subscript[x, 1] - Subscript[y, 2]) + (Subscript[x, 2] - Subscript[y,
1]) + (Subscript[x, 3] - Subscript[y, 1]) (Subscript[x, 3] -
Subscript[y, 2])
Can the the pattern/replace here be used without coding Cases?
