Add more convenience math functions and all tests pass

This PR fixed the build error in #159 and removed the code that might conflict with #161.

Two lessons learned:
1. Make sure to test again every time after rebasing.
2. Keep the codes in the branch that depends on it and nowhere else.