login
A(n,k) = !n + [n > 0] * (k * n!), where !n = A000166(n) is subfactorial of n and [] is an Iverson bracket; square array A(n,k), n>=0, k>=0, read by antidiagonals.
6

%I #22 Feb 11 2021 10:36:29

%S 1,1,0,1,1,1,1,2,3,2,1,3,5,8,9,1,4,7,14,33,44,1,5,9,20,57,164,265,1,6,

%T 11,26,81,284,985,1854,1,7,13,32,105,404,1705,6894,14833,1,8,15,38,

%U 129,524,2425,11934,55153,133496,1,9,17,44,153,644,3145,16974,95473,496376,1334961

%N A(n,k) = !n + [n > 0] * (k * n!), where !n = A000166(n) is subfactorial of n and [] is an Iverson bracket; square array A(n,k), n>=0, k>=0, read by antidiagonals.

%H Alois P. Heinz, <a href="/A334715/b334715.txt">Antidiagonals n = 0..140, flattened</a>

%H Wikipedia, <a href="https://en.wikipedia.org/wiki/Derangement">Derangement</a>

%H Wikipedia, <a href="https://en.wikipedia.org/wiki/Iverson_bracket">Iverson bracket</a>

%F E.g.f. of column k: (k*exp(x)*x+1)*exp(-x)/(1-x).

%F A(n,k) = A000166(n) + [n > 0] * (k * n!).

%F A(n,k) = (k-1)*n + 1 if n<2, A(n,k) = n*A(n-1, k) + (-1)^n if n>=2.

%e Square array A(n,k) begins:

%e 1, 1, 1, 1, 1, 1, 1, 1, ...

%e 0, 1, 2, 3, 4, 5, 6, 7, ...

%e 1, 3, 5, 7, 9, 11, 13, 15, ...

%e 2, 8, 14, 20, 26, 32, 38, 44, ...

%e 9, 33, 57, 81, 105, 129, 153, 177, ...

%e 44, 164, 284, 404, 524, 644, 764, 884, ...

%e 265, 985, 1705, 2425, 3145, 3865, 4585, 5305, ...

%e 1854, 6894, 11934, 16974, 22014, 27054, 32094, 37134, ...

%e ...

%p A:= proc(n, k) option remember; `if`(n<2,

%p (k-1)*n+1, n*A(n-1, k)+(-1)^n)

%p end:

%p seq(seq(A(n, d-n), n=0..d), d=0..10);

%t A[n_, k_] := Subfactorial[n] + Boole[n>0] k n!;

%t Table[A[n, d-n], {d, 0, 10}, {n, 0, d}] // Flatten (* _Jean-François Alcover_, Feb 11 2021 *)

%Y Columns k=0-3 give: A000166, A001120, A110043, A110149.

%Y Rows n=0-3 give: A000012, A001477, A005408, A016933.

%Y Main diagonal gives A334716.

%Y Cf. A000142.

%K nonn,tabl

%O 0,8

%A _Alois P. Heinz_, May 08 2020