Mathematica 9 is now available
Student Support Forum
Student Support Forum: 'pattern matching a^n b^m->f[n,m]' topicStudent Support Forum > General > "pattern matching a^n b^m->f[n,m]"

Help | Reply To Topic
Author Comment/Response
Beat T
10/08/03 8:15pm

Dear student support,
is there a simple way to replace in an expression (not necessarily a polynomial) all subexpressions of the form a^n b^m by f[n,m],including the cases m,n=0 and m,n=1? If I'm trying a^n_ b^m_->f[n,m], this (of course) does not work in the cases {a b^m, a^n b,a b,a,b,1}, since MatchQ[#, a^m_ b^n_]& /@ {a b^m, a^n b, a b, a, b, 1 }={false,false,...}. So I'd like to avoid writing out all "special cases" ( as in a b^m_->f[1,m],a^n b->f[n,1],a->f[1,0] etc.)
Can you help?
Kind regards,
Beat T

URL: ,
Help | Reply To Topic