PowerSeriesCombinB.cin
PowerSeriesCombinB.cin is the C++ routine that combines two asymptotic series, analogy of routine PowerSeriesCombine.cin
Specification: void PowerSeriesCombinB( double *a, double *b, double *c, int N)
a,b,c are arrays of length N+1. The 0th elements of these arrays in not used in this computation.
Array a should be declared to store N+1 elements.
Array b should store at least N coefficients of power series \( B(z)= \sum_{n=1}^N b_n z^n + o(z^N) \)
Array c should store at least N coefficients of power series \( C(z)= \sum_{n=1}^N c_n z^n + o(z^N) \)
Then, after to call PowerSeriesCombinB(a,b,c,N);
array a is supposed to provide N coefficients a[1] .. a[N] of the power series \(\ A(z) = B(C(z)) = \sum_{n=1}^N a_n z^n + o(z^N) \).
Warning 1: The calculus is performed through routine Arbogast from Arbogast.cin.
At the moment of loading, the implementation assumes that b[1]=c[1]=1.
If the last condition is not satisfied, use routine PowerSeriesCombine.cin from PowerSeriesCombine.cin instead of PowerSeriesCombinB.cin.
Warning 2: in the previous version PowerSeriesCombinA.cin, the order of inputs happened to be not the same, b <-> c; the corrected version is denoted with PowerSeriesCombinB, although i used the same routine Arbogast.
PowerSeriesCombinB.cin
//Routine Arbogast from «Arbogast.cin» should be also loaded.
////The main module should #include "Arbogast.cin" before to #include "PowerSeriesCombinA.cin"
void PowerSeriesCombinB(double *a,
double *b,
double *c,
int N)
{
a[0] = c[0];
a[1] = c[1] * b[1];
for(int n=2; n<=N; n++)
{
a[n] = c[1]*b[n]
+ Arbogast(c, b, n);
}
}
Example 0
#include <math.h>
#include <stdio.h>
//#include "PowerSeriesInversion.cin"
//#include "PowerSeriesCombine.cin"
#include "Arbogast.cin"
#include "PowerSeriesCombinB.cin"
int main(){ int n; int N=5; int N1=N+1;
double a[N1];
double b[N1];
double c[N1];
for(n=1;n<N1;n++) { a[n]=0.;}
double f=1.; for(n=1;n<N1;n++) {f/=n; b[n]=f;}
double k=-1; for(n=1;n<N1;n++) {k*=-1;c[n]=(0.+k)/n;}
printf("before:\n");
for(n=0;n<N1;n++) printf("%21.18lf ",a[n]); printf("\n");
for(n=0;n<N1;n++) printf("%21.18lf ",b[n]); printf("\n");
for(n=0;n<N1;n++) printf("%21.18lf ",c[n]); printf("\n");
//printf("\nPowerSeriesInversion(a,b,N):\n");
// PowerSeriesInversion(a,b,N);
printf("\nPowerSeriescombinB(a,b,c,N):\n");
PowerSeriesCombinB(a,b,c,N);
for(n=0;n<N1;n++) printf("%21.18lf ",a[n]); printf("\n");
for(n=0;n<N1;n++) printf("%21.18lf ",b[n]); printf("\n");
for(n=0;n<N1;n++) printf("%21.18lf ",c[n]); printf("\n");
printf("\nPowerSeriescombinB(a,c,b,N):\n");
PowerSeriesCombinB(a,c,b,N);
for(n=0;n<N1;n++) printf("%21.18lf ",a[n]); printf("\n");
for(n=0;n<N1;n++) printf("%21.18lf ",b[n]); printf("\n");
for(n=0;n<N1;n++) printf("%21.18lf ",c[n]); printf("\n");
printf("\nPowerSeriescombinB(a,b,b,N):\n");
PowerSeriesCombinB(a,b,b,N);
for(n=0;n<N1;n++) printf("%21.18lf ",a[n]); printf("\n");
for(n=0;n<N1;n++) printf("%21.18lf ",b[n]); printf("\n");
for(n=0;n<N1;n++) printf("%21.18lf ",c[n]); printf("\n");
does
before: 0.000000000000000000 0.000000000000000000 0.000000000000000000 0.000000000000000000 0.000000000000000000 0.000000000000000000 0.000000000000000000 1.000000000000000000 0.500000000000000000 0.166666666666666657 0.041666666666666664 0.008333333333333333 0.000000000000000000 1.000000000000000000 -0.500000000000000000 0.333333333333333315 -0.250000000000000000 0.200000000000000011 PowerSeriescombinB(a,b,c,N): 0.000000000000000000 1.000000000000000000 0.000000000000000000 -0.000000000000000028 -0.000000000000000076 0.000000000000000016 0.000000000000000000 1.000000000000000000 0.500000000000000000 0.166666666666666657 0.041666666666666664 0.008333333333333333 0.000000000000000000 1.000000000000000000 -0.500000000000000000 0.333333333333333315 -0.250000000000000000 0.200000000000000011 PowerSeriescombinB(a,c,b,N): 0.000000000000000000 1.000000000000000000 0.000000000000000000 -0.000000000000000056 0.000000000000000000 0.000000000000000000 0.000000000000000000 1.000000000000000000 0.500000000000000000 0.166666666666666657 0.041666666666666664 0.008333333333333333 0.000000000000000000 1.000000000000000000 -0.500000000000000000 0.333333333333333315 -0.250000000000000000 0.200000000000000011 PowerSeriescombinB(a,b,b,N): 0.000000000000000000 1.000000000000000000 1.000000000000000000 0.833333333333333259 0.624999999999999889 0.433333333333333348 0.000000000000000000 1.000000000000000000 0.500000000000000000 0.166666666666666657 0.041666666666666664 0.008333333333333333 0.000000000000000000 1.000000000000000000 -0.500000000000000000 0.333333333333333315 -0.250000000000000000 0.200000000000000011
The example confirms that only array at the 0th input of the function is modified.
Example 1
#include <math.h>
#include <stdio.h>
#include "Arbogast.cin"
#include "PowerSeriesCombine.cin"
#include "PowerSeriesCombinB.cin"
int main(){
int n;
int N=7;
double N1=N+1;
double a[8];
double b[8]={0,1,1,1,0,0,0,0}; // B(z)=z+z^2+z^3
double c[8]={0,1,2,0,0,0,0,0}; // C(z)=z+2z^2
printf("Initial values of array b: "); for(n=0;n<N1;n++) printf("%6.2lf",b[n]); printf("\n");
printf("Initial values of array c: "); for(n=0;n<N1;n++) printf("%6.2lf",c[n]); printf("\n");
PowerSeriesCombine(a,b,c,N);
printf("PowerSeriesCombine(a,b,c,N):"); for(n=0;n<N1;n++) printf("%6.2lf",a[n]); printf("\n");
PowerSeriesCombine(a,c,b,N);
printf("PowerSeriesCombinе(a,c,b,N):"); for(n=0;n<N1;n++) printf("%6.2lf",a[n]); printf("\n");
PowerSeriesCombinB(a,b,c,N);
printf("PowerSeriesCombinB(a,b,c,N):"); for(n=0;n<N1;n++) printf("%6.2lf",a[n]); printf("\n");
PowerSeriesCombinB(a,c,b,N);
printf("PowerSeriesCombinB(a,c,b,N):"); for(n=0;n<N1;n++) printf("%6.2lf",a[n]); printf
does
Initial values of array b: 0.00 1.00 1.00 1.00 0.00 0.00 0.00 0.00 Initial values of array c: 0.00 1.00 2.00 0.00 0.00 0.00 0.00 0.00 PowerSeriesCombine(a,b,c,N): 0.00 1.00 3.00 5.00 10.00 12.00 8.00 0.00 PowerSeriesCombinе(a,c,b,N): 0.00 1.00 3.00 5.00 6.00 4.00 2.00 0.00 PowerSeriesCombinB(a,b,c,N): 0.00 1.00 3.00 5.00 10.00 12.00 8.00 0.00 PowerSeriesCombinB(a,c,b,N): 0.00 1.00 3.00 5.00 6.00 4.00 2.00 0.00
Deduction:
B(z)=z+z^2+z^3 \\
C(z)=z+2z^2 \\
B(C(z)) = z + 2z^2 +
z^2 + 4z^3 + 4 z^4 +
z^3 + 6 z^4 + 12 z^5 + 8z^6 =
z + 3z^2 + 5z^3 + 10z^4 + 12 z^5 + 8z^6
C(B(z)) = z + z^2 + z^3 + 2(z + z^2 + z^3)^2
= z + z^2 + z^3 +
2z^2 + 4z^3 + 4z^4 + 2z^4 + 4z^5 + 2z^6
= z + 3z^2 + 5z^3 + 6 z^4 + 4z^5 + 2z^6
Example 2
#include <cmath>
//#include <cstring> // for memset
#include <stdio.h>
#include "Arbogast.cin"
#include "PowerSeriesInversion.cin"
//#include "PowerSeriesCombine.cin"
#include "PowerSeriesCombinB.cin"
double B=sqrt(2.); // 1.4142135623730951
double Q=4.;
double S=log(B);
int main() { int n;
int N=36; int N1=N+1;
double t[N1], a[N1], b[N1],c[N1], d[N1], e[N1];
t[0]=4.;
for(n=1;n<N1;n++) t[n]=t[n-1]*S/n;
a[0]=0.;
a[1]=1.;;
for(n=2;n<N1;n++) a[n] = - Arbogast(t, a, n)/( pow(t[1],n)-t[1] );
PowerSeriesInversion(b,a,N);
PowerSeriesInversion(c,b,N);
PowerSeriesCombinB(d,b,a,N);
PowerSeriesCombinB(e,a,b,N);
for(n=0;n<N1;n++) printf("%02d %19.16lf %19.16lf %19.16lf %19.16lf %19.16lf\n",n,b[n],a[n],c[n],d[n],e[n]);
}
does:
00 0.0000000000000000 0.0000000000000000 0.0000000000000000 0.0000000000000000 0.0000000000000000 01 1.0000000000000000 1.0000000000000000 1.0000000000000000 1.0000000000000000 1.0000000000000000 02 0.4485874311952611 -0.4485874311952611 -0.4485874311952611 0.0000000000000000 0.0000000000000000 03 0.1903722467978066 0.2120891200549195 0.2120891200549195 0.0000000000000000 0.0000000000000000 04 0.0778295765369682 -0.1021843675069716 -0.1021843675069716 0.0000000000000000 0.0000000000000000 05 0.0309358603057080 0.0496986830373718 0.0496986830373717 0.0000000000000000 0.0000000000000000 06 0.0120221257690659 -0.0243075903261195 -0.0243075903261195 0.0000000000000000 0.0000000000000000 07 0.0045849888965618 0.0119330883965108 0.0119330883965108 0.0000000000000000 -0.0000000000000000 08 0.0017207423310578 -0.0058736976420089 -0.0058736976420089 -0.0000000000000000 -0.0000000000000000 09 0.0006368109038799 0.0028968672871058 0.0028968672871058 -0.0000000000000000 0.0000000000000000 10 0.0002327696003031 -0.0014309081060793 -0.0014309081060793 -0.0000000000000000 -0.0000000000000000 11 0.0000841455118381 0.0007076637148566 0.0007076637148567 -0.0000000000000001 0.0000000000000000 12 0.0000301156464937 -0.0003503296158730 -0.0003503296158732 0.0000000000000002 -0.0000000000000000 13 0.0000106807458130 0.0001735756004664 0.0001735756004668 -0.0000000000000003 -0.0000000000000000 14 0.0000037565713616 -0.0000860610119292 -0.0000860610119299 0.0000000000000004 0.0000000000000000 15 0.0000013111367785 0.0000426959089013 0.0000426959089023 -0.0000000000000004 -0.0000000000000000 16 0.0000004543791625 -0.0000211930290684 -0.0000211930290696 0.0000000000000004 -0.0000000000000000 17 0.0000001564298463 0.0000105244225997 0.0000105244226009 -0.0000000000000003 0.0000000000000000 18 0.0000000535232764 -0.0000052285174362 -0.0000052285174370 -0.0000000000000001 0.0000000000000000 19 0.0000000182077863 0.0000025984499950 0.0000025984499946 0.0000000000000009 0.0000000000000000 20 0.0000000061604765 -0.0000012917821009 -0.0000012917820980 -0.0000000000000024 -0.0000000000000000 21 0.0000000020737193 0.0000006423759966 0.0000006423759892 0.0000000000000049 -0.0000000000000000 22 0.0000000006946828 -0.0000003195233018 -0.0000003195232871 -0.0000000000000085 0.0000000000000000 23 0.0000000002316515 0.0000001589712671 0.0000001589712419 0.0000000000000133 -0.0000000000000000 24 0.0000000000769124 -0.0000000791094995 -0.0000000791094604 -0.0000000000000190 -0.0000000000000000 25 0.0000000000254309 0.0000000393753741 0.0000000393753185 0.0000000000000250 -0.0000000000000000 26 0.0000000000083756 -0.0000000196019782 -0.0000000196019049 -0.0000000000000303 -0.0000000000000000 27 0.0000000000027482 0.0000000097599628 0.0000000097598731 0.0000000000000337 0.0000000000000000 28 0.0000000000008985 -0.0000000048603109 -0.0000000048602094 -0.0000000000000340 -0.0000000000000000 29 0.0000000000002927 0.0000000024207097 0.0000000024206050 0.0000000000000297 0.0000000000000000 30 0.0000000000000951 -0.0000000012058126 -0.0000000012057171 -0.0000000000000197 -0.0000000000000000 31 0.0000000000000308 0.0000000006007192 0.0000000006006495 0.0000000000000028 0.0000000000000000 32 0.0000000000000099 -0.0000000002993051 -0.0000000002992820 0.0000000000000220 -0.0000000000000000 33 0.0000000000000032 0.0000000001491436 0.0000000001491913 -0.0000000000000556 -0.0000000000000000 34 0.0000000000000010 -0.0000000000743259 -0.0000000000744721 0.0000000000000986 -0.0000000000000000 35 0.0000000000000003 0.0000000000370440 0.0000000000373185 -0.0000000000001511 -0.0000000000000000 36 0.0000000000000001 -0.0000000000184644 -0.0000000000188983 0.0000000000002127 -0.0000000000000000
Description.
The 0th column just mumerate the lines. Meaning of the 0th,1st and 2d columns is the same as in Table 9.1 at page 107 of book «Superfunctions»[1]. Values at first 20 rows show the agreement with values from the Book.
The 2st column is set of coefficits of the expansion of the Abel function and that of the Koenigs function for the growing Esponential to base sqrt2.
The 1st column is calculated from the 2nd column with routine PowerSeriesInversion from PowerSeriesInversion.cin.
Values at the first column are coefficient of the expansion of the corresponding growing SuperExponential.
The 3d column is test, the series is inverted back to reproduce the 2d column. The 4th and 3th columns are tests of the PowerSeriesCombinB routine; the series with these coefficients is supposed to reproduce the Identiry function (in the range of the conversion), up to the rounding errors.
Notes, attribution, modifications
The routine PowerSeriesCombinB is generated by ChatGPT as »PowerSeriesCombine» and renamed by Editor to PowerSeriesCombinA at PowerSeriesCombinA.cin in order to avoid confusion with PowerSeriesCombine.cin for the case, if some program, in order to compare the performance of the two implementations, will have to call then both.
Then, the order of inputs happened to be not the same as in routine PowerSeriesCombine at PowerSeriesCombine.cin ; the corrected version is denoted with name PowerSeriesCombinB and saved at PowerSeriesCombinB.cin
The honest use is assumed; at the reuse, attribute the source.
The attribution helps to trace bugs, if any.
The 0th elements of the arrays in not used in this computation.
Such a style of numeration allows the straight-forward translation of the code from C++ to some Fortran.
In the current version, the variables are declared to be double.
Editor expects, in this routine, all the specifications «double» can be replaced to something more suitable (for example, «float» or «complex double»).
At the moment of the loading, such a modification is not yet tested.
References
- ↑ https://mizugadro.mydns.jp/BOOK/468.pdf D.Kouznetsov. Superfunctions. Lambert Academic Publishing, 2020.
Keywords
«Arbogast», «Asymototic», «C++», «ChatGPT», «PowerSeriesCombine», «PowerSeriesCombinA.cin», «PowerSeriesCombinB.cin», «PowerSeriesCombine.cin», «PowerSeriesInversion.cin»,