Given a rational function $$ f(x_1,x_2) = \dfrac{r_1 x_1^2 + r_2 x_2}{r_3 x_1 + r_4 x_2}, $$ with $r_i$ arbitrary real or complex numbers, is there a built-in function to get Mathemtica to rewrite as $$ f(x_1,x_2) = \dfrac{x_1^2 + \frac{r_2}{r_1}x_2}{\frac{r_3}{r_1} x_1 + \frac{r_4}{r_1} x_2} ? $$ I wrote a function that finds $r_{max}$ (the $r_i$ with largest modulus) and rescales all other $r_i$'s by the $r_{max}$:

rescale[x_] :=
out, scale
out = x;
scale =
Cases[out,z_ /; Head[z] === Complex || Head[z] === Real, Infinity] // Union;
scale = First[SortBy[scale, Abs[#] &]];
out = out /.
{z_Complex :> Simplify[z/scale], 
r_Real :> Simplify[r/scale]};

Is there a built in Mathematica function that does this? If not, in what ways can I improve this function?

Context: I have such rational functions where the $r_i$ all end up having ridiculously large modulus (say $\cal{O}(|r_{max}|) \sim 10^{750}$), and they clean up nicely under such a replacement.

  • 3
    $\begingroup$ rescale[p_] := Module[{m}, m = First@ SortBy[Flatten@ CoefficientList[{Numerator@p, Denominator@p}, Variables@p], -Abs@# &]; Simplify@(Numerator@p/m)/Simplify@(Denominator@p/m) ] $\endgroup$ Dec 16, 2015 at 22:47
  • $\begingroup$ @belisarius: That performs the same operation as my function, but more compactly/quickly, right? I read that to mean you also do not know of a built-in function that does it. $\endgroup$ Dec 16, 2015 at 22:54
  • $\begingroup$ I believe your sorting is backwards and yours doesn't account for integers or numerical expressions, but it basically does the same, yes $\endgroup$ Dec 16, 2015 at 23:05


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy