recurrence relation
I have the following recurrence relation (which gives the cycle index of the symmetric group), where ak are just indeterminates:
Z0:=1,Zn:=1n∑nk=1akZn−k∀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()