Post Reply 
One-liner mini-challenge [HP-71B]
04-14-2015, 08:45 PM (This post was last modified: 04-15-2015 12:00 AM by Gerson W. Barbosa.)
Post: #10
RE: One-liner mini-challenge [HP-71B]
(04-14-2015 06:55 PM)Valentin Albillo Wrote:  Hi, Gerson:

(04-13-2015 08:14 PM)Gerson W. Barbosa Wrote:  \[\frac{1}{\sqrt{1}}+\frac{1}{\sqrt{2}}+\frac{1}{\sqrt{3}}+\frac{1} {\sqrt{4}}+\frac{1}{\sqrt{5}}+\cdots+\frac{1}{\sqrt{n}}\]

Write an HP-71B BASIC program and use it to evaluate the sum above when n = 10¹². The program must fit in one line. Accuracy in the widest range as possible is desirable, but if you manage to show 12 correct digits for that particular required n, then it is ok. I will present an 80-character long program that gives accurate results for n as low as 30, in less than 300 milliseconds.

.

I guess this 63-char command-line expression will do, which once keyed in can be executed repeatedly by pressing [ENDLINE] and reusing it from the command stack:

INPUTN@2*N^.5+1/(2*N^.5)*(1-1/(12*N)+1/(192*N^3))-1.46035450881

? 34
10.287088415

? 100
18.5896038248

? 1E12
1999998.53965

? 30
9.58513017659

? 25
8.63931219119

? 20
7.59525502536

? 15
6.41399460857

? 10
5.02099790236

If desired, it can be turned into a program by simply issuing a line number in front of it (say "1 "), which will store it as a 56-byte BASIC program executable with RUN. The running time is utterly negligible.

The constant is ζ(1/2). The expression can be shortened by 6 additional characters by simply getting rid of the parentheses in the denominators (i.e.: /12/n instead of /(12*n)) but I've left it that way for clarity, and the last term may be omitted altogether for a shorter expression with somewhat reduced (but still sufficient for the challenge) accuracy.

Regards.
V.


Hello Valentin,

Congratulations for your nicer and even shorter solution! Your results match mine except for n=34 and n=30. Yours are better, BTW. I get 10.2870884151 and 9.58513017649, respectively.

Here is my original HP-71B program:

1 INPUT N @ A=2*SQR(N) @ B=1/A @ C=B/(12*N) @ D=C/(16*N*N) @ A+B-C+D-1.46035450881

By removing two pairs of parentheses and the spaces it can shortened to 65 characters:

1 INPUTN@A=2*SQR(N)@B=1/A@C=B/12/N@D=C/16/N/N@A+B-C+D-1.46035450881

I won't copy your idea of replacing SQR with ^.5. Also, if you remove one pair of parentheses, your program will end up being shorter anyway :-)

Here is the expression I've come up with:

\[\sum_{k=1}^{n}\frac{1}{\sqrt{k}}\simeq \zeta\left ( \frac{1}{2} \right )+2\sqrt{n}+\frac{1}{2\sqrt{n}}-\frac{1}{24\sqrt{n^{3}}}+\frac{15}{8}\cdot \frac{1}{720\sqrt{n^{7}}}\]

Since this was done experimentally and manually, it is possible that not all terms are correct. (*)

Best regards,

Gerson.

P.S.:

(*) Both series appear to be equivalent, at least for x >= 0:

http://www.wolframalpha.com/input/?i=Sim...2%29%29%5D

(somewhat lazy to check it by hand)


WP 34s program:

Code:

001       LBL A
002       ENTER[^]
003       [sqrt]
004       STO+ X
005       ENTER[^]
006       1/x
007       +
008       RCL L
009       # 012
010       /
011       RCL/ Z
012       -
013       RCL L
014       # 016
015       /
016       RCL/ Z
017       RCL/ Z
018       +
019       # 1/2
020       [zeta]
021       +
022       END

This was actually my first program, the HP-71B being a straightforward conversion.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: One-liner mini-challenge [HP-71B] - Gerson W. Barbosa - 04-14-2015 08:45 PM



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