Friday, October 14, 2022

[ykoqomhu] summing reciprocals minimizing round-off error

to decrease round-off error when summing a collection of positive floating-point numbers, sum numbers from smallest to largest.  however, it is not as simple as just first sorting the input list: a partial sum could become large compared to the next number to be added.  better is to put all the numbers in a priority queue (heap), then repeatedly pop off the two smallest numbers, add them, and push them back into the priority queue.  (increased precision comes at the cost of a factor of log n time.)  we demonstrate this in Haskell, using Data.PQueue.Min in the pqueue package as our priority queue.  we sum exact Rational numbers for simplicity, and we keep track of what got added to what in an expression tree.

future work: keep track of roundoff error.

(related work, not implemented here: Kahan summation is another way to decrease round-off error.  Kahan was previously mentioned in the context of trying to avoid catastrophic loss of precision when doing trigonometry.)

source code.

here is the tail-recursive function that sums the contents of a priority queue.

reduceto1 :: Pqueue.MinQueue Expr -> Expr;
reduceto1 q = let {
  (a::Expr, q2) = Pqueue.deleteFindMin q
} in case Pqueue.minView q2 of {
  Nothing -> a;
  Just(b::Expr, q3) -> reduceto1 $ flip Pqueue.insert q3 $ Plus a b; -- smaller number on the left side of the plus sign
};

first, we demonstrate adding the first N reciprocals of integers (partial sums of the harmonic series).

1: 1/1

2: (1/2 + 1/1)

3: ((1/3 + 1/2) + 1/1)

4: (1/1 + (1/2 + (1/4 + 1/3)))

5: (1/1 + (1/2 + (1/3 + (1/5 + 1/4))))

6: (1/1 + ((1/4 + 1/3) + ((1/6 + 1/5) + 1/2)))

7: (1/1 + (((1/7 + 1/6) + 1/3) + ((1/5 + 1/4) + 1/2)))

8: ((1/2 + (1/4 + (1/8 + 1/7))) + ((1/3 + (1/6 + 1/5)) + 1/1))

9: ((1/2 + (1/4 + (1/7 + 1/6))) + ((1/3 + (1/5 + (1/9 + 1/8))) + 1/1))

10: ((1/2 + ((1/8 + 1/7) + 1/3)) + (((1/6 + 1/5) + ((1/10 + 1/9) + 1/4)) + 1/1))

11: ((1/2 + ((1/7 + 1/6) + 1/3)) + ((((1/11 + 1/10) + 1/5) + ((1/9 + 1/8) + 1/4)) + 1/1))

12: (((1/4 + (1/8 + 1/7)) + (1/3 + (1/6 + (1/12 + 1/11)))) + (((1/5 + (1/10 + 1/9)) + 1/2) + 1/1))

13: (((1/4 + (1/7 + (1/13 + 1/12))) + (1/3 + (1/6 + (1/11 + 1/10)))) + (((1/5 + (1/9 + 1/8)) + 1/2) + 1/1))

14: ((((1/8 + 1/7) + ((1/14 + 1/13) + 1/6)) + (1/3 + ((1/12 + 1/11) + 1/5))) + ((((1/10 + 1/9) + 1/4) + 1/2) + 1/1))

15: (((((1/15 + 1/14) + 1/7) + ((1/13 + 1/12) + 1/6)) + (1/3 + ((1/11 + 1/10) + 1/5))) + ((((1/9 + 1/8) + 1/4) + 1/2) + 1/1))

16: ((((1/7 + (1/14 + 1/13)) + 1/3) + ((1/6 + (1/12 + 1/11)) + (1/5 + (1/10 + 1/9)))) + (1/1 + (1/2 + (1/4 + (1/8 + (1/16 + 1/15))))))

17: ((((1/7 + (1/13 + 1/12)) + 1/3) + ((1/6 + (1/11 + 1/10)) + (1/5 + (1/9 + (1/17 + 1/16))))) + (1/1 + (1/2 + (1/4 + (1/8 + (1/15 + 1/14))))))

18: (((((1/14 + 1/13) + 1/6) + 1/3) + (((1/12 + 1/11) + 1/5) + ((1/10 + 1/9) + ((1/18 + 1/17) + 1/8)))) + (1/1 + (1/2 + (1/4 + ((1/16 + 1/15) + 1/7)))))

19: (((((1/13 + 1/12) + 1/6) + 1/3) + (((1/11 + 1/10) + 1/5) + (((1/19 + 1/18) + 1/9) + ((1/17 + 1/16) + 1/8)))) + (1/1 + (1/2 + (1/4 + ((1/15 + 1/14) + 1/7)))))

20: (((1/3 + (1/6 + (1/12 + 1/11))) + ((1/5 + (1/10 + (1/20 + 1/19))) + ((1/9 + (1/18 + 1/17)) + 1/4))) + (1/1 + (1/2 + ((1/8 + (1/16 + 1/15)) + (1/7 + (1/14 + 1/13))))))

21: (((1/3 + (1/6 + (1/11 + (1/21 + 1/20)))) + ((1/5 + (1/10 + (1/19 + 1/18))) + ((1/9 + (1/17 + 1/16)) + 1/4))) + (1/1 + (1/2 + ((1/8 + (1/15 + 1/14)) + (1/7 + (1/13 + 1/12))))))

22: (((1/3 + ((1/12 + 1/11) + ((1/22 + 1/21) + 1/10))) + ((1/5 + ((1/20 + 1/19) + 1/9)) + (((1/18 + 1/17) + 1/8) + 1/4))) + (1/1 + (1/2 + (((1/16 + 1/15) + 1/7) + ((1/14 + 1/13) + 1/6)))))

23: (((1/3 + (((1/23 + 1/22) + 1/11) + ((1/21 + 1/20) + 1/10))) + ((1/5 + ((1/19 + 1/18) + 1/9)) + (((1/17 + 1/16) + 1/8) + 1/4))) + (1/1 + (1/2 + (((1/15 + 1/14) + 1/7) + ((1/13 + 1/12) + 1/6)))))

24: ((((1/6 + (1/12 + (1/24 + 1/23))) + ((1/11 + (1/22 + 1/21)) + 1/5)) + (((1/10 + (1/20 + 1/19)) + (1/9 + (1/18 + 1/17))) + 1/2)) + (1/1 + ((1/4 + (1/8 + (1/16 + 1/15))) + ((1/7 + (1/14 + 1/13)) + 1/3))))

25: ((((1/6 + (1/12 + (1/23 + 1/22))) + ((1/11 + (1/21 + 1/20)) + 1/5)) + (((1/10 + (1/19 + 1/18)) + (1/9 + (1/17 + 1/16))) + 1/2)) + (1/1 + ((1/4 + (1/8 + (1/15 + 1/14))) + ((1/7 + (1/13 + (1/25 + 1/24))) + 1/3))))

26: ((((1/6 + ((1/24 + 1/23) + 1/11)) + (((1/22 + 1/21) + 1/10) + 1/5)) + ((((1/20 + 1/19) + 1/9) + ((1/18 + 1/17) + 1/8)) + 1/2)) + (1/1 + ((1/4 + ((1/16 + 1/15) + 1/7)) + (((1/14 + 1/13) + ((1/26 + 1/25) + 1/12)) + 1/3))))

27: ((((1/6 + ((1/23 + 1/22) + 1/11)) + (((1/21 + 1/20) + 1/10) + 1/5)) + ((((1/19 + 1/18) + 1/9) + ((1/17 + 1/16) + 1/8)) + 1/2)) + (1/1 + ((1/4 + ((1/15 + 1/14) + 1/7)) + ((((1/27 + 1/26) + 1/13) + ((1/25 + 1/24) + 1/12)) + 1/3))))

28: (((((1/12 + (1/24 + 1/23)) + (1/11 + (1/22 + 1/21))) + (1/5 + (1/10 + (1/20 + 1/19)))) + (((1/9 + (1/18 + 1/17)) + 1/4) + 1/2)) + (1/1 + (((1/8 + (1/16 + 1/15)) + (1/7 + (1/14 + (1/28 + 1/27)))) + (((1/13 + (1/26 + 1/25)) + 1/6) + 1/3))))

