Does Mathematica always return a rational number in its simplified form?

0

If I enter: 1/RandomInteger[10^200]+1/RandomInteger[10^200] I get (instantly) an exact fraction. Is this fraction in simplified (reduced) form? In other words is the greatest common divisor of the numerator and denominator equal to 1?.

Geoffrey Critzer

Posted 2015-03-18T13:05:40.590

Reputation: 1 531

Question was closed 2015-03-18T18:39:50.227

Yes. (And what does the reference to RandomInteger have to do with the fundamental question anyway?) – David G. Stork – 2015-03-18T13:12:44.963

The function RandomInteger has nothing to do with my question. My question is how does Mathematica simplify a fraction so quickly. I thought simplifying the fraction would necessitate factoring the integers. – Geoffrey Critzer – 2015-03-18T13:39:13.603

I strongly recommend you change your question title (which isn't a question anyway) to be relate to your actual question. Future users will be very confused by your irrelevant reference to RandomInteger. – David G. Stork – 2015-03-18T13:42:34.873

Now that I have thought better about it I see that we do not need to factor the integers (numerator and denominator) in order to simplify a fraction. – Geoffrey Critzer – 2015-03-18T13:51:48.123

2It is not necessary to factor the integers. Euclidean algorithm can computer the greatest common factor, then both the numerator and denominator divide the gcd. All the operations is only the division. – Amita – 2015-03-18T13:53:43.900

2Note that if you would like it not to reduce the Rational, you can use Internal`RationalNoReduce (e.g. Internal`RationalNoReduce[2, 4]). The lack of reduction is persistent. – Dan Fortunato – 2015-03-18T15:59:03.750

Answers

3

The answer is yes, and you can also test it.

1/RandomInteger[10^200] + 1/RandomInteger[10^200] /. 
 Rational[a_, b_] :> GCD[a, b]
1

Amita

Posted 2015-03-18T13:05:40.590

Reputation: 249