Suppose I have an expression of the form:

expr=f[t]^b + f[t]^a g[t]^-a + g[t]^-c

And I want to create a rule to convert negative exponents to denominators. In the above example, this could be achieved manually as follows:

expr /. f[t]^a* g[t]^-a -> (f[t]/g[t])^a


How would I achieve this with a general pattern match, independent of the identities of the bases and the exponents? In pseudocode, it would look something like this:

expr /. [some expression]^x*[some other expression]^-x -> 
  (some expression/some other expression)^x

I've made several attempts, without success.

Thus far, the only question I've been able to find on the subject is this, but the OP didn't specifically request a simple pattern-match replacement rule. Perhaps as a consequence, the answer is much more complicated than I'd like:

Display negative exponents always as fraction

Here's a related question, which seeks to do the opposite:

How is it possible to prevent separation of negative and positive exponents when symbolic simplifying?


1 Answer 1

expr /. c_. p_^e_  q_^(-1 e_) :> c (p/q)^e // TeXForm


  • $\begingroup$ Yup, that's it—thanks! Since your first version, w/o the c_. , worked fine, I assume you added it to make it more canonical. If so, when would the absence of the c_. cause a failure? I'd be happy to accept the answer but, respecting site conventions, I'll wait the usual couple of days. $\endgroup$
    – theorist
    Aug 18, 2018 at 0:45
  • 1
    $\begingroup$ @theorist, added c_. to cover cases like expr2 = f[t]^b + someCoeff f[t]^a g[t]^-a + g[t]^-c $\endgroup$
    – kglr
    Aug 18, 2018 at 0:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.