1
$\begingroup$

I would like to make a table of values of a sequence similar to Stirling numbers of the first kind and for the Stirling numbers of the first kind.

Stirling numbers of the first kind $c(n,k)$ satisfy the following polynomial relation:

$$x(x+1)(x+1)...(x+n-1)=\sum_{k=0}^{n} c(n, k) x^k$$

What is the code in Python that calculates the values of $c(n, k)$ from the previous polynomial relation?

I know I could use the recurrence relation, but I am studying a sequence, similar to the Stirling numbers of the first kind and I do not know the recurrence relation yet for this sequence and I only have the polynomial relation similar to this - and I would like to have a table of values for this sequence.

$\endgroup$
3
  • 2
    $\begingroup$ It's not clear to me what a general "factorial relation" is supposed to be. You mention the Stirling number, which is just defined as the coefficients of a falling factorial, as if it was one of many possible examples so I'm really don't know what other relations you had in mind for a general technique. $\endgroup$ Sep 3, 2023 at 13:25
  • 1
    $\begingroup$ What you are calling "the factorial relation" has a symbolic character, in that the desired $c(n,k)$ appear as coefficients in a polynomial expansion. One can use python's symbolic library SymPy to implement this sort of thing, perhaps as a learning exercise. It would be helpful to know what your motivating application is. $\endgroup$
    – hardmath
    Sep 10, 2023 at 15:43
  • 1
    $\begingroup$ @hardmath I am studying a sequence, similar to the Stirling numbers of the first kind and I do not know the recurrence relation yet for this sequence and I only have the polynomial relation similar to this - and I would like to have a table of values for this sequence. $\endgroup$
    – User303131
    Jan 21 at 11:13

1 Answer 1

3
$\begingroup$

You can just apply the same technique used in your for the second Stirling number and apply this new recurrence relation (below I shifted it to $s_1(n,k) = (n-1) s_1(n-1,k) + s_1(n-1,k-1)$).

x = 10
s1 = [[0]*(i+1) for i in range(x)]
# boundary conditions, n == k -> 1, k == 0 && n > 0 -> 0
for n in range(x):
    s1[n][n] = 1

for n in range(2,x):
    for k in range(1,n):
        s1[n][k] = (n-1)*s1[n-1][k] + s1[n-1][k-1]

for r in s1:
    for c in r:
        print(c, end=' ')
    print()

which outputs

1 
0 1 
0 1 1 
0 2 3 1 
0 6 11 6 1 
0 24 50 35 10 1 
0 120 274 225 85 15 1 
0 720 1764 1624 735 175 21 1 
0 5040 13068 13132 6769 1960 322 28 1 
0 40320 109584 118124 67284 22449 4536 546 36 1 
$\endgroup$
4
  • 1
    $\begingroup$ I know, I have already tried that. But I am specifically interested in the code with the factorial relation. Do you perhaps know it? $\endgroup$
    – User303131
    Sep 3, 2023 at 12:38
  • 1
    $\begingroup$ Well, I mean if you want to compute the polynomial coefficients from the falling factorial efficiently, you would use previously computed values to compute the next, i.e. you would inadvertently derive the recurrence relation. $\endgroup$ Sep 3, 2023 at 13:15
  • 1
    $\begingroup$ Ok, thank you for the info. So, there isn't a way to compute coefficients only from the polynomial relations like for the Stirling number of the first kind? Perhaps not in Python, in some other programs, for example. Thanks a lot. $\endgroup$
    – User303131
    Jan 21 at 11:20
  • 1
    $\begingroup$ Of course the programming language doesn't matter. It's just an algorithm. You'll have to ask about the sequence that you actually have, otherwise I can't know what you even want. My original comment on your question still applies. $\endgroup$ Mar 26 at 1:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.