Post Reply 
INPUT CMD partially operating on CAS code
12-03-2016, 05:30 PM (This post was last modified: 12-04-2016 03:18 PM by compsystems.)
Post: #1
INPUT CMD partially operating on CAS code
The INPUT CMD is a DIALOG BOXES and is partially operating

if the variables are declared as local (coef1_a, coef2_b, coef3_c, coef4_d) do not work.

Commented the LOCAL VARIABLES
PHP Code:
#cas
    
INPUTtest( ) := 
    
begin
        
//local coef1_a, coef2_b, coef3_c, coef4_d; 
        //coef1_a := 9; coef2_b := 8; coef3_c := 7; coef4_d := 6;

        //local reset_coef1_a, reset_coef2_b, reset_coef3_c, reset_coef4_d; 
        //reset_coef1_a := 3; reset_coef2_b := 2; reset_coef3_c := 1; reset_coef4_d := 0;

        
local ObjectType_AllAllowed := -1;
        
local ObjectType_Real := 0;
        
local ObjectType_Integer := 1;
        
local ObjectType_String := 2;  
        
local ObjectType_Complex := 3;  
        
local ObjectType_Matrix := 4;
        
local ObjectType_List := 6;
        
local ObjectType_Function := 8;  
        
local ObjectType_Unit := 9;  
        
local ObjectType_CAS := 14;

        
local ok := 1;
        
local cancel := !ok;
        
local keyPress := 0;

        
local equequ1;
        
purgeab);

        print; 
// Clear Terminal Window
        
print( "Use cursor keys ↑↓ to move the output screen" );
        print( 
"Another key to continue after PAUSE" );
        print( 
"" );
        print( 
"[PAUSE]" ); wait();

        print; 
// Clear Terminal Window again
        
print( "***** Deduction Quadratic Formula *****" ); // Title
        
print( "" );

        print( 
"assume(a>0);" );
        
assumea>);

        
equ:= (a*x^2+b*x+c) = 0
        print( 
stringequ ) );
        print ( 
"[PAUSE]" ); wait( );

        
keyPress := msgboxequtrue );
        
//print( "Key press for MSGBOX CMD: " + ifte( keyPress == ok, keyPress + "=[OK/ENTER]", keyPress +  "=[ESC]" ) ); wait( );// 0 for [CANCEL], 1 for [OK/ENTER]
        
if keyPress == ok then

            
print( "Ans*4*a" );
            
equ := equ 4*a;         // ((a*x^2+b*x+c)*4*a) = 0 
            
print( stringequ ) );
            print( 
"" );
            
            print( 
"expand(Ans)" );
            
equ := expandequ );     // (4*a^2*x^2+4*a*b*x+4*a*c) = 0
            
print( stringequ ) );
            print( 
"" );

            print( 
"Ans+b^2" );    
            
equ := equ b^2;         // (4*a^2*x^2 +4*a*b*x + 4*a*c+b^2 ) = (b^2)
            
print( stringequ ) );
            print( 
"" );

            print( 
"Ans-4*a*c" );    
            
equ := equ 4*a*c;       // (4*a^2*x^2+4*a*b*x+4*a*c+b^2-4*a*c) = (b^2-4*a*c)
            
print( stringequ ) );
            print( 
"" );

            print( 
"simplify(Ans)" );    
            
equ := simplifyequ );   // (4*a^2*x^2+4*a*b*x+b^2) = (-4*a*c+b^2)  
            
print( stringequ ) );
            print( 
"" );

            print( 
"factor(Ans)" );    
            
equ := factorequ );     // (2*a*x+b)^2) = (-4*a*c+b^2)
            
print( stringequ ) );
            print( 
"" );

            print( 
"√(Ans)" ); 
            
assumeb>); assumec>);
            
equ := equ );          // (abs(2*a*x+b)) = (√(-4*a*c+b^2))
            
print( stringequ ) );
            print( 
"" );

            
            
equ := exprreplacestringequ ), "abs""" ) ); // (2*a*x+b) = (√(-4*a*c+b^2))
            
print( stringequ ) );
            print( 
"" );

            print( 
"Ans-b" );    
            
equ := equ b;           // (2*a*x+b-b) = (√(-4*a*c+b^2)-b)
            
print( stringequ ) );
            print( 
"" );

            print( 
"simplify(Ans)" );    
            
equ := simplifyequ );   // (2*a*x-b) = (√(-4*a*c+b^2)-2*b)
            
