Are Rationals that expensive?

Memory allocation is expected for rationals because BigInt isn’t a machine type.

You can think of BigInts as pointers to dynamically-sized numbers of bits which hold the information for how big that integer is. So as with anything with pointers involved (arrays), you’ll be allocating a lot of memory to make it work. That’s why most math is not done with arbitrary precision arithmetic (of which Rational{BigInt} is as far as it gets): it’s very expensive and there’s no way for it to not be (unless you have an idea… that would be a great Julia library!)

If you want fast arbitrary precision arithmetic, the best setup is likely to use ArbFloats.

They will be much faster than BigFloats until you get up to some absurd levels of precision. They also allow for doing interval arithmetic to show uncertainties, but as @stevangj has already mentioned, interval arithmetic is known to have very pessimistic error bounds and so it is really only applicable in some domains.

For Rational{Int} performance, see issue #11522. These changes could probably be made soon, if someone is keen.

@dpsanders, Thanks for the tip, I transformed the problem to use ValidatedNumerics!

3 Likes

Great! Let me know if you have any questions. I’d be very interested to see your code.

2 Likes

@dpsanders
Paper describing what we did is here:

Relevant code is located here:
https://git.wmi.amu.edu.pl/kalmar/PropertyT.jl/src/master/src/checksolution.jl

comments, questions are welcome!
btw. how can I cite ValidatedNumerics package?

2 Likes

Great, thanks, I’ll take a look.

Good question about citing VN, I’ll get back to you about that.

2 Likes