Programming Challenge: Powers and Roots « Next Oldest | Next Newest »

 ▼ Patrick Senior Member Posts: 266 Threads: 32 Joined: Jan 1970 03-19-2003, 03:05 PM Through the evil of eBay, I recently managed to pick up a pristine copy of the HP-15C Advanced Functions Handbook. I've only had a half hour or so to read it so far, but it appears to be quite excellent. One of the interesting numerical oddities that they point out surrounds the function obtained by taking the square root of a number 50 times and then taking the square or the result 50 times. While mathematically you should end up with the identity function (f(x) = x, for x >= 0), numerically you end up with something quite different. The little challenge that I propose is to write the shortest program to compute the function described. You may only use square roots, squares and arithmetic functions. No y^x, no log/ln, no e^x, etc. In order to make the problem non-trivial, I impose the additional constraint that you may not use any conditional tests, such as [x=0?], [ISG], [DSE], or [F?]. A secondary question is how large the number 50 can be increased to on your selected platform using only these self same functions. Since I only know RPN, not RPL, I'd be primarily interested in seeing the solution done using the former method. I suggest the HP-11C and HP-15C as the platforms to use since I happen to like them the best, but others would work equally well. ▼ Dave Shaffer (Arizona) Posting Freak Posts: 776 Threads: 25 Joined: Jun 2007 03-19-2003, 04:29 PM Am I missing something in your challenge? re: "One of the interesting numerical oddities that they point out surrounds the function obtained by taking the square root of a number 50 times and then taking the square or the result 50 times. While mathematically you should end up with the identity function (f(x) = x, for x >= 0), numerically you end up with something quite different." Unless you do something fancy to maintain precision (maybe that's the challenge?), if you take the square root 50 times (I assume you mean the equivalent of hitting the square root key 50 times in a row), unless you start with a very big - or very small - number, you wind up with 1.000000000! No matter how many times you square that, you're gonna get 1. (I just tried with my '32SII: 99*10^99 goes to 1.000000000 on the display after about 40 square root pushes.) ▼ Patrick Senior Member Posts: 266 Threads: 32 Joined: Jan 1970 03-19-2003, 04:37 PM Well, my challenge hasn't touched upon the numerical lessons (yet). I've only asked for an algorithm to compute the function in the shortest number of steps. Taking advantage of the numerical oddities wasn't what I had in mind, but your point is certainly valid. ▼ Vieira, Luiz C. (Brazil) Posting Freak Posts: 4,027 Threads: 172 Joined: Aug 2005 03-19-2003, 07:13 PM Hi; the example exactly illustrates something that cannot be computed with the Voyagers available range. I'd suggest to write an algorithm or program to compute the uncertainty of the result. Something like the value placed in the Y-register after a numerical integration. The Advanced Functions Handbook deals with accurate, errors and error recovering/detection in an HP15C when using advanced functions - integration, SOLVE, complex numbers and matirces - as you have already seen. You can perform many of the examples in the hP42S and check for the difference/correctness obtained when internal 15 digits take place, instead of 12 internal digits available in the HP15C. You may also see that many examples focus unusual situations, say, regular users unusual situations. Just to add a few more information. Luiz C. Vieira - Brazil Michael F. Coyle Member Posts: 172 Threads: 5 Joined: Jan 1970 03-20-2003, 11:41 PM I observed the same thing...it takes only 38 square roots to get from 9.999999999E99 to 1.0 on the HP-11C, and only 39 square roots to get from 1.0E-99 to 1.0. Still, even though it's therefore useless, I present a solution anyway, in only 32 steps. (Two of which are optional.) To make it more fun, I will present it without comment and (sadistically) leave it as an exercise to the reader to puzzle out. - Michael ```f LBL A (This step's optional!) GSB 5 GSB 4 sqrt x sqrt x f PSE (This one too!) g x^2 g x^2 GSB 8 GSB 8 f LBL 8 GSB 7 f LBL 7 GSB 6 f LBL 6 g x^2 g x^2 g x^2 g x^2 g RTN f LBL 5 GSB 4 f LBL 4 GSB 3 f LBL 3 GSB 2 f LBL 2 sqrt x sqrt x sqrt x sqrt x g RTN ```

 Possibly Related Threads... Thread Author Replies Views Last Post HP prime: logs and roots Alberto Candel 5 912 11-20-2013, 12:31 PM Last Post: Manolo Sobrino HHC 2013 RPN Programming Challenge - Final Thought Jeff O. 7 1,285 10-17-2013, 11:02 AM Last Post: Jeff O. HP 50g - collect by powers of x Juraj O. 9 1,072 02-18-2013, 05:09 AM Last Post: C.Ret HHC 2012 RPN Programming Challenge Conundrum Jeff O. 15 1,863 10-08-2012, 03:34 PM Last Post: Gerson W. Barbosa Mini-challenge: HHC2012 RPL programming contest with larger input David Hayden 14 1,924 10-05-2012, 10:36 PM Last Post: David Hayden Weekend programming challenge: Euler's Totient function Allen 36 3,870 06-03-2012, 10:39 PM Last Post: Paul Dale HP-51G: Back to the honorable roots! Martin Paech 24 2,723 04-08-2012, 01:39 AM Last Post: db (martinez, ca.) A Sunday Programming Challenge Allen 61 5,305 03-17-2012, 06:48 PM Last Post: Allen 35s - find roots of 3rd and higher order equations Chris C 11 1,490 02-25-2012, 02:55 PM Last Post: Thomas Klemm HP-35 powers with negative numbers Dan Lewis 26 2,756 01-26-2012, 02:41 AM Last Post: Nick_S

Forum Jump: