I thought that Mathematica would be smart enough to know that
f[t]^2 should match
a_ * b_ with
b both taking the value
f[t], but it doesn't.
I'm writing some rules for identities involving products. It's mainly finding different ways of doing integration by parts. Am I forced to write separate rules for handling powers, or can Mathematica be persuaded to match
a_ * b_?
I would like to handle arbitrarily large natural powers, so
f[t]^3 should match
a_ * b_ with
f[t]^2, or vice versa.
f[t]^4 should match as both
f[t] * f[t]^3 and
f[t]^2 * f[t]^2. I'm using
ReplaceList, so the order is unimportant. I want the behaviour to be identical to if the powers were represented as
f[t] * f[t] * f[t] ....
If not, is there a nice single pattern I can use to match all cases? I've been looking at
Alternatives, but I don't know how to capture the
b values properly when dealing with the powers forms.
Powerwhile the latter
Times. Seen from this single fact, they two do not match of course. It is not a matter of being smart or not. Pattern matching is performed based on the form of an expression, not its (mathematical) meaning. Using jargon, pattern matching is performed syntactically, not semantically. $\endgroup$
Flatthat allow semantic matching that deviates from those strict rules and I assumed that there would be similar special handling for
Power, although I realise now that there isn't. That's quite inconvenient, because when I have an expression featuring
a * b, and
ahappens to equal
bat some point, MMA automatically transforms it into a power, then all of my rules stop working. Do you know of any concise pattern that is able to match either form interchangably while giving the
Unevaluated, etc. to stop MMA from evaluations before matchings; because MMA "thinks"
Poweris simpler than
Timeswhen multiplying factors are the same. Or why do you not just using
Powerto construct the matching rules? $\endgroup$
Power, but they would be duplicates of ones I've already written that use
Times. Although I'm not sure how to get the exact functionality I need. I'm using
ReplaceListto get every possible match with
a_ * b_, but I don't know how to write a rule for
Powerthat gives all of the different forms of
f[t] * f[t]^3and
f[t]^2 * f[t]^2. The best idea I have is to do this in two stages, first transforming all
Powerinto a new head
myTimesthen doing my matching against that. That feels like a hack. $\endgroup$
Holdetc, because I'm passing these expressions through other functions that transform them too. I'll have another read of the docs in case I'm missing something that I could do there. $\endgroup$