コード例 #1
0
ファイル: mert_unit_tests.py プロジェクト: glogou/tmp_testing
def unit_test_sequence():
    # Do some unit test
    unit_test_get_primes_to_try()
    unit_test_is_this_end_of_tree_leaf()
    unit_test_prime_product_count()

    # generate primes up to target_num,
    target_num = 70
    primes = get_prime_list(target_num)
    print 'num of primes %d'%(len(primes))

    # find the number of prime product with specific factors, and
    # do some cross testing
    all_2_factors_choices = count_number_prime_product_with_2factors(primes, target_num)
    all_3_factors_choices = count_number_prime_product_with_3factors(primes, target_num)
    all_of_1_factors, all_of_2_factors, all_of_3_factors, all_of_4_factors = \
        count_number_prime_product_with_4factors(primes, target_num)

    # verify those result are correct
    assert(all_2_factors_choices == all_of_2_factors)
    assert(all_3_factors_choices == all_of_3_factors)

    begin_list = [1]
    factors_his = [0]* MAX_NUM_FACTORS
    primes = get_prime_list(target_num)
    factors_his, factors_his_cur_n_down = count_number_prime_product_recursive(begin_list, primes, target_num, factors_his)
    print target_num, factors_his, factors_his_cur_n_down

    all_1_factors_comm, all_2_factors_comm, all_3_factors_comm, all_4_factors_comm = get_select_factors(factors_his)

    assert(all_2_factors_comm == all_of_2_factors)
    assert(all_3_factors_comm == all_of_3_factors)
    assert(all_4_factors_comm == all_of_4_factors)
コード例 #2
0
ファイル: selb_formu.py プロジェクト: glogou/tmp_testing
def selb_formu_list_up_to_x(x, format, sample_rate=1):

    selb_sum_list = []
    sum_1st_part_list = []
    sum_2nd_part_list = []

    # calculate prime_list,  von_mang list, cheby_list out side of loop,
    #  so that we do not need to calculate it every time.in the loop
    if(format == 1):
        primes_list = get_prime_list(x)

    if ((format == 2) or (format == 3)):
        von_mang_list = von_mang_upto(x)

    if (format == 3):
        cheby_list = cheby_fun_integer(x)

    if(format == 4):
        primes_list = get_prime_list(x)
        primes_and_log_2d_list = get_primes_and_log_2d_list(primes_list)
        print primes_and_log_2d_list

    print 'Before loop, format = ', format

    count = 0

    for n in range(2, x+1, sample_rate):
        # format 1, log only
        if(format == 1):
            selb_sum, sum_1st_part, sum_2nd_part = selb_formu_for_one_x_log_only(n, primes_list)

        # format 2, use von_mang
        if(format == 2):
            # print n
            selb_sum, sum_1st_part, sum_2nd_part = selb_formu_for_one_x_using_von_mang(n, von_mang_list )

        # format 3: use cheby_fun
        if(format == 3):
            selb_sum, sum_1st_part, sum_2nd_part = selb_formu_for_one_x_using_cheby(n, von_mang_list, cheby_list )

        # format 4, log only, formula is same as 1, with some speed optimization
        if(format == 4):
            selb_sum, sum_1st_part, sum_2nd_part = selb_formu_for_one_x_log_only_optimized(n, primes_and_log_2d_list)

        # show some progress, print every 100 steps,
        count += 1
        if((count%100) == 0):
            print 'Total = ', x, 'current n = ', n

        # Save results
        selb_sum_list.append(selb_sum)
        sum_1st_part_list.append(sum_1st_part)
        sum_2nd_part_list.append(sum_2nd_part)

    return selb_sum_list, sum_1st_part_list, sum_2nd_part_list
