Fibonacci sequence by recursive algorithm fail
04-21-2015, 02:20 PM (This post was last modified: 04-21-2015 03:31 PM by compsystems.)
Post: #10
 compsystems Senior Member Posts: 1,382 Joined: Dec 2013
RE: Fibonacci sequence by recursive algorithm fail

I found the real problem, works well (CAS PROG) if everything is written in lowercase or all uppercase and, in single shift and does not work (if then else end → If  Then Else End)

HP TEAM must review the compiler (CAS PROG) for next versión of firmware, the following code is successfully compiled, but fails to run, you must verify that the commands are well written

Code:
#CAS     fibo_cas(n):=     begin         // version 0.0.2 April 22             If n≤1 Then                      return(n);             Else                     return(fibo_cas(n-1)+fibo_cas(n-2));             End;     end; #end

fibo_cas(16) → "Error: Bad argument count" ? What affects capitalized If, the algorithm?

-------

I found a serious problem, if two functions prog HOME or prog CAS, has the same name appears only version HOME. The only solution is to support working directories for next versión of firmware (DIR nameDir .... EndDir) do you agree?

PROBLEM WITH TWO FOLLOWING CODES, try it yourself
Code:
#CAS     fibo(n):=     begin         // version 0.0.2 April 22             if n≤1 then                      return(n);             else                     return(fibo(n-1)+fibo(n-2));             end;     end; #end

Code:
export fibo(n) begin   // versión 0.0.2 April 22     if n≤1 then          return n;     else         return fibo(n-1)+fibo(n-2);     end; end;

---------------------

OK codes
Code:
#CAS     fibo_cas(n):=     begin         // version 0.0.2 April 22             if n≤1 then                      return(n);             else                     return(fibo_cas(n-1)+fibo_cas(n-2));             end;     end; #end

fibo_cas(16) → 987.0

Code:
export fibo_home(n) begin   // versión 0.0.2 April 22     if n≤1 then          return n;     else         return fibo_home(n-1)+fibo_home(n-2);     end; end;

Or

Code:
export fibo_home2(n) Begin   // versión 0.0.1 April 22     If n≤1 Then          Return n;     Else         Return fibo_home2(n-1)+fibo_home2(n-2);     End; End;

(04-21-2015 01:57 PM)DrD Wrote:  I think a case could be made that a CAS program is not a good construct for this kind of algorithm. Personally, I think that CAS programs are better suited for CAS exclusive purposes (remaining within the CAS environment).

Just to use one type CAS program if the output is symbolic is obligatory, if only numerical output is optional

For example the following code can not code as HOME program

Code:
#CAS      printSymbolic Algebraic ():=      BEGIN          // versión 0.0.1 April 14 2015 for HP-Prime by compSystems          print; //© Clear Terminal Window (I/O)          print( "hpPrime Terminal View, Symbolic Algebraic Printing" );          print( "" );          print( "Expr1:" ); f(x):=x^3-2*x^2+1*x-1;          print( x^3-2*x^2+1*x-1 );          print( f(x) );                    print( "" );          print( "Expr2:" );          print( x^3-2*x^2+1*x-1 | x=y );          print( f(y) );                    print( "" );          print( "Press any key to continue" ); freeze; wait;          print( "Expr3:" ); g(x):=1/(x+3);          print( g(x) );                    print( "Expr4:" );          print( "f(g(x))=" );          print( f(g(x)) );                    print( "g(f(x))=" );          print( g(f(x)) );                     print( "Expr4:");          print( (x^4-x^3-6*x^2+11*x-6)/x^6+(x^3-6*x^2+11*x-6 | x=y) );          return "Done"      END;  #end

a tip, if the return command have parentheses, returns the output is in exact format, otherwise the approx
Code:
#CAS     fibo_cas(n):=     begin         // version 0.0.2 April 22             if n≤1 then                      return n;             else                     return fibo_cas(n-1)+fibo_cas(n-2);             end;     end; #end
 « Next Oldest | Next Newest »

 Messages In This Thread Fibonacci sequence by recursive algorithm fail - compsystems - 04-20-2015, 06:42 PM RE: Fibonacci sequence by recursive algorithm fail - Tim Wessman - 04-20-2015, 07:57 PM RE: Fibonacci sequence by recursive algorithm fail - Gerald H - 04-21-2015, 05:49 AM RE: Fibonacci sequence by recursive algorithm fail - compsystems - 04-20-2015, 09:26 PM RE: Fibonacci sequence by recursive algorithm fail - Didier Lachieze - 04-20-2015, 09:58 PM RE: Fibonacci sequence by recursive algorithm fail - Bill_G - 04-20-2015, 11:45 PM RE: Fibonacci sequence by recursive algorithm fail - Gerald H - 04-21-2015, 05:13 AM RE: Fibonacci sequence by recursive algorithm fail - brickviking - 10-04-2015, 09:10 PM RE: Fibonacci sequence by recursive algorithm fail - Alberto Candel - 04-21-2015, 12:25 AM RE: Fibonacci sequence by recursive algorithm fail - DrD - 04-21-2015, 01:57 PM RE: Fibonacci sequence by recursive algorithm fail - Joe Horn - 04-22-2015, 02:37 AM RE: Fibonacci sequence by recursive algorithm fail - Marcus von Cube - 04-22-2015, 10:20 AM RE: Fibonacci sequence by recursive algorithm fail - compsystems - 04-21-2015 02:20 PM RE: Fibonacci sequence by recursive algorithm fail - DrD - 04-21-2015, 04:00 PM RE: Fibonacci sequence by recursive algorithm fail - DrD - 04-22-2015, 12:41 PM RE: Fibonacci sequence by recursive algorithm fail - compsystems - 04-23-2015, 02:21 AM RE: Fibonacci sequence by recursive algorithm fail - parisse - 04-23-2015, 06:44 AM RE: Fibonacci sequence by recursive algorithm fail - compsystems - 04-23-2015, 02:09 PM RE: Fibonacci sequence by recursive algorithm fail - parisse - 04-23-2015, 06:58 PM RE: Fibonacci sequence by recursive algorithm fail - compsystems - 04-24-2015, 08:37 PM RE: Fibonacci sequence by recursive algorithm fail - parisse - 04-25-2015, 06:12 AM RE: Fibonacci sequence by recursive algorithm fail - MikeOShea - 10-04-2015, 05:33 AM RE: Fibonacci sequence by recursive algorithm fail - cyrille de brébisson - 10-05-2015, 06:03 AM RE: Fibonacci sequence by recursive algorithm fail - parisse - 10-05-2015, 11:23 AM

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