I have expressions like
and I want to replace
tc by something else, but only if it occurs inside
Cos, i.e. the outer
tc should remain as is. Is there any way of specifying the context in which
Replace should act? Maybe some clever pattern tricks?
Note that the actual expressions I'm working on are more complicated and consist of more (similar) terms, so just skipping over the first occurrence isn't going to cut it.
ReplaceAll[c_Cos?(Not@*FreeQ[tc]):>ReplaceAll[c, tc->new]]should do it. It's not a nice pattern to work with. Will be slow. But if the
tccan appear in an arbitrary expression within
Costhen there's not too much else I know to do. $\endgroup$