1
$\begingroup$

I am trying to replace the following expression with the definition $A[m,n]=\frac{1}{k^ml^n}$. The expression is $W=\frac{1}{k}+\frac{1}{kl}$. So it should give $A[1,0]+A[1,1]$. So I need two replacement condition. But I do not know how to give multiple replacement in mathematica. I tried

W= 1/k+1/(k*l) /. {k^a_*l^b_-> A[-a,-b]}, {k^a_ -> A[-a,0]}

But it is not recognizing the second replacement rule

$\endgroup$
1
  • $\begingroup$ think you had an error in the symbols have fixed this to match the answer $\endgroup$
    – Dunlop
    Jul 7 at 4:02

1 Answer 1

4
$\begingroup$
ClearAll[a,b,L,k];
W=1/k+1/(k*L);

You can do

W /. k^a_*L^b_ -> A[-a, -b] /. k^a_ -> A[-a, 0]

Mathematica graphics

Or

W/. k^a_*L^b_->A[-a,-b]/.Power[k,a_]->A[-a,0]

Mathematica graphics

Do not add {..},{..} around patterns.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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