def detect_prime_pairs_using_ster_broc_mat_format_with_fix_denomi(fix_denomi): print '\n=== detect_prime_pairs_using_ster_broc_mat_format_with_fix_denomi = ', fix_denomi # a is odd number a_list = np.arange(3, fix_denomi, 2, dtype = int) b = fix_denomi # print a_list # find co-prime of b cnt, coprime_list = eul_totie(b) # print coprime_list display_option = False # a1 will be p for a1 in a_list: # we only need to check a in 1st half of a_list if(a1 > end_num/2): break # if a1 is a coprime of b if a1 in coprime_list: # get count_fract for the input fraction a/b a1_cf_list = get_cont_fract(a1, b) # get the matrix format for a1/b a1_cf_mat_list, a1_ster_brot_mat, a1_b = ster_brot_mat_format_for_cont_fract(a1_cf_list, display_option) # since we are only interested in p + q = N, which is a1 + a2 = b, # therefore, a2 = b - a1 a2 = b - a1 # get count_fract for the input fraction a2/b a2_cf_list = get_cont_fract(a2, b) # get the matrix format for a2/b a2_cf_mat_list, a2_ster_brot_mat, a2_b = ster_brot_mat_format_for_cont_fract(a2_cf_list, display_option) # if a1 and a2 both are primes if (a1 in prime_list) and (a2 in prime_list): print a1_cf_list, ", ", ", num_of_turns: ", len(a1_cf_list), ", num_of_prod: ", np.sum(a1_cf_list), ", ", a1_b, " <==== GBC" print a2_cf_list, ", ", ", num_of_turns: ", len(a2_cf_list), ", num_of_prod: ", np.sum(a2_cf_list), ", ", a2_b, " <==== GBC" else: print a1_cf_list, ", ", ", num_of_turns: ", len(a1_cf_list), ", num_of_prod: ", np.sum(a1_cf_list), ", ", a1_b print a2_cf_list, ", ", ", num_of_turns: ", len(a2_cf_list), ", num_of_prod: ", np.sum(a2_cf_list), ", ", a2_b print a1_ster_brot_mat print a2_ster_brot_mat
def detect_primes_using_ster_broc_mat_format(start_num, end_num): if(start_num%2 == 1): print "--- detect_primes_using_ster_broc_mat_format(), start_num needs to be even ------------------------------------------" # b is even number, b_list = np.arange(start_num, end_num, 2, dtype = int) print b_list for b in b_list: # print b # we are only interested in the case tht a is odd number, and a is smaller than b # so that we will get a/b a_list = np.arange(3, b, 2, dtype = int) # print a_list # find coprimes of b cnt, coprime_list = eul_totie(b) # print coprime_list for a in a_list: if a in coprime_list: # get count_fract for the input fraction a/b cf_list = get_cont_fract(a, b) # get the matrix format for a/b cf_mat_list, ster_brot_mat, a_b = ster_brot_mat_format_for_cont_fract(cf_list) # we can print out finding # print cf_mat_list, ster_brot_mat, a_b if a in prime_list: sys.stdout.write("<================================== prime\n\n")
def get_all_cont_fracts_with_fix_denomi(fix_denomi): b = fix_denomi # a loop from 1 to b - 1 a_list = np.arange(1, fix_denomi, 1, dtype = int) # print a_list display_option = False tmpstr_1 = 'b = %4d, length for i/b where 1 <= i < b are: '%(b) sys.stdout.write(tmpstr_1) sys.stdout.write(", format: [num_of_mat_prod, i/b], ") # a1 will be p max_num_prods = 0 for a1 in a_list: # get count_fract for the input fraction a/b a1_cf_list = get_cont_fract(a1, b) # get the matrix format for a1/b a1_cf_mat_list, a1_ster_brot_mat, a1_b = ster_brot_mat_format_for_cont_fract(a1_cf_list, display_option) num_of_turns = len(a1_cf_list) num_of_prod = np.sum(a1_cf_list) tmpstr_1 = '[%d, %d/%d],'%(num_of_prod, a1_b[0], a1_b[1]) sys.stdout.write(tmpstr_1) if(num_of_prod > max_num_prods): max_num_prods = num_of_prod print " max_num_prods: ", max_num_prods
display_option = False end_level = 15 tree_as_breadth_1st_trav_list_upto_level = build_calk_wil_tree_upto_level(end_level) print "============ To do the following test, end_level need larger than 15 ===================" print "======if en_num is too small, it will not generate enough data for this test. ========" max_diagonal = 60 diagonal_formula_coeff_list = detect_diagonal_pattern(tree_as_breadth_1st_trav_list_upto_level, max_diagonal) a = 3 b = 13 has_found, found = find_entry_of_a_fract_in_tree(a, b, diagonal_formula_coeff_list) assert(has_found == True) cf_list = get_cont_fract(a, b) cf_mat_list, ster_brot_mat, a_b = ster_brot_mat_format_for_cont_fract(cf_list) a = 2 b = 9 has_found, found = find_entry_of_a_fract_in_tree(a, b, diagonal_formula_coeff_list) assert(has_found == True) cf_list = get_cont_fract(a, b) cf_mat_list, ster_brot_mat, a_b = ster_brot_mat_format_for_cont_fract(cf_list) a = 4 b =11 has_found, found = find_entry_of_a_fract_in_tree(a, b, diagonal_formula_coeff_list) assert(has_found == True)