'Rewrites a Singularity Function expression using Heavisides and DiracDeltas.'

def _eval_rewrite_as_Heaviside(self, *args):

    x = self.args[0]
    a = self.args[1]
    n = sympify(self.args[2])
    if (n == (-2)):
        return diff(Heaviside((x - a)), x.free_symbols.pop(), 2)
    if (n == (-1)):
        return diff(Heaviside((x - a)), x.free_symbols.pop(), 1)
    if n.is_nonnegative:
        return (((x - a) ** n) * Heaviside((x - a)))
