def merge_moments(m_a, m_a2, m_a3, m_a4, n_a, m_b, m_b2, m_b3, m_b4, n_b):
    '''
    Merge moments of two samples A and B.
    parameters are 
    m_a, ..., m_a4 = first through fourth moment of sample A
    n_a = size of sample A
    m_b, ..., m_b4 = first through fourth moment of sample B
    n_b = size of sample B
    '''
    delta = m_b - m_a
    delta_2 = delta * delta
    delta_3 = delta * delta_2
    delta_4 = delta * delta_3
    n_x = n_a + n_b
    m_x = m_a + delta * n_b / n_x
    m_x2 = m_a2 + m_b2 + delta_2 * n_a * n_b / n_x
    m_x3 = m_a3 + m_b3 + delta_3 * n_a * n_b * (n_a - n_b) + 3 * delta * (n_a * m_2b - n_b * m_2a) / n_x
    m_x4 = (m_a4 + m_b4 + delta_4 * (n_a * n_b * (n_a * n_a - n_a * n_b + n_b * n_b)) / (n_x ** 3) +
            6 * delta_2 * (n_a * n_a * m_b2 + n_b * n_b * m_a2) / (n_x ** 2) +
            4 * delta * (n_a * m_b3 - n_b * m_a3) / n_x )
    return m_x, m_x2, m_x3, m_x4, n_x
Merge moments of two samples A and B.
    parameters are 
    m_a, ..., m_a4 = first through fourth moment of sample A
    n_a = size of sample A
    m_b, ..., m_b4 = first through fourth moment of sample B
    n_b = size of sample B