#OK to post # Soham Palande, Assignment 12, 10/18/2020 #PART 1 Cpg:=proc(L) local temp,Result: Result:=L: while nops(Result)>1 do temp:=Result[1]: temp:=CP(Result[1],Result[2]): Result:=subsop(1=temp,Result): Result:=subsop(2=NULL,Result): od: Result: end: #EXAMPLE L1:=[1,2,3,4] L2:=[5,6,7,8] L3 := [9, 10, 11, 12] CP(L1,L2) [6, 7, 8, 9, 7, 8, 9, 10, 8, 9, 10, 11, 9, 10, 11, 12] L:=[L1,L2,L3] L := [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]] Cpg(L) [[15, 16, 17, 18, 16, 17, 18, 19, 17, 18, 19, 20, 18, 19, 20, 21, 16, 17, 18, 19, 17, 18, 19, 20, 18, 19, 20, 21, 19, 20, 21, 22, 17, 18, 19, 20, 18, 19, 20, 21, 19, 20, 21, 22, 20, 21, 22, 23, 18, 19, 20, 21, 19, 20, 21, 22, 20, 21, 22, 23, 21, 22, 23, 24]] #PART 2 AveGF:=proc(f,x) subs(x=1,diff(f,x))/subs(x=1,f): end: kthMomentGF:=proc(f,x,k) local mu,f1,i: mu:=AveClever(L): f1:=f/x^mu/subs(x=1,f): for i from 1 to k do f1:=expand(x*diff(f1,x)): od: subs(x=1,f1): end: # EXAMPLE L:=[4,7,6,8,9] f:=WtEn(L,x) f := x^9+x^8+x^7+x^6+x^4 AveClever(L) 34/5 AveGF(f,x) 34/5 kthMomentClever(L,2) 74/25 kthMomentGF(f,x,2) 74/25 #PART 3 #using function kthMomentGF(f,x,k) written in question 2 of the hw ScaledMomentGF:=proc(f,x,k) local m_k,m_2,denom,res: m_k:=kthMomentGF(f,x,k): m_2:=kthMomentGF(f,x,2): denom:=m_2^(k/2): res:=m_k/denom: res: end: #PART 4 seq(limit(ScaledMomentGF(((1+x)/2)^n,x,k),n=infinity),k=2..10) #Yes the sequence is in the OEIS.