Message Boards Message Boards

0
|
6196 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Pattern recognition of exponents 0 and 1.

Posted 9 years ago

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

3 Replies

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.

POSTED BY: Ivan Morozov

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.

POSTED BY: Sander Huisman
POSTED BY: Isaac Abraham
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract