Is there a way to refactor this to be more concise?  Large if-else branches like this often cause problems in the future.  They are very difficult to change in the future without generating bugs that are difficult to track down.

Also, are you sure that there isn't already functionality somewhere in SymPy that could solve this problem for you?  I wonder if something like a sign function might be a good place for this.