Windows installer: update wxMaxima.
[maxima/cygwin.git] / tests / rtest_abs.mac
blob0a5a64ba384d823d63ac7465ac94c780e0fdb69c
1 (kill(all),0);
2 0$
4 /*--- numbers ----*/
6 abs(-5);
7 5$
9 abs(0);
12 abs(42);
13 42$
15 abs(-7/8);
16 7/8$
18 abs(27/5);
19 27/5$
21 abs(-2.4);
22 2.4$
24 abs(0.0);
25 0.0$
27 abs(6.022e23);
28 6.022e23;
30 abs(-6.022b23);
31 6.022b23$
33 abs(1066.0b3);
34 1066.0b3$
36 abs(inf);
37 inf$
39 abs(minf);
40 inf$
42 abs(infinity);
43 inf$
45 abs(und);
46 und$
48 abs(ind);
49 ind$
51 abs(%pi);
52 %pi$
54 abs(%phi);
55 %phi$
57 abs(%i);
60 abs(1 + %i);
61 sqrt(2)$
63 abs(cos(1));
64 cos(1)$
66 abs((1 + %i) / (1-%i));
69 abs((1 + %i) * (1-%i));
72 /*--reflection simplification ----*/
74 abs(x) - abs(-x);
77 abs(x*y) - abs(-x*y);
80 abs(sin(x)) - abs(sin(-x));
83 expand(abs(14 * a*(b - c)) - abs(-14 * a * (c - b)));
86 ratsubst(c,b,abs(x*(a+b)) - abs(x*(a+c)));
89 /*--database facts -----*/
91 (assume(equal(zip,0)),0);
94 abs(zip * x);
97 is(equal(abs(1 + zip),1));
98 true$
100 (forget(equal(zip,0)),0);
104 /*--absolute value of products and quotients ---*/
106 abs((1+%i) * x);
107 sqrt(2) * abs(x)$
109 abs((1+%i) * %pi);
110 sqrt(2) * %pi$
112 abs((1+%i) / x);
113 sqrt(2) / abs(x)$
115 /*-- absolute value of lists and other mbags---*/
117 abs([a,b]), listarith : true;
118 [abs(a),abs(b)]$
120 abs([%i,-6]), listarith : true;
121 [1,6]$
123 abs(x = 1), listarith : true;
124 abs(x) = 1$
126 abs(-x = 1), listarith : true;
127 abs(x) = 1$
130 /*---- declared complex stuff ---*/
132 (declare(z, complex),0);
135 abs(conjugate(z));
136 abs(z)$
138 abs(exp(z));
139 exp(realpart(z))$
141 subst(z = %i, abs(z^2));
144 (remove(z,complex),0);
147 /*--- abs and tellsimp ---- */
149 (tellsimp(abs(a), a+1), abs_rules : tellsimp(abs(b), b+1), 0);
152 abs(a);
153 a+1$
155 abs(a * x);
156 (a+1) * abs(x)$
158 abs([a]), listarith : true;
159 [a+1]$
161 abs(a*b);
162 (a+1)*(b+1)$
164 abs(a^7);
165 (a+1)^7$
167 abs((a*b)^5);
168 (a+1)^5 * (b + 1)^5$
170 (remrule(abs, first(abs_rules)), remrule(abs, second(abs_rules)),0);
173 (remvalue(abs_rules),0);
176 /*--- abs flatten  ---*/
178 abs(abs(x));
179 abs(x)$
181 abs(abs(-x));
182 abs(x)$
184 abs(abs(abs(x)));
185 abs(x)$
187 abs(abs(abs(x))+1);
188 abs(abs(x) + 1)$
190 /*--- simplify noun form ---*/
192 'abs(1);
195 'abs(1+x^2);
196 1 + x^2$
198 'abs(abs(x));
199 abs(x)$
202 /*-- subst into abs ---*/
204 ratsubst(x,x^2,abs(1+x^3));
205 1+x^2$
207 ratsubst(0,a,abs(%pi + a));
208 %pi$
210 /*-- CRE tests ---*/
212 abs(rat(x) + 1);
213 abs(1+x)$
215 abs(rat(1));
218 /*-- misc -----*/
220 abs(signum(1/x));
223 is(equal(op(abs(a.b)), abs));
224 true$
226 is(equal(op(abs(a^^7)), abs));
227 true$
229 abs(taylor(exp(x),x,0,3)) - taylor(exp(x),x,0,3);
230 ''(taylor(0,x,0,3));
232 /* bug SF[2631766] abs((1+%i)^%i) is wrong */
234 abs((1+%i)^%i);
235 %e^(-%pi/4);
237 abs((sqrt(3)*%i/2-1/2)/(3*(%i/(6*sqrt(3))-1/6)^(1/3))
238             +(%i/(6*sqrt(3))-1/6)^(1/3)*(-sqrt(3)*%i/2-1/2));
241 sqrt(3*sin(5*%pi/18)^2-2*sqrt(3)*cos(5*%pi/18)*sin(5*%pi/18)
242                             +cos(5*%pi/18)^2)
243        /sqrt(3);
246 sin(5*%pi/18)-cos(5*%pi/18)/sqrt(3);
248 /* Bug ID: 900860 - Simplifications involving abs
249  */
251 /* Examples from the bug report */
252 abs(x)/x^2;
253 1/abs(x);
255 x^2/abs(x);
256 abs(x);
258 abs(x)^3;
259 x^2*abs(x);
261 /* More examples */
262 1/x^3*abs(x);
263 1/(x*abs(x));
265 1/abs(x)*x^3;
266 x*abs(x);
268 abs(x)^3/x^2;
269 abs(x);
271 abs(2*x+a)^3/(2*x+a)^2;
272 abs(2*x+a);
274 abs(log(x));
275 abs(log(x))$
277 subst(x=-1, abs(log(x))), lognegint : true;
278 %pi$
280 abs((-1)^x);
283 (declare(z,complex), abs(log(-z)));
284 abs(log(-z))$
286 subst(z=-1, abs(log(-z)));
289 (remove(z,complex),0);
292 /* check sign before using multiplicative identity; from x*y > 0 */
293 (assume(x*y > 0), abs(x*y));
294 x*y$
296 abs(-x*y);
297 x*y$
299 (forget(x*y > 0),0)$
302 /* check sign before using abs(x^n) = abs(x)^n. */
304 abs(x^2);
305 x^2$
307 abs(rat(a-b))-abs(rat(b-a));
310 /* Bug #2230: abs(x)^(2*int) doesn't simplify */
312 (declare(n, integer, e, even), 0);
315 abs(x)^(2*n);
316 x^(2*n)$
318 abs(x)^e;
319 x^e$
321 abs(x)^(2*floor(z));
322 x^(2*floor(z))$
324 (remove(n, integer, e, even), 0);
327 /* SF bug #3152: "invalid simplification of abs(foo)^2 when foo is a complex expression"
328  */
330 (kill(a, foo), declare(a, complex));
331 done;
333 domain:real;
334 real;
336 foo:abs((a + 1)^2);
337 abs(a + 1)^2;
339 foo, a=%i;
342 abs(a^2);
343 abs(a)^2;
345 domain:complex;
346 complex;
348 foo:abs((a + 1)^2);
349 abs(a + 1)^2;
351 foo, a=%i;
354 abs(a^2);
355 abs(a)^2;
357 /* SF bug #2901: "incorrect simplification of abs((a + b*%i)^2) with a, b real"
358  * SF bug #2550: "abs((%i+x)^2) evaluates to (x + %i)^2"
359  */
361 kill(x, y, a, b);
362 done;
364 domain:real;
365 real;
367 (abs(x + %i * y))^2;
368 abs(x + %i*y)^2;
370 abs((x + %i * y)^2);
371 abs(x + %i*y)^2;
373 (cabs(x + %i * y))^2;
374 x^2 + y^2;
376 cabs((x + %i * y)^2);
377 x^2 + y^2;
379 declare ([a, b], real);
380 done;
382 abs((a + b*%i)^2);
383 abs(a + b*%i)^2;
385 abs((%i+x)^2);
386 abs(%i + x)^2;
388 abs(%i^2);
391 abs((%i+x)^2 + 1);
392 abs((%i + x)^2 + 1);
394 domain:complex;
395 complex;
397 (abs(x + %i * y))^2;
398 abs(x + %i*y)^2;
400 abs((x + %i * y)^2);
401 abs(x + %i*y)^2;
403 (cabs(x + %i * y))^2;
404 x^2 + y^2;
406 cabs((x + %i * y)^2);
407 x^2 + y^2;
409 abs((a + b*%i)^2);
410 abs(a + b*%i)^2;
412 abs((%i+x)^2);
413 abs(%i + x)^2;
415 abs(%i^2);
418 abs((%i+x)^2 + 1);
419 abs((%i + x)^2 + 1);
421 (reset(domain), 0);
424 /* SF bug #2549: "function sqrt gives incorrect result"
425  */
427 (kill(z, f), declare (z, complex));
428 done;
430 foo:diff(z(q),q)^2*conjugate(diff(z(q),q))^2;
431 ('diff(z(q),q,1))^2*conjugate('diff(z(q),q,1))^2;
433 sqrt(foo);
434 /* a better result would be abs('diff(z(q),q,1))^2 but at least this result is not incorrect */
435 abs('diff(z(q),q,1))*sqrt(conjugate('diff(z(q),q,1))^2);
437 sqrt(f(z)^2*conjugate(f(z))^2);
438 abs(f(z))*sqrt(conjugate(f(z))^2);
440 /* SF bug #2480: "function abs has bug"
441  */
443 kill(t, u);
444 done;
446 abs(u-%e^(%i*t)) ^2;
447 abs(u-%e^(%i*t)) ^2;
449 /* SF bug #2063: "abs(x^2) with domain:complex"
450  */
452 kill(x, z);
453 done;
455 declare (z, complex);
456 done;
458 domain:real;
459 real;
461 abs(x)^2;
462 x^2;
464 abs(x^2);
465 x^2;
467 abs(z^2);
468 abs(z)^2;
470 domain:complex;
471 complex;
473 abs(x)^2;
474 abs(x)^2;
476 abs(x^2);
477 abs(x)^2;
479 abs(z^2);
480 abs(z)^2;
482 (reset(domain), 0);