Example #1
0
def plot_c_q_m():

    q_range = 500
    m_range = 20

    s = [m_range, q_range]

    c_q_m_2d = np.zeros(s, dtype = np.complex64)

    for m in range(1, m_range + 1):
        for q in range(1, q_range + 1):
            c_q_m = rama_sum_use_prim_unit_root(q, m)
            c_q_m_2d[m - 1][q - 1] = c_q_m

    plt.figure()
    t_range_list = range(1, q_range + 1)
    title_str = 'c_q_m, q_range %d'%(q_range)

    plot_one_list(np.asarray(c_q_m_2d[0]).real, title_str, t_range_list, 'b-*')
    # plot_one_list(np.asarray(c_q_m_2d[1]).real, title_str, t_range_list, 'c-*')
    # plot_one_list(np.asarray(c_q_m_2d[2]).real, title_str, t_range_list, 'y-*')
    # plot_one_list(np.asarray(c_q_m_2d[3]).real, title_str, t_range_list, 'k-*')
    plot_one_list(np.asarray(c_q_m_2d[19]).real, title_str, t_range_list, 'r-*')

    xlabel_str = 'blue: m=1, cyran: m=2, yellow: m=3, black, m=4, red: m=19'
    plt.xlabel(xlabel_str)
Example #2
0
def gaus_sum_for_principle_char_upto_n(N):

    gaus_sum_arr = [1]*N

    # start from 1, because dirichi_char_for_n() is not defined for 1
    for n in range(2, N + 1):

        # print 'n = ', n

        # get dirich_char_mat, which is a 2D matrix
        dirich_char_mat, phi_n, coprime_list, prim_char_stat_all = dirichi_char_for_n(n)

        # char_index = 0 will give principle char
        G_chi = gaus_sum_for_dirich_char_by_index(0, n, dirich_char_mat, phi_n)
        gaus_sum_arr[n - 1] = G_chi

    plt.figure()
    t_range_list = range(1, N+1)
    title_str = 'gaus_sum, for principle character N %d'%(N)

    plot_one_list(np.absolute(gaus_sum_arr), title_str, t_range_list, 'b-*')
    plot_one_list(np.asarray(gaus_sum_arr).real, title_str, t_range_list, 'c-*')
    plot_one_list(np.asarray(gaus_sum_arr).imag, title_str, t_range_list, 'y-*')
    xlabel_str = 'blue: abs, cyran: real, yellow: imag'

    plt.xlabel(xlabel_str)

    # need the round to int first, then astype(int)
    gaus_sum_principle_char = np.round(np.asarray(gaus_sum_arr).real).astype(int)

    print gaus_sum_principle_char

    return gaus_sum_principle_char
Example #3
0
def gaus_sum_for_N(N, more_verify = False):

    # get dirich_char_mat, which is a 2D matrix
    dirich_char_mat, phi_n, coprime_list, prim_char_stat_all = dirichi_char_for_n(N)

    gaus_sum_arr = [0]*phi_n

    # this is the theoretical result, absolute(G(1, chi)) = sqrt(N)
    gaus_sum_for_prim_char = np.sqrt(N)
    ALMOST_ZERO = 0.001
    gaus_sum_prim_char_cnt = 0

    # print np.asarray(dirich_char_mat)
    if(more_verify == True):
        verify_all_propertiers(dirich_char_mat, N, phi_n, coprime_list)

        # Note, in the following plot, 1st row skipped, so its gaus_sum is not correct.
        verify_poly_vinograd_gaus_sum(dirich_char_mat, N, phi_n, prim_char_stat_all)

    # number of row. Note: 1st row is principle
    for i in range(0, phi_n):
        G_chi = gaus_sum_for_dirich_char_by_index(i, N, dirich_char_mat, phi_n)
        gaus_sum_arr[i] = G_chi

        # For prim_char, its gaus_sum == sqrt(N), let's verify this
        diff = np.absolute(G_chi) - gaus_sum_for_prim_char
        if(np.absolute(diff) < ALMOST_ZERO):
            gaus_sum_prim_char_cnt += 1

    plt.figure()
    t_range_list = range(phi_n)
    title_str = 'gaus_sum, N %d, phi_N %d, gaus_sum_prim_char_cnt %d'%(N, phi_n, gaus_sum_prim_char_cnt)

    # for prim_char, gaus_sum shall be equal to sqrt(N)
    plot_one_list(np.absolute(gaus_sum_arr), title_str, t_range_list, 'b-*')
    plot_one_list(np.asarray(gaus_sum_arr).real, title_str, t_range_list, 'c-*')
    plot_one_list(np.asarray(gaus_sum_arr).imag, title_str, t_range_list, 'y-*')
    xlabel_str = 'sqrt(N): %f, blue: abs, cyran: real, yellow: imag'%(np.sqrt(N))
    plt.xlabel(xlabel_str)