#1342Avoid Help:=proc() if args=NULL then print(`a(p,n), b(p,i,n), c(p,i,j,n)`): elif args='a' then print(`a(p,n) gives the number of 1342-avoiding permutations of length n with no proper prefix of length at least p whose elements all exceed all the following elements`): elif args='b' then print(`b(p,i,n) gives the number of 1342-avoiding permutations of length n beginning with i with no proper prefix of length at least p whose elements all exceed all the following elements`): elif args='c' then print(`c(p,i,j,n) gives the number of 1342-avoiding permutations of length n beginning with ij with no proper prefix of length at least p whose elements all exceed all the following elements`): fi: end: a := proc(p,n) local k, output: option remember: output := 0: for k from 1 to n-p-1 do output := output + b(n-k+1,k,n): od: for k from max(1,n-p) to n do output := output + b(p,k,n): od: return(output): end: b := proc(p,i,n) local k, output: option remember: if n = 1 then return(1): end: if p = 0 then return(0): fi: if p = 1 and n = i then return(0): fi: if i <= n-p then return(b(n-i+1,i,n)): fi: output := b(n-1,1,n-1): for k from 2 to n-p-1 do output := output + b(n-k+1-1,k,n-1): od: for k from max(2,n-p) to min(i,n-1) do output := output + b(p-1,k,n-1): od: for k from i+2 to n do output := output + c(p,i,k,n): od: return(output): end: c := proc(p,i,j,n) local k, output: option remember: if p = 0 then return(0): fi: if i <= n-p then return(c(n-i+1,i,n)): fi: output := 0: if j - i < 2 then print(`Something's wrong: j - i <2 in c`): fi: output := output + b(j-i-1,i,j-1)*b(n-j+1,1,n-j+1): for k from 2 to n-p-1 do output := output + b(j-i-1,i-k+1,j-k)*b(n-j+1,k,n-(j-k)): od: for k from max(2,n-p) to i do output := output + b(j-i-1,i-k+1,j-k)*b(p-(j-k),k,n-(j-k)): od: return(output): end: