# [Maxima] Extensions for the Complex components

Dieter Kaiser drdieterkaiser at web.de
Sun Aug 31 13:16:36 CDT 2008

If you are interested: Here is the testfile for the Complex components.

Dieter Kaiser

/******************************************************************************
Test the functions for Complex Components
******************************************************************************/

declare(z,complex);
done;

kill(all);
done\$

/******************************************************************************
Part 1: Test the function rect (This is a test of the function risplit.)
******************************************************************************/

map(rectform,[0,1.0,5/2,1.0b0,%i,1+%i,1.0+1.0*%i,1/2+5/2*%i,1.0b0+2.5b0*%i]);
[0,1.0,5/2,1.0b0,%i,1+%i,1.0+1.0*%i,1/2+5/2*%i,1.0b0+2.5b0*%i];

(declare(z,complex, z1,complex, z2,complex, j,imaginary),0);
0;

/* Addition, Multiplikation, Exponentiation with complex symbols */

rectform(z);
realpart(z)+%i*imagpart(z);

rectform(z1+z2);
realpart(z1)+realpart(z2)+%i*(imagpart(z1)+imagpart(z2));

rectform(z1*z2);
realpart(z1)*realpart(z2)-imagpart(z1)*imagpart(z2)+%i*(imagpart(z1)*realpart(z2
)+realpart(z1)*imagpart(z2));

/* This is the most general case */

rectform(z1^z2);
abs(z1)^realpart(z2)*%e^(-imagpart(z2)*atan2(imagpart(z1),realpart(z1)))*cos(ima
gpart(z2)*log(abs(z1))+realpart(z2)*atan2(imagpart(z1),realpart(z1))) +
%i*abs(z1)^realpart(z2)*%e^(-imagpart(z2)*atan2(imagpart(z1),realpart(z1)))*sin(
imagpart(z2)*log(abs(z1))+realpart(z2)*atan2(imagpart(z1),realpart(z1)));

/* Mixed real and complex symbols */

rectform(x+z);
realpart(z)+%i*imagpart(z)+x;

rectform(x*z);
x*realpart(z)+%i*x*imagpart(z);

rectform(x^z);
%i*abs(x)^realpart(z)*%e^-(atan2(0,x)*imagpart(z))*sin(atan2(0,x)*realpart(z)+lo
g(abs(x))*imagpart(z))+abs(x)^realpart(z)*%e^-(atan2(0,x)*imagpart(z))*cos(atan2
(0,x)*realpart(z)+log(abs(x))*imagpart(z));

rectform(z^x);
abs(z)^x*cos(atan2(imagpart(z),realpart(z))*x) + %i *
abs(z)^x*sin(atan2(imagpart(z),realpart(z))*x);

/* The last results should simplify further if we know the sign of x */

(assume(x1>0,x2<0),done);
done;

rectform(x1^z);
abs(x1)^realpart(z)*cos(imagpart(z)*log(abs(x1))) + %i*
abs(x1)^realpart(z)*sin(imagpart(z)*log(abs(x1)));

rectform(z^x1);
abs(z)^x1*cos(atan2(imagpart(z),realpart(z))*x1) + %i *
abs(z)^x1*sin(atan2(imagpart(z),realpart(z))*x1);

rectform(x2^z);
abs(x2)^realpart(z)*%e^(-%pi*imagpart(z))*cos(imagpart(z)*log(abs(x2))+realpart(
z)*%pi) + %i*
abs(x2)^realpart(z)*%e^(-imagpart(z)*%pi)*sin(imagpart(z)*log(abs(x2))+realpart(
z)*%pi);

rectform(z^x2);
abs(z)^x2*cos(atan2(imagpart(z),realpart(z))*x2) + %i *
abs(z)^x2*sin(atan2(imagpart(z),realpart(z))*x2);

/* Exponentiation with numbers */

rectform(z^(-1));
realpart(z)/(realpart(z)^2+imagpart(z)^2) - %i *
imagpart(z)/(realpart(z)^2+imagpart(z)^2);

rectform((x+%i*y)^(-1));
x/(x^2+y^2) - %i * y/(x^2+y^2);

rectform((%i*y)^(-1));
- %i /y;

rectform(z^2000);
%i*(realpart(z)^2+imagpart(z)^2)^1000*sin(2000*atan2(imagpart(z),realpart(z))) +
(realpart(z)^2+imagpart(z)^2)^1000*cos(2000*atan2(imagpart(z),realpart(z)));

rectform((x+%i*y)^2000);
%i*(x^2+y^2)^1000*sin(2000*atan2(y,x)) + (x^2+y^2)^1000*cos(2000*atan2(y,x));

rectform((%i*y)^2000);
y^2000;

rectform(j^2000);
%i*imagpart(j)^2000*sin(2000*atan2(imagpart(j),0)) +
imagpart(j)^2000*cos(2000*atan2(imagpart(j),0));

/* rectform and functions */

/* real valued functions */

rectform(realpart(z));
realpart(z);

rectform(imagpart(z));
imagpart(z);

rectform(abs(z));
abs(z);

