def compute_cumulants(moments):
    """
    Compute the cumulants from the moments up to order 4
    """
    assert len(moments) >= 4, "You must have moments at least up to order 4."

    kappas = [0] * 4
    kappas[0] = moments[0]
    kappas[1] = moments[1] - moments[0] ** 2
    kappas[2] = moments[2] - 3 * moments[1] * moments[0] + 2 * moments[0] ** 3
    kappas[3] = (
        moments[3]
        - 4 * moments[2] * moments[0]
        - 3 * moments[1] ** 2
        + 12 * moments[1] * moments[0] ** 2
        - 6 * moments[0] ** 4
    )
    return kappas