Tetre2215.cc

From TORI
Jump to: navigation, search

// Generator of picture tetre2215.pdf
// used to make figure tetreal2215.pdf
// that is convetred to tetreal2215.jpg
// used in the article tetration
// Plot of tetrational \(f={\rm tet}_b(z)\)
// for \(-2<x<2\) and \(1<b<5\) the \(x\),\(b\) coordinates shown with lines \(f=\)const.
// The functions defined in conto.cin and ado.cin should be downloaded for the compoillation.
// The file tetreal2215.tex may be necessary to make beutiful figure with this picture.
// WARNING! This is preliminary version!
// The numerical implementation of the complex tet(complex,complex)
// is valid only while the imaginary parts of the arguments are small;
// and even in this case, the function returns only few correct decmal digits;
// this is sufficient to make the camera-ready real-real plot,
// but for the serious numerial analysis the number of terms in the expansion should be increased;
// and for large values of the imaginary part, the asymptotic representaton should be used instead. // At the re-use, please, indicate the source: this helps to trace errors, if any.
// Please let me know if any problem at the compillation or the execution.
// Copyleft 2011 by Dmitrii Kouznetsov.

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define DB double
#define DO(x,y) for(x=0;x<y;x++)
using namespace std;
#include <complex>
typedef complex<double> z_type;
#define Re(x) x.real()
#define Im(x) x.imag()
#define I z_type(0.,1.)
#include "conto.cin"
z_type old0(z_type d){ z_type q=sqrt(d); return -1.0018
+(0.15128484821526975*(1.+33.04715298851381*q-3.51771875598067*d)*q)/
(1.+3.2255053261256337*q) +   (-0.5 + log(2.))/d;}
z_type old1(z_type d){ z_type q=sqrt(d); return
1.1 - 2.608785958462561*(1. - 0.6663562294911147*sqrt(d))*
   sqrt(d) - (-0.625 + log(2.) )/d ;}
z_type old2(z_type d){ z_type q=sqrt(d); return
-0.96 + 3.0912038297987596*(1.+0.6021398048785328*d)*q/(1. + 4.240467556480155*d)  + 
  (-0.6666666666666666 + log(2.))/d;}
z_type old3(z_type d){ z_type q=sqrt(d); return 1.2 - 10.44604984418533*
(1.+0.2137568928431227*q+0.3693275254470449*d)*q/
(1.+4.95715636660691*q + 7.70233216637738*d)
- ( - 131./192. + log(2.))/d ;}
 z_type new0(z_type d){ z_type q=sqrt(d); return 
	q*(0.137467 + q*(4.94969 + q*0.0474179))/( 1. + q*(3.23171 + q*0.471222)) + 
	(-(1./2.)+log(2.))/d -1.;}
z_type new1(z_type d){ z_type q=sqrt(d); return 
q*(-0.424278 +q*(1.75166 +q*(-1.46524 + q*0.93347)))/
 ( 0.0312142+q*(-0.267478 + q)) + (-(5./8.) + log(2.))/d -1. ;} 
/* 
z_type new2(z_type d){ z_type q=sqrt(d); return 
-1 + (3.3925530969774065` Sqrt[d] + 16.10456932466758` d - 
 19.52156841142778` d^(3/2) + 10.745842280690756` d^2)/(
 1 + 4.127401286122306` Sqrt[d] + 5.2544878228486915` d)
+.. log(2.))/d -1. ;} 
NO HIGH PRECISION AT THE PRELIMINARY VERSION, PLEASE!!!*/ 
z_type new2(z_type d){ z_type q=sqrt(d); return 
q*(3.39255 + q*(16.1046 +q*(-19.5216 + q*10.7458)))/
( 1. + q*(4.1274 + q*5.25449)) + (-(2./3.) + log(2.))/d -1.;}
z_type new3(z_type d){ z_type q=sqrt(d); return  // This is not misprint, there is d, not q.
0.16*q*(1. + q*(27.7934 + q*(358.688 +q*(-259.233 + d*61.6566))))/
      (1. - 8.1192*q + 37.087*d) + (-131./192. + log(2))/d -1. ;}
// z_type git(z_type d, z_type x) { return
//     old0(d) + x*( old1(d) + x* ( old2(d) + x*old3(d)));}
z_type git(z_type d, z_type x) { 
 if(Re(d)>log(2.))
 return  new0(d)+x*(new1(d)+x*(new2(d)+x*new3(d))); 
 return  old0(d)+x*(old1(d)+x*(old2(d)+x*old3(d)));
 }
