Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The issue is that the list [0..nn] with symbolic nn is not valid (a list must have an concrete integer not symbolic length). Since in the else clause you want to define SS as the sum with symbolic limits, you best shot would be using symbolic sum function - like this:

def M(kk,nn) :
    if kk==1:
        SS=nn+1
    else :
        uz = var(f'uz{kk}')
        SS = sum(M(kk-1,nn-uz), uz, 0, nn)
    return SS

Note that we give variable uz an index kk to have different summation variables in the recursive sums.