#John Kim #Use whatever you like Help:=proc(): print(` GuessAlg(L,P,x,MaxDegP) `): print( ` GuessAlg1(L,P,x,DegP) , GuessAlg11(L,P,x,DegP,Degx) `): end: #C10.txt: starting the Alg. Formal Power Series #1+1!*x+2!*x^2+3!*x^3+ ...... #GuessAlg(L,P,x,MaxDegP): Inputs a sequence of numbers L #and tries to guess an alg. eq. of the from #F(P,x)=0. where P is the symbol for the generating #function of L, P(x)=add(L[i+1]*x^i,i=0..infinity) #of max. degree MaxDegP GuessAlg:=proc(L,P,x, MaxDegP) local g,DegP: for DegP from 1 to MaxDegP do g:=GuessAlg1(L,P,x,DegP): if g<>FAIL then RETURN(g): fi: od: FAIL: end: #GuessAlg1(L,P,x,DegP): Inputs a sequence of numbers L #and tries to guess an alg. eq. of the from #F(P,x)=0. where P is the symbol for the generating #function of L, P(x)=add(L[i+1]*x^i,i=0..infinity) #of degree DegP in P GuessAlg1:=proc(L,P,x, DegP) local g,Degx: for Degx from 0 while (1+Degx)*(1+DegP)FAIL then RETURN(g): fi: od: FAIL: end: #GuessAlg11(L,P,x,DegP, Degx): Inputs a sequence of numbers L #and tries to guess an alg. eq. of the from #F(P,x)=0. where P is the symbol for the generating #function of L, P(x)=add(L[i+1]*x^i,i=0..infinity) #of degree DegP in P and Degx in x GuessAlg11:=proc(L,P,x, DegP, Degx) local g, F,a, i,j, var,P1,F1,eq, var1,v: F:=add(add(a[i,j]*x^i*P^j,i=0..Degx),j=0..DegP): var:={seq(seq(a[i,j],i=0..Degx),j=0..DegP)}: P1:=add(L[i]*x^(i-1),i=1..nops(L)): F1:=expand(subs(P=P1,F)): eq:={seq( coeff(F1,x,i)=0, i=0..nops(L)-1)}: var1:=solve(eq,var): F:=subs(var1,F): if F=0 then RETURN(FAIL): else F:=subs({seq(v=1, v in var)},F): F:=add(factor(coeff(F,P,i))*P^i,i=0..degree(F,P)): RETURN(F): fi: end: #DiagToAlg(R,x,y,P,t,MaxDegP): inputs a rational function R of the two variables x and y, #and outputs a guessed algebaric equation F(P,t) such that if you do mtaylor to R #(do the two-dimensional Taylor expansion of R about the origin) and call its Taylor coefficients a_i,j, then if #Di(t):=a_0,0+a_1,1*t+a_2,2*t^2+a_3,3*t^3+ ... #then F(Di,t)=0 . DiagToAlg:=proc(R,x,y,P,t,MaxDegP) local L: L:=[seq(coeftayl(R,[x,y]=[0,0],[i,i]),i=0..50)]: GuessAlg(L,P,t,MaxDegP): end: #DiagToAlg(1/((1-x)*(1-y)),x,y,P,t,6); #1+(-1+t)*P #DiagToAlg(1/(1-x-y),x,y,P,t,6); #1/4+(-1/4+t)*P^2 #DiagToAlg(1/(1-x-y+3*x*y),x,y,P,t,6); #-1/9+(1/9+(2/9)*t+t^2)*P^2 #DiagToAlg(1/(1-x-x^2-y-y^2),x,y,P,t,10); #1/128+(1/64*(4*t-3))*(4*t^2-8*t+1)*P^2+(1/128*(5+8*t))*(4*t^2-8*t+1)^2*P^4 #AlgToSeq(F,P,x,K): inputs a polynomial F of the symbols P and x, the symbols P and x, #and a positive integer K, and outputs the sequence consisting of the first K coefficients #of the unique formal-power-series solution of the algebraic equation F(P(x),x)=0 #(if there is such a solution, otherwise it should return FAIL, for example, #AlgToSeq(P^2-x^3*P+1,P,x,20); #should return FAIL, while #AlgToSeq(x*P^2-P+1,P,x,20); #should return the first 20 terms of the Catalan sequence. AlgToSeq:=proc(F,P,x,K) local H,G,f,g,g1,i,j,L: H:=coeff(F,P): G:=H*P-F: g:=simplify(subs(P=f,G/H)): g1:=1: for i from 1 to K do g1:=simplify(subs(f=g1,g)): g1:=add(coeff(g1,x,j)*x^j,j=0..K-1): od: L:=[seq(coeff(g1,x,i),i=0..K-1)]: if convert(L,set)={0} then FAIL: else L: fi: end: #LIF(F,z,P,n) that inputs a polynomial F in z and P signifying an algebraic relation F(P,z)=0 #and symbols P, z, makes a change of dependent variable to get it to the format required by the #Lagrange Inversion Formula (IF POSSIBLE, it is often not possible, in that case return FAIL) #and n, and outputs (in the notation of that writeup PHI(z)^n/(n z^(n-1)). LIF:=proc(F,z,P,n) local H,G,phi,G0: G:=coeff(F,z,0): H:=G-F: G0:=coeff(G,P,0): phi:=simplify((H-G0)/((G-G0)/P)/z): if subs(z=1,phi)<>phi then RETURN(FAIL): fi: #coeff(taylor(phi^n,P=0,n),P,n-1)/n: phi^n/n/(P^(n-1)): end: