def generate_nth_order_R2g(states_tuple, times_tuple):
    order = len(states_tuple)
    if (order != len(times_tuple)):
        raise Exception('Wrong tuple/list length')
    a = states_tuple[0]
    b = states_tuple[(len(states_tuple) - 1)]
    tt = times_tuple[(len(times_tuple) - 1)]
    AL = Uged(a, t1)
    Amid = (Uedg(b, tt) * Ugde(b, (t3 + tt)))
    filL = 1
    filR = 1
    for k in range((len(times_tuple) - 1)):
        tau = times_tuple[k]
        s1 = states_tuple[k]
        s2 = states_tuple[(k + 1)]
        filL = ((filL * Uedg(s1, tau)) * Ugde(s2, tau))
        filR = ((Uedg(s2, tau) * Ugde(s1, tau)) * filR)
    A = (((AL * filL) * Amid) * filR)
    print(A)
    print(evaluate_cumulant(A, positive_times=(t1, tt, t3), leading_index=a, arrays=['gg']))
def generate_nth_order_R2g(states_tuple, times_tuple):
    order = len(states_tuple)
    if (order != len(times_tuple)):
        raise Exception('Wrong tuple/list length')
    a = states_tuple[0]
    b = states_tuple[(len(states_tuple) - 1)]
    tt = times_tuple[(len(times_tuple) - 1)]
    AL = Uged(a, t1)
    Amid = (Uedg(b, tt) * Ugde(b, (t3 + tt)))
    filL = 1
    filR = 1
    for k in range((len(times_tuple) - 1)):
        tau = times_tuple[k]
        s1 = states_tuple[k]
        s2 = states_tuple[(k + 1)]
        filL = ((filL * Uedg(s1, tau)) * Ugde(s2, tau))
        filR = ((Uedg(s2, tau) * Ugde(s1, tau)) * filR)
    A = (((AL * filL) * Amid) * filR)
    print(A)
    print(evaluate_cumulant(A, positive_times=(t1, tt, t3), leading_index=a, arrays=['gg']))