/* But we have a problem with rectform(cabs(z))
because cabs(z) simlifies to sqrt(realpart(z)^2+imagpart(z)^2)
we got an asksign. We have changed the code in risplit-expt
Now it works
We delete in addition the call to rectform in \$cabs.
We get now a more simple result */

rectform(cabs(z));
abs(z);

/* The weired in Trigonomtric functions */

rectform(sin(x));
sin(x);

rectform(sin(z));
cosh(imagpart(z)) * sin(realpart(z)) + %i * sinh(imagpart(z))*cos(realpart(z));

rectform(sin(%i*x));
%i*sinh(x);

rectform(sin(z1+z2));
cosh(imagpart(z1)+imagpart(z2)) * sin(realpart(z1)+realpart(z2)) + %i *
sinh(imagpart(z1)+imagpart(z2))*cos(realpart(z1)+realpart(z2));

rectform(sin(z1*z2));
cosh(imagpart(z1)*realpart(z2)+realpart(z1)*imagpart(z2)) *
sin(realpart(z1)*realpart(z2)-imagpart(z1)*imagpart(z2)) + %i *
sinh(imagpart(z1)*realpart(z2)+realpart(z1)*imagpart(z2))*cos(realpart(z1)*realp
art(z2)-imagpart(z1)*imagpart(z2));

rectform(sin(z1^z2));
%i*cos(abs(z1)^realpart(z2)*%e^-(atan2(imagpart(z1),realpart(z1))*imagpart(z2))*
cos(atan2(imagpart(z1),realpart(z1))*realpart(z2)+log(abs(z1))*imagpart(z2)))*si
nh(abs(z1)^realpart(z2)*%e^-(atan2(imagpart(z1),realpart(z1))*imagpart(z2))*sin(
atan2(imagpart(z1),realpart(z1))*realpart(z2)+log(abs(z1))*imagpart(z2)))+sin(ab
s(z1)^realpart(z2)*%e^-(atan2(imagpart(z1),realpart(z1))*imagpart(z2))*cos(atan2
(imagpart(z1),realpart(z1))*realpart(z2)+log(abs(z1))*imagpart(z2)))*cosh(abs(z1
)^realpart(z2)*%e^-(atan2(imagpart(z1),realpart(z1))*imagpart(z2))*sin(atan2(ima
gpart(z1),realpart(z1))*realpart(z2)+log(abs(z1))*imagpart(z2)));

/******************************************************************************
Part 2: Test the function cabs and abs (This is a test of absarg)
We do every test for the function abs too and look for
the differences.
******************************************************************************/

kill(all);
done;

declare(z,complex);
done;

/*--- numbers ----*/

map(cabs,[-5,0,42,-7/8,+4/5,-2.4,0.0,+3.5,-12.7b0,0.0b0,+4.3b0]);
[5,0,42,7/8,4/5,2.4,0.0,3.5,12.7b0,0.0b0,4.3b0];

map(abs,[-5,0,42,-7/8,+4/5,-2.4,0.0,+3.5,-12.7b0,0.0b0,+4.3b0]);
[5,0,42,7/8,4/5,2.4,0.0,3.5,12.7b0,0.0b0,4.3b0];

/* constants */

map(cabs,[inf,minf,infinity,%e,%pi,%gamma,%phi]);
[inf,inf,inf,%e,%pi,%gamma,%phi];

/* Problem: cabs(und) and cabs(ind) doesn't work!
We have to add code in absarg

map(cabs,[und,ind]);
[und,ind];
*/

map(abs,[inf,minf,infinity,und,ind,%e,%pi,%gamma,%phi]);
[inf,inf,inf,und,ind,%e,%pi,%gamma,%phi];

/* symbols */

(declare(z,complex),
assume(x1>0, x2>=0, y1<0, y2<=0, a1>2, a2>=2, b1<-2, b2<=-2),
done);
done;

map(cabs,[z,x1,x2,y1,y2,a1,a2,b1,b2]);
[abs(z),x1,x2,-y1,-y2,a1,a2,-b1,-b2];

map(abs,[z,x1,x2,y1,y2,a1,a2,b1,b2]);
[abs(z),x1,x2,-y1,-y2,a1,a2,-b1,-b2];

map(cabs,[a1-1,a1-2,a1-3,b1+1,b1+2,b1+3]);
[a1-1,a1-2,abs(a1-3),-b1-1,-b1-2,abs(b1+3)];

map(abs,[a1-1,a1-2,a1-3,b1+1,b1+2,b1+3]);
[a1-1,a1-2,abs(a1-3),-b1-1,-b1-2,abs(b1+3)];

/* this work only with the extension sign-shift */

map(cabs,[a1+a2-1,a1+a2-2,a1+a2-4,a1+a2-5]);
[a1+a2-1,a1+a2-2,a1+a2-4,abs(a1+a2-5)];

map(abs,[a1+a2-1,a1+a2-2,a1+a2-4,a1+a2-5]);
[a1+a2-1,a1+a2-2,a1+a2-4,abs(a1+a2-5)];

map(cabs,[b1+b2+1,b1+b2+2,b1+b2+4,b1+b2+5]);
[-b1-b2-1,-b1-b2-2,-b1-b2-4,abs(b1+b2+5)];

map(abs,[b1+b2+1,b1+b2+2,b1+b2+4,b1+b2+5]);
[-b1-b2-1,-b1-b2-2,-b1-b2-4,abs(b1+b2+5)];

/* complex numbers */

map(cabs,[%i,-%i,1+%i,1-%i,(1+%i)/(1-%i),(1+%i)*(1-%i)]);
[1,1,sqrt(2),sqrt(2),1,2];

map(abs,[%i,-%i,1+%i,1-%i,(1+%i)/(1-%i),(1+%i)*(1-%i)]);
[1,1,sqrt(2),sqrt(2),1,2];

/* Complex numbers multiplied with a complex value */

map(cabs,[z,-z,%i*z,-%i*z,(1+%i)*z,(1-%i)*z,z*(1+%i)/(1-%i),z*(1+%i)*(1-%i)]);
[abs(z),abs(z),abs(z),abs(z),

sqrt((realpart(z)+imagpart(z))^2+(realpart(z)-imagpart(z))^2),sqrt((realpart(z)+
imagpart(z))^2+(imagpart(z)-realpart(z))^2),sqrt(realpart(z)^2+imagpart(z)^2),2*
abs(z)];

map(abs,[z,-z,%i*z,-%i*z,(1+%i)*z,(1-%i)*z,z*(1+%i)/(1-%i),z*(1+%i)*(1-%i)]);
[abs(z),abs(z),abs(z),abs(z),

sqrt((realpart(z)+imagpart(z))^2+(realpart(z)-imagpart(z))^2),sqrt((realpart(z)+
imagpart(z))^2+(imagpart(z)-realpart(z))^2),sqrt(realpart(z)^2+imagpart(z)^2),2*
abs(z)];

/*
[abs(z),abs(z),abs(z),abs(z),sqrt(2)*abs(z),sqrt(2)*abs(z),abs(z),2*abs(z)];
*/

/* The same as above but z multiplied into the sum */
map(abs,[z,-z,%i*z,-%i*z,(z+%i*z),(z-%i*z),(z+%i*z)/(1-%i),(z+%i*z)*(1-%i)]);
[abs(z),abs(z),abs(z),abs(z),

sqrt((realpart(z)+imagpart(z))^2+(realpart(z)-imagpart(z))^2),sqrt((realpart(z)+
imagpart(z))^2+(imagpart(z)-realpart(z))^2),sqrt(realpart(z)^2+imagpart(z)^2),2*
abs(z)];

/*
[abs(z),abs(z),abs(z),abs(z),sqrt(2)*abs(z),sqrt(2)*abs(z),abs(z),2*abs(z)];
*/

/* Complex values multiplied with a real value */

map(cabs,[x,-x,%i*x,-%i*x,(1+%i)*x,(1-%i)*x,x*(1+%i)/(1-%i),x*(1+%i)*(1-%i)]);
[abs(x),abs(x),abs(x),abs(x),sqrt(2)*abs(x),sqrt(2)*abs(x),abs(x),2*abs(x)];

map(abs,[x,-x,%i*x,-%i*x,(1+%i)*x,(1-%i)*x,x*(1+%i)/(1-%i),x*(1+%i)*(1-%i)]);
[abs(x),abs(x),abs(x),abs(x),sqrt(2)*abs(x),sqrt(2)*abs(x),abs(x),2*abs(x)];

/* Complex numbers multiplied with a positive real value > 2 */

map(cabs,[x1,-x1,%i*x1,-%i*x1,(1+%i)*x1,(1-%i)*x1,x1*(1+%i)/(1-%i),x1*(1+%i)*(1-
%i)]);
[x1,x1,x1,x1,sqrt(2)*x1,sqrt(2)*x1,x1,2*x1];

map(abs,[x1,-x1,%i*x1,-%i*x1,(1+%i)*x1,(1-%i)*x1,x1*(1+%i)/(1-%i),x1*(1+%i)*(1-%
i)]);
[x1,x1,x1,x1,sqrt(2)*x1,sqrt(2)*x1,x1,2*x1];

/* Complex numbers muliplied with a sum of two real value a1+a2-2 > 0 */

map(cabs,[a1+a2-2,-a1-a2+2,%i*(a1+a2-2),-%i*(a1+a2-2),(1+%i)*(a1+a2-2),(1-%i)*(a
1+a2-2),(a1+a2-2)*(1+%i)/(1-%i),(a1+a2-2)*(1+%i)*(1-%i)]);
[a2+a1-2,a2+a1-2,a2+a1-2,a2+a1-2,sqrt(2)*(a2+a1-2),
sqrt((a2+a1-2)^2+(-a2-a1+2)^2),a2+a1-2,2*a2+2*a1-4];

