Discussion:
abs/cabs
Adam Majewski
2009-10-31 21:44:05 UTC
Permalink
Hi,

What is a difference between abs and cabs ?
(abs can handle complex values)
When use abs, when cabs ?

Regards

Adam
Dieter Kaiser
2009-10-31 22:30:00 UTC
Permalink
Post by Adam Majewski
Hi,
What is a difference between abs and cabs ?
(abs can handle complex values)
When use abs, when cabs ?
In short:

The abs function is a simplifying function, which calls cabs, when the
argument seems to be complex. That is not perfectly implemented. More
work can be done.

The cabs function is a verb function, which assumes a complex argument.
Therefore the argument is always split into a real and imaginary part.

E.g.

(%i2) declare(z,complex)$

For this case the simplifying abs function returns an unsimplified
expressions:

(%i3) abs(log(z));
(%o3) abs(log(z))

The verb function cabs calculates the following answer:

(%i4) cabs(log(z));
(%o4) sqrt(log(abs(z))^2+carg(z)^2)

Dieter Kaiser
Robert Dodier
2009-11-01 18:36:51 UTC
Permalink
Post by Dieter Kaiser
The abs function is a simplifying function, which calls cabs, when the
argument seems to be complex. That is not perfectly implemented. More
work can be done.
The cabs function is a verb function, which assumes a complex argument.
Therefore the argument is always split into a real and imaginary part.
Hmm. Does this suggest that cabs should be hidden from the user,
and only called from abs as necessary?

I've often wondered about abs vs cabs myself ....

best

Robert Dodier
Stavros Macrakis
2009-11-01 19:04:08 UTC
Permalink
As Dieter says, abs is a simplifying function, and cabs is a routine.

The distinction is that abs is for when you want to *express* the concept of
absolute value; cabs is for when you want to *change the form* of the
expression to make it more explicit. This is similar to the noun/verb forms
of integrate/limit/diff: 'integrate is to integrate as abs is to cabs. The
consistent solution would be to change over to 'abs/abs.

Somewhere along the line (post-Maxima 5.9), the two concepts seem to have
gotten mixed up.

For example,

declare(z,complex)$
cabs(z+1) => sqrt(realpart(z)+1)^2+imagpart(z)^2)

which is as expected. But abs(z+1) does the same thing, which it did not
used to. So there is now no way to express the concept of "the absolute
value of z" without writing it out in terms of real/imaginary components,
which is horrible.

-s
Post by Robert Dodier
Post by Dieter Kaiser
The abs function is a simplifying function, which calls cabs, when the
argument seems to be complex. That is not perfectly implemented. More
work can be done.
The cabs function is a verb function, which assumes a complex argument.
Therefore the argument is always split into a real and imaginary part.
Hmm. Does this suggest that cabs should be hidden from the user,
and only called from abs as necessary?
I've often wondered about abs vs cabs myself ....
best
Robert Dodier
_______________________________________________
Maxima mailing list
http://www.math.utexas.edu/mailman/listinfo/maxima
Robert Dodier
2009-11-01 23:25:20 UTC
Permalink
Post by Stavros Macrakis
The distinction is that abs is for when you want to *express* the concept of
absolute value; cabs is for when you want to *change the form* of the
expression to make it more explicit. This is similar to the noun/verb forms
of integrate/limit/diff: 'integrate is to integrate as abs is to cabs. The
consistent solution would be to change over to 'abs/abs.
Hmm, yes, that makes sense.
Post by Stavros Macrakis
declare(z,complex)$
cabs(z+1) => sqrt(realpart(z)+1)^2+imagpart(z)^2)
which is as expected. But abs(z+1) does the same thing, which it did not
used to. So there is now no way to express the concept of "the absolute
value of z" without writing it out in terms of real/imaginary components,
which is horrible.
Yes, that seems bad. Typically, though, stuff gets changed because
of some other problem, of which we have now lost sight ...
I guess if we trawl through the CVS history we could discover
why it was changed?

best

Robert Dodier
Dieter Kaiser
2009-11-01 23:42:21 UTC
Permalink
Post by Robert Dodier
Post by Dieter Kaiser
declare(z,complex)$
cabs(z+1) => sqrt(realpart(z)+1)^2+imagpart(z)^2)
which is as expected. But abs(z+1) does the same thing, which it did not
used to. So there is now no way to express the concept of "the absolute
value of z" without writing it out in terms of real/imaginary components,
which is horrible.
Yes, that seems bad. Typically, though, stuff gets changed because
of some other problem, of which we have now lost sight ...
I guess if we trawl through the CVS history we could discover
why it was changed?
This example has changed of course, because abs tries to look more
carefully for complex expressions. In earlier versions of Maxima cabs is
called from abs only if we have the symbol %i within the expression. Now
abs looks for complex symbols too to get a lot of other things more
correct.

The above problem is the reason, I hesitated to introduce not only
support for complex symbols, but complex functions too.

All this might be a dilemma. I often thought about the code for complex
expressions. Perhaps it is necessary to start from the very beginning
and define what the code should really do to handle complex expressions.

Dieter Kaiser
Stavros Macrakis
2009-11-02 02:10:46 UTC
Permalink
Dieter,

I agree entirely that we need to think more systematically about the
handling of complex expressions in Maxima. But in the meantime we shouldn't
be changing important existing distinctions (abs vs. cabs).

...abs tries to look more
Post by Dieter Kaiser
carefully for complex expressions. In earlier versions of Maxima cabs is
called from abs only if we have the symbol %i within the expression.
That seems like a peculiar rule to start with. There is, after all, no more
reason that abs(z+%i) should call cabs than abs(z+1) should.
Post by Dieter Kaiser
Now abs looks for complex symbols too to get a lot of other things more
correct.
Can you elaborate? Remember that abs and cabs have quite different
functions in the system.

-s

Loading...