44
55ZQDFEGSRHTDR = 35279032783773322923326661023
66
7- import math , time , os
7+ import math , os
88from datetime import datetime
99import log
1010import parse_config
3030
3131def initialize (n ):
3232
33- d = int (pow (3 * math .log (n )/ math .log (math .log (n )),1 / 3 ))
34- first_B = int (math .exp (pow ((8 / 9 )* math .log (n ),1 / 3 )* pow (math .log (math .log (n )),2 / 3 )))
33+ d = int (pow (3 * math .log (n )/ math .log (math .log (n )),1 / 3 ))
34+ first_B = int (math .exp (pow ((8 / 9 )* math .log (n ),1 / 3 )* pow (math .log (math .log (n )),2 / 3 )))
3535 B = 10 * first_B // 70
3636
3737 return d , B
3838
39- def initialize_2 (f_x , n , m1 , d , primes , leading_coeff ):
40- pairs_used ,R_p ,logs ,tmp = [],[],[],10 * d
41- divide_leading ,pow_div = [],[]
39+ def initialize_2 (f_x , m1 , d , primes , leading_coeff ):
40+ pairs_used ,R_p ,logs ,tmp = [],[],[],10 * d
41+ divide_leading ,pow_div = [],[]
4242 for p in primes :
4343 if not leading_coeff % p :
4444 divide_leading .append (p )
4545 u = p
4646 while not leading_coeff % u : u *= p
4747 pow_div .append (u // p )
48+ 4849 logs .append (round (math .log2 (p )))
49- if p > tmp : R_p .append (find_roots_poly (f_x ,p ))
50- else : R_p .append (fast_roots (f_x ,p ))
50+ if p > tmp : R_p .append (find_roots_poly (f_x ,p ))
51+ else : R_p .append (fast_roots (f_x ,p ))
5152 if len (R_p [- 1 ]) == d :
52- if d & 1 : pairs_used .append ([[leading_coeff * p ],leading_coeff * pow (p ,d ),[[1 ,1 ]],p * m1 ,[1 ],[0 ,p ],1 ])
53- else : pairs_used .append ([[leading_coeff * p ],leading_coeff * p ,[[1 ,1 ]],p * m1 ,[1 ],[0 ,p ],1 ])
53+ if d & 1 : pairs_used .append ([[leading_coeff * p ], leading_coeff * pow (p , d ), [[1 ,1 ]], p * m1 , [1 ], [0 ,p ], 1 ])
54+ else : pairs_used .append ([[leading_coeff * p ], leading_coeff * p , [[1 ,1 ]], p * m1 , [1 ], [0 ,p ], 1 ])
55+ 5456 for p in divide_leading :
5557 for i in range (len (pairs_used )): pairs_used [i ].append (True )
5658
@@ -67,9 +69,9 @@ def initialize_3(n, f_x, f_prime, const1, leading_coeff):
6769 if is_prime (q ) and leading_coeff % q :
6870 if not n % q : return q , n // q
6971 else :
70- tmp = find_roots_poly (f_x ,q )
72+ tmp = find_roots_poly (f_x ,q )
7173 for r in tmp :
72- if eval_mod (f_prime ,r , q ): Q .append ([q ,r ])
74+ if eval_mod (f_prime ,r , q ): Q .append ([q ,r ])
7375 q += 2
7476
7577 return Q , k
@@ -81,17 +83,17 @@ def NFS(n):
8183
8284 parameters = parse_config .parse_config (CONFIG_PATH )
8385
84- flag_use_batch_smooth_test = parameters [0 ].lower () in ["true" ]
85- flag_gaussian_pivot = parameters [1 ].lower () in ["true" ]
86- flag_lanczos = parameters [2 ].lower () in ["true" ]
87- flag_square_root_couveignes = parameters [3 ].lower () in ["true" ]
88- const = int (parameters [4 ])
86+ FLAG_USE_BATCH_SMOOTH_TEST = parameters [0 ].lower () in ["true" ]
87+ FLAG_GAUSSIAN_PIVOT = parameters [1 ].lower () in ["true" ]
88+ FLAG_LANCZOS = parameters [2 ].lower () in ["true" ]
89+ FLAG_SQUARE_ROOT_COUVEIGNES = parameters [3 ].lower () in ["true" ]
90+ CONST = int (parameters [4 ])
8991 BLOCK_SIZE = int (parameters [5 ])
90- nb_poly_coarse_eval = int (parameters [6 ])
91- nb_poly_precise_eval = int (parameters [7 ])
92- prime_bound = int (parameters [8 ])
93- nb_roots = int (parameters [9 ])
94- multiplier = int (parameters [10 ])
92+ NB_POLY_COARSE_EVAL = int (parameters [6 ])
93+ NB_POLY_PRECISE_EVAL = int (parameters [7 ])
94+ PRIME_BOUND = int (parameters [8 ])
95+ NB_ROOTS = int (parameters [9 ])
96+ MULTIPLIER = int (parameters [10 ])
9597 NB_CPU_POLY_SELECTION = int (parameters [11 ])
9698 NB_CPU_SIEVE = int (parameters [12 ])
9799
@@ -101,54 +103,54 @@ def NFS(n):
101103
102104 primes = create_smooth_primes_base (B )
103105 for p in primes :
104- if not n % p : return p ,n // p
106+ if not n % p : return p ,n // p
105107
106108 prod_primes = math .prod (primes )
107109
108- const1 , const2 = const * primes [- 1 ], const * primes [- 1 ]* primes [- 1 ]
110+ const1 , const2 = CONST * primes [- 1 ], CONST * primes [- 1 ]* primes [- 1 ]
109111
110112 if NB_CPU_POLY_SELECTION == 1 :
111- f_x ,m0 ,m1 ,tmp ,_ = mono_cpu_polynomial_selection .poly_search (n ,primes ,nb_roots , prime_bound , multiplier ,
112- int (pow (n ,1 / (d + 1 ))),d , nb_poly_coarse_eval ,
113- nb_poly_precise_eval , LOG_PATH )
113+ f_x ,m0 ,m1 ,tmp ,_ = mono_cpu_polynomial_selection .poly_search (n ,primes ,NB_ROOTS , PRIME_BOUND , MULTIPLIER ,
114+ int (pow (n ,1 / (d + 1 ))),d , NB_POLY_COARSE_EVAL ,
115+ NB_POLY_PRECISE_EVAL , LOG_PATH )
114116
115117 else :
116- f_x ,m0 ,m1 ,tmp ,_ = multi_cpu_polynomial_selection .poly_search (n ,primes ,nb_roots , prime_bound , multiplier ,
117- int (pow (n ,1 / (d + 1 ))),d , nb_poly_coarse_eval ,
118- nb_poly_precise_eval , NB_CPU_POLY_SELECTION ,LOG_PATH )
118+ f_x ,m0 ,m1 ,tmp ,_ = multi_cpu_polynomial_selection .poly_search (n ,primes ,NB_ROOTS , PRIME_BOUND , MULTIPLIER ,
119+ int (pow (n ,1 / (d + 1 ))),d , NB_POLY_COARSE_EVAL ,
120+ NB_POLY_PRECISE_EVAL , NB_CPU_POLY_SELECTION ,LOG_PATH )
119121
120122 log .write_log (LOG_PATH , "poly search completed, parameters : m0 = " + str (m0 )+ " ; m1 = " + str (m1 )+ " ; d = " + str (d )+ "\n " )
121123
122- f_x , m0 , M = mono_cpu_polynomial_selection .evaluate_polynomial_quality (f_x ,B , m0 ,m1 ,primes ,LOG_PATH )
124+ f_x , m0 , M = mono_cpu_polynomial_selection .evaluate_polynomial_quality (f_x ,B , m0 ,m1 ,primes ,LOG_PATH )
123125
124126 leading_coeff = f_x [0 ]
125127 zeros_f = get_complex_roots (f_x )
126128 zeros = [leading_coeff * i for i in zeros_f ]
127129 f_prime = get_derivative (f_x )
128130
129131 g = [1 ,f_x [1 ]]
130- for i in range (2 ,len (f_x )): g .append (f_x [i ]* pow (leading_coeff ,i - 1 ))
132+ for i in range (2 ,len (f_x )): g .append (f_x [i ]* pow (leading_coeff ,i - 1 ))
131133 g_prime = get_derivative (g )
132134
133- g_prime_sq ,g_prime_eval = div_poly (poly_prod (g_prime ,g_prime ),g ),pow (leading_coeff , d - 2 , n )* eval_F (m0 ,m1 ,f_prime ,d - 1 )% n
135+ g_prime_sq ,g_prime_eval = div_poly (poly_prod (g_prime ,g_prime ),g ),pow (leading_coeff , d - 2 , n )* eval_F (m0 ,m1 ,f_prime ,d - 1 )% n
134136
135137 delta = []
136138 for r in range (d ):
137139 tmp = []
138140 for i in range (d ):
139141 delt = 0
140142 for j in range (d - i ):
141- if zeros [r ].real == 0 or zeros [r ].imag == 0 or j == 0 : delt += (abs (g [- i - j - 2 ])* pow (leading_coeff ,j )* pow (my_norm (zeros_f [r ]),j ))
142- else : delt += (abs (g [- i - j - 2 ])* pow (leading_coeff ,j )* pow (my_norm (zeros_f [r ]),j ))+ 1
143+ if zeros [r ].real == 0 or zeros [r ].imag == 0 or j == 0 : delt += (abs (g [- i - j - 2 ])* pow (leading_coeff ,j )* pow (my_norm (zeros_f [r ]),j ))
144+ else : delt += (abs (g [- i - j - 2 ])* pow (leading_coeff ,j )* pow (my_norm (zeros_f [r ]),j ))+ 1
143145 tmp .append (delt )
144146 delta .append (tmp )
145147
146148
147149 inert_set = []
148150 for p in primes :
149- if m1 % p and leading_coeff % p and irreducibility (g ,p ): inert_set .append (p )
151+ if m1 % p and leading_coeff % p and irreducibility (g ,p ): inert_set .append (p )
150152
151- pairs_used , R_p , logs , divide_leading , pow_div , B_prime = initialize_2 (f_x , n , m1 , d , primes , leading_coeff )
153+ pairs_used , R_p , logs , divide_leading , pow_div , B_prime = initialize_2 (f_x , m1 , d , primes , leading_coeff )
152154
153155 Q , k = initialize_3 (n , f_x , f_prime , B , leading_coeff )
154156
@@ -157,63 +159,63 @@ def NFS(n):
157159
158160 if NB_CPU_SIEVE <= 1 :
159161 if NB_CPU_SIEVE < 1 : print ("NB_CPU parameter incorrectly set. Must be > 0. Sieving with 1 CPU." )
160- pairs_used , V = mono_cpu_sieve .find_relations (f_x ,leading_coeff ,g , primes ,R_p ,Q , B_prime ,divide_leading ,
161- prod_primes ,pow_div ,pairs_used ,const1 ,const2 ,logs ,m0 ,m1 ,
162- M ,d , n , flag_use_batch_smooth_test ,LOG_PATH )
162+ pairs_used , V = mono_cpu_sieve .find_relations (f_x ,leading_coeff ,g , primes ,R_p ,Q , B_prime ,divide_leading ,
163+ prod_primes ,pow_div ,pairs_used ,const1 ,const2 ,logs ,m0 ,m1 ,
164+ M ,FLAG_USE_BATCH_SMOOTH_TEST ,LOG_PATH )
163165
164166 else :
165- pairs_used , V = multi_cpu_sieve .find_relations (f_x ,leading_coeff ,g , primes ,R_p ,Q , B_prime ,divide_leading ,
166- prod_primes ,pow_div ,pairs_used ,const1 ,const2 ,logs ,m0 ,m1 ,
167- M ,d , n , flag_use_batch_smooth_test , LOG_PATH ,NB_CPU_SIEVE )
167+ pairs_used , V = multi_cpu_sieve .find_relations (f_x ,leading_coeff ,g , primes ,R_p ,Q , B_prime ,divide_leading ,
168+ prod_primes ,pow_div ,pairs_used ,const1 ,const2 ,logs ,m0 ,m1 ,
169+ M ,FLAG_USE_BATCH_SMOOTH_TEST , LOG_PATH ,NB_CPU_SIEVE )
168170
169171 print ("" )
170172 log .write_log (LOG_PATH , "sieving complete, building matrix..." )
171- if flag_gaussian_pivot :
173+ if FLAG_GAUSSIAN_PIVOT :
172174 matrix = build_dense_matrix (pairs_used , primes , R_p , Q , divide_leading )
173175 length = len (matrix [0 ])
174176 matrix , N , U = siqs_build_matrix_opt (matrix )
175177 log .write_log (LOG_PATH , "matrix built " + str (len (matrix ))+ "x" + str (len (pairs_used ))+ " finding kernel..." )
176178 else :
177- matrix = build_sparse_matrix (pairs_used ,primes ,R_p ,Q , divide_leading )
179+ matrix = build_sparse_matrix (pairs_used ,primes ,R_p ,Q , divide_leading )
178180 matrix = transpose_sparse (matrix , V )
179181 log .write_log (LOG_PATH , "matrix built " + str (len (matrix ))+ "x" + str (len (pairs_used ))+ " reducing..." )
180- if not flag_gaussian_pivot :
182+ if not FLAG_GAUSSIAN_PIVOT :
181183 matrix , pairs_used = reduce_sparse_matrix (matrix , pairs_used )
182184 log .write_log (LOG_PATH , "matrix built " + str (len (matrix ))+ "x" + str (len (pairs_used ))+ " finding kernel..." )
183185
184186 time_1 = datetime .now ()
185187
186- if flag_gaussian_pivot :
188+ if FLAG_GAUSSIAN_PIVOT :
187189 null_space = siqs_solve_matrix_opt (matrix , N , U )
188190 log .write_log (LOG_PATH , str (len (null_space ))+ " kernel vectors found" )
189191 for vec in null_space :
190192 vec = compute_solutions .convert_to_binary (vec , length )
191- flag , res = compute_solutions .compute_factors (pairs_used ,vec ,n , primes ,f_x , g , g_prime ,g_prime_sq ,g_prime_eval ,
192- m0 ,m1 ,leading_coeff ,d ,inert_set ,zeros ,delta ,M , flag_square_root_couveignes ,
193- time_1 ,LOG_PATH )
193+ flag , res = compute_solutions .compute_factors (pairs_used ,vec ,n , primes ,g , g_prime ,g_prime_sq ,g_prime_eval ,
194+ m0 ,m1 ,leading_coeff ,d ,inert_set ,zeros ,delta ,M , FLAG_SQUARE_ROOT_COUVEIGNES ,
195+ time_1 ,LOG_PATH )
194196 if flag : return res
195197
196198 else :
197- if flag_lanczos :
199+ if FLAG_LANCZOS :
198200 while True :
199- null_space = block_lanczos (matrix ,len (pairs_used ),BLOCK_SIZE , LOG_PATH )
201+ null_space = block_lanczos (matrix ,len (pairs_used ),BLOCK_SIZE , LOG_PATH )
200202
201203 log .write_log (LOG_PATH , str (len (null_space ))+ " kernel vectors found" )
202204 for vec in null_space :
203205 vec = compute_solutions .convert_to_binary_lanczos (vec , len (pairs_used ))
204- flag , res = compute_solutions .compute_factors (pairs_used ,vec ,n , primes ,f_x , g , g_prime ,g_prime_sq ,g_prime_eval ,
205- m0 ,m1 ,leading_coeff ,d , inert_set ,zeros ,delta ,M , flag_square_root_couveignes ,
206- time_1 ,LOG_PATH )
206+ flag , res = compute_solutions .compute_factors (pairs_used ,vec ,n , primes ,g , g_prime ,g_prime_sq ,g_prime_eval ,
207+ m0 ,m1 ,leading_coeff ,d , inert_set ,zeros ,delta ,M , FLAG_SQUARE_ROOT_COUVEIGNES ,
208+ time_1 ,LOG_PATH )
207209 if flag : return res
208210
209211 else :
210212 mini_poly_estim = 1
211213 while True :
212- null_space , mini_poly_estim = wiedemann (matrix ,len (pairs_used ),BLOCK_SIZE ,mini_poly_estim )
214+ null_space , mini_poly_estim = wiedemann (matrix ,len (pairs_used ),BLOCK_SIZE ,mini_poly_estim )
213215 null_space = reduce_null_space_vectors (null_space )
214216 log .write_log (LOG_PATH , str (len (null_space ))+ " kernel vectors found" )
215217 for vec in null_space :
216- flag , res = compute_solutions .compute_factors (pairs_used ,vec ,n , primes ,f_x , g , g_prime ,g_prime_sq ,g_prime_eval ,
217- m0 ,m1 ,leading_coeff ,d , inert_set ,zeros ,delta ,M ,flag_square_root_couveignes ,
218- time_1 ,LOG_PATH )
218+ flag , res = compute_solutions .compute_factors (pairs_used ,vec ,n , primes ,g , g_prime ,g_prime_sq ,g_prime_eval ,
219+ m0 ,m1 ,leading_coeff ,d , inert_set ,zeros ,delta ,M ,FLAG_SQUARE_ROOT_COUVEIGNES ,
220+ time_1 ,LOG_PATH )
219221 if flag : return res
0 commit comments