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-8 of 8 results.

A301897 Number of permutations b of length n that satisfy the Diaconis-Graham inequality I_n(b) + EX_n(b) <= D_n(b) with equality.

Original entry on oeis.org

1, 2, 6, 23, 103, 511, 2719, 15205, 88197, 526018, 3206206, 19885911, 125107063, 796453594, 5121305414, 33213428285, 216998830397, 1426936199824, 9436710005524, 62723077297135, 418784925848463, 2807458708620337, 18889686239933521, 127520180043751313, 863473397167656913, 5863055250124397156
Offset: 1

Views

Author

Petros Hadjicostas, Mar 28 2018

Keywords

Comments

Let S_n be the symmetric group of order n. For permutation b = (b_1,...,b_n) in S_n, let I_n(b) be the number of inversions in b; EX_n(b) be the smallest number of transpositions needed to transform b into the identity (1,...,n); and D_n(b) = Sum_{1 <= i <= n} |b_i - i|. Cayley (1849) proved that EX_n(b) equals n minus the number of cycles in permutation b. In the references for sequence A062869, the quantity D_n(b) is called the total distance of b or the total displacement of b.
Diaconis and Graham (1977) proved that I_n(b) + EX_n(b) <= D_n(b) <= 2*I_n(b), while Hadjicostas and Monico (2015) proved that D_n(b) <= I_n(b) + EX_n(b) + floor(n/2)*(floor(n/2) - 1). Here, a(n) equals the number of permutations b in S_n that satisfy the equality I_n(b) + EX_n(b) = D_n(b).
Let M_n be the set of all permutations b in S_n that satisfy I_n(b) + EX_n(b) = D_n(b). We describe how to construct M_n recursively. Let M_1 = S_1. For n >= 2, construct set M_{n1} from M_{n-1} as follows: Take a permutation c in M_{n-1} and an integer i in {1,...,n-1} and such that either the number of integers in c to the left of c_i that are greater than c_i is zero or the number of integers in c to the right of c_i that are less than c_i is zero. Replace c_i with n and put c_i at the end to form permutation b in M_{n1}. Construct set M_{n2} from M_{n-1} as follows: take a permutation c in M_{n-1} and attach n at the end to form permutation b in M_{n2}. Finally, define M_n as the union of sets M_{n1} and M_{n2}. See Hadjicostas and Monico (2013) for more details.
Diaconis and Graham (1977) and Hadjicostas and Monico (2013) examined when I_n(b) + EX_n(b) = D_n(b) = 2*I_n(b) (i.e., when both inequalities hold as equalities simultaneously). This happens if and only if I_n(b) = EX_n(b), which in turn happens if and only if permutation b belongs to M_n and has no 3-inversion (i.e., it avoids the pattern 321). A 3-inversion in b is a triple of integers (i,j,k) in {1,...,n} such that i < j < k but b_i > b_j > b_k. The number of permutations in S_n that satisfy both equalities is Fibonacci(2n-1) = A001519(n) = A000045(2*n-1).
In the language of the Petersen-Tenner reference, these are permutations for which the depth is equal to the average of length and reflection length. - Joel B. Lewis, Sep 08 2019
Weiner's g.f. (A(x)), see formula section, follows from either Theorem 6.5 of Cornwell and McNew (G(x)) or Corollary 1.2 of Woo (G(x)) by setting A(x) = G(x) - 1. - G. C. Greubel, Feb 17 2022

Examples

			For n=4, the only permutation b that does not satisfy I_4(b) + EX_4(b) = D_4(b) is b = 3412. (Here, b = 3412 means b_1 = 3, b_2 = 4, b_3 = 1, b_4 = 2. We do not use cycle notation.) We have I_4(b) = 4, EX_4(b) = 4-2 = 2, and D_4(b) = 8, and hence I_4(b) + EX_4(b) = 6 < D_4(b) = 8.
For n=5, the 5! - a(5) = 17 permutations b that do not satisfy I_5(b) + EX_5(b) = D_5(b) are the following: 14523, 24513, 34125, 34152, 34512, 34521, 35124, 35142, 35412, 41523, 42513, 43512, 45123, 45132, 45213, 45312, 54123.
		

Crossrefs

Column k=0 of A369518 (with different offset).

