Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
def verify_von_mang_as_sum_of_rama_sum(n,  num_of_sum_terms = 1000):

    vm_list = von_mang_upto(n)

    # print 'test_1: vm_list', vm_list

    sum_of_rama_sum_list=[]

    for m in range(1, n + 1):

        tmp = 0

        for term in range(1, num_of_sum_terms + 1):
            rama_sum = rama_sum_use_mobi(m, term)
            # rama_sum = rama_sum_use_prim_unit_root(m, term)
            # print rama_sum
            tmp += rama_sum/float(term)

        sum_of_rama_sum_list.append(tmp)

    print 'verify_von_mang_as_sum_of_rama_sum, n = %d, num_of_sum_terms = %d'%(n, num_of_sum_terms )
    print '-vm_list = ', -np.asarray(vm_list)
    print 'sum_of_rama_sum_list = ', np.asarray(sum_of_rama_sum_list)

    # diff = sum_of_rama_sum_list - (-vm_list) = sum_of_rama_sum_list + vm_list
    diff = np.asarray(vm_list) + np.asarray(sum_of_rama_sum_list)

    print 'Diff: sum_of_rama_sum_list - (-vm_list) = ', diff

    print '================ verify_von_mang_as_sum_of_rama_sum: done !\n'
Ejemplo n.º 3
0
def cheby_fun_q_a_integer_use_saved_von_mang(n, q, a):

    global g_cnt
    global von_mang_list
    global g_n

    # only call von_mang_upto() once
    if(g_cnt == 0):
        von_mang_list =  von_mang_upto(n)
        g_cnt = 1
        g_n = n
        print '1st time calculate von_mang_list for n = %d, len(von_mang_list) = %d'%(n, len(von_mang_list) )

    else:
        assert(g_n == n)
        assert(len(von_mang_list) == n)
        print 'use existing von_mang_list for n = %d, len(von_mang_list) = %d, q = %d, a = %d'%(n, len(von_mang_list), q, a)

    cheby_list=[]

    # construct cheby_fun without consider averaging on jump of prime numbers
    tmp_sum = 0

    # Note, the range(0, n) will goes to n-1, which actually access von_mang_list[n-1], which is for
    # von_mang for number n.
    for i in range(1, n+1):

        if ((i%q) == a):
            tmp_sum = tmp_sum + von_mang_list[i - 1]

        cheby_list.append(tmp_sum)

    return cheby_list
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
def cheby_fun_integer(n):

    von_mang_list =  von_mang_upto(n)
    cheby_list=[]

    # construct cheby_fun without consider averaging on jump of prime numbers
    tmp_sum = 0

    # von_mang_list[] is for prime 1, 2, 3, ..., n
    # von_mang_list[0] is for prime 1, von_mang_list[n-1] is for von_mang function(n)
    for i in range(1, n+1):
        tmp_sum = tmp_sum + von_mang_list[i-1]
        cheby_list.append(tmp_sum)

    return cheby_list
Ejemplo n.º 6
0
def cheby_fun_real(n, sampling_per_unit):

    von_mang_list =  von_mang_upto(n)
    cheby_list=[]
    cheby_ave_list =[]

    assert(sampling_per_unit > 1)
    # construct range_list
    step = 1/float(sampling_per_unit)
    # step = 0.1

    # add step to n, to make sure that the largest number is n,
    #
    range_list = np.arange(0, n+step, step)

    # construct cheby_fun without considering averaging on jump of prime numbers
    tmp_sum = 0
    for x in range_list:
        x_int = int(x)

        if(x_int <1):
            tmp_sum = 0

        else:
            # Note, von_mang_list is defined for n =1, 2, 3, von_mang[0] is actual for number 1
            if((x - x_int) == 0):
                tmp_sum = tmp_sum + von_mang_list[x_int-1]

        cheby_list.append(tmp_sum)

    # construct cheby_fun considering averaging on jump of prime numbers
    tmp_sum = 0
    for x in range_list:
        x_int = int(x)
        if(x_int <1):
            tmp_sum = 0

        else:
            if((x - x_int) == 0):
                tmp_sum = tmp_sum + 0.5*(von_mang_list[x_int -2] + von_mang_list[x_int -1])

        cheby_ave_list.append(tmp_sum)

    assert(len(cheby_list) == len(cheby_ave_list))
    assert(len(cheby_list) == len(range_list))

    return cheby_list, cheby_ave_list, range_list
