Post Reply 
TERMINAL VIEW does not sync with PRINT cmd
12-11-2016, 04:18 PM (This post was last modified: 12-13-2016 08:02 PM by compsystems.)
Post: #1
TERMINAL VIEW does not sync with PRINT cmd
Hello hp-prime developer group and HP-prime users

The following code is a program that shows step by step, the deduction of the quadratic, Bhaskara formula
SOURCE:
https://es.wikipedia.org/wiki/Deducci%C3...e_Bhaskara

PHP Code:
//The following code is a program that shows step by step, the deduction of the quadratic formula
export lineByLineFlag := 0
#cas
    
deductionQuadFormula_3():=
    
begin
        local ansStr
equstr0equStr1;
                
purge(a,b,c,x);

        print; 
// Clear Terminal Window 
        
print( "***** Deduction Quadratic Formula *****" ); // Title
        
print( "version 3 with intermediate steps & subroutines" ); 
        
wait();
        
choose_cas(); 
        
        
assume(a>0);
        print( 
"Quadratic Equation" );
        
equ := ((a*x^2+b*x+c) = 0); output:={ equ };
        print( 
">"+equ );
        print( 
"assume(a>0)" );   

        
pause();

        
ansStr := "answer * 4*a"// ((a*x^2+b*x+c)*4*a) = 0 
        
str2expransStr );
      
        
pause();
      
        
ansStr := "expand( answer )"// (4*a^2*x^2 +4*a*b*x +4*a*c) = 0
        
str2expransStr );
      
        
pause();

        
ansStr := "answer + b²"// (4*a^2*x^2 +4*a*b*x + 4*a*c+b^2 ) = (b^2)
        
str2expransStr );
      
        
pause();
      
        
ansStr := "answer - 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)
        
str2expransStr );
      
        
pause();
      
        
ansStr := "simplify( answer )"// (4*a^2*x^2 +4*a*b*x +b^2) = (-4*a*c +b^2)  
        
str2expransStr );     
      
        
pause();
      
        
ansStr := "factor( answer )"// (2*a*x+b)^2) = (-4*a*c+b^2)
        
str2expransStr );
        
pause();
        
        
ansStr := "√(answer)"// (abs(2*a*x+b)) = (√(-4*a*c+b^2))
        
str2expransStr );
        
pause();        
    
        
equ := exprreplacestringequ ), "abs""" ) ); // (2*a*x+b) = (√(-4*a*c+b^2))
        
print( stringequ ) );
         
        
pause();
      
        
ansStr :=  "answer - b" ;  // (2*a*x+b-b) = (√(-4*a*c+b^2)-b)  
        
str2expransStr );     
         
        
pause();

        
ansStr := "simplify( answer )"// (2*a*x-b) = (√(-4*a*c+b^2)-2*b)     
        
str2expransStr );     
         
        
pause();

        
ansStr := "answer/( 2*a )";    // (2*a*x/(2*a)) = (-b+√(-4*a*c+b^2))/(2*a)         
        
str2expransStr );     
         
        
pause(); 

        
ansStr := "simplify( answer )"
        
str2expransStr );     

        
pause(); 
        
        
ansStr :=  "replace( answer, \"b+\", \"b±\" )"// x1 = (-b±√[b^2-4*a*c])/(2*a) 
        
print( ">"+ansStr ); equStr0:= replaceansStr"answer",  "string(" equ ")" ); 
        print( 
">"+equStr0 ); 
        
equStr1 := exprequStr0 ); print( "" ); print( ""equStr1 ); 

        
pause(); 

        
// ansStr := "expr( replace( string( answer ), \"x\", \"x1\" ))"; // x1 = (-b+√(-4*a*c+b^2))/(2*a) 
        // str2expr( ansStr );      
        // pause(); 

        // ansStr :=  "expr( replace( string( answer ), \"b+\", \"b-\" ))"; // x1 = (-b-√[b^2-4*a*c])/(2*a) 
        // str2expr( ansStr );
        // pause(); 

        // ansStr := "expr( replace( string( answer ), \"x1\", \"x2\" ))"; // x2 = (-b-√(-4*a*c+b^2))/(2*a) 
        // str2expr( ansStr );      
        // pause(); 
        
purge(a);
        return 
"done";
    
end;
    
    
//
    
str2expransStr ):=
    
begin
      local equStr0
;
      print( 
">"+ansStr ); output:= appendoutput"> "+ansStr); 
      
equStr0:= replaceansStr"answer",  "(" equ ")" ); output:= appendoutput"> "+equStr0);
      print( 
">"+equStr0 ); 
      
equ := exprequStr0 ); output:= appendoutput"→ "+equ); 
      print( 
"" ); 
      print( 
""equ );     
    
end;
#end 


// Not CAS prg
export pause()
begin
  
if lineByLineFlag == 1 then         
    
//print( "____________________________[PAUSE]"  ); wait( );
    
print( "                                                                [PAUSE]"  ); wait( );
    else 
      print( 
"" );
  
end;    
end;

// Not CAS prg
export choose_cas()
begin
  local ok 
:= 1;
  
local cancel := 0;
  
local keyPressedOnMenu := 0;
  
local currentPos := 2;
  
keyPressedOnMenu := choose(currentPos,"Pause every step", { "No""Yes" });
  if 
keyPressedOnMenu >= ok then
    
if currentPos == 2 then
      
