# Revision history [back]

### Recurrent definiton of a function

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.

### Recurrent definiton of a function

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 results the correct tuple (7/6, 15/4).

So what is the problem in the definition ? Thanks in advance for any help.

### Recurrent definiton of a function

Hi, I am trying to define the function compose a code for calculating the numbers H01 using two defined as a sum of the following recursively defined functions H11 and H12:numbers:

H11(r) = \sum_{a + b = r}  a*b/r  (H11(a) + H12(a)) * H11(b)
H12(r) = \sum_{a + b = r}  a*b/r  (H11(a) + H12(a)) * (H11(b) + H12(b))

H01(r) = H11(r) + H12(r)


I ended up with the following code:

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. And here problems start. If I just type

H01(8)


it produces the incorrect value 27/8. But if I type

(H01(6), H01(8))
H01(6), H01(8)


it results the correct tuple (7/6, 15/4).

So what is the problem in the definition how to fix the code ? Thanks in advance for any help.