'Represents the Heaviside function in the form of sign function.
The value of the second argument of Heaviside must specify Heaviside(0)
= 1/2 for rewritting as sign to be strictly equivalent.  For easier
usage, we also allow this rewriting when Heaviside(0) is undefined.
Examples
>>> from sympy import Heaviside, Symbol, sign
>>> x = Symbol(\'x\', real=True)
>>> Heaviside(x).rewrite(sign)
sign(x)/2 + 1/2
>>> Heaviside(x, 0).rewrite(sign)
Heaviside(x, 0)
>>> Heaviside(x - 2).rewrite(sign)
sign(x - 2)/2 + 1/2
>>> Heaviside(x**2 - 2*x + 1).rewrite(sign)
sign(x**2 - 2*x + 1)/2 + 1/2
>>> y = Symbol(\'y\')
>>> Heaviside(y).rewrite(sign)
Heaviside(y)
>>> Heaviside(y**2 - 2*y + 1).rewrite(sign)
Heaviside(y**2 - 2*y + 1)
See Also
sign'

def _eval_rewrite_as_sign(self, arg, H0=None):

    if arg.is_real:
        if ((H0 is None) or (H0 == S.Half)):
            return ((sign(arg) + 1) / 2)
