'Perform substitutions over non-dummy variables
of an expression with limits.  Also, can be used
to specify point-evaluation of an abstract antiderivative.
Examples
>>> from sympy import Sum, oo
>>> from sympy.abc import s, n
>>> Sum(1/n**s, (n, 1, oo)).subs(s, 2)
Sum(n**(-2), (n, 1, oo))
>>> from sympy import Integral
>>> from sympy.abc import x, a
>>> Integral(a*x**2, x).subs(x, 4)
Integral(a*x**2, (x, 4))
See Also
variables : Lists the integration variables
transform : Perform mapping on the dummy variable for intgrals
change_index : Perform mapping on the sum and product dummy variables'

def _eval_subs(self, old, new):

    from sympy.core.function import AppliedUndef, UndefinedFunction
    (func, limits) = (self.function, list(self.limits))
    limits.reverse()
    if ((not isinstance(old, Symbol)) or old.free_symbols.intersection(self.free_symbols)):
        sub_into_func = True
        for (i, xab) in enumerate(limits):
            if ((1 == len(xab)) and (old == xab[0])):
                xab = (old, old)
            limits[i] = Tuple(xab[0], *[l._subs(old, new) for l in xab[1:]])
            if (len(xab[0].free_symbols.intersection(old.free_symbols)) != 0):
                sub_into_func = False
                break
        if (isinstance(old, AppliedUndef) or isinstance(old, UndefinedFunction)):
            sy2 = set(self.variables).intersection(set(new.atoms(Symbol)))
            sy1 = set(self.variables).intersection(set(old.args))
            if (not sy2.issubset(sy1)):
                raise ValueError('substitution    can    not    create    dummy    dependencies')
            sub_into_func = True
        if sub_into_func:
            func = func.subs(old, new)
    else:
        for (i, xab) in enumerate(limits):
            if (len(xab) == 3):
                limits[i] = Tuple(xab[0], *[l._subs(old, new) for l in xab[1:]])
                if (old == xab[0]):
                    break
    for (i, xab) in enumerate(limits):
        if ((len(xab) == 2) and (xab[0] - xab[1]).is_zero):
            limits[i] = Tuple(xab[0])
    limits.reverse()
    return self.func(func, *limits)
