The Museum of HP Calculators

HP Forum Archive 19

 A simple 11c/15c mini-challenge (phi)Message #1 Posted by Gerson W. Barbosa on 20 Aug 2009, 12:50 p.m. 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.

 Re: A simple 11c/15c mini-challenge (phi)Message #2 Posted by Alain Mellan on 20 Aug 2009, 2:12 p.m.,in response to message #1 by Gerson W. Barbosa We can get a good approximation with: ```4 PI / x^2 ```

 Re: A simple 11c/15c mini-challenge (phi)Message #3 Posted by Gerson W. Barbosa on 20 Aug 2009, 6:04 p.m.,in response to message #2 by Alain Mellan Approximations are welcome. The following is better but requires five steps: ```2 ex ex 1E03 / ``` Regards, Gerson.

 Re: A simple 11c/15c mini-challenge (phi)Message #4 Posted by Vladan Dugaric on 20 Aug 2009, 2:37 p.m.,in response to message #1 by Gerson W. Barbosa 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.

 Re: A simple 11c/15c mini-challenge (phi)Message #5 Posted by Chuck on 20 Aug 2009, 3:28 p.m.,in response to message #4 by Vladan Dugaric 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.

 Re: A simple 11c/15c mini-challenge (phi)Message #6 Posted by Jeff O. on 20 Aug 2009, 4:06 p.m.,in response to message #5 by Chuck 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.

 Re: A simple 11c/15c mini-challenge (phi)Message #7 Posted by Gerson W. Barbosa on 20 Aug 2009, 6:33 p.m.,in response to message #6 by Jeff O. 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.

 Re: A simple 11c/15c mini-challenge (phi)Message #8 Posted by Jeff O. on 20 Aug 2009, 8:42 p.m.,in response to message #7 by Gerson W. Barbosa I did not think for a second that that is what you had in mind. I'm sure there is a better way.

 Re: A simple 11c/15c mini-challenge (phi)Message #9 Posted by Gerson W. Barbosa on 20 Aug 2009, 4:57 p.m.,in response to message #4 by Vladan Dugaric 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.

 Re: A simple 11c/15c mini-challenge (phi)Message #10 Posted by Vladan Dugaric on 20 Aug 2009, 5:27 p.m.,in response to message #9 by Gerson W. Barbosa 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.

 Re: A simple 11c/15c mini-challenge (phi)Message #11 Posted by Gerson W. Barbosa on 20 Aug 2009, 5:40 p.m.,in response to message #10 by Vladan Dugaric 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.

 Re: A simple 11c/15c mini-challenge (phi)Message #12 Posted by Paul Dale on 20 Aug 2009, 6:06 p.m.,in response to message #1 by Gerson W. Barbosa 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

 Re: A simple 11c/15c mini-challenge (phi)Message #13 Posted by Gerson W. Barbosa on 20 Aug 2009, 6:15 p.m.,in response to message #12 by Paul Dale 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.

 Re: A simple 11c/15c mini-challenge (phi) SPOILERMessage #14 Posted by Paul Dale on 20 Aug 2009, 7:41 p.m.,in response to message #13 by Gerson W. Barbosa 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

 Re: A simple 11c/15c mini-challenge (phi)Message #15 Posted by Valentin Albillo on 21 Aug 2009, 4:50 a.m.,in response to message #1 by Gerson W. Barbosa 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.

 Re: A simple 11c/15c mini-challenge (phi)Message #16 Posted by Gerson W. Barbosa on 21 Aug 2009, 10:46 a.m.,in response to message #15 by Valentin Albillo 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.

 Re: A simple 11c/15c mini-challenge (phi)Message #17 Posted by Jeff O. on 21 Aug 2009, 12:44 p.m.,in response to message #16 by Gerson W. Barbosa So is the anwswer: ```.5 sinh-1 ex ``` or: ```2 1/x sinh-1 ex ``` Either sequence takes me six keystrokes. ...

 Re: A simple 11c/15c mini-challenge (phi)Message #18 Posted by Gerson W. Barbosa on 21 Aug 2009, 1:30 p.m.,in response to message #17 by Jeff O. 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.

 Re: A simple 11c/15c mini-challenge (phi)Message #19 Posted by Jeff O. on 21 Aug 2009, 3:55 p.m.,in response to message #18 by Gerson W. Barbosa 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.

 Re: A simple 11c/15c mini-challenge (phi)Message #20 Posted by Gerson W. Barbosa on 21 Aug 2009, 4:56 p.m.,in response to message #19 by Jeff O. 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.

 Re: A simple 11c/15c mini-challenge (phi)Message #21 Posted by Paul Dale on 22 Aug 2009, 8:35 a.m.,in response to message #18 by Gerson W. Barbosa 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

 Re: A simple 11c/15c mini-challenge (phi)Message #22 Posted by Gerson W. Barbosa on 22 Aug 2009, 9:33 a.m.,in response to message #21 by Paul Dale 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.

 Re: A simple 11c/15c mini-challenge (phi)Message #23 Posted by Paul Dale on 22 Aug 2009, 8:17 a.m.,in response to message #15 by Valentin Albillo 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

 Re: A simple 11c/15c mini-challenge (phi)Message #24 Posted by Gerson W. Barbosa on 22 Aug 2009, 9:05 a.m.,in response to message #23 by Paul Dale 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.

 Re: A simple 11c/15c mini-challenge (phi)Message #25 Posted by Paul Dale on 22 Aug 2009, 6:23 p.m.,in response to message #24 by Gerson W. Barbosa 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.

 Re: A simple 11c/15c mini-challenge (phi)Message #26 Posted by Kiyoshi Akima on 21 Aug 2009, 11:53 a.m.,in response to message #1 by Gerson W. Barbosa Do multi-digit number entries count as only one step? If so, then ```1.25 sqrt .5 + ```

 Re: A simple 11c/15c mini-challenge (phi)Message #27 Posted by Gerson W. Barbosa on 21 Aug 2009, 12:22 p.m.,in response to message #26 by Kiyoshi Akima Actually, .5 is part of one of the solutions and that alone takes up two steps on the 11c/15c. Regards, Gerson.

 Re: A simple 11c/15c mini-challenge (phi)Message #28 Posted by Kiyoshi Akima on 21 Aug 2009, 12:48 p.m.,in response to message #1 by Gerson W. Barbosa 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.

 Re: A simple 11c/15c mini-challenge (phi)Message #29 Posted by Gerson W. Barbosa on 21 Aug 2009, 1:44 p.m.,in response to message #28 by Kiyoshi Akima :-) 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.

Go back to the main exhibit hall