cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

Showing 1-4 of 4 results.

A062869 Triangle read by rows: For n >= 0, k >= 0, T(n,k) is the number of permutations pi of n such that the total distance Sum_i abs(i-pi(i)) = 2k. Equivalently, k = Sum_i max(i-pi(i),0).

Original entry on oeis.org

1, 1, 1, 1, 1, 2, 3, 1, 3, 7, 9, 4, 1, 4, 12, 24, 35, 24, 20, 1, 5, 18, 46, 93, 137, 148, 136, 100, 36, 1, 6, 25, 76, 187, 366, 591, 744, 884, 832, 716, 360, 252, 1, 7, 33, 115, 327, 765, 1523, 2553, 3696, 4852, 5708, 5892, 5452, 4212, 2844, 1764, 576, 1, 8, 42, 164, 524
Offset: 0

Views

Author

Olivier Gérard, Jun 26 2001

Keywords

Comments

Number of possible values is 1,2,3,5,7,10,13,17,21,... = A033638. Maximum distance divided by 2 is the same minus one, i.e., 0,1,2,4,6,9,12,16,20,... = A002620.
T. Kyle Petersen and Bridget Eileen Tenner proved that T(n,k) is also the number of permutations of n for which the sum of descent differences equals k. - Susanne Wienand, Sep 11 2014

Examples

			Triangle T(n,k) begins:
  1;
  1;
  1, 1;
  1, 2,  3;
  1, 3,  7,  9,   4;
  1, 4, 12, 24,  35,  24,  20;
  1, 5, 18, 46,  93, 137, 148, 136, 100,  36;
  1, 6, 25, 76, 187, 366, 591, 744, 884, 832, 716, 360, 252;
  ...
(4,3,1,2) has distances (3,1,2,2), sum is 8 and there are 3 other permutations of degree 4 with this sum.
		

References

  • D. E. Knuth, The Art of Computer Programming, vol. 3, (1998), page 22 (exercise 28) and page 597 (solution and comments).

Crossrefs

Row sums give A000142.
T(2n,n) gives A072948.
A357329 is a sub-triangle.

