コード例 #1
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
コード例 #2
0
def compare_mert_log_sum_with_cheby(n, mert_list):

    cheby_list = cheby_fun_integer(n)

    cheby_approx_list = mert_related_to_cheby(mert_list)

    range_list = range(1, n+1)

    # plot cheby_fun(x) against x
    plt.figure(1)
    plot_one_list(cheby_list, n, range_list, 'b-*')
    plot_one_list(range_list, n, range_list, 'g-*')
    plot_one_list(cheby_approx_list, n, range_list, 'r-*')

    plt.xlabel('blue, cheby; red: mert_approx; green: x')

    # it turns out cheby_list and cheby_approx_list are EXACT same.
    print 'cheby_list[1] = ', cheby_list[1]
    print 'cheby_approx_list[1] = ', cheby_approx_list[1]

    plt.show()
コード例 #3
0
    # NOTE: It is better to test n = 10,000, 1,000, 10, to see
    # the difference. When n = 10,000, one can zoom in some interesting region to see
    # fine details.

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

    if(len(args) != 2):
        print 'Wrong arguments, require parameters: max_num factor_list_option'
        print 'factor_list_option = 1: TRUE_PRIME, 2: PRIME_XLOGX_NON_PRECISE, 3: LIOUVI_FACTOR, 4: PRIME_XLOGX_PRECISE'
        sys.exit(0)

    n = int(args[0])
    factor_list_option = int(args[1])

    cheby_list = cheby_fun_integer(n)

    range_list = range(1, n+1)

    # plot cheby_fun(x) against x
    plt.figure(1)
    plot_one_list(cheby_list, n, range_list, 'b-*')
    plot_one_list(range_list, n, range_list, 'g-*')
    plt.xlabel('blue, cheby;  green: x')
    title_str = 'cheby_fun, target_num %d'%(n)
    plt.title(title_str)
    # plt.show()

    # plot cheby_fun(x) - x
    plt.figure(2)
    cheby_minus_x_arr = cheby_minus_x(cheby_list, range_list)