Extended precision library
|
05-25-2019, 12:43 AM
Post: #7
|
|||
|
|||
RE: Extended precision library
Hi, G.E.: (05-23-2019 08:34 AM)G.E. Wrote: [...]I published an extended precision package for the HP Prime [...] Would you mind give me your opinion on this ? I've done a cursory read of the "basic arithmetic" part, up to the Square Root code, but not having a Prime I can't really comment on the actual running performance. That said, at first sight the division code seems to me somewhat inefficient, there are better ways to implement multiprecision division, IMHO, (see point 9 below) and as many additional functions fully depend on it (Square Root, transcendental functions, etc.) it's essential for its code to be highly efficient and in particular as fast as possible, lest it'll be the weakest link on the chain, the bottleneck so to say. Many years ago (16 June 2002) I posted my "Short & Sweet Math Challenge #4" to the old MoHP forum, which dealt with some multiprecision tasks and to ease the burden on the challenge-takers I included there what I titled as "12 Guidelines for writing a multiprecision program/library/package for your HP calculator". Quoting from said challenge, with some expanded bits (keep in mind that this was written for the 10-digit HP-41C, scale it to use the extra digits the Prime allows instead): " There are many ways to do it, but you can follow these simple guidelines. They aren't optimal, but will get the job done easily:
x1 = x0 * (2 - B * x0) which means we can compute reciprocals without division, just using multiplication. For instance, if x0 = 0.3 is an approximation to the reciprocal of B = 3.7, then X1 = 0.3 * (2 - 3.7 * 0.3) = 0.267 x2 = 0.267 * (2 - 3.7 * 0.267) = 0.2702307 x3 = 0.2702307 * (2 - 3.7 * 0.2702307) = 0.27027026 are better approximations. The iterations converge quadratically, i.e: you get double the number of exact digits after each. As your initial approximation, you can use 1/B, which you can get to 10 or 12 digits by using the 1/X function of your HP calc ! Write a procedure to convert that value to the internal representation of multiprecision numbers, then compute 1/B using the iterative method above. As your initial 1/B is already accurate to 10 or 12 digits, just 2 or 3 iterations will give you 1/B accurate to in excess of 50 digits. Once you've got 1/B to 50-digit precision, then A/B reduces to A*(1/B), which you can compute with just one additional multiprecision multiplication. x1 = (x0 + A/x0) / 2 As your initial approximation, just use the value of SQRT(A) given by the square root built-in function. This will give you a value accurate to 10 digits, and then just 2 or 3 iterations of the procedure above will give you a square root accurate to in excess of 50 digits. Notice also that there's an alternative Newton procedure which will instead converge to the reciprocal of Sqrt(A) without using divisions, and once you've obtained 1/Sqrt(A) then you get Sqrt(A) proper by doing a single additional multiplication (by A itself, of course). Pi = 3.14159265358979323846264338327950288419716939937511 eX = 1 + X + X2/2! + X3/3! + X4/4! + ... + Xn/n! + ... where each term involves just one additional multiplication by X and division by a small integer constant, and you should stop when the next term to add would be smaller than 1E-50. Of course, n! is the factorial function = 1*2*3*4*...*n. There are a number of tricks you could try to accelerate convergence. For instance, you could use the identity: eX = (eX/2)2 i.e: you can first divide X by 2, then compute eX/2 and square the result. As the argument X is smaller, convergence of the Taylor Series will be faster. Similarly, you could divide X by 8, then square the result three times in a row, or make use of the fact that eX = eInt(X) * eFrac(X) where the first multiplicand is computed using repeated multiplications and the second one using the Taylor Series Expansion, which will converge very quickly because Abs(Frac(X)) is less than 1. Other transcendental functions (logs, trigonometrics, Gamma, Lambert W) can be implemented similarly. Perhaps some of this could be of help to you or some other people reading this thread. Also, all the multiprecision operations and results found in S&SMC#4 might be useful to you for testing your routines. Have a nice weekend. V. All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
Extended precision library - G.E. - 05-23-2019, 08:34 AM
RE: Extended precision library - G.E. - 05-23-2019, 09:02 PM
RE: Extended precision library - Dan - 05-24-2019, 04:52 AM
RE: Extended precision library - G.E. - 05-24-2019, 10:20 AM
RE: Extended precision library - rprosperi - 05-24-2019, 12:59 PM
RE: Extended precision library - StephenG1CMZ - 05-24-2019, 01:46 PM
RE: Extended precision library - Valentin Albillo - 05-25-2019 12:43 AM
RE: Extended precision library - G.E. - 05-25-2019, 10:30 AM
RE: Extended precision library - pier4r - 05-25-2019, 11:40 AM
RE: Extended precision library - Valentin Albillo - 05-25-2019, 06:36 PM
RE: Extended precision library - G.E. - 06-02-2019, 09:56 AM
RE: Extended precision library - pier4r - 06-02-2019, 05:35 PM
|
User(s) browsing this thread: 1 Guest(s)