66 abs((1 + %i) / (1-%i));
69 abs((1 + %i) * (1-%i));
72 /*--reflection simplification ----*/
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);
97 is(equal(abs(1 + zip),1));
100 (forget(equal(zip,0)),0);
104 /*--absolute value of products and quotients ---*/
115 /*-- absolute value of lists and other mbags---*/
117 abs([a,b]), listarith : true;
120 abs([%i,-6]), listarith : true;
123 abs(x = 1), listarith : true;
126 abs(-x = 1), listarith : true;
130 /*---- declared complex stuff ---*/
132 (declare(z, complex),0);
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);
158 abs([a]), listarith : true;
170 (remrule(abs, first(abs_rules)), remrule(abs, second(abs_rules)),0);
173 (remvalue(abs_rules),0);
176 /*--- abs flatten ---*/
190 /*--- simplify noun form ---*/
202 /*-- subst into abs ---*/
204 ratsubst(x,x^2,abs(1+x^3));
207 ratsubst(0,a,abs(%pi + a));
223 is(equal(op(abs(a.b)), abs));
226 is(equal(op(abs(a^^7)), abs));
229 abs(taylor(exp(x),x,0,3)) - taylor(exp(x),x,0,3);
232 /* bug SF[2631766] abs((1+%i)^%i) is wrong */
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)
246 sin(5*%pi/18)-cos(5*%pi/18)/sqrt(3);
248 /* Bug ID: 900860 - Simplifications involving abs
251 /* Examples from the bug report */
271 abs(2*x+a)^3/(2*x+a)^2;
277 subst(x=-1, abs(log(x))), lognegint : true;
283 (declare(z,complex), 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));
302 /* check sign before using abs(x^n) = abs(x)^n. */
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);
324 (remove(n, integer, e, even), 0);
327 /* SF bug #3152: "invalid simplification of abs(foo)^2 when foo is a complex expression"
330 (kill(a, foo), declare(a, complex));
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"
373 (cabs(x + %i * y))^2;
376 cabs((x + %i * y)^2);
379 declare ([a, b], real);
403 (cabs(x + %i * y))^2;
406 cabs((x + %i * y)^2);
424 /* SF bug #2549: "function sqrt gives incorrect result"
427 (kill(z, f), declare (z, complex));
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;
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"
449 /* SF bug #2063: "abs(x^2) with domain:complex"
455 declare (z, complex);