
%mathpiper
CASCompare(expressions) :=
[
    Local(count,e,me, answer);

    count := 1;
    
    ForEach(e,expressions)
    [
        If(IsList(e), [answer := e[2]; e := e[1];]);
        
        Echo("#",count ,"Exercise:   ",e, If(IsBound(answer),ToString()[WriteString("  Answer: " );Write(answer);Clear(answer);],"") );
        
        
        //Echo("MathPiper:    ",Simplify(Eval(FromString(e:";") Read())));
        Echo("MathPiper:    ",Eval(FromString(e:";") Read()));
        
        //me := ToString()[WriteString("ratsimp(");Write(Atom(e));WriteString(")");];
        me := ToString()[WriteString("(");Write(Atom(e));WriteString(")");];
        Echo("Maxima:",Maxima(me));
        
        count := count + 1;
    
    ];

];
%/mathpiper

    %output,preserve="false"
      Result: True
.   %/output



%mathpiper,title="page 55 exercises 1a.
Echo("pp.55 exercises. 1a  ");
NewLine();

expressions :={
{"x^2*x^3","x^5"},
{"x^(1/2)*x^(1/3)","x^(5/6)"},
{"x^a*x^b","x^(a+b)"},
{"(x^2)^3","x^6"},
{"(x^a)^2","x^(2*a)"},
{"(x^2)^(1/2)","|x|"},
{"(x^(1/2))^2","x"},
{"(x^2)^a","x^(2*a)"},
{"(x*y)^2","x^2*y^2"},
{"(x*y)^(1/3)","x^(1/3)*y^(1/3)"},
{"(x*y)^a","x^a*y^a"},

};

CASCompare(expressions);

%/mathpiper

    %output,preserve="false"
      Result: True
      
      Side Effects:
      pp.55 exercises. 1a  
      
      #1 Exercise:   x^2*x^3  Answer: "x^5"
      MathPiper:    x^5 
      Maxima:(%o700) x^5
       
      #2 Exercise:   x^(1/2)*x^(1/3)  Answer: "x^(5/6)"
      MathPiper:    Sqrt(x)*x^(1/3) 
      Maxima:(%o701) x^(5/6)
       
      #3 Exercise:   x^a*x^b  Answer: "x^(a+b)"
      MathPiper:    x^(b+a) 
      Maxima:(%o702) x^(b+a)
       
      #4 Exercise:   (x^2)^3  Answer: "x^6"
      MathPiper:    x^6 
      Maxima:(%o703) x^6
       
      #5 Exercise:   (x^a)^2  Answer: "x^(2*a)"
      MathPiper:    x^a^2 
      Maxima:(%o704) x^(2*a)
       
      #6 Exercise:   (x^2)^(1/2)  Answer: "|x|"
      MathPiper:    Sqrt(x^2) 
      Maxima:(%o705) abs(x)
       
      #7 Exercise:   (x^(1/2))^2  Answer: "x"
      MathPiper:    x 
      Maxima:(%o706) x
       
      #8 Exercise:   (x^2)^a  Answer: "x^(2*a)"
      MathPiper:    x^2^a 
      Maxima:(%o707) abs(x)^(2*a)
       
      #9 Exercise:   (x*y)^2  Answer: "x^2*y^2"
      MathPiper:    (x*y)^2 
      Maxima:(%o708) x^2*y^2
       
      #10 Exercise:   (x*y)^(1/3)  Answer: "x^(1/3)*y^(1/3)"
      MathPiper:    (x*y)^(1/3) 
      Maxima:(%o709) x^(1/3)*y^(1/3)
       
      #11 Exercise:   (x*y)^a  Answer: "x^a*y^a"
      MathPiper:    (x*y)^a 
      Maxima:(%o710) (x*y)^a
.   %/output





%mathpiper,title="page 55 exercises 2a.
Echo("pp.55 exercises. 1a  ");
NewLine();

expressions :={
{"2*x+3*x","5*x"},
{"(1+x)+2*(1+x)","3*(1+x)"},
{"2*x+Sqrt(2)*x","(2+Sqrt(2))*x"},
{"a*x + b*x","(a+b)*x"},
{"(a+b)*x","a*x+b*x)"},
{"2*(x+y)","2*x+2*y"},
{"-(x+y)","-x-y"},
{"a*(x+y)","a*x+a*y"},
};

//CASCompare(expressions);

%/mathpiper

    %output,preserve="false"
      Result: {{"2*x+3*x","5*x"},{"(1+x)+2*(1+x)","3*(1+x)"},{"2*x+Sqrt(2)*x","(2+Sqrt(2))*x"},{"a*x + b*x","(a+b)*x"},{"(a+b)*x","a*x+b*x)"},{"2*(x+y)","2*x+2*y"},{"-(x+y)","-x-y"},{"a*(x+y)","a*x+a*y"}}
      
      Side Effects:
      pp.55 exercises. 1a
.   %/output


