Post Reply 
One-Line Exact CAS Fibonacci?
09-01-2018, 06:40 PM
Post: #1
One-Line Exact CAS Fibonacci?
In Home, generating successive members of the Fibonacci Sequence with each press of the Enter key, without using variables, is as simple as this:

[Image: Fibo.png]

However, Home is limited to 12-digit mantissas, so the above is only accurate up to 10^12.

My question is: Is it POSSIBLE to accomplish the same goal (generating successive members of the Fibonacci Sequence with each press of the Enter key, without using variables) in CAS, thereby allowing exact results > 10^12? (The above method fails in CAS because Ans(2) has a different meaning in CAS.) If possible at all, how many ways are there of doing it? If the use of variables is required, can just one variable suffice?

I found a solution that uses the undocumented command 'bloc' but it's fugly and uses two variables that must be initialized first. Sad So I'm eager to see all your clever and non-obvious solutions. ("Just because something is obvious to you, doesn't mean it's obvious to everybody." -- Richard J. Nelson) Have fun!

N.B. Yes, Fibonacci has been discussed MANY times here before, but AFAIK never in terms of the specific goal described above, for the HP Prime.

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
09-01-2018, 07:15 PM
Post: #2
RE: One-Line Exact CAS Fibonacci?
With one variable :

[Image: mini_180901092605372950.jpg]
Find all posts by this user
Quote this message in a reply
09-01-2018, 09:38 PM
Post: #3
RE: One-Line Exact CAS Fibonacci?
And here is a way to generate the successive members of the Fibonacci sequence with each press of the Enter key without using variables :

[Image: mini_18090111490097103.jpg]

The only drawback is that you get also the previous (or next) number.
Find all posts by this user
Quote this message in a reply
09-01-2018, 11:15 PM
Post: #4
RE: One-Line Exact CAS Fibonacci?
(09-01-2018 09:38 PM)Didier Lachieze Wrote:  The only drawback is that you get also the previous (or next) number.

Maybe remove the overlap, so Ans(1) returned even Fibonacci sequence, Ans(2) for odd ?
Find all posts by this user
Quote this message in a reply
09-02-2018, 02:15 AM
Post: #5
RE: One-Line Exact CAS Fibonacci?
[[1,0]]
or is it
[[1],[0]]
I can't tell because of the template - it looks like this
||1||
||0||
then
list2mat({Ans(2,1),Ans(2,1)+Ans(1,1)},1)
[ ENTER ]
[ ENTER ]

VPN
PS: What picture service should I use - all that I tried failed
*I can't remember ... Tumblr?

[Image: 177641266536]

HP Prime Matrix
Find all posts by this user
Quote this message in a reply
09-02-2018, 03:25 AM
Post: #6
RE: One-Line Exact CAS Fibonacci?
(09-01-2018 07:15 PM)Didier Lachieze Wrote:  With one variable :

Based on Didier's single variable solution, this shows [n, F(n)]:

a:=0
[1,1]
[((Ans(1)+1),(a+(a:=Ans(2)))]

   

Ceci n'est pas une signature.
Find all posts by this user
Quote this message in a reply
09-02-2018, 03:27 AM
Post: #7
RE: One-Line Exact CAS Fibonacci?
Wow, these are all cool! I didn't even know that a+(a:=Ans) was a valid statement! Yowza!

My fugly solution that uses two variables:

Setup:
a:=1
b:=1


Command line:
bloc((b:=a),(a:=b+Ans),a)

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
09-02-2018, 08:04 AM
Post: #8
RE: One-Line Exact CAS Fibonacci?
(09-02-2018 03:27 AM)Joe Horn Wrote:  Command line:
bloc((b:=a),(a:=b+Ans),a)

It doesn't work, I get 2, 4, 8, 16, 32...

This works better:
bloc((a:=b+a),(b:=Ans),a)
Find all posts by this user
Quote this message in a reply
09-02-2018, 12:07 PM
Post: #9
RE: One-Line Exact CAS Fibonacci?
(09-02-2018 08:04 AM)Didier Lachieze Wrote:  
(09-02-2018 03:27 AM)Joe Horn Wrote:  Command line:
bloc((b:=a),(a:=b+Ans),a)

It doesn't work, I get 2, 4, 8, 16, 32...

This works better:
bloc((a:=b+a),(b:=Ans),a)

Oh yeah. Oops.
[Image: MoreCoffee.jpg]

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




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