29: (((((1/12 + (1/23 + 1/22)) + (1/11 + (1/21 + 1/20))) + (1/5 + (1/10 + (1/19 + 1/18)))) + (((1/9 + (1/17 + 1/16)) + 1/4) + 1/2)) + (1/1 + (((1/8 + (1/15 + (1/29 + 1/28))) + (1/7 + (1/14 + (1/27 + 1/26)))) + (((1/13 + (1/25 + 1/24)) + 1/6) + 1/3))))

30: ((((((1/24 + 1/23) + 1/11) + ((1/22 + 1/21) + 1/10)) + (1/5 + ((1/20 + 1/19) + 1/9))) + ((((1/18 + 1/17) + 1/8) + 1/4) + 1/2)) + (1/1 + ((((1/16 + 1/15) + ((1/30 + 1/29) + 1/14)) + (1/7 + ((1/28 + 1/27) + 1/13))) + ((((1/26 + 1/25) + 1/12) + 1/6) + 1/3))))

31: ((((((1/23 + 1/22) + 1/11) + ((1/21 + 1/20) + 1/10)) + (1/5 + ((1/19 + 1/18) + 1/9))) + ((((1/17 + 1/16) + 1/8) + 1/4) + 1/2)) + (1/1 + (((((1/31 + 1/30) + 1/15) + ((1/29 + 1/28) + 1/14)) + (1/7 + ((1/27 + 1/26) + 1/13))) + ((((1/25 + 1/24) + 1/12) + 1/6) + 1/3))))

32: (((((1/11 + (1/22 + 1/21)) + 1/5) + ((1/10 + (1/20 + 1/19)) + (1/9 + (1/18 + 1/17)))) + 1/1) + ((1/2 + (1/4 + (1/8 + (1/16 + (1/32 + 1/31))))) + ((((1/15 + (1/30 + 1/29)) + 1/7) + ((1/14 + (1/28 + 1/27)) + (1/13 + (1/26 + 1/25)))) + (1/3 + (1/6 + (1/12 + (1/24 + 1/23)))))))

33: (((((1/11 + (1/21 + 1/20)) + 1/5) + ((1/10 + (1/19 + 1/18)) + (1/9 + (1/17 + (1/33 + 1/32))))) + 1/1) + ((1/2 + (1/4 + (1/8 + (1/16 + (1/31 + 1/30))))) + ((((1/15 + (1/29 + 1/28)) + 1/7) + ((1/14 + (1/27 + 1/26)) + (1/13 + (1/25 + 1/24)))) + (1/3 + (1/6 + (1/12 + (1/23 + 1/22)))))))

34: ((((((1/22 + 1/21) + 1/10) + 1/5) + (((1/20 + 1/19) + 1/9) + ((1/18 + 1/17) + ((1/34 + 1/33) + 1/16)))) + 1/1) + ((1/2 + (1/4 + (1/8 + ((1/32 + 1/31) + 1/15)))) + (((((1/30 + 1/29) + 1/14) + 1/7) + (((1/28 + 1/27) + 1/13) + ((1/26 + 1/25) + 1/12))) + (1/3 + (1/6 + ((1/24 + 1/23) + 1/11))))))

35: ((((((1/21 + 1/20) + 1/10) + 1/5) + (((1/19 + 1/18) + 1/9) + (((1/35 + 1/34) + 1/17) + ((1/33 + 1/32) + 1/16)))) + 1/1) + ((1/2 + (1/4 + (1/8 + ((1/31 + 1/30) + 1/15)))) + (((((1/29 + 1/28) + 1/14) + 1/7) + (((1/27 + 1/26) + 1/13) + ((1/25 + 1/24) + 1/12))) + (1/3 + (1/6 + ((1/23 + 1/22) + 1/11))))))

36: ((((1/5 + (1/10 + (1/20 + 1/19))) + ((1/9 + (1/18 + (1/36 + 1/35))) + ((1/17 + (1/34 + 1/33)) + 1/8))) + 1/1) + ((1/2 + (1/4 + ((1/16 + (1/32 + 1/31)) + (1/15 + (1/30 + 1/29))))) + (((1/7 + (1/14 + (1/28 + 1/27))) + ((1/13 + (1/26 + 1/25)) + 1/6)) + (1/3 + ((1/12 + (1/24 + 1/23)) + (1/11 + (1/22 + 1/21)))))))

