Oneliner minichallenge [HP71B]

04132015, 08:14 PM
(This post was last modified: 04142015 03:30 AM by Gerson W. Barbosa.)
Post: #1




Oneliner minichallenge [HP71B]
\[\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 HP71B 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 80character long program that gives accurate results for n as low as 30, in less than 300 milliseconds. This can be extended to other HP calculators and the WP34S as well. As a reference, a 21step program on the latter gives 12 accurate digits when n = 30 and 33 or 34 correct digits for n around 100000 and greater. Have fun! Gerson. EDITED TO CHANGE THE SUBJECT TITLE AS THE MATH ROM IS NOT REQUIRED. 

04132015, 10:14 PM
Post: #2




RE: Oneliner minichallenge [HP71B wITH Math ROM]
At this point I wish I'd implemented some additional functions in the 34S. The Hurwitz zeta function or polygamma would help a lot here.
 Pauli 

04132015, 10:34 PM
Post: #3




RE: Oneliner minichallenge [HP71B wITH Math ROM]
Yes, Hurwitz zeta function along with the existing zeta function would allow for exact answers. I wonder if the Prime has it.
Gerson. 

04132015, 11:40 PM
Post: #4




RE: Oneliner minichallenge [HP71B wITH Math ROM]
And the result can also be expressed fairly simply using the polygamma or polylogarithm functions  all of these functions are interrelated.
Your reference lists an expansion of Hurwitz zeta in terms of the Bernoulli polynomials valid for integer arguments such as here. These in turn are defined by the Bernoulli numbers which are available on the 34S. Any program taking this approach would be extremely slow I suspect.  Pauli 

04132015, 11:54 PM
(This post was last modified: 04142015 02:41 PM by Gerson W. Barbosa.)
Post: #5




RE: Oneliner minichallenge [HP71B wITH Math ROM]
On the WP 34S I get, for instance:
34 A > 10.28708841498052 (after 2.5 seconds, DBLOFF) Almost instantly on the HP71B: 10.2870884151 but only because I use a hardcoded constant (no point taking about three minutes to compute it on the HP71B for this application). Gerson. P.S.: My HP41C displays all ten digits correctly :) 34 XEQ SR > 10.28708841 About 1.8 seconds, regardless of the argument, 22 steps. 

04142015, 01:06 AM
(This post was last modified: 04142015 01:08 AM by Gerson W. Barbosa.)
Post: #6




RE: Oneliner minichallenge [HP71B]  
04142015, 12:53 PM
(This post was last modified: 04142015 12:59 PM by Gerson W. Barbosa.)
Post: #7




RE: Oneliner minichallenge [HP71B]
(04132015 11:40 PM)Paul Dale Wrote: Your reference lists an expansion of Hurwitz zeta in terms of the Bernoulli polynomials valid for integer arguments such as here. In fact one of the arguments I use is not integer, but the reason I wasn't able to use the integral representation of Hurwitz zeta on the HP71B is that it requires Re(s) to be greater than 1. Anyway, I'm using an empirical approximation I'd found prior to checking the Wikipedia article. So far I have only the first few terms of the series, but they suffice for this application. If Hurwitz zeta were available, then an exact solution would be possible: \[\zeta\left ( \frac{1}{2} \right )= \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}}+\frac{1}{\sqrt{n+1}}+\frac{1}{\sqrt{n+2}}+\cdots\] \[\zeta\left ( \frac{1}{2},n+1 \right )=\frac{1}{\sqrt{n+1}}+\frac{1}{\sqrt{n+2}}+\frac{1}{\sqrt{n+3}}+\frac{1}{\sqrt{n+4}}+\cdots\] \[\therefore \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}}= \zeta \left ( \frac{1}{2} \right ) \zeta \left ( \frac{1}{2},n+1 \right )\] We can use WA to check our previous result for n = 34: zeta(1/2)  zeta(1/2, 35) Gerson. 

04142015, 06:55 PM
(This post was last modified: 04142015 07:02 PM by Valentin Albillo.)
Post: #8




