def derivatives(dim, order):
    """Return all the orders of a multidimensional derivative."""
    if dim == 1:
        return [(order, )]

    out = []
    for i in range(order + 1):
        out += [(i, ) + j for j in derivatives(dim - 1, order - i)]
    return out