#OK to post homework #Alan Chernoff, 2/1/20, Assignment 3 Help:=proc():print(`PGF(X,t), Moms(X,k), Alpha(X,k), BiRV(p,n), BiRVMoms(p,N,k) `): end: #PGF(X,t): The probability generating function (a finite sum, or "generalized polynomial #t^(-3) is OK and t^(1/2) is OK PGF:=proc(X,t) local i: if not (type(t,symbol) and type(X,list) and {seq(nops(X[i]),i=1..nops(X))}={2} and {seq(type(X[i],list), i=1..nops(X))}={true}) then print(`Bad input`): RETURN(FAIL): fi: add(X[i][1]*t^X[i][2],i=1..nops(X)): end: #Moms(X,k): inputs a finite prob. dist. (with our data structre) and #a pos. integer k, outputs a list of size k whose first entry is #the mean (alias expectaion alias average), the second entry is #the variance and the i-th entry is the i-th moment ABOUT the mean Moms:=proc(X,k) local t, f,mu,f1,L,i: f:=PGF(X,t): mu:=subs(t=1,diff(f,t)): L:=[mu]: f:=t*diff(f/t^mu,t): #standardizes it for i from 2 to k do f:=t*diff(f,t): L:=[op(L), subs(t=1,f)]: od: L: end: #Alpha(X,k): inputs a finite prob. dist. (with our data structure) and #a pos. integer k, outputs a list of size k who first entry is the mean, #whose second entry is the variance, and whose i-th entry is the i-th scaled #moment about the mean Alpha:=proc(X,k) local t, f, mu, var, L, i: f:=PGF(X,t): mu:=subs(t=1,diff(f,t)): L:=[mu]: f:=t*diff(f/t^mu,t): f:=t*diff(f,t): var:=subs(t=1,f): L:=[op(L), var]: for i from 3 to k do f:=t*diff(f,t): L:=[op(L), subs(t=1,f)/var^(i/2)]; od: L: end: #BiRV(p,N): generates a binomial r.v. with parameters p and N BiRV:=proc(p,N) local i,L: with(combinat): L:=[[((1-p))^N,0]]: for i from 1 to N do L:=[op(L), [numbcomb(N,i)*p^i*(1-p)^(N-i),i]]: od: L: end: #BiRVMoms(p,N,k): generates binomial rv expectation, variance, and k scaled moments with parameters N, p BiRVMoms:=proc(p,N,k): simplify(Alpha(BiRV(p,N),k)): end: