Eulerian Number Calculator
Count the permutations of n elements with exactly k descents, with the row total and mirror check shown.
What it does
Write the numbers one through four in any order. Scan adjacent pairs and count how often the first is larger than the second. That count is the number of descents. The Eulerian number A(n, k) tells how many of the n factorial orders have exactly k descents.
The numbers carry the name of Leonhard Euler, who introduced them while studying sums of powers and permutation patterns. They appear in the analysis of sorting algorithms, in the study of runs in card shuffles, and in polynomial identities that connect to the Bernoulli numbers.
The recurrence has two terms. A permutation of n elements with k descents can be built by inserting the largest element into a smaller permutation. Inserting it at the end of a rising pair or at the start of a new descent leads to A(n, k) equals (n - k) times A(n - 1, k - 1) plus (k + 1) times A(n - 1, k).
This page applies the recurrence with exact integers and reports the row total and a mirror check beside the main answer. The row total must equal n factorial, since every permutation has some number of descents, and the mirror check confirms the symmetry that every Eulerian row possesses.
The input limit is 60. At that size n factorial is far beyond what anyone would list by hand, yet the recurrence returns the exact count immediately. Values of k outside the range from zero to n minus one are rejected.
How to use
- Enter the element count n from 1 to 60.
- Enter the descent count k from 0 through n minus 1.
- Read A(n, k) from the main result box.
- Check the row total, which must equal n factorial.
- Read the mirror check to confirm the row symmetry.
- The defaults n = 4 and k = 1 reproduce the worked example.
Formula
- n
- The number of elements being permuted.
- k
- The exact number of descents required.
- A(n, k)
- The Eulerian number counting permutations with k descents.
The first term covers inserting the largest element where it creates a new descent, and the second covers inserting it where it does not. Boundary terms outside the valid range count as zero. The row always sums to n factorial, and A(n, k) equals A(n, n - 1 - k), which is the symmetry the mirror check reports.
Worked example
Example: A(4, 1)
The page opens with n = 4 and k = 1.
- Write the recurrence: A(4, 1) = (4 - 1) x A(3, 0) + (1 + 1) x A(3, 1).
- Find A(3, 0) = 1, since only 1 2 3 has no descent.
- Find A(3, 1) = 4 from the row for three elements.
- Substitute: A(4, 1) = 3 x 1 + 2 x 4 = 11.
- The tool reports 11 as the Eulerian number.
- The row total is 4! = 24, and the mirror entry A(4, 2) is also 11.
- The full row for n = 4 is 1, 11, 11, 1.
Reference table
| n | k = 0 | k = 1 | k = 2 | k = 3 | k = 4 | Row total |
|---|---|---|---|---|---|---|
| 2 | 1 | 1 | 0 | 0 | 0 | 2 |
| 3 | 1 | 4 | 1 | 0 | 0 | 6 |
| 4 | 1 | 11 | 11 | 1 | 0 | 24 |
| 5 | 1 | 26 | 66 | 26 | 1 | 120 |
Limits
- Only strict descents are counted, never equal neighboring values.
- k must be from 0 through n minus 1.
- Inputs above 60 are rejected to keep the output readable.
- The tool reports counts but does not list the permutations.
Common mistakes
- Counting ascents and descents together instead of descents alone.
- Using k up to n rather than n minus 1.
- Forgetting that the row total is n factorial, not two to the n.
- Swapping the two coefficients in the recurrence.
- Assuming every row entry is unique when the middle two often match.
Try it yourself
Quick checks. Answers sit tucked under each question.
What is A(4, 2)?
A(4, 2) = (4 - 2) x A(3, 1) + 3 x A(3, 2) = 2 x 4 + 3 x 1 = 11.
What is A(3, 1)?
It is 4, and the row 1, 4, 1 adds to 3! = 6.
What is A(4, 0)?
It is 1, because only the increasing order 1 2 3 4 has no descent.
Questions
What is a descent?
A position where the entry is larger than the entry immediately to its right.
Why does a row sum to n factorial?
Every one of the n factorial permutations has exactly one number of descents, so the counts partition the total.
Are the rows symmetric?
Yes. A(n, k) equals A(n, n minus one minus k), which the mirror check verifies.
Where are Eulerian numbers used?
In sorting analysis, run counts in shuffles and polynomial identities.
Is the answer exact?
Yes. The recurrence uses only integer multiplication and addition.
What is the maximum n?
Sixty, with a clear error message for larger entries.