37: ((((1/5 + (1/10 + (1/19 + (1/37 + 1/36)))) + ((1/9 + (1/18 + (1/35 + 1/34))) + ((1/17 + (1/33 + 1/32)) + 1/8))) + 1/1) + ((1/2 + (1/4 + ((1/16 + (1/31 + 1/30)) + (1/15 + (1/29 + 1/28))))) + (((1/7 + (1/14 + (1/27 + 1/26))) + ((1/13 + (1/25 + 1/24)) + 1/6)) + (1/3 + ((1/12 + (1/23 + 1/22)) + (1/11 + (1/21 + 1/20)))))))

38: ((((1/5 + ((1/20 + 1/19) + ((1/38 + 1/37) + 1/18))) + ((1/9 + ((1/36 + 1/35) + 1/17)) + (((1/34 + 1/33) + 1/16) + 1/8))) + 1/1) + ((1/2 + (1/4 + (((1/32 + 1/31) + 1/15) + ((1/30 + 1/29) + 1/14)))) + (((1/7 + ((1/28 + 1/27) + 1/13)) + (((1/26 + 1/25) + 1/12) + 1/6)) + (1/3 + (((1/24 + 1/23) + 1/11) + ((1/22 + 1/21) + 1/10))))))

39: ((((1/5 + (((1/39 + 1/38) + 1/19) + ((1/37 + 1/36) + 1/18))) + ((1/9 + ((1/35 + 1/34) + 1/17)) + (((1/33 + 1/32) + 1/16) + 1/8))) + 1/1) + ((1/2 + (1/4 + (((1/31 + 1/30) + 1/15) + ((1/29 + 1/28) + 1/14)))) + (((1/7 + ((1/27 + 1/26) + 1/13)) + (((1/25 + 1/24) + 1/12) + 1/6)) + (1/3 + (((1/23 + 1/22) + 1/11) + ((1/21 + 1/20) + 1/10))))))

40: (((((1/10 + (1/20 + (1/40 + 1/39))) + ((1/19 + (1/38 + 1/37)) + 1/9)) + (((1/18 + (1/36 + 1/35)) + (1/17 + (1/34 + 1/33))) + 1/4)) + 1/1) + ((1/2 + ((1/8 + (1/16 + (1/32 + 1/31))) + ((1/15 + (1/30 + 1/29)) + 1/7))) + ((((1/14 + (1/28 + 1/27)) + (1/13 + (1/26 + 1/25))) + 1/3) + ((1/6 + (1/12 + (1/24 + 1/23))) + ((1/11 + (1/22 + 1/21)) + 1/5)))))

next, sums of the reciprocals of the primes up to N.  like the harmonic series, sum diverges when taken over all primes.

2: 1/2

3: (1/3 + 1/2)

5: (1/2 + (1/5 + 1/3))

7: (1/2 + (1/3 + (1/7 + 1/5)))

11: (1/2 + (1/3 + (1/5 + (1/11 + 1/7))))

13: ((1/5 + (1/7 + (1/13 + 1/11))) + (1/3 + 1/2))

17: (((1/11 + (1/17 + 1/13)) + 1/3) + ((1/7 + 1/5) + 1/2))

19: ((((1/19 + 1/17) + 1/7) + 1/3) + (((1/13 + 1/11) + 1/5) + 1/2))

23: ((((1/17 + 1/13) + 1/7) + 1/3) + (((1/11 + (1/23 + 1/19)) + 1/5) + 1/2))

29: (((1/7 + (1/13 + (1/29 + 1/23))) + 1/3) + ((1/5 + (1/11 + (1/19 + 1/17))) + 1/2))

31: (((1/7 + (1/13 + 1/11)) + 1/3) + ((1/5 + ((1/23 + 1/19) + (1/17 + (1/31 + 1/29)))) + 1/2))

37: (((1/7 + ((1/29 + 1/23) + 1/11)) + 1/3) + ((1/5 + ((1/19 + 1/17) + ((1/37 + 1/31) + 1/13))) + 1/2))

41: (((((1/31 + 1/29) + 1/13) + (1/11 + (1/23 + (1/41 + 1/37)))) + 1/3) + ((1/5 + ((1/19 + 1/17) + 1/7)) + 1/2))