print( stringequ ) );
            print( 
"" );

            print( 
"Ans/(2*a)" );      
            
equ := equ / ( 2*);       // (2*a*x/(2*a)) = (-b+√(-4*a*c+b^2))/(2*a)
            
print( stringequ )  );
            print( 
""  );

            print( 
"simplify(Ans)"  );    
            
equ := simplifyequ );   // x1 = (-b+√(-4*a*c+b^2))/(2*a)
            
equ := exprreplacestringequ ), "x""x1" ) );
            print( 
stringequ )  );
            print( 
""  );

            print( 
"expr(replace(string(equ),"-b+","-b-"))" );
            
equ1 := exprreplacestringequ ), "-b+""-b-" ) ); // x2 = (-b-√[b^2-4*a*c])/(2*a) 
            
equ1 := exprreplacestringequ1 ), "x1""x2" ) );    
            print( 
stringequ1 )  ); 

            print( 
"[PAUSE]"  ); wait( );

            
//keyPress := 1;
            
keyPress := input( { {coef1_a, [ObjectType_Real]}, {coef2_b, [ObjectType_Real]}, {coef3_c, [ObjectType_Real]}, {coef4_d, [ObjectType_Real] } }, "1a x² + b x + c = 0 ? ax²+bx=d",  {"a:""b:""c:""d:"}, {"Enter coeff a""Enter coeff b""Enter coeff c""Enter coeff d"} , {reset_coef1_a,0,0,0}, {coef1_a,2,3,4} ) ;
            if 
keyPress == ok then
                a 
:= 1;
                
:= 2;
                
:= 3;
                
//a := coef1_a; 
                //b := coef2_b;
                //coef3_c := coef3_c-coef3_d; // => ax²+bx+c=0
                //c := coef3_c;
                
return([ eval(equ), eval(equ1) ]);
            
end;
        
end;

        return 
"done";
    
end;
#end 
INPUTtest(); [enter] open the INPUT DialogBox, but then [enter] returns "Error: Bad argument type" Why?

Now without comment do not execute anything
PHP Code:
#cas
    
INPUTtest():= 
    
begin
      local coef1_a
coef2_bcoef3_ccoef4_d
      
coef1_a:=9coef2_b:=8coef3_c:=7coef4_d:=6;

      
local reset_coef1_areset_coef2_breset_coef3_creset_coef4_d
      
reset_coef1_a:=3reset_coef2_b:=2reset_coef3_c:=1reset_coef4_d:=0;

      
local ObjectType_Real := 0;

      
input( { {coef1_a, [ObjectType_Real]}, {coef2_b, [ObjectType_Real]}, {coef3_c, [ObjectType_Real]}, {coef4_d, [ObjectType_Real] } }, "1a x² + b x + c = 0 ∨ ax²+bx=d",  {"a:""b:""c:""d:"}, {"Enter coeff a""Enter coeff b""Enter coeff c""Enter coeff d"} , {reset_coef1_a,0,0,0}, {coef1_a,2,3,4} ) ;
     
//...
      
return "done";
    
end;
#end 
INPUTtest(); [enter] INPUTtest() ?
Find all posts by this user
Quote this message in a reply
12-04-2016, 04:13 AM
Post: #2
RE: INPUT CMD on CAS code
You are creating a CAS program. INPUT() is not a CAS command.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
12-04-2016, 02:09 PM (This post was last modified: 12-04-2016 03:32 PM by compsystems.)
Post: #3
RE:
(12-04-2016 04:13 AM)Han Wrote:  You are creating a CAS program. INPUT() is not a CAS command.

sorry for my bad English

CHOOSE, MSGBOX cmds are also DIALOG BOXES and works perfectly on CAS MODE, please run the following program.

I think it is a problem with the LOCALS VARIABLES.

Some hp-prime developer that confirms what happens

Thanks


With the current firmware I still can not execute the following code correctly =(

1: Screen does not autoscroll
2: INPUT does not work
3: ASSUME does not work
4: There is not pretty print
5: print; // Clear Terminal Window, does not operate when called for the second time
6: CHOOSE and MSGBOX must be above the terminal window (pop-up) and not go to the CAS/HOME MODE view
7: When copying then paste this source code into the program editor (hp-conn Kit), Tabulation is lost in certain parts.
8: When changing the font size distorts the strings, there must be a flag to set the font size

Any hope of seeing any of the previous points implemented?

Program: Deduction Quadratic Formula Step by Step
PHP Code:
#cas
    
deductionQuadFormula_SbyS( ) := 
    
begin
        
//local coef1_a, coef2_b, coef3_c, coef4_d; 
        //coef1_a := 9; coef2_b := 8; coef3_c := 7; coef4_d := 6;

        //local reset_coef1_a, reset_coef2_b, reset_coef3_c, reset_coef4_d; 
        //reset_coef1_a := 3; reset_coef2_b := 2; reset_coef3_c := 1; reset_coef4_d := 0;

        
local ObjectType_AllAllowed := -1;
        
local ObjectType_Real := 0;
        
local ObjectType_Integer := 1;
        
local ObjectType_String := 2;  
        
local ObjectType_Complex := 3;  
        
local ObjectType_Matrix := 4;
        
local ObjectType_List := 6;
        
local ObjectType_Function := 8;  
        
local ObjectType_Unit := 9;  
        
local ObjectType_CAS := 14;

        
local ok := 1;
        
local cancel := !ok;
        
local keyPress := 0;

        
local equequ1;
        
purgeab);

        print; 
// Clear Terminal Window
        
print( "Use cursor keys ↑↓ to move the output screen" );
        print( 
"Another key to continue after PAUSE" );
        print( 
"" );
        print( 
"[PAUSE]" ); wait();

        print; 
// Clear Terminal Window again
        
print( "***** Deduction Quadratic Formula *****" ); // Title
        
print( "" );

        print( 
"assume(a>0);" );
        
assumea>);

        
equ:= (a*x^2+b*x+c) = 0
        print( 
stringequ ) );
        print ( 
"[PAUSE]" ); wait( );

        
keyPress := msgboxequtrue );
        
//print( "Key press for MSGBOX CMD: " + ifte( keyPress == ok, keyPress + "=[OK/ENTER]", keyPress +  "=[ESC]" ) ); wait( );// 0 for [CANCEL], 1 for [OK/ENTER]
        
if keyPress == ok then

            
print( "Ans*4*a" );
            
equ := equ 4*a;         // ((a*x^2+b*x+c)*4*a) = 0 
            
print( stringequ ) );
            print( 
"" );
            
            print( 
"expand(Ans)" );
            
equ := expandequ );     // (4*a^2*x^2+4*a*b*x+4*a*c) = 0
            
print( stringequ ) );
            print( 
"" );

            print( 
"Ans+b^2" );    
            
equ := equ b^2;         // (4*a^2*x^2 +4*a*b*x + 4*a*c+b^2 ) = (b^2)
            
print( stringequ ) );
            print( 
"" );

            print( 
"Ans-4*a*c" );    
            
equ := equ 4*a*c;       // (4*a^2*x^2+4*a*b*x+4*a*c+b^2-4*a*c) = (b^2-4*a*c)
            
print( stringequ ) );
            print( 
"" );

            print( 
"simplify(Ans)" );    
            
equ := simplifyequ );   // (4*a^2*x^2+4*a*b*x+b^2) = (-4*a*c+b^2)  
            
print( stringequ ) );
            print( 
"" );

            print( 
"factor(Ans)" );    
            
equ := factorequ );     // (2*a*x+b)^2) = (-4*a*c+b^2)
            
print( stringequ ) );
            print( 
"" );

            print( 
"√(Ans)" ); 
            
assumeb>); assumec>);
            
equ := equ );          // (abs(2*a*x+b)) = (√(-4*a*c+b^2)) // Should not show ABS
            
print( stringequ ) );
            print( 
"" );

            
// patch
            
equ := exprreplacestringequ ), "abs""" ) ); // (2*a*x+b) = (√(-4*a*c+b^2))
            
print( stringequ ) );
            print( 
"" );

            print( 
"Ans-b" );    
            
equ := equ b;           // (2*a*x+b-b) = (√(-4*a*c+b^2)-b)
            
print( stringequ ) );
            print( 
"" );

            print( 
"simplify(Ans)" );    
            
equ := simplifyequ );   // (2*a*x-b) = (√(-4*a*c+b^2)-2*b)
            
print( stringequ ) );
            print( 
"" );

            print( 
"Ans/(2*a)" );      
            
equ := equ / ( 2*);       // (2*a*x/(2*a)) = (-b+√(-4*a*c+b^2))/(2*a)
            
print( stringequ )  );
            print( 
""  );

            print( 
"simplify(Ans)"  );    
            