map(abs,[a1+a2-2,-a1-a2+2,%i*(a1+a2-2),-%i*(a1+a2-2),(1+%i)*(a1+a2-2),(1-%i)*(a1
+a2-2),(a1+a2-2)*(1+%i)/(1-%i),(a1+a2-2)*(1+%i)*(1-%i)]);
[a2+a1-2,a2+a1-2,a2+a1-2,a2+a1-2,sqrt(2)*(a2+a1-2),sqrt((a2+a1-2)^2+(-a2-a1+2)^2
),a2+a1-2,2*a2+2*a1-4];

/* Complex numbers muliplied with a negative real value */

map(cabs,[y1,-y1,%i*y1,-%i*y1,(1+%i)*y1,(1-%i)*y1,y1*(1+%i)/(1-%i),y1*(1+%i)*(1-
%i)]);
[-y1,-y1,-y1,-y1,sqrt(2)*-y1,sqrt(2)*-y1,-y1,2*-y1];

map(abs,[y1,-y1,%i*y1,-%i*y1,(1+%i)*y1,(1-%i)*y1,y1*(1+%i)/(1-%i),y1*(1+%i)*(1-%
i)]);
[-y1,-y1,-y1,-y1,sqrt(2)*-y1,sqrt(2)*-y1,-y1,2*-y1];

/* Complex numbers muliplied with a sum of two negative real value b1+b1+2<0
The function abs gives sometimes more simple results. */

map(cabs,[b1+b2+2,-(b1+b2+2),%i*(b1+b2+2),-%i*(b1+b2+2),(1+%i)*(b1+b2+2),(1-%i)*
(b1+b2+2),(b1+b2+2)*(1+%i)/(1-%i),(b1+b2+2)*(1+%i)*(1-%i)]);
[-(b1+b2+2),-(b1+b2+2),-(b1+b2+2),-(b1+b2+2),sqrt(2)*-(b1+b2+2),sqrt((b2+b1+2)^2
+(-b2-b1-2)^2),-(b1+b2+2),(-2*b1-2*b2-4)];

map(abs,[b1+b2+2,-(b1+b2+2),%i*(b1+b2+2),-%i*(b1+b2+2),(1+%i)*(b1+b2+2),(1-%i)*(
b1+b2+2),(b1+b2+2)*(1+%i)/(1-%i),(b1+b2+2)*(1+%i)*(1-%i)]);
[-b2-b1-2,-b2-b1-2,-b2-b1-2,-b2-b1-2,sqrt(2)*(-b2-b1-2),
sqrt((b2+b1+2)^2+(-b2-b1-2)^2),-b2-b1-2,-2*b2-2*b1-4];

/* Complex numbers and exponentiation */

declare(z,complex);
done;

(declare(z1,complex,z2,complex,j,imaginary),done);
done;

cabs(z^(1+%i));
abs(z)* %e^(-atan2(imagpart(z),realpart(z)));

cabs(j^(1+%i));
abs(j)*%e^(-atan2(imagpart(j),0));

cabs(z1^z2);
abs(z1)^realpart(z2)*%e^(-atan2(imagpart(z1),realpart(z1))*imagpart(z2));

cabs(z^x);
abs(z)^x;

cabs(x^z);
abs(x)^'realpart(z)*%e^-(atan2(0,x)*imagpart(z));

cabs(j^z);
abs(j)^realpart(z)*%e^(-atan2(imagpart(j),0)*imagpart(z));

cabs(z^j);
%e^(-atan2(imagpart(z),realpart(z))*imagpart(j));

cabs((x+%i*y)^(a+%i*b));
sqrt(x^2+y^2)^a*%e^(-atan2(y,x)*b);

kill(all);
done;

/*--reflection simplification ----*/

declare(z,complex);
done;

cabs(x) - cabs(-x);
0\$

abs(x) - abs(-x);
0\$

cabs(x*y) - cabs(-x*y);
0\$

abs(x*y) - abs(-x*y);
0\$

cabs(sin(x)) - cabs(sin(-x));
0\$

abs(sin(x)) - abs(sin(-x));
0\$

expand(cabs(14 * a*(b - c)) - cabs(-14 * a * (c - b)));
0\$

expand(abs(14 * a*(b - c)) - abs(-14 * a * (c - b)));
0\$

ratsubst(c,b,cabs(x*(a+b)) - cabs(x*(a+c)));
0\$

ratsubst(c,b,abs(x*(a+b)) - abs(x*(a+c)));
0\$

declare(z,complex);
done;

/*--database facts -----*/

(assume(equal(zip,0)),0);
0\$

cabs(zip * x);
0\$

abs(zip * x);
0\$

is(equal(cabs(1 + zip),1));
true\$

is(equal(abs(1 + zip),1));
true\$

(forget(equal(zip,0)),0);
0\$

declare(z,complex);
done;

/*--absolute value of products and quotients ---*/

cabs((1+%i) * x);
sqrt(2) * abs(x)\$

cabs((1+%i) * %pi);
sqrt(2) * %pi\$

cabs((1+%i) / x);
sqrt(2) / abs(x)\$

declare(z,complex);
done;

/*-- absolute value of lists and other mbags---*/

cabs([a,b]), listarith : true;
[abs(a),abs(b)]\$

abs([a,b]), listarith : true;
[abs(a),abs(b)]\$

