Optimizing Python code for fast math