Alternating Permutation

Author

Eric W. Weisstein
January 16, 2004

This notebook downloaded from http://mathworld.wolfram.com/notebooks/Combinatorics/AlternatingPermutation.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/AlternatingPermutation.html.

©2005 Wolfram Research, Inc. except for portions noted otherwise

Initialization

<<DiscreteMath`Combinatorica`

Code

AlternatingPermutationQ[p_List]:=
If[Length[p]==3,
Nor[OrderedQ[p],OrderedQ[Reverse[p]]],
Nor[OrderedQ[#],OrderedQ[Reverse[#]]]&/@And@@Partition[p,3,1]
]

AlternatingPermutions[n_]:=Select[Permutations[n],AlternatingPermutationQ
]

Enumeration

Timing[Length/@(alt=Table[AlternatingPermutions[n],{n,8}])]

Timing[Length/@(alt=Table[AlternatingPermutions[n],{n,9}])]

Take[alt,4]

Union[#,SameTest->(#1==Reverse[#2]&)]&/@Take[alt,4]

Secant and Tangent Numbers

Length/@alt/2

EulerE/@Range[10]

Table[EulerE[2n],{n,5}]

Series

Series[Sec[x]+Tan[x],{x,0,10}]

CoefficientList[Series[Sec[x]+Tan[x],{x,0,10}],x]Range[0,10]!