def binop(op, left, right, name=None, doc=None):
    """Define a function which applies a binary operator to the results of the two operand
    functions `left` and `right`.

    The name and docstring of the newly created function can be given through the `name` and
    `doc` arguments.
    """
    def binop_func(*args, **kwargs):
        return op(left(*args, **kwargs), right(*args, **kwargs))

    if not name:
        name = "binop({}, {}, {})".format(op.__name__, left.__name__, right.__name__)
    binop_func.__name__ = name
    binop_func.__doc__ = doc
    return binop_func