def update_hull(hull,newx,newhx,newhpx,domain,isDomainFinite):
    """update_hull: update the hull with a new function evaluation

    Input:
       hull            - the current hull (see setup_hull for a definition)
       newx            - a new abcissa
       newhx           - h(newx)
       newhpx          - hp(newx)
       domain          - [.,.] upper and lower limit to the domain
       isDomainFinite  - [.,.] is there a lower/upper limit to the domain?

    Output:
       newhull

    History:
       2009-05-21 - Written - Bovy (NYU)
    """
    #BOVY: Perhaps add a check that newx is sufficiently far from any existing point
    #Find where newx fits in with the other xs
    if newx > hull[1][-1]:
        newxs= sc.append(hull[1],newx)
        newhxs= sc.append(hull[2],newhx)
        newhpxs= sc.append(hull[3],newhpx)
        #new z
        newz= ( newhx - hull[2][-1] - newx*newhpx + hull[1][-1]*hull[3][-1])/( hull[3][-1] - newhpx)
        newzs= sc.append(hull[4],newz)
        #New hu
        newhu= hull[3][-1]*(newz-hull[1][-1]) + hull[2][-1]
        newhus= sc.append(hull[6],newhu)
    else:
        indx= 0
        while newx > hull[1][indx]:
            indx=indx+1
        newxs= sc.insert(hull[1],indx,newx)
        newhxs= sc.insert(hull[2],indx,newhx)
        newhpxs= sc.insert(hull[3],indx,newhpx)
        #Replace old z with new zs
        if newx < hull[1][0]:
            newz= (hull[2][0]-newhx-hull[1][0]*hull[3][0]+newx*newhpx)/(newhpx-hull[3][0])
            newzs= sc.insert(hull[4],0,newz)
            #Also add the new hu
            newhu= newhpx*(newz-newx)+newhx
            newhus= sc.insert(hull[6],0,newhu)
        else:
            newz1= (newhx-hull[2][indx-1] - newx*newhpx+hull[1][indx-1]*hull[3][indx-1])/(hull[3][indx-1]-newhpx)
            newz2= (hull[2][indx]-newhx - hull[1][indx]*hull[3][indx]+newx*newhpx)/(newhpx-hull[3][indx])
            #Insert newz1 and replace z_old
            newzs= sc.insert(hull[4],indx-1,newz1)
            newzs[indx]= newz2
            #Update the hus
            newhu1= hull[3][indx-1]*(newz1-hull[1][indx-1])+hull[2][indx-1]
            newhu2= newhpx*(newz2-newx)+newhx
            newhus= sc.insert(hull[6],indx-1,newhu1)
            newhus[indx]= newhu2
    #Recalculate the cumulative sum
    nx= len(newxs)
    newscum= sc.zeros(nx-1)
    if isDomainFinite[0]:
        newscum[0]= 1./newhpxs[0]*(m.exp(newhus[0])-m.exp(
            newhpxs[0]*(domain[0]-newxs[0])+newhxs[0]))
    else:
        newscum[0]= 1./newhpxs[0]*m.exp(newhus[0])
    if nx > 2:
        for jj in range(nx-2):
            if newhpxs[jj+1] == 0.:
                newscum[jj+1]= (newzs[jj+1]-newzs[jj])*m.exp(newhxs[jj+1])
            else:
                newscum[jj+1]=1./newhpxs[jj+1]*(m.exp(newhus[jj+1])-m.exp(newhus[jj]))
    if isDomainFinite[1]:
        newcu=1./newhpxs[nx-1]*(m.exp(newhpxs[nx-1]*(
            domain[1]-newxs[nx-1])+newhxs[nx-1]) - m.exp(newhus[nx-2]))
    else:
        newcu=- 1./newhpxs[nx-1]*m.exp(newhus[nx-2])
    newcu= newcu+sc.sum(newscum)
    newscum= sc.cumsum(newscum)/newcu
    newhull=[]
    newhull.append(newcu)
    newhull.append(newxs)
    newhull.append(newhxs)
    newhull.append(newhpxs)
    newhull.append(newzs)
    newhull.append(newscum)
    newhull.append(newhus)
    return newhull
update_hull: update the hull with a new function evaluation

    Input:
       hull            - the current hull (see setup_hull for a definition)
       newx            - a new abcissa
       newhx           - h(newx)
       newhpx          - hp(newx)
       domain          - [.,.] upper and lower limit to the domain
       isDomainFinite  - [.,.] is there a lower/upper limit to the domain?

    Output:
       newhull

    History:
       2009-05-21 - Written - Bovy (NYU)