Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log(im) not implemented #5295

Closed
dlfivefifty opened this issue Jan 4, 2014 · 16 comments
Closed

log(im) not implemented #5295

dlfivefifty opened this issue Jan 4, 2014 · 16 comments

Comments

@dlfivefifty
Copy link
Contributor

log(im)
no method log(ImaginaryUnit)
while loading In[39], in expression starting on line 1

But log(1.im) works.

@ivarne
Copy link
Sponsor Member

ivarne commented Jan 4, 2014

See #4922, for some discussion about why we have this situation.

@dlfivefifty
Copy link
Contributor Author

Maybe it’s better to overwrite log(im) and throw an error?

On 4 Jan 2014, at 7:02 pm, Ivar Nesje notifications@github.com wrote:

See #4922, for some discussion about why we have this situation.


Reply to this email directly or view it on GitHub.

@ViralBShah
Copy link
Member

Closing this as a dup of #4922. The discussion can continue there.

@ivarne
Copy link
Sponsor Member

ivarne commented Jan 4, 2014

Closing as a dup of a closed PR?

@ViralBShah
Copy link
Member

Oops, I didn't realize that the PR was also closed.

@ViralBShah ViralBShah reopened this Jan 4, 2014
@johnmyleswhite
Copy link
Member

I think they're all supposed to be closed as we decided not to treat a standalone im as a number.

@ViralBShah
Copy link
Member

Perhaps we should note this in our documentation, before closing this.

@ivarne
Copy link
Sponsor Member

ivarne commented Jan 4, 2014

Yes, and this issue is now (as so many other issues) about giving a better error message. It seems that MethodError is not the most friendly introduction to Julia, and it indicates that fixing the problem involves implementing more methods, when there is a well discussed design decision behind the behavior.

@jiahao
Copy link
Member

jiahao commented Jan 4, 2014

There is a genuine issue about im left unresolved. I presume im's behavior was meant to mimic Kahan's proposal for an imaginary type (which Julia doesn't have).

Although in #4922, @JeffBezanson wrote that the alternative to current behavior would lead to problems like:

maybe we should just live with the NaN problem and let im == complex(false,true)

However, we already have these problems and so have the worst of both worlds at the moment (where functions over im are undefined and should stay that way). Note that this equality already holds true now

julia> im==complex(false,true)
true

I assume the NaN problem refers to the issue which Kahan points out [pdf], namely that automatically promoting all operations on (Real, Complex) operands produces bad computations sometimes, like

julia> 4*complex(Inf, 5)
Inf + 20.0im

julia> complex(4,0)*complex(Inf, 5)
complex(Inf,NaN)

While this works correctly for (Real, Complex), it doesn't work on imaginary*Complex:

julia> 4im*complex(Inf,5) #Expect complex(-20,Inf)
NaN + Inf*im

or in other words, that the current arithmetic rules obtained via type promotion retain half the "NaN problem".

This can be fixed fairly simply with parentheses, viz.:

julia> 4(im*complex(Inf,5))
complex(-20.0,Inf)

so it could be simply an order-of-operations issue. (and similarly with division)

For addition and subtraction, however, I don't see how to rescue the sign-of-zero problem without special casing:

julia> 4.0 + complex(5.0, -0.0)
9.0 - 0.0im

julia> complex(4.0) + complex(5.0, -0.0) #0.0 + (-0.0) == 0.0
9.0 + 0.0im

julia> 4.0im + complex(-0.0, 5.0) #expect -0.0 + 9.0im
0.0 + 9.0im

@StefanKarpinski
Copy link
Sponsor Member

I fairly strongly support the addition of a purely imaginary type. I suspect that we can define im as Imaginary(1) or maybe Imaginary(true).

@jiahao
Copy link
Member

jiahao commented Jan 5, 2014

Since Imaginary would have to have a Number parameter, would defining im as Imaginary(true) incur cost in type promotion?

@StefanKarpinski
Copy link
Sponsor Member

No, I don't think so. I'm actually working on a pr for this, so we'll see how it works out.

@StefanKarpinski
Copy link
Sponsor Member

See #5313.

@JeffBezanson
Copy link
Sponsor Member

We would still face the question of whether to implement every function for the Imaginary type.

Half seriously, would we define Complex{T} as something like CompoundNumber{T,Imaginary{T}}?

@stevengj
Copy link
Member

Fixed by #5468, since im is now a Complex type and gets promoted to Complex{Float32}.

@jiahao
Copy link
Member

jiahao commented Jan 2, 2015

Looks like the lack of a pure imaginary type continues to haunt us; c.f. #9531

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants