<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def hard_limit(self, yidx, ymin, ymax, min_set=None, max_set=None):
 """Set hard limits for algebraic variables and reset the equation mismatches :param yidx: algebraic variable indices :param ymin: lower limit to check for :param ymax: upper limit to check for :param min_set: optional lower limit to set (``ymin`` as default) :param max_set: optional upper limit to set (``ymax`` as default) :type yidx: list, matrix :type ymin: matrix, int, float, list :type ymax: matrix, int, float, list :type min_set: matrix :type max_set: matrix :return: None """

        yidx = matrix(yidx)
        yval = self.y[yidx]
        ny = len(yidx)

        if isinstance(ymin, (int, float, list)):
            ymin = matrix(ymin, (ny, 1), 'd')
        if isinstance(ymax, (int, float, list)):
            ymax = matrix(ymax, (ny, 1), 'd')

        if not min_set:
            min_set = ymin
        elif isinstance(min_set, (int, float, list)):
            min_set = matrix(min_set, (ny, 1), 'd')

        if not max_set:
            max_set = ymax
        elif isinstance(max_set, (int, float, list)):
            max_set = matrix(max_set, (ny, 1), 'd')

        above = ageb(yval, ymax)
        below = aleb(yval, ymin)

        above_idx = index(above, 1.0)
        below_idx = index(below, 1.0)

        above_yidx = yidx[above_idx]
        below_yidx = yidx[below_idx]
        idx = list(above_idx) + list(below_idx)

        if len(above_yidx) > 0:
            self.y[above_yidx] = max_set[above_idx]
            self.zymax[above_yidx] = 0

        if len(below_yidx) > 0:
            self.y[below_yidx] = min_set[below_idx]
            self.zymin[below_yidx] = 0

        if len(idx):
            self.g[yidx[idx]] = 0
            self.ac_reset = True