print( "Any key to continue after [PAUSE]" );
      print( 
"" ); 
      
lineByLineFlag := 1;
    else 
      print( 
"Use cursor keys ↑↓ to move the output screen" );
      print( 
"" ); 
      
lineByLineFlag:= 0;
    
end;

    else
        
kill;
  
end;    
end

output with [PAUSE] on
Quote:(a*x^2+b*x+c) = 0
> answer * 4*a
> ((a*x^2+b*x+c) = 0) * 4*a
→ ((a*x^2+b*x+c)*4*a) = 0
[PAUSE]
> expand( answer )
> expand( (((a*x^2+b*x+c)*4*a) = 0) )
→ (4*a^2*x^2+4*a*b*x+4*a*c) = 0
[PAUSE]
> answer + b ²
> ((4*a^2*x^2+4*a*b*x+4*a*c) = 0) + b ²
→ (4*a^2*x^2+4*a*b*x+4*a*c+b^2) = (b^2)
[PAUSE]
> answer - 4*a*c
> ((4*a^2*x^2+4*a*b*x+4*a*c+b^2) = (b^2)) - 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)
[PAUSE]
> simplify( answer )
> simplify( ((4*a^2*x^2+4*a*b*x+4*a*c+b^2-4*a*c) = (b^2-4*a*c)) )
→ (4*a^2*x^2+4*a*b*x+b^2) = (-4*a*c+b^2)
[PAUSE]
> factor( answer )
> factor( ((4*a^2*x^2+4*a*b*x+b^2) = (-4*a*c+b^2)) )
→ ((2*a*x+b)^2) = (-4*a*c+b^2)
[PAUSE]
> √ (answer)
> √ ((((2*a*x+b)^2) = (-4*a*c+b^2)))
→ (abs(2*a*x+b)) = (√(-4*a*c+b^2))
[PAUSE]
> answer - b
> ((2*a*x+b) = (√(-4*a*c+b^2))) - b
→ (2*a*x+b-b) = (√(-4*a*c+b^2)-b)
[PAUSE]
> simplify( answer )
> simplify( ((2*a*x+b-b) = (√(-4*a*c+b^2)-b)) )
→ (2*a*x) = (-b+√(-4*a*c+b^2))
[PAUSE]
> answer/( 2*a )
> ((2*a*x) = (-b+√(-4*a*c+b^2)))/( 2*a )
→ (2*a*x/(2*a)) = ((-b+√(-4*a*c+b^2))/(2*a))
[PAUSE]
> simplify( answer )
> simplify( ((2*a*x/(2*a)) = ((-b+√(-4*a*c+b^2))/(2*a))) )
→ x = ((-b+√(-4*a*c+b^2))/(2*a))

Without [PAUSE] off
Quote:(a*x^2+b*x+c) = 0
> answer * 4*a
> ((a*x^2+b*x+c) = 0) * 4*a
→ ((a*x^2+b*x+c)*4*a) = 0

> expand( answer )
> expand( (((a*x^2+b*x+c)*4*a) = 0) )
→ (4*a^2*x^2+4*a*b*x+4*a*c) = 0

> answer + b ²
> ((4*a^2*x^2+4*a*b*x+4*a*c) = 0) + b ²
→ (4*a^2*x^2+4*a*b*x+4*a*c+b^2) = (b^2)


> answer - 4*a*c
> ((4*a^2*x^2+4*a*b*x+4*a*c+b^2) = (b^2)) - 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)

> simplify( answer )
> simplify( ((4*a^2*x^2+4*a*b*x+4*a*c+b^2-4*a*c) = (b^2-4*a*c)) )
→ (4*a^2*x^2+4*a*b*x+b^2) = (-4*a*c+b^2)

> factor( answer )
> factor( ((4*a^2*x^2+4*a*b*x+b^2) = (-4*a*c+b^2)) )
→ ((2*a*x+b)^2) = (-4*a*c+b^2)

> √ (answer)
> √ ((((2*a*x+b)^2) = (-4*a*c+b^2)))
→ (abs(2*a*x+b)) = (√(-4*a*c+b^2))

> answer - b
> ((2*a*x+b) = (√(-4*a*c+b^2))) - b
→ (2*a*x+b-b) = (√(-4*a*c+b^2)-b)

> simplify( answer )
> simplify( ((2*a*x+b-b) = (√(-4*a*c+b^2)-b)) )
→ (2*a*x) = (-b+√(-4*a*c+b^2))

> answer/( 2*a )
> ((2*a*x) = (-b+√(-4*a*c+b^2)))/( 2*a )
→ (2*a*x/(2*a)) = ((-b+√(-4*a*c+b^2))/(2*a))

> simplify( answer )
> simplify( ((2*a*x/(2*a)) = ((-b+√(-4*a*c+b^2))/(2*a))) )
→ x = ((-b+√(-4*a*c+b^2))/(2*a))

[Image: deductionQuadraticFormula_hp_prime_image02.png]

At the beginning it generates a dialogue box that says:

Show execution step by step ie pause each input / output, the current terminal view does not scroll vertically, so that not only the first screen is displayed, wait for the program to end to see the result.

In alls languages I have programmed all the terminals advance vertically when printed on the last line.

I think that HP should improve the terminal view
Do you agree with my reasoning?
.
Find all posts by this user
Quote this message in a reply
Post Reply 




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