Post Reply 
Fibonacci sequence by recursive algorithm fail
10-04-2015, 05:33 AM
Post: #21
RE: Fibonacci sequence by recursive algorithm fail
Tail recursive version. Runs quick.
Example Run:
fibo(400)
28481229810848961175798893768146099561538008878230489098647719564596927140403232​3901

fibotail(I,J,N):=
BEGIN
if N>0 then
return fibotail(J,I+J,N-1);
else
return J;
end;
END;

fibo(N):=
BEGIN
return fibotail(0,1,N);
END;
Find all posts by this user
Quote this message in a reply
10-04-2015, 09:10 PM
Post: #22
RE: Fibonacci sequence by recursive algorithm fail
(04-21-2015 05:13 AM)Gerald H Wrote:  
(04-20-2015 11:45 PM)Bill_G Wrote:  TIM and compsystems:

The program runs fine using RETURN (i.e., in capitals).

Bill_G

Font type differentiation of names is a trap that catches all practitioners.

I must have got lucky, I typed all keywords in capitals because of previous experience with picky parsers that weren't case-insensitive. So far I haven't been bitten yet, but no doubt I'll have it happen some day.

(Post 38)

Regards, BrickViking
HP-50g |Casio fx-9750G+ |Casio fx-9750GII (SH4a)
Visit this user's website Find all posts by this user
Quote this message in a reply
10-05-2015, 06:03 AM
Post: #23
RE: Fibonacci sequence by recursive algorithm fail
Hello,

The cas evaluator is recursive.
ie, each recursive function call that you make in a CAS program does result in a stack layer in the native program stack. And they add up quickly. And there is no way to control them (ie, know that you are running out of RAM). Your native program (which executes your CAS program) will crash, fast if the native program stack is small. This is why the CAS limits recursive user calls.

The Home evaluator, on the other hand is NON recursive. It handles evaluated programs in a while loop and handles user program recursivity using a manually managed stack. This results in a much more complex chunk of code, and might even be slower, BUT, it takes less RAM AND it allows the controled evaluation of deep recursive programs. Even low memory detection and proper error reporting.

Bernard's XCAS, I believe does have a non recursive evaluator, BUT I am not sure if it is implemented on Prime and even less sure of how to call it.

Cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
10-05-2015, 11:23 AM
Post: #24
RE: Fibonacci sequence by recursive algorithm fail
The non recursive eval activates itself automatically on system where PTHREAD_T is enabled, when the stack is about to be exhausted. Otherwise you need specific code, there is currently no specific code for the Prime but it could probably be added (like for RTOS_THREADX in gen.cc in gen::in_eval).
Find all posts by this user
Quote this message in a reply
Post Reply 




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