Programs

  • Magma
    A301897:= func< n | n lt 3 select Factorial(n) else  Catalan(n) + (&+[ (&+[ Binomial(n,k-1)*Binomial(n-1,k+j)*Binomial(n-k+j-1,j-1)/j: j in [1..n-k-1]]): k in [1..n-2]]) >;
    [A301897(n): n in [1..40]]; // G. C. Greubel, Feb 21 2022
    
  • Mathematica
    a[n_]:= a[n]= If[n<2, n, 2*a[n-1] + Sum[a[k+2]*a[n-k-1] + (Sum[a[k+1-j]*a[j], {j, 0, k}] - 3*a[k+2] + 4*a[k+1])*a[n-k-2], {k, 0, n-3}]];
    Table[a[n], {n, 40}] (* G. C. Greubel, Feb 20 2022 *)
  • PARI
    upto(n)=my(v1); v1=vector(n+1, i, 0); v1[2]=1; for(i=2, n, v1[i+1]=2*v1[i] + sum(k=0, i-3, v1[k+3]*v1[i-k] + v1[i-k-1]*(4*v1[k+2] - 3*v1[k+3] + sum(j=0, k, v1[j+1]*v1[k-j+2])))); v1=vector(n, i, v1[i+1]) \\ Mikhail Kurkov, Aug 01 2023
  • Sage
    @CachedFunction
    def a(n):
        if (n<2): return n
        else: return 2*a(n-1) + sum(a(k+2)*a(n-k-1) + (sum(a(j)*a(k-j-1) for j in (0..k)) - 3*(k+2) + 4*a(k+1))*a(n-k-2) for k in (0..n-3))
    [a(n) for n in (1..40)] # G. C. Greubel, Feb 20 2022
    

Formula

a(n) <= 1 + Sum_{m=2..n} ((m-1)!*Sum_{k=1..m-1} (2/k) - Sum_{k=1..m-1} (k-1)!*(m-k-1)!).
a(n) >= 1 + Sum_{m=2..n} (m-1)*Fibonacci(2*m-3) = 1 + Sum_{2 <= m <= n} (m-1)*A001519(m-1). (For a proof of this lower bound, see the links above.)
G.f.: A(x) satisfies 0 = x^2*A(x)^3 + (4*x^2-3*x+1)*A(x)^2 + (5*x^2-3*x)*A(x) + 2*x^2. - Michael D. Weiner, Jun 29 2020
a(n) = binomial(2*n,n)/(n+1) + Sum_{k=1..n-2} Sum_{j=1..n-1-k} binomial(n,k-1)*binomial(n-1,k+j)*binomial(n-k+j-1,j-1)*(1/j). - Michael D. Weiner, Jun 30 2020
If, in Weiner's formula for a(n), we replace 1/j with (-1)^j/j, then we get the Motzkin numbers A001006. That is A001006(n) = binomial(2*n,n)*1/(n+1) + Sum_{k=1..n-2} Sum_{j=1..n-1-k} binomial(n,k-1)*binomial(n-1,k+j)*binomial(n-k+j-1,j-1)*(-1)^j/j for n >= 1. - Petros Hadjicostas, Jul 01 2020
From G. C. Greubel, Feb 20 2022: (Start)
a(n) = 2*a(n-1) + Sum_{k=0..n-3} ( a(k+2)*a(n-k-1) + ((Sum_{j=0..k} a(j)*a(k-j+1)) - 3*a(k+2) + 4*a(k+1))*a(n-k-2) ), with a(0) = 0, a(1) = 1.
a(n) = 1 + Sum_{k=1..n-1} ((-2)^(n-k-1)/(n-k))*binomial(n, k-1)*JacobiP(n-k-1, 2*k -2*n+1, k; 0), where JacobiP(n, a, b; x) is the Jacobi polynomial. (End)
D-finite with recurrence 3*(n+2)*(n-1)*a(n) +6*(10*n+9)*(n-2)*a(n-1) +(-421*n^2+1259*n-348)*a(n-2) +18*(72*n^2-334*n+369)*a(n-3) +(-1801*n^2+11339*n-17940)*a(n-4) -30*(n-5)*(10*n-51)*a(n-5) +25*(n-5)*(n-6)*a(n-6)=0. - R. J. Mathar, Jun 25 2023
a(n) ~ sqrt((1 + s)*(-3*s + 2*r*(2 + 3*s + s^2)) / (1 - 3*r + r^2*(4 + 3*s))) / (2*sqrt(Pi)*n^(3/2)*r^(n - 1/2)), where r = 0.13826667124150045791560993482... and s = 0.23874607068542101537529085629... are positive real roots of the system of equations s^2 + r^2*(1 + s)^2*(2 + s) = 3*r*s*(1 + s), 2*s + r^2*(5 + 8*s + 3*s^2) = 3*r*(1 + 2*s). - Vaclav Kotesovec, Jul 05 2024

