12-11-2016, 04:18 PM
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
output with [PAUSE] on
Without [PAUSE] off
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?
.
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, equstr0, equStr1;
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
str2expr( ansStr );
pause();
ansStr := "expand( answer )"; // (4*a^2*x^2 +4*a*b*x +4*a*c) = 0
str2expr( ansStr );
pause();
ansStr := "answer + b²"; // (4*a^2*x^2 +4*a*b*x + 4*a*c+b^2 ) = (b^2)
str2expr( ansStr );
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)
str2expr( ansStr );
pause();
ansStr := "simplify( answer )"; // (4*a^2*x^2 +4*a*b*x +b^2) = (-4*a*c +b^2)
str2expr( ansStr );
pause();
ansStr := "factor( answer )"; // (2*a*x+b)^2) = (-4*a*c+b^2)
str2expr( ansStr );
pause();
ansStr := "√(answer)"; // (abs(2*a*x+b)) = (√(-4*a*c+b^2))
str2expr( ansStr );
pause();
equ := expr( replace( string( equ ), "abs", "" ) ); // (2*a*x+b) = (√(-4*a*c+b^2))
print( string( equ ) );
pause();
ansStr := "answer - b" ; // (2*a*x+b-b) = (√(-4*a*c+b^2)-b)
str2expr( ansStr );
pause();
ansStr := "simplify( answer )"; // (2*a*x-b) = (√(-4*a*c+b^2)-2*b)
str2expr( ansStr );
pause();
ansStr := "answer/( 2*a )"; // (2*a*x/(2*a)) = (-b+√(-4*a*c+b^2))/(2*a)
str2expr( ansStr );
pause();
ansStr := "simplify( answer )";
str2expr( ansStr );
pause();
ansStr := "replace( answer, \"b+\", \"b±\" )"; // x1 = (-b±√[b^2-4*a*c])/(2*a)
print( ">"+ansStr ); equStr0:= replace( ansStr, "answer", "string(" + equ + ")" );
print( ">"+equStr0 );
equStr1 := expr( equStr0 ); 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;
//
str2expr( ansStr ):=
begin
local equStr0;
print( ">"+ansStr ); output:= append( output, "> "+ansStr);
equStr0:= replace( ansStr, "answer", "(" + equ + ")" ); output:= append( output, "> "+equStr0);
print( ">"+equStr0 );
equ := expr( equStr0 ); output:= append( output, "→ "+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))
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?
.