Euler Zigzag Number Calculator
Count the alternating permutations of n elements where comparisons rise and fall in turn, with the growth shown.
What it does
An alternating permutation arranges distinct numbers so that the comparisons switch direction at every step. For four elements, 1 3 2 4 rises, then falls, then rises. The Euler zigzag number E(n), also called the up-down number, counts how many orders of n elements alternate in this way.
The numbers come from the power series of secant x plus tangent x, which is why they are sometimes called the secant tangent numbers. The even indexed values are the secant numbers and the odd indexed values are the tangent numbers. Leonhard Euler studied the series, and the alternating permutation interpretation came later.
This page computes E(n) with a recurrence derived from that generating function. Each new term is half a binomial convolution of earlier terms, with a small correction at the very start. All the arithmetic is done with exact integers, so the division by two is always clean.
The tool reports E(n), the previous value and the ratio between them. The growth is fast: the count reaches 16 at index 5, 1385 at index 9 and 50521 at index 12, so the ratio row climbs steadily.
The index limit is 100. Even E(100) is an exact integer with well over one hundred digits, and the tool prints every one of them without rounding.
How to use
- Enter an index n from 0 to 100.
- Read E(n) from the main result box.
- Check the previous value and the growth ratio beside it.
- The default index 5 reproduces the worked example.
- Try index 9 to confirm the value 7,936.
- Compare even and odd indices to see the secant and tangent families.
Formula
- n
- The index of the zigzag number.
- E(n)
- The number of alternating permutations of n elements.
- C(n, k)
- A binomial coefficient used in the convolution.
The generating function for these numbers is secant x plus tangent x, and differentiating it gives the convolution recurrence used here. The correction term appears only for n equal to zero, making E(1) equal to one. Every other step divides an even integer by two, so the sequence stays whole.
Worked example
Example: E(5)
The page opens with index 5 as the default.
- Start with E(0) = 1, E(1) = 1, E(2) = 1, E(3) = 2 and E(4) = 5.
- Use n = 4 in the convolution for E(5).
- Compute the terms: 1 x 1 x 5 = 5, 4 x 1 x 2 = 8, 6 x 1 x 1 = 6, 4 x 2 x 1 = 8 and 1 x 5 x 1 = 5.
- Add them: 5 + 8 + 6 + 8 + 5 = 32.
- Halve the total: 32 / 2 = 16.
- The tool reports 16, previous value 5, and growth 3.20x.
- For four elements the same process gives E(4) = 5.
Reference table
| n | E(n) | Previous | Growth |
|---|---|---|---|
| 0 | 1 | n/a | n/a |
| 1 | 1 | 1 | 1.00x |
| 2 | 1 | 1 | 1.00x |
| 3 | 2 | 1 | 2.00x |
| 4 | 5 | 2 | 2.50x |
| 5 | 16 | 5 | 3.20x |
| 9 | 7936 | 1385 | 5.73x |
Limits
- The alternating order can start with either a rise or a fall in the usual definition.
- Indices above 100 are rejected so the printed integer stays readable.
- The growth ratio is rounded to two decimals.
- The tool returns counts and does not list the alternating orders themselves.
Common mistakes
- Forgetting the correction term that makes E(1) equal to one.
- Using ordinary factorials instead of the alternating counts.
- Assuming the sequence is monotonic from the start, since the first three values are all one.
- Dropping the binomial coefficient in the convolution.
- Confusing these with Eulerian numbers, which count permutations by descents.
Try it yourself
Quick checks. Answers sit tucked under each question.
What is E(9)?
E(9) = 7,936, with E(8) = 1,385 before it and a growth of 5.73.
What is E(5)?
E(5) = (5 + 8 + 6 + 8 + 5) / 2 = 16.
What is E(4)?
E(4) = 5, the number of alternating orders of four distinct elements.
Questions
What is an alternating permutation?
An ordering where each comparison is opposite the one before it, rising then falling in turn.
Why are these called secant tangent numbers?
Even index values are coefficients of secant x and odd index values are coefficients of tangent x.
How do these differ from Eulerian numbers?
Eulerian numbers count permutations by how many descents they have, without requiring alternation.
Is the division by two always exact?
Yes. The convolution sum is even at every step, so the result stays an integer.
Are large values exact?
Yes. The recurrence uses integer arithmetic throughout, including the binomial factors.
What is the maximum index?
One hundred, with a clear error message for larger inputs.