Taking the numerator and the denominator












6












$begingroup$


Is there any way to get the Numerator and the Denominator of an expression split in the same way that Mathematica graphically represents it.



Say I have an expression:



(a^(p1 + p2 - p3) b^(p1 - p2 + p3))/(c d)


When plugged into mathematica it gets represented with the $c$ and $d$ in the denominator but if I were to try to extract the numerator and denominator with respectively Numerator and Denominator I would not get the same split. I understand that a different (probably more sensible) choice of representation is made in Numerator and Denominator. However, is it possible to (automatically and reliably) take the denominator and numerator parts as split in the graphical representation? Mathematica must be able to determine this split since it has to decide how to graphically represent the output.










share|improve this question









$endgroup$

















    6












    $begingroup$


    Is there any way to get the Numerator and the Denominator of an expression split in the same way that Mathematica graphically represents it.



    Say I have an expression:



    (a^(p1 + p2 - p3) b^(p1 - p2 + p3))/(c d)


    When plugged into mathematica it gets represented with the $c$ and $d$ in the denominator but if I were to try to extract the numerator and denominator with respectively Numerator and Denominator I would not get the same split. I understand that a different (probably more sensible) choice of representation is made in Numerator and Denominator. However, is it possible to (automatically and reliably) take the denominator and numerator parts as split in the graphical representation? Mathematica must be able to determine this split since it has to decide how to graphically represent the output.










    share|improve this question









    $endgroup$















      6












      6








      6





      $begingroup$


      Is there any way to get the Numerator and the Denominator of an expression split in the same way that Mathematica graphically represents it.



      Say I have an expression:



      (a^(p1 + p2 - p3) b^(p1 - p2 + p3))/(c d)


      When plugged into mathematica it gets represented with the $c$ and $d$ in the denominator but if I were to try to extract the numerator and denominator with respectively Numerator and Denominator I would not get the same split. I understand that a different (probably more sensible) choice of representation is made in Numerator and Denominator. However, is it possible to (automatically and reliably) take the denominator and numerator parts as split in the graphical representation? Mathematica must be able to determine this split since it has to decide how to graphically represent the output.










      share|improve this question









      $endgroup$




      Is there any way to get the Numerator and the Denominator of an expression split in the same way that Mathematica graphically represents it.



      Say I have an expression:



      (a^(p1 + p2 - p3) b^(p1 - p2 + p3))/(c d)


      When plugged into mathematica it gets represented with the $c$ and $d$ in the denominator but if I were to try to extract the numerator and denominator with respectively Numerator and Denominator I would not get the same split. I understand that a different (probably more sensible) choice of representation is made in Numerator and Denominator. However, is it possible to (automatically and reliably) take the denominator and numerator parts as split in the graphical representation? Mathematica must be able to determine this split since it has to decide how to graphically represent the output.







      expression-manipulation






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked yesterday









      KvotheKvothe

      926317




      926317






















          3 Answers
          3






          active

          oldest

          votes


















          7












          $begingroup$

          The problem is that the negative terms in the exponent are being included in the denominator. A way to workaround this is to inactivate Plus, use Numerator and Denominator, and reactivate:



          expr = (a^(p1+p2-p3) b^(p1-p2+p3))/(c d);

          Activate @* Through @* {Numerator, Denominator} @* ReplaceAll[Plus->Inactive[Plus]] @ expr



          {a^(p1 + p2 - p3) b^(p1 - p2 + p3), c d}







          share|improve this answer









          $endgroup$





















            3












            $begingroup$

            So, for your particular expression (which is a single fraction), the following kluge works:



            expr = (a^(p1 + p2 - p3) b^(p1 - p2 + p3))/(c d);
            ToExpression /@ List @@ ToBoxes@expr
            (* {a^(p1 + p2 - p3) b^(p1 - p2 + p3), c d} *)


            This is a little tricky to automat, because you have to inspect the formatting expression that you get.





            This uses the visual formatting in the following way. ToBoxes converts the output to front-end formatting:



            ToBoxes@expr
            (* FractionBox[
            RowBox[{SuperscriptBox["a", RowBox[{"p1", "+", "p2", "-", "p3"}]], " ", SuperscriptBox["b", RowBox[{"p1", "-", "p2", "+", "p3"}]]}],
            RowBox[{"c", " ", "d"}]
            ] *)


            Then, noting that the numerator and the denominator are the first and second elements of the the FractionBox expression, we replace FractionBox with List using List@@, and then convert the remaining formatting expression to Mathematica input expressions using ToExpression.






            share|improve this answer









            $endgroup$





















              0












              $begingroup$

              Here is another option using TeXForm.



              expr = (a^(p1 + p2 - p3) b^(p1 - p2 + p3))/(c d);
              t = ToString[TeXForm[expr]]

              (* frac{a^{text{p1}+text{p2}-text{p3}} b^{text{p1}-text{p2}+text{p3}}}{c d} *)


              Numerator:



              ToExpression[StringCases[t, RegularExpression["frac{(.+)}{(.+)}$"] -> "$1"][[1]], TeXForm]

              (* a^(p1 + p2 - p3) b^(p1 - p2 + p3) *)


              Denominator:



              ToExpression[StringCases[t, RegularExpression["frac{(.+)}{(.+)}$"] -> "$2"][[1]], TeXForm]

              (* cd *)





              share|improve this answer









              $endgroup$













                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',
                autoActivateHeartbeat: false,
                convertImagesToLinks: false,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                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%2f193569%2ftaking-the-numerator-and-the-denominator%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                7












                $begingroup$

                The problem is that the negative terms in the exponent are being included in the denominator. A way to workaround this is to inactivate Plus, use Numerator and Denominator, and reactivate:



                expr = (a^(p1+p2-p3) b^(p1-p2+p3))/(c d);

                Activate @* Through @* {Numerator, Denominator} @* ReplaceAll[Plus->Inactive[Plus]] @ expr



                {a^(p1 + p2 - p3) b^(p1 - p2 + p3), c d}







                share|improve this answer









                $endgroup$


















                  7












                  $begingroup$

                  The problem is that the negative terms in the exponent are being included in the denominator. A way to workaround this is to inactivate Plus, use Numerator and Denominator, and reactivate:



                  expr = (a^(p1+p2-p3) b^(p1-p2+p3))/(c d);

                  Activate @* Through @* {Numerator, Denominator} @* ReplaceAll[Plus->Inactive[Plus]] @ expr



                  {a^(p1 + p2 - p3) b^(p1 - p2 + p3), c d}







                  share|improve this answer









                  $endgroup$
















                    7












                    7








                    7





                    $begingroup$

                    The problem is that the negative terms in the exponent are being included in the denominator. A way to workaround this is to inactivate Plus, use Numerator and Denominator, and reactivate:



                    expr = (a^(p1+p2-p3) b^(p1-p2+p3))/(c d);

                    Activate @* Through @* {Numerator, Denominator} @* ReplaceAll[Plus->Inactive[Plus]] @ expr



                    {a^(p1 + p2 - p3) b^(p1 - p2 + p3), c d}







                    share|improve this answer









                    $endgroup$



                    The problem is that the negative terms in the exponent are being included in the denominator. A way to workaround this is to inactivate Plus, use Numerator and Denominator, and reactivate:



                    expr = (a^(p1+p2-p3) b^(p1-p2+p3))/(c d);

                    Activate @* Through @* {Numerator, Denominator} @* ReplaceAll[Plus->Inactive[Plus]] @ expr



                    {a^(p1 + p2 - p3) b^(p1 - p2 + p3), c d}








                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered yesterday









                    Carl WollCarl Woll

                    70.9k394184




                    70.9k394184























                        3












                        $begingroup$

                        So, for your particular expression (which is a single fraction), the following kluge works:



                        expr = (a^(p1 + p2 - p3) b^(p1 - p2 + p3))/(c d);
                        ToExpression /@ List @@ ToBoxes@expr
                        (* {a^(p1 + p2 - p3) b^(p1 - p2 + p3), c d} *)


                        This is a little tricky to automat, because you have to inspect the formatting expression that you get.





                        This uses the visual formatting in the following way. ToBoxes converts the output to front-end formatting:



                        ToBoxes@expr
                        (* FractionBox[
                        RowBox[{SuperscriptBox["a", RowBox[{"p1", "+", "p2", "-", "p3"}]], " ", SuperscriptBox["b", RowBox[{"p1", "-", "p2", "+", "p3"}]]}],
                        RowBox[{"c", " ", "d"}]
                        ] *)


                        Then, noting that the numerator and the denominator are the first and second elements of the the FractionBox expression, we replace FractionBox with List using List@@, and then convert the remaining formatting expression to Mathematica input expressions using ToExpression.






                        share|improve this answer









                        $endgroup$


















                          3












                          $begingroup$

                          So, for your particular expression (which is a single fraction), the following kluge works:



                          expr = (a^(p1 + p2 - p3) b^(p1 - p2 + p3))/(c d);
                          ToExpression /@ List @@ ToBoxes@expr
                          (* {a^(p1 + p2 - p3) b^(p1 - p2 + p3), c d} *)


                          This is a little tricky to automat, because you have to inspect the formatting expression that you get.





                          This uses the visual formatting in the following way. ToBoxes converts the output to front-end formatting:



                          ToBoxes@expr
                          (* FractionBox[
                          RowBox[{SuperscriptBox["a", RowBox[{"p1", "+", "p2", "-", "p3"}]], " ", SuperscriptBox["b", RowBox[{"p1", "-", "p2", "+", "p3"}]]}],
                          RowBox[{"c", " ", "d"}]
                          ] *)


                          Then, noting that the numerator and the denominator are the first and second elements of the the FractionBox expression, we replace FractionBox with List using List@@, and then convert the remaining formatting expression to Mathematica input expressions using ToExpression.






                          share|improve this answer









                          $endgroup$
















                            3












                            3








                            3





                            $begingroup$

                            So, for your particular expression (which is a single fraction), the following kluge works:



                            expr = (a^(p1 + p2 - p3) b^(p1 - p2 + p3))/(c d);
                            ToExpression /@ List @@ ToBoxes@expr
                            (* {a^(p1 + p2 - p3) b^(p1 - p2 + p3), c d} *)


                            This is a little tricky to automat, because you have to inspect the formatting expression that you get.





                            This uses the visual formatting in the following way. ToBoxes converts the output to front-end formatting:



                            ToBoxes@expr
                            (* FractionBox[
                            RowBox[{SuperscriptBox["a", RowBox[{"p1", "+", "p2", "-", "p3"}]], " ", SuperscriptBox["b", RowBox[{"p1", "-", "p2", "+", "p3"}]]}],
                            RowBox[{"c", " ", "d"}]
                            ] *)


                            Then, noting that the numerator and the denominator are the first and second elements of the the FractionBox expression, we replace FractionBox with List using List@@, and then convert the remaining formatting expression to Mathematica input expressions using ToExpression.






                            share|improve this answer









                            $endgroup$



                            So, for your particular expression (which is a single fraction), the following kluge works:



                            expr = (a^(p1 + p2 - p3) b^(p1 - p2 + p3))/(c d);
                            ToExpression /@ List @@ ToBoxes@expr
                            (* {a^(p1 + p2 - p3) b^(p1 - p2 + p3), c d} *)


                            This is a little tricky to automat, because you have to inspect the formatting expression that you get.





                            This uses the visual formatting in the following way. ToBoxes converts the output to front-end formatting:



                            ToBoxes@expr
                            (* FractionBox[
                            RowBox[{SuperscriptBox["a", RowBox[{"p1", "+", "p2", "-", "p3"}]], " ", SuperscriptBox["b", RowBox[{"p1", "-", "p2", "+", "p3"}]]}],
                            RowBox[{"c", " ", "d"}]
                            ] *)


                            Then, noting that the numerator and the denominator are the first and second elements of the the FractionBox expression, we replace FractionBox with List using List@@, and then convert the remaining formatting expression to Mathematica input expressions using ToExpression.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered yesterday









                            marchmarch

                            17.4k22769




                            17.4k22769























                                0












                                $begingroup$

                                Here is another option using TeXForm.



                                expr = (a^(p1 + p2 - p3) b^(p1 - p2 + p3))/(c d);
                                t = ToString[TeXForm[expr]]

                                (* frac{a^{text{p1}+text{p2}-text{p3}} b^{text{p1}-text{p2}+text{p3}}}{c d} *)


                                Numerator:



                                ToExpression[StringCases[t, RegularExpression["frac{(.+)}{(.+)}$"] -> "$1"][[1]], TeXForm]

                                (* a^(p1 + p2 - p3) b^(p1 - p2 + p3) *)


                                Denominator:



                                ToExpression[StringCases[t, RegularExpression["frac{(.+)}{(.+)}$"] -> "$2"][[1]], TeXForm]

                                (* cd *)





                                share|improve this answer









                                $endgroup$


















                                  0












                                  $begingroup$

                                  Here is another option using TeXForm.



                                  expr = (a^(p1 + p2 - p3) b^(p1 - p2 + p3))/(c d);
                                  t = ToString[TeXForm[expr]]

                                  (* frac{a^{text{p1}+text{p2}-text{p3}} b^{text{p1}-text{p2}+text{p3}}}{c d} *)


                                  Numerator:



                                  ToExpression[StringCases[t, RegularExpression["frac{(.+)}{(.+)}$"] -> "$1"][[1]], TeXForm]

                                  (* a^(p1 + p2 - p3) b^(p1 - p2 + p3) *)


                                  Denominator:



                                  ToExpression[StringCases[t, RegularExpression["frac{(.+)}{(.+)}$"] -> "$2"][[1]], TeXForm]

                                  (* cd *)





                                  share|improve this answer









                                  $endgroup$
















                                    0












                                    0








                                    0





                                    $begingroup$

                                    Here is another option using TeXForm.



                                    expr = (a^(p1 + p2 - p3) b^(p1 - p2 + p3))/(c d);
                                    t = ToString[TeXForm[expr]]

                                    (* frac{a^{text{p1}+text{p2}-text{p3}} b^{text{p1}-text{p2}+text{p3}}}{c d} *)


                                    Numerator:



                                    ToExpression[StringCases[t, RegularExpression["frac{(.+)}{(.+)}$"] -> "$1"][[1]], TeXForm]

                                    (* a^(p1 + p2 - p3) b^(p1 - p2 + p3) *)


                                    Denominator:



                                    ToExpression[StringCases[t, RegularExpression["frac{(.+)}{(.+)}$"] -> "$2"][[1]], TeXForm]

                                    (* cd *)





                                    share|improve this answer









                                    $endgroup$



                                    Here is another option using TeXForm.



                                    expr = (a^(p1 + p2 - p3) b^(p1 - p2 + p3))/(c d);
                                    t = ToString[TeXForm[expr]]

                                    (* frac{a^{text{p1}+text{p2}-text{p3}} b^{text{p1}-text{p2}+text{p3}}}{c d} *)


                                    Numerator:



                                    ToExpression[StringCases[t, RegularExpression["frac{(.+)}{(.+)}$"] -> "$1"][[1]], TeXForm]

                                    (* a^(p1 + p2 - p3) b^(p1 - p2 + p3) *)


                                    Denominator:



                                    ToExpression[StringCases[t, RegularExpression["frac{(.+)}{(.+)}$"] -> "$2"][[1]], TeXForm]

                                    (* cd *)






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered yesterday









                                    MelaGoMelaGo

                                    2163




                                    2163






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Mathematica Stack Exchange!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        Use MathJax to format equations. MathJax reference.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f193569%2ftaking-the-numerator-and-the-denominator%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        數位音樂下載

                                        When can things happen in Etherscan, such as the picture below?

                                        格利澤436b