Repository: sympy/sympy
File: sympy/concrete/summations.py (Python)

Code before:
        return -S.Pi * sum(residues)

    rational_function_symmetry = get_function_symmetry(numer, denom)
    if not ('even' == rational_function_symmetry):
        #for odd function flip the limit and negate
        #limit (-oo, a) is flipped to (-a, oo) and the answer is negated
        if ('odd' == rational_function_symmetry):
            if a is S.NegativeInfinity and b.is_finite:
                res = eval_sum_residue(f, (i, -b, S.Infinity))
                if res is not None:
                    return -res

        # Try shifting summation and check if the summand can be made
        # and even function from the origin.
        # Sum(f(n), (n, a, b)) => Sum(f(n + s), (n, a - s, b - s))
        shift = get_shift(denom)

        if not shift.is_Integer:
            return None
        if shift == 0:
            return None

        numer = numer.shift(shift)
        denom = denom.shift(shift)

        if not ('even' == get_function_symmetry(numer, denom)):
            return None

        if alternating:
            f = S.NegativeOne**i * (S.NegativeOne**shift * numer.as_expr() / denom.as_expr())
        else:
            f = numer.as_expr() / denom.as_expr()
        return eval_sum_residue(f, (i, a-shift, b-shift))
    elif ('even' == rational_function_symmetry):
        #for even function flip the limit
        #limit (-oo, a) is flipped to (-a, oo)
        if a is S.NegativeInfinity and b.is_finite:
            res = eval_sum_residue(f, (i, -b, S.Infinity))
            if res is not None:
                return res


    poles = get_poles(denom)
    if poles is None:
        return None
    int_roots, nonint_roots = poles

    if int_roots:
        int_roots = [int(root) for root in int_roots]
        int_roots_max = max(int_roots)
        int_roots_min = min(int_roots)

Review comment (suggestion):
This is calling the function again.

Also these conditions read strangely with
```
if 'even' == ...:
```
It is usually more natural to write
```
if ... == 'even':
```

Code after:
                f = S.NegativeOne**i * (S.NegativeOne**shift * numer.as_expr() / denom.as_expr())
            else:
                f = numer.as_expr() / denom.as_expr()
            return eval_sum_residue(f, (i, a-shift, b-shift))
        elif not both_inf:
            return None  # can't make a shift that keeps limits integer

    if both_inf:  # even or not
        poles = get_poles(denom)
        if poles is None:
            return None
        int_roots, nonint_roots = poles
        if int_roots:
            return None

        return -S.Pi * sum(residues(numer, denom, alternating, nonint_roots))

    # handle even function with semi-infinite limits

    if a is S.NegativeInfinity:
        # this is ok for an even function and will be necessary
        # so the extraneous roots can be handled properly below
        a, b = -b, -a

    assert a.is_Integer and b is S.Infinity  # even function with limits (k, oo)

    poles = get_poles(denom)
    if poles is None:
        return None
    int_roots, nonint_roots = poles

    if int_roots:
        int_roots_max = max(int_roots)
        int_roots_min = min(int_roots)
        # Integer valued poles must be next to each other
        # and also symmetric from origin (because the function is even)
        if not len(int_roots) == int_roots_max - int_roots_min + 1:
            return None

        # Check whether the summation indices contain poles
        if a <= max(int_roots):
            return None

    full_sum = -S.Pi * sum(residues(numer, denom, alternating, int_roots + nonint_roots))

    if not int_roots:
        # Compute Sum(f, (i, 0, oo)) by adding a extraneous evaluation
        # at the origin.
        half_sum = (full_sum + f.xreplace({i: 0})) / 2

        # Add and subtract extraneous evaluations