print(`For a list of procedures, type:`): print(`Help()`): print(`For details about a procedure, type:`): print(`WhatIs(procedurename)`): Help:=proc(): print(`PST(n)`, `ST(n)`, `ST2(n)`, `NuPST(n)`, `NuST(n)`): print(`PSTnb(n)`, `STnb(n)`, `STnb2(n)`, `NuPSTnb(n)`, `NuSTnb(n)`): print(`basepair(st,n)`, `hairpin(st,n)`, `island(st,n)`, `Wt(n,x,y,z)`, `Wtnb(n,x,y,z)`): print(`mij(F,X,x,z,i,j)`, `Opeij(F,x,z,i,j,n,N,Comp)`): print(`THE FOLLOWING PROCEDURES ARE IN PROGRESS (missing y variable)`): print( `PCleverWt(n,x,y,z)`, `CleverWt(n,x,y,z)`, `PCleverWtnb(n,x,y,z)`, `CleverWtnb(n,x,y,z)`): print(`AJBu(X,x,z), AJBuOpe(x,z,n,N)`): end: WhatIs:=proc(procedure): if procedure=PST then print(`PST(n): inputs a positive integer n`): print(`outputs the set of prime RNA secondary structures, i.e. RNA secondary structures where (1,n) is a pair, on the vertices (1,...,n)`): elif procedure=ST then print(`ST(n): inputs a positive integer n`): print(`outputs the set of RNA secondary structures on n vertices, which also list the edges between two consecutive vertices`): elif procedure=ST2 then print(`ST2(n): inputs a positive integer n`): print(`outputs the set of RNA secondary structures on n vertices, where only the base pairs are listed`): elif procedure=PSTnb then print(`PSTnb(n): inputs a positive integer n`): print(`outputs the set of prime RNA secondary structures, i.e. RNA secondary structures where (1,n) is a pair, on the vertices (1,...,n)`): print(`with NO bulge`): elif procedure=STnb then print(`STnb(n): inputs a positive integer n`): print(`outputs the set of RNA secondary structures on n vertices, which also list the edges between two consecutive vertices`): print(`with NO bulge`): elif procedure=STnb2 then print(`STnb2(n): inputs a positive integer n`): print(`outputs the set of RNA secondary structures on n vertices with NO bulge, where only the base pairs are listed`): elif procedure=basepair then print(`basepair(st,n): inputs an RNA secondary structure st on n vertices,`): print(`and outputs the number of base pairs`): print(`e.g. both basepair({{1, 7}, {2, 6}, {8, 10}},10), and`): print(`basepair({{1, 2}, {1, 7}, {2, 3}, {2, 6}, {3, 4}, {4, 5}, {5, 6}, {6, 7}, {7, 8}, {8, 9}, {8,10}, {9, 10}},10)`): print(`output 3`): elif procedure=hairpin then print(`hairpin(st,n): inputs an RNA secondary structure st on n vertices,`): print(`Outputs the number of hairpins,`): print(`i.e. a sequence of unpaired vertices (i+1,i+2,...,j-1) where (i,j) is a base pair`): elif procedure=island then print(`island(st,n): inputs an RNA secondary structure st on n vertices,`): print(`Outputs the number of islands,`): print(`i.e. a sequence of paired vertices (i,i+1,...,j) where either`): print(`1. i-1 and j+1 are both unpaired, 1{} and S2<>{} then S:=S union {seq(seq((s1 union s2) union {seq({i, i+1}, i=1..n-1)}, s1 in S1), s2 in S2)}: elif S2={} then S:=S union {seq(seq(s1 union {seq({i, i+1}, i=1..n-1)}, i=1..n-1), s1 in S1)}; else print(`S1 should not be the empty set so something is wrong with the code`); fi: od: end: # PST2(n): inputs a positive integer n # Outputs the set of prime RNA secondary structures on n vertices, where only the base pairs are listed PST2:=proc(n) local S,s,i: S:=PST(n): S:={seq(s minus {seq({i,i+1},i=1..n-1)},s in S)}: end: # ST2(n): inputs a positive integer n # Outputs the set of RNA secondary structures on n vertices, where only the base pairs are listed ST2:=proc(n) local S,s,i: S:=ST(n): S:={seq(s minus {seq({i,i+1},i=1..n-1)},s in S)}: end: # PSTnb(n): inputs a positive integer n # Outputs the set of prime RNA secondary structures (i.e. secondary structures where (1,n) is a pair) on the vertices (1,...,n) # with NO bulge PSTnb:=proc(n) local S,m,S1,S2,s1,s2,i1,s,i: option remember: if n<2 then RETURN({}): fi: S:={{{1,n}}}: for m from 4 to n-1 do S1:=PSTnb(m-1): S1:=subs({seq(i1=i1+1,i1=1..m-1)},S1): S2:=STnb(n-m-1): S2:=subs({seq(i1=i1+m,i1=1..n-m-1)},S2): if S2={} then S:=S union S1: S:={seq(s union {{1,n}},s in S)}: else S:=S union {seq(seq(s1 union s2 union {{1,n}}, s1 in S1),s2 in S2)}: fi: S:=S union {seq(seq(s1 union s2 union {{1,n}}, s1 in S1),s2 in S2)}: od: S:={seq(s union {seq({i,i+1}, i=1..n-1)},s in S)}: S: end: # STnb(n): inputs a positive integer n # Outputs the set of RNA secondary structures on n vertices, which also list the edges between two consecutive vertices # with NO bulge STnb:=proc(n) local S, S1, S2, m, s1, s2, i1, i, s: option remember: if n<2 then RETURN({}): fi: if n=2 then RETURN({{{1,2}}}): fi: S:=PSTnb(n): for m from 2 to n-1 do S1:=PSTnb(m): if m=2 then S2:=STnb(n-1): S2:=subs({seq(i1=i1+1, i1=1..n-1)}, S2): else S2:=STnb(n-m): S2:=subs({seq(i1=i1+m, i1=1..n-m)}, S2): fi: if S1<>{} and S2<>{} then S:=S union {seq(seq((s1 union s2) union {seq({i, i+1}, i=1..n-1)}, s1 in S1), s2 in S2)}: elif S2={} then S:=S union {seq(seq(s1 union {seq({i, i+1}, i=1..n-1)}, i=1..n-1), s1 in S1)}; else print(`S1 should not be the empty set so something is wrong with the code`); fi: od: S: end: # PSTnb2(n): inputs a positive integer n # Outputs the set of prime RNA secondary structures on n vertices with NO bulge, where only the base pairs are listed PSTnb2:=proc(n) local S,s,i: S:=PSTnb(n): S:={seq(s minus {seq({i,i+1},i=1..n-1)},s in S)}: end: # STnb2(n): inputs a positive integer n # Outputs the set of RNA secondary structures on n vertices with no bulge, where only the base pairs are listed STnb2:=proc(n) local S,s,i: S:=STnb(n): S:={seq(s minus {seq({i,i+1},i=1..n-1)},s in S)}: end: # NuPST(n): inputs a positive integer n # Outputs the number of prime RNA secondary structures (i.e. secondary structures where (1,n) is a pair) on the vertices (1,...,n) NuPST:=proc(n) local s,s1,s2,m: option remember: if n<2 then RETURN(0): fi: s:=0: if n=2 or n=3 or n=4 then RETURN(1): fi: for m from 3 to n-1 do if m=3 then s1:=1: s2:=NuST(n-3): elif m=n-1 then s1:=NuPST(n-2): s2:=1: else s1:=NuPST(m-1): s2:=NuST(n-m-1): fi: if s2=0 then s2:=1: fi: s:=s+s1*s2: od: s: end: # NuST(n): inputs a positive integer n # Outputs the number of RNA secondary structures on n vertices NuST:=proc(n) local s1, s2, m, s: option remember: if n<2 then RETURN(0): fi: if n=2 then RETURN(1): fi: s:=NuPST(n): for m from 2 to n-1 do s1:=NuPST(m): if m=2 then s2:=NuST(n-1): elif m=n-1 then s2:=1: else s2:=NuST(n-m): fi: #if s2=0 then s2:=1: fi: s:=s+s1*s2: #print(m,s): od: s: end: # NuPSTnb(n): inputs a positive integer n # Outputs the number of prime RNA secondary structures (i.e. secondary structures where (1,n) is a pair) on the vertices (1,...,n) # with no bulge NuPSTnb:=proc(n) local s,s1,s2,m: option remember: if n<2 then RETURN(0): fi: s:=1: if n=2 or n=3 then RETURN(1): fi: for m from 4 to n-1 do s1:=NuPSTnb(m-1): s2:=NuSTnb(n-m-1): if s2=0 then s2:=1: fi: s:=s+s1*s2: od: s: end: # NuSTnb(n): inputs a positive integer n # Outputs the number of RNA secondary structures on n vertices with no bulge NuSTnb:=proc(n) local s1, s2, m, s: option remember: if n<2 then RETURN(0): fi: if n=2 then RETURN(1): fi: s:=NuPSTnb(n): for m from 2 to n-1 do s1:=NuPSTnb(m): if m=2 then s2:=NuSTnb(n-1): elif m=n-1 then s2:=1: else s2:=NuSTnb(n-m): fi: if s2=0 then s2:=1: fi: s:=s+s1*s2: od: s: end: # basepair(st,n): inputs an RNA secondary structure st on n vertices, # Outputs the number of base pairs basepair:=proc(st,n)local pair, bp, st1, i: st1:=st minus {seq({i,i+1},i=1..n-1)}: nops(st1): end: # hairpin(st,n): inputs an RNA secondary structure st on n vertices, # Outputs the number of hairpins ## i.e. a sequence of unpaired vertices (i+1,i+2,...,j-1) where (i,j) is a base pair hairpin:=proc(st,n) local hp, st1,PV, n1,i,pair: hp:=0: st1:=st minus {seq({i,i+1},i=1..n-1)}: PV:={seq(op(pair), pair in st1)}: n1:=nops(PV): for pair in st1 do for i from pair[1]+1 to pair[2]-1 do if member(i,PV)=true then i:=pair[2]: elif member(i,PV)=false and i=pair[2]-1 then hp:=hp+1: fi: od: od: hp: end: # island(st,n): inputs an RNA secondary structure st on n vertices, # Outputs the number of islands ## i.e. a sequence of paired vertices (i,i+1,...,j) where either ### 1. i-1 and j+1 are both unpaired, 11 then eq1:=y^2*eq1: fi: eq2:=CleverWtnb(n-m-1,x,y,z): if eq2=0 then eq2:=1: fi: eq:=eq+z*eq1*eq2: od: expand(eq): end: # CleverWtnb(n,x,y,z): inputs positive integer n and variables x, y, z` # Using the "clever" way, computes the weight enumerator found by taking the summation of ## x^hairpin(st)*y^island(st)*z^basepair(st) #over the set of RNA secondary structures st on n vertices with NO bulge CleverWtnb:=proc(n,x,y,z)local eq, eq1, eq2, m: option remember: if n<2 then RETURN(0): fi: if n=2 then RETURN(1): fi: eq:=PCleverWtnb(n,x,y,z): for m from 2 to n-1 do eq1:=PCleverWtnb(m,x,y,z): if eq1<>1 then eq1:=y^2*eq1: fi: if m=2 then eq2:=CleverWtnb(n-1,x,y,z) elif m=n-1 then eq2:=0: else eq2:=CleverWtnb(n-m,x,y,z): fi: if eq2=0 then eq2:=1: fi: eq:=eq+eq1*eq2: od: expand(eq): end: mij:=proc(F,X,x,z,i,j) local f,i1,j1: f:=F: for i1 from 1 to i do f:=x*diff(f,x): od: for j1 from 1 to j do f:=z*diff(f,z): od: subs({x=1,z=1},f): end: Opeij:=proc(F,x,z,i,j,n,N,Comp) local k,f, L, ope, ope1, L1: f:=mij(F,X,x,z,i,j): L:=[seq(coeff(taylor(f, X=0, 100), X, k), k = 1 .. 80)]: ope:=Findrec(L, n, N, Comp): SeqFromRec(ope,n,N,[op(1..degree(ope,N),L)],100): end: AJBu:=proc(X,x,z): 1/2*(-2*X^4*z+X^3*x*z+X^2*z-X^2+2*X-1+(X^6*x^2*z^2-2*X^5*x*z^2-2*X^5*x*z+4*X^4* x*z+X^4*z^2-2*X^4*z-2*X^3*x*z+X^4+4*X^3*z-4*X^3-2*X^2*z+6*X^2-4*X+1)^(1/2))/X^2 /z/(X-1): end: AJBuOpe:=proc(x,z,n,N): -x^2*z^2*(n+1)/(n+10)*N+x*z*(n*x*z+2*n*z+x*z+2*n+5*z+5)/(n+10)*N^2-(2*n*x*z^2+6 *n*x*z+n*z^2+5*x*z^2-2*n*z+21*x*z+4*z^2+n-8*z+4)/(n+10)*N^3+(6*n*x*z+n*z^2-6*n* z+27*x*z+4*z^2+5*n-30*z+26)/(n+10)*N^4-(2*n*x*z-6*n*z+11*x*z+10*n-36*z+64)/(n+ 10)*N^5-2*(n*z-5*n+7*z-38)/(n+10)*N^6-(5*n+44)/(n+10)*N^7+N^8: end: