![]() |
fast accurate Kneser sexp algorithm - Printable Version +- Tetration Forum (https://math.eretrandre.org/tetrationforum) +-- Forum: Tetration and Related Topics (https://math.eretrandre.org/tetrationforum/forumdisplay.php?fid=1) +--- Forum: Computation (https://math.eretrandre.org/tetrationforum/forumdisplay.php?fid=8) +--- Thread: fast accurate Kneser sexp algorithm (/showthread.php?tid=486) |
fast accurate Kneser sexp algorithm - sheldonison - 08/07/2010 Here is the most recent code, Nov 12th, 2013: updates Nov 12th 2013 o updated to be compatible with latest pari-gp o removed eval, and kill o enhanced prtpoly routine o added lambertL routine end updates Nov 12th, 2013 This is the first of several posts. update: changed the names of the routines to match current code. I found a fast accurate way to implement the Knesser sexp, and implemented it in Pari-GP, which is a free mathematics program available on the web. The algorithm generates the Knesser sexp accurate to 15 decimal digits in about a minute. This includes a 400 term Riemann mapping approximation, and a 50 term Cauchy unit circle approximation to generate the Taylor series. I've tried the algorithm for base 2, base e, and base 10, and they are all well behaved. I will post the pari-GP code, as well as the Cauchy series it generated. The algorithm is for bases > eta. The algorithm is to start with the linear approximation for the sexp, that has a smooth first derivative. For base e, this is the approximation that the sexp(z) from [-1 to 0]=z+1. This region is extended with the exponent/logarithm to extend the initial unit length estimate. This is the initial trivial Taylor series. In my program, this Taylor series approximation for the sexp is called sexp. Then iterate as follows: 1) generate the Riemann mapping of the unit length segment This involves the Laurent series of the inverse superfunction of the unit length segment, mapped to the unit circle. The complex valued superfunction and its inverse are developed from the complex fixed point. Specifically, over a unit length, generate inverse_superfunction(sexp(z))-z, which is then mapped to the unit circle. Use the Cauchy Integral formula to generate the Taylor series. Strictly speaking, this function has a Laurent series, not a Taylor series, but we ignore the x^-n terms in the Laurent series, and only keep the x^+n terms, where n>=0. This is then trivially mapped back into a complex valued 1-cyclic fourier series, theta(z). 2) riemaprx(z). This 1-cyclic fourier series is used to generate a sexp approximation defined only in the imag(z)>0 portion of the plane. riemaprx(z)=superfunction(z+theta(z)). riemaprx(z) is poorly behaved at the real axis, with high frequency oscillations due to the slowly converging theta function. But the high frequency terms decay very rapidly as imag(z) increases in the complex plane, and if imag(z)>=1*I, the function behaves close to the complex superfunction. 3) sexp(z). Using riemaprx(z), generate the upper half of a unit half circle, conventionally centered on z=0, in the upper half of the complex plane. Treat the lower half of the unit circle as the complex conjugate of the upper half of the unit circle. Use the Cauchy integral to generate a Taylor series. This is a real valued Taylor series. The Taylor series is renormalized and recentered, so that sexp(0)=1, and so that sexp(+0.5)=exponent(sexp(-0.5). Iterate steps 1) 2) and 3). The claim is that this infinite iteration converges to Knessder's sexp(z), which is real valued at the real axis, with sexp(0)=1, and sexp(z+1)=exp(sexp(z)). Seven iterations were required to get 15 digits of accuracy, which each iteration adding approximately 8 binary bits of accuracy. In the Pari-GP program, each iteration takes less than 10 seconds. Implementing this algorithm is highly problematic and requires very large numbers of terms in the 1-cyclic theta function, due to the very slow convergence of the Riemann mapping. I found a trick to dramatically improve the convergence of the Riemann mapping, to handle the singularity, and to allow fast convergence. Here a few more details, before I call it a night. In my implementation, I wanted a 50 term Taylor series for the sexp approximation. This requires 200 points around a unit circle. Since we only generate the upper half of the unit circle, that's 100 points. These points are evenly spaced, with all points having imag(z)>0. The first point has z=e^(I*pi/200), which has imag(z)=0.015. This means that in riemprx(z), the imag(z) will always be >=0.015. That in turns means that the high frequency oscillations decay. For Riemann mapping theta terms>~300 is not computationally significant for any of these 100 points on the unit circle. This is the first of several posts. The next post will deal with the ideas required to improve the Riemann mapping convergence problems due to the singularity. I need to get some sleep, and it may take a few days to post all of my results. I want to clean up the code a little bit, since there's a lot of junk in the code that I needed to debug it and get it all working that I want to remove before posting, to avoid unnecessary confusion. Teaser: This is the output of my program, to generate the Taylor series terms I generated for base e, base 2, and base 10. - Sheldon base 2.71828182845904523536028747135266249775724709369 Cauchy Taylor series approximation terms 0 0.999999999999999920606916968922030701567136645654 1 1.09176735125832094016082238370083804714 2 0.271483212901694628277009772276018058438 3 0.212453248176256341682340133816642561735 4 0.069540376139987455601815633290052837540 5 0.0442919520904733787858836715649205635588 6 0.0147367420963894641781675687873762988951 7 0.0086687818172253171998963830218805136384 8 0.00279647939838551204530926929318637318059 9 0.00161063129058431027448748226836099353371 10 0.00048992723148441335050668409792945192050 11 0.000288181071154071176125207353574308091920 12 0.000080094612538568642532817921403719623613 13 0.0000502911417938227014378026179786713377326 14 0.0000121837903449185625957879474875634578856 15 0.0000086655336673937799848419995967770476324 16 0.00000168778231933152083906008897805134285921 17 0.00000149325324858236409519824063327981138611 18 0.000000198760764215837789507617671297185393027 19 0.000000260867356010921328462837051102110834560 20 0.0000000147099541512649833075949006297264385980 21 0.0000000468344973323925542131416564470746086702 22 -0.00000000154924165843564586518006754343312538792 23 0.0000000087415107851444402981222259166563437222 24 -0.00000000112578730421439340057613203197171894664 25 0.00000000170795927016981912380839845219103887952 26 -0.000000000377858310553104789819392071420497066106 27 0.000000000349577878719151948745500164259927239404 28 -1.05377008157789121410377229095750742668 E-10 29 7.4590973139432053510241775086048122696 E-11 30 -2.71759784858227219934013489755749519135 E-11 31 1.64607673327765883270714032926236921945 E-11 32 -6.7418700690910586159590314585805404498 E-12 33 3.7253295931126574070795526274392527304 E-12 34 -1.63908465536567938669004255576025126318 E-12 35 8.5836440640244217926800645809445203856 E-13 36 -3.94371548069373997097518693401613112984 E-13 37 2.00252641630788814440567087736426238381 E-13 38 -9.4417589560533107254019594050715409934 E-14 39 4.71206677912917615338890731001808112440 E-14 40 -2.25611366289088681618159333858518060425 E-14 41 1.11546306823408543027263377496376191447 E-14 42 -5.3891796465832969287083377311762631343 E-15 43 2.65194707551149745587030410085037067028 E-15 44 -1.28753286810996291447909130936705727867 E-15 45 6.3232296660338767222943776801526973230 E-16 46 -3.07332373088892725649620921357557234127 E-16 47 1.50855996920297588144091655941600050227 E-16 48 -7.2896911298653544932621055870671863118 E-17 49 3.57053526604856938153249432482269325976 E-17 base 2 Cauchy Taylor series approximation terms 0 1.00000000000000007750805374695916476506324315386 1 0.88936495462097636471560015559202608188 2 0.0086765489653699778435866428210914580477 3 0.095238800075181821015052159076811795525 4 -0.0057523485401261058429044155126967586843 5 0.0129665820200371929900639963746185426267 6 -0.00219604962303099108685649788446966214674 7 0.00199674684791144956471972891306784395245 8 -0.00056335481487852293422791227955443116661 9 0.000348242328188164833713322066658348490588 10 -0.000128532441264722069102630177525101178612 11 0.000067081924420528746629841393628806788277 12 -0.0000282987528228002605436935419049427621654 13 0.0000138001319906297777277157382455652644180 14 -0.0000062019093983767935657716936885382308667 15 0.00000295556146480613946456248019931704026334 16 -0.00000136867922453685047021475603425081919190 17 0.00000064905707564831820958280933643834369294 18 -0.000000305166939330940495799879426965798767859 19 0.000000144948206147741006787309611484943294178 20 -0.000000068746643115668186072914364608901276865 21 0.0000000327674451745520233209052672738147657033 22 -0.0000000156310874697440742179774639803902393806 23 0.0000000074781283860060906963656804741326980492 24 -0.00000000358267681486784107606081902426567798118 25 0.00000000171986774278787862816161264617020453732 26 -0.00000000082681596398826102575453499011874838983 27 0.000000000398110465534940913092926440510368851600 28 -1.91942994009799320930467536291965520002 E-10 29 9.2663184086753526923394526399596161631 E-11 30 -4.47869896241156433452311745776051738114 E-11 31 2.16712006481128547956338987778919331607 E-11 32 -1.04969755427424430603006383413954325851 E-11 33 5.0894457415080947575828909582705030799 E-12 34 -2.46987949612974961256130795951078775734 E-12 35 1.19965332790083051126762500373890740311 E-12 36 -5.8316699693946087927290168849662635343 E-13 37 2.83700134396762172106948455139976794164 E-13 38 -1.38119296763538037439839695675052294198 E-13 39 6.7286246573391428225154736432311797155 E-14 40 -3.28040714229361317312282338553709457619 E-14 41 1.59994527980264052587204787980778074081 E-14 42 -7.8111883641343962658543820790964098310 E-15 43 3.8123345996113862398910808416038811110 E-15 44 -1.86468916410329958272266244696629139897 E-15 45 9.0928731462620461748731226835758948880 E-16 46 -4.4652219382963819619261489249575291192 E-16 47 2.16258309701983021090373383869474626354 E-16 48 -1.07562115928439172115561558722739104721 E-16 49 5.05103639405910509662889857211651054178 E-17 base 10 Cauchy Taylor series approximation terms 0 1.00000000003413666821707397610280580973 1 1.6842890280105318114702665361 2 1.4130640093559017784867641066 3 1.3295945895120850984491868131 4 1.1104423522130456306141162585 5 0.90791475960484107525431757972 6 0.70590812180827017012794979492 7 0.53596957102484588479532491192 8 0.39514882149633253685483274509 9 0.28568024972253825344818666302 10 0.20237131278470927324534438107 11 0.14110168269002467755684498200 12 0.096870196895171185635561049276 13 0.065642683799764598157183797364 14 0.043932559903871435514499480872 15 0.029083045516276459146860315440 16 0.019054947684195538710084470697 17 0.0123686846345218426147071658882 18 0.0079582306458762837173385697464 19 0.0050792074578440317507369752633 20 0.0032170388379653970425789785613 21 0.0020231559289094629314623265337 22 0.0012638006922446651516872615141 23 0.00078448455296479211241357653392 24 0.00048404347686816718054617660014 25 0.00029697714889618699433841203816 26 0.00018122446592630282867291500326 27 0.000110023183879937876785387661614 28 0.000066469809662926642710985803857 29 0.000039970210188298586919385209485 30 0.000023927948827218540851314911165 31 0.0000142631537294666506633793631158 32 0.0000084672146369634588559435171282 33 0.0000050067182976642942211046734889 34 0.0000029492933862829666416493809347 35 0.0000017310105129704227353019917697 36 0.0000010124091578563321764991987405 37 0.00000059013055820603257123183162307 38 0.00000034287053679750024168609816182 39 0.00000019859459586612750224033089360 40 0.000000114688324996137110089024467356 41 0.000000066049601906226671780697958378 42 0.000000037941008758273721620067345461 43 0.000000021745359672035340985615756584 44 0.0000000124403916641799613324962201452 45 0.0000000071074328972264520946865200883 46 0.0000000040598591783922772751609136103 47 0.0000000023194687970727546265839419100 48 0.0000000013297332794947389880115713152 49 0.00000000076366914316723959202509556617 The pari-GP code - sheldonison - 08/07/2010 Next, I'd like to post the pari-GP code I have right now. Then I'll translate each of the subroutines in the code back into mathematics language, talk about convergence, and how I handled the singularity in the Riemann mapping, without requiring an infinite number of terms in the very slowly converging Riemann mapping. Lots of posts to come. Download this code, at the end of this post, and save it to a file. There is also an attachment at the end of this post with the "kneser.gp" file. Save it in the pari-GP directory, and start pari-GP. Type "\r kneser.gp". The first thing that comes up is a help menu, with the various routines I wrote, and a short one line description of what they do. The program starts initialized for base=e. By the way, here is the link for pari-GP download. Here's what comes up in the pari-GP window: Code: loop(n) n iteration loops, each loop adds ~8 bits precision Follow the suggestion and type "loop(6)", to loop through the estimation iteration routine six times. This will take about a minute. The program has now calculated a 50 term Taylor series for the sexp approximation for base=e accurate to 15 significant digits. To access that routine, type "sexp(0)"=1.00000000000000. "sexp(1)"=2.71828182845905. "sexp(-0.5)"=0.498563287941115. This is the half iterate for base=e. The code handles complex arguments just fine. "sexp(-2.5)"=-0.362370072029386 + 3.14159265358979*I. "sexp(0.5*I)"=0.936255672826876 + 0.520646429188355*I. The sexp(z) routine is accurate for -I<imag(z)<I. There's a second routine, that converges in the upper half of the complex plane, for imag(I)>0.015. For example, type riemaprx(0+4*I)=0.331375339574123 + 1.34164499758753*I. Type "help" at any time to reprint the help menu. Try typing "init(2)". This initializes the program for base=2. Once again "loop(6)" to generate another taylor series. sexp(-0.5)=0.543035666027967. This is the half-iterate for base 2. Cool! To go back to base=e, type "init(exp(1));loop(6)" Two other really useful routines are "superf(z)", and "isuperf(z)". These implement the complex valued superfunction and the complex valued inverse super-function for the current base. "superf(0)"= 1.14934109947623 + 1.12294996859363*I. "isuperf(0.5)" = -0.989970104598650 - 0.856059475588971*I. And here is the code itself (also, see downloadable attachment after the code). For the most recent code version: go to the Nov 21st, 2011 thread. - Sheldon Code: \p 38; /* default precision 38 decimal digits */ RE: fast accurate Knesser sexp algorithm - bo198214 - 08/08/2010 (08/07/2010, 06:53 AM)sheldonison Wrote: I found a fast accurate way to implement the Knesser sexp, and implemented it in Pari-GP Wow this sounds to be a great thing! But before continuing, please explain what you mean by "unit length segment"? In Quote:1) generate the Riemann mapping of the unit length segment Also , his name is "Kneser", not "Knesser"! (08/07/2010, 09:17 PM)sheldonison Wrote: Henryk, can I save the file, "knesser.gp" itself, to the eretrandre website? I added the .gp extension to the allowed uploads. Just make an attachment. RE: fast accurate Knesser sexp algorithm - sheldonison - 08/08/2010 (08/08/2010, 03:54 PM)bo198214 Wrote: Wow this sounds to be a great thing!Thanks Henryk. I think this could be an important development that I have stumbled upon. I finally had to expand to something more powerful than an excel spreadsheet (and perl programs) though! Its really neat that pari-GP is available on the web as shareware. Hopefully, my thid post in the Mathematical discussion forum helps a little in explaining the theta(z) funciton and the Riemann mapping. The fourier series for theta(z) can be developed from any arbitrary unit length on the real axis of sexp(z), where z>-2. - Sheldon Quote:Also , his name is "Kneser", not "Knesser"!ps. I fixed the pari-GP code to spell Kneser's name correctly! RE: fast accurate Kneser sexp algorithm - nuninho1980 - 08/15/2010 I like your code that it is better and faster on world! wow! ![]() my cpu c2d e6600 benchmarked during 24seconds -> init(exp(1)); loop(6). ![]() what's your cpu? same or c2q q6600? if eta > base (> 1 or > 0 or > -oo ?) then you add tetration regular for code, ok? ![]() updated kneser.gp code - sheldonison - 08/19/2010 I updated the code today, in the second post,. You can download the attachment there. Major changes:
For the highest precision results, I would like to modify the code to generate more Taylor series terms, to increase the radius of accurate convergence, to a unit circle, instead of within a circle of radius=0.5. Right now, for example the 110 term Taylor series described above is only accurate to 64 decimal digits when abs(z)<=0.5, but only accurate to 35 decimal digits out to a radius of abs(z)<=1. That's because there's only 110 terms, and the 110th term is ~10E-35. That has to do with the limitations and time optimizations of how the Taylor series is generated from the superf(z+theta(z)), which makes it expensive to add Taylor series terms. Later, I will probably post results showing how the Taylor and Fourier series terms converge, and how many terms it takes to get appropriate precision in the theta(z) fourier series so as to generate sufficiently accurate samples for the sexp(z) series. This will justify the "complex conjugate" trick to generate the Taylor series for sexp(z) from superf(z+theta(z)), which is one very small step along the way to showing convergence. Later, I could also add some of nuninho's requests..... - Sheldon (08/15/2010, 12:09 AM)nuninho1980 Wrote: ..... Strangely, the "superf"/"isuperf" subroutines sort of work for bases<eta, For example, if you type init(sqrt(2)); superf(0) You'll get 5.76705325376430. This is the superfunction developed from the upper repelling fixed point, which is "4". For bases<eta, the sexp(z) function doesn't work, nor does the loop(n) function. It would require special unique code to get the function to work for the lower fixed point (=2), since "2" is an attracting fixed point, and the rest of the code is for repelling fixed points. Maybe someday? Also, eta doesn't work at all, and the loop(n) routine overflows for bases<1.7. I haven't debugged to understand why it ges an "exponent (expo) overflow." RE: updated kneser.gp code - nuninho1980 - 08/19/2010 (08/19/2010, 02:35 AM)sheldonison Wrote: Strangely, the "superf"/"isuperf" subroutines sort of work for bases<eta, For example, if you typeya! I have same error when I tried base=1.7. ![]() your code already was updated today. wow. ![]() RE: updated kneser.gp code - sheldonison - 08/20/2010 (08/19/2010, 02:35 AM)sheldonison Wrote: Later, I will probably post results showing how the Taylor and Fourier series terms converge, and how many terms it takes to get appropriate precision in the theta(z) fourier series so as to generate sufficiently accurate samples for the sexp(z) series......Here's an example, settings which I like as the next step up from the term term double precision results, which take less than a minute. Type "init(exp(1));loop(14);" and this next example runs for 7-8 minutes on my laptop, and reports that resulting sexp(z) Taylor series is accurate to 108 binary bits, or just a bit over 32 decimal digits. That precision would be within a radius of abs(z)<=0.5. \p 67; ctrm = 75; cvec = 150; rtrm = 1000; rvec = 2000; sfuncprec = 1E-32; Here, gp's precision is set to 67 digits. The goal is 32 decimal digits of precision. The sfuncprec (superfunction precision) is set to 1E-32 digits, to give superf/isuperf results accurate to 32 digits. That is, the isuperf/superf iteration count was set to 235 iterations. If you take the 67-32 leaves 35 digits of precision for gp to work with, or 3 spare bits for rounding errors, which surprisingly seems sufficient! We're asking for a Taylor series with 75 terms. By the Nyquist sampling criteria, we need at least 150 sample points. So cvec (the number of sample terms used to generate the sexp(z) Taylor series) =150. There will be a small sampling error term, due to higher frequencies in the superfunction being sampled. But, for base e sexp(z), the higher frequency terms roll off pretty fast, with each term being roughly half the magnitude of the term before. We want results accurate to 32 decimal digits, so we need 150 sample points, accurate to 32 decimal digits. The sample points will be in the upper half of the complex plane, centered around z=0. The points closest to the real axis are rtrm = 1000 is driven by the requirement that the Riemann approximation, which is We also need to show that our 75 term sexp(z) Taylor series supports 32 decimal digits of precision at a radius with abs(z)<=0.5. This is for the unit length we use to generate the RiemannCircle/Theta function from. The unit length will be from -0.5+idelta to +0.5+idelta. We want all terms over the unit length accurate to 32 decimal digits. The 75th term is -7.15 E-25. 7.15E-25*(0.5^75)=1.9E-47, which is much much less then 1E-32. The sexp(z) Taylor series has 32 decimal digits of precision out to a radius of about 0.78, which is greater then 1/2. So, all of the parameters are sufficient to get around 32 bits of precision. Observationally, when iterating the "loop(14)", we get about 108 binary bits equal in the sexp(z) algorithm versus the riemaprx(z) algorithm. This is about 33 decimal digits. Graphing the error gainst a golden copy with higher precision shows similar results. - Sheldon RE: fast accurate Kneser sexp algorithm - sheldonison - 10/14/2010 Below, see the attached file, with a new version of the kneser.gp "pari-gp" code, with minor enhancements to speedup the algorithm. The default "kneser.gp" precision is now "\p 67", which supports results accurate to 32 decimal digits, or 105 binary bits. This takes about 14 or so iterations, and takes about a minute to run. This code version updates the size of the arrays as you go, so it is a lot more efficient. The size of the sexp(z) Taylor series and the Riemann mapping series is now updated to match the algorithm's increases in precision, of about 7-8 bits per iteration. Also, the number of exp/log iterations used in the super/isuper super function routine is now also increased each iteration through the loop. The program initializes the same as before. As an example, to calculate the series for other bases, like base 10, type the following, which will execute in just under a minute. For larger bases, like base10, it actually takes more like "loop(17)" iterations to get the full 32 decimal digits of precision supported by "\p 67". The last iteration always takes extra long, since I chose to also increases the size of both series, so as to allow for more terms in the sexp(z) Taylor series result than are required simply for the next loop iteration, but this allows for a larger radius of convergence in the sexp(z) Taylor series, and is controlled by the variable "lastradius". Code: \r kneser.gp; Much higher precision results are also made possible by this update. Type the following on the command line. In about 30 minutes or so, after 28 iterations, the result is a Taylor series for the base "e" sexp(z), accurate to 64 decimal digits or so. The Taylor series dumped to the file are printed to 64 decimal digits by default, you'll need to update the code in dumparray to get the Taylor series results with more than 64 decimal digits. I know of several further enhancements that are possible, and I've experimented with implementing some of them. I think my focus is going to shift more towards explaining convergence, and other ideas I've had. - Sheldon Code: \r kneser.gp; RE: fast accurate Kneser sexp algorithm - nuninho1980 - 10/15/2010 lastest your code for faster. ![]() I tried bases 1.5, 1.68, 1.7 and 100 and worked (not work on your older code). it's better. ![]() errors here: base 1.6 PHP Code: (15:51) gp > init(1.6);loop(1) base 200 PHP Code: (15:46) gp > init(200) I tried base 1.67 but I get 3 bits precision (last loop (from 2 until 5) is less bits precision than previous loop) may you fix this code. ![]() |