cabs([%i,-6]), listarith : true;
[1,6]\$

abs([%i,-6]), listarith : true;
[1,6]\$

cabs(x = 1), listarith : true;
abs(x) = 1\$

abs(x = 1), listarith : true;
abs(x) = 1\$

cabs(-x = 1), listarith : true;
abs(x) = 1\$

abs(-x = 1), listarith : true;
abs(x) = 1\$

/*---- declared complex stuff ---*/

(declare(z, complex),0);
0\$

cabs(conjugate(z));
/* Should we return sqrt(realpart(conjugate(z))^2+imagpart(conjugate(z))^2) */
abs(z);

abs(conjugate(z));
abs(z)\$

cabs(exp(z));
exp(realpart(z))\$

abs(exp(z));
exp(realpart(z))\$

subst(z = %i, cabs(z^2));
1\$

subst(z = %i, abs(z^2));
1\$

(remove(z,complex),0);
0\$

/*--- abs and tellsimp. This does not work for cabs. ---- */

(tellsimp(abs(a), a+1), abs_rules : tellsimp(abs(b), b+1), 0);
0\$

abs(a);
a+1\$

abs(a * x);
(a+1) * abs(x)\$

abs([a]), listarith : true;
[a+1]\$

abs(a*b);
(a+1)*(b+1)\$

abs(a^7);
(a+1)^7\$

abs((a*b)^5);
(a+1)^5 * (b + 1)^5\$

(remrule(abs, first(abs_rules)), remrule(abs, second(abs_rules)),0);
0\$

(remvalue(abs_rules),0);
0\$

/*--- cabs flatten  ---*/

cabs(cabs(x));
abs(x)\$

cabs(cabs(-x));
abs(x)\$

cabs(cabs(cabs(x)));
abs(x)\$

cabs(cabs(cabs(x))+1);
abs(abs(x) + 1)\$

/*--- simplify noun form ---*/

'cabs(1);
'cabs(1)\$

'abs(1);
1;

'cabs(1+x^2);
'cabs(1 + x^2)\$

'abs(1+x^2);
1 + x^2\$

'cabs(cabs(x));
'cabs(abs(x))\$

'abs(abs(x));
abs(x)\$

/*-- subst into cabs ---*/

ratsubst(x,x^2,cabs(1+x^3));
1+x^2\$

ratsubst(0,a,cabs(%pi + a));
%pi\$

/*-- CRE tests ---*/

cabs(rat(x) + 1);
abs(x+1)\$

cabs(rat(1));
1\$

/*-- misc -----*/

cabs(signum(1/x));
1\$

abs(signum(1/x));
1\$

/* The two following example don't work for cabs */
is(equal(op(abs(a.b)), abs));
true\$

is(equal(op(abs(a^^7)), abs));
true\$

cabs(taylor(exp(x),x,0,3)) - taylor(exp(x),x,0,3);
''(taylor(0,x,0,3));

abs(taylor(exp(x),x,0,3)) - taylor(exp(x),x,0,3);
''(taylor(0,x,0,3));

/******************************************************************************
Part 3: Test the more general Complex characteristics of the
Complex Components
******************************************************************************/

kill(all);
done;

declare(z,complex);
done;

(assume(x1>0,x2<0),done);
done;

/* for z = x+%i*y, x,y are real */

abs(x+%i*y);
sqrt(x^2+y^2);

carg(x+%i*y);
atan2(y,x);

realpart(x+%i*y);
x;

imagpart(x+%i*y);
y;

conjugate(x+%i*y);
x-%i*y;

signum(x+%i*y);
(x+%i*y)/sqrt(x^2+y^2);

/* Results for z=0,1, -1, %i, -%i */

map(abs, [0,1,-1,%i,-%i]);
[0,1,1,1,1];

map(carg, [0,1,-1,%i,-%i]);
[atan2(0,0),0,%pi,%pi/2,-%pi/2];

map(realpart, [0,1,-1,%i,-%i]);
[0,1,-1,0,0];

map(imagpart, [0,1,-1,%i,-%i]);
[0,0,0,1,-1];

map(conjugate, [0,1,-1,%i,-%i]);
[0,1,-1,-%i,%i];

map(signum, [0,1,-1,%i,-%i]);
[0,1,-1,%i,-%i];

/* Results for z= 1+%i, -1+%i, -1-%i, 1-%i */

map(abs, [1+%i, -1+%i, -1-%i, 1-%i]);
[sqrt(2),sqrt(2),sqrt(2),sqrt(2)];

map(carg, [1+%i, -1+%i, -1-%i, 1-%i]);
[%pi/4,3*%pi/4,-3*%pi/4,-%pi/4];

map(realpart, [1+%i, -1+%i, -1-%i, 1-%i]);
[1,-1,-1,1];

map(imagpart, [1+%i, -1+%i, -1-%i, 1-%i]);
[1,1,-1,-1];

map(conjugate, [1+%i, -1+%i, -1-%i, 1-%i]);
[1-%i, -1-%i, -1+%i, 1+%i];

