Hello everybody, I stumbled across the following problem: I want to do the following substitution in some lengthy expression: f[ x^a_ y^b_ z^c_]->g[a,b,c] including the case a,b,c ={0,1}. Of course I could brute force code all the cases 0,1,n>1, but that would require 3^3 terms, and I will probably need to do this with a greater number of variables. So any smart idea is most welcome, and I might learn some coding trick in the process as I have relatively small experience with Mathematica. Cheers
To match 0 and 1 exponents for monomials you could multiply the whole expression by a general monomial, e.g. :
list = Flatten[Table[x ^i y^j z^k, {k, 0, 2}, {j, 0, 2}, {i, 0, 2}]] list x^p y^p z^p /. x^a_ y^b_ z^c_ :> f[a, b, c] /. p -> 0
I.M.
You could use the _. notation like in this example:
_.
integrate[x_^n_., x_] := x^(n + 1)/(n + 1) /; FreeQ[n, x] && n != -1
here x^1 is also matched. By setting the proper defaults you can match most of them.