コード例 #3
0
ファイル: mert_unit_tests.py プロジェクト: glogou/tmp_testing
def unit_test_is_this_end_of_tree_leaf():

    begin_list = [1, 2]
    primes=[2]
    target_num = 2
    result_0 = is_this_end_of_tree_leaf(begin_list, primes, target_num)
    assert(result_0 == g_END_LEAF_WITH_UNIQ_FACTORIZATION)
    print result_0

    begin_list = [1]
    primes=[2, 3, 5]
    target_num = 6
    result_1 = is_this_end_of_tree_leaf(begin_list, primes, target_num)
    assert(result_1 == g_NOT_END_OF_LEAF)
    print result_1

    begin_list = [1, 2]
    primes=[2, 3, 5]
    target_num = 6
    result_2 = is_this_end_of_tree_leaf(begin_list, primes, target_num)
    assert(result_2 == g_NOT_END_OF_LEAF)
    print result_2

    begin_list = [1, 2, 3]
    primes=[2, 3, 5]
    target_num = 6
    result_3 = is_this_end_of_tree_leaf(begin_list, primes, target_num)
    assert(result_3 == g_END_LEAF_WITH_UNIQ_FACTORIZATION)
    print result_3

    begin_list = [1, 3]
    primes= get_prime_list(28)
    target_num = 28
    result_4 = is_this_end_of_tree_leaf(begin_list, primes, target_num)
    assert(result_4 == g_NOT_END_OF_LEAF)
    print result_4

    begin_list = [1, 3, 5]
    primes= get_prime_list(28)
    target_num = 28
    result_5 = is_this_end_of_tree_leaf(begin_list, primes, target_num)
    assert(result_5 == g_END_LEAF_NOT_UNIQ_FACTORIZATION)
    print result_5

    begin_list = [1, 3, 7]
    primes= get_prime_list(28)
    target_num = 28
    result_6 = is_this_end_of_tree_leaf(begin_list, primes, target_num)
    assert(result_6 == g_END_LEAF_NOT_UNIQ_FACTORIZATION)
    print result_6
コード例 #4
0
ファイル: mert_theo.py プロジェクト: glogou/tmp_testing
def mert_theo_list_up_to_x(x, format):

    mert_theo_list = [0]

    # calculate prime_list,  von_mang list,  out side of loop,
    #  so that we do not need to calculate it every time.in the loop
    if (format == 2):
        von_mang_list = von_mang_upto(x)
    else:
        primes_list = get_prime_list(x)

    print 'Before loop'

    for n in range(2, x+1):

        # format 1, log only
        if(format == 1):
            mert_item =  mert_theo_1_log_x(n, primes_list)

        # format 2, use von_mang
        if(format == 2):
            mert_item = mert_theo_1_using_von_mang(n, von_mang_list )

        # format 3:
        if(format == 3):
            mert_item = mert_theo_2_sum_1_p(n, primes_list)

        # format 4:
        if(format == 4):
            mert_item =mert_theo_3_prod_1_1_p_inv(n, primes_list)

        mert_theo_list.append(mert_item)

    return mert_theo_list
コード例 #5
0
ファイル: get_factor_list.py プロジェクト: glogou/tmp_testing
def get_factor_list(max_num, option = g_TRUE_PRIME):

    # liouvi_power_prime_dict will be only filled up for g_LIOUVI_FACTOR option
    liouvi_power_prime_dict = {}

    if (option == g_TRUE_PRIME):
        print 'get_factor_list, use real prime'
        factor_list = get_prime_list(max_num)

    elif (option == g_PRIME_XLOGX_NON_PRECISE):
        print 'get_factor_list, use xlogx_up_to_n non-precise version'
        factor_list = xlogx_up_to_n(max_num, False)
        print factor_list

    elif (option == g_PRIME_XLOGX_PRECISE):
        print 'get_factor_list, use xlogx_up_to_n, precise version'
        factor_list = xlogx_up_to_n(max_num, True)
        print factor_list

    elif (option == g_LIOUVI_FACTOR):
        print 'get_factor_list, use get_liouvi_factor_list'

        # Sort entire factor list, because our program depends on sorted list.
        liouvi_factor_list_option = 1
        factor_list, liouvi_power_prime_dict = get_liouvi_factor_list(max_num, liouvi_factor_list_option)

        # print 'factor_list: ', factor_list

    else:
        print 'NOT supported option %d'%(option)
        sys.exit(0)

    return factor_list, liouvi_power_prime_dict