Ejemplo n.º 7
0
def cheby_fun_q_a_integer(n, q, a):

    von_mang_list =  von_mang_upto(n)
    cheby_list=[]

    # construct cheby_fun without consider averaging on jump of prime numbers
    tmp_sum = 0

    # Note, the range(0, n) will goes to n-1, which actually access von_mang_list[n-1], which is for
    # von_mang for number n.
    for i in range(1, n+1):

        if ((i%q) == a):
            tmp_sum = tmp_sum + von_mang_list[i - 1]

        cheby_list.append(tmp_sum)

    return cheby_list
def verify_hard_littlew_conj_for_twi_prim(x):

    # fix h = 2
    h = 2
    von_mang_list = von_mang_upto(x+h)

    lamda_n_lamda_n_h_sum_list = []

    for i in range(1, x+1):

        lamda_n_lamda_n_h_sum = 0
        for n in range(1, i):

            tmp = von_mang_list[n - 1]*von_mang_list[n + h - 1]
            lamda_n_lamda_n_h_sum += tmp

            # print h, von_mang_list[n - 1], von_mang_list[n + h - 1], tmp, lamda_n_lamda_n_h_sum

        lamda_n_lamda_n_h_sum_list.append(lamda_n_lamda_n_h_sum)

    return lamda_n_lamda_n_h_sum_list
def verify_hard_littlew_conj(x, h):

    # if we fix h to 2, then, it will be verify_hard_littlew_conj_for_twi_prim(...)
    von_mang_list = von_mang_upto(x+h)

    lamda_n_lamda_n_h_sum_list = []

    for i in range(1, x+1):

        lamda_n_lamda_n_h_sum = 0
        for n in range(1, i):

            tmp = von_mang_list[n - 1]*von_mang_list[n + h - 1]
            lamda_n_lamda_n_h_sum += tmp

            # print h, von_mang_list[n - 1], von_mang_list[n + h - 1], tmp, lamda_n_lamda_n_h_sum

        lamda_n_lamda_n_h_sum_list.append(lamda_n_lamda_n_h_sum)

    last_num_vs_x = lamda_n_lamda_n_h_sum/float(x)

    print 'h = ', h, ', x = ', x, ', last_num_vs_x = ', last_num_vs_x

    return lamda_n_lamda_n_h_sum_list, last_num_vs_x
Ejemplo n.º 10
0
    for i in range(5, 20):

        von_mang_new = vaugh_iden_von_mang_3_parts_format(i, y, z,  von_mang_list, mobi_list)

        # print von_mang_new
        diff_abs = np.absolute(von_mang_new - von_mang_list[i - 1])

        assert(diff_abs < ALMOST_ZERO)

        von_mang_list_new.append(von_mang_new)

    print 'unit_test_vaugh_iden_von_mang_3_parts_format, start from 5, new von_mang_list: \n', np.asarray(von_mang_list_new)

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

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

    print mobi_list

    unit_test_vaugh_iden_mobi_format_version()

    von_mang_list = von_mang_upto(100)
    
    #print 'old: von_mang_list', np.asarray(von_mang_list)
    unit_test_vaugh_iden_von_mang_4_parts_format()

    unit_test_vaugh_iden_von_mang_3_parts_format()
Ejemplo n.º 11
0
    unit_fun_list = unit_fun(n)
    constant_fun_list = constant_fun(n)
    x_fun_list = x_fun(n)
    log_x_fun_list = log_x_fun(n)
    e_x_fun_list = e_x_fun(n)               # value of this function is too large, we do not include in function list
    unit_circle_fun_list = unit_circle_fun(n)
    unit_circle_fun_arr = np.asarray(unit_circle_fun_list)

    # mobi_fun
    mobi_fun_list = mobi_list[:n]

    # liouv_fun
    liouvi_fun_list = liouvi_list[:n]

    # von_mang_fun
    von_mang_fun_list = von_mang_upto(n)

    # get square of mobi_fun
    mobi_square_fun_list = [0]*n
    for i in range(n):
        mobi_square_fun_list[i] = mobi_fun_list[i]*mobi_fun_list[i]

    build_fun_list(unit_fun_list, 'unit')
    build_fun_list(constant_fun_list, 'constant')
    build_fun_list(x_fun_list, 'x')
    build_fun_list(log_x_fun_list, 'log')
    build_fun_list(unit_circle_fun_arr, 'unit circle')
    build_fun_list(mobi_fun_list, 'mobi')
    build_fun_list(liouvi_fun_list, 'liouvi')
    build_fun_list(mobi_square_fun_list, 'mobi square')
    build_fun_list(von_mang_fun_list, 'von mang')