Opened 12 years ago

Closed 18 months ago

#11323 closed defect (fixed)

Fix ComplexNumber.__pow__ to allow float^complex

Reported by: Karl-Dieter Crisman Owned by: Alex Ghitza
Priority: major Milestone: sage-9.4
Component: basic arithmetic Keywords: plot li Li pow
Cc: Samuel Lelièvre, Thierry Monteil Merged in:
Authors: Samuel Lelièvre Reviewers: Travis Scrimshaw
Report Upstream: N/A Work issues:
Branch: f86837f (Commits, GitHub, GitLab) Commit: f86837fc32a55794a785d14d56cb3dd3aaacadde
Dependencies: #24247 Stopgaps:

Status badges

Description

In sage.rings.complex_number.ComplexNumber.__pow__??

def __pow__(self, right, modulus):

    try:
        return (self.log()*right).exp()
    except TypeError:
        pass

makes it so that

float(5)^(0.5+14.1347251*i)

doesn't work.

This means plotting even mpmath.li for complex values with a lambda function won't work nicely.

Change History (13)

comment:1 Changed 9 years ago by Jeroen Demeyer

Milestone: sage-5.11sage-5.12

comment:2 Changed 9 years ago by For batch modifications

Milestone: sage-6.1sage-6.2

comment:3 Changed 9 years ago by For batch modifications

Milestone: sage-6.2sage-6.3

comment:4 Changed 8 years ago by For batch modifications

Milestone: sage-6.3sage-6.4

comment:5 Changed 5 years ago by Jeroen Demeyer

Summary: allow floats to be taken to complex powersFix ComplexNumber.__pow__

comment:6 Changed 5 years ago by Jeroen Demeyer

Dependencies: #24247

comment:7 Changed 19 months ago by Samuel Lelièvre

Authors: Samuel Lelièvre
Branch: public/11323
Cc: Samuel Lelièvre Thierry Monteil added
Commit: f86837fc32a55794a785d14d56cb3dd3aaacadde
Milestone: sage-6.4sage-9.3
Status: newneeds_review
Summary: Fix ComplexNumber.__pow__Fix ComplexNumber.__pow__ to allow float^complex

Please @kcrisman can you provide the plotting example you had in mind?

Please @tmonteil can you test on 32-bit?


New commits:

f86837f11323: Fix complex number power so float^complex works

comment:8 in reply to:  7 Changed 19 months ago by Karl-Dieter Crisman

Please @kcrisman can you provide the plotting example you had in mind?

From a decade ago?

I am not sure. I think I had attempted something like this directly, rather than parametrically.

import mpmath
parametric_plot((lambda t: mpmath.ei(log(20)*(0.5+i*RR(t))).real, lambda t: mpmath.ei(log(20)*(0.5+i*RR(t))).imag), (0,14.1), rgbcolor=hue(0.7), plot_points=300) + point((mpmath.ei(log(20)*(0.5+i*14.1)).real, mpmath.ei(log(20)*(0.5+i*14.1)).imag), color='red',size=20)

where I used that on this domain the log integral is the exp integral of the log and somehow that avoided the problem.

But I can't remember what exactly I tried that failed, because presumably I discarded it. Sorry!

comment:9 Changed 19 months ago by Matthias Köppe

Milestone: sage-9.3sage-9.4

Moving to 9.4, as 9.3 has been released.

comment:10 Changed 18 months ago by Trevor Karn

Should line 1695 isinstance(right, (int, long, Integer)) be changed to isinstance(right, (int, Integer)), for python 3, or should it be left as is for backwards compatibility?

comment:11 Changed 18 months ago by Travis Scrimshaw

Reviewers: Travis Scrimshaw
Status: needs_reviewpositive_review

It's not hurting anything by being there, so I would say leave it since it is not related to this ticket. It might also matter for 16-bit machines since this is Cython code (I'm not 100% sure of this however).

LGTM.

comment:12 Changed 18 months ago by Samuel Lelièvre

Thanks!

comment:13 Changed 18 months ago by Volker Braun

Branch: public/11323f86837fc32a55794a785d14d56cb3dd3aaacadde
Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.