#hw9.txt Cole Franks 22/02/2014 read(`/Users/Cole/C9.txt`): #### problem 1. Help:=proc(): print(`ApplyUmbra(P,x,U,m),PnG(n, x, U, m),GuessCoeff(n,i,U,m), GuessOP(n,r,U,m)`): end: # ApplyUmbra(P,x,U,m) replaces x^m by the expression U(m) # and extends to U(P) by linearity. ApplyUmbra:=proc(P,x,U,m) local i, Q, d: Q:=expand(P): d:=degree(P,x): for i from 0 to d-1 do Q:=applyrule(x^(d-i)=subs(m=(d-i),U),Q): #print(Q): od: Q: end: #### problem 2. PnG:=proc(n, x, U, m) local eq,var,i,P,a: option remember: P:=x^n+add(a[i]*x^i,i=0..n-1): var:={seq(a[i],i=0..n-1)}: eq:={ seq( ApplyUmbra(expand(P*x^i), x, U,m)=0, i=0..n-1)}: #eq: sort(subs(solve(eq,var),P)): end: ###### Problem 3. GuessCoeff:=proc(n,i,U,m) local L, j, limit: option remember: #limit is just a reasonable large number of #inputs to guessRF that we would possibly want to make. limit:=100: L:=[]: for j from i to i+limit do L:=[op(L),coeff(PnG(j,x,U,m), x, (j-i))]: #print(L): if GuessRF(L,n)<>FAIL then #we have to substitute n=n-i+1 because #the 1st entry of the list gives the #value for n=i. return(factor(subs(n=n-i+1, GuessRF(L, n)))): fi: od: return(FAIL): end: #i, rational function: #U=1/m+1 # 0, 1 # 1 # 1, - - n # 2 # 2 # (n - 1) n # 2, ------------ # 4 (-1 + 2 n) # 2 # (n - 2) n (n - 1) # 3, - ------------------ # 24 (-1 + 2 n) # 2 2 # (n - 3) n (n - 1) (n - 2) # 4, --------------------------- # 96 (-1 + 2 n) (-3 + 2 n) # # 2 2 # (n - 4) n (n - 1) (n - 2) (n - 3) # 5, - ----------------------------------- # 960 (-1 + 2 n) (-3 + 2 n) # 2 2 2 # (n - 5) n (n - 1) (n - 2) (n - 3) (n - 4) # 6, -------------------------------------------- # 5760 (2 n - 5) (-1 + 2 n) (-3 + 2 n) # # 2 2 2 # (n - 6) n (n - 1) (n - 2) (n - 3) (n - 4) (n - 5) # 7, - ---------------------------------------------------- # 80640 (2 n - 5) (-1 + 2 n) (-3 + 2 n) #U=1/m+3 # 0, 1 # 1 # 1, - - n # 2 # 2 # (n - 1) n # 2, ------------ # 4 (-1 + 2 n) # 2 # (n - 2) n (n - 1) # 3, - ------------------ # 24 (-1 + 2 n) # 2 2 # (n - 3) n (n - 1) (n - 2) # 4, --------------------------- # 96 (-1 + 2 n) (-3 + 2 n) # 2 2 # (n - 4) n (n - 1) (n - 2) (n - 3) # 5, - ----------------------------------- # 960 (-1 + 2 n) (-3 + 2 n) # 2 2 2 # (n - 5) n (n - 1) (n - 2) (n - 3) (n - 4) # 6, -------------------------------------------- # 5760 (2 n - 5) (-1 + 2 n) (-3 + 2 n) # 2 2 2 # (n - 6) n (n - 1) (n - 2) (n - 3) (n - 4) (n - 5) # 7, - ---------------------------------------------------- # 80640 (2 n - 5) (-1 + 2 n) (-3 + 2 n) #U = eval(m!) # 0, 1 # 2 # 1, -n # 1 2 2 # 2, - n (n - 1) # 2 # 1 2 2 2 # 3, - - n (n - 1) (n - 2) # 6 # 1 2 2 2 2 # 4, -- n (n - 1) (n - 2) (n - 3) # 24 # 1 2 2 2 2 2 # 5, - --- n (n - 1) (n - 2) (n - 3) (n - 4) # 120 # 1 2 2 2 2 2 2 # 6, --- n (n - 5) (n - 1) (n - 2) (n - 3) (n - 4) # 720 # 1 2 2 2 2 2 2 2 #7, - ---- n (n - 1) (n - 2) (n - 3) (n - 4) (n - 5) (n - 6) # 5040 # note that the constant in the denominator is n!. #### problem 4 #it does not appear that these will be rational functions. # it does, however, appear that their ratios will be. #GuessOP(n,r,U,m) takes variables n,r and an umbra U in the variable m #and guesses a formula for the ratio #GuessCoeff(n,r,U,m)/GuessCoeff(n,r-1,U,m). GuessOP:=proc(n,r,U,m) local L, i, limit: #we will do this by making #a list of ratios of GuessCoeff(n, i, U,m) #for i ranging from 0 to some fairly large number (limit). #then we will use guess(RF) to guess this ratio. #I am considering a ratio (and an initial value, which here will always be 1) #to be just as good as a #closed form, because you can just multiply #the ratio lots of times to get the formula. limit:=100: L:=[]: for i from 1 to limit do L:=[op(L), GuessCoeff(n,i,U,m)/GuessCoeff(n,i-1,U,m)]: #ColeGuess is a slightly altered version of #GuessRF that only asks for 2d + 2 elements in the #list so that we donâ€™t have to compute so many #expressions. if ColeGuessRF(L,r)<>FAIL then return(factor(ColeGuessRF(L,r))): fi: od: return(FAIL): end: ### old stuff ColeGuessRF1:=proc(L,d,n) local R,a,b,i,j,eq,var: if nops(L)<=2*d+2 then #print(`Make list bigger`): RETURN(FAIL): fi: R:=(n^d+add(a[i]*n^i,i=0..d-1))/add(b[j]*n^j,j=0..d): var:={seq(a[i],i=0..d-1), seq(b[j],j=0..d)}: eq:={seq( numer(L[i]-subs(n=i,R)) =0,i=1..2*d+2)}: var:=solve(eq,var): if var=NULL then RETURN(FAIL): fi: R:=subs(var , R): if {seq( numer(L[i]-subs(n=i,R)),i=1..nops(L))}<>{0} then print(`It worked up to`, 2*d+6, `terms, but that's life `): FAIL: else R: fi: end: #GuessRF(L,n): inputs a list of numbers (or expressions) #L, and a (discrete) variable name #n and tries to guess a rational function of n of degree #<=(nops(L)-6)/2 such that L[i]-R(i)=0 for all i from 1 to nops(L) ColeGuessRF:=proc(L,n) local d, katie: for d from 0 to (nops(L)-2)/2 do katie:=GuessRF1(L,d,n): if katie<>FAIL then RETURN(katie): fi: od: FAIL: end: