import sympy


def replace_heaviside(formula):
    """Set Heaviside(0) = 0

    Differentiating sympy Min and Max is giving Heaviside:
    Heaviside(x) = 0 if x < 0 and 1 if x > 0, but
    Heaviside(0) needs to be defined by user.

    We set Heaviside(0) to 0 because in general there is no sensitivity.  This
    done by setting the second argument to zero.
    """
    if not isinstance(formula, sympy.Expr):
        return formula
    w = sympy.Wild("w")
    return formula.replace(sympy.Heaviside(w), sympy.Heaviside(w, 0))