There's consensus that answering with fractions is allowable for decimals that can be expressed as fractions. But what about irrational numbers? Can they be expressed as a rational representation of the corresponding decimal approximation?


\$\sqrt{2}\$ can be approximated as \$1.4142135623730951\$, and that's fine because we've established that questions need to establish accuracy. But is approximating it as something like \$\frac{6369051672525773}{4503599627370496}\$ or \$\frac{665857}{470832}\$ allowable?

\$\pi\$ is approximately \$3.1415926535897\$, and can be represented by something like \$\frac{3126535}{995207}\$ or \$\frac{884279719003555}{281474976710656}\$, but is that valid?

Essentially, can fractions be used to approximate irrationals?


I'd say sure

After all, a float is just a fraction with some extra rules on top. If you can output a fraction that's approximately as accurate as a typical floating point number, I see no reason it shouldn't be allowed.

I think the easiest way to handle this would be to apply any rules the author specifies for floating point numbers' accuracy to fractions, unless they specify a rule for fractions specifically.

  • 7
    \$\begingroup\$ Another argument to support this: If a challenge specifies accuracy requirements, one can show that the outputted fraction falls within the accepted interval. Otherwise, we can idealize rationals just like how we idealize floats to real numbers. Also, (not really an argument but) limited precision rational machine is something that exists. \$\endgroup\$
    – Bubbler
    Nov 5 at 1:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .