OFFSET
1,2
LINKS
Alois P. Heinz, Table of n, a(n) for n = 1..485
R. P. Stanley, Alternating permutations, Talk slides.
FORMULA
a(2n) = E(2n)-(-1)^n; a(2n+1) = Sum_{j=0..n}(-1)^j*E(2n+1-2j), where E(i) = A000111(i) are the Euler (or up-down) numbers.
EXAMPLE
a(4) = 4 because in the 5 (=A000111(4)) up-down permutations of {1,2,3,4}, namely 1423, 1324, 3412, 2413, and 2314, we have a total of 1+2+0+0+1=4 fixed points.
MAPLE
E := sec(x)+tan(x): Eser := series(E, x = 0, 30): for n from 0 to 27 do E[n] := factorial(n)*coeff(Eser, x, n) end do: for n to 12 do a[2*n] := E[2*n]-(-1)^n end do: for n from 0 to 12 do a[2*n+1] := add((-1)^j*E[2*n+1-2*j], j = 0 .. n) end do: seq(a[n], n = 1 .. 25);
# second Maple program:
b:= proc(u, o) option remember; `if`(u+o=0, 1,
add(b(o-1+j, u-j), j=1..u))
end:
a:= proc(n) option remember; `if`(irem(n, 2, 'r')=0,
b(n, 0)-(-1)^r, add((-1)^j*b(n-2*j, 0), j=0..r))
end:
seq(a(n), n=1..30); # Alois P. Heinz, Dec 09 2016
MATHEMATICA
b[u_, o_] := b[u, o] = If[u + o == 0, 1, Sum[b[o - 1 + j, u - j], {j, 1, u}]]; a[n_] := a[n] = If[{q, r} = QuotientRemainder[n, 2]; r == 0, b[n, 0] - (-1)^q, Sum[(-1)^j*b[n - 2*j, 0], {j, 0, q}]]; Table[a[n], {n, 1, 30}] (* Jean-François Alcover, Dec 20 2016, after Alois P. Heinz *)
CROSSREFS
KEYWORD
nonn
AUTHOR
Emeric Deutsch, Aug 06 2009
STATUS
approved