43: ((1/3 + ((1/13 + (1/29 + 1/23)) + (1/11 + ((1/43 + 1/41) + 1/19)))) + ((1/5 + ((1/17 + (1/37 + 1/31)) + 1/7)) + 1/2))

47: ((1/3 + ((1/13 + (1/23 + (1/47 + 1/43))) + (1/11 + ((1/41 + 1/37) + 1/19)))) + ((1/5 + ((1/17 + (1/31 + 1/29)) + 1/7)) + 1/2))

53: ((1/3 + ((1/13 + 1/11) + 1/5)) + ((((1/23 + (1/43 + 1/41)) + (1/19 + 1/17)) + (((1/37 + 1/31) + (1/29 + (1/53 + 1/47))) + 1/7)) + 1/2))

59: ((1/3 + ((((1/59 + 1/53) + 1/23) + 1/11) + 1/5)) + (((((1/47 + 1/43) + (1/41 + 1/37)) + (1/19 + 1/17)) + (1/7 + ((1/31 + 1/29) + 1/13))) + 1/2))

61: ((1/3 + ((((1/53 + 1/47) + 1/23) + 1/11) + 1/5)) + (1/2 + ((((1/43 + 1/41) + 1/19) + (1/17 + (1/37 + 1/31))) + (1/7 + (((1/61 + 1/59) + 1/29) + 1/13)))))

67: ((1/3 + (((1/23 + (1/47 + 1/43)) + 1/11) + 1/5)) + (1/2 + ((((1/41 + 1/37) + 1/19) + (1/17 + ((1/67 + 1/61) + 1/31))) + (1/7 + ((1/29 + (1/59 + 1/53)) + 1/13)))))

71: ((1/3 + ((1/11 + (1/23 + (1/43 + 1/41))) + 1/5)) + (1/2 + (((1/19 + (1/37 + (1/71 + 1/67))) + (1/17 + (1/31 + (1/61 + 1/59)))) + (1/7 + ((1/29 + (1/53 + 1/47)) + 1/13)))))

73: ((1/3 + ((1/11 + ((1/47 + 1/43) + (1/41 + 1/37))) + 1/5)) + (1/2 + (((1/19 + 1/17) + (((1/73 + 1/71) + (1/67 + 1/61)) + (1/31 + 1/29))) + (1/7 + (1/13 + ((1/59 + 1/53) + 1/23))))))

79: ((1/3 + ((1/11 + ((1/43 + 1/41) + 1/19)) + 1/5)) + (1/2 + (((((1/79 + 1/73) + 1/37) + 1/17) + (((1/71 + 1/67) + 1/31) + ((1/61 + 1/59) + 1/29))) + (1/7 + (1/13 + ((1/53 + 1/47) + 1/23))))))

83: ((1/3 + ((1/11 + ((1/41 + (1/83 + 1/79)) + 1/19)) + 1/5)) + (1/2 + ((((1/37 + (1/73 + 1/71)) + 1/17) + (((1/67 + 1/61) + 1/31) + (1/29 + (1/59 + 1/53)))) + (1/7 + (1/13 + (1/23 + (1/47 + 1/43)))))))

89: ((1/3 + ((1/11 + ((1/41 + (1/79 + 1/73)) + 1/19)) + 1/5)) + (1/2 + ((((1/37 + (1/71 + 1/67)) + 1/17) + ((1/31 + (1/61 + 1/59)) + (1/29 + (1/53 + 1/47)))) + (1/7 + (1/13 + (1/23 + (1/43 + (1/89 + 1/83))))))))

97: ((1/3 + (((1/23 + (1/43 + 1/41)) + (((1/83 + 1/79) + 1/37) + 1/19)) + 1/5)) + (1/2 + (((1/17 + ((1/73 + 1/71) + (1/67 + 1/61))) + 1/7) + (((1/31 + 1/29) + 1/13) + (((1/59 + 1/53) + (1/47 + (1/97 + 1/89))) + 1/11)))))

