# Rescale large numerical factors in rational functions

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_] :=
Module[
{
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]};
out
];


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.

• rescale[p_] := Module[{m}, m = First@ SortBy[Flatten@ CoefficientList[{Numerator@p, Denominator@p}, Variables@p], -Abs@# &]; Simplify@(Numerator@p/m)/Simplify@(Denominator@p/m) ] – Dr. belisarius Dec 16 '15 at 22:47
• @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. – jjstankowicz Dec 16 '15 at 22:54
• I believe your sorting is backwards and yours doesn't account for integers or numerical expressions, but it basically does the same, yes – Dr. belisarius Dec 16 '15 at 23:05