map(signum, [1+%i, -1+%i, -1-%i, 1-%i]);
[(1+%i)/sqrt(2), (-1+%i)/sqrt(2), (-1-%i)/sqrt(2), (1-%i)/sqrt(2)];

/* Results for z= %pi, %e, %gamma, %phi */

map(abs, [%pi, %e, %gamma, %phi]);
[%pi, %e, %gamma, %phi];

map(carg, [%pi, %e, %gamma, %phi]);
[0,0,0,0];

map(realpart, [%pi, %e, %gamma, %phi]);
[%pi, %e, %gamma, %phi];

map(imagpart, [%pi, %e, %gamma, %phi]);
[0,0,0,0];

map(conjugate, [%pi, %e, %gamma, %phi]);
[%pi, %e, %gamma, %phi];

map(signum, [%pi, %e, %gamma, %phi]);
[1,1,1,1];

/* Results for x and y real and x1 > 0, x2 < 0 */

map(abs, [x, x1, x2, %i*y]);
[sqrt(x^2),x1,-x2,sqrt(y^2)]; /* Maxima simplifies sqrt(x^2) -> abs(x) */

map(carg, [x, x1, x2, %i*y]);
[atan2(0,x),0,%pi,atan2(0,y)+%pi/2]; /* atan2(y,0)=atan2(0,y)+%pi/2 */

map(realpart, [x, x1, x2, %i*y]);
[x, x1, x2, 0];

map(imagpart, [x, x1, x2, %i*y]);
[0,0,0,y];

map(conjugate, [x, x1, x2, %i*y]);
[x,x1,x2,-%i*y];

map(signum, [x, x1, x2, %i*y]);
[signum(x),1,-1,%i*y/abs(y)];

/* Tests the infinities */

map(abs, [inf,minf,infinity,ind,und]);
[inf, inf, inf,ind,und];

map(carg, [inf,minf,infinity]);
[0,%pi,ind]; /* for infinity not atan2(infinity,infinity) !!!!! */

/* Problem: carg don't work for und and ind
It is possible code to give correct results but then the routine
mabs-subt in limit.lisp no longer works. We get an endless loop.
This can be corrected but we don't do it now.

map(carg, [und,ind]);
[und,ind];
*/

map(realpart, [inf,minf,infinity,und,ind]);
[inf, minf, und, und, ind];

map(imagpart, [inf,minf,infinity]);
[0,0,und];

/* Problem: The results for und and ind for the function imagpart are wrong.
See above.

map(imagpart, [und, ind]);
[und,ind];
*/

map(conjugate, [inf,minf,infinity,und,ind]);
/* conjugate does not simplify infinity, und and ind */
[inf, minf, conjugate(infinity), conjugate(und), conjugate(ind)];

map(signum, [inf,minf,infinity,und,ind]);
[1,-1,und,und,ind];

/* Parity and symmetrie */

abs(conjugate(z));
abs(z);

/* we have a difficult to understand bug.
sometimes we no longer get the correct complex sign.
But if we call csign once we get in the second call the correct answer */
(csign(conjugate),done);
done;

carg(conjugate(z));
atan2(imagpart(conjugate(z)),realpart(conjugate(z)));

realpart(conjugate(z));
realpart(conjugate(z));

imagpart(conjugate(z));
imagpart(conjugate(z));

conjugate(conjugate(z));
z;

signum(conjugate(z));
/*conjugate(signum(z));*/
conjugate(z)/sqrt(realpart(conjugate(z))^2+imagpart(conjugate(z))^2);

abs(-z);
abs(z);

carg(-z);
atan2(imagpart(z),realpart(z))+%pi;

realpart(-z);
-realpart(z);

imagpart(-z);
-imagpart(z);

conjugate(-z);
-conjugate(z);

signum(-z);
-signum(z);

/* Test for Homogeneity */

declare(w,complex);
done;
(assume(a>0),done);
done;

abs(w*z);
abs(w)*abs(z);

carg(a*z);
atan2(imagpart(z),realpart(z));

realpart(x*z);
x*realpart(z);

imagpart(x*z);
x*imagpart(z);

conjugate(w*z);
conjugate(w)*conjugate(z);

signum(w*z);
signum(w)*signum(z);

/* Scale symmetrie */

abs(z^x);
abs(z)^x;

signum(z^x);
signum(z)^x;

/* Transformations with z = -z, %i*z, -%i*z, x*z, a*z and x real and a>0 */

map(abs,[-z,%i*z,-%i*z,x*z,a*z]);
[abs(z), abs(z), abs(z), abs(x)*abs(z), a*abs(z)];

/* Should we accept the results of carg ???
one problem is, that we imediatly simplify to atan2 */
map(carg,[-z,%i*z,-%i*z,x*z,a*z]);
[atan2(imagpart(z),realpart(z))+%pi,atan2(imagpart(z),realpart(z))+%pi/2,atan2(i
magpart(z),realpart(z))-%pi/2,
atan2(imagpart(z),realpart(z))+atan2(0,x),atan2(imagpart(z),realpart(z))];

map(realpart,[-z,%i*z,-%i*z,x*z,a*z]);
[-realpart(z), -imagpart(z), imagpart(z), x*realpart(z), a*realpart(z)];

