Non-numba optimizations collected together

This is the rest of the non-numba changes, along with some numba development test scripts. Just as with the Newton's method change, you can expect some numeric discrepancies from a few changes like a different matrix multiplication order and similar changes.

The numba-specific changes have been appended in another branch, and we'll create a PR for them once these are merged.
numba