Suppose I have a function of the form $ a_1 a_2 \cdots a_n b_1 \cdots b_m \cdots f[L[x,y]]$. I want to make some particular letters and their power inside the bracket.

i.e., I want the letter $\alpha, \beta$ be inside the bracket \begin{align} X * \alpha^{m} *\beta^{n} f[A[x,y]] \Rightarrow X f[\alpha^{m}\beta^{n} A[x,y]] \end{align} What I know for the include of function in general is the following :

 a*f[L[x, y]] /. {A_ f[x__] -> f[A*x]}

but this does not specify the certain conditions for my purpose. i.e., for Xaf[L[x,y]] it just gives f[a X L[x,y]]$.

Specifically what I want to do is for some specific powers of letters $X*\alpha^{m}*\beta^{n}*\gamma^{l}*\delta^{e} f[A[x,y]]$ I want to pick some letter, i.e. ,$\alpha, \beta$, and include this the function $f$, i.e. ,I want my result be $X \gamma^{l} \delta^{e} f[ \alpha^{m} \beta^{n} A[x,y]]$

Without explicit substitution case by case, are there a nice way to implement this by mathematica?


1 Answer 1


(* "13.3.1 for Mac OS X ARM (64-bit) (July 24, 2023)" *)


rule = {(A : _?(! FreeQ[#, a | b] &) : 1)*
  (B : _?(FreeQ[#, a | b] &) : 1)*f[x__] -> B*f[A*x]};

test = {X f[L[x, y]], a*f[L[x, y]], a*X*f[L[x, y]], b^n*X*f[L[x, y]], 
   a^m*b*X*f[L[x, y]], a^m*b^n*X*f[L[x, y]]};

Transpose[{test, test /. rule}] // Column

enter image description here

  • $\begingroup$ if I want to include $c$ or $d$ in the rule, what should I modify? $\endgroup$
    – phy_math
    Commented Dec 5, 2023 at 7:03
  • $\begingroup$ Look at the documentation for Alternatives, it can take as many arguments as you want. $\endgroup$
    – Bob Hanlon
    Commented Dec 5, 2023 at 7:58

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.