コード例 #6
0
ファイル: von_mang.py プロジェクト: glogou/tmp_testing
def get_p_andd_pk_upto(n):

    primes = get_prime_list(n)

    # in case of n = 20,
    # list of primes and prime powers, 2, 3, 5, 7, 11, 13, 17, 4, 8, 16, 9
    p_and_pk_list = copy.deepcopy(primes)

    # in case of n = 20,
    # list of primes 2, 3, 5, 7, 11, 13, 17, 2, 2, 2, 3
    p_and_p_list = copy.deepcopy(primes)

    # in case of n = 20,
    # power_of_p_list 1, 1, 1, 1, 1, 1,  1, 2, 3, 4, 2
    power_of_p_list = [1]*len(primes)

    for p in primes:
        k = int(math.floor(math.log(n, p)))

        for i in range(2, k+1):
            p_power_i = int(round(math.pow(p, i)))
            p_and_pk_list.append(p_power_i)
            p_and_p_list.append(p)
            power_of_p_list.append(i)

    assert(len(p_and_pk_list) == len(p_and_p_list))
    assert(len(p_and_pk_list) == len(power_of_p_list))

    return p_and_pk_list, p_and_p_list, power_of_p_list
コード例 #7
0
ファイル: mert_unit_tests.py プロジェクト: glogou/tmp_testing
def unit_test_get_primes_to_try():

    target_num = 70

    # generate primes up to target_num, for example, up to 100
    primes = get_prime_list(target_num)

    begin_list = [1, 2, 3]
    result_1 = get_primes_to_try(begin_list, primes, target_num)
    print result_1

    begin_list = [1, 2, 5]
    result_2 = get_primes_to_try(begin_list, primes, target_num)
    print result_2

    begin_list = [1, 2, 5, 7]
    result_3 = get_primes_to_try(begin_list, primes, target_num)
    print result_3

    begin_list = [1, 2]
    primes=[2]
    target_num = 2
    result_4 = get_primes_to_try(begin_list, primes, target_num)
    print result_4

    begin_list = [1]
    primes=[2, 3, 5]
    target_num = 6
    result_5 = get_primes_to_try(begin_list, primes, target_num)
    print result_5
コード例 #8
0
ファイル: dirich_char.py プロジェクト: glogou/tmp_testing
def dirichi_char_for_n(n):

    prime_list = get_prime_list(n)
    factor_list = factor_a_number(n, prime_list)
    num_of_diff_primes = len(factor_list)

    # this will be a list of 2D matrix, each 2D matrix hold a dirich_char matrix for a prime
    dirich_char_mat_list =[]
    prim_char_stat_list = []

    # handle all prime factor
    for i in range(0, num_of_diff_primes):

        p = factor_list[i][0]
        l = factor_list[i][1]
        dirich_char_p_mat, phi_p_l, coprime_list, prim_char_stat = dirich_char_power_p(p, l)

        print 'p = ', p, ', l = ', l, np.asarray(dirich_char_p_mat).shape

        dirich_char_mat_list.append(dirich_char_p_mat)
        prim_char_stat_list.append(prim_char_stat)

        print prim_char_stat

    # form a product of all of above matrix
    tmp_mat = np.eye(1)

    for i in range(0, num_of_diff_primes):
        tmp_mat = dirich_char_mat_product(tmp_mat, dirich_char_mat_list[i])

    print 'n = ', n, ', matrix shape = ', np.asarray(tmp_mat).shape

    phi_p_n, coprime_list = eul_totie(n)

    # set initial default value for statistics count
    prim_char_stat_all = {}
    prim_char_stat_all['num_of_total_char'] = -1
    prim_char_stat_all['num_of_prim_char'] = -1
    prim_char_stat_all['num_of_non_prim_char'] = -1      # include principle char
    prim_char_stat_all['num_of_real_char'] = -1

    num_of_total_char_all = 1
    num_of_prim_char_all = 1
    num_of_prim_char_real = 1

    for i in range(0, num_of_diff_primes):

        num_of_total_char_all = num_of_total_char_all*prim_char_stat_list[i]['num_of_total_char']
        num_of_prim_char_all = num_of_prim_char_all*prim_char_stat_list[i]['num_of_prim_char']
        num_of_prim_char_real = num_of_prim_char_real*prim_char_stat_list[i]['num_of_real_char']

    prim_char_stat_all['num_of_total_char'] =  num_of_total_char_all
    prim_char_stat_all['num_of_prim_char'] = num_of_prim_char_all
    prim_char_stat_all['num_of_non_prim_char'] = num_of_total_char_all - num_of_prim_char_all
    prim_char_stat_all['num_of_real_char'] = num_of_prim_char_real

    print prim_char_stat_all

    return tmp_mat, phi_p_n, coprime_list, prim_char_stat_all
