#May 1, 2014, C27.txt, more gambler's ruin Help:=proc(): print(` PGFam(N,p,t), Moms(N,p,R) `): print(`Momsi(N,R,i) , MomsiN(N,R,i) , AStmomsiN(R,x)`): end: ###old stuff #C26.txt, Gambler's ruin, April 28, 2014 Help26:=proc(): print(`Die1(p), GR(i,N,p), ExpD(N,p)`): print(`ExpDf(N,p) , PGF(N,p,t), PGFf(N,p,t), GuessP(L,x) `): end: #Die1: inputs p rational between 0 and 1 #and outputs 1 with prob. p and 0 with prob. 1-p Die1:=proc(p) local a,b,ra: a:=numer(p): b:=denom(p): ra:=rand(1..b)(): if ra<=a then 1: else -1: fi: end: #GR(i,N,p): simulates a gambler's ruin session #staring with i dollars, ending with 0 or N dollars #and with prob. of winning a dollar =p GR:=proc(i,N,p) local x,j: x:=i: for j from 0 while (x>0 and xFAIL then RETURN(gu): fi: od: FAIL: end: #end Added after class #end of old stuff #PGFam(N,p,t): the list of pgf for duration of #a gambler's ruin game with exit capital N #about the mean PGFam:=proc(N,p,t) local Li, Liav: Li:=PGFf(N,p,t): Liav:=subs(t=1,diff(Li,t)): [seq(Li[i]/t^Liav[i],i=1..nops(Li))]: end: #Moms(N,p,R): the list of length N-1 whose #ith item is the R-th moment Moms:=proc(N,p,R) local t,Li,i1: Li:=PGFam(N,p,t): for i1 from 1 to R do Li:=expand(t*diff(Li,t)): od: subs(t=1,Li): end: #Momsi(N,R,i): The explicit polynomial expression in #the symbol i for the R-th moment of the r.v. #remainign duration of the FAIR game Momsi:=proc(N,R,i) : GuessP(Moms(N,1/2,R),i): end: #MomsiN(N,R,i): a guessed polynomial in symbolic i and N #for the R-th moment of the r.v. "duration of a game #staring at i dollars and ending at either 0 or N, with #a FAIR coin MomsiN:=proc(N,R,i) local N1: option remember: expand(subs(N=N-19,GuessP([seq(Momsi(N1,R,i),N1=20..30+3*R)],N))): end: #AStmomsiN(R,x): Asympotic standarized R-th moment #if you start with x*N dollars to order k AStmomsiN:=proc(R,x) local N,f,i,y: f:=MomsiN(N,R,i)/MomsiN(N,2,i)^(R/2): f:=subs(i=x*N,f): if R mod 2=0 then f:=normal(subs(N=1/y,f)): coeff(taylor(f,y=0,7),y,0): else f:=simplify(normal(subs(N=1/y,f))^2): coeff(taylor(f,y=0,7),y,0)^(1/2): fi: end: