/* Copyright (C) 2025 The PARI group PARI/GP is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY WHATSOEVER. Check the License for details. You should have received a copy of it, along with the package; see the file 'COPYING'. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ /* BA20250515 */ /* First part: compute CF using the continued fraction */ /* N first terms of T^i M^i */ TM(i,N)=prod(k=0,N,sum(j=0,i-1, x^(j*((2*i)^k))-x^((i+j)*((2*i)^k)))); sercontfrac(P,m)= { my(Q=x^(poldegree(P)+1)); P = polrecip(P); my(V=vector(m)); for(i=1,m, my(q,r); [q,r]=divrem(P,Q); V[i]=q; P=Q;Q=r; if(Q==0,break); ); V; } /* N firsrt terms of the continued fraction of T^i M^i */ CF(i,N)=sercontfrac(TM(i,logint(N-1,2)+(i==1)),N); /* Second part: compute cf using the formulas */ Pcol(i,k,m)= { if(k==0,vectorv(m,i,i==1), Colrev(((x+1)^(2*i)-1)^(k-1)*((x+1)^i+1)^2,m)); } /* P_{i,n}(1) for n=1..N */ P_1(i,N)= { my(V, M, D); M = Mat([Pcol(i,k,N)|k<-[0..N]]); D = Colrev(sum(k=0,i-1,(x+1)^(2*i*k)),N+1); V=[1]; concat(D[1],vector(N,j, V*=M[1..j,1..(j+1)];V*D[1..#V])); } /* P_{i,n} for n=1..N */ P(i,N) = { my(P = (x^(2*i^2)-1)/(x^(2*i)-1) ); concat(P,vector(N,j, my(Q = subst(P,x,x^(2*i))); P = Q+2*(Q-subst(P,x,1))/(x^i-1))); } /* lambda_{i,n} for n=1..N */ lambda(i,N)= { my(S=1, M =(N+3)\4); my(P1 = P_1(i,logint(4*M,2))); my(L=vector(4*M)); L[1]=1; for(k=1,M, if (k>1, S += P1[1+valuation(k-1,2)]*L[2*k-1]); L[4*k-3] = L[2*k-1]; L[4*k-2] = (2*S)^-1; L[4*k-1] = -L[2*k]*(2*S)^2; L[4*k] = -L[4*k-2]; ); L[1..N]; } /* N first terms of the formula for T^i M^i */ cf(i,N)= { my(L=lambda(i,N)); my(V0=if(i==1,x+1,x-1)); my(V1=if(i==1,x-1,(x^i-1)/(x-1))); my(V=concat(V1,V0*P(i,logint(N-1,2)))); concat(0,vector(N-1,k, if(k==1,V0,L[k]*V[1+valuation(k-1,2)]))); } /* Third part: check P_1 = P(1), cf = CF */ test(s)=print(s,":",if(eval(s),"OK","ERROR")); default(parisize,max(default(parisize),128000000)); check()= { for(i=1,4, if(P_1(i,5)!=subst(P(i,5),x,1),error("P_1(",i,")"))); test(()->cf(1,2048)==CF(1,2048)); test(()->cf(2,128)==CF(2,128)); test(()->cf(3,64)==CF(3,64)); test(()->cf(4,32)==CF(4,32)); test(()->cf(5,16)==CF(5,16)); }