def cubic_hermite_spline(x, p0, m0, p1, m1):
    """The third order polynomial p(x) with p(0)=p0, p'(0)=m0, p(1)=p1, p'(1)=m1."""
    a3 = m0 + m1 + p0 + p0 - p1 - p1
    a2 =  p1 - a3 - m0 - p0
    return p0 + x * (m0 + x * (a2 + x * a3))