The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function
/showthread.php 795 errorHandler->error





Post Reply 
(35S) Fibonacci Fun for the HP35s and the number phi
01-22-2015, 08:07 AM (This post was last modified: 06-15-2017 01:35 PM by Gene.)
Post: #1
(35S) Fibonacci Fun for the HP35s and the number phi
Greetings,
While playing with my new FX115es Plus from Casio I ran into the infamous Fibonacci sequence, once again, Fn = Fn-1 + Fn-2 using the classic 1 1 startup:
1 1 2 3 5 8 13 21 34 ...

The authors of the fx115 user guide were demonstrating the [Ans] + [PreAns] [=] iterative key sequence and were pleased that with the correct startup [1] [=], [+] [1] followed by repeating [Ans] + [PreAns] iteratively would generate the Fibonacci numbers line at a time 'till ad infinitum or 'till boredom; which ever came first prior to overflow.

That's the back-story; the fx115 in not programable and although the [PreAns] feature is relatively useful, the example was not terribly enlightening.

The little small exercise did give me pause to think about my new HP35s programable with classic four level stack, LASTx, RPN; ... and the iterative steps that would be necessary to conduct the same relatively painless example on the 35s--- bumping the Fibonacci sequence of numbers up the stack and out the TOP. The rules? Glad you asked: only stack manipulations allowed (no exchanges except for [x<>y]), only [+] operation, no direct nor indirect memory registers, and no loss of Fibonacci numbers until they leave the T level of the stack-- out the TOP. Also, we are assuming the classic startup of 1 1, NOT 0 1. Stop reading here and play with your HP a bit to see what you think the minimum steps are that produce the results manually, and then continue reading (you can use any classic HP to do this step).

Welcome back. The setup is:
Code:


     [1]
     [+]
     [ENTER]
     [ENTER]
... and the five(5) iterative steps are:
Code:


     [LASTx]          (retrieves old Fn-2)
     [x<>y]           (sets up the sum   LASTx will become next Fn-2)
     [+]                 (adds   Fn = Fn-1 + Fn-2    x holds Fn  y holds Fn-3)
     [LASTx]           (retrieves new Fn-2)
     [x<>y]            (x holds old Fn [new Fn-1]   y holds old Fn-1 [new Fn-2])
Try it.

So what? What if we automate the silly thing so that we can have the machine stop on whatever nth Fibonacci number we want (from a parmameter) and then allow us to step through the rest with [R/S] or watch it run 'slowly' with an embedded [PSE]?

Here is the program key sequence:
Code:

     F001  LBL F
     F002  CLSTK
     F003  0.00201               ( this sets up DSE counter register mantissa
     F004  STO C                  ( iterative counter
     F005  CLx
     F006  4                         ( default  nth  Fibonacci number (3)   1 1 2 3
     F007  STOP                   ( get operator a chance to change the default
     F008  STO+ C               ( sets the final counter   4.00201
     F009  CLx
     F010  1                         (begin  1 1  setup
     F011  +
     F012  ENTER
     F013  XEQ F020             (call iterative sequence subroutine
     F014  DSE C                  (decrement the counter and prepare to loop back
     F015  GTO F013             (loop
     F016  STOP                    (display nth Fibonacci ;   stack holds last four Fibs
     F017  XEQ F020              (begin automated continue with PSE
     F018  PSE
     F019  GTO F017              (loop ad infinitum, or until boredom
     
     F020  LASTx                    (entry point of iterative sequence subroutine
     F021  x<>y 
     F022  +
     F023  LASTx
     F024  x<>y
     F025  RTN
Run this code with the standard [XEQ] F [ENTER].

The machine will stop with 4 in x, waiting for the operator to accept the default, or change it to a higher integer. The largest integer which may be entered (without overflow) is 59. Clear the 4, and place 59 in the x stack position, then press [R/S].

Four and a half seconds later the stack will contain the last four Fibs from the nth and x will hold 956,722,026,041.

Run the program again, this time leaving the default of 4. The stack will hold

t 1
z 1
y 2
x 3

Now, press [R/S] and watch the Fibonacci numbers bump up the stack ad infinitum or boredom... whichever comes first prior to overflow.

Do THAT on your FX115es Plus, I double dare you.

PS It is well known that the ratio of any two consecutive Fibonacci numbers produces a more and more accurate convergence on the number phi:
(SQ(5)+1)/2. This happens accurately (more or less) for the HP35s at about the 29th iteration of the above program. Stop the sequence at the 29th iteration and then press [x<>y] [/] and you should see: 1.61803398875 ~phi more or less!

PSS The program may be interrupted with [R/S] but remember that since the main program never hits a RTN the program counter is stuck in the F program. Inadvertently hitting [R/S] again will restart the program (which you may not want).
To avoid this, when you're done playing, either delete F or press [GTO] [.] [.] to set the program counter to the TOP.
[/php]

Cheers
marcus
Smile

Kind regards,
marcus
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(35S) Fibonacci Fun for the HP35s and the number phi - MarkHaysHarris777 - 01-22-2015 08:07 AM



User(s) browsing this thread: 1 Guest(s)