3

Here is an example:

enter image description here

Obviously one could cancel $10^{12}$ from the numerator and denominator. I think Mathematica does not do it because this operation is not exact in floating point arithmetic (these are machine numbers). But I don't really care about that level of precision here. How can I force Mathematica to do the cancellation?

(I cannot do it by hand, because this expression is generated automatically inside a bunch of other functions in my code.)

a06e
  • 11,327
  • 4
  • 48
  • 108
  • 1
    I know there are other, possibly better duplicates of this question. Please comment if you find one so that I can add it to the header. – Mr.Wizard Oct 13 '17 at 19:19

3 Answers3

3

One more way is as follows.

expr = (1.2*10^12 + 1.5*10^13 x)/(1.3*10^12 + 1.32*10^13 y);
Rationalize[expr, 0.01] // Simplify

$$ \frac{6 (25 x+2)}{132 y+13}$$

user64494
  • 26,149
  • 4
  • 27
  • 56
1

This works in version 9:

Simplify @ Rationalize @ Factor @ (1.2*10^12 + 1.5*10^13 x)/(1.3*10^12 + 1.32*10^13 y)

(6 (2 + 25 x))/(13 + 132 y)

it doesn't in version 11.

kglr
  • 394,356
  • 18
  • 477
  • 896
0

You can try converting these to ints (as the FractionalPart will be zero)

(1.2*^12 + 1.5*^13 x)/(1.3*^12 + 1.3210*^13 y) /. 
  r_Real?(FractionalPart[#] === 0. &) :> IntegerPart[r] // FullSimplify

(60 (2 + 25 x))/(130 + 1321 y)
b3m2a1
  • 46,870
  • 3
  • 92
  • 239