#Yusra Naqvi: HW #10 #OK to post ################################################################################ #We first copy the procedures from C10.txt. ################################################################################ #GuessAlg(L,P,x,MaxDegP): inputs a sequence of numbers L and tries to guess #an algebraic eqn of the form: #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) #where the degree of P in F is at most 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 algebraic eqn of the form: #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) #where the degree of P in F is DegP GuessAlg1:=proc(L,P,x,DegP) local g,Degx,MaxDegx: for Degx from 0 while (DegP+1)*(Degx+1)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 algebraic eqn of the form: #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) #where the degree of P in F is DegP, and the degree of x is Degx GuessAlg11:=proc(L,P,x,DegP,Degx) local F,a,i,j,var,P1,F1,eq,var1: 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: ################################################################################ #We now go on to the homework problems. ################################################################################ #2 #DiagToAlg(R,x,y,P,t,MaxDegP): Inputs a rational function R in variables x and y #and outputs a guessed algebraic equation F(P,t) such that if a_{i,j} are the #co-efficients in the 2-variable Taylor expansion of R and Di(t) is the series: #a_{0,0}+a_{1,1}t+a_{2,2}t^2+... #then F(Di,t)=0. DiagToAlg:=proc(R,x,y,P,t,MaxDegP) local L,i: L:=[seq(coeff(coeff(mtaylor(R,[x,y],10*MaxDegP+1),x,i),y,i),i=0..5*MaxDegP)]: GuessAlg(L,P,t,MaxDegP): end: ### #We get: #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+(1-4*t)*P^2 #DiagToAlg(1/(1-x-y+3*x*y),x,y,P,t,6); #-1/2+(1/2+t+(9/2)*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 ################################################################################ #3 #AlgToSeq(F,P,x,K): inputs a polynomial F of the symbols P and x and #a positive integer K, and outputs the sequence consisting of #the first K coefficient of the unique formal-power-series solution #of the algebraic equation: #F(P(x),x)=0 AlgToSeq:=proc(F,P,x,K) local H,f,i,L: H:=coeff(coeff(F,P,1),x,0): if H=0 then return(FAIL): fi: f:=(F-H*P)/(-H): for i from 1 to K do f:=subs(P=f,f): L:=[seq(coeff(f,x,i),i=0..K)]: if {seq(degree(L[i]),i=1..nops(L))} subset {0,infinity} then return(L): fi: od: FAIL: end: ################################################################################ #5 #LIF(F,x,P,n): inputs an algebraic relation F(P,x)=0 and outputs #PHI(x)^n/(x^(n-1)*n) LIF:=proc(F,x,P,n) local Phi: #First check to see if it is possible to get Phi from F Phi:=LIFform(F,x,P): if Phi=FAIL then return(Phi): fi: (subs(P=x,Phi^n))/n/x^(n-1): end: ### #LIFform(F,x,P): outputs Phi, if it is possible to find it. #This is a work in progress, and it may be possible to transform #more expressions to the correct form than what I have here. LIFform:=proc(F,x,P) local F1,G,P1: F1:=coeff(F,x,0): if degree(F,x)=1 and degree(F1,P)=1 then G:=(F1-F)/x: P1:=(P-coeff(F1,P,0))/(coeff(F1,P,1)): subs(P=P1,G): else FAIL: fi: #We can insert an elif statement for any additional possible #change of variables. end: ################################################################################