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

missing Complex expm1 and log1p #3141

Closed
stevengj opened this issue May 17, 2013 · 4 comments
Closed

missing Complex expm1 and log1p #3141

stevengj opened this issue May 17, 2013 · 4 comments

Comments

@stevengj
Copy link
Member

The expm1 and log1p functions are not yet implemented for Complex types.

In principle, I think these are straightforward: use a Taylor expansion for small arguments z (e.g. it is cheapest to check whether |real(z)|+|imag(z)| is small), and explicit function exp/log calls otherwise. The only annoyance is that you have to change the "small" cutoff and the order of the Taylor series depending upon the precision. For Float64 and Float32 this is simple, but for BigFloat matters are hairier.

@bsxfan
Copy link

bsxfan commented Jun 8, 2013

Bump. The absence of these functions breaks complex step differentiation of code that uses these functions.

@stevengj
Copy link
Member Author

Now that #6539 is merged (thanks to @simonbyrne), we only need a log1p function. There are a couple of tricks to implement this accurately that should work for complex values, I think (though this should be checked). Either:

log1p(x) = 2*atanh(x/(x+2))

or (due to Kahan, apparently)

function log1p(x)
    u = 1+x
    u == 1 ? x : log(u)*x/(u-1)
end

though some care is required in the latter version to ensure type stability (e.g. for x::Complex{Int}).

@stevengj
Copy link
Member Author

On my machine, the atanh version above is slightly faster for complex x. However, the atanh version is wrong for x == -2 + 0im, and is inaccurate near -2.

Some care is required with the branch cuts, in both versions, e.g. to have the right sign of zero along the negative real axis.

@stevengj
Copy link
Member Author

Actually, both versions are inaccurate near x == -2. Grrr.

stevengj added a commit to stevengj/julia that referenced this issue May 21, 2014
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

2 participants