Post Reply 
[VA] SRC #012c - Then and Now: Sum
12-03-2022, 12:59 PM
Post: #26
RE: [VA] SRC #012c - Then and Now: Sum
Ok, I was able to get it into the 41 with the below code.
As mentioned earlier I had gotten to the equation with ln(2) on the right side but needed Werner's trick (Thank you!) for getting it solved.
Based on HP41 accuracy, I have split the calculation into three segments:
1) Straight Forward calculation of f(x)
2) Using the approximation H(n) ~ ln(n) + 1/(2n) - 1/(12n^2) + 1/(120n^4)
3) Using the approximation that H(n) - H(n-1) ~ Ln(2)

On the hp 41, the approximation 2) is accurate within the precision of the HP41 from n = 2^5 onwards.

On the hp41, the approximation 3) is accurate within the precision of he HP41 from n = 2^31 onwards.

So I am calculating a straight sum from n = 1 till 2^5-1, then switch to the approximation sum 2) from then onwards until 2^31, after which I use ln(2).

I looked at the approximations and I do believe that they prove that the series converges.

I dont know how to do the nice math font here, so my appologies for the below.

S = sum Valentin asked us to calculate.
f(n) = function that valentin gave us
g(x) = H(2^x-1) - H(2^(x-1)-1)
with H(x) being the Harmonic Series up to x
ap(x) = ln(x) + 1/(2x) - 1/(12x^2) + 1/(120x^4)


S = sum(n = 1 to 2^m-1) of f(n)^-1 + sum(x = m+1 to infinity) of f(x)^-1*g(x)
replacing g(x) with the approximation we note that the approximation is always larger than g(x) as we stop with an addition.

S<=sum(n = 1 to 2^m-1) of f(n)^-1 + sum(x = m+1 to infinity) of f(x)^-1* (ap(2^x-1)-ap(2^(x-1)-1)

We then replace the ap() on the right side with ln(2) after a certain cut off point, noting that Ln(2) is also larger than ap()

S<= sum(n = 1 to 2^m-1) of f(n)^-1 + sum(x = m+1 to p-1) of f(x)^-1* (ap(2^x-1)-ap(2^(x-1)-1) + ln(2) * sum(y=p to infinity) of f(y)^-1

with an infinite sum on the right side, this inequality can only be true if S converges.

Or at least this is how my thinking went.

Runtime on the i41cx emulator is a few seconds, result it produces is 2,088075017. Which means that my assumptions about the correct cross-over points are not correct and I might be able to squeeze out a slightly better result by choosing later cross over points but I am not entirely sure how/why, as the calc can't differentiate between ln(2) and the approximation and the approximation and H(2x-1) - H(x-1) anymore at my current cut off points.

However, my flight has landed and I had given up on this when reading it but then had nothing to do on my flight over (europe to US) and made some progress, then got Werners tip, and was able to finish it on the way back. So I feel pretty happy, and thankful.

Here is the code.
Lbl F calculates Valentin's function
Lbl G calculates the approximation of H

Lbl VA12c
CLA
CLX
STO 10
STO 11
STO 12
2
STO 02
31
STO 00
LBL 00
RCL 00
XEQ F
ST+10
DSE00
GTO 00
31.005
STO 00
LBL 01
RCL 00
INT
XEQ G
STO 11
RCL 00
INT
XEQ F
RCL 11
*
ST+ 12
DSE 00
GTO 01
RCL 02
ln
SIGN
LastX
-
1/x
RCL 12
*
RCL 10
+
BEEP
STOP
LBL F
SIGN
STO M
X<>L
LBL 10
3
x>y?
GTO 12
x<>y
ST*M
LN
RCL 02
LN
/
INT
INCX
GTO 10
LBL 12
X<>Y
RCL M
*
1/x
RTN
LBL G
RCL 02
X<>Y
Y^X
DECX
STO N
RCL 02
LASTx
DECX
Y^X
DECX
STO O
LN
LASTx
RCL 02
*
1/x
+
RCLO
X^2
12
*
1/x
-
RCL O
X^2
x^2
120
*
1/x
+
RCL N
LN
LASTx
RCL 02
*
1/x
+
RCL N
X^2
12
*
1/x
-
RCL N
X^2
X^2
120
*
1/x
+
X<>Y
-
RTN

Cheers,

PeterP
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] SRC #012c - Then and Now: Sum - PeterP - 12-03-2022 12:59 PM



User(s) browsing this thread: 1 Guest(s)