Programs

  • Maple
    # The following program yields the entries of the specified row n
    n := 9: with(combinat): P := permute(n): excsum := proc (p) (1/2)*add(abs(p[i]-i), i = 1 .. nops(p)) end proc: f[n] := sort(add(t^excsum(P[j]), j = 1 .. factorial(n))): seq(coeff(f[n], t, j), j = 0 .. floor((1/4)*n^2)); # Emeric Deutsch, Apr 02 2010
    # Maple program using the g.f. given by Guay-Paquey and Petersen:
    g:= proc(h, n) local i, j; j:= irem(h, 2, 'i');
           1-`if`(h=n, 0, (i+1)*z*t^(i+j)/g(h+1, n))
        end:
    T:= n-> (p-> seq(coeff(p, t, k), k=0..degree(p)))
            (coeff(series(1/g(0, n), z, n+1), z, n)):
    seq(T(n), n=0..10);  # Alois P. Heinz, May 02 2014
  • Mathematica
    g[h_, n_] := Module[{i, j}, {i, j} = QuotientRemainder[h, 2]; 1 - If[h == n, 0, (i + 1)*z*t^(i + j)/g[h + 1, n]]]; T[n_] := Function[p, Table[ Coefficient[p, t, k], {k, 0, Exponent[p, t]}]][SeriesCoefficient[ 1/g[0, n], {z, 0, n}]]; Table[T[n], {n, 1, 10}] // Flatten (* Jean-François Alcover, Jan 07 2016, after Alois P. Heinz *)
    f[i_] := If[i == 1, 1, -(i-1)^2 t^(2i - 3) z^2];
    g[i_] := 1 - (2i - 1) t^(i-1) z;
    cf = ContinuedFractionK[f[i], g[i], {i, 1, 5}];
    CoefficientList[#, t]& /@ CoefficientList[cf + O[z]^10, z] // Rest // Flatten (* Jean-François Alcover, Nov 25 2018, after Mathieu Guay-Paquet *)
  • Sage
    # The following Sage program
    # yields the entries of the first n rows
    # as a list of lists
    def get_first_rows(n):
        R, t = PolynomialRing(ZZ, 't').objgen()
        S, z = PowerSeriesRing(R, 'z').objgen()
        gf = S(1).add_bigoh(1)
        for i in srange(n, 0, -1):
            a = (i+1) // 2
            b = i // 2
            gf = 1 / (1 - a * t^b * z * gf)
        return [list(row) for row in gf.shift(-1)]
    # Mathieu Guay-Paquet, Apr 30 2014

Formula

From Mathieu Guay-Paquet, Apr 30 2014: (Start)
G.f.: 1/(1-z/(1-t*z/(1-2*t*z/(1-2*t^2*z/(1-3*t^2*z/(1-3*t^3*z/(1-4*t^3*z/(1-4*t^4*z/(...
This is a continued fraction where the (2i)th numerator is (i+1)*t^i*z, and the (2i+1)st numerator is (i+1)*t^(i+1)*z for i >= 0. The coefficient of z^n gives row n, n >= 1, and the coefficient of t^k gives column k, k >= 0. (End)
From Alois P. Heinz, Oct 02 2022: (Start)
Sum_{k=0..floor(n^2/4)} k * T(n,k) = A005990(n).
Sum_{k=0..floor(n^2/4)} (-1)^k * T(n,k) = A009006(n). (End).

Extensions

T(0,0)=1 prepended by Alois P. Heinz, Oct 03 2022

A072948 Number of permutations p of {1,2,3,...,2n} such that Sum_{k=1..2n} abs(k-p(k)) = 2n.

Original entry on oeis.org

1, 1, 7, 46, 327, 2350, 17222, 127508, 952299, 7159090, 54107670, 410729140, 3129241874, 23914923644, 183254996828, 1407497158968, 10832287881639, 83516348514010, 644935028526278, 4987483388201684, 38619491922881310, 299390833303838980, 2323441087636417604
Offset: 0

Views

Author

Benoit Cloitre, Aug 20 2002

Keywords

Comments

This is impossible if the number of symbols is odd.

Crossrefs

Programs

  • Mathematica
    f[n_] := If[n == 1, 1, Floor[n/2] t^Floor[(n - 1)/2] z];
    F[t_, z_] = ContinuedFractionK[f[i], 1, {i, 1, 8}];
    a[n_] := a[n] = SeriesCoefficient[F[t, z], {z, 0, 2 n}, {t, 0, n}];
    Table[Print[n, " ", a[n]]; a[n], {n, 1, 15}] (* Jean-François Alcover, Feb 25 2019 *)
  • PARI
    a(n)=sum(k=1,n!,if(sum(i=1,n,abs(i-component(numtoperm(n,k),i)))-n,0,1))

Formula

a(n) = A062869(2n,n).

Extensions

a(5) from Michel ten Voorde Jun 13 2003
a(6) from Ryan Propper, Mar 26 2007
a(7)-a(8) from Sean A. Irvine, Sep 22 2009
a(9)-a(12) from Robert Gerbicz, Nov 27 2010
a(13)-a(16) from Alois P. Heinz, May 02 2014 using formula given by Guay-Paquey and Petersen
a(17)-a(22) from Alois P. Heinz, Oct 01 2022

A263898 Number of length n arrays of permutations of 0..n-1 with each element moved by -n to n places and the total absolute value of displacements not greater than 2*(n-1).

Original entry on oeis.org

1, 2, 6, 20, 76, 300, 1252, 5324, 23124, 101548, 450320, 2010108, 9022704, 40674180, 184026168, 835121676, 3799670208, 17326530900, 79163726536, 362316871964, 1660794058176, 7623209945860, 35034482102360, 161190157871724, 742373773430192, 3422236265162068
Offset: 1

Views

Author

R. H. Hardin, Oct 29 2015

Keywords

Examples

			Some solutions for n=7:
..0....2....4....4....2....4....1....0....5....2....3....0....1....0....0....3
..1....1....2....3....5....2....2....1....1....1....2....1....2....1....6....2
..2....5....3....1....1....1....0....3....0....0....1....4....4....5....2....0
..3....0....0....2....0....0....5....6....3....6....4....5....0....6....4....4
..6....3....1....0....3....3....4....4....4....4....0....2....5....4....3....1
..4....4....5....5....4....5....6....5....2....5....5....3....6....2....5....6
..5....6....6....6....6....6....3....2....6....3....6....6....3....3....1....5
		

Crossrefs

Diagonal of A263905.
Row sums of A357329.
Cf. A263905.

Extensions

a(21)-a(26) from Alois P. Heinz, Oct 01 2022

A356257 Irregular triangle: row n consists of the frequencies of positive distances between permutations P and reverse(P), as P ranges through the permutations of (1, 2, ..., n); see Comments.

Original entry on oeis.org

1, 2, 4, 2, 8, 16, 24, 16, 32, 32, 16, 48, 192, 192, 288, 192, 144, 576, 576, 576, 576, 960, 576, 576, 288, 384, 2304, 4608, 7680, 9216, 6912, 9216, 1920, 1536, 9216, 9216, 16128, 18432, 29184, 26112, 36864, 32256, 41472, 23040, 39168, 32256, 18432, 18432
Offset: 1

Views

Author

Clark Kimberling, Oct 04 2022

Keywords

Comments

For n >= 1, let P = (p(1),p(2),...,p(n)) and Q = (q(1),q(2),...,q(n)) be permutations of (1,2,...,n). The distance between P and Q is defined by |p(1)-q(1)| + |p(2)-q(2)| + ... + |p(n)-q(n)|. For fixed n >= 1, let m be the least distance that occurs and let M be the greatest. If n is odd, let S = (m, m+2, m+4, ..., M); if n > 2 is even, let S = (m, m+4, m+8, ..., M). Then S gives all the positive distances that occur, and the frequencies in row n of the array account for the distances in S. Four open questions about the numbers in row n follow. (1) How many are there? (2) What are the first and last? (3) What are the least and greatest? (4) What is the greatest common divisor?

Examples

			First 8 rows:
    1
    2
    4      2
    8     16
   24     16    32    32    16
   48    192   192   288
  192    144   576   576   576   576    960    576    576    288
  384   2304  4608  7680  9216  6912   9216
For n=3, the 6 permutations and their reverses are represented by
  123 132 213 231 212 321
  321 231 312 132 213 123,
so the 6 distances are 4,2,2,2,2,4, whence row 3 accounts for four 2's and two 4's.
		

Crossrefs

Cf. A000142 (row sums), A357329.

Programs

  • Mathematica
    p[n_] := p[n] = Permutations[Range[n]];
    f[n_, k_] := f[n, k] = Abs[p[n][[k]] - Reverse[p[n][[k]]]]
    c[n_, k_] := c[n, k] = Total[f[n, k]]
    t[n_] := t[n] = Table[c[n, k], {k, 1, n!}]
    z = 6; Table[t[n], {n, 1, z}]
    u = Table[Count[t[n], k], {n, 1, z}, {k, Min[t[n]], Max[t[n]], 2}]
    v[n_] := Select[u[[n]], # > 0 &]
    w = Table[v[n], {n, 1, z}]
    TableForm[w] (* 356257 array *)
    Flatten[w]   (* 356257 sequence *)
Showing 1-4 of 4 results.