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

Code before:
            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 a.is_Integer or b.is_Integer:
            return None

    if a is S.NegativeInfinity and b is not S.Infinity:
        a, b = -b, -a

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

    if (a, b) == (S.NegativeInfinity, S.Infinity):
        if int_roots:
            return None

        residue_factor = get_residue_factor(numer, denom, alternating)
        residues = [residue(residue_factor, z, root) for root in nonint_roots]
        return -S.Pi * sum(residues)

    assert a.is_Integer and b is S.Infinity

    if int_roots:
        int_roots = [int(root) for root in 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

    residue_factor = get_residue_factor(numer, denom, alternating)
    residues = [residue(residue_factor, z, root) for root in int_roots + nonint_roots]
    full_sum = -S.Pi * sum(residues)

    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
        extraneous_neg = [f.xreplace({i: i0}) for i0 in range(int(a), 0)]

Review comment (suggestion):
```suggestion
    if a is S.NegativeInfinity:
        a, b = -b, -a
    assert a.is_Integer and b is S.Infinity  # and the function is even
```

Code after:
            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
        extraneous_neg = [f.xreplace({i: i0}) for i0 in range(int(a), 0)]