swift-numerics icon indicating copy to clipboard operation
swift-numerics copied to clipboard

Conform `Complex` to `ElementaryFunctions`

Open stephentyrone opened this issue 5 years ago • 5 comments

All of the usual ElementaryFunctions operations should be defined for Complex types. Implementation details may be found in Kahan's "Branch Cuts for Complex Elementary Functions; or Much Ado About Nothing's Sign Bit".

We can simplify the implementation somewhat for Swift complex numbers, because: (a) we do not need to worry about fenv flags (b) we do not need to bother with sign of zero/inf, because we're not trying to be precise with those cases (they do not pull their weight, complexity-wise).

stephentyrone avatar Jun 25 '19 00:06 stephentyrone

@stephentyrone, is there something holding this up?

NevinBR avatar Nov 12 '19 01:11 NevinBR

Finite number of hours in a day, plus some higher-priority projects to work on.

As a side note, I would advise against asking things like "is there something holding this up?" on an open-source repo. In my case, I just have a bunch of projects in flight, so any one of them doesn't have my full attention, so this is no big deal. But, people can have all sorts of life issues that could cause them to set something aside for a few weeks or months, which they may not want to talk about on a random public website. How are they supposed to answer this question? I guess they could talk in vague generalities, but they may not even want to do that, and the person asking the question is unlikely to find such an answer very satisfying.

I would suggest phrasing more like "Is there anything I can do to help with this feature?" in general.

stephentyrone avatar Nov 12 '19 13:11 stephentyrone

Adding a concrete schedule here: I'll make some time to wrap this up during (US) thanksgiving week, so it should be available before the end of the month.

stephentyrone avatar Nov 12 '19 14:11 stephentyrone

I would suggest phrasing more like "Is there anything I can do to help with this feature?" in general.

Thanks, for the feedback, that’s good advice.

I intended the question to be about the mathematical / computational side, as in, do we need to make any difficult decisions regarding tradeoffs when selecting specific formulas / algorithms for these functions, or would it be acceptable to drop in “textbook” implementations and then potentially refine them later for, eg. numerical stability.

NevinBR avatar Nov 12 '19 16:11 NevinBR

Ah. These are mostly fairly-straightforward.

The only real issue is that there are multiple "textbook" formulas for all of these, and we do need to take some care about:

  • ensuring that the branch cuts fall in the "right" place (Kahan's 1986 paper "Branch Cuts for Complex Elementary Functions" has good choices for all of these).
  • avoiding spurious overflow/underflow (this is a little bit trickier in a generic context than what Kahan deals with in his paper, but definitely isn't new research or anything).

I'm not going after last-bit rounding (or really even close to it) at this point. I will be leaving notes about what would need to change to enable it. The biggest pile of work is actually writing test cases, not the implementations themselves.

stephentyrone avatar Nov 12 '19 16:11 stephentyrone

This has been done for a while now.

stephentyrone avatar Apr 28 '23 17:04 stephentyrone