RE: Oneliner minichallenge [HP71B]
Hi, Gerson:
(04132015 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}}\] . I guess this 63char commandline 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)*(11/(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 56byte 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 

04142015, 07:04 PM
Post: #9




RE: Oneliner minichallenge [HP71B]
The Prof is back! :)
Greetings, Massimo +×÷ ↔ left is right and right is wrong 

04142015, 08:45 PM
(This post was last modified: 04152015 12:00 AM by Gerson W. Barbosa.)
Post: #10




RE: Oneliner minichallenge [HP71B]
(04142015 06:55 PM)Valentin Albillo Wrote: Hi, Gerson: 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 HP71B program: 1 INPUT N @ A=2*SQR(N) @ B=1/A @ C=B/(12*N) @ D=C/(16*N*N) @ A+BC+D1.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+BC+D1.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:
This was actually my first program, the HP71B being a straightforward conversion. 

04142015, 08:54 PM
Post: #11




RE: Oneliner minichallenge [HP71B]
(04142015 07:04 PM)Massimo Gnerucci Wrote: The Prof is back! Hopefully back to stay. Valentin really knows how to concoct a challenge. Furthermore, his explanations are outstanding! Here is an HP41 solution: Code:
Perhaps Valentin's formula makes for a shorter program, in case anyone wants to try it. Best regards, Gerson. 

04172015, 01:46 PM
(This post was last modified: 04172015 07:19 PM by Gerson W. Barbosa.)
Post: #12




RE: Oneliner minichallenge [HP71B]
Perhaps this is a more interesting problem:
\[\sqrt{1}+\sqrt{2}+\sqrt{3}+\sqrt{4}+\sqrt{5}+\cdots+\sqrt{n}\] And here is a simple WP 34s solution: Code:
100 A > 671.462947108 This of course will fit in one HP71B programming line, but I'll leave that as an exercise for the reader :) Gerson. P.S.: Slightly more accurate: Code:
079 A > 423.352471483 100 A > 671.462947103 Obviously, no optimization attempts here. 

04192015, 03:32 PM
Post: #13




RE: Oneliner minichallenge [HP71B]
.
Hi, Gerson: (04172015 01:46 PM)Gerson W. Barbosa Wrote: Perhaps this is a more interesting problem: . This 69char HP71B oneliner will probably do as well: INPUTN@2/3*N^1.5+N^.5/20.207886224977+(11/80/N^2+1/384/N^4)/N^.5/24 which gives 12digit precision for arguments as low as 7 or 8 and even 6digit precision (save for a few ulps) for arguments as low as 1 ! (1,00003...). The constant is Zeta(1/2). Of course one or several final terms can be omitted if desired for a shorter expression with somewhat reduced accuracy. Regards. V. . All My Articles & other Materials here: Valentin Albillo's HP Collection 

04202015, 04:41 PM
Post: #14




RE: Oneliner minichallenge [HP71B]
(04192015 03:32 PM)Valentin Albillo Wrote: . Hello Valentin, Thank you for your ongoing interest in this fascinating subject! At page 81 of his book Prime Obsession, John Derbyshire says: "...if you take the trouble to actually work out the sums and add them up, you see that the first ten terms add up to 5.020997899..., the first hundred add up to 18.589603824..., the first thousand add up to 61.801008765..., the first ten thousand to 198.544645449... and so on." The first problem was an attempt to overcome the trouble of doing these tasks which would become impracticable for very large numbers, even with the help of calculators or computer. The reading of that book has also prompted me to write these programs to compute the Riemann's zeta funcion on various RPL calculators which work for complex arguments, albeit Im(s) being limited to values no greater than 10, for full accuracy. The oddnumbered chapters become become heavier and heavier (at least for me) past half of the book. But I digress. Back to your very short solution, I would like to point out I get your exact result for n = 1, using this series, disregarding the last term: \[\zeta \left ( \frac{1}{2} \right )+n\left ( \frac{2\sqrt{n}}{3}+\frac{1}{2\sqrt{n}}+\frac{1}{24\sqrt{n^{3}}}\frac{3}{8}\cdot \frac{1}{720\sqrt{n^{7}}}+\frac{35}{8}\cdot \frac{1}{40320\sqrt{n^{11}}}\frac{31185}{128}\cdot \frac{1}{3628800\sqrt{n^{15}}}+\cdots \right )\] By the time I posted my first WP 34s program, I had only the first three terms of the series. The sixth term doesn't help much for n = 1, but it of help as n gets larger: nSumnumber of terms 00011.0000347819670898784271377190473955 00010.99996764329521487842713771904739516 00058.3823323492756804873068982057405145 00058.3823323473540595691430164353888806 actual:8.382332347441762038738308734446847 070012359.861896817032384396050169396155 070012359.861896817032384396050147826886 actual:12359.86189681703238439605014782693 My second program is flawed, that is, it's inaccurate for small arguments (I don't remember what I did). Best regards, Gerson. 