map(imagpart,[-z,%i*z,-%i*z,x*z,a*z]);
[-imagpart(z), realpart(z), -realpart(z), x*imagpart(z), a*imagpart(z)];

map(conjugate,[-z,%i*z,-%i*z,x*z,a*z]);
[-conjugate(z), -%i*conjugate(z), %i*conjugate(z), x*conjugate(z),
a*conjugate(z)];

/* signum(x)*signum(z) simplifies differently from signum(x*z)
The reason is that for complex expression we allways simplify like
z/abs(z), but signum(x) is pure real and don't simplify to x/abs(x) */
map(signum,[-z,%i*z,-%i*z,x*z,a*z]);
[-signum(z), %i*signum(z), -%i*signum(z), x/abs(x)*signum(z),signum(z)];

/* Transformations with z = 1/z, z^w, %e^z, %e^(%i*z) */

map(abs, [1/z, z^w, %e^z, %e^(%i*z)]);
[1/abs(z),abs(z)^realpart(w)*%e^-(imagpart(w)*atan2(imagpart(z),realpart(z))),%e
^realpart(z),%e^-imagpart(z)] ;

map(carg, [1/z, z^w, %e^z, %e^(%i*z)]);
[-atan2(imagpart(z),realpart(z)),imagpart(w)*log(abs(z))+realpart(w)*atan2(imagp
art(z),realpart(z)),imagpart(z),realpart(z)];

map(realpart, [1/z, z^w, %e^z, %e^(%i*z)]);
[realpart(z)/(realpart(z)^2+imagpart(z)^2),abs(z)^realpart(w)*%e^-(imagpart(w)*a
tan2(imagpart(z),realpart(z)))*cos(imagpart(w)*log(abs(z))+realpart(w)*atan2(ima
gpart(z),realpart(z))),%e^realpart(z)*cos(imagpart(z)),%e^-imagpart(z)*cos(realp
art(z))];

map(imagpart, [1/z, z^w, %e^z, %e^(%i*z)]);
[-imagpart(z)/(realpart(z)^2+imagpart(z)^2),abs(z)^realpart(w)*%e^-(imagpart(w)*
atan2(imagpart(z),realpart(z)))*sin(imagpart(w)*log(abs(z))+realpart(w)*atan2(im
agpart(z),realpart(z))),%e^realpart(z)*sin(imagpart(z)),%e^-imagpart(z)*sin(real
part(z))];

map(conjugate, [1/z, z^w, %e^z, %e^(%i*z)]);
[1/conjugate(z),conjugate(z^w),%e^conjugate(z),%e^-(%i*conjugate(z))];

/* The results are correct, but not as simple as possible, e.g.
z-realpart(z) = %i*imagpart(z) */
map(signum, [1/z, z^w, %e^z, %e^(%i*z)]);
[abs(z)/z,z^w*%e^(imagpart(w)*atan2(imagpart(z),realpart(z)))/abs(z)^realpart(w)
, %e^(z-realpart(z)),%e^(imagpart(z)+%i*z)];

/* Transformations with z = z1+z2, z1*z2, z1/z2 */

declare(z1,complex, z2,complex);
done;

map(abs, [z1+z2, z1*z2, z1/z2]);
[sqrt((realpart(z2)+realpart(z1))^2+(imagpart(z2)+imagpart(z1))^2),abs(z1)*abs(z
2),abs(z1)/abs(z2)];

map(carg, [z1+z2, z1*z2, z1/z2]);
[atan2(imagpart(z2)+'imagpart(z1),realpart(z2)+realpart(z1)),atan2(imagpart(z2),
realpart(z2))+atan2(imagpart(z1),realpart(z1)),atan2(imagpart(z1),realpart(z1))-
atan2(imagpart(z2),realpart(z2))];

map(realpart, [z1+z2, z1*z2, z1/z2]);
[realpart(z2)+realpart(z1),realpart(z1)*realpart(z2)-imagpart(z1)*imagpart(z2),(
realpart(z1)*realpart(z2)+imagpart(z1)*imagpart(z2))/(realpart(z2)^2+imagpart(z2
)^2)];

map(imagpart, [z1+z2, z1*z2, z1/z2]);
[imagpart(z2)+imagpart(z1),imagpart(z1)*realpart(z2)+realpart(z1)*imagpart(z2),(
imagpart(z1)*realpart(z2)-realpart(z1)*imagpart(z2))/(realpart(z2)^2+imagpart(z2
)^2)];

map(conjugate, [z1+z2, z1*z2, z1/z2]);
[conjugate(z2)+conjugate(z1),conjugate(z1)*conjugate(z2),conjugate(z1)/conjugate
(z2)];

map(signum, [z1+z2, z1*z2, z1/z2]);
[(z2+z1)/sqrt((realpart(z2)+realpart(z1))^2+(imagpart(z2)+imagpart(z1))^2),z1*z2
/(abs(z1)*abs(z2)),z1*abs(z2)/(abs(z1)*z2)];

/* Transformations with some special values a>0 and x real */

