A simple 11c/15c mini-challenge (phi) « Next Oldest | Next Newest »

 ▼ Gerson W. Barbosa Posting Freak Posts: 2,761 Threads: 100 Joined: Jul 2005 08-20-2009, 12:50 PM The goal is to obtain the golden ratio phi=1.618033989 using the least number of programming steps. There are at least two four-step solutions (LBL and RTN don't count). Gerson. ▼ Alain Mellan Member Posts: 55 Threads: 5 Joined: Jul 2007 08-20-2009, 02:12 PM We can get a good approximation with: ```4 PI / x^2 ``` ▼ Gerson W. Barbosa Posting Freak Posts: 2,761 Threads: 100 Joined: Jul 2005 08-20-2009, 06:04 PM Approximations are welcome. The following is better but requires five steps: ```2 ex ex 1E03 / ``` Regards, Gerson. Vladan Dugaric Junior Member Posts: 34 Threads: 0 Joined: Jul 2008 08-20-2009, 02:37 PM A solution with 4 steps excluding LBL that requires manual input before starting program: ```LBL A 1/x 1 + RTN``` To run: ```1 fA fA fA ... fA``` Eventually, the value converges to phi. This program implements the continued fraction formula: phi = 1/(1 + 1/(1 + 1/(...))) Or, an even shorter solution (3 steps): ```LBL A 1 + SQRT RTN``` implementing the formula phi = sqrt(1 + sqrt(1 + ...)) Again, run by pressing fA fA fA ...; this will converge with anything in X that won't cause SQRT to return an error, therefore -1 or anything greater will do. Or, even simpler (but 5 steps): ```LBL A 3 6 cos 2 x RTN``` because phi = 2 cos 36 degrees. Or ```1 ENTER .5 ->P LSTx +``` because phi = 0.5 + diagonal of rectangle with sides (1/2, 1), but this requires 7 steps. Vladan Edited: 20 Aug 2009, 3:25 p.m. ▼ Chuck Senior Member Posts: 320 Threads: 59 Joined: Dec 2006 08-20-2009, 03:28 PM You beat me to it Vladan. I had: ```Lbl A 1 + sqrt GOTO A ``` and press R/S after running a few seconds. As you mentioned, as long as the stack starts with x>-1 it will converge to phi. CHUCK Edited: 20 Aug 2009, 3:29 p.m. ▼ Jeff O. Posting Freak Posts: 875 Threads: 37 Joined: Jul 2005 08-20-2009, 04:06 PM Since: ```1 + SQRT ``` is no shorter than: ```1 + 1/x ``` I propose the following, which works with all starting values: ```LABEL A 1 + 1/x GOTO A RTN ``` press fA, let run for a while, then press R/S. If not converged, or if stopped with 0.6180339898 in the display, press R/S twice in rapid succession. ▼ Gerson W. Barbosa Posting Freak Posts: 2,761 Threads: 100 Joined: Jul 2005 08-20-2009, 06:33 PM Quoting myself: "The goal is to obtain the golden ratio phi=1.618033989 using the least number of programming steps." I think your program meets the requirement, even though that was not what I had in mind. Regards, Gerson. ▼ Jeff O. Posting Freak Posts: 875 Threads: 37 Joined: Jul 2005 08-20-2009, 08:42 PM I did not think for a second that that is what you had in mind. I'm sure there is a better way. Gerson W. Barbosa Posting Freak Posts: 2,761 Threads: 100 Joined: Jul 2005 08-20-2009, 04:57 PM Quote: Or ```1 ENTER .5 ->P LSTx +``` because phi = 0.5 + diagonal of rectangle with sides (1/2, 1), but this requires 7 steps. This is interesting but 5 sqrt 1 + 2 / would be one step shorter. The other solutions are also interesting but the one we are looking for is non-iterative. Tip: this one (and its variation) will work on the 11c and the 15c, but will not work on any other Voyager. An older related mini-challenge by Paul Dale: Regards, Gerson. ▼ Vladan Dugaric Junior Member Posts: 34 Threads: 0 Joined: Jul 2008 08-20-2009, 05:27 PM Something with factorial function perhaps? HP-11C and HP-15C factorial is actually gamma(n+1) while 12C factorial is just factorial and does not accept decimal values. 16C does not have factorial and I don't know if 10C factorial is gamma or just factorial. ▼ Gerson W. Barbosa Posting Freak Posts: 2,761 Threads: 100 Joined: Jul 2005 08-20-2009, 05:40 PM Quote: I don't know if 10C factorial is gamma or just factorial. Answer in the Museum's Calculator Comparison Table. The solution I've found doesn't involve Gamma. Gerson. Paul Dale Posting Freak Posts: 3,229 Threads: 42 Joined: Jul 2006 08-20-2009, 06:06 PM I can find three command sequences of length four that produce the required answer. Two are basically the same. All are exactly six key presses. - Pauli ▼ Gerson W. Barbosa Posting Freak Posts: 2,761 Threads: 100 Joined: Jul 2005 08-20-2009, 06:15 PM Looks like you found them (and an extra one)! Mine, which are basically the same, are four-step long and requires exactly six key presses as well. Regards, Gerson. ▼ Paul Dale Posting Freak Posts: 3,229 Threads: 42 Joined: Jul 2006 08-20-2009, 07:41 PM Okay, here us the unique one then: ```6 g x^2 2 f ->R ``` Four commands & six keystrokes. It assumes the calculator is in DEG mode so it isn't as good as the other solutions. I won't spoil the other two :-) - Pauli Valentin Albillo Posting Freak Posts: 1,755 Threads: 112 Joined: Jan 2005 08-21-2009, 04:50 AM Not wanting to spoil the 4-step solutions either, I'll just offer this remarkable HP-15C-specific solution which works in any angular mode: ``` .5 Re<>Im SIN-1 Re<>Im ex ``` Best regards from V. ▼ Gerson W. Barbosa Posting Freak Posts: 2,761 Threads: 100 Joined: Jul 2005 08-21-2009, 10:46 AM Hello Valentin, Thanks for participating. This is based on formula (26) in http://mathworld.wolfram.com/GoldenRatio.html. I wonder why its hyperbolic counterpart, which only lacks the imaginary constant, is not there. Well, it appears now I have spoiled it all :-) Best regards, Gerson. ▼ Jeff O. Posting Freak Posts: 875 Threads: 37 Joined: Jul 2005 08-21-2009, 12:44 PM So is the anwswer: ```.5 sinh-1 ex ``` or: ```2 1/x sinh-1 ex ``` Either sequence takes me six keystrokes. ... ▼ Gerson W. Barbosa Posting Freak Posts: 2,761 Threads: 100 Joined: Jul 2005 08-21-2009, 01:30 PM Yes, you've found 'em!. Interesting isn't it? When googling for "sinh(ln(phi))" I found only six hits. It appears only the German and Polish versions of wikipedia mentions it: http://pl.wikipedia.org/wiki/Funkcje_hiperboliczne (and now I know what the Polish currency, the zloty, comes from :-) The equality is easy to prove: ```phi=(sqrt(5)+1)/2 sinh(ln(phi))=(e^ln(phi) - 1/e^ln(phi))/2 = (phi - 1/phi)/2 = 1/2 ``` Gerson. ▼ Jeff O. Posting Freak Posts: 875 Threads: 37 Joined: Jul 2005 08-21-2009, 03:55 PM Yes, quite interesting. Thanks for sharing! I certainly did not find the above references. I looked at equation 26 in the reference of your previous post: ```sin(i ln(phi)) = 0.5 i ``` Then I found a calculator that can do arcsin with a complex argument (my 42s) and took arcsin(0.5i), which is 0+ i0.48121182506. I guess that told me that ln(phi) is equal to 0.48121182506. You had mentioned hyperbolics, so I wondered if arcsinh(0.5i) might go somewhere, which it did not. Then tried arcsinh(0.5) and found it equals 0.48121182506, previously found to be ln(phi), so I was done. So basically, using the clues you gave, I just fiddled around until I got the right answer. . Edited: 21 Aug 2009, 4:02 p.m. ▼ Gerson W. Barbosa Posting Freak Posts: 2,761 Threads: 100 Joined: Jul 2005 08-21-2009, 04:56 PM Until yesterday I hadn't looked up any reference either. I was trying to simplify some constants so that they took up less steps on the 11C. For instance, I had found 4 LN HYP SIN was equivalent to 1.875, which was a gain (3 steps instead of 5). For other constants I would do the backward sequence: k HYP-1 SIN ex. I don't remember for what reason, since there's no way to get .5 with less than two steps, I did .5 HYP-1 SIN ex. I recognized the number on the display as phi... The following is somewhat interesting: It appears the continued fraction form for 1/n+sqrt(1+(1/n)^2), which is equivalent to e^sinh-1(1/n), where n is an integer greater than 1, is always [1; n-1, 1, 1, n-1, 1, 1, n-1, 1, 1, ...]. When n=2, the continued fraction form for the expression will be [1; 1, 1, 1, 1, 1, ...], that is, phi. Paul Dale Posting Freak Posts: 3,229 Threads: 42 Joined: Jul 2006 08-22-2009, 08:35 AM My alternate proof of the arcsinh version. Start with the formula for arcsinh: ``` arcsinh(x) = ln(x + sqrt(x^2+1)) ``` Taking EXP of this gives us: ``` e^arcsinh(x) = x + sqrt(x^2+1) ``` Not let x = 1/2 and substitute into the above: ``` 1/2 + sqrt(1/4 + 1) = 1/2 + sqrt(5/4) = 1/2 + sqrt(5)/2 = (1 + sqrt(5)) / 2 = phi ``` Now for my alternate solution: ``` 36 2 ->RECT in DEG mode ``` The conversion from polar to rectangular coordinates: ``` | STACK IN | STACK OUT Y | theta | r . SIN(theta) X | r | r . COS(theta) ``` We don't care about the output in the Y register. So consider the X register output when theta is 36 degrees and r is 2: ``` X = r . COS(theta) = 2 . COS(36) ``` Now, a quick look into some trigonometric identities / trigonometric tables or Wolfram alpha :-) gives us this interesting result: ``` COS(36) = (1 + sqrt(5)) / 4 ``` Finally, substitute this into the above: ``` X = 2 . COS(36) = 2 . (1 + sqrt(5)) / 4 = (1 + sqrt(5)) / 2 = phi ``` - Pauli ▼ Gerson W. Barbosa Posting Freak Posts: 2,761 Threads: 100 Joined: Jul 2005 08-22-2009, 09:33 AM Quote: Now, a quick look into some trigonometric identities / trigonometric tables or Wolfram alpha :-) gives us this interesting result: ``` COS(36) = (1 + sqrt(5)) / 4 ``` And 2COS(36) gives ```(1+sqrt(5))/2 1.6180339887498948482... 1/2 + sqrt(5)/2 [1; 1...] ``` but no explicit reference to phi... On the other hand, 1.6180339887498948482 gives ```Phi+1 (1+sqrt(5))/2 1/Phi, where Phi is the golden ratio conjugate ``` e^ArcSinh(1/2) gives a lot of interesting results though. Gerson. Paul Dale Posting Freak Posts: 3,229 Threads: 42 Joined: Jul 2006 08-22-2009, 08:17 AM Quote: Not wanting to spoil the 4-step solutions either, I'll just offer this remarkable HP-15C-specific solution which works in any angular mode: ... This doesn't work if there is a value in the complex X register :-) - Pauli ▼ Gerson W. Barbosa Posting Freak Posts: 2,761 Threads: 100 Joined: Jul 2005 08-22-2009, 09:05 AM Quote: This doesn't work if there is a value in the complex X register :-) This had occurred to me too, but in my tests it always worked. In complex mode, when only the real part is entered (.5) it is assumed the imaginary part is 0 and it will replace whatever value is there. Do you have an example? Gerson. ▼ Paul Dale Posting Freak Posts: 3,229 Threads: 42 Joined: Jul 2006 08-22-2009, 06:23 PM Yeah, it is a bit contrived though: ``` 22 Re<>Im CLx .5 Re<>Im ASIN Re<>Im e[sup]2[/sup] ``` Looks like the 15c's complex mode outsmarted me again :-( - Pauli Edited: 22 Aug 2009, 6:30 p.m. Kiyoshi Akima Senior Member Posts: 325 Threads: 18 Joined: Jul 2006 08-21-2009, 11:53 AM Do multi-digit number entries count as only one step? If so, then ```1.25 sqrt .5 + ``` ▼ Gerson W. Barbosa Posting Freak Posts: 2,761 Threads: 100 Joined: Jul 2005 08-21-2009, 12:22 PM Actually, .5 is part of one of the solutions and that alone takes up two steps on the 11c/15c. Regards, Gerson. Kiyoshi Akima Senior Member Posts: 325 Threads: 18 Joined: Jul 2006 08-21-2009, 12:48 PM Here's a two-step program that may or may not produce the desired result, depending on how lucky you get :-) ```RAND 1/x ``` You may have better luck replacing the second step with e^x. The three-step program ```RAND 1 + ``` should produce the desired result, if iterated enough times. Please do not consider these as serious attempts at the mini-challenge. ▼ Gerson W. Barbosa Posting Freak Posts: 2,761 Threads: 100 Joined: Jul 2005 08-21-2009, 01:44 PM :-) You only have to find the right seed. See message #9 in the link below: Strange as it might seem I considered this yesterday. I thought of trying to find a seed that would generate i/phi. But I realized it would take up more than 2 steps, if it existed... Gerson. Edited: 21 Aug 2009, 1:51 p.m.

 Possibly Related Threads... Thread Author Replies Views Last Post Simple Tetris. free for you to improve on cyrille de Brébisson 3 943 11-20-2013, 05:43 PM Last Post: Erwin Ried [HP-Prime] Simple Game (Bugs) CompSystems 1 662 11-01-2013, 10:18 AM Last Post: Han HPCC Mini Conference 2013 hugh steers 6 1,043 09-13-2013, 04:27 PM Last Post: BruceH Simple Math Question Namir 2 696 08-09-2013, 06:13 PM Last Post: Eddie W. Shore Picture from the Mini-HHC (LA) Geir Isene 11 1,467 07-07-2013, 01:06 PM Last Post: Jim Horn HP-42S with Electroluminescent screen and simple I/O port Jose Poyan 8 1,405 03-27-2013, 07:11 PM Last Post: Jose Poyan Simple sample programs for the HP-41CX? Tom Lewis 5 974 03-25-2013, 07:11 PM Last Post: Allen Simple? programming question [WP34S] Shawn Gibson 3 760 03-15-2013, 11:56 AM Last Post: Didier Lachieze My birthday, so a little commemorative mini-challenge ! Valentin Albillo 43 4,570 03-07-2013, 03:44 AM Last Post: Walter B Good (simple?) calculation for benchmarking? Jedidiah Smith 28 3,334 03-01-2013, 05:13 PM Last Post: Harald

Forum Jump: