#c25.txt, April 23, 2015; More on the Shepp Urn Help:=proc(): print(` V(m,p) , Vf(m,p) , Bd(m,p) , B(m,p)`): print(` beta(p), betaSeq(N), Vx(m,p,x) `): end: #V(m,p): the expected final gain in a Shepp game #with m minus balls and p plus balls, you can quit any #time. You quit as soon as your expectation is <=0 V:=proc(m,p) option remember: if m=0 then RETURN(p): elif p=0 then RETURN(0): else max(0, m/(m+p)*(-1+ V(m-1,p)) + p/(m+p)*(1+ V(m,p-1)) ): fi: end: #Vf(m,p): Floating point version of V(m,p) #the expected final gain in a Shepp game #with m minus balls and p plus balls, you can quit any #time. You quit as soon as your expectation is <=0 Vf:=proc(m,p) option remember: if m=0 then RETURN(p): elif p=0 then RETURN(0): else max(0, evalf(m/(m+p)*(-1+ Vf(m-1,p)) + p/(m+p)*(1+ Vf(m,p-1))) ): fi: end: C:=proc(m,p) option remember: binomial(m+p,m): end: #Bd(m,p):=V(m,p)*C(m,p) Bd:=proc(m,p) V(m,p)*C(m,p): end: #B(m,p): V(m,p)*C(m,p) using the recurrence in Eq. (10) #in William M. Boyce's paper, Discrete Math v. 5 (1973), #297-312. B:=proc(m,p) option remember: if m=0 then RETURN(p): elif p=0 then RETURN(0): else max(0, C(m,p-1)-C(m-1,p)+ B(m-1,p)+B(m,p-1) ): fi: end: beta:=proc(p) local m: for m from p while V(m,p)>0 do od: m-1: end: #betaSeq(N): the first N terms of beta(p) betaSeq:=proc(N) local p: [seq(beta(p),p=1..N)]: end: #Vx(m,p,x): the pgf of the player's ultimate #results with m minus balls and p plus balls #the output is a Laurent polynomial #such that the coefficient of #x^i is the prob. that at the end you got i dollars Vx:=proc(m,p,x) option remember: if m=0 then RETURN(x^p): elif p=0 then RETURN(1): elif V(m,p)=0 then RETURN(1): else expand(m/(m+p)*(Vx(m-1,p,x)/x) + p/(m+p)*( x*Vx(m,p-1,x))): fi: end: