I am trying (so far unsuccessfully) to isolate terms in an expression which are product of variables with a specific subscript pattern (the b_,_'s). I want only terms for which the first subscript index is different in all b's that appear in a product. e.g. for $b_{1,2} b_{2,1} r_{1,2,2,1}$ the first subscript of the first b is 1 and the first subscript of the second b is 2, so this is a valid term. $b_{1,2} b_{1,1} r_{1,1,2,2}$ would not be valid as the first indices of both b's are identical.

I have tried to use patterns

Expression = $b_{1,1}^2 r_{1,1,2,1} r_{2,1,2,1}+b_{1,2} b_{1,1} r_{1,1,2,2} r_{2,1,2,1} +b_{1,2} b_{2,1} r_{1,2,2,1} r_{2,1,2,2}$

But I already fail to specify a pattern on a product of b's... This works: (It will isolate all terms that contain a b where the second index is 1

Select[Expression, MemberQ[#, Subscript[b_, _, 1]] &]

This however does not:

Select[Expression, MemberQ[#, Subscript[b_, 1, _]]*Subscript[b_, 1, 1]] &]

Any help is greatly appreciated!


1 Answer 1

   /. (Subscript[b, x_, y_] -> btmp[x] Subscript[b, x, y]) )
   /. {btmp[x_]^y_ /; y > 1 -> 0, btmp[x_] -> 1}

This double replacement collects all of the first indices in a temporary multiplier. If any first index appears multiple times, it forms a power which is then replaced with 0. Otherwise, all of the multipliers are re-replaced with 1 again and vanish.

  • $\begingroup$ Thanks! This works nicely! $\endgroup$
    – Adrian
    Feb 11, 2018 at 11:23

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.