Tet2Li3.cin

From TORI
Jump to navigation Jump to search

// Tet2Li3.cin is the C++ implementation of approximation of tetration to base 2 for moderate values of real part of argument and positive moderated values of the imaginary part of the argument.

The following header is recommended for a program that uses this routine:

#include <stdio.h>
#include <stdlib.h>
#define DB double
#define DO(x,y) for(x=0;x<y;x++)
#include <complex>
#define z_type std::complex<double>
#define Re(x) x.real()
#define Im(x) x.imag()
#define I z_type(0.,1.)

// The text of the routine is copypasted below.

Code of the routine

z_type Tet2Li3(z_type z){ int n; z_type s,c; 
z_type L4c[101]=
{z_type(-0.96442197143292163, 0.05583913456798329)
,z_type(-0.44386570464167646, 1.51106601107493432)
,z_type(-0.52039308389402539, 0.15450254330734406)
,z_type(-0.62355791508386527, 0.17862280636827535)
,z_type(-0.71926217937183412,-0.57516849053290331)
,z_type( 0.05749830306418217,-0.82994217925992275)
,z_type( 0.43105359157262174,-0.49348248684090301)
,z_type( 0.64982487652611143,-0.20197590071626564)
,z_type( 0.63428645257823568, 0.32777473947912916)
,z_type( 0.19066098117240221, 0.59716413625540921)
,z_type(-0.16929224200198975, 0.51191304596747855)
,z_type(-0.43277756099569964, 0.31015093384750825)
,z_type(-0.50803880616233599,-0.06382362922870075)
,z_type(-0.29243448199504934,-0.33099175914462525)
,z_type(-0.04064936446829150,-0.38690390935293639)
,z_type( 0.19555514821283981,-0.31920326250291897)
,z_type( 0.32894214135024552,-0.09828120884621465)
,z_type( 0.26944910286553658, 0.11177913048912366)
,z_type( 0.13954393438926971, 0.21971021918723688)
,z_type(-0.02581292789333949, 0.24438102847859960)
,z_type(-0.15936450902190646, 0.14745186185612344)
,z_type(-0.18185161411949777, 0.01742769092611251)
,z_type(-0.14377642294507287,-0.08134062483323933)
,z_type(-0.05501982590348137,-0.14271190932093702)
,z_type( 0.04315099336263601,-0.12322960204752699)
,z_type( 0.08972837022303276,-0.06328369280246879)
,z_type( 0.10076073895258324, 0.00047998410103517)
,z_type( 0.06898847578276167, 0.05927724361718365)
,z_type( 0.01332972341490650, 0.07398840735627932)
,z_type(-0.02570068625604698, 0.05869216497883219)
,z_type(-0.05172097161127105, 0.02941268881794933)
,z_type(-0.05080229143069231,-0.01037506714434418)
,z_type(-0.02757901334921590,-0.03133987854930548)
,z_type(-0.00546322938165580,-0.03627631473049315)
,z_type( 0.01715705125867679,-0.02946263734365678)
,z_type( 0.02688849312920095,-0.00897449272218340)
,z_type( 0.02173617811106088, 0.00612384503350845)
,z_type( 0.01369861764416750, 0.01561347372318526)
,z_type(-0.00003287868453682, 0.01891860379000663)
,z_type(-0.00962025062651870, 0.01131331623919105)
,z_type(-0.01142748605738148, 0.00393921956696400)
,z_type(-0.01118815977860720,-0.00326985485593909)
,z_type(-0.00502464629123980,-0.00876059458746675)
,z_type( 0.00094985791374801,-0.00740625009361331)
,z_type( 0.00373694125378012,-0.00536076276373415)
,z_type( 0.00622462027483341,-0.00168500536017759)
,z_type( 0.00442989747969840, 0.00258176966491394)
,z_type( 0.00176631559869888, 0.00319518970415377)
,z_type( 0.00007310635245690, 0.00362370309322360)
,z_type(-0.00245512873560677, 0.00245365498295746)
,z_type(-0.00243221602224390, 0.00002011548331446)
,z_type(-0.00169901290818137,-0.00063485732558974)
,z_type(-0.00118336233167492,-0.00167997624232268)
,z_type( 0.00052458682611526,-0.00170092415011180)
,z_type( 0.00086976653179552,-0.00059357465758510)
,z_type( 0.00091036532311980,-0.00038024421570873)
,z_type( 0.00105850512096046, 0.00048113979927880)
,z_type( 0.00012602042659601, 0.00083174033478296)
,z_type(-0.00008622246594299, 0.00040931639700827)
,z_type(-0.00027812449828624, 0.00053242098053083)
,z_type(-0.00063587568461917, 0.00001609634833726)
,z_type(-0.00018253901941825,-0.00029001257366755)
,z_type(-0.00015506695295160,-0.00012828934236503)
,z_type(-0.00002996351748379,-0.00038054789615742)
,z_type( 0.00030231236254942,-0.00012182090022998)
,z_type( 0.00007763375454987, 0.00005743328041207)
,z_type( 0.00015169602237680,-0.00003887561095912)
,z_type( 0.00011353137812138, 0.00020757465003278)
,z_type(-0.00012474003847589, 0.00008616891475390)
,z_type( 0.00001041542798485, 0.00000316351490342)
,z_type(-0.00008801761239733, 0.00009255810050519)
,z_type(-0.00009916071506107,-0.00009795531452574)
,z_type( 0.00005462958189017,-0.00003408399422652)
,z_type(-0.00004733337061949,-0.00000055466895962)
,z_type( 0.00003724277408065,-0.00008661168938259)
,z_type( 0.00006358679057164, 0.00004652159392422)
,z_type(-0.00003443377146479, 0.00000305632800170)
,z_type( 0.00004987251922054,-0.00001172281172453)
,z_type(-0.00001163567858825, 0.00006326592250238)
,z_type(-0.00003603332203559,-0.00002736506629286)
,z_type( 0.00002968990404160, 0.00000786644656885)
,z_type(-0.00003926188226218, 0.00001762032044778)
,z_type( 0.00000282992874630,-0.00004221696016455)
,z_type( 0.00002071301987636, 0.00002080964719940)
,z_type(-0.00002648997970265,-0.00000862292494458)
,z_type( 0.00002768773458769,-0.00001699850316945)
,z_type(-0.00000118908087485, 0.00002800804015221)
,z_type(-0.00001316792012014,-0.00001748225342134)
,z_type( 0.00002229027261526, 0.00000638281027493)
,z_type(-0.00001925760751739, 0.00001402286912933)
,z_type( 0.00000177825673539,-0.00001855855520970)
,z_type( 0.00000924387242742, 0.00001435275174947)
,z_type(-0.00001671687638994,-0.00000479140314426)
,z_type( 0.00001233435793512,-0.00001105497404848)
,z_type(-0.00000151922074091, 0.00001363774455698)
,z_type(-0.00000624952168421,-0.00001038808853014)
,z_type( 0.00001390188179944, 0.00000223388551343)
,z_type(-0.00001256467584753, 0.00000584236963269)
,z_type(-0.00000029067672508,-0.00001118872850170)
,z_type( 0.00000228471905911, 0.00000491389003744)
,z_type(-0.00001047526247999, 0.00000020892389615)
};
c=z-3.*I; c/=4.; s=L4c[90]*c; for(n=89;n>0;n--){ s+=L4c[n]; s*=c;}
return log(z+2.)/log(2.)+L4c[0]+s;}

