Help:=proc() print(`Emnp(m,n,p)`): print(`Emp(m,p), P(m1,n1,m2,n3,p)`): end: Emp:=proc(m,p): if m=0 then 0: else (p*Emp(m-1,p)+1)/p: fi: end: #Emnp(m,n,p): The expected number of #(loaded)coin tosses needed in a Knock `m Down #game with m pennies in the H side #n tokens in the T side, and Prob(H)=p #if the coin is H (T): remove a penny from the H #(T) side (if possible) Emnp:=proc(m::nonnegint,n::nonnegint,p) option remember: if m>0 and n>0 then p*Emnp(m-1,n,p) +(1-p)* Emnp(m,n-1,p)+1: elif m>0 and n=0 then Emp(m,p): elif m=0 and n>0 then Emp(n,1-p): elif m=0 and n=0 then 0: else ERROR(`Something is wrong`): fi: end: P:=proc(m1,n1,m2,n2,p): if m1=0 and n1=0 and m2=0 and n2=0 then 1/2: elif m1=0 and n1=0 then 1: elif m2=0 and n2=0 then 0: elif m1>0 and n1>0 and m2>0 and n2>0 then p*P(m1-1,n1,m2-1,n2,p) + (1-p)*P(m1,n1-1,m2,n2-1,p): elif m1=0 and m2=0 then if n1>n2 then 0: elif n1=n2 then 1/2: else 1: fi: elif n1=0 and n2=0 then if m1>m2 then 0: elif m1=m2 then 1/2: else 1: fi: else p*P(max(m1-1,0),n1,max(m2-1,0),n2,p) + (1-p)*P(m1,max(n1-1,0),m2,max(n2-1,0),p): fi: end: