moble/spherical_functions — pull request #6 by moble (2014-11-10 06:27:55+00:00)
Title: Eliminate overflow and spurious underflow; double speed of Wigner D; closes #5

...ses #5

By changing to an abs/angle representation of the complex numbers, I
was able to simultaneously double the speed of the code, while also
eliminating overflow and spurious underflows.

Whenever one complex component (Ra or Rb) of the quaternion is small
and we ask for far-off-diagonal elements of the D matrices, the naive
formulas can easily lead to overflow. However, by keeping more
careful track of the exponents of abs(Ra) and abs(Rb), I was able to
ensure that the exponents are all well behaved.

Miraculously, this also doubles the speed of the code -- at least for
everything up to ell=16. In fact, it's closer to a 2.3x speed up.
This new technique uses the cmath.polar and cmath.rect functions,
which enable me to simplify the computer's job.