map(abs, [a^z, z^x, %e^(x+%i*y)]);
[a^realpart(z), abs(z)^x, %e^x];

/* Recalculate the results. Some are not correct??? */
map(carg, [a^z, z^x, %e^(x+%i*y)]);
[log(a)*imagpart(z),x*atan2(imagpart(z),realpart(z)),y];

map(realpart, [a^z, z^x, %e^(x+%i*y)]);
[a^realpart(z)*cos(log(a)*imagpart(z)),abs(z)^x*cos(x*atan2(imagpart(z),realpart
(z))),%e^x*cos(y)];

map(imagpart, [a^z, z^x, %e^(x+%i*y)]);
[a^realpart(z)*sin(log(a)*imagpart(z)),abs(z)^x*sin(x*atan2(imagpart(z),realpart
(z))),%e^x*sin(y)];

map(conjugate, [a^z, z^x, %e^(x+%i*y)]);
[a^conjugate(z),conjugate(z^x),%e^(x-%i*y)];

/* z-realpart(z) not simplified to %i*imagpart(z) */
map(signum, [a^z, z^x, %e^(x+%i*y)]);
[a^(z-realpart(z)),z^x/abs(z)^x,%e^(%i*y)];

/* Apply the complex components to complex components */

map(abs, [abs(z),carg(z),realpart(z),imagpart(z),conjugate(z)]);
[abs(z),abs(atan2(imagpart(z),realpart(z))),abs(realpart(z)),abs(imagpart(z)),sq
rt(realpart(conjugate(z))^2+imagpart(conjugate(z))^2)];

map(carg, [abs(z),carg(z),realpart(z),imagpart(z),conjugate(z)]);
[atan2(0,abs(z)),atan2(0,atan2(imagpart(z),realpart(z))),atan2(0,realpart(z)),at
an2(0,imagpart(z)),atan2(imagpart(conjugate(z)),realpart(conjugate(z)))];

map(realpart, [abs(z),carg(z),realpart(z),imagpart(z),conjugate(z)]);
[abs(z),atan2(imagpart(z),realpart(z)),realpart(z),imagpart(z),realpart(conjugat
e(z))];

map(imagpart, [abs(z),carg(z),realpart(z),imagpart(z),conjugate(z)]);
[0,0,0,0,imagpart(conjugate(z))];

map(conjugate, [abs(z),carg(z),realpart(z),imagpart(z),conjugate(z)]);
[abs(z),conjugate(atan2(imagpart(z),realpart(z))),realpart(z),imagpart(z),z];

map(signum, [abs(z),carg(z),realpart(z),imagpart(z),conjugate(z)]);
[signum(abs(z)),signum(atan2(imagpart(z),realpart(z))),signum(realpart(z)),signu
m(imagpart(z)),conjugate(z)/sqrt(realpart(conjugate(z))^2+imagpart(conjugate(z))
^2)];

map(abs,
[abs(x+%i*y),carg(x+%i*y),realpart(x+%i*y),imagpart(x+%i*y),conjugate(x+%i*y)]);
[abs(sqrt(y^2+x^2)),abs(atan2(y,x)),abs(x),abs(y),sqrt(y^2+x^2)];

map(carg,
[abs(x+%i*y),carg(x+%i*y),realpart(x+%i*y),imagpart(x+%i*y),conjugate(x+%i*y)]);
[atan2(0,y^2+x^2)/2,atan2(0,atan2(y,x)),atan2(0,x),atan2(0,y),-atan2(y,x)];

/* For realpart and imagpart we need to assume x^2+y^2>0. Why??? */
(assume(x^2+y^2>0),done);
done;

map(realpart,
[abs(x+%i*y),carg(x+%i*y),realpart(x+%i*y),imagpart(x+%i*y),conjugate(x+%i*y)]);
[sqrt(y^2+x^2),atan2(y,x),x,y,x];

map(imagpart,
[abs(x+%i*y),carg(x+%i*y),realpart(x+%i*y),imagpart(x+%i*y),conjugate(x+%i*y)]);
[0,0,0,0,-y];

map(conjugate,
[abs(x+%i*y),carg(x+%i*y),realpart(x+%i*y),imagpart(x+%i*y),conjugate(x+%i*y)]);
[sqrt(y^2+x^2),conjugate(atan2(y,x)),x,y,%i*y+x];

map(signum,
[abs(x+%i*y),carg(x+%i*y),realpart(x+%i*y),imagpart(x+%i*y),conjugate(x+%i*y)]);
[signum(sqrt(y^2+x^2)),signum(atan2(y,x)),signum(x),signum(y),(x-%i*y)/sqrt(y^2+
x^2)];

/******************************************************************************
Part 4: Tests which no longer works but works again
******************************************************************************/

/* rtest16.mac Problem 57 fails
The code calls sign with an imaginary argument.
* Bug [ 1661490 ] An integral gives a wrong result.
*/
(assume(a>0,b>0,sqrt(b^2+a^2)-a>0,sqrt(sqrt(b^2+a^2)-a)*(sqrt(b^2+a^2)+a)^(3/2)-
b^2>0),0);
0;