z_type fit1(z_type d, z_type x) { DB L=log(2.);
 		if(Re(d)<.001) { if(Re(x)>-1) return 1.;
  				 if(Re(x)<-1) return -990.; }
		return (x+1.)*(git(d,x)*x+1.)+ log(x+2.)/d - log(2.)/d*(1.+x);}
  z_type FIT1(z_type d,z_type z){ 
  	if(Re(d)<.03) { if(Re(z)<-1.) return (-30.); return 1.;}
    if(Re(z)<-.5)return log(FIT1(d,z+1.))/d;
    if(Re(z)>.5) return exp(d*FIT1(d,z-1.));
     return fit1(d,z);}
main(){ int j,k,m,n; DB x,y, p,q, t; z_type z,c,d;
int M=159,M1=M+1;
int N=121,N1=N+1;
DB X[M1],Y[N1], g[M1*N1], w[M1*N1]; // w is working array.
char v[M1*N1]; // v is working array
FILE *o;o=fopen("tetre2215.eps","w");ado(o,408,408);
fprintf(o,"202 2 translate\n 100 100 scale\n");
DO(m,M1) X[m]=-2. +.02501*(m+.8);
DO(n,N1) Y[n]=    +.033*(n);
for(m=-20;m<21;m+=10){	M(.1*m, 0)L(.1*m,4)}
for(n=0;n<41;n+=10){ 	M(-2,.1*n)L(2.,.1*n)}
M(-2,M_E-1.)L(2,M_E-1.)
//M(-2,.5)L(2,.5)
M(-2,exp(1./M_E)-1.)L(2,exp(1./M_E)-1.)
//M(-2,sqrt(2.)-1.)L(2,sqrt(2.)-1.)
fprintf(o,".006 W 0 0 0 RGB S\n");
DO(m,M1)DO(n,N1){g[m*N1+n]=9999;}
DO(m,M1){x=X[m]; //printf("run at x=%6.3f\n",x);
DO(n,N1){y=Y[n]; z=z_type(x,y);
	p=Re(FIT1(log(1.+y),x));
 //	p=Re(fit1(log(1.+y),x)); // For the debugging only!
	if(p>-85 && p<85)  g[m*N1+n]=p;
	}}
 fprintf(o,"1 setlinejoin 1 setlinecap\n");
 p=8.;q=2.;
 for(m=0;m<3;m++) for(n=2;n<10;n+=2)conto(o,g,w,v,X,Y,M,N,-(m+.1*n),-q,q);
 						fprintf(o,".01 W .9 0 0 RGB S\n");
 for(m=0;m<3;m++) for(n=2;n<10;n+=2)conto(o,g,w,v,X,Y,M,N, (m+.1*n),-q,q);
 						fprintf(o,".01 W 0 0 .9 RGB S\n");
 for(m=-5;m<5;m++)conto(o,g,w,v,X,Y,M,N,(0.+m),-p,p);fprintf(o,".02 W 0 0 0 RGB S\n");
     m=-10; conto(o,g,w,v,X,Y,M,N,(0.+m),-p,p);fprintf(o,".02 W 0 0 0 RGB S\n");
//  m=-20; conto(o,g,w,v,X,Y,M,N,(0.+m),-p,p);fprintf(o,".02 W 0 0 0 RGB S\n");
    m=10; conto(o,g,w,v,X,Y,M,N,(0.+m),-p,p);fprintf(o,".02 W 0 0 0 RGB S\n");
//    m=20; conto(o,g,w,v,X,Y,M,N,(0.+m),-p,p);fprintf(o,".02 W 0 0 0 RGB S\n");
//    m=100; conto(o,g,w,v,X,Y,M,N,(0.+m),-p,p);fprintf(o,".02 W 0 0 0 RGB S\n");
// (Too many lines are difficylt to describe)
fprintf(o,"showpage\n%cTrailer",'%'); fclose(o);
 	system("epstopdf tetre2215.eps");
 	system(    "open tetre2215.pdf"); //these 2 commands may be specific for macintosh
//getchar(); system("killall Preview");// if run at another operational sysetm, may need to modify
}

/* (End of generator)*/