How would I permutate n books on n shelves, with no limit on how many books could be placed on a shelf?

https://math.stackexchange.com/questions/290570/how-to-solve-for-the-amount-of-arrangements-of-books-on-a-shelf

Take a numerical example,

suppose you have 3 different books on 3 different shelves
the books can line up on the shelves as:
3 0 0 or 0 3 0 or 0 0 3 ----- 3!/2! = 3 ways
2 1 0 or 2 0 1 or 1 2 0 or 1 0 2 or 0 1 2 or 0 2 1 ---- 3! = 6 ways
1 1 1 ----> 3!/3! = 1 way
10 ways just to arrange the books, but in each of these arrangement we can permutate the 3 books without changing the shelf arrangements.
So number of ways = 10*3! = 60

suppose you have 4 books with 4 shelves
the books can line up on the shelves as:
4 0 0 0 ------> 4!/3! = 4 ways
3 1 0 0 ------> 4!/2! = 12 ways
2 2 0 0 -----> 4!/(2!2!) = 6 ways
2 1 1 0 -----> 4!/2! = 12 ways
1 1 1 1 -----> 4!/4! = 1 way
35 ways just to arrange the books, but in each of these arrangement we can permutate the 4 books without changing the shelf arrangements.
So number of ways = 35*4! = 840

suppose you have 5 books with 5 shelves
the books can line up on the shelves as:
5 0 0 0 0 ---- 5!/4! = 5 ways
4 1 0 0 0 ----- 5!/3! = 20
3 2 0 0 0 -----> 5!/3! = 20
3 1 1 0 0 -----> 5!/(2!2!) = 30
2 2 1 0 0 -----> 5!/(2!2!) = 30
2 1 1 1 0 -----> 5!/3! = 20
1 1 1 1 1 ------> 1 way
126 ways just to arrange the books, but in each of these arrangement we can permutate the 5 books without changing the shelf arrangements.
So number of ways = 126*5! = 15120

I might be overthinking this problem, and I might have missed one or more cases, or might have made arithmetic errors,
but I really don't see any organized way of doing this.

To find the number of ways to permute n books on n shelves with no limit on the number of books per shelf, you need to use the concept of partitions.

A partition of a positive integer n represents a way to express that integer as a sum of positive integers. In this case, each positive integer in the partition represents the number of books on a shelf.

To solve this problem, you can use the concept of generating functions. The generating function for partitions of n is denoted by P(n), where the coefficient of x^k in P(n) represents the number of ways to partition n into k positive integers.

To illustrate the process:

1. Start with the generating function P(0) = 1, as there is only one way to partition 0 (i.e., with no positive integers).

2. Iterate through all positive integers from 1 to n, and for each integer i, compute P(i) using the following formula:
P(i) = x^i + P(i-1) + P(i-2) + ... + P(1)

Explanation of the formula:
- The term x^i represents the case where all the books in the partition are placed on a single shelf.
- The term P(i-1) represents the case where the last shelf in the partition contains only one book, and the remaining books are partitioned into i-1 shelves. This accounts for cases where the last shelf is not filled to its maximum capacity.
- The term P(i-2) represents the case where the last shelf in the partition contains two books, and the remaining books are partitioned into i-2 shelves. This accounts for cases where the last shelf is not filled to its maximum capacity.
- Repeat this process for all terms until reaching P(1).

Once you have computed P(n), you can find the total number of ways to permutate n books on n shelves by summing the coefficients of all terms in P(n).

Note: Since this approach uses generating functions, using a computer program or software capable of symbolic manipulation (e.g., Python with SymPy package, Mathematica, Maple) will make the computation much easier and efficient for larger values of n.