I would like to select the term Subscript[Cos\[CapitalDelta], Subscript[p, B]] of expression


I can use Take[exp,{-3}] but it is not general. The selection rule should indeed be the terms that start with C. For example, in the above expression, I want terms Subscript[CosΔ, Subscript[p, B]] and Derivative[1][Subscript[CosΔ, Subscript[p, B]]].

For other times I may have expression like


For this expression, I really need the term

 Subscript[C, Subscript[p, B]]

Can anyone help me with this?

  • $\begingroup$ In your expressions it is not clear, how their terms are connected to one another. Now they are simply written as several different input lines within the same cell. Do they form a list? Or, may be, they should be connected by the sign plus? Or what? Further, what do you mean by such a notation as Subscript[Cos\[CapitalDelta], Subscript[p, B]]? Do you mean, may be, Cos[Subscript[\[CapitalDelta], Subscript[p,B]]]? $\endgroup$ – Alexei Boulbitch Aug 27 '18 at 9:38
  • $\begingroup$ @ Alexei Boulbitch sorry, I have changed the messy code. Now, it is more clear. $\endgroup$ – ZHANG Juenjie Aug 27 '18 at 12:15
  • $\begingroup$ It still seems to contain a syntax error: Subscript[Cos\[CapitalDelta], Subscript[p, B]] does not exist within the Mma syntax, unless you mean that it is such a variable with so a strange name. Further, now your expression represents a single term: a product of several factors. In this case I do not understand the sense of your question. $\endgroup$ – Alexei Boulbitch Aug 27 '18 at 12:55

In the first case, this may work out:

FullForm /@ Cases[
  x : Subscript[a_, b_] /; StringTake[ToString[a], {1, 1}] == "C",

{Subscript[CosΔ, Subscript[p, B]], Subscript[CosΔ, Subscript[p, B]]}

It does miss the derivative around the second occurrence, though. I don't know whether this iss desired or not.

  • $\begingroup$ @ Henrik Schumacher How to take into account the Derivative? $\endgroup$ – ZHANG Juenjie Aug 27 '18 at 12:57
  • 1
    $\begingroup$ Cases[exp, x : (Derivative[1][Subscript[a_, b_]]) | Subscript[a_, b_] /; StringTake[ToString[a], {1, 1}] == "C", All] $\endgroup$ – ZHANG Juenjie Aug 27 '18 at 12:59

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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