Message Boards Message Boards

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

Pattern recognition of exponents 0 and 1.

Posted 9 years ago
3 Replies
POSTED BY: Isaac Abraham

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

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
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