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.
A simple 11c/15c mini-challenge (phi)
|
|
« Next Oldest | Next Newest »
|
▼
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. ▼
08-20-2009, 02:12 PM
We can get a good approximation with:
4 ▼
08-20-2009, 06:04 PM
Approximations are welcome. The following is better but requires five steps:
2 Regards, Gerson.
08-20-2009, 02:37 PM
A solution with 4 steps excluding LBL that requires manual input before starting program:
LBL A To run:
1 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 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 because phi = 2 cos 36 degrees. Or
1 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. ▼
08-20-2009, 03:28 PM
You beat me to it Vladan. I had: Lbl Aand 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. ▼
08-20-2009, 04:06 PM
Since: 1
is no shorter than: 1 I propose the following, which works with all starting values:
LABEL A 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.
▼
08-20-2009, 06:33 PM
Quoting myself:
I think your program meets the requirement, even though that was not what I had in mind. Regards, Gerson.
08-20-2009, 04:57 PM
Quote: 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: http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/archv018.cgi?read=145811 Regards, Gerson. ▼
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. ▼
08-20-2009, 05:40 PM
Quote: Answer in the Museum's Calculator Comparison Table. The solution I've found doesn't involve Gamma. Gerson.
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 ▼
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.
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 Best regards from V. ▼
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.
▼
08-21-2009, 12:44 PM
So is the anwswer: .5 or:
2 Either sequence takes me six keystrokes. ... ▼
08-21-2009, 01:30 PM
Yes, you've found 'em!. Interesting isn't it? http://de.wikipedia.org/wiki/Sinus_Hyperbolicus_und_Kosinus_Hyperbolicus 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 Gerson. ▼
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. ▼
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.
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)
36 2 ->RECT in DEG mode The conversion from polar to rectangular coordinates:
| STACK IN | STACK OUT 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) 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)
▼
08-22-2009, 09:33 AM
Quote: And 2COS(36) gives
(1+sqrt(5))/2 but no explicit reference to phi... On the other hand, 1.6180339887498948482 gives
Phi+1 e^ArcSinh(1/2) gives a lot of interesting results though. Gerson.
08-22-2009, 08:17 AM
Quote: This doesn't work if there is a value in the complex X register :-)
▼
08-22-2009, 09:05 AM
Quote: 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.
08-21-2009, 11:53 AM
Do multi-digit number entries count as only one step?
If so, then 1.25 ▼
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.
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 You may have better luck replacing the second step with e^x.
The three-step program RANDshould produce the desired result, if iterated enough times. Please do not consider these as serious attempts at the mini-challenge. ▼
08-21-2009, 01:44 PM
:-) You only have to find the right seed. See message #9 in the link below: http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/archv017.cgi?read=112157 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. |