Generator

This section is for those, who like to ask: "How did you get it?"

The routine above is generated with the code below. The rough implementation z_type F4(z_type z) of tetration to base 2 should be loaded, ../tet2f4c.cin; it includes two files more, GLxw2048.inc and tet2f2048.inc; they also should be loaded.

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define DB double
#define DO(x,y) for(x=0;x<y;x++)
#include <complex>
#define z_type std::complex<double>
#define Re(x) x.real()
#define Im(x) x.imag()
#define I z_type(0.,1.)
#include "../tet2f4c.cin"
//#include "conto.cin"

int main(){ int j,k,m,n; DB x,y, f,p,q,r, t; z_type z,c,d,s;
//z_type Zo=z_type(.31813150520476413, 1.3372357014306895);
int M=300;
r=3.2;
FILE*o = fopen("Tet2Li3.cin","w");
fprintf(o,"z_type Tet2Li3(z_type z){ int n; z_type s,c; \n");
fprintf(o,"z_type L4c[101]=\n{");
for(k=0;k<101;k++)
{ s=0;
  for(m=0;m<M;m++)
  { f=2*M_PI/M*(m-M/2+.25);
    z=r*z_type(cos(f),sin(f))+3.*I;
    c=z_type(cos(-k*f),sin(-k*f));
    s+=(F4(z)-log(z+2.)/log(2.))*c;
  }
  s/=pow(r/4.,k)*M;
  printf("%3d %20.17lf %20.17lf\n",k,Re(s),Im(s));
  if(k>0) fprintf(o,",");
  fprintf(o, "z_type(%20.17lf,%20.17lf)\n",Re(s),Im(s));
}
fprintf(o,"};\n");
fprintf(o,"c=z-3.*I; c/=4.; s=L4c[90]*c; for(n=89;n>0;n--){ s+=L4c[n]; s*=c;}\n");
fprintf(o,"return log(z+2.)/log(2.)+L4c[0]+s;}\n");
fclose(o);
}

References