'Evaluates the function along the sym in a given interval ab'

def _eval_interval(self, sym, a, b):

    if ((a is None) or (b is None)):
        return piecewise_fold(super(Piecewise, self)._eval_interval(sym, a, b))
    mul = 1
    if ((a == b) == True):
        return S.Zero
    elif ((a > b) == True):
        (a, b, mul) = (b, a, (-1))
    elif ((a <= b) != True):
        newargs = []
        for (e, c) in self.args:
            intervals = self._sort_expr_cond(sym, S.NegativeInfinity, S.Infinity, c)
            values = []
            for (lower, upper, expr) in intervals:
                if ((a < lower) == True):
                    mid = lower
                    rep = b
                    val = e._eval_interval(sym, mid, b)
                    val += self._eval_interval(sym, a, mid)
                elif ((a > upper) == True):
                    mid = upper
                    rep = b
                    val = e._eval_interval(sym, mid, b)
                    val += self._eval_interval(sym, a, mid)
                elif (((a >= lower) == True) and ((a <= upper) == True)):
                    rep = b
                    val = e._eval_interval(sym, a, b)
                elif ((b < lower) == True):
                    mid = lower
                    rep = a
                    val = e._eval_interval(sym, a, mid)
                    val += self._eval_interval(sym, mid, b)
                elif ((b > upper) == True):
                    mid = upper
                    rep = a
                    val = e._eval_interval(sym, a, mid)
                    val += self._eval_interval(sym, mid, b)
                elif (((b >= lower) == True) and ((b <= upper) == True)):
                    rep = a
                    val = e._eval_interval(sym, a, b)
                else:
                    raise NotImplementedError('The    evaluation    of    a    Piecewise    interval    when    both    the    lower\n                                                                                                                and    the    upper    limit    are    symbolic    is    not    yet    implemented.')
                values.append(val)
            if (len(set(values)) == 1):
                try:
                    c = c.subs(sym, rep)
                except AttributeError:
                    pass
                e = values[0]
                newargs.append((e, c))
            else:
                for i in range(len(values)):
                    newargs.append((values[i], (((c == True) and (i == (len(values) - 1))) or And((rep >= intervals[i][0]), (rep <= intervals[i][1])))))
        return self.func(*newargs)
    int_expr = self._sort_expr_cond(sym, a, b)
    ret_fun = 0
    for (int_a, int_b, expr) in int_expr:
        if isinstance(expr, Piecewise):
            ret_fun += piecewise_fold(super(Piecewise, expr)._eval_interval(sym, Max(a, int_a), Min(b, int_b)))
        else:
            ret_fun += expr._eval_interval(sym, Max(a, int_a), Min(b, int_b))
    return (mul * ret_fun)