コード例 #9
0
ファイル: selb_siev.py プロジェクト: glogou/tmp_testing
def get_g_k_r_k(M_set, k_range, g_k_option):

    g_k_list = []
    r_k_list = []
    g_k_M_list = []

    M = len(M_set)

    show_g_k_option(g_k_option)

    # for GBC or twi_prim sequence, we need prime_list
    if (g_k_option == 5) or (g_k_option == 6):
        prime_list = get_prime_list(k_range)

    # For GBC, to calculate g(k), we need N
    if g_k_option == 5:
        N = k_range

    # For twi_prim, N = 2
    if g_k_option == 6:
        N = 2

    for k in range(1, k_range + 1):

        g_k_M = find_M_set_divided_by_k(M_set, k)

        if g_k_option == 1:
            g_k = 1 / float(k)

        if g_k_option == 2:
            g_k = 1 / float(k * k)

        if g_k_option == 3:
            g_k = 1 / np.sqrt(k)

        # this is NOT a multiplicative, we have it for testing purpose
        if g_k_option == 4:
            g_k = 2 / float(k)

        # GBC
        if g_k_option == 5:
            g_k = get_g_k_for_GBC_twi_prim(k, N, prime_list)

        # twi_prim
        if g_k_option == 6:
            g_k = get_g_k_for_GBC_twi_prim(k, 2, prime_list)

        r_k = g_k_M - g_k * M

        g_k_M_list.append(g_k_M)
        g_k_list.append(g_k)
        r_k_list.append(r_k)

    return g_k_M_list, g_k_list, r_k_list
コード例 #10
0
def unit_test_simple():
    tmp_1 = pi_k_x(1, 5)
    tmp_2 = pi_k_x(1, 100)
    tmp_2_compare = len(get_prime_list(100))

    tmp_3 = pi_k_x(1, 1000)
    tmp_3_compare = len(get_prime_list(1000))

    tmp_4 = pi_k_x(1, 10000)
    tmp_4_compare = len(get_prime_list(10000))

    tmp_5 = pi_k_x(2, 100)
    tmp_6 = pi_k_x(2, 1000)
    tmp_7 = pi_k_x(2, 10000)

    x = 100
    k = 10
    pi_k_x_arr = pi_k_x_list(x, k)

    print x, k, pi_k_x_arr
コード例 #11
0
ファイル: selb_siev.py プロジェクト: glogou/tmp_testing
def get_prime_num_count_in_M_set(M_set):

    largest = M_set[len(M_set) - 1]

    prime_list = get_prime_list(largest)

    prime_cnt = 0

    for m in M_set:
        if m in prime_list:
            prime_cnt += 1

    return prime_cnt
