Separates collection of ranges from the tracing

The collection of summation and integration ranges in the
trace_over_dummies function has been isolated into a separate function
named get_sum_int_ranges. This refactorization could be helpful for the
pretty printing function for the many-body expression.