equ := simplifyequ );   // x1 = (-b+√(-4*a*c+b^2))/(2*a)
            
equ := exprreplacestringequ ), "x""x1" ) );
            print( 
stringequ )  );
            print( 
""  );

            print( 
"expr(replace(string(equ),"-b+","-b-"))" );
            
equ1 := exprreplacestringequ ), "-b+""-b-" ) ); // x2 = (-b-√[b^2-4*a*c])/(2*a) 
            
equ1 := exprreplacestringequ1 ), "x1""x2" ) );    
            print( 
stringequ1 )  ); 

            print( 
"[PAUSE]"  ); wait( );

            
//keyPress := 1;
            
keyPress := input( { {coef1_a, [ObjectType_Real]}, {coef2_b, [ObjectType_Real]}, {coef3_c, [ObjectType_Real]}, {coef4_d, [ObjectType_Real] } }, "1a x² + b x + c = 0 ? ax²+bx=d",  {"a:""b:""c:""d:"}, {"Enter coeff a""Enter coeff b""Enter coeff c""Enter coeff d"} , {reset_coef1_a,0,0,0}, {coef1_a,2,3,4} ) ;
            if 
keyPress == ok then
                a 
:= 1;
                
:= 2;
                
:= 3;
                
//a := coef1_a; 
                //b := coef2_b;
                //coef3_c := coef3_c-coef3_d; // => ax²+bx+c=0
                //c := coef3_c;
                
return([ eval(equ), eval(equ1) ]);
            
end;
        
end;

        return 
"done";
    
end;
#end 
Find all posts by this user
Quote this message in a reply
12-04-2016, 03:12 PM
Post: #4
RE: INPUT CMD on CAS code
Hi Compsystems!

Han mentioned that INPUT() is not a CAS command, and doesn't work inside your CAS program. Han did not specify anything about the CHOOSE() command. Han has offered you good advice.

Whether or not commands work in both environments is not well documented. In general, lowercase commands work in CAS, and probably work in HOME. Uppercase commands work in HOME and may not work in CAS. As the prime evolves, these distinctions are being improved. Case matters, for both commands and variables. If you see issues, errors, etc., you might be more productive if you look at the active environment, and the case of the command name, or variables being used.

-Dale-
Find all posts by this user
Quote this message in a reply
12-04-2016, 03:31 PM
Post: #5
RE: INPUT CMD partially operating on CAS code
Actually INPUT does work on CAS (partially), after entering the data this fails.
Please try the code above yourself.

Finally, please the HP-Prime team should be to solve the 8 previous points.

I want to create programs that show in a window (terminal window) the output data, request data by dialog boxes and return to show data again. This capability is available on ti68k calcs, or similar to the library I'm writing for the hp50,
see http://www.hpmuseum.org/forum/thread-7048.html
another aption is to create my own TERMINAL VIEW, but I make missing commands (HP50) like convert from string to graphic object (2 -> GROB), etc.
Find all posts by this user
Quote this message in a reply
12-04-2016, 04:55 PM
Post: #6
RE: INPUT CMD partially operating on CAS code
(12-04-2016 03:31 PM)compsystems Wrote:  Actually INPUT does work on CAS (partially), after entering the data this fails.
Please try the code above yourself.

This CAS test example demonstrates that the input() command doesn't work in CAS, while the same INPUT() structure does work in the following HOME example:
(Please try the code below for yourself.)
Code:

#cas

CAStest():= 
begin

  local a,b,c,resetVAL,initVAL;

  input ({ {a, [0], {21,21,0}}, 
           {b, [0], {21,21,1}},
           {c, [0], {21,21,2}} }, 
           "title", 
           {"label_a", "label_b","label_c"}, 
           {"help_a", "help_b", "help_c"},           
           {resetVAL,resetVAL,resetVAL}, 
           {initVAL, initVAL, initVAL} );

end;

#end


Code:

EXPORT HOMEtest()
BEGIN

  LOCAL a,b,c,resetVAL,initVAL;

  INPUT ({ {a, [0], {21,21,0}}, 
           {b, [0], {21,21,1}},
           {c, [0], {21,21,2}} }, 
           "title", 
           {"label_a", "label_b","label_c"}, 
           {"help_a", "help_b", "help_c"},           
           {resetVAL,resetVAL,resetVAL}, 
           {initVAL, initVAL, initVAL} );

END;

"Partially" working simply means it doesn't work.
Find all posts by this user
Quote this message in a reply
Post Reply 




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