##################################################################### ## RNAstat.txt Save this file as RNAStat.txt to use it, # # stay in the # ## same directory, get into Maple (by typing: maple ) # ## and then type: read `RNAstat.txt` # ## Then follow the instructions given there # ## # ## Written by Doron Zeilberger, Rutgers University , # ## DoronZeil at gmail dot com # ###################################################################### with(plots): print(`First Written: Jan. 14, 2026: tested for Maple 2025 `): print(`This Version: Jan. 14, 2026 `): print(): print(`This is RNAstat.txt, a Maple package`): print(`accompanying AJ Bu, Manuel Kauers and Doron Zeilberger's article: `): print(` Statistical Analysis of The Number of Hairpins and Basepairs in RNA Secondary Structures `): print(): print(`The most current version is available on WWW at:`): print(` http://sites.math.rutgers.edu/~zeilberg/tokhniot/RNAstat.txt .`): print(`Please report all bugs to: DoronZeil at gmail dot com .`): print(): print(`For general help, and a list of the MAIN functions,`): print(` type "ezra();". For specific help type "ezra(procedure_name);" `): print(`For a list of the Story functions type: ezraSt();`): print(): print(`For a list of the Single variable functions type: ezraS();`): print(): ezraS:=proc() if args=NULL then print(`The single procedures are: cSeqMomR, DiffR, GenStSingle, ScSeqMomR, SeqMomR, SeqR `): else ezra(args): fi: end: ezraSt:=proc() if args=NULL then print(`The Story procedures are: RNAstory, Story, StorySingle `): else ezra(args): fi: end: ezra1:=proc() if args=NULL then print(`The SUPPORTING procedures are: DiffRS, MyAsy1, NormRS, SeqMomRS, SeqRS `): else ezra(args): fi: end: ezra:=proc() if args=NULL then print(` RNAstat.txt: A Maple package for the statistical analysis of the number of hairpins and basepairs in RNA secondary structures`): print(`The MAIN procedures are: cSeqMomRS, GenStN, GGF, GGFdyck, MyAsy, MyAsyM, RNAstN, ScSeqMomRS, SeqMomRS, Stat `): print(``): elif nargs=1 and args[1]=cSeqMomR then print(`cSeqMomR(f,X,x,z,R,S,N): The centalized R-th moment of the r.v. given by the parameters x in the generating function f(X,x). Try:`): print(`cSeqMomR(-1/2*(h*x+(h^2*x^2-2*h*x-4*x^2+1)^(1/2)-1)/x^2,x,h,4,20);`): elif nargs=1 and args[1]=cSeqMomRS then print(`cSeqMomRS(f,X,x,z,R,S,N): The centalized mixed R-S moment of the r.v. given by the parameters x and z in the grand generating function f(X,x,z). Try:`): print(`cSeqMomRS(GGF(X,x,z),X,x,z,1,1,20);`): elif nargs=1 and args[1]=DiffR then print(`DiffR(f,X,x,R): inpute a function f(X,x), and a non-negative integer R, outputs (xd/d)^R f(X,x)|x=1. Try:`): print(`DiffR(-1/2*(h*x+(h^2*x^2-2*h*x-4*x^2+1)^(1/2)-1)/x^2,x,h,4);`): elif nargs=1 and args[1]=DiffRS then print(`DiffRS:=proc(f,X,x,z,R,S): inpute a function f(X,x,z), and non-negative integers R and S, outputs (xd/d)^R(zd/dz)^S f(X,x,z)|{x=1,z=1}. Try:`): print(`DiffRS(GGF(X,x,z),X,x,z,1,1);`): elif nargs=1 and args[1]=GenStN then print(`GenStN(f,X,x,z, N,n,r): inputs the grand-generating function f in X,x,z, where, for some combinatorial family,`): print(`equipped with two discrete variables, R_1(n), R_2(n), the coeff. of`): print(`X^n*x^i*z^j is the number of objects,s, of size n with R_1(s)=i and R_2(s)=j`): print(`The asympotitc in n of the counting sequence, followed by the`): print(`asympotics of the R_1(n) and R_2(n), using N terms and order r asymptotics. Try:`): print(`GenStN(GGF(X,x,z),X,x,z,200,n,4);`): elif nargs=1 and args[1]=GenStSingle then print(`GenStSingle(f,X,x,N,n,r): inputs the grand-generating function f in X,x, where, for some combinatorial family,`): print(`equipped with a discrete variable, R_1(n) the coeff. of`): print(`X^n*x^i is the number of objects, s, of size n with R_1(s)=i`): print(`The asympotitc in n of the counting sequence, followed by the`): print(`asympotics of R_1(n) using N terms and order r asymptotics`): print(`Try:`): print(`GenStSingle(-1/2*(h*x+(h^2*x^2-2*h*x-4*x^2+1)^(1/2)-1)/x^2,x,h,20,n,4);`): elif nargs=1 and args[1]=GGF then print(`GGF(X,x,z): The generating function in the variable X, with parameters x and z whose coefficient of X^n is the`): print(`weight-enumerator of RNA secondary structures of size n according to the weight x^NumerOfHairpins(object)*z^NumberOfBasepair(object). Type:`): print(`GGF(X,x,z);`): elif nargs=1 and args[1]=GGFdyck then print(`GGFdyck(z,p): The generating function in the variable z, with parameter p whose coefficient of z^n is the weight-enumerator of the set of Dyck paths of semi-length n`): print(`according to the weight p^NumerOfPeaks. Try:`): print(`GGFdyck(z,p);`): elif nargs=1 and args[1]=MyAsy then print(`MyAsy(L,n,k): tries to fit the sequence L to be of the form C*mu^n*n^theta*(1+c1/n+...+ck/n^k). Try:`): elif nargs=1 and args[1]=MyAsy1 then print(`MyAsy1(L,n,k): inputs a sequence that is believed to have an asympotic expansion finds the best a[0]+a[1]/n+...+a[k]/n^k that fits it. Try:`): print(`MyAsy1([seq(0.1+0.2/i+0.3/i^2,i=1..200)],n,2);`): elif nargs=1 and args[1]=MyAsyM then print(`MyAsyM(L,mu,n,k): tries to fit the sequence L to be of the form C*mu^n*n^theta*(1+c1/n+...+ck/n^k), with known mu. Try:`): elif nargs=1 and args[1]=NormRS then print(`NormRS(c,R,S): The scaled moments of the bi-varirate normal with correlation c. Try:`): print(`NormRS(c,2,2);`): elif nargs=1 and args[1]=RNAstN then print(`RNAstN(N,n,r): The asympotitc in n of the counting sequence, followed by the`): print(`asympotics of the hairpins and basepairs of RNA secondary structures using N terms and order r asymptotics. Try:`): print(`RNAstN(200,n,4);`): elif nargs=1 and args[1]=RNAstory then print(`RNAstory(M): Using numerics, estimates the asymptotics of the expectations, variances, of the number of hairpins and Basepairs in RNA secondary structures`): print(`and it takes it up to the (M,M) mixed moment. Try:`): print(`RNAstory(4);`): elif nargs=1 and args[1]=ScSeqMomR then print(`ScSeqMomR(f,X,x,R,N): The Scaled centalized Rmoment of the r.v. given by the parameter x in the grand generating function f(X,x). Try:`): print(`ScSeqMomR(-1/2*(h*x+(h^2*x^2-2*h*x-4*x^2+1)^(1/2)-1)/x^2,x,h,4,20);`): elif nargs=1 and args[1]=ScSeqMomRS then print(`ScSeqMomRS(f,X,x,z,R,S,N): The Scaled centalized mixed R-S moment of the r.v. given by the parameters x and z in the grand generating function f(X,x,z). Try:`): print(`ScSeqMomRS(GGF(X,x,z),X,x,z,1,1,20);`): elif nargs=1 and args[1]=SeqMomR then print(`SeqMomR(f,X,x,R,N): first N terms of The R-th moment of the r.v. given by f(X,x). Try:`): print(`SeqMomR(-1/2*(h*x+(h^2*x^2-2*h*x-4*x^2+1)^(1/2)-1)/x^2,x,h,4,20);`): elif nargs=1 and args[1]=SeqMomRS then print(`SeqMomRS(f,X,x,z,R,S,N): The (R-S) mixed moment of the r.v. given by f(X,x,z). Try:`): print(`SeqMomRS(GGF(X,x,z),X,x,z,1,1,20);`): elif nargs=1 and args[1]=SeqR then print(`SeqR(f,X,x,R,N): The first N terms stating at n=1 of the Maclaurin coefficients of DiffR(f,X,x,R). Try:`): print(`SeqR(-1/2*(h*x+(h^2*x^2-2*h*x-4*x^2+1)^(1/2)-1)/x^2,x,h,4,20);`): elif nargs=1 and args[1]=SeqRS then print(`SeqRS(f,X,x,z,R,S,N): The first N terms stating at n=1 of the Maclaurin coefficients of DiffRS(r,X,x,z,R,S). Try:`): print(`SeqRS(GGF(X,x,z),X,x,z,1,1,20);`): elif nargs=1 and args[1]=Stat then print(`Stat(F,t,K): Given a generating function F of t, for a r.v. `): print(` finds the statistical information. Try:`): print(`Stat((1+t)^100,t,6);`): elif nargs=1 and args[1]=Story then print(`Story(f,X,x,z,M): Using numerics, estimates the asymptotics of the expectations, variances, of a pair of discrete random vairables, let's call them X1 and X2`): print(`defined on combinatorial objects`): print(`and it takes it up to the (M,M) mixed moment. Ror the original problem, same as RNAstory,Try:`): print(`Story(GGF(X,x,z), X,x,z,4);`): print(``): print(`For Motzkin paths according to the number of horizontal steps and up steps, try:`): print(``): print(`Story(-1/2*(x*z1+(x^2*z1^2-4*x^2*z2-2*x*z1+1)^(1/2)-1)/x/z2,x,z1,z2,4);`): print(``): print(`For the pair of Statistics on binary trees studied by Werner Krandick, see`): print(``): print(`https://sites.math.rutgers.edu/~zeilberg/mamarim/mamarimhtml/krandick.html`): print(``): print(`Story(-1/2*(-q*t*x+t*x+(q^2*t^2*x^2-2*q*t^2*x^2-2*q*t^2*x+t^2*x^2-2*t^2*x+t^2)^(1/2)+t-2)/(q*t*x+t^2*x-t*x-t+1),x,t,q,4);`): print(``): elif nargs=1 and args[1]=StorySingle then print(`StorySingle(f,X,x,M): Using numerics, estimates the asymptotics of the expectations, variances, of a discrete random vairable, let's call it X1`): print(`defined on combinatorial objects and goes up to the M moment `): print(` For RNA secondary structures according to the number of hairpins, Try:`): print(`StorySingle(GGF(X,x,1), X,x,4); `): print(``): print(` For Dyck-path of semi-length n according to the number of picks, try::`): print(`StorySingle( -1/2*(p*x+(p^2*x^2-2*p*x^2-2*p*x+x^2-2*x+1)^(1/2)-x-1)/x, x,p,10); `): else print(`There is no such thing as`, args): fi: end: ###From Stat #Stat(F,t,K): Given a generating function F of t, for a r.v. # finds the statistical information. Try: #Stat((1+t)^100,t,6); Stat:=proc(F,t,K) local gu,mu,sd,k,f: f:=evalf(F/subs(t=1,F),20): mu:=subs(t=1,diff(f,t)): gu:=[mu]: if K=1 then RETURN(gu): fi: f:=f/t^mu: f:=t*diff(t*diff(f,t),t): sd:=sqrt(subs(t=1,f)): gu:=[op(gu),sd]: for k from 3 to K do f:=t*diff(f,t): gu:=[op(gu),subs(t=1,f)/sd^k]: od: evalf(gu,20): end: ##end from Stat #GGF(X,x,z): The generating function in the variable X, with parameters x and z whose coefficient of X^n is the #weight-enumerator of RNA secondary structures of size n according to the weight x^NumerOfHairpins(object)*z^NumberOfBasepair(object). Type: #GGF(X,x,z); GGF:=proc(X,x,z) 1/2*(-2*X^4*z+X^3*x*z+X^2*z-X^2+2*X-1+(X^6*x^2*z^2-2*X^5*x*z^2-2*X^5*x*z+4*X^4*x*z+X^4*z^2-2*X^4*z-2*X^3*x*z+X^4+4*X^3*z-4*X^3-2*X^2*z+6*X^2-4*X+1)^(1/2))/X^2/z/(X-1): end: #GGFdyck(z,p): The generating function in the variable z, with parameter p whose coefficient of z^n is the weight-enumerator of the set of Dyck paths of semi-length n #according to the weight p^NumerOfPeaks. Try: #GGFdyck(z,p); GGFdyck:=proc(z,p): -1/2*(p*z-z+(p^2*z^2-2*p*z^2-2*p*z+z^2-2*z+1)^(1/2)-1)/z: end: #MyAsy(L,n,k): tries to fit the sequence L to be of the form C*mu^n*n^theta*(1+c1/n+...+ck/n^k). Try: MyAsy:=proc(L,n,k) local gu,logC,logmu,theta,c,i,eq,var,C,mu,x,ku: if nops(L)<20 then print(`List must be at least of length 20`): RETURN(FAIL): fi: if 10+k>nops(L) then print(`k must be at most`, nops(L)-10 ): fi: gu:=logC+logmu*n+theta*log(n)+add(c[i]/n^i,i=1..k): var:={logC,logmu,theta,seq(c[i],i=1..k)}: eq:={seq(log(L[i])-subs(n=i,gu),i=nops(L)-k-2..nops(L))}: var:=evalf(solve(eq,var)): C:=exp(subs(var,logC)): mu:=exp(subs(var,logmu)): theta:=subs(var,theta): C:=evalf(C,10): mu:=evalf(mu,10): theta:=evalf(theta,10): ku:= exp(subs(var,add(c[i]*x^i,i=1..k))): ku:=taylor(ku,x=0,k+1): ku:=add(evalf(coeff(ku,x,i),10)/n^i,i=0..k): evalf(C*mu^n*n^theta*ku,10): end: #MyAsyM(L,mu,n,k): tries to fit the sequence L to be of the form C*mu^n*n^theta*(1+c1/n+...+ck/n^k), where mu is given. Try: #gu:=Cap([2,3],200): MyAsyM(gu,n,3); MyAsyM:=proc(L,mu,n,k) local gu,logC,logmu,theta,c,i,eq,var,C,x,ku: if nops(L)<20 then print(`List must be at least of length 20`): RETURN(FAIL): fi: if 10+k>nops(L) then print(`k must be at most`, nops(L)-10 ): fi: logmu:=evalf(log(mu)): gu:=logC+logmu*n+theta*log(n)+add(c[i]/n^i,i=1..k): var:={logC,theta,seq(c[i],i=1..k)}: eq:={seq(log(L[i])-subs(n=i,gu),i=nops(L)-k-1..nops(L))}: var:=evalf(solve(eq,var)): C:=exp(subs(var,logC)): theta:=subs(var,theta): C:=evalf(C,10): theta:=evalf(theta,10): ku:= exp(subs(var,add(c[i]*x^i,i=1..k))): ku:=taylor(ku,x=0,k+1): ku:=add(evalf(coeff(ku,x,i),10)/n^i,i=0..k): evalf(theta,10),evalf(C,10)*mu^n*n^evalf(theta,10)*evalf(ku,10): end: sn:=proc(resh,n1): -1/log(op(n1+1,resh)*op(n1-1,resh)/op(n1,resh)^2): end: #Zinn(resh): Zinn-Justin's method to estimate #the C,mu, and theta such that #resh[i] is appx. Const*mu^i*i^theta #For example, try: #Zinn([seq(5*i*2^i,i=1..30)]); Zinn:=proc(resh) local s1,s2,theta,mu,n1,i: if nops({seq(sign(resh[i]),i=1..nops(resh))})<>1 then RETURN(FAIL): fi: n1:=nops(resh)-1: s1:=sn(resh,n1): s2:=sn(resh,n1-1): theta:=evalf(2*(s1+s2)/(s1-s2)^2): mu:=evalf(sqrt(op(n1+1,resh)/op(n1-1,resh))*exp(-(s1+s2)/((s1-s2)*s1))): evalf([theta,mu],10): end: #DiffRS:=proc(f,X,x,z,R,S): inpute a function f(X,x,z), and non-negative integers R and S, outputs (xd/d)^R(zd/dz)^S f(X,x,z)|{x=1,z=1}. Try: #DiffRS(GGF(X,x,z),X,x,z,1,1); DiffRS:=proc(f,X,x,z,R,S) local g,r,s: g:=f: for r from 1 to R do g:=normal(simplify(x*diff(g,x))): od: for s from 1 to S do g:=normal(simplify(z*diff(g,z))): od: g:=normal(simplify(subs({x=1,z=1},g))): end: #SeqRS(f,X,x,z,R,S,N): The first N terms stating at n=1 of the Maclaurin coefficients of DiffRS(r,X,x,z,R,S). Try: #SeqRS(GGF(X,x,z),X,x,z,1,1,20); SeqRS:=proc(f,X,x,z,R,S,N) local g,i: g:=DiffRS(f,X,x,z,R,S): g:=taylor(g,X=0,N+10): [seq(coeff(g,X,i),i=1..N)]: end: #SeqMomRS(f,X,x,z,R,S,N): The (R-S) mixed moment of the r.v. given by f(X,x,z). Try: #SeqMomRS(GGF(X,x,z),X,x,z,1,1,20); SeqMomRS:=proc(f,X,x,z,R,S,N) local L0,L,i,gu: option remember: L0:=SeqRS(f,X,x,z,0,0,N): L:=SeqRS(f,X,x,z,R,S,N): gu:=[]: for i from 1 to N do if L0[i]=0 then gu:=[op(gu),1]: else gu:=[op(gu),L[i]/L0[i]]: fi: od: gu: end: #cSeqMomRS(f,X,x,z,R,S,N): The centalized mixed R-S moment of the r.v. given by the parameters x and z in the grand generating function f(X,x,z). Try: #cSeqMomRS(GGF(X,x,z),X,x,z,1,1,20); cSeqMomRS:=proc(f,X,x,z,R,S,N) local T,a,b,n,L,ka,mu1,mu2: for a from 0 to R do for b from 0 to S do T[a,b]:=SeqMomRS(f,X,x,z,a,b,N): od: od: L:=[]: for n from 1 to N do mu1:=T[1,0][n]: mu2:=T[0,1][n]: ka:=add(add(binomial(R,a)*binomial(S,b)*(-mu1)^a*(-mu2)^b*T[R-a,S-b][n],b=0..S),a=0..R): L:=[op(L),ka]: od: L: end: #RNAstN(N,n,r): The asympotitc in n of the counting sequence, followed by the #asympotics of the hairpins and basepairs of RNA secondary structures using N terms and order r asymptotics #Try: #RNAstN(200,n,4); RNAstN:=proc(N,n,r) local f,L00,ka,L10,L01,A00,A10,A01,X,x,z: Digits:=100: ka:=3/2+1/2*5^(1/2): f:=GGF(X,x,z): L00:=SeqRS(f,X,x,z,0,0,N): L10:=SeqRS(f,X,x,z,1,0,N): L01:=SeqRS(f,X,x,z,0,1,N): A00:=MyAsyM(L00,ka,n,r)[2]: A10:=MyAsyM(L10,ka,n,r)[2]: A01:=MyAsyM(L01,ka,n,r)[2]: evalf([A00, asympt(A10/A00,n,4), asympt(A01/A00,n,4)],10): end: #GenStN(f,X,x,z, N,n,r): inputs the grand-generating function f in X,x,z, where, for some combinatorial family, #equipped with two discrete variables, R_1(n), R_2(n), the coeff. of #X^n*x^i*z^j is the number of objects,s, of size n with R_1(s)=i and R_2(s)=j #The asympotitc in n of the counting sequence, followed by the #asympotics of the R_1(n) and R_2(N) using N terms and order r asymptotics #Try: #GenStN(GGF(X,x,z),200,n,4); GenStN:=proc(f,X,x,z,N,n,r) local L00,ka,L10,L01,A00,A10,A01: Digits:=100: L00:=SeqRS(f,X,x,z,0,0,N): L10:=SeqRS(f,X,x,z,1,0,N): L01:=SeqRS(f,X,x,z,0,1,N): A00:=MyAsy(L00,n,2): ka:=op(1,op(2,A00)): if not type(ka, numeric) then RETURN(FAIL): fi: A10:=MyAsyM(L10,ka,n,r)[2]: A01:=MyAsyM(L01,ka,n,r)[2]: evalf([A00, asympt(A10/A00,n,4), asympt(A01/A00,n,4)],10): end: #ScSeqMomRS(f,X,x,z,R,S,N): The Scaled centalized mixed R-S moment of the r.v. given by the parameters x and z in the grand generating function f(X,x,z). Try: #ScSeqMomRS(GGF(X,x,z),X,x,z,1,1,20); ScSeqMomRS:=proc(f,X,x,z,R,S,N) local gu,L20,L02,i,L: gu:=cSeqMomRS(f,X,x,z,R,S,N): L20:=cSeqMomRS(f,X,x,z,2,0,N): L02:=cSeqMomRS(f,X,x,z,0,2,N): L:=[]: for i from 1 to N do if L20[i]=0 or L02[i]=0 then L:=[op(L),1]: else L:=[op(L),gu[i]/L20[i]^(R/2)/L02[i]^(S/2)]: fi: od: evalf(L): end: NormRS1:=proc(c,R,S) local f,x,y: assume(c>0 and c<1): f:=exp(-x^2/2-y^2/2+c*x*y)/2/Pi*sqrt(1-c^2): normal(int(int(x^R*y^S*f,x=-infinity..infinity),y=-infinity..infinity)): end: #NormRS(c,R,S): The scaled moments of the bi-varirate normal with correlation c. Try: #NormRS(c,2,2); NormRS:=proc(c,R,S): assume(c>0 and c<1): normal(NormRS1(c,R,S)*(1-c^2)^((R+S)/2)): end: #MyAsy1(L,n,k): inputs a sequence that is believed to have an asympotic expansion finds the best a[0]+a[1]/n+...+a[k]/n^k that fits it. Try: #MyAsy1([seq(0.1+0.2/i+0.3/i^2,i=1..200)],n,2); MyAsy1:=proc(L,n,k) local eq, var,a,k1,f,i: var:={seq(a[k1],k1=0..k)}: f:=add(a[k1]/n^k1,k1=0..k): eq:={seq(subs(n=i,f)-evalf(L[i]),i=nops(L)-k..nops(L))}: subs(solve(eq,var),f): end: #RNAstory(M): Using numerics, estimates the asymptotics of the expectations, variances, of the number of hairpins and Basepairs in RNA secondary structures #and it takes it up to the (M,M) mixed moment. Try: #RNAstory(M) RNAstory:=proc(M) local f,X,x,z,f1,a,n,i,j,gu,L,A,c,A1: gu:=RNAstN(400,n,4): print(`The Asymptotics of the Statistics of the Numbers of Hairpins and Basepairs in RNA Secondary Structures, using Numerics, Derived from the Exact Generating Function `): print(``): print(`By Shalosh B. Ekhad `): print(``): f:=GGF(X,x,z): f1:=subs({x=1,z=1},f): print(`The following theorem is due to Waterman (Adv. Math. Supp. Studies 1 (1978), 167-212`): print(``): print(`Theorem 1 (Waterman): Let a(n) be the number of Secondary Structures on {1, ...,n} , then `): print(``): print(Sum(a(n)*X^n,n=0..infinity)= f1): print(``): print(`and in Maple notation`): print(``): lprint(Sum(a(n)*X^n,n=0..infinity)= f1): print(``): print(`It follows that a(n) is asympotically given (using numerics) by `): print(``): print(gu[1]): print(``): print(`and in Maple notation `): print(``): lprint(gu[1]): print(``): print(`Let A(n,i,j) be the number of RNA secondary-structures with exactly i hairpins and j basepairs, then we have the following more refined theorem `): print(``): print(`Theorem 2 (AJ Bu)`): print(``): print(Sum(Sum(Sum(A(n,i,j)*X^n*x^i*z^j,i=0..n),j=0..n),n=0..infinity)= f): print(``): print(`and in Maple notation`): print(``): print(``): lprint(Sum(Sum(Sum(A(n,i,j)*X^n*x^i*z^j,i=0..n),j=0..n),n=0..infinity)= f): print(``): print(`Using numerics we have the following theorem`): print(``): print(`Theorem 3 :Let H[n] and B[n] be the random variables "number of hairpins" and "number of basepairs", respectively, then`): print(``): print(`The Expectation of H[n], E[H[n]] is given asympotically by `): print(``): print(gu[2]): print(``): print(` and in Maple notation `): print(``): lprint(gu[2]): print(``): print(`The Expectation of B[n], E[B[n]] is given asympotically by `): print(``): print(gu[3]): print(``): print(` and in Maple notation `): print(``): lprint(gu[3]): print(``): L:=cSeqMomRS(f,X,x,z,2,0,400): L:=[seq(L[i]/i,i=1..nops(L))]: A:=MyAsy1(L,n,1): print(``): print(`The variance of H[n], Var(H[n]) is asymptotically, numerically`): print(``): print(n*A): print(``): print(`and in Maple notation`): print(``): lprint(n*A): print(``): L:=cSeqMomRS(f,X,x,z,0,2,400): L:=[seq(L[i]/i,i=1..nops(L))]: A:=MyAsy1(L,n,1): print(``): print(`The variance of B[n], Var(B[n]) is asymptotically, numerically`): print(``): print(n*A): print(``): print(`and in Maple notation`): print(``): lprint(n*A): print(``): L:=ScSeqMomRS(f,X,x,z,1,1,400): A:=MyAsy1(L,n,1): print(``): print(`The Correlation of H[n] and B[n], Corr(H[n],B[n]) is asymptotically `): print(``): print(A): print(``): print(`and in Maple notation `): print(``): lprint(A): print(``): c:=coeff(A,n,0): print(`We claim that the scaled-centralized joint distribution tends, as n goes to infinity, to the joint normal distribution of H[infinity] and B[infinity] with correlation coefficient that approximately equals`, c): print(``): print(`Let's confirm this numerically up to the `, (M,M), `scaled-central mixed moments (i,j) for i+j evem `): for i from 1 to M do for j from 1 to M do if i+j mod 2=0 and i+j>2 then print(``): print(` The `, (i,j), `central-scaled moment of H[n] and B[n] converges, numerically and asympotitically to`): print(``): L:=ScSeqMomRS(f,X,x,z,i,j,400): A:=coeff(MyAsy1(L,n,1),n,0): print(``): print(A): print(``): A1:=NormRS(c,i,j): print(``): print(`while the `, (i,j), `scaled-moment of the normal distribution with the above correlation coefficient is`): print(``): print(A1): print(``): fi: od: od: print(`-------------------`): print(``): end: #Story(f,X,x,z,M): Using numerics, estimates the asymptotics of the expectations, variances, of a pair of discrete random vairables, let's call them X1 and X2 #defined on combinatorial objects #and it takes it up to the (M,M) mixed moment. Try: #Story(GGF(X,x,z), X,x,z,M) Story:=proc(f,X,x,z,M) local f1,a,n,i,j,gu,L,A,c,A1: gu:=GenStN(f,X,x,z,400,n,4): print(`The Asymptotics of the Statistics of two Discrete Random Variables defined on Algebraic Combinatorial Objects whose Grand Generating Function is`): print(``): print(f): print(``): print(`By Shalosh B. Ekhad `): print(``): f1:=subs({x=1,z=1},f): print(`We have two random variables, let's call then R_1, R_2, defined on an infinite family A(n) of combinatorial sets such that the number of`): print(`of these objects s of size n, and with R_1(s)=i and R_2(s)=j, is the coefficient of X^n*x^i*z^j in the Maclaurin expansion of (with respect to x)`): print(``): print(f): print(``): print(`and in Maple notation`): print(``): lprint(f): print(``): print(` Theorem 1: Let a(n) be the number of these objects of size n, then `): print(``): print(Sum(a(n)*X^n,n=0..infinity)= f1): print(``): print(`and in Maple notation`): print(``): lprint(Sum(a(n)*X^n,n=0..infinity)= f1): print(``): print(`It follows that a(n) is asympotically given (using numerics) by `): print(``): print(gu[1]): print(``): print(`and in Maple notation `): print(``): lprint(gu[1]): print(``): print(`Using numerics we have the following theorem`): print(``): print(`Theorem 2 :`): print(``): print(`The Expectation of R_1(n), E[R_1(n)] is given asympotically by `): print(``): print(gu[2]): print(``): print(` and in Maple notation `): print(``): lprint(gu[2]): print(``): print(`The Expectation of R_2(n), E[R_2(n)] is given asympotically by `): print(``): print(gu[3]): print(``): print(` and in Maple notation `): print(``): lprint(gu[3]): print(``): L:=cSeqMomRS(f,X,x,z,2,0,400): L:=[seq(L[i]/i,i=1..nops(L))]: A:=MyAsy1(L,n,1): print(``): print(`The variance of R_1(n), Var(R_1(n)) is asymptotically, numerically`): print(``): print(n*A): print(``): print(`and in Maple notation`): print(``): lprint(n*A): print(``): L:=cSeqMomRS(f,X,x,z,0,2,400): L:=[seq(L[i]/i,i=1..nops(L))]: A:=MyAsy1(L,n,1): print(``): print(`The variance of R_2(n), Var(R_2(n)) is asymptotically, numerically`): print(``): print(n*A): print(``): print(`and in Maple notation`): print(``): lprint(n*A): print(``): L:=ScSeqMomRS(f,X,x,z,1,1,400): A:=MyAsy1(L,n,1): print(``): print(`The Correlation of R_1(n) and R_2(n), Corr(R_1(n),R_2(n)) is asymptotically `): print(``): print(A): print(``): print(`and in Maple notation `): print(``): lprint(A): print(``): c:=coeff(A,n,0): print(`c is`, c): print(`We claim that the scaled-centralized joint distribution tends, as n goes to infinity, to the joint normal distribution of R_1(infinity and R_2(infinity) with correlation coefficient that approximately equals`, c): print(``): print(`Let's confirm this numerically up to the `, (M,M), `scaled-central mixed moments (i,j) for i+j even `): for i from 1 to M do for j from 1 to M do if i+j mod 2=0 and i+j>2 then print(``): print(` The `, (i,j), `central-scaled moment of R_1(n) and R_2(n) converges, numerically and asymptotically to`): print(``): L:=ScSeqMomRS(f,X,x,z,i,j,400): A:=coeff(MyAsy1(L,n,1),n,0): print(``): print(A): print(``): if (c>0 and c<1) then A1:=NormRS(c,i,j): print(``): print(`while the `, (i,j), `scaled-moment of the normal distribution with the above correlation coefficient is`): print(``): print(A1): print(``): fi: fi: od: od: print(`-------------------`): print(``): end: ### start single r.v #DiffR(f,X,x,R): inpute a function f(X,x), and a non-negative integer R, outputs (xd/d)^R f(X,x,z)|x=1. Try: #DiffR(-1/2*(h*x+(h^2*x^2-2*h*x-4*x^2+1)^(1/2)-1)/x^2,x,h,4); DiffR:=proc(f,X,x,R) local g,r: g:=f: for r from 1 to R do g:=normal(simplify(x*diff(g,x))): od: g:=normal(simplify(subs({x=1},g))): end: #SeqR(f,X,x,R,N): The first N terms stating at n=1 of the Maclaurin coefficients of DiffR(f,X,x,R). Try: #SeqR(-1/2*(h*x+(h^2*x^2-2*h*x-4*x^2+1)^(1/2)-1)/x^2,x,h,4,20); SeqR:=proc(f,X,x,R,N) local g,i: g:=DiffR(f,X,x,R): g:=taylor(g,X=0,N+10): [seq(coeff(g,X,i),i=1..N)]: end: #SeqMomR(f,X,x,R,N): first N terms of The R-th moment of the r.v. given by f(X,x). Try: #SeqMomR(-1/2*(h*x+(h^2*x^2-2*h*x-4*x^2+1)^(1/2)-1)/x^2,x,h,4,20); SeqMomR:=proc(f,X,x,R,N) local L0,L,i,gu: option remember: L0:=SeqR(f,X,x,0,N): L:=SeqR(f,X,x,R,N): gu:=[]: for i from 1 to N do if L0[i]=0 then gu:=[op(gu),1]: else gu:=[op(gu),L[i]/L0[i]]: fi: od: gu: end: #cSeqMomR(f,X,x,z,R,S,N): The centalized R-th moment of the r.v. given by the parameters x in the generating function f(X,x). Try: #cSeqMomR(-1/2*(h*x+(h^2*x^2-2*h*x-4*x^2+1)^(1/2)-1)/x^2,x,h,4,20); cSeqMomR:=proc(f,X,x,R,N) local T,a,n,L,ka,mu1: for a from 0 to R do T[a]:=SeqMomR(f,X,x,a,N): od: L:=[]: for n from 1 to N do mu1:=T[1][n]: ka:=add(binomial(R,a)*(-mu1)^a*T[R-a][n] ,a=0..R): L:=[op(L),ka]: od: L: end: #ScSeqMomR(f,X,x,R,N): The Scaled centalized Rmoment of the r.v. given by the parameter x in the grand generating function f(X,x). Try: #ScSeqMomR(-1/2*(h*x+(h^2*x^2-2*h*x-4*x^2+1)^(1/2)-1)/x^2,x,h,4,20); ScSeqMomR:=proc(f,X,x,R,N) local gu,L2,i,L: gu:=cSeqMomR(f,X,x,R,N): L2:=cSeqMomR(f,X,x,2,N): L:=[]: for i from 1 to N do if L2[i]=0 then L:=[op(L),1]: else L:=[op(L),gu[i]/L2[i]^(R/2)]: fi: od: evalf(L): end: #GenStSingle(f,X,x,N,n,r): inputs the grand-generating function f in X,x, where, for some combinatorial family, #equipped with a discrete variable, R_1(n) the coeff. of #X^n*x^i is the number of objects, s, of size n with R_1(s)=i #The asympotitc in n of the counting sequence, followed by the #asympotics of R_1(n) using N terms and order r asymptotics #Try: #GenStSingle(-1/2*(h*x+(h^2*x^2-2*h*x-4*x^2+1)^(1/2)-1)/x^2,x,h,20,n,r); GenStSingle:=proc(f,X,x,N,n,r) local L0,ka,L1,A0,A1: Digits:=100: L0:=SeqR(f,X,x,0,N): L1:=SeqR(f,X,x,1,N): A0:=MyAsy(L0,n,2): ka:=op(1,op(2,A0)): if not type(ka, numeric) then RETURN(FAIL): fi: A1:=MyAsyM(L1,ka,n,r)[2]: evalf([A0, asympt(A1/A0,n,4)],10): end: #StorySingle(f,X,x,M): Using numerics, estimates the asymptotics of the expectations, variances, of a discrete random vairable, let's call it X1 #defined on combinatorial objects #and it takes it up to the N-th moment. Try: #StorySingle(GGF(X,x,1), X,x,M) StorySingle:=proc(f,X,x,M) local f1,a,n,i,gu,L,A: gu:=GenStSingle(f,X,x,400,n,M): print(`The Asymptotics of the Statistics of a Discrete Random Variable defined on Algebraic Combinatorial Objects whose Grand Generating Function is`): print(``): print(f): print(``): print(`By Shalosh B. Ekhad `): print(``): f1:=subs({x=1},f): print(`We have a random variable, let's call it R_1, defined on an infinite family A(n) of combinatorial sets such that the number of`): print(`of these objects s of size n, and with R_1(s)=i is the coefficient of X^n*x^i in the Maclaurin expansion of (with respect to x)`): print(``): print(f): print(``): print(`and in Maple notation`): print(``): lprint(f): print(``): print(` Theorem 1: Let a(n) be the number of these objects of size n, then `): print(``): print(Sum(a(n)*X^n,n=0..infinity)= f1): print(``): print(`and in Maple notation`): print(``): lprint(Sum(a(n)*X^n,n=0..infinity)= f1): print(``): print(`It follows that a(n) is asympotically given (using numerics) by `): print(``): print(gu[1]): print(``): print(`and in Maple notation `): print(``): lprint(gu[1]): print(``): print(`Using numerics we have the following theorem`): print(``): print(`Theorem 2 :`): print(``): print(`The Expectation of R_1(n), E[R_1(n)] is given asympotically by `): print(``): print(gu[2]): print(``): print(` and in Maple notation `): print(``): lprint(gu[2]): L:=cSeqMomR(f,X,x,2,400): L:=[seq(L[i]/i,i=1..nops(L))]: A:=MyAsy1(L,n,1): print(``): print(`The variance of R_1(n), Var(R_1(n)) is asymptotically, numerically`): print(``): print(n*A): print(``): print(`and in Maple notation`): print(``): lprint(n*A): print(``): print(`We claim that the scaled-centralized joint distribution tends, as n goes to infinity, is asymtotically normal`): print(``): print(`Let's confirm this numerically up to the `, M, `scaled-central mixed moment `): for i from 3 to M do print(``): print(` The `, i, ` -th scaled moment of R_1(n) converges, numerically and asympotitically to`): print(``): L:=ScSeqMomR(f,X,x,i,400): A:=coeff(MyAsy1(L,n,1),n,0): print(``): print(A): print(``): od: print(`-------------------`): print(``): end: ###end Single variable