Ejemplo n.º 1
0
def get_max_cheby_minus_x_phi_over_coprimes(x, q):

    phi_q, coprime_list = eul_totie(q)

    # cheby_mod_list will be list of list, 2D array
    cheby_mod_list = []

    # let's calculate cheby_lst_for_a mod(q) 1st
    for a in range(q):

        # only calculate when a and q is coprime, this is needed, because
        # only these choice will get something similar to x/phi_q
        if a in coprime_list:

            # we use the cheby_fun_q_a_integer_use_saved_von_mang() instead of the following function
            # to speed up calculation.
            # cheby_list_for_a =  cheby_fun_q_a_integer(x, q, a)                    # calculate von_mang every time.
            cheby_list_for_a = cheby_fun_q_a_integer_use_saved_von_mang(x, q, a)    # use cached von_mang

            tmp = deepcopy(cheby_list_for_a)
            cheby_mod_list.append(tmp)

    num_of_coprimes = len(coprime_list)

    cheby_minus_x_phi_max = []

    for i in range(x):

        # initialize largest for each a, in the follow, i is actual x in
        # analytic formula, we just need to do (i+1) because array count start from 0
        x_phi_q = float(i + 1)/phi_q
        largest = np.absolute(cheby_mod_list[0][i] - x_phi_q )

        # loop for 1<= a <= q, (a, q) = 1
        for a in range(num_of_coprimes):
            tmp = np.absolute(cheby_mod_list[a][i] - x_phi_q)
            if(tmp > largest):
                largest = tmp

        cheby_minus_x_phi_max.append(largest)

    return  cheby_minus_x_phi_max
Ejemplo n.º 2
0
def get_max_cheby_minus_x_phi_fast_simulation(x, q):

    print 'get_max_cheby_minus_x_phi use fast simulation. x = %d, q = %d'%(x, q)

    phi_q, coprime_list = eul_totie(q)

    a = 1
    cheby_list_for_a = cheby_fun_q_a_integer_use_saved_von_mang(x, q, a)

    cheby_minus_x_phi_max = []

    for i in range(x):

        # initialize largest for each a, in the follow, i is actual x in
        # analytic formula, we just need to do (i+1) because array count start from 0
        x_phi_q = float(i + 1)/phi_q
        largest = np.absolute(cheby_list_for_a[i] - x_phi_q )

        cheby_minus_x_phi_max.append(largest)

    return  cheby_minus_x_phi_max