Extensions

Terms a(15) onward added by G. C. Greubel, Feb 20 2022

A357329 Triangular array read by rows: T(n, k) = number of occurrences of 2k as a sum |1 - p(1)| + |2 - p(2)| + ... + |n - p(n)|, where (p(1), p(2), ..., p(n)) ranges through the permutations of (1,2,...,n), for n >= 1, 0 <= k <= n-1.

Original entry on oeis.org

1, 1, 1, 1, 2, 3, 1, 3, 7, 9, 1, 4, 12, 24, 35, 1, 5, 18, 46, 93, 137, 1, 6, 25, 76, 187, 366, 591, 1, 7, 33, 115, 327, 765, 1523, 2553, 1, 8, 42, 164, 524, 1400, 3226, 6436, 11323, 1, 9, 52, 224, 790, 2350, 6072, 13768, 27821, 50461, 1, 10, 63, 296, 1138, 3708, 10538, 26480, 59673, 121626, 226787
Offset: 1

Views

Author

Clark Kimberling, Sep 24 2022

Keywords

Comments

In the Name, (1,2,...,n) can be replaced by any of its permutations. The first 10 row sums are the first 10 terms of A263898.

Examples

			First 8 rows:
  1
  1     1
  1     2     3
  1     3     7     9
  1     4    12    24     35
  1     5    18    46     93     137
  1     6    25    76    187     366    591
  1     7    33   115    327     765   1523    2553
For n=3, write
  123   123   123   123   123   123
  123   132   213   231   312   312
  000   011   110   112   211   211,
where row 3 represents |1 - p(1)| + |2 - p(2)| + |3 - p(n)| for the 6 permutations (p(1), p(2), p(2)) in row 3. The sums in row 3 are 0,2,2,4,4,4, so that the numbers 0, 2, 4 occur with multiplicities 1, 2, 3, as in row 3 of the array.
		

Crossrefs

Subtriangle of A062869.
T(2n,n) gives A072948 (for n>0).

Programs

  • Maple
    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..n-1))
            (coeff(series(1/g(0, n), z, n+1), z, n)):
    seq(T(n), n=1..12);  # Alois P. Heinz, Oct 02 2022
  • Mathematica
    p[n_] := p[n] = Permutations[Range[n]];
    f[n_, k_] := f[n, k] = Abs[p[n][[k]] - Range[n]]
    c[n_, k_] := c[n, k] = Total[f[n, k]]
    t[n_] := Table[c[n, k], {k, 1, n!}]
    u = Table[Count[t[n], 2 m], {n, 1, 10}, {m, 0, n - 1}]  (* A357329, array *)
    Flatten[u]  (* A357329, sequence *)

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

A369596 Number T(n,k) of permutations of [n] whose fixed points sum to k; triangle T(n,k), n>=0, 0<=k<=A000217(n), read by rows.

Original entry on oeis.org

1, 0, 1, 1, 0, 0, 1, 2, 1, 1, 1, 0, 0, 1, 9, 2, 2, 3, 3, 2, 1, 1, 0, 0, 1, 44, 9, 9, 11, 11, 13, 5, 5, 4, 4, 2, 1, 1, 0, 0, 1, 265, 44, 44, 53, 53, 62, 64, 29, 22, 24, 16, 16, 8, 6, 5, 4, 2, 1, 1, 0, 0, 1, 1854, 265, 265, 309, 309, 353, 362, 406, 150, 159, 126, 126, 93, 86, 44, 36, 29, 19, 19, 9, 7, 5, 4, 2, 1, 1, 0, 0, 1
Offset: 0

Views

Author

Alois P. Heinz, Mar 02 2024

Keywords

Examples

			T(3,0) = 2: 231, 312.
T(3,1) = 1: 132.
T(3,2) = 1: 321.
T(3,3) = 1: 213.
T(3,6) = 1: 123.
T(4,0) = 9: 2143, 2341, 2413, 3142, 3412, 3421, 4123, 4312, 4321.
Triangle T(n,k) begins:
   1;
   0, 1;
   1, 0, 0,  1;
   2, 1, 1,  1,  0,  0, 1;
   9, 2, 2,  3,  3,  2, 1, 1, 0, 0, 1;
  44, 9, 9, 11, 11, 13, 5, 5, 4, 4, 2, 1, 1, 0, 0, 1;
  ...
		

