#2550 abs((%i+x)^2) evaluates to (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
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)


  • Robert Dodier

    Robert Dodier - 2013-03-24

    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
  • Albrecht Mueller

    If you try this with the Maxima Online Caluculator, you get:

    (%i1) abs((x+%i)^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

  • Robert Dodier

    Robert Dodier - 2013-05-24
    • labels: --> Lisp Core - Simplification
  • Robert Dodier

    Robert Dodier - 2013-05-24

    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"

  • Paolo Bolognesi

    Paolo Bolognesi - 2013-11-20

    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

  • Jaime E. Villate

    Why don't you use cabs instead of abs? abs is for real numbers
    and cabs for complex numbers.

      (%i2) cabs((%i+x)^2);
      (%o2)                         x  + 1
    Last edit: Jaime E. Villate 2013-11-20
    • Albrecht Mueller

      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.

  • Rupert Swarbrick

    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?

  • Rupert Swarbrick

    Er, it would indeed be work. I meant worth, of course...

  • Jaime E. Villate

    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.

    Last edit: Jaime E. Villate 2013-11-22
    • Albrecht Mueller

      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.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks