Post Reply 
[VA] SRC #012c - Then and Now: Sum
12-03-2022, 05:30 PM
Post: #28
RE: [VA] SRC #012c - Then and Now: Sum
(12-03-2022 12:15 PM)Albert Chan Wrote:  Let F(n) = n * F(bits of n), except that F(2)=2, F(1)=1
Let G(n) = sum of n-bits integer reciprocal, except that G(1)=5/4

Implementation details, I do not define F(1) or G(1) for simplicity.
Loops sum Z=(G-LN2)/F, from index of 2, until convergence.

(G(1)-LN2)/F(1) = (5/4-LN2)/1 = 1/4 + (1-LN2)

10 DESTROY ALL @ L2=LN(2) @ SETTIME 0
20 DEF FNB(N)=IP(LN(N+.5)/L2)+1 ! BITS OF INTEGER N
30 DEF FNF(N) @ F=2 @ WHILE N>2 @ F=F*N @ N=FNB(N) @ END WHILE @ FNF=F @ END DEF
40 DEF FNG(N) @ G=0 @ N=2^N-1 @ Y=N*(N-1) ! SUM IN PAIRS
50 FOR X=N+N-1 TO N STEP -4 @ G=G+X/Y @ Y=Y-X-X+4 @ NEXT X @ FNG=G @ END DEF
60 DEF FNZ(N) @ IF N<5 THEN Z=FNG(N)-L2 @ GOTO 80
70 Z=.5^(N+1) @ Z2=Z*Z @ Z=(((-272*Z2+16)*Z2-2)*Z2+1)*Z2+Z
80 FNZ=Z/FNF(N) @ END DEF
100 S=1/4 @ I=1 @ REPEAT @ I=I+1 @ P=S @ S=S+FNZ(I) @ UNTIL P=S
110 DISP S/(1-L2)+1,I,TIME

>run
 2.086377665      31      0.1

Emu/DOS WinXP ≈ 200X --> HP71B runtime about 20 seconds.
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 - Albert Chan - 12-03-2022 05:30 PM



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