Post Reply 
One-liner mini-challenge [HP-71B]
04-14-2015, 06:55 PM (This post was last modified: 04-14-2015 07:02 PM by Valentin Albillo.)
Post: #8
RE: One-liner mini-challenge [HP-71B]
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.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website 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] - Valentin Albillo - 04-14-2015 06:55 PM



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