# Complete Maple program for A057113 using code collected from other sequences. # This code was used to produce the b-file. with(group); factorial_base := proc(nn) local n, a, d, j, f; n := nn; if(0 = n) then RETURN([0]); fi; a := []; f := 1; j := 2; while(n > 0) do d := floor(`mod`(n, (j*f))/f); a := [d, op(a)]; n := n - (d*f); f := j*f; j := j+1; od; RETURN(a); end; cdr := proc(l) if 0 = nops(l) then ([]) else (l[2..nops(l)]); fi; end; fac_base := n -> fac_base_aux(n, 2); fac_base_aux := proc(n, i) if(0 = n) then RETURN([]); else RETURN([op(fac_base_aux(floor(n/i), i+1)), (n mod i)]); fi; end; PermRevLexRank := proc(pp) local p, n, i, j, r; p := pp; n := nops(p); r := 0; for j from n by -1 to 1 do r := r + (((j-p[j])*((j-1)!))); for i from 1 to (j-1) do if(p[i] > p[j]) then p[i] := p[i]-1; fi; od; od; RETURN(r); end; adj_tp_seq := proc(n) local fl, fd, v; fl := fac_base(n); fd := fl[1]; if((1 = fd) and (0 = convert(cdr(fl), `+`))) then RETURN(nops(fl)); fi; if(n < 6) then RETURN(2 - (`mod`(n, 2))); fi; if((0 = convert(cdr(fl), `+`)) and (n < 24)) then RETURN((nops(fl)+1)-fd); fi; if(n < 18) then if(0 = (`mod`(n, 2))) then RETURN(2); else RETURN(4-(`mod`(n, 4))); fi; else if(n < 24) then RETURN(2+(`mod`(n, 2))); else if(n < 120) then if(0 = convert(cdr(fl), `+`)) then RETURN(nops(fl)); else RETURN(adj_tp_seq(`mod`(n, 24))); fi; else if(n < 720) then if(125 = n) then RETURN(5); fi; v := (`mod`(n, 5)); if(0 = v) then v := (n-125)/5; RETURN(adj_tp_seq(v)+(`mod`(v+1, 2))); else if(5 > (`mod`(n, 10))) then RETURN(5-v); else RETURN(v); fi; fi; else if(0 = convert(cdr(fl), `+`)) then RETURN(nops(fl)); fi; RETURN(adj_tp_seq(`mod`(n, 720))); fi; fi; fi; fi; end; atp_perm_ranks := proc(upto_n) local t, a, p, i, k; p := convert([1], 'disjcyc'); k := nops(factorial_base(upto_n))+1; a := []; for i from 1 to upto_n do a := [op(a), PermRevLexRank(convert(p, 'permlist', k))]; t := adj_tp_seq(i); p := mulperms([[t, t+1]], p); od; RETURN(a); end; perm_ranks_seq := atp_perm_ranks(120);