For the record, declare(x, complex) doesn't change the result.
(%i2) declare (x, complex); (%o2) done (%i3) abs((x+%i)^2); (%o3) (x+%i)^2
There is an error in the simplification of the abs function:
abs((%i+x)^2) ==> (x + %i)^2
Other examples work, e.g.
abs(%i^2) ==> 1
or
abs((%i+x)^2 + 1) ==> abs((%i+x)^2 + 1)
Maxima version: "5.28.0-2"
Maxima build date: "2012-08-27 23:16:48"
Host type: "i686-pc-mingw32"
Lisp implementation type: "GNU Common Lisp (GCL)"
Lisp implementation version: "GCL 2.6.8"
This worked in Version 5.19.02:
abs((%i+x)^2) ==> sqrt((x^2-1)^2 + 4 * x^2)
For the record, declare(x, complex) doesn't change the result.
(%i2) declare (x, complex); (%o2) done (%i3) abs((x+%i)^2); (%o3) (x+%i)^2
Maybe there are other problems related to this bug:
Bug #2549 function sqrt gives incorrect result
Discussion in wxMaxima: plot2d: expression evaluates to non-numeric value everywhere in plotting range
If you try this with the Maxima Online Caluculator, you get:
(%i1) abs((x+%i)^2); 2 (%o1) x + 1
The online calculator reports the following build info:
(%i1) build_info();
Maxima version: 5.21.1
Maxima build date: 7:25 9/18/2010
Host type: x86_64-unknown-linux-gnu
Lisp implementation type: GNU Common Lisp (GCL)
Lisp implementation version: GCL 2.6.7
Observed in current development version.
Maxima version: "branch_5_30_base_90_g122d48e_dirty"
Maxima build date: "2013-05-22 15:13:12"
Host type: "i686-pc-linux-gnu"
Lisp implementation type: "ECL"
Lisp implementation version: "12.12.1"
The same problem is observed also in a bit more generic case as shown in the attachment.
Basically, it seems that when evaluating abs(c)^2, or even when multiplying the latter by itself abs(c)abs(c), the core does not realize that c=a+ib is actually a complex quantity rather than a real one, so it cannot be simply squared as well.
The same even happens when either a or b are assigned a numerical real value; only when both of them are assigned real numerical values, the bug disappears.
The software version is:
wxMaxima version: 13.4.0
Maxima version: 5.31.2
Maxima build date: 2013-10-07 23:05:06
Host type: i686-pc-mingw32
Lisp implementation type: GNU Common Lisp (GCL)
Lisp implementation version: GCL 2.6.8
Why don't you use cabs instead of abs? abs is for real numbers
and cabs for complex numbers.
(%i2) cabs((%i+x)^2); 2 (%o2) x + 1
The documentation of the abs function says: "If the argument, z, is a real or complex number, abs returns the absolute value of z. If possible, symbolic expressions using the absolute value function are also simplified." In the documentation of cabs I found: "cabs is a verb function and is not suitable for symbolic calculations."
It is not clear to me why there is a need for a cabs function if abs is working properly. If abs is restricted to real values then it should issue an error message when the argument is of wrong type instead of returning a wrong result.
Yes I know, the situation with cabs vs. abs is very confusing; see for example this message in the list: http://www.math.utexas.edu/pipermail/maxima/2011/025213.html
That's a truly excellent write-up. Jaime: Do you think it would be work trying to distil it into improved documentation for abs and cabs?
Er, it would indeed be work. I meant worth, of course...
Yes Rupert, I think that Stavros' write-up is much better than the current manual description. However, as Stavros himself says, his summary refers to an ideal-world Maxima. In practice, abs does not work exactly as described in his summary (recent bugs or new features?). For instance abs((x+%i*y)^2)returns (%i*y+x)^2 and not abs(%i*y+x)^2.
Also, users might end up thinking that cabs should not be used when you want to simplify an expression, but in some cases the situation is the opposite: abs will not make the simplification you expected while cabs will; see for instance today's message in the mailing list and the answer given by Leo Butler.
If abs(x) - where x is a real or a complex number - returns or is simplified to something that is not a real number I think this is a recent bug. I cannot imagine what kind of a new useful feature this behaviour could be.
Log in to post a comment.