101: ((1/3 + ((((1/47 + 1/43) + ((1/89 + 1/83) + 1/41)) + (1/19 + ((1/79 + 1/73) + 1/37))) + 1/5)) + (1/2 + (((1/17 + ((1/71 + 1/67) + 1/31)) + 1/7) + ((((1/61 + 1/59) + 1/29) + 1/13) + (((1/53 + (1/101 + 1/97)) + 1/23) + 1/11)))))

103: ((1/3 + (1/5 + ((((1/97 + 1/89) + 1/43) + (1/41 + (1/83 + 1/79))) + (1/19 + (1/37 + (1/73 + 1/71)))))) + (1/2 + (((1/17 + ((1/67 + 1/61) + 1/31)) + 1/7) + (((1/29 + (1/59 + 1/53)) + 1/13) + ((((1/103 + 1/101) + 1/47) + 1/23) + 1/11)))))

107: ((1/3 + (1/5 + (((1/43 + (1/89 + 1/83)) + (1/41 + (1/79 + 1/73))) + (1/19 + (1/37 + (1/71 + 1/67)))))) + (1/2 + (((1/17 + (1/31 + (1/61 + 1/59))) + 1/7) + (((1/29 + (1/53 + (1/107 + 1/103))) + 1/13) + ((((1/101 + 1/97) + 1/47) + 1/23) + 1/11)))))

109: ((1/3 + (1/5 + (((1/43 + 1/41) + ((1/83 + 1/79) + 1/37)) + (1/19 + 1/17)))) + (1/2 + (((((1/73 + 1/71) + (1/67 + 1/61)) + (1/31 + 1/29)) + 1/7) + ((((1/59 + (1/109 + 1/107)) + (1/53 + (1/103 + 1/101))) + 1/13) + (((1/47 + (1/97 + 1/89)) + 1/23) + 1/11)))))

113: ((1/3 + (1/5 + ((((1/89 + 1/83) + 1/41) + 1/19) + (((1/79 + 1/73) + 1/37) + 1/17)))) + (1/2 + (((((1/71 + 1/67) + 1/31) + ((1/61 + 1/59) + 1/29)) + 1/7) + (((((1/113 + 1/109) + 1/53) + ((1/107 + 1/103) + (1/101 + 1/97))) + 1/13) + ((1/23 + (1/47 + 1/43)) + 1/11)))))

127: ((((1/13 + (((1/109 + 1/107) + 1/53) + ((1/103 + 1/101) + 1/47))) + ((1/23 + ((1/97 + 1/89) + 1/43)) + 1/11)) + (1/5 + (((1/41 + (1/83 + 1/79)) + 1/19) + ((1/37 + (1/73 + 1/71)) + 1/17)))) + (1/2 + (((((1/67 + 1/61) + 1/31) + (((1/127 + 1/113) + 1/59) + 1/29)) + 1/7) + 1/3)))

131: ((((1/13 + ((1/53 + (1/107 + 1/103)) + ((1/101 + 1/97) + 1/47))) + ((1/23 + (1/43 + (1/89 + 1/83))) + 1/11)) + (1/5 + (((1/41 + (1/79 + 1/73)) + 1/19) + ((1/37 + (1/71 + 1/67)) + 1/17)))) + (1/2 + ((((((1/131 + 1/127) + 1/61) + 1/31) + (1/29 + (1/59 + (1/113 + 1/109)))) + 1/7) + 1/3)))

137: ((((1/13 + ((1/53 + (1/103 + 1/101)) + (1/47 + (1/97 + 1/89)))) + (1/11 + (1/23 + (1/43 + 1/41)))) + (1/5 + ((((1/83 + 1/79) + 1/37) + 1/19) + (((1/73 + 1/71) + (1/67 + (1/137 + 1/131))) + 1/17)))) + (1/2 + ((((1/31 + (1/61 + (1/127 + 1/113))) + (1/29 + (1/59 + (1/109 + 1/107)))) + 1/7) + 1/3)))

139: ((((1/13 + (((1/107 + 1/103) + (1/101 + 1/97)) + 1/23)) + (1/11 + ((1/47 + 1/43) + ((1/89 + 1/83) + 1/41)))) + (1/5 + ((1/19 + ((1/79 + 1/73) + 1/37)) + (1/17 + ((1/71 + (1/139 + 1/137)) + (1/67 + (1/131 + 1/127))))))) + (1/2 + ((((1/31 + (1/61 + 1/59)) + (1/29 + ((1/113 + 1/109) + 1/53))) + 1/7) + 1/3)))

