2021: Examples of CAS-type programs
Hello
In this post I am going to put a series of examples of CAS-type programs
SCRIPT 01: obtaining the solutions of the quadratic equation
You can run the following sentences line by line in the CAS history, please let me know if the results on your calculator are different.
Change manually Simplify mode to None [shift] + [CAS (settings)]
autosimplify cmd of Xcas is not yet available in firmware 2021
autosimplify (0); // Xcas only = (
SCRIPT 01
PHP Code:
autosimplify(0); // Xcas only =( purge(a,b,c,x,equ0,equ1,equ2); equ0:= (a*x^2+b*x+c) = 0; // [enter] (a*x^2+b*x+c) = 0 equ := equ0 * 4*a; // [enter] (4*(a*x^2+b*x+c)*a) = 0 equ := expand( equ ); // [enter] (4*a^2*x^2+4*a*b*x+4*a*c) = 0 equ := equ + b^2; // [enter] (4*a^2*x^2+4*a*b*x+4*a*c+b^2) = (b^2) equ := equ - 4*a*c; // [enter] (4*a^2*x^2+4*a*b*x+4*a*c+b^2-4*a*c) = (b^2-4*a*c) equ := simplify( equ ); // [enter] (4*a^2*x^2+4*a*b*x+b^2) = (-4*a*c+b^2) equ := factor( equ ); // [enter] ((2*a*x+b)^2) = (-4*a*c+b^2) equ := √( equ ); // [enter] (ABS(2*a*x+b)) = (sqrt(-4*a*c+b^2)) equ := expr( replace( string( equ ), "abs", "" ) ); // [enter] (2*a*x+b) = (sqrt(-4*a*c+b^2)) equ := equ - b; // [enter] (2*a*x+b-b) = (sqrt(-4*a*c+b^2)-b) equ := simplify( equ ); // [enter] (2*a*x) = (-b+sqrt(-4*a*c+b^2)) equ := equ / ( 2*a ); // [enter] (2*a*x/(2*a)) = (-b+sqrt(-4*a*c+b^2))/(2*a) equ := simplify( equ ); // [enter] x = (-b+sqrt(-4*a*c+b^2))/(2*a) equ1 := expr( replace( string( equ ), "x", "x1" ) ); // [enter] x1 = (-b+sqrt(-4*a*c+b^2))/(2*a) equ2 := expr( replace( string( equ1 ), "x1", "x2" )); // [enter] x2 = (-b+sqrt(-4*a*c+b^2))/(2*a) equ2 := expr( replace( string( equ2 ), "-b+", "-b-" ) ); // [enter] x2 = (-b-sqrt(-4*a*c+b^2))/(2*a)
Please inform me if I am wrong.
What other calculator with CAS and original firmware can do the above? I think no one, only the HP-Prime with Xcas, simply because they (TI; Texas Instruments, CASIO, Sharp, Numworks ...) can't control the simplification type of output.
the same script above but with comments
PHP Code:
autosimplify(0); purge(a,b,c,x,equ0,equ1,equ2); equ0:= (a*x^2+b*x+c) = 0; equ := equ0 * 4*a; equ := expand( equ ); equ := equ + b^2; equ := equ - 4*a*c; equ := simplify( equ ); equ := factor( equ ); equ := √( equ ); equ := expr( replace( string( equ ), "abs", "" ) ); equ := equ - b; equ := simplify( equ ); equ := equ / ( 2*a ); equ := simplify( equ ); equ1 := expr( replace( string( equ ), "x", "x1" ) ); equ2 := expr( replace( string( equ1 ), "x1", "x2" )); equ2 := expr( replace( string( equ2 ), "-b+", "-b-" ) );
the same script above but using SUBST to make changes to the expression without converting to text strings
PHP Code:
autosimplify(0); purge(a,b,c,x,equ0,equ1,equ2); equ0:= (a*x^2+b*x+c) = 0; equ := equ0 * 4*a; equ := expand( equ ); equ := equ + b^2; equ := equ - 4*a*c; equ := simplify( equ ); equ := factor( equ ); equ := √( equ ); equ := subst(equ,'abs', nop); equ := equ - b; equ := simplify( equ ); equ := equ / ( 2*a ); equ := simplify( equ ); equ1 := subst(equ,x, x1); // or, equ1 := subst(equ,x=x1); equ2 := subst(equ1,x1, x2); // or, equ2 := subst(equ1,x1=x2); equ2 := subst(equ1,"-b+", "-b+");
as a program and 2D printing
PHP Code:
#cas //Deduction Quadratic Formula quadraticform():= begin autosimplify(0); purge(a,b,c,x,equ0,equ1,equ2); equ0:= (a*x^2+b*x+c) = 0; print(equ0); equ := equ0 * 4*a; print(equ); equ := expand( equ ); print(equ); equ := equ + b^2; print(equ); equ := equ - 4*a*c; print(equ); equ := simplify( equ ); print(equ); equ := factor( equ ); print(equ); equ := √( equ ); print(equ); equ := subst(equ,'abs', nop); print(equ); equ := equ - b; print(equ); equ := simplify( equ ); print(equ); equ := equ / ( 2*a ); print(equ); equ := simplify( equ ); equ1 := subst(equ,x=x1); print(equ1); equ2 := subst(equ1,x1=x2); equ2 := subst(equ2,"-b+", "-b+"); print(equ2); return [equ0, equ1, equ2]; end;
quadraticform() [enter]
Printing with the #183 character "·" would look more compact and legible, this will allow to display the "*" symbol as a "·", this could be changed by configuration, depending on how you want to display the multiplication operator. This feature was available on the hp48gx
using optional template for cas prg
PHP Code:
#cas function name(args) ... return ... end; #end
Code:
#cas
//Deduction Quadratic Formula
function quadraticform()
autosimplify(0);
purge(a,b,c,x,equ0,equ1,equ2);
equ0:= (a*x^2+b*x+c) = 0; print(equ0);
equ := equ0 * 4*a; print(equ);
equ := expand( equ ); print(equ);
equ := equ + b^2; print(equ);
equ := equ - 4*a*c; print(equ);
equ := simplify( equ ); print(equ);
equ := factor( equ ); print(equ);
equ := √( equ ); print(equ);
equ := subst(equ,'abs', nop); print(equ);
equ := equ - b; print(equ);
equ := simplify( equ ); print(equ);
equ := equ / ( 2*a ); print(equ);
equ := simplify( equ );
equ1 := subst(equ,x=x1); print(equ1);
equ2 := subst(equ1,x1=x2);
equ2 := subst(equ2,"-b+", "-b+"); print(equ2);
return [equ0, equ1, equ2];
end;
Script using only the ANS variable
PHP Code:
(a*x^2+b*x+c) = 0; Ans*4*a; expand(Ans); Ans+b^2; Ans-4*a*c; simplify(Ans); factor(Ans); √(Ans); subst(Ans,'abs', nop); Ans-b; simplify(Ans); Ans/(2*a); simplify(Ans); expr(replace(string(Ans),"-b+","-b-"));
as prgm
PHP Code:
#cas //Deduction Quadratic Formula function quadraticform_1() (a*x^2+b*x+c) = 0; Ans*4*a; expand(Ans); Ans+b^2; Ans-4*a*c; simplify(Ans); factor(Ans); √(Ans); subst(Ans,'abs', nop); Ans-b; simplify(Ans); Ans/(2*a); simplify(Ans); expr(replace(string(Ans),"-b+","-b-")); return Ans; end;
in writing.
|