gimel:=proc(): lprint(` x `): lprint(` x `): lprint(` x `): lprint(` x `): lprint(` x `): lprint(` x `): lprint(` xxxxxxxxxxxxxxxxxxx`): lprint(` x ggggg x`): lprint(` x g x`): lprint(` x g x`): lprint(` x gg x`): lprint(` x g g x`): lprint(` x x`): lprint(` x x`): lprint(` x`): end: heh:=proc(): lprint(` x `): lprint(` x `): lprint(` x `): lprint(` x `): lprint(` x `): lprint(` x `): lprint(` xxxxxxxxxxxxxxxxxxx`): lprint(` x hhhhh x`): lprint(` x h x`): lprint(` x h h x`): lprint(` x h h x`): lprint(` x x`): lprint(` x x`): lprint(` x x`): lprint(` x`): end: nun:=proc(): lprint(` x `): lprint(` x `): lprint(` x `): lprint(` x `): lprint(` x `): lprint(` x `): lprint(` xxxxxxxxxxxxxxxxxxx`): lprint(` x nnn x`): lprint(` x n x`): lprint(` x n x`): lprint(` x n x`): lprint(` x nnn x`): lprint(` x x`): lprint(` x x`): lprint(` x`): end: shin:=proc(): lprint(` x `): lprint(` x `): lprint(` x `): lprint(` x `): lprint(` x `): lprint(` x `): lprint(` xxxxxxxxxxxxxxxxxxx`): lprint(` x x`): lprint(` x s s s x`): lprint(` x s s s x`): lprint(` x sssssss x`): lprint(` x x`): lprint(` x x`): lprint(` x x`): lprint(` x`): end: print(`Nes Gadol Haya Sham`): lprint(``): lprint(``): nun(); lprint(``): lprint(``): gimel(); lprint(``):lprint(``): heh(); lprint(``):lprint(``): shin(); lprint(``):lprint(``): print(` Version of Kislev 24, 5756`): print(`This is DREIDEL, A Maple package that plays the dreidel (with any`): print(`number of players), and computes the probability of winning,`): print(` and expected duration, at any given state(so far with two players).`): print(`Written by: Doron Zeilberger (zeilberg@math.temple.edu)`): print(`The most current version of DREIDEL is always available by anon. ftp`): print(` to ftp.math.temple.edu directory pub/zeilberg/programs`): print(`or on WWW: http://www.math.temple.edu/~zeilberg`): print(`For general help, and a list of the available functions,`): print(` type "ezra();". For specific help type "ezra(procedure_name)" `): lprint(``): ezra:=proc() if args=NULL then print(`DREIDEL`): print(`Written by Doron Zeilberger: zeilberg@math.temple.edu`): print(`A Maple package that plays the dreidel and computes probabilities`): print(`For help with a specific procedure, type "ezra(procedure_name);"`): print(`Contains procedures: `): print(`dreidel,prob,pr1,pr2,fpr1,fpr2,LENGTH,LENGTH1,LENGTH2,Sevi,fSevi`): print(`ProbLasting,fProbLasting,ProbFirstWinBy,fProbFirstWinBy`): print(`ProbSecondWinBy,fProbSecondWinBy,Lengthn`): elif nops([args])=1 and op(1,[args])=`Lengthn` then print(`Lengthn(NUTS,n):the expected duration of a 2-person dreidel game`): print(`that starts out with two players each having M nuts, if it is`): print(`terminated after n spins. If n is large it appx. the expected`): print(`length LENGTH(NUTS), that may be slow to compute`): elif nops([args])=1 and op(1,[args])=`Sevi` then print(`Sevi(NUTS,NUMBER_OF_SPINS) gives the "Hanukkah polynomials"`): print(`and the two quitting polynomials of a 2-person dreidel game`): print(`that started out with each of the two players having NUTS nuts`): print(`The first component Sevi(NUTS,NUMBER_OF_SPINS)[1],`): print(`H_NUMBER_OF_SPINS(x,y,t), say, gives the g.f. for the probabilities of`): print(`all the outcomes after NUMBER_OF_SPINS spins, in the game. `): print(`more precisely, the coeff. of x^a*y^b*t^c is the probability`): print(`that after NUMBER_OF_SPINS spins, the first player has a nuts`): print(`the second player has b nuts, and the pot has c nuts`): elif nops([args])=1 and op(1,[args])=`ProbLasting` then print(`fProbLasting(NUTS,SPINS): the prob. of a 2-person dreidel`): print(`game that started out with each player having NUTS nuts`): print(`is still going on after SPINS number of spins`): elif nops([args])=1 and op(1,[args])=`ProbFirstWinBy` then print(`ProbFirstWinBy(M,n): the probability of the First player,`): print(`in a 2-player dreidel game that started out with M nuts ,winning`): print(`by the n-th spin`): elif nops([args])=1 and op(1,[args])=`ProbSecondWinBy` then print(`ProbSecondWinBy(M,n): the probability of the Second player,`): print(`in a 2-player dreidel game that started out with M nuts ,winning`): print(`by the n-th spin`): elif nops([args])=1 and op(1,[args])=`fProbLasting` then print(`fProbLasting(NUTS,SPINS): the prob., in float, of a 2-person dreidel`): print(`game that started out with each player having NUTS nuts`): print(`is still going on after SPINS number of spins`): elif nops([args])=1 and op(1,[args])=`fSevi` then print(`fSevi(NUTS,NUMBER_OF_SPINS): exactly like Sevi, but with`): print(`floating point answers`): elif nops([args])=1 and op(1,[args])=`fProbFirstWinBy` then print(`ProbFirstWinBy(M,n): the probability, in float, of the First player,`): print(`in a 2-player dreidel game that started out with M nuts ,winning`): print(`by the n-th spin`): elif nops([args])=1 and op(1,[args])=`fProbSecondWinBy` then print(`ProbSecondWinBy(M,n): the probability, in float, of the Second player,`): print(`in a 2-player dreidel game that started out with M nuts ,winning`): print(`by the n-th spin`): elif nops([args])=1 and op(1,[args])=`dreidel` then print(`dreidel(NUTS, NAME1,NAME2, ...,NAMEk) simulates a k-person dreidel`): print(`game with players named NAME1, MANE2, ..., Namek`): print(`For example, a game in which the players are Hadas,Tamar,Celia,`): print(`Doron and Jane, in which each player starts out with 3 nuts would be`): print(`obtained by typing:`): print(`dreidel(3,Hadas,Tamar,Celia,Doron,Jane);`): elif nops([args])=1 and op(1,[args])=`prob` then print(`prob(NUTS) returns two lists of lists`): print(`describing probabilities in a 2-person dreidel game.`): print(`list1[a][b] is the probability of him or her winning if in the game`): print(`when they each started with NUTS nuts (i.e. the initially they each`): print(`had NUTS-1 nuts and the pot had 2 nuts), right now the first player `): print(`has a nuts, and the second player has b nuts, and it is the first`): print(`player's turn to spin. The second list describes the analogous `): print(`quantity when it is the second player's turn to move`): elif nops([args])=1 and op(1,[args])=`fprob` then print(`fprob(NUTS) : like prob(NUTS) but the output is in floating point`): elif nops([args])=1 and op(1,[args])=`pr1` then print(`pr1(a,b,NUTS) : In a 2-player dreidel match, that started with each`): print(`player having NUTS nuts, and right now it is the first player's turn`): print(`to spin and he has a nuts, while the second player has b nuts, then`): print(`pr1(a,b,NUTS) is the probability of the first player winning`): elif nops([args])=1 and op(1,[args])=`pr2` then print(`pr1(a,b,NUTS) : In a 2-player dreidel match, that started with each`): print(`player having NUTS nuts, and right now it is the second player's turn`): print(`to spin and he has b nuts, while the first player has a nuts, then`): print(`pr1(a,b,NUTS) is the probability of the FIRST player winning`): elif nops([args])=1 and op(1,[args])=`LENGTH` then print(`LENGTH(NUTS) : How long should a 2-player dreidel game, where each`): print(`player started with NUTS nuts, be expected to last`): elif nops([args])=1 and op(1,[args])=`LENGTH1` then print(`LENGTH1(a,b,NUTS) : In a 2-player dreidel game, where each`): print(`player started with NUTS nuts, and right now, the first player`): print(`is about to spin and`): print(`has a nuts and the second player has b nuts, the expected number`): print(`of spins until the end of the game`): elif nops([args])=1 and op(1,[args])=`LENGTH2` then print(`LENGTH1(a,b,NUTS) : In a 2-player dreidel game, where each`): print(`player started with NUTS nuts, and right now, the first player`): print(`just finished spinning and`): print(`has a nuts and the second player has b nuts, the expected number`): print(`of spins until the end of the game`): elif nops([args])=1 and op(1,[args])=`fpr1` then print(` fpr1(a,b,NUTS): like pr1(a,b,NUTS), but with floating point answers`): elif nops([args])=1 and op(1,[args])=`fpr2` then print(` fpr2(a,b,NUTS): like pr2(a,b,NUTS), but with floating point answers`): else ERROR(`There is no procedure in the DREIDEL package by the name of`, args): fi: end: spin:=proc() local dreid,ra,i; dreid:=[Gimel,Heh,Nun,Shin]: ra:=rand(1..4): i:=ra(): op(i,dreid): end: pr1:=proc(a,b,NUTS) local gu: if a<=0 or b<=0 or a+b+1>2*NUTS then ERROR(`a>0, b>0, a+b<=2*NUTS-1`): fi: gu:=prob(NUTS)[1]: op(b,op(a,gu)): end: pr2:=proc(a,b,NUTS) local gu: gu:=prob(NUTS)[2]: op(b,op(a,gu)): end: LENGTH:=proc(NUTS) local gu: LENGTH1(NUTS-1,NUTS-1,NUTS): end: LENGTH1:=proc(a,b,NUTS) local gu: if a<=0 or b<=0 or a+b+1>2*NUTS then ERROR(`a>0, b>0, a+b<=2*NUTS-1`): fi: gu:=fKAMAOD(NUTS)[1]: op(b,op(a,gu)): end: LENGTH2:=proc(a,b,NUTS) local gu: gu:=fKAMAOD(NUTS)[2]: op(b,op(a,gu)): end: fpr1:=proc(a,b,NUTS) local gu: if a<=0 or b<=0 or a+b+1>2*NUTS then ERROR(`a>0, b>0, a+b<=2*NUTS-1`): fi: gu:=fprob(NUTS)[1]: op(b,op(a,gu)): end: fpr2:=proc(a,b,NUTS) local gu: gu:=fprob(NUTS)[2]: op(b,op(a,gu)): end: prob:=proc(NUTS) local eq,var,a,b,pr1,pr2,POT,gu1,gu2,mu: option remember: var:={}: eq:={}: for b from 1 to 2*NUTS-1 do var:=var union {pr1[0,b]}: eq:=eq union {pr1[0,b]=0}: od: for a from 1 to 2*NUTS-1 do var:=var union {pr1[a,0]}: eq:=eq union {pr1[a,0]=1}: for b from 1 to 2*NUTS-a-1 do POT:=2*NUTS-a-b: var:=var union {pr1[a,b]}: eq:=eq union {pr1[a,b]= 1/4*( pr2[a+POT-1,b-1]+pr2[a+trunc(POT/2),b]+pr2[a,b]+pr2[a-1,b] ) }: od: od: for b from 1 to 2*NUTS-1 do var:=var union {pr2[0,b]}: eq:=eq union {pr2[0,b]=0}: od: for a from 1 to 2*NUTS-1 do var:=var union {pr2[a,0]}: eq:=eq union {pr2[a,0]=1}: for b from 1 to 2*NUTS-a-1 do POT:=2*NUTS-a-b: var:=var union {pr2[a,b]}: eq:=eq union {pr2[a,b]= 1/4*( pr1[a-1,b+POT-1]+pr1[a,b+trunc(POT/2)]+pr1[a,b]+pr1[a,b-1]) }: od: od: var:=solve(eq,var): gu1:=[]: for a from 1 to 2*NUTS-2 do mu:=[]: for b from 1 to 2*NUTS-1-a do mu:=[op(mu),subs(var,pr1[a,b])]: od: gu1:=[op(gu1),mu]: od: gu2:=[]: for a from 1 to 2*NUTS-2 do mu:=[]: for b from 1 to 2*NUTS-1-a do mu:=[op(mu),subs(var,pr2[a,b])]: od: gu2:=[op(gu2),mu]: od: gu1,gu2: end: KAMAOD:=proc(NUTS) local eq,var,a,b,pr1,pr2,POT,gu1,gu2,mu: option remember: var:={}: eq:={}: for b from 1 to 2*NUTS-1 do var:=var union {pr1[0,b]}: eq:=eq union {pr1[0,b]=0}: od: for a from 1 to 2*NUTS-1 do var:=var union {pr1[a,0]}: eq:=eq union {pr1[a,0]=0}: for b from 1 to 2*NUTS-a-1 do POT:=2*NUTS-a-b: var:=var union {pr1[a,b]}: eq:=eq union {pr1[a,b]= 1+1/4*( pr2[a+POT-1,b-1]+pr2[a+trunc(POT/2),b]+pr2[a,b]+pr2[a-1,b] ) }: od: od: for b from 1 to 2*NUTS-1 do var:=var union {pr2[0,b]}: eq:=eq union {pr2[0,b]=0}: od: for a from 1 to 2*NUTS-1 do var:=var union {pr2[a,0]}: eq:=eq union {pr2[a,0]=0}: for b from 1 to 2*NUTS-a-1 do POT:=2*NUTS-a-b: var:=var union {pr2[a,b]}: eq:=eq union {pr2[a,b]= 1+1/4*( pr1[a-1,b+POT-1]+pr1[a,b+trunc(POT/2)]+pr1[a,b]+pr1[a,b-1]) }: od: od: var:=solve(eq,var): gu1:=[]: for a from 1 to 2*NUTS-2 do mu:=[]: for b from 1 to 2*NUTS-1-a do mu:=[op(mu),subs(var,pr1[a,b])]: od: gu1:=[op(gu1),mu]: od: gu2:=[]: for a from 1 to 2*NUTS-2 do mu:=[]: for b from 1 to 2*NUTS-1-a do mu:=[op(mu),subs(var,pr2[a,b])]: od: gu2:=[op(gu2),mu]: od: gu1,gu2: end: fKAMAOD:=proc(NUTS) local eq,var,a,b,pr1,pr2,POT,gu1,gu2,mu: option remember: var:={}: eq:={}: for b from 1 to 2*NUTS-1 do var:=var union {pr1[0,b]}: eq:=eq union {pr1[0,b]=0}: od: for a from 1 to 2*NUTS-1 do var:=var union {pr1[a,0]}: eq:=eq union {pr1[a,0]=0}: for b from 1 to 2*NUTS-a-1 do POT:=2*NUTS-a-b: var:=var union {pr1[a,b]}: eq:=eq union {pr1[a,b]= 1+.25*( pr2[a+POT-1,b-1]+pr2[a+trunc(POT/2),b]+pr2[a,b]+pr2[a-1,b] ) }: od: od: for b from 1 to 2*NUTS-1 do var:=var union {pr2[0,b]}: eq:=eq union {pr2[0,b]=0}: od: for a from 1 to 2*NUTS-1 do var:=var union {pr2[a,0]}: eq:=eq union {pr2[a,0]=0}: for b from 1 to 2*NUTS-a-1 do POT:=2*NUTS-a-b: var:=var union {pr2[a,b]}: eq:=eq union {pr2[a,b]= 1+.25*( pr1[a-1,b+POT-1]+pr1[a,b+trunc(POT/2)]+pr1[a,b]+pr1[a,b-1]) }: od: od: var:=solve(eq,var): gu1:=[]: for a from 1 to 2*NUTS-2 do mu:=[]: for b from 1 to 2*NUTS-1-a do mu:=[op(mu),subs(var,pr1[a,b])]: od: gu1:=[op(gu1),mu]: od: gu2:=[]: for a from 1 to 2*NUTS-2 do mu:=[]: for b from 1 to 2*NUTS-1-a do mu:=[op(mu),subs(var,pr2[a,b])]: od: gu2:=[op(gu2),mu]: od: gu1,gu2: end: fprob:=proc(NUTS) local eq,var,a,b,pr1,pr2,POT,gu1,gu2,mu: option remember: var:={}: eq:={}: for b from 1 to 2*NUTS-1 do var:=var union {pr1[0,b]}: eq:=eq union {pr1[0,b]=0}: od: for a from 1 to 2*NUTS-1 do var:=var union {pr1[a,0]}: eq:=eq union {pr1[a,0]=1}: for b from 1 to 2*NUTS-a-1 do POT:=2*NUTS-a-b: var:=var union {pr1[a,b]}: eq:=eq union {pr1[a,b]= .25*( pr2[a+POT-1,b-1]+pr2[a+trunc(POT/2),b]+pr2[a,b]+pr2[a-1,b] ) }: od: od: for b from 1 to 2*NUTS-1 do var:=var union {pr2[0,b]}: eq:=eq union {pr2[0,b]=0}: od: for a from 1 to 2*NUTS-1 do var:=var union {pr2[a,0]}: eq:=eq union {pr2[a,0]=1}: for b from 1 to 2*NUTS-a-1 do POT:=2*NUTS-a-b: var:=var union {pr2[a,b]}: eq:=eq union {pr2[a,b]= .25*( pr1[a-1,b+POT-1]+pr1[a,b+trunc(POT/2)]+pr1[a,b]+pr1[a,b-1]) }: od: od: var:=solve(eq,var): gu1:=[]: for a from 1 to 2*NUTS-2 do mu:=[]: for b from 1 to 2*NUTS-1-a do mu:=[op(mu),subs(var,pr1[a,b])]: od: gu1:=[op(gu1),mu]: od: gu2:=[]: for a from 1 to 2*NUTS-2 do mu:=[]: for b from 1 to 2*NUTS-1-a do mu:=[op(mu),subs(var,pr2[a,b])]: od: gu2:=[op(gu2),mu]: od: gu1,gu2: end: m1:=proc(Listnuts,POT,Listnames,i) local P,oc,NAME,j,Listnuts1,Listnames1,i1,kaki; NAME:=op(i,Listnames): oc:=spin(); lprint(`It is the turn of `,NAME,`to spin the dreidel`): if oc=Gimel then gimel(): lprint(NAME,` You got Gimel`): Listnuts1:=[]: for j from 1 to i-1 do Listnuts1:=[op(Listnuts1),op(j,Listnuts)-1]: od: Listnuts1:=[op(Listnuts1),op(i,Listnuts)+POT-1]: for j from i+1 to nops(Listnames) do Listnuts1:=[op(Listnuts1),op(j,Listnuts)-1]: od: P:=nops(Listnuts); print(`The pot now has`,P,`nuts`): Listnames1:=[]: Listnuts2:=[]: for j from 1 to nops(Listnames) do if op(j,Listnuts1)>0 then Listnames1:=[op(Listnames1),op(j,Listnames)]: Listnuts2:=[op(Listnuts2),op(j,Listnuts1)]: lprint(op(j,Listnames),`you now have`,op(j,Listnuts1),`nuts`): else if op(j,Listnames)=NAME then if j=nops(Listnames) then i1:=1: else i1:=j: fi: kaki:=1: fi: lprint(`Sorry`, op(j,Listnames), `you have no nuts left, `): lprint(`you are out of the game`): fi: od: if nops(Listnames1)=1 then lprint(`Congratulations`,op(1,Listnames1),`You won!`): exit: fi: if kaki<>1 then for j from 1 to nops(Listnames1) do if op(j,Listnames1)=NAME then i1:=j mod nops(Listnames1)+1: break: fi: od: fi: RETURN(Listnuts2,P,Listnames1,i1) fi: if oc=Heh then heh(): lprint(NAME,` You got Heh`): Listnuts1:=[]: for j from 1 to i-1 do Listnuts1:=[op(Listnuts1),op(j,Listnuts)]: od: Listnuts1:=[op(Listnuts1),op(i,Listnuts)+trunc(POT/2)]: for j from i+1 to nops(Listnames) do Listnuts1:=[op(Listnuts1),op(j,Listnuts)]: od: P:=POT-trunc(POT/2); lprint(`The pot now has`,P,`nuts`): i1:=i mod nops(Listnames) +1: for j from 1 to nops(Listnames) do print(op(j,Listnames),`you now have`,op(j,Listnuts1),`nuts`): od: RETURN(Listnuts1,P,Listnames,i1) fi: if oc=Nun then nun(): lprint(NAME,` You got Nun`): i1:=i mod nops(Listnames)+1: lprint(`The pot now has`,POT,`nuts`): for j from 1 to nops(Listnames) do lprint(op(j,Listnames),`you now have`,op(j,Listnuts),`nuts`): od: RETURN(Listnuts,POT,Listnames,i1) fi: if oc=Shin then shin(): lprint(NAME,` You got Shin`): Listnuts1:=[]: for j from 1 to i-1 do Listnuts1:=[op(Listnuts1),op(j,Listnuts)]: od: Listnuts1:=[op(Listnuts1),op(i,Listnuts)-1]: for j from i+1 to nops(Listnames) do Listnuts1:=[op(Listnuts1),op(j,Listnuts)]: od: P:=POT+1; lprint(`The pot now has`,P,`nuts`): Listnames1:=[]: Listnuts2:=[]: for j from 1 to nops(Listnames) do if op(j,Listnuts1)>0 then Listnames1:=[op(Listnames1),op(j,Listnames)]: Listnuts2:=[op(Listnuts2),op(j,Listnuts1)]: lprint(op(j,Listnames),`you now have`,op(j,Listnuts1),`nuts`): else if op(j,Listnames)=NAME then if j=nops(Listnames) then i1:=1: else i1:=j: fi: kaki:=1: fi: lprint(`Sorry`, op(j,Listnames), `you have no nuts left, `): lprint(`you are out of the game`): fi: od: if nops(Listnames1)=1 then lprint(`Congratulations`,op(1,Listnames1),`You won!`): exit: fi: if kaki<>1 then for j from 1 to nops(Listnames1) do if op(j,Listnames1)=NAME then i1:=j mod nops(Listnames1)+1: break: fi: od: fi: RETURN(Listnuts2,P,Listnames1,i1) fi: end: dreidel:=proc() local NUTS,Listnuts,POT,Listnames,i: if nargs<3 then ERROR(`dreidel(Number_Of_Nuts,Name1,Name2,...`): fi: NUTS:=args[1]: if not (type(NUTS,integer) and NUTS>1) then ERROR(`The 1st argument of dreidel, the initial #nuts each player>=2`): fi: Listnames:=[]: Listnuts:=[]: for i from 1 to nargs-1 do Listnames:=[op(Listnames),args[i+1]]: Listnuts:=[op(Listnuts),NUTS-1]: od: POT:=nargs-1: gu:=Listnuts,POT,Listnames,1: sfor:=0: while nops(gu[1])>1 do sfor:=sfor+1: gu:=m1(gu): od: print(`the game took`, sfor, `spins`): end: SevFirst:=proc(f) local gu,p,lu,gu1,gu2: gu:=(1/4)*(subs(t=x,f)*t^2/x/y+ f+subs(f)*t/x): gu:=expand(gu): for p from 1 to degree(f,t) do lu:=coeff(f,t,p): gu:=gu+(1/4)*lu*x^(trunc(p/2))*t^(p-trunc(p/2)): od: gu:=expand(gu): gu1:=coeff(gu,y,0): gu2:=coeff(gu,x,0): gu:=gu-gu1-gu2 : expand(gu),expand(gu1),expand(gu2): end: SevSecond:=proc(f) local gu,p,lu,gu1,gu2: gu:=(1/4)*(subs(t=y,f)*t^2/x/y+ f+subs(f)*t/y): gu:=expand(gu): for p from 1 to degree(f,t) do lu:=coeff(f,t,p): gu:=gu+(1/4)*lu*y^(trunc(p/2))*t^(p-trunc(p/2)): od: gu:=expand(gu): gu1:=coeff(gu,y,0): gu2:=coeff(gu,x,0): gu:=gu-gu1-gu2 : expand(gu),expand(gu1),expand(gu2): end: Sevi:=proc(M,n) option remember: if not type(n,integer) or n<0 then ERROR(`the second argument, the number of spins, should be an integer >=0`): fi: if not type(M,integer) or M<0 then ERROR(`the first argument, the number of nuts, should be an integer >=2`): fi: if n=0 then x^(M-1)*y^(M-1)*t^2,0,0: elif n mod 2=1 then SevFirst(Sevi(M,n-1)[1]): else SevSecond(Sevi(M,n-1)[1]): fi: end: ProbLasting:=proc(M,n) local gu: gu:=Sevi(M,n)[1]: gu:=subs({t=1,x=1,y=1},gu): evalf(gu): end: Lengthn:=proc(M,n) local gu,i: gu:=1: for i from 1 to n do gu:=gu+ProbLasting(M,i): od: evalf(gu): end: ProbFirstWin:=proc(M,n) local gu: subs({x=1,t=1,y=1},Sevi(M,n)[2]): end: ProbSecondWin:=proc(M,n) local gu: subs({x=1,t=1,y=1},Sevi(M,n)[3]): end: ProbFirstWinBy:=proc(M,n) local i,gu: gu:=0: for i from 0 to n do gu:=gu+ProbFirstWin(M,i): od: gu: end: ProbSecondWinBy:=proc(M,n) local i,gu: gu:=0: for i from 0 to n do gu:=gu+ProbSecondWin(M,i): od: gu: end: fSevFirst:=proc(f) local gu,p,lu,gu1,gu2: gu:=(.25)*(subs(t=x,f)*t^2/x/y+ f+subs(f)*t/x): gu:=expand(gu): for p from 1 to degree(f,t) do lu:=coeff(f,t,p): gu:=gu+(.25)*lu*x^(trunc(p/2))*t^(p-trunc(p/2)): od: gu:=expand(gu): gu1:=coeff(gu,y,0): gu2:=coeff(gu,x,0): gu:=gu-gu1-gu2 : expand(gu),expand(gu1),expand(gu2): end: fSevSecond:=proc(f) local gu,p,lu,gu1,gu2: gu:=(.25)*(subs(t=y,f)*t^2/x/y+ f+subs(f)*t/y): gu:=expand(gu): for p from 1 to degree(f,t) do lu:=coeff(f,t,p): gu:=gu+(.25)*lu*y^(trunc(p/2))*t^(p-trunc(p/2)): od: gu:=expand(gu): gu1:=coeff(gu,y,0): gu2:=coeff(gu,x,0): gu:=gu-gu1-gu2 : expand(gu),expand(gu1),expand(gu2): end: fSevi:=proc(M,n) option remember: if not type(n,integer) or n<0 then ERROR(`the second argument, the number of spins, should be an integer >=0`): fi: if not type(M,integer) or M<0 then ERROR(`the first argument, the number of nuts, should be an integer >=2`): fi: if n=0 then x^(M-1)*y^(M-1)*t^2,0,0: elif n mod 2=1 then fSevFirst(fSevi(M,n-1)[1]): else fSevSecond(fSevi(M,n-1)[1]): fi: end: fProbLasting:=proc(M,n) local gu: gu:=fSevi(M,n)[1]: gu:=subs({t=1,x=1,y=1},gu): evalf(gu): end: fLengthn:=proc(M,n) local gu,i: gu:=1: for i from 1 to n do gu:=gu+fProbLasting(M,i): od: evalf(gu): end: fProbFirstWin:=proc(M,n) local gu: subs({x=1,t=1,y=1},fSevi(M,n)[2]): end: fProbSecondWin:=proc(M,n) local gu: subs({x=1,t=1,y=1},Sevi(M,n)[3]): end: fProbFirstWinBy:=proc(M,n) local i,gu: gu:=0: for i from 0 to n do gu:=gu+fProbFirstWin(M,i): od: gu: end: fProbSecondWinBy:=proc(M,n) local i,gu: gu:=0: for i from 0 to n do gu:=gu+fProbSecondWin(M,i): od: gu: end: