###################################################################### ## DD321.txt Save this file as DD321.txt to use it, # # stay in the # ## same directory, get into Maple (by typing: maple ) # ## and then type: read `DD321.txt` # ## Then follow the instructions given there # ## # ## Written by Doron Zeilberger, Rutgers University, # # Tipaluck Krityakierne, Mahidol University # #and Thotsaporn "Aek" Thanatipanonda , Mahidol University # #please report bugs to: # ## DoronZeil at gmail dot com # ###################################################################### with(plots): print(`First Written: July 2, 2026 `): print(): print(`This is DD321.txt, A Maple package`): print(`accompanying Tipaluck Krityakierne, Thotsaporn "Aek" Thanatipanonda, and Doron Zeilberger's article` ): print(`A quick proof that 321-avoiding permutations without double deficiencies are counted by the Motzkin numbers`): print(): print(`The most current version is available on WWW at:`): print(` http://sites.math.rutgers.edu/~zeilberg/tokhniot/DD321.txt .`): print(`Please report all bugs to: DoronZeil at gmail dot com .`): print(): print(`For general help, and a list of the MAIN functions,`): print(` type "ezra();". For specific help type "ezra(procedure_name);" `): print(``): print(`-------------------`): print(`For a list of the supporting functions type: ezra1();`): print(): print(`-------------------`): print(`For a list of the CHECKING functions type: ezraC();`): print(): print(`-------------------`): print(`For a list of the Paper functions type: ezraP();`): print(): print(`-------------------`): with(combinat): ezraP:=proc() if args=NULL then print(`The Paper procedures are`): print(` PaperMotToPim PaperMotToPiU `): else ezra(args): fi: end: ezraC:=proc() if args=NULL then print(`The CHECKING procedures are`): print(` CheckConj2a, CheckConj2, CheckLemma3, CheckLemma3a, CheckLemma4, CheckLemma4a, CheckLemma5, CheckLemma5a, CheckLemma6, CheckLemma6a, CheckLemma7, CheckLemma7a, `): else ezra(args): fi: end: ezra1:=proc() if args=NULL then print(`The SUPPORTING procedures are`): print(` AvoidP, BJS, Bset, CMtoSeq, CMtoStump,CrossV, DD, Dset, InvPi, IsGood, IsTherePattern, MotToCM, MyA, MyC, Nset, PlotAllB, PlotAllG, Quad`): print(` SeqtoSets, SetstoD, Stat, `): else ezra(args): fi: end: ezra:=proc() if args=NULL then print(` DD321.txt: A Maple package for `): print(`The MAIN procedures are`): print(`CMtoD, DtoCM, DW, Fnx, FnxF,FnxSeq, FnxSeqGF,`): print(`FnxGF, GoodG, LeftO, Mot2P, Mot2, PlotCM, PicStory, PlotW, rcSeq `): print(`NewCMtoD, MapK,`): print(`BigA, GenDD, BigADD, MotP, LR, PiToMot, MotToPi `): elif nargs=1 and args[1]=BJS then print(`BJS(w): the 321-avoiding permutation corresponding to the Dyck work w according to the Billey-Jockusch-Stanley bijection. Try:`): print(`BJS([1,1,1,-1,-1,-1]);`): print(` BJS([1,1,-1,1,1,1,-1,-1,1$7,(-1)$5,1,-1,1,-1,-1,1,-1,-1,1,-1,1,-1,-1,-1]);`): elif nargs=1 and args[1]=Bset then print(`Bset(w): the set of bad indices. Try:`): print(`Bset([1,1,1,-1,1,-1,-1,-1]);`): elif nargs=1 and args[1]=CheckConj2 then print(`CheckConj2(n): Checks Conj. 2 (corrected) for all Dyck paths of semi-length n, Try:`): print(`CheckConj2(6);`): elif nargs=1 and args[1]=CheckConj2 then print(`CheckConj2a(w): Checks Conj. 2 for the Dyck path w. Try:`): print(` CheckConj2a([1,1,-1,1,1,1,-1,-1,1$7,(-1)$5,1,-1,1,-1,-1,1,-1,-1,1,-1,1,-1,-1,-1]);`): elif nargs=1 and args[1]=CheckLemma3 then print(`CheckLemma3(w): Checks Lemma 3 for all Dyck paths of semi-length n, Try:`): print(`CheckLemma3(6);`): elif nargs=1 and args[1]=CheckLemma3a then print(`CheckLemma3a(w): Checks Lemma 3 for the Dyck path w. Try:`): print(` CheckLemma3a([1,1,-1,1,1,1,-1,-1,1$7,(-1)$5,1,-1,1,-1,-1,1,-1,-1,1,-1,1,-1,-1,-1]);`): elif nargs=1 and args[1]=CheckLemma4 then print(`CheckLemma4(w): Checks Lemma 4 for all Dyck paths of semi-length n, Try:`): print(`CheckLemma4(6);`): elif nargs=1 and args[1]=CheckLemma4a then print(`CheckLemma4a(w): Checks Lemma 4 for the Dyck path w. Try:`): print(` CheckLemma4a([1,1,-1,1,1,1,-1,-1,1$7,(-1)$5,1,-1,1,-1,-1,1,-1,-1,1,-1,1,-1,-1,-1]);`): elif nargs=1 and args[1]=CheckLemma5 then print(`CheckLemma5(w): Checks Lemma 5 for all Dyck paths of semi-length n, Try:`): print(`CheckLemma5(6);`): elif nargs=1 and args[1]=CheckLemma5a then print(`CheckLemma5a(w): Checks Lemma 5 for the Dyck path w. Try:`): print(` CheckLemma5a([1,1,-1,1,1,1,-1,-1,1$7,(-1)$5,1,-1,1,-1,-1,1,-1,-1,1,-1,1,-1,-1,-1]);`): elif nargs=1 and args[1]=CheckLemma6 then print(`CheckLemma6(w): Checks Lemma 6 for all Dyck paths of semi-length n, Try:`): print(`CheckLemma6(6);`): elif nargs=1 and args[1]=CheckLemma6a then print(`CheckLemma6a(w): Checks Lemma 6 for the Dyck path w. Try:`): print(` CheckLemma6a([1,1,-1,1,1,1,-1,-1,1$7,(-1)$5,1,-1,1,-1,-1,1,-1,-1,1,-1,1,-1,-1,-1]);`): elif nargs=1 and args[1]=CheckLemma7 then print(`CheckLemma7(w): Checks Lemma 7 for all Dyck paths of semi-length n, Try:`): print(`CheckLemma7(6);`): elif nargs=1 and args[1]=CheckLemma7a then print(`CheckLemma7a(w): Checks Lemma 7 for the Dyck path w. Try:`): print(` CheckLemma7a([1,1,-1,1,1,1,-1,-1,1$7,(-1)$5,1,-1,1,-1,-1,1,-1,-1,1,-1,1,-1,-1,-1]);`): elif nargs=1 and args[1]=CrossV then print(`CrossV(w): set of crosses in the valleys of the Dyck path w. Try:`): print(` CrossV([1,1,-1,1,1,1,-1,-1,1$7,(-1)$5,1,-1,1,-1,-1,1,-1,-1,1,-1,1,-1,-1,-1]);`): elif nargs=1 and args[1]=CMtoD then print(`CMtoD(w): The inverse ofthe mapping in the Rubey-Stump paper that inputs a colored Motzkin word and outputs a Dyck word. Try:`): print(`CMtoD([1,[0,1],-1]);`): print(` {seq(evalb(CMtoD(DtoCM(w))=w),w in DW(6))} ;`): elif nargs=1 and args[1]=DD then print(`DD(pi): The set of double-deficiencies of permutation pi. Try:`): print(`DD([1,3,2,4]);`): elif nargs=1 and args[1]=DtoCM then print(`DtoCM(w): The mapping in the Rubey-Stump paper that inputs a Dyck path and outputs a colored Motzkin path. Try:`): print(` DtoCM([1,1,-1,1,1,1,-1,-1,1$7,(-1)$5,1,-1,1,-1,-1,1,-1,-1,1,-1,1,-1,-1,-1]);`): elif nargs=1 and args[1]=Dset then print(`Dset(w): inputs a Dyck word w and outputs the set of indices D, in other words the set of k such that c[k+1]=c[k]-1`): print(`Defined in the Rubey-Stump paper, p.2. Try:`): print(`Dset([1,1,-1,-1,1,1,-1,-1]);`): elif nargs=1 and args[1]=DW then print(`DW(n): the set of Dyck words of semi-length n. Try:`): print(`DW(5);`): elif nargs=1 and args[1]=Fnx then print(`Fnx(n,x): The weight-enumerator of Dyck words according to the number of bad places. Try:`): print(`Fnx(8,x);`): elif nargs=1 and args[1]=FnxF then print(`FnxF(n,x): a fast way to compute Fnx(n,x) using the recurrence . Try:`): print(`FnxF(20,x);`): elif nargs=1 and args[1]=FnxSeq then print(`FnxSeq(x,N): The list of the first N members of Fnx(n,x). Done directly (very slow). Try:`): print(`FnSeq(x,10);`): elif nargs=1 and args[1]=FnxSeqGF then print(`FnxSeqGF(x,N): Same as FnxSeq(x,N) but much faster, using the conjectured generating function`): print(`FnSeqGF(x,10);`): elif nargs=1 and args[1]=FnxGF then print(`FnxGF(x,z): The (conjectured) function whose coefficient of z^n is Fnx(n,x) . Try:`): print(`FnxGF(x,z);`): elif nargs=1 and args[1]=GoodG then print(`GoodG(n): the set of good Dyck words of semi-lenght n. Try:`): print(`GoodG(5);`): elif nargs=1 and args[1]=InvPi then print(`InvPi(pi): The inverse of the permutation pi. Try:`): print(`InvPi([2,1,3]);`): elif nargs=1 and args[1]=IsGood then print(`IsGood(w): Does the Dyck word w satisfy the condition that Nset(w) Intersect Dset(w) is contained in the set F, defined in the paper. Try:`): print(`IsGood([1,-1,1,-1]);`): elif nargs=1 and args[1]=LeftO then print(`LeftO(n): the set of members of GoodG(n) that are NOT catenations of two smaller good words. Try:`): print(`LeftO(6);`): elif nargs=1 and args[1]=Mot2P then print(`Mot2P(n): the set of colored Motzkin words of length n where the flat steps along the bottom are not colored (or are always colored red). Try:`): print(`Mot2P(6);`): elif nargs=1 and args[1]=Mot2 then print(`Mot2(n): the set of colored Motzkin words without restriction of length n. Try:`): print(`Mot2(6);`): elif nargs=1 and args[1]=MotToCM then print(`MotToCM(P): inputs a Motzkin word P outputs the corresponding colored Motzkin word with all the horizontal steps colored by color 1. Try:`): print(`MotToCM([1,0,-1]):`): elif nargs=1 and args[1]=Nset then print(`Nset(w): inputs a Dyck word w and outputs the set of rows that do not contain a vally`): print(`Defined in the Rubey-Stump paper, p.2. Try:`): print(`Nset([1,1,-1,-1,1,1,-1,-1]);`): elif nargs=1 and args[1]=PaperMotToPi then print(`PaperMotToPi(n): Spells out the images of MotToPi for all Motzkin words of length n. Try:`): print(`PaperMotToPi(4);`): elif nargs=1 and args[1]=PaperMotToPiU then print(`PaperMotToPiU(n): Spells out the images of MotToPi and CMtoSeq, for all Motzkin words of length n. Try:`): print(`PaperMotToPiU(4);`): elif nargs=1 and args[1]=PlotAllB then print(`PlotAllB(n): plots all the irred. bad walks of length n, together with [N,D, N intersect D, F]. Try:`): print(`PlotAllB(4);`): elif nargs=1 and args[1]=PlotAllG then print(`PlotAllG(n):plots all the irred. good walks of length n, together with [N,D, N intersect D, F]`): print(`PlotAllG(4);`): elif nargs=1 and args[1]=PlotCM then print(`PlotCM(w): plots the colored Motzkin word w.. Try:`): print(`PlotCM([1,1,[0,2],-1,-1]);`): elif nargs=1 and args[1]=PicStory then print(`PicStory(n): all the images under DtoCM(w) for all Good words followed by the images for bad words (that may to actually colored Motzkin words). Try:`): print(`PicStory(n):`): elif nargs=1 and args[1]=PlotW then print(`PlotW(w): plots the walk w. Try:`): print(`PlotW([1,1,-1,-1]);`): elif nargs=1 and args[1]=Quad then print(`Quad(pi): Inputs a permutation pi, and outputs the list of four sets [Exc(pi),FixedPoints(pi),Deficienty(pi), DoubleDescent(pi)]/ Try:`): print(`Quad([1,3,2,4]);`): elif nargs=1 and args[1]=rcSeq then print(`rcSeq(w): inputs a Dyck work and outputs the row-area sequence [r_i] and column-area sequence [c_i]`): print(`as defined on the top of p. 2 of the Rubey/Stump paper arxiv:1708.05092v1 [math.CO] 16 Aug 2017. Try: (using the Dyck path in Fig. 2 of that paper:`): print(` rcSeq([1,1,-1,1,1,1,-1,-1,1$7,(-1)$5,1,-1,1,-1,-1,1,-1,-1,1,-1,1,-1,-1,-1]);`): elif nargs=1 and args[1]=Stat then print(`Stat(F,t,K): Given a generating function F of t, for a r.v. `): print(` finds the statistical information: [ave, s.d, skewness, kurtosis, scaled-5th-comment,...] up the K-th scaled moment. Try:`): print(`Stat((1+t)^100,t,6);`): elif nargs=1 and args[1]=CMtoSeq then print(`CMtoSeq(w): Maps bi-colored Motzkin (where flat step at the bottom`): print(`are not colored) to 321 avoidance seq. Try:`): print(`CMtoSeq([1,[0,2],[0,1],[0,2],[0,2],-1,[0,0],1,1,[0,2],1,[0,2],[0,1],[0,1],-1,-1,-1]); `): elif nargs=1 and args[1]=SeqtoSets then print(`SeqtoSets(pi): Maps the seq in 321-avoidance permutation to`): print(`sets N,D and F of the paper. Try:`): print(`SeqtoSets([3,1,6,2,4,5,7,13,14,8,15,9,16,17,10,11,12]);`): elif nargs=1 and args[1]=SetstoD then print(`SetstoD(N,D,F,n): maps sets N,D and F and length n`): print(`to the corresponding Dyck word of semi-length n. Try:`): print(`SetstoD({1,2,4,5,7,8,9,10,11,12},{2,4,5,6,7,10,12,15,16,17},{7},17);`): elif nargs=1 and args[1]=NewCMtoD then print(`NewCMtoD(w): maps a bi-colored Motzkin word (where flat step at the bottom`): print(`is not colored) to the corresponding Dyck word of semi-length n. Try:`): print(`A:={seq( NewCMtoD(w) ,w in Mot2P(4))}; B:=DW(4); evalb(A=B);`): elif nargs=1 and args[1]=CMtoStump then print(`CMtoStump(w): maps the bi-colored Motzkin (where flat step at the bottom`): print(`is not colored) without red color to subset of Dyck paths of semi-length n. Try:`): print(`A:={seq( CMtoStump(w) ,w in Mot2P(5))}: B:=GoodGold(5): A minus B; B minus A;`): elif nargs=1 and args[1]=MyA then print(`MyA(n): Number colored Motzkin word without restriction through recurrence. Try:`): print(`[seq(MyA(n),n=0..10)];`): print(`[seq(binomial(2*(n+1),n+1)/(n+2),n=0..10)];`): elif nargs=1 and args[1]=MyC then print(`MyC(n): Number of Dyck path of semi-length n through recurrence. . Try:`): print(`[seq(MyC(n),n=0..10)];`): print(`[seq(binomial(2*n,n)/(n+1),n=0..10)];`): elif nargs=1 and args[1]=MapK then print(`MapK(M): Mapping of Colored Motzkin word without restriction`): print(`of length n to Dyck path of semi-length n+1.`): print(`Remark: need some investigations on what maps to what. Try:`): print(`MapK([[0, 2], [0, 2], [0, 1]]);`): print(`A:={seq(MapK(M),M in Mot2(4))}: B:= DW(5): nops(A); nops(B); evalb(A=B);`): elif nargs=1 and args[1]=BigA then print(`BigA(n,PP): the set of permutation of length n which does not contain patterns in PP. Try:`): print(`BigA(4,{[3,2,1]});`): print(`BigA(5,{[3,2,1],[1,3,2]});`): elif nargs=1 and args[1]=AvoidP then print(`AvoidP(w,PP): A brute force function to compute pattern avoidance of length 3`): print(`return true if permutation w avoids pattern in the set PP and false if w contains a pattern in PP. Try:`): print(`AvoidP([1,2,3,4],{[3,2,1]});`): elif nargs=1 and args[1]=IsTherePattern then print(`IsTherePattern(W,P): return true if the list of length 3 has relative`): print(`order the same as the list P. Try:`): print(`IsTherePattern([5,3,4],[3,1,2]);`): print(`IsTherePattern([5,3,4],[1,3,2]);`): elif nargs=1 and args[1]=GenDD then print(`GenDD(n,x,PP): Generating function of DD from pattern`): print(`avoidance of set PP of length n. Try:`): print(`GenDD(6,x,{[3,2,1]});`): elif nargs=1 and args[1]=BigADD then print(`BigADD(n,PP): Set of permutations of length n which`): print(`avoid patterns in DD and also has no DD. Try:`): print(`BigADD(5,{[3,2,1]});`): print(`[seq( nops(BigADD(n,{[3,2,1]})),n=1..8)];`): elif nargs=1 and args[1]=MotP then print(`MotP(n): Set of Motzkin Paths of length n. Try:`): print(`MotP(3); `): elif nargs=1 and args[1]=LR then print(`LR(pi): List of indices of left-to-right maxima`): print(`and list of elements of left-to-right maxima. Try:`): print(`LR([3,1,2,4]);`): elif nargs=1 and args[1]=PiToMot then print(`PiToMot(pi): Input: 321-permutation with no DD`): print(`Output: The corresponding Motzkin path of length n. Try:`): print(`PiToMot([2,4,5,1,3]);`): print(`A:={seq( PiToMot(pi) ,pi in BigADD(6,{[3,2,1]}))}: `): print(`B:= MotP(6);`): print(`evalb(A=B);`): print(`{seq( evalb(M=PiToMot(MotToPi(M))),M in MotP(7))};`): elif nargs=1 and args[1]=MotToPi then print(`MotToPi(M): Input: Motzkin path of length n`): print(`Output: The corresponding 321-permutation with no DD. Try:`): print(`MotToPi([0,1,0,-1]);`): print(`A:=BigADD(5,{[3,2,1]});`): print(`B:={seq(MotToPi(M),M in MotP(5))};`): print(`evalb(A=B);`): print(`{seq( evalb(pi=MotToPi(PiToMot(pi))),pi in BigADD(7,{[3,2,1]}))};`): else print(`There is no such thing as`, args): fi: end: #DW(n): The set of Dyck words of semi-length n DW:=proc(n) local k,gu1,gu2,w1,w2,gu: option remember: if n=0 then RETURN({[]}): fi: gu:={}: for k from 1 to n do gu1:=DW(k-1): gu2:=DW(n-k): gu:= gu union {seq(seq([1,op(w1),-1,op(w2)], w1 in gu1), w2 in gu2)}: od: gu: end: #rcSeq(w): inputs a Dyck work and outputs r_i and c_i rcSeq:=proc(w) local i,c,r,s: r:=[]: c:=[]: s:=0: for i from 1 to nops(w) do if w[i]=1 then r:=[op(r),s]: s:=s+w[i]: elif w[i]=-1 then c:=[op(c),s-1]: s:=s+w[i]: fi: od: [r,c]: end: #Dset(w): inputs a Dyck word w and outputs the set of indices D Dset:=proc(w) local D1,c,k: c:=rcSeq(w)[2]: c:=[op(c),-1]: D1:={}: for k from 1 to nops(c)-1 do if c[k]=c[k+1]+1 then D1:=D1 union {k}: fi: od: D1: end: #Nset(w): inputs a Dyck word w and outputs the set of indices N Nset:=proc(w) local N1,i,k: N1:={}: k:=1: for i from 2 to nops(w) do if w[i]=1 then k:=k+1: if w[i-1]=-1 then N1:=N1 union {k}: fi: fi: od: {seq(i,i=1..k)} minus N1: end: #IsGoodOld(w): is the Dyck word good? IsGoodOld:=proc(w) local gu,K,R,C,k,c,i,r: K:=Nset(w) intersect Dset(w): gu:=rcSeq(w): r:=gu[1]: c:=gu[2]: R[0]:=-1: for i from 1 to nops(r) do R[i]:=r[i]: od: for i from 1 to nops(c) do C[i]:=c[i]: od: C[nops(c)+1]:=-1: for k in K do if R[k+1+C[k+1]]<>R[k-1]+C[k+1]+2 then RETURN(false): fi: od: true: end: #GoodGold(n): the set of good Dyck words GoodGold:=proc(n) local lu,lu1,gu: lu:=DW(n): gu:={}: for lu1 in lu do if IsGoodOld(lu1) then gu:=gu union {lu1}: fi: od: gu: end: PlotW:=proc(w) local i,gu,s: gu:=0: s:=0: gu:=[[0,0]]: for i from 1 to nops(w) do s:=s+w[i]: gu:=[op(gu),[i,s]]: od: plot(gu,scaling=constrained): end: #Dugot(n1,n2): The catenation of the Good words of semi-length n1 and semi-length n2. Try: Zugot:=proc(n1,n2) local gu1,gu2,w1,w2: gu1:=GoodG(n1): gu2:=GoodG(n2): {seq(seq([op(w1),op(w2)],w1 in gu1),w2 in gu2)}: end: #LeftO(n): the set of members of GoodG(n) that are NOT catenations of two smaller good words. Try: #LeftO(6); LeftO:=proc(n) local k,gu: gu:=GoodG(n): for k from 1 to n-1 do gu:=gu minus Zugot(k,n-k): od: gu: end: #BsetOld(w): the set of bad indices, old version BsetOld:=proc(w) local gu,K,R,C,k,c,i,r,B: K:=Nset(w) intersect Dset(w): gu:=rcSeq(w): r:=gu[1]: c:=gu[2]: R[0]:=-1: for i from 1 to nops(r) do R[i]:=r[i]: od: for i from 1 to nops(c) do C[i]:=c[i]: od: C[nops(c)+1]:=-1: B:={}: for k in K do if R[k+1+C[k+1]]<>R[k-1]+C[k+1]+2 then B:=B union {k}: fi: od: B: end: #Bset(w): the set of bad indices Bset:=proc(w) : Nset(w) intersect Dset(w) minus Fset(w):end: #Fnx(n,x): The weight-enumerator of Dyck words according to the number of bad places. Try: #Fnx(8,x); Fnx:=proc(n,x) local W,w: W:=DW(n): add(x^nops(Bset(w)),w in W): end: #FnxGFd(x,z): The generating whose coefficient of z^n is Fnx(n,x) . Directly #FnxGFd(x,z); FnxGFd:=proc(x,z) 1/2*(-x*z+z-1+(x^2*z^2+2*x*z^2-2*x*z-3*z^2-2*z+1)^(1/2))/z/(x*z-x-z): end: #Stat(F,t,K): Given a generating function F of t, for a r.v. # finds the statistical information. Try: #Stat((1+t)^100,t,6); Stat:=proc(F,t,K) local gu,mu,sd,k,f: f:=evalf(F/subs(t=1,F),20): mu:=subs(t=1,diff(f,t)): gu:=[mu]: if K=1 then RETURN(gu): fi: f:=f/t^mu: f:=t*diff(t*diff(f,t),t): sd:=sqrt(subs(t=1,f)): gu:=[op(gu),sd]: for k from 3 to K do f:=t*diff(f,t): gu:=[op(gu),subs(t=1,f)/sd^k]: od: evalf(gu,20): end: #FnxSeq(x,N): The list of the first N members of Fnx(n,x). Done directly (very slow). Try: #FnSeq(x,10); FnxSeq:=proc(x,N) local n: [seq(Fnx(n,x),n=1..N)]: end: #FnxSeqGF(x,N): The list of the first N members of Fnx(n,x). Done Fast, using the conjectured generating function #FnSeqGF(x,10); FnxSeqGF:=proc(x,N) local n,f,z: f:=FnxGF(x,z): f:=taylor(f,z=0,N+4): [seq(expand(coeff(f,z,n)),n=1..N)]: end: FnxF:=proc(n,x) local L1,ope3,N,i: option remember: L1:=[1,2,x+4]: ope3:=(2*n*x^2+3*n*x-x^2-n-1)/x/(n+1)/N-(n*x^3+4*n*x^2-2*x^3-3*n*x-5*x^2-2*n+6*x+1)/x /(n+1)/N^2+(n*x^3+n*x^2-2*x^3-5*n*x-2*x^2+3*n+10*x-6)/x/(n+1)/N^3: if n>=1 and n<=3 then RETURN(L1[n]): else normal(add(coeff(ope3,N,-i)*FnxF(n-i,x),i=1..3)): fi: end: #IsGood(w): the set F of the paper IsGood:=proc(w) local N1,D1,S,i: N1:=sort(convert(Nset(w),list)); D1:=sort(convert(Dset(w),list)); if nops(N1)<>nops(D1) then print(`Something is wrong`): RETURN(FAIL): fi: S:={}: for i from 1 to nops(N1) do if N1[i]=D1[i] then S:=S union {N1[i]}: fi: od: evalb(convert(N1,set) intersect convert(D1,set)=S): end: #GoodG(n): the set of good Dyck words GoodG:=proc(n) local lu,lu1,gu: lu:=DW(n): gu:={}: for lu1 in lu do if IsGood(lu1) then gu:=gu union {lu1}: fi: od: gu: end: #Fset(w): the set F of the paper Fset:=proc(w) local N1,D1,S,i: N1:=sort(convert(Nset(w),list)); D1:=sort(convert(Dset(w),list)); if nops(N1)<>nops(D1) then print(`Something is wrong`): RETURN(FAIL): fi: S:={}: for i from 1 to nops(N1) do if N1[i]=D1[i] then S:=S union {N1[i]}: fi: od: S: end: #PlotAllG(n): plots all irred. good walks PlotAllG:=proc(n) local S,i: S:=LeftO(n): for i from 1 to nops(S) do print(`--------`): print(S[i]): print(``): print(``): print(PlotW(S[i])); print(``): print([Nset(S[i]),Dset(S[i]), Nset(S[i]) intersect Dset(S[i]), Fset(S[i])]): od: end: #PlotAllB(n): plots all irred. bad walks PlotAllB:=proc(n) local i,S,S1,w: S:=LeftO(n): S1:=DW(n-1): S1:={seq([1,op(w),-1], w in S1)}: S:=S1 minus S: for i from 1 to nops(S) do print(`--------`): print(``): print(S[i]): print(``): print(PlotW(S[i])); print(``): print([Nset(S[i]),Dset(S[i]), Nset(S[i]) intersect Dset(S[i]), Fset(S[i])]): od: end: #BJS(w): the 321-avoiding permutation corresponding to the Dyck work w according to the Billey-Jockusch-Stanley bijection. Try: #BJS([1,1,1,-1,-1,-1]); BJS:=proc(w) local n,i,x,y,S1,S2,T,S1c,S2c: option remember: n:=nops(w)/2: x:=0: y:=0: S1:={}: S2:={}: for i from 2 to nops(w) do if w[i]=1 then y:=y+1: elif w[i]=-1 then x:=x+1: fi: if w[i-1]=-1 and w[i]=1 then S1:=S1 union {x}: S2:=S2 union {y+1}: T[x]:=y+1: fi: od: S1c:=sort(convert({seq(i,i=1..n)} minus S1,list)): S2c:=sort(convert({seq(i,i=1..n)} minus S2,list)): for i from 1 to nops(S1c) do T[S1c[i]]:=S2c[i]: od: [seq(T[i],i=1..n)]: end: #InvPi(pi): The inverse of the permutation pi. Try: #InvPi([2,1,3]); InvPi:=proc(pi) local n,i,T: n:=nops(pi): for i from 1 to n do T[pi[i]]:=i: od: [seq(T[i],i=1..n)]: end: #DD(pi): The set of double-deficiencies of permutation pi. Try: #DD([1,3,2,4]); DD:=proc(pi) local n,gu,pi1,k: n:=nops(pi): pi1:=InvPi(pi): gu:={}: for k from 1 to n do if pi[k]k then gu1:=gu1 union {k}: elif pi[k]=k then gu2:=gu2 union {k}: elif pi[k]{} then RETURN(false): elif pi[k]<>k and {seq(seq([i,j],i=1..k),j=k..n)} intersect S={} then RETURN(false): fi: od: true: end: #CheckLemma4(n): Checks Lemma 4 for all Dyck paths of semi-length n.. Try: #CheckLemma4(6); CheckLemma4:=proc(n) local S,s: S:=DW(n): evalb({seq(CheckLemma4a(s), s in S)}={true}): end: #CheckLemma5a(w): checks Lemma 5 for the Dyck path w. Try: #CheckLemma5a([1,-1]); CheckLemma5a:=proc(w) local lu: lu:=Quad(BJS(w)): evalb(lu[2] union lu[3]=Dset(w)): end: #CheckLemma5(n): Checks Lemma 5 for all Dyck paths of semi-length n.. Try: #CheckLemma5(6); CheckLemma5:=proc(n) local S,s: S:=DW(n): evalb({seq(CheckLemma5a(s), s in S)}={true}): end: #CheckLemma6a(w): checks Lemma 5 for the Dyck path w. Try: #CheckLemma6a([1,-1]); CheckLemma6a:=proc(w) local lu: lu:=Quad(BJS(w)): evalb(lu[2]=Fset(w)): end: #CheckLemma6(n): Checks Lemma 6 for all Dyck paths of semi-length n.. Try: #CheckLemma6(6); CheckLemma6:=proc(n) local S,s: S:=DW(n): evalb({seq(CheckLemma6a(s), s in S)}={true}): end: #CheckLemma7a(w): checks Lemma 5 for the Dyck path w. Try: #CheckLemma7a([1,-1]); CheckLemma7a:=proc(w) local n,pi1,lu,N,k,N1,S,pi: pi:=BJS(w): n:=nops(pi): pi1:=InvPi(pi): lu:=Quad(pi): N:=Nset(w): S:=lu[2] union lu[3]: N1:={}: for k from 1 to n do if member(pi1[k],S) then N1:=N1 union {k}: fi: od: evalb(N=N1): end: #CheckLemma7(n): Checks Lemma 6 for all Dyck paths of semi-length n.. Try: #CheckLemma7(6); CheckLemma7:=proc(n) local S,s: S:=DW(n): evalb({seq(CheckLemma7a(s), s in S)}={true}): end: #CheckConj2a(w): checks conj. 7 for the Dyck path w. CheckConj2a:=proc(w) local pi: pi:=BJS(w): evalb(Nset(w) intersect Dset(w) minus Fset(w)=DD(pi)): end: #CheckConj2(n): Checks Conj 2for all Dyck paths of semi-length n.. Try: #CheckConj2(6); CheckConj2:=proc(n) local S,s: S:=DW(n): evalb({seq(CheckConj2a(s), s in S)}={true}): end: #DtoCM(w): inputs a Dyck word and outputs the corresponding bi-colored Motzkin word DtoCM:=proc(w) local pi,L,i,n,pi1: pi:=BJS(w): n:=nops(pi): pi1:=InvPi(pi): L:=[]: for i from 1 to n do if pi[i]=i then L:=[op(L),[0,0]]: elif pi1[i]i then L:=[op(L),[0,1]]: elif pi1[i]>i and pi[i]i and pi1[i]>i then L:=[op(L),1]: else L:=[op(L),-1]: fi: od: L: end: #PlotCM(w): plots a colored Motzkin word. Try: #PlotCM([1,[0,1],-1]); PlotCM:=proc(w) local i,gu,pt,pt1: pt:=[0,0]: gu:=plot([[0,0],[0,0]],scaling=constrained): for i from 1 to nops(w) do if nops(w[i])=2 then if w[i][1]<>0 then RETURN(FAIL): fi: if w[i][2]=1 then pt1:=pt+[1,0]: gu:=gu,plot([pt,pt1], color=red, thickness=1): pt:=pt1: elif w[i][2]=2 then pt1:=pt+[1,0]: gu:=gu,plot([pt,pt1], color=blue, thickness=3): pt:=pt1: elif w[i][2]=0 then pt1:=pt+[1,0]: gu:=gu,plot([pt,pt1], color=red, thickness=3): pt:=pt1: fi: elif w[i]=1 then pt1:=pt+[1,1]: gu:=gu,plot([pt,pt1],color=red): pt:=pt1: else pt1:=pt+[1,-1]: gu:=gu,plot([pt,pt1],color=red): pt:=pt1: fi: od: display(gu): end: #PicStory(n): all the images under DtoCM(w) for all Good words followed by the images for bad words (that may to actually colored Motzkin words). Try: #PicStory(n): PicStory:=proc(n) local i,G,B,w: print(``): print(`--------------------`): print(``): G:=GoodG(n): B:=DW(n) minus GoodG(n): print(`We present all the Dyck words of semi-length `, n, `and their images (as colored Motzkin words) under the Rubey-Stump bijection`): print(``): print(`We start with the good words, that output UNCOLORED Motzkin words`): print(``): for i from 1 to nops(G) do w:=G[i]: print(`-------------------`): print(``): print(`For the Dyck word`, w, `its plot, followed by the plot of its image is`): print(``): print(PlotCM(w)); print(``): print(PlotCM(DtoCM(w))); od: print(`--------------------`): print(`--------------------`): print(`We continue with the bad words, that output COLORED Motzkin words`): for i from 1 to nops(B) do w:=B[i]: print(`-------------------`): print(``): print(`For the Dyck word`, w, `the bed set is`, Bset(w)): print(``): print(``): print(PlotCM(w)); print(``): print(PlotCM(DtoCM(w))); od: end: ############################################### ############################################### # Generating function of colored Motzkin FnxGF:=proc(x,z) local f,f1,f1a,eq: f1a:=solve(f=1+z*f+z*f1*z*f,f1); eq:=f1-1-(z+z*x)*f1-z^2*f1^2; eq:=numer(subs(f1=f1a,eq)): solve(eq,f)[1]; end: ############################################# ############################################# ############################################# # Start Mint+Aek's part # The main functions are # CMtoD(w), Mot2P(n), Mot2(n). # The help functions are # CMtoSeq(w), SeqtoSets(pi), # SetstoD(N,D,F,n). # Main commands # {seq(evalb(CMtoD(DtoCM(w))=w),w in DW(8))}; # {seq(evalb(DtoCM(CMtoD(w))=w),w in Mot2P(8))}; #CMtoD(w): inputs a bi-colored Motzkin word #and outputs the corresponding Dyck word # Try: # w:=[1, [0, 2], [0, 1], [0, 2], [0, 2], -1, # [0, 0], 1, 1, [0, 2], 1, [0, 2], [0, 1], # [0, 1], -1, -1, -1]: # CMtoD(w); CMtoD:=proc(w) local n,pi,S; pi := CMtoSeq(w); S := SeqtoSets(pi); SetstoD(S[1],S[2],S[3],nops(w)); end: # Turns bi-colored Motzkin to # 321 avoidance seq. # Try: # w:=[1, [0, 2], [0, 1], [0, 2], [0, 2], -1, # [0, 0], 1, 1, [0, 2], 1, [0, 2], [0, 1], # [0, 1], -1, -1, -1]: # CMtoSeq(w); # Output suppose to be: # [3,1,6,2,4,5,7,13,14,8,15,9,16,17,10,11,12]; # # W:=Mot2P(4); # [seq(CMtoSeq(w),w in W)]; CMtoSeq := proc(w) option remember; local i,n,u,d,U,D,L,R,pi; n := nops(w); U :=[]; D :=[]; L :=[]; R :=[]; pi := [0$n]; for i from 1 to n do if w[i]=1 then U := [op(U),i]; R := [op(R),i]; elif w[i]=-1 then D := [op(D),i]; L := [op(L),i]; elif w[i]=[0,1] then U := [op(U),i]; L := [op(L),i]; elif w[i]=[0,2] then D := [op(D),i]; R := [op(R),i]; elif w[i]=[0,0] then pi[i] := i; fi: od: #print(nops(U),nops(L),nops(D),nops(R)): for i from 1 to nops(U) do pi[U[i]] := L[i]; od: for i from 1 to nops(D) do pi[D[i]] := R[i]; od: pi; end: # Maps the seq in 321-avoidance seq to # sets N,D and F # Try: # SeqtoSets([3,1,6,2,4,5,7,13,14,8,15,9,16,17,10,11,12]); # Output is supposed to be: # [{1,2,4,5,7,8,9,10,11,12},{2,4,5,6,7,10,12,15,16,17},{7}]; SeqtoSets := proc(pi) option remember; local i,n,N,D,F; n := nops(pi); N := {seq(i,i=1..n)}; D := {}; F := {}; for i from 1 to n do if pi[i]>i then N := N minus {pi[i]}; elif pi[i]<=i then D := D union {i}; fi: if pi[i]=i then F := F union {i}; fi: od: [N,D,F]; end: #SetstoD(w): input sets N,D and F and length n #and outputs the corresponding Dyck word # Try: # SetstoD({1,2,4,5,7,8,9,10,11,12}, # {2,4,5,6,7,10,12,15,16,17},{7},17); SetstoD := proc(N,D,F,n) option remember; local i,T,dyck; T := [[]]; for i from 1 to n do if member(i,N) then T[nops(T)] := [op(T[nops(T)]),1]; else T := [op(T),[-1,1]]; fi: od: dyck := [op(T[1])]; T := [op(2..nops(T),T)]; for i from 1 to n do if member(i,D) then dyck := [op(dyck),-1]; else dyck := [op(dyck),op(T[1])]; T := [op(2..nops(T),T)]; fi: od: dyck; end: ############################################### # Mot2P: Input n and output # set of 2-color Motzkin Paths # as in the paper (no color on x-axis) # Try: # Mot2P(3); Mot2P := proc(n) option remember; local k,s,t; if n=0 then return({[]}); fi: { seq( [[0,0],op(s)],s in Mot2P(n-1))} union {seq(seq(seq( [1,op(s),-1,op(t)] ,s in Mot2(k-2)), t in Mot2P(n-k)),k=2..n)}; end: # Mot2: Input n and output # colored Motzkin words # without restriction. # Try: # Mot2(3); Mot2 := proc(n) option remember; local k,s,t; if n=0 then return({[]}); fi: { seq( op([[[0,1],op(s)],[[0,2],op(s)]]) ,s in Mot2(n-1))} union {seq(seq(seq( [1,op(s),-1,op(t)] ,s in Mot2(k-2)), t in Mot2(n-k)),k=2..n)}; end: ############################################# ############################################# ############################################# # June 15, 2026 # Aek added Bijection of restircted # color Motzkin of length n to Dyck path # of semi-length n. # NewCMtoD(w): maps a bi-colored Motzkin # word (where flat step at the bottom is not colored) # to the corresponding Dyck word of semi-length n. # Try: # A:={seq( NewCMtoD(w) ,w in Mot2P(4))}; # B:=DW(4); # evalb(A=B); NewCMtoD := proc(w) option remember; local i,n,dy; n := nops(w); dy := []; for i from 1 to n do if w[i] = 1 then dy := [op(dy),1,1]; elif w[i] = -1 then dy := [op(dy),-1,-1]; elif w[i] = [0,0] or w[i]=[0,1] then dy := [op(dy),1,-1]; elif w[i] = [0,2] then dy := [op(dy),-1,1]; fi: od: dy; end: # maps the bi-colored Motzkin # (where flat step at the bottom is not colored) # without red color to subset # of Dyck paths of semi-length n. # Try: # A:={seq( CMtoStump(w) ,w in Mot2P(5))}: # B:=GoodGold(5): # A minus B; # B minus A; CMtoStump := proc(w) option remember; if member([0,2], {op(w)}) then return(); else NewCMtoD(w); fi: end: ############################################# ############################################# ############################################# # Khyber coffee shop June 16 # # Functions: # MyA(n), MyC(n), # MapK(n), PartialMot1(k,M), # Number colored Motzkin word without # restriction through recurrence. # Try: # [seq(MyA(n),n=0..10)]; # [seq(binomial(2*(n+1),n+1)/(n+2),n=0..10)]; MyA := proc(n) option remember; local i; if n=0 then return(1); fi: 2*MyA(n-1)+add(MyA(i)*MyA(n-2-i),i=0..n-2); end: # Number of Dyck path of semi-length n # through recurrence. # Try: # [seq(MyC(n),n=0..10)]; # [seq(binomial(2*n,n)/(n+1),n=0..10)]; MyC := proc(n) option remember; local i; if n=0 then return(1); fi: add(MyC(i)*MyC(n-1-i),i=0..n-1); end: # Mapping of # Colored Motzkin word without # restriction of length n to # Dyck path of semi-length n+1. # Remark: need some investigations # on what maps to what. # Try: # MapK([[0, 2], [0, 2], [0, 1]]); # # A:={seq(MapK(M),M in Mot2(4))}: # B:= DW(5): # nops(A); nops(B); # evalb(A=B); MapK := proc(M) option remember; local i,MP,s; if M = [] then return([1,-1]); fi: if M[1] = 1 then for i from 1 to nops(M) while PartialMot1(i,M)>0 do od: return([1,op(MapK([op(2..i-1,M)])),-1 ,op(MapK([op(i+1..nops(M),M)]))]); elif M[1]=[0,1] then MP := [op(2..nops(M),M)]; return([1,op(MapK(MP)),-1]); elif M[1]=[0,2] then MP := [op(2..nops(M),M)]; return([1,-1,op(MapK(MP))]); fi: end: # Try: # PartialMot1(1,[1, [0, 2], -1]); PartialMot1 := proc(k,M) option remember; local i,s; s :=0; for i from 1 to k do if type(M[i],integer) then s := s+M[i]; fi: od: s; end: ############################################ # June 28, 2026 # Bijective proof between 321-avoidance # permutation with no DD and Motzkin path # of the same lengths ############################ # Section 0.1: Pattern Avoidance # of length 3 by brute force # # Functions: # BigA(n,PP), # AvoidP(w,PP), # IsTherePattern(W,P), # ############################ # Output: the set of permutation # of length n which does not # contain patterns in PP # Try: # [seq(nops(BigA(n,{})),n=1..4)]; # # [seq(Cat(n),n=1..8)]; # [seq(nops(BigA(n,{[1,2,3]})),n=1..8)]; # [seq(nops(BigA(n,{[1,3,2]})),n=1..8)]; # [seq(nops(BigA(n,{[2,1,3]})),n=1..8)]; # [seq(nops(BigA(n,{[2,3,1]})),n=1..8)]; # [seq(nops(BigA(n,{[3,1,2]})),n=1..8)]; # [seq(nops(BigA(n,{[3,2,1]})),n=1..8)]; # # BigA(5,{[3,2,1],[3,1,2]}); # [seq(nops(BigA(n,{[3,2,1],[3,1,2]})),n=1..8)]; # [seq(2^(n-1),n=1..8)]; BigA := proc(n,PP) option remember; local w,T; T := {}; for w in permute(n) do if AvoidP(w,PP) then T := T union {w}; fi: od: T; end: # A brute force function # to compute pattern avoidance # of length 3 # Output: true if permutation w avoids pattern # in the set PP and false if w contains pattern # in PP. # Try: # AvoidP([1,2,3,4],{[3,2,1]}); AvoidP := proc(w,PP) option remember; local i,j,k,n,P; n := nops(w); for i from 1 to n do for j from i+1 to n do for k from j+1 to n do if member(true, {seq(IsTherePattern([w[i],w[j],w[k]],P),P in PP)}) then return(false); fi: od: od: od: return(true); end: # Output: true if the list of length 3 # has relative order the same as the list P. # Try: # IsTherePattern([5,3,4],[3,1,2]); # IsTherePattern([5,3,4],[1,3,2]); IsTherePattern := proc(W,P) option remember; if P = [3,2,1] then if W[1]>W[2] and W[2]>W[3] then return(true); fi: elif P = [3,1,2] then if W[1]>W[3] and W[3]>W[2] then return(true); fi: elif P = [2,3,1] then if W[2]>W[1] and W[1]>W[3] then return(true); fi: elif P = [2,1,3] then if W[3]>W[1] and W[1]>W[2] then return(true); fi: elif P = [1,3,2] then if W[2]>W[3] and W[3]>W[1] then return(true); fi: elif P = [1,2,3] then if W[3]>W[2] and W[2]>W[1] then return(true); fi: else ERROR("NoCase"); fi: return(false) end: ############################ # Section 0.2: About DD, # aka double-deficiencies # # Functions: # GenDD(n,x,PP), # BigADD(n,PP), # ############################ # Generating function of DD # from pattern avoidance of set PP # of length n. # Try: # GenDD(6,x,{[3,2,1]}); # [seq(GenDD(n,0,{}),n=1..8)]; # This is number of permutations of n # elements not containing the consecutive pattern 123. # Because of Cycle cycle notation. # [seq(nops(CycleDD(n)),n=1..8)]; # # [seq(GenDD(n,0,{[2,3,1]}),n=1..8)]; # [seq(GenDD(n,0,{[3,2,1]}),n=1..8)]; # [seq(GenDD(n,0,{[1,2,3]}),n=1..8)]; # [seq(GenDD(n,x,{[1,3,2]}),n=1..8)]; # [seq(GenDD(n,x,{[2,1,3]}),n=1..8)]; # [seq(GenDD(n,x,{[3,1,2]}),n=1..8)]; GenDD := proc(n,x,PP) option remember; local w; sort(add( x^nops(DD(w)),w in BigA(n,PP))); end: # Set of permutations of length n which # avoid patterns in DD and also has no DD. # Try: # BigADD(5,{[3,2,1]}); # [seq( nops(BigADD(n,{[3,2,1]})),n=1..8)]; # [seq(Mot(n),n=1..10)]; BigADD := proc(n,PP) option remember; local w,T; T := {}; for w in BigA(n,PP) do if DD(w) = {} then T := T union {w}; fi: od: T; end: ############################ # Section 0.3: Bijective # map of 321-permutation # with no DD to Motzkin paths # of the same length # # Functions: # MotP(n), LR(pi), # PiToMot(pi), MotToPi(w), # ############################ # List of indices of left-to-right maxima # and list of elements of left-to-right maxima. # Try: # LR([3,1,2,4]); LR := proc(pi) option remember; local i,max1,Ind,V; Ind:={}; V:= {}; max1 := 0; for i from 1 to nops(pi) do if pi[i] > max1 then Ind := Ind union {i}; V := V union {pi[i]}; max1 := pi[i]; fi: od: [Ind,V]; end: # Set of Motzkin Paths of length n # Try: # MotP(3); MotP := proc(n) option remember; local k,s,t; if n=0 then return({[]}); fi: { seq( [0,op(s)],s in MotP(n-1))} union {seq(seq(seq( [1,op(s),-1,op(t)] ,s in MotP(k-2)), t in MotP(n-k)),k=2..n)}; end: ############################################### # Main command: # {seq( evalb(M=PiToMot(MotToPi(M))) # ,M in MotP(7))}; # {seq( evalb(pi=MotToPi(PiToMot(pi))) # ,pi in BigADD(7,{[3,2,1]}))}; # Input: 321-permutation with no DD # Output: The corresponding Motzkin # path of length n # Try: # PiToMot([2,4,5,1,3]); # # A:={seq( PiToMot(pi) ,pi in BigADD(6,{[3,2,1]}))}: # B := MotP(6); # evalb(A=B); PiToMot := proc(pi) option remember; local i,n,Ind,V,M; n := nops(pi); Ind := LR(pi)[1]; V := LR(pi)[2]; M := []; for i from 1 to n do if member(i,Ind) and member(i,V) then M := [op(M),0]; elif member(i,Ind) then M := [op(M),1]; elif member(i,V) then M := [op(M),-1]; else ERROR("BadInput"); fi: od: M; end: # Input: Motzkin path of length n # Output: The corresponding # 321-permutation with no DD # Try: # MotToPi([0,1,0,-1]); # # A:=BigADD(5,{[3,2,1]}); # B:={seq(MotToPi(M),M in MotP(5))}; # evalb(A=B); MotToPi := proc(M) option remember; local i,n,Ind,V,P,R,T; # Step1: Motzkin to sets Ind and V n := nops(M); Ind := {}; V := {}; for i from 1 to n do if M[i]=0 then Ind := Ind union {i}; V := V union {i}; elif M[i]=1 then Ind := Ind union {i}; elif M[i]=-1 then V := V union {i}; else ERROR("BadInput"); fi: od: #print([Ind,V]); # Step2: sets Ind and V to 321-permutation P := [0$n]; for i from 1 to nops(Ind) do P[Ind[i]] := V[i]; od: R := {seq(i,i=1..n)} minus Ind; T := {seq(i,i=1..n)} minus V; for i from 1 to nops(R) do P[R[i]] := T[i]; od: P; end: #MotToCM(P): inputs a Motzkin word P outputs the corresponding colored Motzkin word with all the horizontal steps colored by color 1. Try: #MotToCM([1,0,-1]): MotToCM:=proc(P) local i, P1: P1:=[]: for i from 1 to nops(P) do if P[i]<>0 then P1:=[op(P1),P[i]]: else P1:=[op(P1),[0,1]]: fi: od: P1: end: #PaperMotToPi(n): Spells out the images of MotToPi for all Motzkin words of length n. Try: #PaperMotToPi(4); PaperMotToPi:=proc(n) local S,i: print(`A table of the images of all Motzkin words of length`, n, `under the NICE mapping that sends them to 321-avoiding permutations without double deficiencies`): print(``): print(`By Shalosh B. Ekhad `): print(``): S:=MotP(n): for i from 1 to nops(S) do print(``): print(S[i], MotToPi(S[i])): print(``): od: end: #PaperMotToPiU(n): Spells out the images of MotToPi for all Motzkin words of length n followed by the Rubey-Stump map. Try: #PaperMotToPiU(4); PaperMotToPiU:=proc(n) local S,i: print(`A table of the images of all Motzkin words of length`, n, `under the NICE and UGLY mapping that sends them to 321-avoiding permutations without double deficiencies`): print(``): print(`By Shalosh B. Ekhad `): print(``): S:=MotP(n): for i from 1 to nops(S) do print(``): print(S[i], MotToPi(S[i]), CMtoSeq(MotToCM(S[i])) ): print(``): od: end: