Opened 7 years ago

Closed 7 years ago

#15032 closed defect (fixed)

`real` and `imag` of `complex` should return `float`

Reported by: eviatarbach Owned by:
Priority: major Milestone: sage-5.12
Component: symbolics Keywords:
Cc: Merged in: sage-5.12.beta3
Authors: Eviatar Bach Reviewers: Punarbasu Purkayastha
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:


real(z) and imag(z), where z is complex, as of now returns a complex. It should return a float, since that makes it consistent with real(CC(3, 4)), for example. It also fixes problems with plotting the real or imaginary parts of complex functions.

Attachments (1)

trac15032.3.patch (1.8 KB) - added by eviatarbach 7 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 7 years ago by eviatarbach

  • Status changed from new to needs_review

Patchbot apply trac15032.2.patch

Last edited 7 years ago by eviatarbach (previous) (diff)

comment:2 Changed 7 years ago by ppurka

The new functions needs some doctests to check that the type is correct.

I am actually quite surprised by the inconsistency of the Sage implementation. self.real contains the number in the case of python's complex but it is a function in Sage's implementation. Do you know what is the reason behind the function in the Sage implementation?

sage: a = CC(1)     
sage: a.real
<function real>
sage: a = complex(1)
sage: a.real
Version 0, edited 7 years ago by ppurka (next)

comment:3 Changed 7 years ago by eviatarbach

Okay, I'll add the tests.

I think the reason for the functions is that it's converting from MPFR. It could be changed with the @property decorator so that self.real will work.

Changed 7 years ago by eviatarbach

comment:4 Changed 7 years ago by eviatarbach

I added the tests to __call__ but also left the other ones intact, since the __call__ ones aren't visible in the documentation.

comment:5 Changed 7 years ago by ppurka

  • Authors set to Eviatar Bach
  • Reviewers set to Punarbasu Purkayastha
  • Status changed from needs_review to positive_review

Looks good to me. All tests pass in sage/rings and sage/functions

Patchbot apply trac15032.3.patch

comment:6 Changed 7 years ago by jdemeyer

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