Skip to content

Conversation

stephentyrone
Copy link
Member

This PR sets up some basic testing, and adds implementations for the following ElementaryFunctions on Complex:

  • exp
  • expMinusOne
  • log
  • pow
  • root
  • sqrt

exp and expMinusOne are reasonably well tested. Additional testing is needed for the latter four. I also added stubs for all the other functions (which simply fatalError), except for the functions that can be defined by trivial symmetries. I expect to work through the remaining operations fairly quickly, but contributions are welcome and encouraged.

If you want to make contributions, I would prefer PRs that add only a single function (or its obvious counterparts, e.g. sin and cos could come together), plus testing, as I expect to subject all of these implementations to fairly careful scrutiny.

- Renamed scaled/unscaled to multiplied/divided
- Adopted new Real module name
- Adopted expMinusOne, log(onePlus:) names
Rebased on master, then cleaned up exp and expm1. New algorithm for expm1 that gives good componentwise accuracy as well as normwise. I _think_ that this is fundamentally new; I can't recall seeing it anywhere before, though it's simple enough that I expect someone has thought of it before.

Also beefed up testing for exp and expm1. Left sketches of log/pow/sqrt/root in place, though I'm still working on filling out the testing for those.
// exp((log(gfm) + log(9/8), π/4) = exp((log(gfm*9/8), π/4))
// = gfm*9/8 * (1/sqrt(2), 1/(sqrt(2))
let x = T.log(.greatestFiniteMagnitude) + T.log(9/8)
let huge = Complex<T>.expMinusOne(Complex(x, .pi/4))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in the testExp method, so it should be testing exp, not expMinusOne, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah. Cleaned it up for expMinusOne and copied it back for improvements =)

@stephentyrone
Copy link
Member Author

I've created a branch in the main Swift Numerics repo for further work on this, complex-elfns. If you'd like to contribute, please raise PRs against that branch.

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

Successfully merging this pull request may close these issues.

2 participants