# [Maxima] complex conjugate and modulus

Stavros Macrakis macrakis at alum.mit.edu
Sat Aug 9 18:08:42 CDT 2008

```In my previous message, I posted some code that I hope will help with
questions.

On Sat, Aug 9, 2008 at 12:10 AM, John Lapeyre <pdl at johnlapeyre.com> wrote:

> This last result is mathematically correct, but I dont know how to
>  stop the replacement   conjugate(cos(z)) --> cos(conjugate(z)), which
> happens before it is passed to my routine.

As a general rule, it is a bad idea to block Maxima's simplifications,
which standardize the form of expressions so that further
simplifications can be applied.  For example, if conjugate(cos(x))
weren't simplified to cos(conjugate(x)), Maxima wouldn't be able to
recognize that conjugate(cos(x)) - cos(conjugate(x)) = 0. Or that
sqrt(x)=x^(1/2).

That said, I understand that it is frustrating when these automatic
simplifications put things in a form that you don't want or that is
harder to work with.

> In this case, my pattern matching routine refuses to recognize
>    sqrt(z) = sqrt(z) as true.

Without trying to debug in detail, I would guess that this is because
you've turned simplification off.  The standard internal
representation of sqrt(x) is x^(1/2); the transformation is done by
simplification.

> But if I set simp:true, then abs(sqrt(z))^2 is simplified to z , which is incorrect.

This is a bug.  Sorry. I believe Dieter Kaiser is looking into this
and related bugs.

> 1) What kind of facilities are there for dumping various representations of an expression?

The visible form of the expression is what "part" works off of.  So
part(a/b) => "/". The internal form is what "inpart" works off of, so
inpart(a/b,0) => "*" and inargs(a/b) => [a, 1/b] where
inargs(ex):=block([inflag:true],args(ex)).  You can also look at the
internal (Lisp-based) representation with ?print(expr).  As a general
rule, if you are manipulating expressions programmatically, I would
strongly recommend using inpart and inargs; part is extremely
inefficient because it reformats the *whole* expression every time it
looks at it....

> 2) I guess there is not much opportunity for fine grained simplification.
> In order to get my routine to work, I have to turn of simplification in
> blocks. ...Or is there something better than simp:false ?

simp:false is almost always a bad thing to do, because everything in
Maxima depends on simplification, even arithmetic as you can see.
Many parts of Maxima do not work correctly with simp:false.

The problem with abs(sqrt(z))^2 is not something you will be able to
work around by turning simplification off.