149: ((((1/13 + (((1/103 + 1/101) + 1/47) + 1/23)) + (1/11 + (((1/97 + 1/89) + 1/43) + (1/41 + (1/83 + 1/79))))) + (1/5 + ((1/19 + (1/37 + (1/73 + (1/149 + 1/139)))) + (1/17 + ((1/71 + 1/67) + ((1/137 + 1/131) + 1/61)))))) + (1/2 + ((((1/31 + ((1/127 + 1/113) + 1/59)) + (1/29 + ((1/109 + 1/107) + 1/53))) + 1/7) + 1/3)))

151: ((((1/13 + (((1/101 + 1/97) + 1/47) + 1/23)) + (1/11 + ((1/43 + (1/89 + 1/83)) + (1/41 + (1/79 + (1/151 + 1/149)))))) + (1/5 + ((1/19 + (1/37 + (1/73 + 1/71))) + (1/17 + (((1/139 + 1/137) + 1/67) + ((1/131 + 1/127) + 1/61)))))) + (1/2 + ((((1/31 + 1/29) + ((1/59 + (1/113 + 1/109)) + (1/53 + (1/107 + 1/103)))) + 1/7) + 1/3)))

157: ((((1/13 + ((1/47 + (1/97 + 1/89)) + 1/23)) + (1/11 + ((1/43 + 1/41) + ((1/83 + 1/79) + ((1/157 + 1/151) + 1/73))))) + (1/5 + ((1/19 + (1/37 + ((1/149 + 1/139) + 1/71))) + (1/17 + ((1/67 + (1/137 + 1/131)) + 1/31))))) + (1/2 + (((((1/61 + (1/127 + 1/113)) + 1/29) + ((1/59 + (1/109 + 1/107)) + (1/53 + (1/103 + 1/101)))) + 1/7) + 1/3)))

163: ((((1/13 + (1/23 + (1/47 + 1/43))) + (1/11 + (((1/89 + 1/83) + 1/41) + (((1/163 + 1/157) + 1/79) + 1/37)))) + (1/5 + ((1/19 + (((1/151 + 1/149) + 1/73) + (1/71 + (1/139 + 1/137)))) + (1/17 + ((1/67 + (1/131 + 1/127)) + 1/31))))) + (1/2 + ((1/7 + (((1/61 + 1/59) + 1/29) + (((1/113 + 1/109) + 1/53) + ((1/107 + 1/103) + (1/101 + 1/97))))) + 1/3)))

167: (((((((1/109 + 1/107) + 1/53) + ((1/103 + 1/101) + 1/47)) + (1/23 + ((1/97 + 1/89) + 1/43))) + (1/11 + (((1/83 + (1/167 + 1/163)) + 1/41) + 1/19))) + (1/5 + ((((1/79 + (1/157 + 1/151)) + 1/37) + ((1/73 + (1/149 + 1/139)) + (1/71 + 1/67))) + (1/17 + (((1/137 + 1/131) + 1/61) + 1/31))))) + (1/2 + ((1/7 + ((((1/127 + 1/113) + 1/59) + 1/29) + 1/13)) + 1/3)))

173: ((((((1/53 + (1/107 + 1/103)) + ((1/101 + 1/97) + 1/47)) + (1/23 + ((1/89 + (1/173 + 1/167)) + 1/43))) + (1/11 + ((1/41 + (1/83 + (1/163 + 1/157))) + 1/19))) + (1/5 + ((((1/79 + (1/151 + 1/149)) + 1/37) + ((1/73 + 1/71) + ((1/139 + 1/137) + 1/67))) + (1/17 + (((1/131 + 1/127) + 1/61) + 1/31))))) + (1/2 + ((1/7 + ((1/29 + (1/59 + (1/113 + 1/109))) + 1/13)) + 1/3)))

do these expression trees have any rhyme or reason?  the parenthesized representation is not good for seeing structural patterns.  future work: draw them as trees.

the expression trees define a unique binary tree for each integer, or for each prime.

No comments :