コード例 #12
0
def get_liouvi_factor_list(max_num, option = 1):

    prime_list = get_prime_list(max_num)

    liouvi_list = copy.deepcopy(prime_list)

    # create a dictionary, to hold additional information
    # for number such as p^2, p^2, ..., p^n
    # Dictionay format will be:
    # [4:[2, 2], 8:[2, 3], 16:[2, 4], 32:[2, 5], 9:[3, 2], 27:[3, 3], 81:[3, 4]]
    # where key will be p^2, and the value will be list of pair such as [2, 5] where 2 is basic prime factor
    # and 5 is the number of prime factors in 2^5

    liouvi_power_prime_dict={}

    for p in prime_list:
        # get max order of p^n which less than max_num
        max_order = math.log(max_num, p)

        # get integer
        max_order_int = int(math.floor(max_order))

        # if the max_order_int == 1, which means only p < max_num, p^2 > max_num
        # since p is already in prime_list, we do not need to add more
        if(max_order_int <= 1):
            continue

        else:
            print '%d'%(math.pow(p, max_order_int))

            # for any number p^n, we need to add p^2, p^3, ...p^n to the list,
            # because p is already in prime_list, we do not need to add it.
            # for example, p = 2, max_order_int = 4,
            # we need to add 2^2, 2^3, 2^4 sequences
            for i in range(2, max_order_int + 1):

                # we add 2^2, 2^3, 2^4 to the list
                p_power_i = int(math.pow(p, i))
                liouvi_list.append(p_power_i )

                # put value in liouvi_power_prime_dict
                liouvi_power_prime_dict[p_power_i] = [p, i]

    # defaulted, sorted
    if(option == 1):
        liouvi_list = sorted(liouvi_list)

    return liouvi_list, liouvi_power_prime_dict
コード例 #13
0
ファイル: eul_totie.py プロジェクト: glogou/tmp_testing
def unit_test_factor_number():

    max_num = 100000
    prime_list = get_prime_list(max_num)

    num = 6
    factor_list = factor_a_number(num, prime_list)
    print 'i = ', num, factor_list

    num=2*2*2*5*5*7*7
    factor_list = factor_a_number(num, prime_list)
    print 'i = ', num, factor_list

    for i in range(2, 10000):
        factor_list = factor_a_number(i, prime_list)
        print 'i = ', i, factor_list
コード例 #14
0
ファイル: selb_siev.py プロジェクト: glogou/tmp_testing
def get_num_count_in_M_set_not_divisible_by_prime_less_than_xi(M_set, xi):

    # need to be at least 2
    target_num = len(M_set)
    assert target_num >= 1

    prime_list = get_prime_list(xi)

    init_list = deepcopy(M_set)
    # print init_list

    j = 0

    # construct initial list. Initial list may include [1] at beginning, we skip it.
    if init_list[0] == 1:
        new_list = init_list[1:]
    else:
        new_list = init_list

    while 1:
        checkNum = prime_list[j]

        # show the progress of each iteration
        # print 'j = %5d checkNum %5d, new_list_len %5d'%(j, checkNum, new_list_len)

        new_list = erato_siev_one_round(new_list, checkNum)
        # print new_list
        j = j + 1

        if j == len(prime_list):
            break

    sift_left_cnt = len(new_list)

    print "number not_divisible_by_prime_less_than_xi: %d \n" % (sift_left_cnt)
    # print 'number not_divisible_by_prime_less_than_xi:', new_list, '\n'

    return sift_left_cnt
コード例 #15
0
def plot_primes_points_on_unit_circle(start, num_of_points, wrap_around_once = True):

    prime_max = 120000
    prime_list = get_prime_list(prime_max)

    prime_arr = prime_list[start:(start + num_of_points)]
    prime_arr = np.asarray(prime_arr)

    # NOT wrap around once
    if(wrap_around_once == False):
        prime_phase = 1j*prime_arr

    # Wrapped around once
    else:
        begin = prime_arr[0]
        end = prime_arr[num_of_points - 1]

        prime_wrap_around_once_arr = (prime_arr - begin)*(2*np.pi)/(end - begin)

        # print prime_wrap_around_once_arr
        prime_phase = 1j*prime_wrap_around_once_arr

    prime_data = np.exp(prime_phase)

    real_part = prime_data.real
    imag_part = prime_data.imag

    plt.figure()
    plt.plot(real_part, imag_part, 'k.')
    plt.grid(True)

    title_str = 'prime,  start %d, num_of_points = %d, wrap_around = %d'%(start, num_of_points, wrap_around_once)
    plt.title(title_str)

    plt.ylim((-1.2,1.2))
    plt.xlim((-1.2,1.2))
