Refactored the heuristic code and rewrote the second heuristic

I added helper functions with documentation , and optimised it a bit. I rewrote the second heuristic according to a code that @raoulb gave me. I would like this to be merged before https://github.com/sympy/sympy/pull/2247 and after https://github.com/sympy/sympy/pull/2282 . There are test failures, because I am not able to assert the infinitesimals due to some strange reason, however it works fine on my terminal.