[VA] SRC #017 - April 1st, 2024 Spring Special
|
04-01-2024, 06:59 PM
Post: #1
|
|||
|
|||
[VA] SRC #017 - April 1st, 2024 Spring Special
Hi, all, Welcome to my new SRC #017 - April 1st, 2024 Spring Special
Once again April 1st is here and I want to celebrate both it and the new season with this Spring Special where I'm proposing a number of mini-challenges for you to tackle with your favorite vintage HP calc, plus interesting facts not widely known (if at all).
1. LOL the First: Squares Let's start nice and easy. Square numbers have been a source of beauty and admiration since Pythagoras did his thing with them millennia ago. Just look at these small (related) beauties ! 375,5012 = 141,001,001,001 751,0022 = 564,004,004,004 Now, if these are cute just consider the sheer amounts of beauty you'll discover when dealing with their bigger relatives, so this mini-challenge asks you to calculate the following 22 squares: 1308349044300152392 = ? 4712877147889716634938992 = ? 257811083055916284179757382 = ? 1414220828760672199498050500052 = ? I know you can simply paste them in Wolfram Alpha or use the multiprecision library in your RPL model or mutiprecision canned software in any device or web site and get done with it, but it would be so lame that you'll risk ridicule. What I'm asking you to do is to program your own multiprecision squaring routine in your vintage HP calc and use it to get the results. It's not that difficult at all, you know ... that is, if you've got what it takes .. I'll post my own squaring routine that I wrote for the HP-71B from scratch, just a mere 483 bytes long and taking the form of a user-defined function so that it can be called right from the command line. It produces results like this, which you can profitably use for testing your code: 31479267847267265637800300423742371877512 = 9909443041999946686063013207932562462851613614976494122324802303779777224438001 Remember: if you decide to solve this mini-challenge, you must post both the (beautiful) results and the code which produces them, do not post results alone. Comments are most welcome, plus you might try getting more results like these. 2. LOL the Second: GCD OK, full throttle now. You may remember the GCD function appearing in my recent SRC #016 - Pi Day 2024 Special, where it was used in the Second appearance to count the number of co-prime pairs of random integers in a range and then this count was used to compute an approximation to \(\pi\). Sample GCD values: GCD(35, 13) = 1, GCD(35, 14) = 7 and GCD(35, 15) = 5 In this mini-challenge you must write code for any HP calc to find out the answer to this simple question: As we have that GCD(15, 4) = 1 and GCD(15, 5) = 5, for what value of x is GCD(15, x) = 2 ? As always, you must post both results and code. Comments also most welcome. I'll post mine next Sat/Sun. 3. LOL the Third: Random You may be aware that advanced 12-digit HP models of old incorporated an excellent RNG (pseudo-Random Number Generator) which could generate a trillion (i.e. 1012) full 12-digit real (pseudo-)random numbers in the interval [0-1) before repeating. This RNG passes the Spectral test so it's extremely reliable for use in simulations and other advanced topics (e.g. multidimensional integration, Monte Carlo algorithms, etc.) without fear of any bias or short period degrading the results. As far as I know, the implementations for the HP-71B, the RPL models, the HP-42S and Free42 (and perhaps many other HP models) are functionally identical so they produce exactly the same sequence of RNDs from the same seed. Now, this mini-challenge's question is:
N First RND Next RND |Difference| ---------------------------------------------------------------- 2 .731362440213 .77207218067 .040709740457 13 5.64471991805E-2 6.30768172146E-2 6.6296180341E-3 125 .805774019056 .803607575861 .002166443195 ... I'll post my 3-line, ~90 byte solution which produces the above, plus a 4-line, 149-byte variant which stops right before a given pair of consecutive RNDs is generated so that you can generate them manually right from the command line (i.e. >RND;RND) and see for yourself how close they indeed are. And remember, post code and results. What's your record ? Me, I've found a pair of consecutive RNDs which are only 0.00000000001 apart ! Can you do better ? 4. LOL the Fourth: Logs This is not a mini-challenge but a somewhat unexpected fact I've found, so you don't need to do anything but read on and eventually comment. I've always thought that the two logarithmic functions available in the 10-digit HP-15C (LOG and LN, base 10 and base e respectively) would have essentially the same accuracy overall, but lo and behold, I've found that LOG seems to be substantially more accurate in some cases than LN. For instance, let's consider computing logb(57) / logb(5), which should return exactly 7 for any base b ≥ 2. But the actual results are: LN(57) / LN(5) -> 7.000000004 { 4 ulp from the exact value } LOG(57) / LOG(5) -> 7 { exact } and the same happens with other powers N of 5, e.g. for N = 2 to 9 we have: N LOG LN --------------------------------- 2 2.00000001 2.00000001 3 3 3.00000001 4 4 4.00000001 5 5.00000001 5.00000001 6 6 6.00000002 7 7 7.00000004 8 8.00000001 8.00000002 9 9 9.00000001 ----------------------------------- Total ulps: 3 13 { more than 400% larger error overall } This much larger error puzzled me no end but I thought that perhaps the limited 10-digit accuracy (13-digit internally) might be playing a role and decided to test the same computations using the 12-digit (15-digit internally) HP-71B, which has LN, LOG10 and LOG2 (respectively base e, base 10 and base 2.) These were the results for power 8: >STD >LN(5^8) / LN(5) -> 8.00000000004 { 4 ulp from the exact value } >LOG10(5^8) / L0G10(5) -> 8 { exact } >LOG2(5^8) / LOG2(5) -> 7.99999999999 { 1 ulp from the exact value } so we see that all three results differ among them, being in error by 4 ulp, 0 ulp and 1 ulp, respectively, and again the same happens with other powers N of 5, e.g. for N = 2 to 9 we have: N LOG10 LN --------------------------------------- 2 2 2.00000000001 3 3 3.00000000001 4 3.99999999999 4.00000000001 5 5 5.00000000001 6 6.00000000001 6.00000000001 7 7 6.99999999999 8 8 8.00000000004 9 8.99999999999 9.00000000002 ---------------------------------------- Total ulps: 3 12 { 400% larger error overall } and again the LN error is much larger, so having two extra digits didn't help at all. For LOG2 (not shown in the table above) the Total ulps for the range is 6 ulps, half LN's total error but twice LOG10's total error. In the end, LOG10 seems to be the most accurate logarithm available. If you want to pursue the matter, you can try the above examples in your HP models, both 10-digit and 12-digit, from the first HP-35 up to the latest RPL models, to see if LOG10 and LN differ that much in their respective errors. Testing other range of values (here from 52 = 25 to 59 = 1,953,125) could be revealing as well. Are there arguments with even larger errors ? At any rate, comments and discussion would be most welcome. 5. LOL the Fifth: Gamma Here's something peculiar I noticed while playing around with my HP-71B several decades ago, in Experimental Mathematics fashion. Back then, I executed this loop directly from the command line to list the values of \(\Gamma\)(10-1), \(\Gamma\)(10-2), ..., \(\Gamma\)(10-10), and got the following unexpectedly peculiar results: >DESTROY ALL @ FOR N=1 TO 10 @ N;GAMMA(10^(-N))@ NEXT N N \(\Gamma\)(10-N) ------------------- 1 9.51350769867 2 99.4325851191 3 999.423772485 4 9999.42288323 5 99999.4227942 6 999999.422785 7 9999999.42278 8 99999999.4228 9 999999999.423 10 9999999999.42 where the evergrowing integer part of each value is clearly 10N - 1, while the fractional part seems to be quickly converging to some limit around ~0.42 but the 12-digit HP-71B lacks the accuracy needed to refine it further, so this mini-challenge is: You must write code to find this limit to much greater accuracy (say 10-12 digits or more,) perhaps by simply using Free42 Decimal to compute the values. Once done, answer these two questions:
6. LOL the Sixth: Miscellanea
That's all. Waiting for your clever solutions and/or comments galore, I'll post mine next Saturday/Sunday so you've got plenty of time to concoct and polish your code. And no CODE pannels, please. V. All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 11 Guest(s)