Opened 8 years ago

Closed 6 years ago

#11668 closed defect (fixed)

abs(a+b)^2 == (a+b)^2

Reported by: jan Owned by: burcin
Priority: major Milestone: sage-5.11
Component: symbolics Keywords: maxima abs
Cc: kcrisman, mjo Merged in: sage-5.11.beta3
Authors: Karl-Dieter Crisman Reviewers: Michael Orlitzky
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:


sage: version()
'Sage Version 4.7, Release Date: 2011-05-23'
sage: var('a b', domain='real');
sage: A = abs((a+i*b))^2
sage: A
abs(a + I*b)^2
sage: imag(A)
sage: A.simplify_full()
a^2 + 2*I*a*b - b^2
sage: imag(A.simplify_full())

The last result is clearly wrong. abs() is real by definition. simplify_full() doesn't handle abs() correctly.

Demo Notebook:

Attachments (1)

trac_11668.patch (988 bytes) - added by kcrisman 6 years ago.
Based on 5.10.rc1

Download all attachments as: .zip

Change History (9)

comment:1 Changed 8 years ago by jan

  • Component changed from sage-mode to symbolics
  • Owner changed from ncalexan to burcin

comment:2 Changed 8 years ago by kcrisman

  • Cc kcrisman added

The exact place is

sage: A.simplify_radical()
a^2 + 2*I*a*b - b^2

This is how radcan in Maxima does this over the real domain, which simplify_radical temporarily makes us in.

I'm not sure what the best thing to do here is. Two ideas:

  • Change so that we stay in domain:complex in Maxima, sort of missing the point of simplify_radical
  • Give lots of warnings not to trust simplification because (like most simplification) it is not always true, but useful. (Sort of like how \sqrt{x^2}\neq x but sometimes it's useful to simplify it that way.)

I do not think we pass the domain information from the (Pynac) variables in any case, or if that would be very easy to do.

comment:3 Changed 6 years ago by kcrisman

This has been fixed by #12780.

sage: var('a b')
(a, b)
sage: A = abs((a+i*b))^2
sage: A.simplify_radical()
abs(a + I*b)^2
sage: imag(A)
sage: imag(A.simplify_full())

Patch probably coming up. This would also be dealt with by #12737, but that is orthogonal to having fixed the domain issues.

comment:4 Changed 6 years ago by kcrisman

  • Authors set to Karl-Dieter Crisman
  • Cc mjo added
  • Status changed from new to needs_review

comment:5 Changed 6 years ago by mjo

Two minor things, can you use a,b = SR.var('a,b') to create the variables? That will eliminate one line of unrelated output. And just a style preference, since sage outputs the complex unit as I, I think it's a tiny bit more consistent to use that for input as well, but I'll take it either way.

Changed 6 years ago by kcrisman

Based on 5.10.rc1

comment:6 Changed 6 years ago by kcrisman

Two minor things

Sure, no problem. I put the i instead of I just because I copied from the original example in the ticket, but that is unimportant. Thanks!

comment:7 Changed 6 years ago by mjo

  • Reviewers set to Michael Orlitzky
  • Status changed from needs_review to positive_review

comment:8 Changed 6 years ago by jdemeyer

  • Merged in set to sage-5.11.beta3
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.