Post Reply 
2021: Examples of CAS-type programs
05-01-2021, 12:22 AM (This post was last modified: 05-09-2021 11:25 PM by compsystems.)
Post: #1
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 = (

[Image: autosimplify_flag_image00.jpg]

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 := expandequ );    // [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 := simplifyequ );  // [enter]  (4*a^2*x^2+4*a*b*x+b^2) = (-4*a*c+b^2)
    
equ := factorequ );    // [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 := exprreplacestringequ ), "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 := simplifyequ );  // [enter]   (2*a*x) = (-b+sqrt(-4*a*c+b^2))
    
equ := equ / ( 2*);    // [enter]   (2*a*x/(2*a)) = (-b+sqrt(-4*a*c+b^2))/(2*a)
    
equ := simplifyequ );  // [enter]   x = (-b+sqrt(-4*a*c+b^2))/(2*a)
    
equ1 := exprreplacestringequ ), "x""x1" ) );    // [enter]   x1 = (-b+sqrt(-4*a*c+b^2))/(2*a)
    
equ2 := exprreplacestringequ1 ), "x1""x2" ));    // [enter]  x2 = (-b+sqrt(-4*a*c+b^2))/(2*a)
    
equ2 := exprreplacestringequ2 ), "-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 := expandequ );
    
equ := equ b^2;
    
equ := equ 4*a*c;
    
equ := simplifyequ );
    
equ := factorequ );
    
equ := equ );
    
equ := exprreplacestringequ ), "abs""" ) );
    
equ := equ b;
    
equ := simplifyequ );
    
equ := equ / ( 2*);
    
equ := simplifyequ );
    
equ1 := exprreplacestringequ ), "x""x1" ) );
    
equ2 := exprreplacestringequ1 ), "x1""x2" ));
    
equ2 := exprreplacestringequ2 ), "-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 := expandequ );
    
equ := equ b^2;
    
equ := equ 4*a*c;
    
equ := simplifyequ );
    
equ := factorequ );
    
equ := equ );
    
equ := subst(equ,'abs'nop);
    
equ := equ b
    
equ := simplifyequ );
    
equ := equ / ( 2*);
    
equ := simplifyequ ); 
    
equ1 := subst(equ,xx1); // or, equ1 := subst(equ,x=x1);
    
equ2 := subst(equ1,x1x2); // 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 := expandequ );             print(equ);
    
equ := equ b^2;                 print(equ);
    
equ := equ 4*a*c;               print(equ);
    
equ := simplifyequ );           print(equ);
    
equ := factorequ );             print(equ);
    
equ := equ );                  print(equ);
    
equ := subst(equ,'abs'nop);     print(equ);
    
equ := equ b;                   print(equ); 
    
equ := simplifyequ );           print(equ);
    
equ := equ / ( 2*);             print(equ);
    
equ := simplifyequ );            
    
equ1 := subst(equ,x=x1);          print(equ1);
    
equ2 := subst(equ1,x1=x2);        
    
equ2 := subst(equ2,"-b+""-b+"); print(equ2);
    return [
equ0equ1equ2];
end
quadraticform() [enter]

[Image: quadraticform_scriptcas_image00.png]

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-")); 

[Image: quadraticform_scriptcas_image01.png]

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


Messages In This Thread
2021: Examples of CAS-type programs - compsystems - 05-01-2021 12:22 AM



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