import math


def transmon_perturbative(tmax, omega_q, eta, g):
    """Produce energies and cuplings of the transmon perturbatively
    
    Uses an anharmonic approximation of the transmon to get the energies

    Args:
        tmax (int): maximum number of transmon levels
        omega_q (float): qubit frequency, eta: transmon anharmonicity (defined
            positive).
        g (float): coupling normalization. Value of the coupling between levels
            0 and 1.
    """
    qubit_energy_list = [omega_q*q -
                          q*(q-1)/2*eta -
                          q*(q-1)*(q-2)/4*eta**2/omega_q
                          for q in range(tmax)]
    g_list = [g*math.sqrt(q+1)*(1-q/2*eta/omega_q) for q in range(tmax-1)]
    
    #qubit_energy_list[q] is transmon energy for level 'q'
    #g_list[q] is transmon charge matrix element between levels 'q+1' and 'q'
    return [qubit_energy_list, g_list]