Crossrefs

Column k=0 gives A000166.
Column k=3 gives A000255(n-2) for n>=2.
Row sums give A000142.
Row lengths give A000124.
Reversed rows converge to A331518.
T(n,n) gives A369796.

Programs

  • Maple
    b:= proc(s) option remember; (n-> `if`(n=0, 1, add(expand(
          `if`(j=n, x^j, 1)*b(s minus {j})), j=s)))(nops(s))
        end:
    T:= n-> (p-> seq(coeff(p, x, i), i=0..degree(p)))(b({$1..n})):
    seq(T(n), n=0..7);
    # second Maple program:
    g:= proc(n) option remember; `if`(n=0, 1, n*g(n-1)+(-1)^n) end:
    b:= proc(n, i, m) option remember; `if`(n>i*(i+1)/2, 0,
         `if`(n=0, g(m), b(n, i-1, m)+b(n-i, min(n-i, i-1), m-1)))
        end:
    T:= (n, k)-> b(k, min(n, k), n):
    seq(seq(T(n, k), k=0..n*(n+1)/2), n=0..7);
  • Mathematica
    g[n_] := g[n] = If[n == 0, 1, n*g[n - 1] + (-1)^n];
    b[n_, i_, m_] := b[n, i, m] = If[n > i*(i + 1)/2, 0,
       If[n == 0, g[m], b[n, i-1, m] + b[n-i, Min[n-i, i-1], m-1]]];
    T[n_, k_] := b[k, Min[n, k], n];
    Table[Table[T[n, k], {k, 0, n*(n + 1)/2}], {n, 0, 7}] // Flatten (* Jean-François Alcover, May 24 2024, after Alois P. Heinz *)

Formula

Sum_{k=0..A000217(n)} k * T(n,k) = A001710(n+1) for n >= 1.
Sum_{k=0..A000217(n)} (1+k) * T(n,k) = A038720(n) for n >= 1.
Sum_{k=0..A000217(n)} (n*(n+1)/2-k) * T(n,k) = A317527(n+1).
T(n,A161680(n)) = A331518(n).
T(n,A000217(n)) = 1.

A062870 Number of permutations of degree n with greatest sum of distances.

Original entry on oeis.org

1, 1, 1, 3, 4, 20, 36, 252, 576, 5184, 14400, 158400, 518400, 6739200, 25401600, 381024000, 1625702400, 27636940800, 131681894400, 2501955993600, 13168189440000, 276531978240000, 1593350922240000, 36647071211520000, 229442532802560000, 5736063320064000000
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,... which I conjecture to be A033638. Maximum distance divided by 2 is the same minus one, i.e., 0,1,2,4,6,9,12,16,20,... which seems to be A002620.

Examples

			(4,3,1,2) has distances (3,1,2,2), sum is 8 and there are 3 other permutations of degree 4 {3, 4, 1, 2}, {3, 4, 2, 1}, {4, 3, 2, 1} with this sum which is the maximum possible.
		

Crossrefs

A007590(n) is the greatest sum of distances for a permutation of degree n. - Dmitry Kamenetsky, Nov 14 2017

Programs

  • Maple
    a:= proc(n) option remember; `if`(n<2, 1+n*(n-1),
          (n*((n-1)^2*(3*n-4)*a(n-2)-4*a(n-1)))/(4*(n-1)*(3*n-7)))
        end:
    seq(a(n), n=0..30);  # Alois P. Heinz, Jan 16 2014
  • Mathematica
    a[n_?EvenQ] := (n/2)!^2; a[n_?OddQ] := n*((n-1)/2)!^2; Table[a[n], {n, 0, 30}] (* Jean-François Alcover, Apr 15 2015 *)
  • PARI
    for(k=0,20,print1((2*k+1)*k!^2","(k+1)!^2",")) \\ Herman Jamke (hermanjamke(AT)fastmail.fm), Dec 27 2007

Formula

a(n) = (n/2)!^2 if n is even else n*((n-1)/2)!^2, cf. A092186. - Conjectured by Vladeta Jovovic, Aug 21 2007; proved (see the link) by Max Alekseyev, Aug 21 2007
a(n) = A062869(n,floor(n^2/4)) for n>=1. - Alois P. Heinz, Oct 02 2022

Extensions

a(10)-a(14) from Hugo Pfoertner, Sep 23 2004
More terms from Herman Jamke (hermanjamke(AT)fastmail.fm), Dec 27 2007

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

