2
$\begingroup$

This has been annoying me for a long time. I want a rational function to be represented in the form

$$\frac{a_nx^n+....a_0x^0}{b_mx^m+....b_0x^0}$$

But this seems to be quite difficult. Mathematica really loves to factor things out. //ExpandAll usually gives me a sum of bunch of rational functions. I just want the numerator to be a straightforward polynomial and the denominator to be a straightforward polynomial.

I can //Together to get a single fraction and //Expand the numerator and denominator separately, and then combine them by hand, but that is very annoying and it feels like there should be a command to do this. The form I wrote above is the most common rational function form, so why would it be so difficult to arrive at?

For example what do I need to do the fraction below to get it to be a polynomial divided by a polynomial?

-2/n^3 + (32 n)/(1 - 8 n^2 + 16 n^4)
$\endgroup$
2
  • 1
    $\begingroup$ Actually the Together plus Expand on numerator and denominator is likely to be your best bet. Together typically does not actually factor but it also does not go out of its way to avoid factors, and sometimes it feels a need to do a square-free factorization. It can be a bit headstrong that way. $\endgroup$ Commented May 6, 2021 at 19:59
  • $\begingroup$ I think ExpandNumerator and ExpandDenominator in certain cases can help. Try -2/n^3 + (32 n)/(1 - 8 n^2 + 16 n^4) // Together //ExpandDenominator // ExpandNumerator for your example. $\endgroup$ Commented Jul 1, 2022 at 8:22

4 Answers 4

1
$\begingroup$

Look at the commands ExpandNumerator and ExpandDenominator .

-2/n^3 + (32 n)/(1 - 8 n^2 + 16 n^4) // Together // 
    ExpandNumerator // ExpandDenominator

(*   (-2 + 16 n^2)/(n^3 - 8 n^5 + 16 n^7)  *)
$\endgroup$
0
$\begingroup$

Try

Together[-2/n^3 + (32 n)/(1 - 8 n^2 + 16 n^4)]
(*(2 (-1 + 8 n^2))/(n^3 (-1 + 4 n^2)^2)*)
$\endgroup$
3
  • $\begingroup$ It factors the numerator and the denominator. The result is not a straightforward polynomial. It is a factored polynomial in the numerator and the denominator. $\endgroup$ Commented May 6, 2021 at 19:55
  • $\begingroup$ This works: F[x_] := TraditionalForm[Expand[Numerator[Together[x]]]]/ TraditionalForm[Expand[Denominator[Together[x]]]] , but is there really no default function to see a rational function in the form I want? $\endgroup$ Commented May 6, 2021 at 19:56
  • 2
    $\begingroup$ The function NumeratorDenominator was introduced in v12.0. F[x_] := TraditionalForm[Divide @@ Expand@NumeratorDenominator@Together@x] $\endgroup$
    – Bob Hanlon
    Commented May 6, 2021 at 22:33
0
$\begingroup$

Apply Factor or Together to the expression, separate the numerator and denominator, then Expand and form the fraction.

eq = -2/n^3 + (32 n)/(1 - 8 n^2 + 16 n^4);

(#1 / #2) &@@ Expand[Through[{Numerator, Denominator}[Together[eq]]]] // TraditionalForm

$$\frac{16 n^2-2}{16 n^7-8 n^5+n^3}$$

$\endgroup$
0
$\begingroup$

Try this:

With[{eq = -2/n^3 + (32 n)/(1 - 8 n^2 + 16 n^4)},  Inactive@Evaluate@
    Divide @@ ((Expand@#@Simplify@eq) & /@ {Numerator, Denominator})]
    // TeXForm

which returns $$ \left(16 n^2-2\right)/\left(16 n^7-8 n^5+n^3\right) $$

$\endgroup$

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.