コード例 #16
0
ファイル: mert_unit_tests.py プロジェクト: glogou/tmp_testing
def unit_test_prime_product_count():

    # test 1, target number is 5
    # it will produce a sequence of factors: 1*2, 1*3, 1*5, 1 (in this order)
    begin_list = [1]
    factors_his = [0]* MAX_NUM_FACTORS
    target_num = 5
    primes = [2, 3, 5]
    factors_his, factors_his_cur_n_down = count_number_prime_product_recursive(begin_list, primes, target_num, factors_his)
    print target_num, factors_his, factors_his_cur_n_down

    all_1_factors_comm, all_2_factors_comm, all_3_factors_comm, all_4_factors_comm = get_select_factors(factors_his)
    # the following assertion is based on previous observations
    assert(all_1_factors_comm == 3)
    assert(all_2_factors_comm == 0)
    assert(all_3_factors_comm == 0)
    assert(all_4_factors_comm == 0)

    # test 2, target number is 6
    #  it will produce a sequence of  factors: 1*2*3, 1*2, 1*3, 1*5, 1 (in this order)
    begin_list = [1]
    factors_his = [0]* MAX_NUM_FACTORS
    target_num = 6
    primes = get_prime_list(target_num)
    factors_his, factors_his_cur_n_down = count_number_prime_product_recursive(begin_list, primes, target_num, factors_his)
    print target_num, factors_his, factors_his_cur_n_down

    all_1_factors_comm, all_2_factors_comm, all_3_factors_comm, all_4_factors_comm = get_select_factors(factors_his)
    # the following assertion is based on previous observations
    assert(all_1_factors_comm == 3)
    assert(all_2_factors_comm == 1)
    assert(all_3_factors_comm == 0)
    assert(all_4_factors_comm == 0)

    # test 3, it will produce a sequence of the follow factors: (in the order)
    #[1, 2, 3], [1, 2, 5], [1, 2, 7], [1, 2, 11], [1, 2, 13], [1, 2], [1, 3, 5], [1, 3, 7], [1, 3]
    # [1, 5], [1, 7], [1, 11], [1, 13], [1, 17], [1, 19], [1, 23]
    target_num = 28
    begin_list = [1]
    factors_his = [0]* MAX_NUM_FACTORS
    primes = get_prime_list(target_num)
    factors_his, factors_his_cur_n_down = count_number_prime_product_recursive(begin_list, primes, target_num, factors_his)
    print target_num, factors_his, factors_his_cur_n_down

    all_1_factors_comm, all_2_factors_comm, all_3_factors_comm, all_4_factors_comm = get_select_factors(factors_his)
    # the following assertion is based on previous observations
    assert(all_1_factors_comm == 9)
    assert(all_2_factors_comm == 7)
    assert(all_3_factors_comm == 0)
    assert(all_4_factors_comm == 0)

    # Test 4
    target_num = 70
    begin_list = [1]
    factors_his = [0]* MAX_NUM_FACTORS
    primes = get_prime_list(target_num)
    factors_his, factors_his_cur_n_down = count_number_prime_product_recursive(begin_list, primes, target_num, factors_his)
    print target_num, factors_his, factors_his_cur_n_down

    all_1_factors_comm, all_2_factors_comm, all_3_factors_comm, all_4_factors_comm = get_select_factors(factors_his)
    # the following assertion is not based on observation, we just run code once, and record number.
    # Those numbers are also produced by count_number_prime_product_with_4factors(...)
    # We believe those are correct, and use them for future. At least, if something are detected different in future,
    # we will can detect changes and try to find out why.
    assert(all_1_factors_comm == 19)
    assert(all_2_factors_comm == 20)
    assert(all_3_factors_comm == 4)
    assert(all_4_factors_comm == 0)
