Taking the numerator and the denominator
$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.
expression-manipulation
$endgroup$
add a comment |
$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.
expression-manipulation
$endgroup$
add a comment |
$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.
expression-manipulation
$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
expression-manipulation
asked yesterday
KvotheKvothe
926317
926317
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
$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}
$endgroup$
add a comment |
$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
.
$endgroup$
add a comment |
$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 *)
$endgroup$
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
$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}
$endgroup$
add a comment |
$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}
$endgroup$
add a comment |
$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}
$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}
answered yesterday
Carl WollCarl Woll
70.9k394184
70.9k394184
add a comment |
add a comment |
$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
.
$endgroup$
add a comment |
$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
.
$endgroup$
add a comment |
$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
.
$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
.
answered yesterday
marchmarch
17.4k22769
17.4k22769
add a comment |
add a comment |
$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 *)
$endgroup$
add a comment |
$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 *)
$endgroup$
add a comment |
$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 *)
$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 *)
answered yesterday
MelaGoMelaGo
2163
2163
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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