Replacement rule to display negative exponents as denominators

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












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(fracf(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?







share|improve this question


























    up vote
    3
    down vote

    favorite












    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(fracf(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?







    share|improve this question
























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      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(fracf(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?







      share|improve this question














      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(fracf(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?









      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 18 at 11:52









      kglr

      157k8181378




      157k8181378










      asked Aug 18 at 0:23









      theorist

      997319




      997319




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










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



          $left(fracf(t)g(t)right)^a+f(t)^b+g(t)^-c$







          share|improve this answer




















          • 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 at 0:45






          • 1




            @theorist, added c_. to cover cases like expr2 = f[t]^b + someCoeff f[t]^a g[t]^-a + g[t]^-c
            – kglr
            Aug 18 at 0:48










          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "387"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f180193%2freplacement-rule-to-display-negative-exponents-as-denominators%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          4
          down vote



          accepted










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



          $left(fracf(t)g(t)right)^a+f(t)^b+g(t)^-c$







          share|improve this answer




















          • 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 at 0:45






          • 1




            @theorist, added c_. to cover cases like expr2 = f[t]^b + someCoeff f[t]^a g[t]^-a + g[t]^-c
            – kglr
            Aug 18 at 0:48














          up vote
          4
          down vote



          accepted










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



          $left(fracf(t)g(t)right)^a+f(t)^b+g(t)^-c$







          share|improve this answer




















          • 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 at 0:45






          • 1




            @theorist, added c_. to cover cases like expr2 = f[t]^b + someCoeff f[t]^a g[t]^-a + g[t]^-c
            – kglr
            Aug 18 at 0:48












          up vote
          4
          down vote



          accepted







          up vote
          4
          down vote



          accepted






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



          $left(fracf(t)g(t)right)^a+f(t)^b+g(t)^-c$







          share|improve this answer












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



          $left(fracf(t)g(t)right)^a+f(t)^b+g(t)^-c$








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 18 at 0:37









          kglr

          157k8181378




          157k8181378











          • 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 at 0:45






          • 1




            @theorist, added c_. to cover cases like expr2 = f[t]^b + someCoeff f[t]^a g[t]^-a + g[t]^-c
            – kglr
            Aug 18 at 0:48
















          • 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 at 0:45






          • 1




            @theorist, added c_. to cover cases like expr2 = f[t]^b + someCoeff f[t]^a g[t]^-a + g[t]^-c
            – kglr
            Aug 18 at 0:48















          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 at 0:45




          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 at 0:45




          1




          1




          @theorist, added c_. to cover cases like expr2 = f[t]^b + someCoeff f[t]^a g[t]^-a + g[t]^-c
          – kglr
          Aug 18 at 0:48




          @theorist, added c_. to cover cases like expr2 = f[t]^b + someCoeff f[t]^a g[t]^-a + g[t]^-c
          – kglr
          Aug 18 at 0:48












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f180193%2freplacement-rule-to-display-negative-exponents-as-denominators%23new-answer', 'question_page');

          );

          Post as a guest













































































          這個網誌中的熱門文章

          How to combine Bézier curves to a surface?

          Mutual Information Always Non-negative

          Why am i infinitely getting the same tweet with the Twitter Search API?