From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Fun with Unbounded Rational Numbers Date: Sat, 8 Apr 2017 13:19:19 +0200 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: BYuA7L7MRjuLLjcoGHOBxw.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:46543 Date: 2017-04-08T13:19:19+02:00 List-Id: On 2017-04-08 12:37, Jeffrey R. Carter wrote: > I decided to see what happens when you calculate square roots using > Newton's method and the unbounded rational numbers in > PragmARC.Rational_Numbers. Some interesting things happen. > > For example, trying to calculate sqrt(2) to a small enough accuracy > (0.000001 will do it) results in the calculation of the next estimate > > M := Two * X; > X := X - Y / M; > > taking a Long Time (it does conclude eventually). > > More alarming, though, is that for some values, even a fairly large > accuracy will quickly result in Storage_Error. For example, sqrt(1.28) > to an accuracy of 0.01 will do it. > > I realize that square roots are often irrational, but the accuracies > seem so large that I didn't anticipate consuming GB of memory. Just > naive, I guess. To use unbounded rational numbers should have the purpose of having exact computations <=> both absolutely accurate and absolutely precise. Otherwise, if accuracy is not absolute, you are allowed to choose from a set of rational numbers within the accuracy interval. Doing so you can take one with a less demanding representation, i.e. you are fiddling with the precision. And conversely for any algorithm involving irrational numbers you can always find an approximation requiring however much memory to waste. In short unbounded rational numbers is *always* bad idea unless proven otherwise. For transferring algorithms from real to unbounded rational numbers one could consider rounding the results within the accuracy constraint to some simpler (shorter) number. OK, this is what the floating-point arithmetic does already, right? (:-)) -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de