Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Reliability of rational arithmetic #11736
Consider the following code that computes a cubic root using Newton's method from a given initial value:
Let's do this in the standard way, using floating-point arithmetic (
The result is
Since the root that the iteration converges to is hard to predict, let's try again using rational arithmetic:
This can be tracked down to the usual issue with rational arithmetic: the denominators of all the intermediate results grow rapidly and overflow the
So let's try
with the result:
That's what I think everyone would have expected to get - but it takes considerable care and ugly syntax to get there.
Finally, let's see the remaining intermediate option,
The result is surprising:
Question: are there any situations where arithmetic
In my personal experience, rational arithmetic is mainly used for infinite-precision computations, where correctness is the top priority. This implies that
@khinsen I did bring up the issue of how the arithmetic in julia is unchecked, but I just looked at the code for rational numbers, and they are supposed to be used checked arithmetic (i.e.
@pao: I am not familiar enough with Julia internals to prepare a bug report about checked Int128 arithmetic, sorry! If it's a fixed problem in LLVM, I guess we just have to wait anyway.
@simonbyrne: After reading through #11522, I understand that some people are interested in high-performance rational arithmetic within the limits of Int64 denominators, and that this somehow relates to interpolation, but I didn't find any more explicit reference to a use case.