Skip to main content
2 of 3
added 18 characters in body
Benjamin Young
  • 1.3k
  • 10
  • 17

Sage code:

values = {}
def A(n,k):
    if (n,k) in values:
        return values[(n,k)]
    if n==0:
        if k==0:
            result = 1
        else:
            result = 0
    else:
        result =  (n + 1 - k)**2 * A(n-1, k-1)
        result += 2*(n*(n+1)-k**2) * A(n-1, k)
        result += (n + 1 + k)**2 * A(n-1, k+1)
    values[(n,k)]=result
    return result

for n in range(5):
    print [A(n,k) for k in range(-n, n+1)]

Output:

[1]
[1, 4, 1]
[1, 26, 66, 26, 1]
[1, 120, 1191, 2416, 1191, 120, 1]
[1, 502, 14608, 88234, 156190, 88234, 14608, 502, 1]

These are famous numbers to combinatorists. It looks like you're getting Eulerian numbers for odd n, with k shifted. See sequence A008292 at oeis.org. Note that it's easy to see that A(n,k) = A(n,-k) by induction on n, even if you didn't know that.

Benjamin Young
  • 1.3k
  • 10
  • 17