Post Reply 
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
RE: Fibonacci sequence by recursive algorithm fail
Sorry for my bad English

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
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Fibonacci sequence by recursive algorithm fail - compsystems - 04-21-2015 02:20 PM



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