###################################################################### ##SuckerBets.txt: Save this file as SuckerBets.txt # ## To use it, stay in the # ##same directory, get into Maple (by typing: maple ) # ##and then type: read `SuckerBets.txt` # ##Then follow the instructions given there # ## # ##Written by Doron Zeilberger, Rutgers University , # #DoronZeil at gmail dot com # ###################################################################### #Created: print(`Created: Sept.-Oct. 2017`): print(` This is SuckerBets.txt `): print(`It is one of the Maple package that accompanies the article `): print(` A Treatise on Sucker's Bets`): print(`by Shalosh B. Ekhad and Doron Zeilberger`): print(`and also available from Zeilberger's website`): print(``): print(`Please report bugs to DoronZeil at gmail dot com `): print(``): print(`The most current version of this package and paper`): print(` are available from`): print(`http://www.math.rutgers.edu/~zeilberg/ .`): print(`---------------------------------------`): print(`For a list of the Supporting procedures type ezra1();, for help with`): print(`specific procedure, type ezra(procedure_name); .`): print(``): print(`---------------------------------------`): print(`---------------------------------------`): print(`For a list of the Story procedures type ezraS();, for help with`): print(`specific procedure, type ezra(procedure_name); .`): print(``): print(`---------------------------------------`): print(`---------------------------------------`): print(`For a list of the MAIN procedures type ezra();, for help with`): print(`a specific procedure, type ezra(procedure_name); .`): print(``): print(`---------------------------------------`): with(combinat): ezraS:=proc() if args=NULL then print(` The STORY procedures are: Efron1v, Efron1vC, Sefer `): print(``): else ezra(args): fi: end: ezra1:=proc() if args=NULL then print(` The supporting procedures are: AllKatan, AllKatanP, AllKatanU, DiffSc, Efron1, Efron1q, GrabPos, MtoW, PrBeat1, SetDecks, WtoD `): print(``): else ezra(args): fi: end: ezra:=proc() if args=NULL then print(`The main procedures are: PrBeat, EfronD, EfronP, EfronPs, F, GFq, GFqx, NuEfron, NuF `): print(` `): elif nops([args])=1 and op(1,[args])=AllKatan then print(`AllKatan(L): Given a list of integers L, outputs the set of lists of non-negative integers that are smaller than L. Try: `): print(`AllKatan([2,2,2]);`): elif nops([args])=1 and op(1,[args])=AllKatanP then print(`AllKatanP(L): Given a list of integers L, outputs the set of lists of non-negative integers that are smaller than L and are Pure Steps.`): print(`i.e. only change in one coordinate. `): print(` Try:`): print(`AllKatanP([2,2,2]);`): elif nops([args])=1 and op(1,[args])=AllKatanU then print(`AllKatanU(L): Given a list of integers L, outputs the set of lists of non-negative integers that are smaller than L and are Unit Steps. Try:`): print(`AllKatanU([2,2,2]);`): elif nops([args])=1 and op(1,[args])=DiffSc then print(`DiffSc(a1,s1): inputs a vector of non-negative integers a1, of length k, say, describing the current`): print(`sizes of k-decks of cards with denominations taken from {1, ..., m-1} say and s1 a vector of`): print(`length k such that the cards with denomination m is placed such that deck 1 gets s1[1] such cards,`): print(`deck 2 gets s1[2] such cards, ... deck gets s1[k] such cards.`): print(`Outputs a list of integers of length k whose :`): print(`first component is the difference between #12-#21, `): print(`second component is the difference between #23-#32, `): print(`....`): print(`k-th component is the difference between #k1-#1k. Try:`): print(`DiffSc([2,2,2],[1,1,1]); `): elif nops([args])=1 and op(1,[args])=EfronD then print(`EfronD(A): All the Efron sequences of decks where the deck (or die)-sizes are A[1], ..., A[k], using all different denominations`): print(`1...convert(A,`+`): `): dprint(`Try: `): print(` EfronD([3,3,3]); `): elif nops([args])=1 and op(1,[args])=EfronP then print(`EfronP(A,m): All the Efron sequences of decks where the deck (or die)-sizes are A[1], ..., A[k], using all denominations 1..m`): print(`Without overlap, i.e. there is never a tie.`): dprint(`Try: `): print(` EfronP([3,3,3],6); `): elif nops([args])=1 and op(1,[args])=EfronPs then print(`EfronPs(A): the Efron dice with number of faces (or cards in decks) given by the list A with the smallest possible`): print(`different denominations. It also outputs that number of denominations. Try:`): print(` EfronPs([3,3,3]); `): elif nops([args])=1 and op(1,[args])=Efron1 then print(`Efron1(A,m,c): All the Efron sequences of decks where the deck (or die)-sizes are A[1], ..., A[k], using denominations {1, ..,m}`): print(`where c is a parameter such that `): print(`when c=1 all the denominations are distinct numbers (and m equals the sum of the entries of A) and c=2 is not-necessarily distinct, but no overlaps. `): print(`if c=3 then there may be overlaps (but warning, it is very slow)`): print(`Here A[1] beats A[2], A[2] beats A[3], ..., A[k] beats by A[1]`): print(`Try:`): print(`Efron1([3,3,3],9,1);`): elif nops([args])=1 and op(1,[args])=Efron1q then print(`Efron1q(A,m,c,q): All the weights in terms of polynomial in q[1], ...,q[nops(A)]`): print(`where c=1 are distinct numbers and c=2 is not-necessarily distinct, but no overlaps. Try:`): print(`Efron1q([3,3,3],9,1,q);`): elif nops([args])=1 and op(1,[args])=Efron1v then print(`Efron1v(A,m,c): A verbose form of Efron1(A,m,c) (q.v.). Try:`): print(`Efron1v([3,3,3],9,1):`): elif nops([args])=1 and op(1,[args])=Efron1vC then print(`Efron1vC(A,m,N): like Efron1v(A,m,2) but as Chapter Number N. Try:`): print(`Efron1vC([3,3,3],9,2):`): elif nops([args])=1 and op(1,[args])=F then print(`F(A,B,m,c): the set of all walks with steps that are unit if c=1, pure if c=2 and general of c=3`): print(`of m steps from the origin to A with score-vector [#12-#21,#23-#32, ..., $k1-#1k] B. Try:`): print(`F([3,3,3],[1,1,1],9,1);`): elif nops([args])=1 and op(1,[args])=GFq then print(`GFq(A,qL,m,c): the Generating function according to qL[1]^(#12-#21)*..*qL[k]^(#k1-#1k) `): print(`of the set of m-step walks from the origin to A with score-vector `): print(`where c is a parameter such that `): print(`when c=1 all the denominations are distinct numbers (and m equals the sum of the entries of A) and c=2 is not-necessarily distinct, but no overlaps. `): print(`if c=3 then there may be overlaps (but warning, it is very slow). Try:`): print(`GFq([3,3,3],[q1,q2,q3],9,1);`): elif nops([args])=1 and op(1,[args])=GFqx then print(`GFqx(A,qL,m,c,x): the Generating function according to qL[1]^(#12-#21)*..*qL[k]^(#k1-#1k) *mul(x[StepNumber,Step])`): print(`of the set of m-step walks from the origin to A with score-vector `): print(`where c is a parameter such that `): print(`when c=1 all the denominations are distinct numbers (and m equals the sum of the entries of A) and c=2 is not-necessarily distinct, but no overlaps. `): print(`if c=3 then there may be overlaps (but warning, it is very slow). Try:`): print(`GFqx([3,3,3],[q1,q2,q3],9,1,x);`): elif nops([args])=1 and op(1,[args])=GrabPos then print(`GrabPos(P,q): Given a Laruent polynomial P in the list of variables q, extracts the part whose exponets are all positive. Try: `): print(`GrabPos(5*x*y+4/x/y,[x,y]); `): elif nops([args])=1 and op(1,[args])=MtoW then print(`MtoW(M): given a monomial as a product of x[i,si], for 1<=i<=m, converts to the walk [s1,s2,..., sm]. Try: `): print(`MtoW(x[2,[2,0]]*x[1,[0,3]]);`): elif nops([args])=1 and op(1,[args])=NuEfron then print(`NuEfron(A,m): The number of possible sucker's bets with deck sizes given by the list A and m different denominations. `): print(`If A has only one element, then it is modulo cyclic symmetry. Otherwise no.`): print(` Try: `): print(` NuEfron([3,3,3],5); `): elif nops([args])=1 and op(1,[args])=NuF then print(`NuF(A,B,m,c): the NUMBER of all walks with steps that are unit if c=1, pure if c=2 and general of c=3`): print(`of m steps from the origin to A with score-vector [#12-#21,#23-#32, ..., $k1-#1k] B. Try:`): print(`NuF([3,3,3],[1,1,1],9,1);`): elif nops([args])=1 and op(1,[args])=PrBeat then print(`PrBeat(L): Given a list of decks finds the list of prob. that deck L[i], beats deck L[i+1] where k+1=1. Try:`): print(`PrBeat([[1,2,3],[3,4,5],[6,7,8]]);`): elif nops([args])=1 and op(1,[args])=PrBeat1 then print(`PrBeat1(L1,L2): given two decks L1 and L2 outputs the probability that deck L1 beats deck K2 `): print(`Try: `): print(` PrBeat1([1,1,2],[2,2,3]); `): elif nops([args])=1 and op(1,[args])=Sefer then print(`Sefer(k,R,s): inputs a positive integer k>=3, a positive integer R>=3, and a non-negative integer s, outputs a`): print(`computer-generated book listing all the Sucker's bets with k decks, with deck-sizes from 3 to R and`): print(`with denominations from the smallest non-empty one up to s about it. `): print(`The alternative title of the book, "A gift to con artists and swindlers" was suggested by Tamar Zeilberger`): print(``): print(`Try:`): print(`Sefer(3,4,2):`): elif nops([args])=1 and op(1,[args])=SetDecks then print(`SetDecks(k,R): all weakly-inreasing sequences of deck sizes with k decks and sizes between 3 and R. Try:`): print(`SetDecks(3,5);`): elif nops([args])=1 and op(1,[args])=WtoD then print(`WtoD(W,k): given a walk W, of length m, say, in k-dimensions, converts it to a list of k decks . Try:`): print(`WtoD([[0,1,0],[1,0,0],[0,1,0]]);`): else print(`There is no ezra for`,args): fi: end: #PrBeat1(L1,L2): given two decks L1 and L2 outputs the probability that deck L1 beats L2 #Try: #PrBeat1([1,1,2],[2,2,3]); PrBeat1:=proc(L1,L2) local i,j,gu1,gu2: gu1:=0: gu2:=0: for i from 1 to nops(L1) do for j from 1 to nops(L2) do if L1[i]>L2[j] then gu1:=gu1+1: elif L1[i]k then RETURN(FAIL): fi: [seq(a1[i]*s1[i+1]-a1[i+1]*s1[i],i=1..k-1),a1[k]*s1[1]-a1[1]*s1[k]]: end: #AllKatan(L): Given a list of integers L, outputs the set of lists of non-negative integers that are smaller than L. Try #AllKatan([2,2,2]); AllKatan:=proc(L) local i,k,gu,gu1,L1: k:=nops(L): if k=0 then RETURN({[]}): fi: if L=[0$k] then RETURN({}): fi: L1:=[op(1..k-1,L)]: gu:=AllKatan(L1): {seq(seq([op(gu1),i],gu1 in gu), i=0..L[k])}: end: #AllKatanU(L): Given a list of integers L, outputs the set of lists of non-negative integers that are smaller than L and are Unit Steps. Try #AllKatanU([2,2,2]); AllKatanU:=proc(L) local i,k,gu: k:=nops(L): gu:={}: for i from 1 to k do if L[i]>0 then gu:=gu union {[0$(i-1),1,0$(k-i)]}: fi: od: gu: end: #AllKatanP(L): Given a list of integers L, outputs the set of lists of non-negative integers that are smaller than L and are Pure Steps #(i.e. only in one coordinate). Try #AllKatanP([3,4,3]); AllKatanP:=proc(L) local i,j,k,gu: k:=nops(L): gu:={}: for i from 1 to k do for j from 1 to L[i] do gu:=gu union {[0$(i-1),j,0$(k-i)]}: od: od: gu: end: #F(A,B,m,c): the set of all walks with steps that are unit if c=1, pure if c=2 and general of c=3 #of m steps from the origin to A with score-vector [#12-#21,#23-#32, ..., $k1-#1k] B. Try: #F([3,3,3],[1,1,1],9,1); F:=proc(A,B,m,c) local gu,k,St,s,lu,lu1,di: option remember: if not member(c,{1,2,3}) then print(`The last argument must be a member of {1,2,3}`): RETURN(FAIL): fi: k:=nops(A): if nops(B)<>k then print(`B must have size`, k): RETURN(FAIL): fi: if min(op(A))<0 then RETURN({}): fi: if m=0 then if A=[0$k] then if B=[0$k] then RETURN({[]}): else RETURN({}): fi: else RETURN({}): fi: fi: if m>convert(A,`+`) then RETURN({}): fi: if c=1 then St:=AllKatanU(A): elif c=2 then St:=AllKatanP(A): else St:=AllKatan(A) minus {[0$k]}: fi: gu:={}: for s in St do di:=DiffSc(A-s,s): lu:=F(A-s,B-di,m-1,c): gu:=gu union {seq([op(lu1),s], lu1 in lu)}: od: gu: end: #WtoD(W,k): given a walk W, of length m, say, in k-dimensions, converts it to a list of k decks . Try #WtoD([[0,1,0],[1,0,0],[0,1,0]]); WtoD:=proc(W,k) local i,m,T,s,st: m:=nops(W): if m<1 then RETURN(FAIL): fi: if {seq(nops(W[i]),i=1..m)}<>{k} then RETURN(FAIL): fi: for i from 1 to k do T[i]:=[]: od: for s from 1 to m do st:=W[s]: for i from 1 to k do T[i]:=[op(T[i]),s$st[i]]: od: od: [seq(T[i],i=1..k)]: end: #NuF(A,B,m,c): the Number of all walks with steps that are unit if c=1, pure if c=2 and general of c=3 #of m steps from the origin to A with score-vector [#12-#21,#23-#32, ..., $k1-#1k] B. Try: #NuF([3,3,3],[1,1,1],9,1); NuF:=proc(A,B,m,c) local gu,k,St,s,di: option remember: if not member(c,{1,2,3}) then print(`The last argument must be a member of {1,2,3}`): RETURN(FAIL): fi: k:=nops(A): if nops(B)<>k then print(`B must have size`, k): RETURN(FAIL): fi: if min(op(A))<0 then RETURN(0): fi: if m=0 then if A=[0$k] then if B=[0$k] then RETURN(1): else RETURN(0): fi: else RETURN(0): fi: fi: if m>convert(A,`+`) then RETURN(0): fi: if c=1 then St:=AllKatanU(A): elif c=2 then St:=AllKatanP(A): else St:=AllKatan(A) minus {[0$k]}: fi: gu:=0: for s in St do di:=DiffSc(A-s,s): gu:=gu+NuF(A-s,B-di,m-1,c): od: gu: end: #GFq(A,qL,m,c): the Generating function according to qL[1]^(#12-#21)*..*qL[k]^(#k1-#1k) #of the set of m-step walks from the origin to A with score-vector #GFq([3,3,3],[q1,q2,q3],9,1); GFq:=proc(A,qL,m,c) local gu,k,St,s,di,i1: option remember: if not member(c,{1,2,3}) then print(`The last argument must be a member of {1,2,3}`): RETURN(FAIL): fi: k:=nops(A): if nops(qL)<>k then print(`B must have size`, k): RETURN(FAIL): fi: if min(op(A))<0 then RETURN(0): fi: if m=0 then if A=[0$k] then RETURN(1): else RETURN(0): fi: fi: if m>convert(A,`+`) then RETURN(0): fi: if c=1 then St:=AllKatanU(A): elif c=2 then St:=AllKatanP(A): else St:=AllKatan(A) minus {[0$k]}: fi: gu:=0: for s in St do di:=DiffSc(A-s,s): gu:=expand(gu+ mul(qL[i1]^di[i1],i1=1..k)*GFq(A-s,qL,m-1,c)): od: gu: end: #GrabPos(P,q): Given a polynomial P in the list of variables q, extracts the part whose exponets are all positive. Try #GrabPos(5*x*y+4/x/y,[x,y]); GrabPos:=proc(P,q) local i,i1,P1,gu: if not type(P,`+`) then if min(seq(degree(P,q[i1]),i1=1..nops(q)))>0 then RETURN(P): else RETURN(0): fi: fi: gu:=0: for i from 1 to nops(P) do P1:=op(i,P): if min(seq(degree(P1,q[i1]),i1=1..nops(q)))>0 then gu:=gu+P1: fi: od: gu: end: #GFqx(A,qL,m,c,x): the Generating function according to qL[1]^(#12-#21)*..*qL[k]^(#k1-#1k) *mul(x[i,s]) #of the set of m-step walks from the origin to A with score-vector #GFqx([3,3,3],[q1,q2,q3],9,1,x); GFqx:=proc(A,qL,m,c,x) local gu,k,St,s,di,i1: option remember: if not member(c,{1,2,3}) then print(`The last argument must be a member of {1,2,3}`): RETURN(FAIL): fi: k:=nops(A): if nops(qL)<>k then print(`B must have size`, k): RETURN(FAIL): fi: if min(op(A))<0 then RETURN(0): fi: if m=0 then if A=[0$k] then RETURN(1): else RETURN(0): fi: fi: if m>convert(A,`+`) then RETURN(0): fi: if c=1 then St:=AllKatanU(A): elif c=2 then St:=AllKatanP(A): else St:=AllKatan(A) minus {[0$k]}: fi: gu:=0: for s in St do di:=DiffSc(A-s,s): gu:=expand(gu+ x[m,s]*mul(qL[i1]^di[i1],i1=1..k)*GFqx(A-s,qL,m-1,c,x)): od: gu: end: #PrBeat(L): Given a list of decks finds the list of prob. that deck L[i], beats deck L[i+1] where k+1=1. Try #PrBeat([[1,2,3],[3,4,5],[6,7,8]]); PrBeat:=proc(L) local i: [seq(PrBeat1(L[i],L[i+1]),i=1..nops(L)-1), PrBeat1(L[nops(L)],L[1])]: end: #MtoW(M,x): given a monomial as a product of x[i,si], for 1<=i<=m, converts to the walk [s1,s2,..., sm]. Try #MtoW(x[2,[2,0]]*x[1,[0,3]],x); MtoW:=proc(M) local M1,i,T: if not type(M,`*`) then RETURN(FAIL): fi: for i from 1 to nops(M) do M1:=op(i,M): if not type(M1,indexed) then RETURN(FAIL): fi: T[op(1,M1)]:=op(2,M1): od: [seq(T[i],i=1..nops(M))]: end: haf:=proc(L) local i: [seq(L[nops(L)+1-i],i=1..nops(L))]:end: #Can1(L): given a list of sorted lists find its cyclic shift starting with the smallest Can1:=proc(L) local m,i: m:=min(seq(L[i][1],i=1..nops(L))): for i from 1 to nops(L) while L[i][1]<>m do od: [op(i..nops(L),L),op(1..i-1,L)]: end: #Efron1(A,m,c): All the Efron sequences of decks where the deck (or die)-sizes are A[1], ..., A[k], using denominations {1, ..,m} #where c=1 are distinct numbers and c=2 is not-necessarily distinct, but no overlaps. Try: #Efron1([3,3,3],9,1); Efron1:=proc(A,m,c) local k,gu,q,x,i,j,gu1,lu,lu1: k:=nops(A): if not member(c,{1,2}) then print(`c, the third argument must be 1 or 2`): RETURN(FAIL): fi: gu:=GrabPos(GFqx(A,[seq(q[i],i=1..k)],m,c,x),[seq(q[i],i=1..k)]): if gu=0 then RETURN({}): fi: gu:=subs({seq(q[i]=1,i=1..k)},gu): if type(gu,`+`) then gu:={seq(WtoD(MtoW(op(i,gu)),k),i=1..nops(gu))}: else gu:={seq(WtoD(MtoW(gu),k),i=1..nops(gu))}: fi: lu:={}: while gu<>{} do gu1:=op(1,gu): lu:=lu union {gu1}: gu:=gu minus {seq([op(j..k,gu1),op(1..j-1,gu1)],j=1..k)}: od: {seq(Can1(haf(lu1)),lu1 in lu)}: end: #Efron1q(A,m,c,q): All the weights in terms of polynomial in q[1], ...,q[nops(A)] #where c=1 are distinct numbers and c=2 is not-necessarily distinct, but no overlaps. Try: #Efron1q([3,3,3],9,1,q); Efron1q:=proc(A,m,c,q) local k,i: k:=nops(A): if not member(c,{1,2}) then print(`c, the third argument must be 1 or 2`): RETURN(FAIL): fi: GrabPos(GFq(A,[seq(q[i],i=1..k)],m,c),[seq(q[i],i=1..k)]): end: #EfronD(A): All the Efron sequences of decks where the deck (or die)-sizes are A[1], ..., A[k], using all different denominations #1...convert(A,`+`): #Try #EfronD([3,3,3]); EfronD:=proc(A) : Efron1(A,convert(A,`+`),1): end: #EfronP(A,m): All the Efron sequences of decks where the deck (or die)-sizes are A[1], ..., A[k], using all denominations 1..m #with no overlap (i.e. no ties) #Try #EfronP([3,3,3],5); EfronP:=proc(A,m) local q: if Efron1q(A,m,2,q)=0 then {}: else Efron1(A,m,2): fi: end: #EfronPs(A): the Efron dice with number of faces (or cards in decks) given by the list A with the smallest possible #different denominations. It also outputs that number of denominations. Try: #EfronPs([3,3,3]); EfronPs:=proc(A) local m: for m from 1 to convert(A,`+`) while EfronP(A,m)={} do od: [EfronP(A,m),m]: end: #Efron1v(A,m,c): A verbose form of Efron1(A,m,c) (q.v.). Try: #Efron1v([3,3,3],9,1); Efron1v:=proc(A,m,c) local gu,i,gu1,j,t0: t0:=time(): if not (c=1 or c=2) then print(`The last argument be 1 or 2`): RETURN(FAIL): fi: if c=1 and m<>convert(A,`+`) then print(`m must be`, convert(A,`+`)): RETURN(FAIL): fi: if not (type(A,list) and type(m,integer) and m>1) then print(`bad input`): RETURN(FAIL): fi: gu:=Efron1(A,m,c): if gu={} then print(`There do not exist Sucker's Bets Sets of Decks with`, nops(A), `decks, with deck sizes`, op(A), ` using `, m, `different denominations from 1 to`, m): RETURN(gu): fi: if c=1 then print(``): print(`All the Suckers's Bets Decks with`, nops(A), `decks, with deck sizes`, op(A), ` using `, m, `different denominations from 1 to`, m): print(`with DISTINCT denominations`): print(``): print(`By Shalosh B. Ekhad `): print(``): elif c=2 then print(``): print(`All the Suckers's Bets Decks with`, nops(A), `decks, with deck sizes`, op(A), ` using `, m, ` denominations labelled from 1 to`, m): print(`Where No denomination appears in more than one deck (hence there is never a tie)`): print(``): print(`By Shalosh B. Ekhad `): print(``): fi: print(`Up to obvious cyclic symmetry, there are`, nops(gu), `distinct such collection of decks where`): for i from 1 to nops(A)-1 do print(` Deck `, i, `beats deck`, i+1): od: print(``): print(`but surprise, surprise Deck`, nops(A), `beats deck 1`): print(``): print(`Here there all are`): for i from 1 to nops(gu) do print(``): print(`-------------------------------------------------------`): print(``): print(`Set Number`, i, `is as follows `): print(``): gu1:=gu[i]: for j from 1 to nops(A) do print(` Deck `, j, ` has denominations `, op(sort(gu1[j])) ): od: print(`It is readily seen that `): for j from 1 to nops(A)-1 do print(` Deck `, j, `beats deck `, j+1, `with probability `, PrBeat1(gu1[j],gu1[j+1])): od: print(`yet Deck`, nops(A), `beats deck 1, with probability `, PrBeat1(gu1[nops(gu1)],gu1[1]) ): od: print(``): print(`---------------------------------------------------`): print(`---------------------------------------------------`): print(``): print(`This ends this article, that took`, time() -t0, `seconds to generate. `): gu: end: #SetDecks(k,R): all weakly-inreasing sequences of deck sizes with k decks and sizes between 3 and R. Try: #SetDecks(3,5); SetDecks:=proc(k,R) local mu,mu1, gu,j,j1: option remember: if k=0 then RETURN({[]}): fi: if k=1 then RETURN({seq([j],j=3..R)}): fi: mu:=SetDecks(k-1,R): gu:={}: for mu1 in mu do j:=mu1[k-1]: gu:=gu union {seq([op(mu1),j1],j1=j..R)}: od: gu: end: #Efron1vC(A,m,N): Like Efron1vC(A,m,2), but outputs a chapter number N, not an article. Try: #Efron1vC([3,3,3],9,1); Efron1vC:=proc(A,m,N) local gu,i,gu1,j,t0: t0:=time(): if not (type(A,list) and type(m,integer) and m>1) then print(`bad input`): RETURN(FAIL): fi: gu:=Efron1(A,m,2): if gu={} then print(`There do not exist Sucker's Bets Sets of Decks with`, nops(A), `decks, with deck sizes`, op(A), ` using `, m, ` denominations labelled from 1 to`, m): RETURN(gu): fi: print(``): print(`Chapter Number`, N): print(``): print(`In this chapter we will consider the set whose deck sizes are`, op(A) ): print(`and there are`, m, ` denominations from 1(Ace) to`, m): print(``): print(``): print(`Up to obvious cyclic symmetry, there are`, nops(gu), `distinct such collection of decks where`): for i from 1 to nops(A)-1 do print(` Deck `, i, `beats deck`, i+1): od: print(``): print(`but surprise, surprise Deck`, nops(A), `beats deck 1`): print(``): print(`Here there all are`): for i from 1 to nops(gu) do print(``): print(`-------------------------------------------------------`): print(``): print(`Set Number`, i, `is as follows `): print(``): gu1:=gu[i]: for j from 1 to nops(A) do print(` Deck `, j, ` has denominations `, op(sort(gu1[j])) ): od: print(`It is readily seen that `): for j from 1 to nops(A)-1 do print(` Deck `, j, `beats deck `, j+1, `with probability `, PrBeat1(gu1[j],gu1[j+1])): od: print(`yet Deck`, nops(A), `beats deck 1, with probability `, PrBeat1(gu1[nops(gu1)],gu1[1]) ): od: print(``): print(`---------------------------------------------------`): print(`---------------------------------------------------`): print(``): print(`This ends this chapter, that took`, time() -t0, `seconds to generate. `): gu: end: #Sefer(k,R,s): inputs a positive integer k>=3, a positive integer R>=3, and a non-negative integer s, outputs a #computer-generated book listing all the Sucker's bets with k decks, with deck-sizes from 3 to R and #with denominations from the smallest non-empty one up to s about it. Try: #Sefer(3,4,2): Sefer:=proc(k,R,s) local N,j,t0,gu,A,i,m: t0:=time(): print(`All the Suckers's Bets Decks with`, k, `decks, with deck sizes from 3 to`,R): print(`Where No denomination appears in more than one deck (hence there is never a tie)`): print(`With various different denominations`): print(``): print(`Or: `): print(`A gift to Con Artists and Swindlers`): print(``): print(`By Shalosh B. Ekhad `): print(``): N:=0: gu:=SetDecks(k,R): for i from 1 to nops(gu) do A:=gu[i]: j:=EfronPs(A): if j[1]={} then print(`There are no Sucker Bets with deck sizes`, op(A)): next: fi: j:=j[2]: for m from j to j+s do N:=N+1: Efron1vC(A,m,N): od: od: print(`------------------------------------------------------------------------------`): print(`This ends this book that took`, time()-t0, `seconds to generate. `): end: #NuEfron(A,m): The number of possible sucker's bets with deck sizes given by the list A and m different denominations. #If A has only one element, then it is modulo cyclic symmetry. Otherwise no. #Try: #NuEfron([3,3,3],5); NuEfron:=proc(A,m) local q,i,gu: gu:=Efron1q(A,m,2,q): gu:=subs({seq(q[i]=1,i=1..nops(A))},gu): if nops(convert(A,set))=1 then RETURN(gu/nops(A)): else RETURN(gu): fi: end: