human
I wrote the below code

    distances = numpy.asarray(distances)
    M = numpy.zeros_like(distances)
    indices = numpy.array([leaf.value.index for leaf in leaves(tree)])
    distances = distances[(indices[numpy.newaxis, :], indices[:, numpy.newaxis])]
    distances = numpy.ascontiguousarray(distances)
    def argmin_ordered_xpypZ(x, y, Z, sorter_x=None, sorter_y=None):
        C = numpy.min(Z)
        if (sorter_x is None):
            sorter_x = range(len(x))
            ordered_x = x
        else:
            ordered_x = x[sorter_x]
        if (sorter_y is None):
            sorter_y = range(len(y))
            ordered_y = y
        else:
            ordered_y = y[sorter_y]
        y0 = ordered_y[0]
        best_val = numpy.inf
        (best_i, best_j) = (0, 0)
        y0pC = (y0 + C)
        for (i, x) in zip(sorter_x, ordered_x):
            if ((x + y0pC) >= best_val):
                break
            xpC = (x + C)
            for (j, y) in zip(sorter_y, ordered_y):
                if ((xpC + y) >= best_val):
                    break
                val = ((x + y) + Z[(i, j)])
                if (val < best_val):
                    (best_val, best_i, best_j) = (val, i, j)
        return (best_i, best_j)
    def argmin_xpypZ(x, y, Z):
        (_, h) = Z.shape
        A = (Z + numpy.reshape(x, ((-1), 1)))
        A += numpy.reshape(y, (1, (-1)))
        i = numpy.argmin(A)
        return ((i // h), (i % h))
    def optimal_ordering(tree, M, ordering):
        if tree.is_leaf:
            M[(tree.value.first, tree.value.first)] = 0.0
        else:
            (left, right) = (tree.left, tree.right)
            if (not left.is_leaf):
                V_ll = range(*left.left.value.range)
                V_lr = range(*left.right.value.range)
                u_iter = chain(((u, V_lr) for u in V_ll), ((u, V_ll) for u in V_lr))
            else:
                V_lr = range(*left.value.range)
                u_iter = ((u, V_lr) for u in V_lr)
            u_iter = list(u_iter)
            assert ([u for (u, _) in u_iter] ==...

What's a good function header?

Here's a good function header?
assistant
#Here's a good function header.

def optimal_leaf_ordering(tree, distances, progress_callback=None):