# Replacement rule to display negative exponents as denominators

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


$\left(\frac{f(t)}{g(t)}\right)^a+f(t)^b+g(t)^{-c}$

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?

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

$\left(\frac{f(t)}{g(t)}\right)^a+f(t)^b+g(t)^{-c}$
• 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. – theorist Aug 18 '18 at 0:45
• @theorist, added c_. to cover cases like expr2 = f[t]^b + someCoeff f[t]^a g[t]^-a + g[t]^-c – kglr Aug 18 '18 at 0:48