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) 284812298108489611757988937681460995615380088782304890986477195645969271404032323901 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; |
|||
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: 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) |
|||
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. |
|||
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).
|
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 7 Guest(s)