Help:=proc(): print(` AlgToSeq(F,P,x,K,f0)`): end: Help10:=proc(): print(` GuessAlg(L,P,x,MaxDegP) `): print( ` GuessAlg1(L,P,x,DegP) , GuessAlg11(L,P,x,DegP,Degx) `): end: ###stuff from C10.txt########### #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: ##end stuff from C10.txt #new stuff starts #AlgToSeq(F,P,x,K,f0): INPUTS #(i) a polynomial F in the variables P and x #denoting an algebraic relation satisfied by a formal #power series P(x), such that #F(P(x),x)=0 #(ii) and (iii) variables P and as above #(iv): a pos. integter K #(v): f0 the constant term #OUTPUTS: #a sequence of length K+1 denoting the #coeff. of x^0 through x^K of the Maclaurin expansion #of the power series of P(x). #For example, #AlgToSeq(P*(1-x)-1,P,x,4); should output #[1,1,1,1,1]; #AlgToSeq(P-1-x*P^2,P,x,4); should yield: #[1,1,2,5,14] AlgToSeq:=proc(F,P,x,K,f0) local H,F1,i,f,L,m: H:=coeff(F,P,1): if subs(x=0,H)=0 then RETURN(FAIL): fi: #a0(x)+H(x)*P(x)+a2(x)*P(x)^2+...=0 #P(x)=-(a0(x)+a2(x)*P(x)^2+....)/H(x) F1:=(P*H-F)/H: #start at f(x)=1 and iterate f(x)->F1(f(x)) f:=f0: L:=[f0]: for i from 1 to K do f:=subs(P=f,F1): f:=taylor(f,x=0,i+1): L:=[op(L),coeff(f,x,i)]: f:=add(coeff(f,x,m)*x^m,m=0..i): od: L: end: