human
Complete this python program:
def binary_operator(op):
assistant
#Here is the Python code you requested.

    """Factory function for making binary operator methods on a Filter subclass.
    Returns a function "binary_operator" suitable for implementing functions
    like __and__ or __or__.
    """
    commuted_method_getter = attrgetter(method_name_for_op(op, commute=True))
    def binary_operator(self, other):
        if isinstance(self, NumericalExpression):
            (self_expr, other_expr, new_inputs) = self.build_binary_op(op, other)
            return NumExprFilter.create('({left})    {op}    ({right})'.format(left=self_expr, op=op, right=other_expr), new_inputs)
        elif isinstance(other, NumericalExpression):
            return commuted_method_getter(other)(self)
        elif isinstance(other, Term):
            if (other.dtype != bool_dtype):
                raise BadBinaryOperator(op, self, other)
            if (self is other):
                return NumExprFilter.create('x_0    {op}    x_0'.format(op=op), (self,))
            return NumExprFilter.create('x_0    {op}    x_1'.format(op=op), (self, other))
        elif isinstance(other, int):
            return NumExprFilter.create('x_0    {op}    {constant}'.format(op=op, constant=int(other)), binds=(self,))
        raise BadBinaryOperator(op, self, other)
    binary_operator.__doc__ = ("Binary    Operator:    '%s'" % op)
    return binary_operator