Original entry on oeis.org

1, 0, 0, 0, 4, 24, 148, 744, 3696, 17640, 83420, 390144, 1817652, 8438664, 39117852, 181136304, 838372452, 3879505944, 17952463180, 83086702848, 384626048292, 1781018204328, 8249656925564, 38225193868560, 177179811427796, 821544012667704, 3810648054607212
Offset: 0

Views

Author

Benoit Cloitre, Aug 20 2002

Keywords

Comments

a(n) is always even for n>=1. More generally, A062869(n,k) is even whenever k >= n. - Conjectured by Franklin T. Adams-Watters, proved by Max Alekseyev. (see link in A062869)

Crossrefs

Programs

  • Maple
    with(linalg): f := (i,j) -> x^(abs(i-j)):for n from 1 to 17 do A := matrix(n,n,f): printf("%d,",coeff(permanent(A),x,2*n)) od: # Herman Jamke (hermanjamke(AT)fastmail.fm), Apr 27 2008
  • Mathematica
    g[h_, n_] := 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]]]; a[n_ /; n<4] = 0; a[n_] := SeriesCoefficient[1/g[0, n], {z, 0, n}, {t, 0, n}]; Table[an = a[n]; Print["a(", n, ") = ", an]; an, {n, 1, 26}] (* Jean-François Alcover, Jan 07 2016, after Alois P. Heinz *)
  • PARI
    a(n)=sum(k=1,n!,if(sum(i=1,n,abs(i-component(numtoperm(n,k),i)))-2*n,0,1))

Extensions

More terms from Herman Jamke (hermanjamke(AT)fastmail.fm), Apr 27 2008
a(18)-a(21) from Robert Gerbicz, Nov 21 2010
a(22)-a(26) from Alois P. Heinz, May 02 2014 using formula given by Guay-Paquey and Petersen
a(0)=1 prepended by Alois P. Heinz, Oct 01 2022

A382570 a(n) is the number of shallow permutations of length n that avoid 231.

Original entry on oeis.org

1, 1, 2, 5, 14, 41, 121, 355, 1037, 3025, 8824, 25746, 75130, 219246, 639805, 1867066, 5448412, 15899370, 46397015, 135394275, 395103258, 1152977744, 3364582879, 9818418346, 28651794889, 83610752932, 243990229487, 712004497223, 2077748790043, 6063220178075
Offset: 0

Views

Author

Kassie Archer, Mar 31 2025

Keywords

Comments

A shallow permutation is a permutation that satisfies the lower bound of the Diaconis-Graham inequality (i.e., so that the total displacement is equal to the sum of the length and reflection length).

Crossrefs

Programs

  • Mathematica
    CoefficientList[Series[(1 - 3*x + 2*x^2 - x^3 - x^4 - x^5)/(1 - 4*x + 4*x^2 - 2*x^3 -x^4 - x^5), {x, 0, 29}], x] (* Michael De Vlieger, Apr 01 2025 *)

Formula

G.f: (1-3*x+2*x^2-x^3-x^4-x^5)/(1-4*x+4*x^2-2*x^3-x^4-x^5).

A382574 a(n) is the number of shallow permutations of length n that avoid 123.

Original entry on oeis.org

1, 1, 2, 5, 13, 35, 90, 225, 525, 1181, 2526, 5289, 10729, 21583, 42566, 83909, 163225, 318713, 616122, 1198029, 2309829, 4483643, 8635314, 16750761, 32247973, 62538517, 120378518, 233428337, 449294497, 871206887, 1676835486, 3251439501, 6258092337, 12134600945
Offset: 0

Views

Author

Kassie Archer, Mar 31 2025

Keywords

Comments

A shallow permutation is a permutation that satisfies the lower bound of the Diaconis-Graham inequality (i.e., so that the total displacement is equal to the sum of the length and reflection length).

Crossrefs

Programs

  • Mathematica
    CoefficientList[Series[(1 - 3*x + 11*x^3 - 13*x^4 + 7*x^5 + 6*x^6 + 3*x^7)/((1 - x)^4*(1 - 4*x^2 + x^4)), {x, 0, 33}], x] (* Michael De Vlieger, Apr 01 2025 *)

Formula

G.f.: (1-3*x+11*x^3-13*x^4+7*x^5+6*x^6+3*x^7) / ((1-x)^4 * (1-4*x^2+x^4)).
Showing 1-8 of 8 results.