04202015, 09:23 PM
Post: #15




RE: Oneliner minichallenge [HP71B]
.
Hi again, Gerson: (04202015 04:41 PM)Gerson W. Barbosa Wrote: Thank you for your ongoing interest in this fascinating subject! You're welcome. Thanks to you for issuing this particular oneliner minichallenge, it's indeed a fascinating subject as you say. Quote:At page 81 of his book Prime Obsession, John Derbyshire says: I followed the link but regrettably page 81 is nowhere to be seen, it belongs in a page gap which isn't visualized so I couldn't check the reference. Quote:But I digress. Back to your very short solution, I would like to point out I get your exact result for n = 1, using this series, disregarding the last term: [...] The sixth term doesn't help much for n = 1, [...] It's an asymptotic series (and thus divergent) so using more terms improves accuracy only up to some point, adding more terms after that actually degrades the precision. This can be seen in your example for x=1, where the first five terms do help while adding yet another one (or more) does not. Regards. V. . All My Articles & other Materials here: Valentin Albillo's HP Collection 

04222015, 10:57 PM
(This post was last modified: 04242015 04:14 PM by Gerson W. Barbosa.)
Post: #16




RE: Oneliner minichallenge [HP71B]
Hello again, Valentin,
(04202015 09:23 PM)Valentin Albillo Wrote:(04202015 04:41 PM)Gerson W. Barbosa Wrote: At page 81 of his book Prime Obsession, John Derbyshire says: It's still working here. There are links that lead to chapters 5 and 6 in page vii (Contents), but I cannot copy them: 5 Riemann’s Zeta Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 6 The Great Fusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 The other day links to more chapters were available though. (04202015 09:23 PM)Valentin Albillo Wrote:(04202015 04:41 PM)Gerson W. Barbosa Wrote: But I digress. Back to your very short solution, I would like to point out I get your exact result for n = 1, using this series, disregarding the last term: [...] The sixth term doesn't help much for n = 1, [...] You are right! Although the sixth term improves the result for n = 1, albeit only slightly, the seventh term makes it equal 1.00005029507, which is slightly worse than the two previous results. Curve fitting is an option if we want more accurate results for small numbers, as you can see in the (not so small) HP42S program. Best regards, Gerson. HP42S program: Code:
Examples: 1 .... 1.............(.....1....) 2 .... 2.41421356235 (.....6237 ) 3 .... 4.14626436995 (.....6994 ) 4 .... 6.14626436989 (.....6994 ) 5 .... 8.38233234743 (.....4744 ) 10.... 22.4682781862 (.....1862 ) 100... 671.462947104 (.....7103 ) 1.E12. 6.66666666668E17 (....67 ) 1.E333 2.10818510678E499 (...78 ) a := 2*n*sqrt(n)/3 b := 3*a/(4*n) c := b/(12*n) d := c/(80*n^2) e := 5*d/(24*n^2) s := (a + b + c  d + e  0.207886224977355)/(1 + ln(1 + exp(8.03012316626854*ln(n)  9.07189622971032  1.19449787181792/n))) P.S.: On the HP71B, this hardly fits in two lines: Code:
? 1 1 ? 2 2.41421356235 ? 3 4.14626436995 ? 4 6.14626436989 ? 5 8.38233234743 ? 10 22.4682781862 ? 100 671.462947104 ? 1E12 6.66666666668E17 ? 1E333 WRN L1:Underflow WRN L2:Underflow 2.10818510678E499 P.P.S.: The constant 9.07189622971 in step 40 of the the HP42S program and in line 2 of the HP71B program has how been corrected. Previously the second '9' was missing: 9.0718622971. As a result, both programs now return 1 exactly for n = 1. I ought to have noticed 0.99999999882 was way off! 

« Next Oldest  Next Newest »

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