#2550 abs((%i+x)^2) evaluates to (x + %i)^2

None
open
nobody
5
2013-11-22
2013-02-19
Albrecht Mueller
No

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)

Discussion

1 2 > >> (Page 1 of 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
    
     
  • 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

     
  • 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"

     
  • 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

     
    Attachments
  • 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
    
     
    Last edit: Jaime E. Villate 2013-11-20
    • 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.

       
  • 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?

     
1 2 > >> (Page 1 of 2)