Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

recurrence relation

I have the following recurrence relation, where $a_k$ are just indeterminates:

$Z_0 := 1, \quad Z_n := \frac1n \sum_{k=1}^n a_k Z_{n-k} \quad \forall n>0$

I tried the following, but it doesn't work:

def Z(n):
    if n == 0:
        return 1
    else:
        a = var(','.join('a%s'%(i+1) for i in range(n)))
        return 1/n*sum(a[k-1]*Z(n-k),k,1,n)

What am I doing wrong?

recurrence relation

I have the following recurrence relation, where $a_k$ are just indeterminates:

$Z_0 := 1, \quad Z_n := \frac1n \sum_{k=1}^n a_k Z_{n-k} \quad \forall n>0$

I tried the following, but it doesn't work:

def Z(n):
    if n == 0:
        return 1
    else:
        a = var(','.join('a%s'%(i+1) for i in range(n)))
        return 1/n*sum(a[k-1]*Z(n-k),k,1,n)

What am I doing wrong?

Edit: Based on dan_fulea's answer, I found a way how to put a inside Z(n):

def Z(n):
    if n == 0:
        return 1
    a = var(','.join(f'a{k}' for k in [0..n]))
    return 1/n * sum([ a[k] * Z(n-k) for k in [1..n] ]).expand()

recurrence relation

I have the following recurrence relation, relation (which gives the cycle index of the symmetric group), where $a_k$ are just indeterminates:

$Z_0 := 1, \quad Z_n := \frac1n \sum_{k=1}^n a_k Z_{n-k} \quad \forall n>0$

I tried the following, but it doesn't work:

def Z(n):
    if n == 0:
        return 1
    else:
        a = var(','.join('a%s'%(i+1) for i in range(n)))
        return 1/n*sum(a[k-1]*Z(n-k),k,1,n)

What am I doing wrong?

Edit: Based on dan_fulea's answer, I found a way how to put a inside Z(n):

def Z(n):
    if n == 0:
        return 1
    a = var(','.join(f'a{k}' for k in [0..n]))
    return 1/n * sum([ a[k] * Z(n-k) for k in [1..n] ]).expand()