コード例 #17
0
ファイル: abc_xyz.py プロジェクト: glogou/tmp_testing
    assert(ab_search_range_start < ab_search_range_end)
    assert(xy_power_range_start < xy_power_range_end)

    # the following assert is because we use uint16 to save data to save memory we can not handle any larger number than 65535
    assert(ab_search_range_end < 65535)

    print 'ab_search_range_start = %d, ab_search_range_end  = %d, xy_power_range_start = %d, xy_power_range_end = %d, only_co_prime = %d'%( ab_search_range_start, ab_search_range_end, xy_power_range_start, xy_power_range_end, only_co_prime)

    np.set_printoptions(precision=4)
    np.set_printoptions(suppress=True)

    cnt_list = []

    # we need factor gcd of a and b (ab_gcd) into prime factor.
    # so we need list of prime numbers
    g_primes_list = get_prime_list(ab_search_range_end)

    # select an initial_mod for congruence
    initial_mod = select_initial_mod(ab_search_range_end)

    # show a few additional filter numbers  n2, n3, n4, n5 used in initial screening
    n = initial_mod
    do_not_care = -1
    additional_filtering(do_not_care, initial_mod, print_only = True)

    if(abc_fixed_option == 0):
        found_list, init_total_cnt, total_loop_cnt = abc_xyz(n, ab_search_range_start, ab_search_range_end, xy_power_range_start, xy_power_range_end, only_co_prime, x_same_y, abc_odd_option)

    # this is one of two the smallest a, b, c configs
    elif (abc_fixed_option == 1):
        a = 3
コード例 #18
0
ファイル: l_fun.py プロジェクト: glogou/tmp_testing
    hard_code_x_minus_4()

def plot_one_list(one_list, title_str, t_range_list, style):

    p1, = plt.plot(t_range_list, one_list, style, label="his")
    plt.ylabel('numbers')

    plt.title(title_str)
    plt.grid(True)

    # plt.draw and plt.show are different
    #plt.draw()
    plt.show(block=False)
# ===============================================================================================
if __name__=='__main__':

    MAX_NUM = 10000
    prime_list = get_prime_list(MAX_NUM)

    d_range = 31

    # use 100 terms in series summation
    sum_term = 100
    L_1_x_over_d_upto(d_range, prime_list, sum_term)

    compare_clas_num_formula(d_range, prime_list, sum_term)

    # unit_test_all()

    plt.show()
コード例 #19
0
ファイル: circl_meth.py プロジェクト: glogou/tmp_testing
            if ((N%2) == 1):
                result_summary_str = 'N= %5d, TMj= %5.2f, Tmi = %5.2f, TS=%5.2f, TMj_vs_Mi = %5.2f, arc_len: MA= %1.3f, mi = %1.3f, Q= %2d, t= %4d, step = %f, s_interval= %f'\
                                    %(N,       TMj,          Tmi,           TS,        TMj_vs_Mi_real,                       Mj_arc_len,  mi_arc_len,   Q,       t,        step,       s_interval )

                print result_summary_str
                thefile.write(result_summary_str)
                thefile.write("\n")

# =====================================================================================================================
if __name__=='__main__':

    np.set_printoptions(precision=4)
    np.set_printoptions(suppress=True)

    prime_max = 100000
    prime_list = get_prime_list(prime_max)

    parser = OptionParser()
    (options, args) = parser.parse_args()

    if(len(args) != 3):
        print 'Wrong arguments, require parameters: start_num, max_num, loop_step'
        print 'For N between start_num, max_num, with increment step as loop_step, this program will calculate'
        print 'contribution from mj vs mi for D(N) and T(N), where:'
        print 'D(N) is for integral of s^2(a, N)*e(-Na), Pan book P4, (15)'
        print 'T(N) is for integral of s^3(a, N)*e(-Na), Pan book P4, (16)'
        sys.exit(0)

    start_num = int(args[0])
    max_num = int(args[1])
    loop_step = int(args[2])
