The quick workaround is to set domain:'complex.
Better to rethink the mabs clause of simpexpt to check whether the argument
is syntactically complex. Remember that (even when we fix that) Maxima by
default assumes that expressions which are syntactically real (e.g.
sqrt(x)) are real.
There are some other weird bugs, e.g. abs(sqrt(-x^4-x^2)) => 0 ...
(regardless of domain) though cabs is correct.
The *historical explanation* of all this probably goes back to 'abs'
originally being designed as a function of a real argument, and all the
cases where the argument is non-real have not been thought through. But
that is no excuse for bugs....
-s
On Wed, Jun 6, 2012 at 5:04 PM, Henry Baker <hbaker1 at pipeline.com> wrote:
> Can this problem be fixed, or is there any workaround?
>
> At 12:57 PM 6/6/2012, Stavros Macrakis wrote:
> >Ah, the problem here has nothing to do with cabs. It is the general
> simplifier that blindly and incorrectly transforms 'abs(EX)^2 => EX^2,
> assuming (without checking) that EX is real.
> >
> > -s
> >
> >On Wed, Jun 6, 2012 at 1:49 PM, Henry Baker <hbaker1 at pipeline.com> wrote:
> >Yes, it work, but only _after_ I defined my own absolute value function.
> See my previous message.
> >
> >At 10:22 AM 6/6/2012, Stavros Macrakis wrote:
> >>What exactly do you consider "hopelessly broken" in this? In other
> words, which of these outputs would you want to be different, and what
> would you want them to be?
> >>
> >> -s
> >>
> >>On Wed, Jun 6, 2012 at 12:52 PM, Henry Baker <hbaker1 at pipeline.com>
> wrote:
> >>cabs() and abs() on complex numbers seem hopelessly broken.
> >>
> >>I defined my own cabs() function:
> >>myabs(a):=sqrt(a*conjugate(a));
> >>
> >>(%i7) myabs(a)^2=realpart(a)^2+imagpart(a)^2;
> >> 2 2
> >>(%o7) a conjugate(a) = realpart (a) + imagpart (a)
> >>(%i8) %,nouns;
> >> 2 2
> >>(%o8) a conjugate(a) = realpart (a) + imagpart (a)
> >>(%i9) %,a=ar+%i*ay;
> >> 2 2
> >>(%o9) (ar - %i ay) (%i ay + ar) = realpart (%i ay + ar) + imagpart (%i
> ay + ar)
> >>(%i10) %,expand;
> >> 2 2 2 2
> >>(%o10) ay + ar = realpart (%i ay + ar) + imagpart (%i ay + ar)
> >>(%i11) %,rectform;
> >> 2 2 2 2
> >>(%o11) ay + ar = realpart (%i ay + ar) + imagpart (%i ay + ar)
> >>(%i12) %,nouns;
> >> 2 2 2 2
> >>(%o12) ay + ar = ay + ar
> >>
> >>At 09:31 AM 6/6/2012, Henry Baker wrote:
> >>>Yes, but if I do the following, it doesn't work:
> >>>
> >>>(%i2) cabs(a)^2=realpart(a)^2+imagpart(a)^2;
> >>> 2 2 2
> >>>(%o2) abs(a) = realpart (a) + imagpart (a)
> >>>(%i3) %,a=r+%i*s;
> >>> 2 2 2
> >>>(%o3) (%i s + r) = realpart (%i s + r) + imagpart (%i s + r)
> >>>(%i4) %,expand;
> >>> 2 2 2 2
> >>>(%o4) - s + 2 %i r s + r = realpart (%i s + r) + imagpart (%i s + r)
> >>>(%i5) rectform(%);
> >>> 2 2 2 2
> >>>(%o5) - s + 2 %i r s + r = realpart (%i s + r) + imagpart (%i s + r)
> >>>
> >>>At 08:59 AM 6/6/2012, Richard Fateman wrote:
> >>>>Henry:
> >>>>
> >>>>try this:
> >>>>
> >>>>a: r+%i*s;
> >>>>
> >>>>cabs(a)^2= realpart(a)^2 + imagpart(a)^2;
> >>>>
> >>>>you can say declare(r,real); declare(s,real) if you wish, but
> >>>>it seems to be unnecessary.
> >>>>
> >>>>RJF
> >>>>
> >>>>On 6/6/12 8:37 AM, Stavros Macrakis wrote:
> >>>>>I believe that cabs(a) used to return
> sqrt('realpart(a)^2+'imagpart(a)^2), though it now returns 'abs(a) (prints
> as |a|). I think the former is more in the spirit of cabs (which is
> supposed to give you an explicit formula, not just punt to a nounform), so
> I would consider the current behavior to be a bug.
> >>>>>
> >>>>>If I remember correctly, a few years ago, someone tried to unify abs
> and cabs (I objected) -- this may be related to that?
> >>>>>
> >>>>>As a workaround, you can do cabs(rectform(a))^2 =>
> 'realpart(a)^2+'imagpart(a)^2. Unfortunately, rectform(abs(a)) currently
> returns 'abs(a) -- again, I think this is a bug. If you're starting with
> the abs form, I suppose you could do
> subst(lambda([ex],cabs(rectform(ex))),'abs, ... ).
> >>>>>
> >>>>> -s
> >>>>>
> >>>>>On Wed, Jun 6, 2012 at 11:06 AM, Henry Baker <hbaker1 at pipeline.com>
> wrote:
> >>>>>I'm trying to get maxima to prove that
> >>>>>
> >>>>>abs(a)^2=realpart(a)^2+imagpart(a)^2.
> >>>>>
> >>>>>I tell maxima:
> >>>>>
> >>>>>declare(a,complex);
> >>>>>abs(a)^2=realpart(a)^2+imagpart(a)^2;
> >>>>>
> >>>>>What do I tell maxima to get it to simplify this?
>
>