<div dir="ltr">Clojure also performs automatic reduction of rational numbers. However, the source code seems to indicate that reduction is built into the definitions of the methods that perform arithmetic on rational numbers, and the "Ratio" class that implements rational number support does not do any reduction itself.<div><br></div><div>(c.f. <a href="https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Numbers.java">https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Numbers.java</a>, ll. 350-364, 704-727, et al)</div><div><br></div><div>From a semantic standpoint, I would be very surprised if e.g. 2/6 and 1/3 were not considered equal, or for that matter if they weren't completely interchangeable.</div><div><br></div><div>- Austin</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec 3, 2015 at 11:21 PM, Kevin Ballard <span dir="ltr"><<a href="mailto:kevin@sb.org" target="_blank">kevin@sb.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Dec 3, 2015, at 9:48 PM, Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com">gribozavr@gmail.com</a>> wrote:<br>
><br>
>> A good invariant for Rationals might be having them always<br>
>> represented in the most simplified form - for example, Rational(2, 6) should<br>
>> be represented internally as 1/3 when constructed.<br>
><br>
> This has performance tradeoffs. What do other libraries and languages do?<br>
<br>
</span>I know Haskell always reduces Rationals to their reduced form. This does have performance implications, but not doing so has surprising consequences for operations you perform on them. For example, it’s reasonable to expect that Rational(2,6) == Rational(1,3), but implementing that without reduced Rationals pretty much requires reducing them on the fly. The alternative, of saying they’re not equal, would probably surprise most people.<br>
<span class="HOEnZb"><font color="#888888"><br>
-Kevin Ballard</font></span></blockquote></div><br></div>