コード例 #20
0
ファイル: quadr_recip.py プロジェクト: glogou/tmp_testing
        sys.exit(0)

    n = int(args[0])

    if(n < 2):
        print 'Wrong input n = ', n
        sys.exit(0)

    else:
        print 'n = ', n

    # do some simple tests.
    check_num_of_qr_for_a_prime(19)
    check_num_of_qr_for_a_prime(53)

    prime_list = get_prime_list(n)

    # get_not_quadr_recip_ratio_only(n, prime_list)
    # sys.exit(0)

    # check qr for (-1|p)
    check_qr_for_minus_1_vs_p(prime_list)

    # check qr for(2|p)
    check_qr_for_2_vs_p(prime_list)

    # check eul_criter vs. brute force method to calculate quadr_recip
    check_qf_brute_force_sames_as_eul_criter(prime_list)

    # check legend_symb vs. quadr_recip properties
    check_legend_symb_vs_quadr_recip(n, prime_list)
コード例 #21
0
import matplotlib.pyplot as plt
import numpy as np

from prime_counting import pi_n
from li import li
from x_over_logx import x_over_logx
from get_prime_list import get_prime_list

# plot prime distribution
def plot_prime_distribution(pi_n_list, n_over_logn, li_n):

    p1, = plt.plot(pi_n_list, label="pi n")
    plt.ylabel('some numbers')
    plt.grid(True)
    p2, =  plt.plot(n_over_logn, label="n log")
    p3, = plt.plot(li_n, label="li")
    plt.legend([p1, p2, p3], ["pi", "n log(n)", "li(n)"])
    plt.show()

if __name__=='__main__':

    cnt = 1000

    primes = get_prime_list(cnt)
    pi_n_list = pi_n(primes)
    li_x_list = li(cnt)
    n_over_logn = x_over_logx(cnt)

    plot_prime_distribution(pi_n_list, n_over_logn, li_x_list)

    print 'all done'
コード例 #22
0
ファイル: liouvi_fun.py プロジェクト: glogou/tmp_testing
# we try to verify the correlation of liouvi_fun

import numpy as np
from optparse import OptionParser
import sys

from eul_totie import factor_a_number
from read_write_a_list_to_file import read_1d_data_list_from_file
from get_prime_list import get_prime_list

# target_num = 2000
target_num = 200000
file_name = "outputs_mert\\liouvi_upto_%d.txt" % (target_num)
liouvi_list = read_1d_data_list_from_file(file_name)

prime_list = get_prime_list(target_num)

# verify multiply_properties for selected numbers
def verify_multiply_properties(start_num, end_num, step_num):

    for n in xrange(start_num, end_num + 1, step_num):

        # factor m into products of prime powers, and use multiplicative properties
        factor_list = factor_a_number(n, prime_list)

        num_of_diff_primes = len(factor_list)

        liouvi_n = liouvi_list[n - 1]

        liouvi_n_by_factor = 1
コード例 #23
0
        step_in_t_range = 0.01          # Estimation can not be more accurate than this limit

    elif (run_option == g_TMP_SETTING):     #  this option is for tmp testing
        up_to = 20                        # prime up to this number,
        m_num_of_terms = 20
        t_range = 70                        # u
        step_in_t_range = 0.001             # Estimation can not be more accurate than this limit

    else:
        print 'NOT supported options'


    print 'x = %f'%(x)

    # generate primes up to up_to, for example, up to 100
    primes = get_prime_list(up_to)

    # Test any any sequences, not primes to see if we can detect ZEROS of zeta in this way.
    # A few simple tests show that those sequences will not generate zeros
    #primes = range(2, 500, 5)
    print 'num of primes %d'%(len(primes))

    t_range_list = np.arange(1, t_range, step_in_t_range)
    argument_list = get_argument_alone_a_vertical_line(x, t_range_list, m_num_of_terms, primes)

    phase_shift_pos = detect_phase_pi_shift(argument_list, t_range_list)

    # write to file
    result_file_name = 'outputs_primes_0s_loc\\up_to_%3d_x_%2.2f_st_%3.3f.txt'%(up_to, x, step_in_t_range)

    # name for picture file