Hi, I am trying to define the function H01 using two recursively defined functions H11 and H12:
memoH11 = {1:0, 2:1/2}
def H11(r1):
if memoH11.has_key(r1):
return memoH11[r1]
else:
a = 0
for j1 in range(1,r1):
a += j1*(r1 - j1)/r1 * (H11(j1) + H12(j1)) * H11(r1-j1)
memoH11[r1] = a
return a
memoH12 = {1:0, 2:0}
def H12(r2):
if memoH12.has_key(r2):
return memoH12[r2]
else:
b = 0
for j2 in range(1,r2):
b += j2*(r2 - j2)/r2 * ( H11(j2) + H12(j2) ) * ( H11(r2 - j2) + H12(r2-j2) )
memoH12[r2] = b
return b
def H01(r):
return H11(r) + H12(r)
My problem is the following. If I just type
H01(8)
it produces the incorrect value 27/8. But if I type
(H01(6), H01(8))
it result the correct tuple (7/6, 15/4).
So what is the problem in the definition ? Thanks in advance for any help.