Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 088c1b7

Browse files
Add files via upload
1 parent 86c2176 commit 088c1b7

File tree

6 files changed

+80
-84
lines changed

6 files changed

+80
-84
lines changed

‎README.txt‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,6 @@ Here are some points I consider working on at some point:
103103
- I have to implement the Montgomery algorithm for the algebraic square root computation.
104104
For the small numbers I have used my algorithm on, it is not a bottleneck yet.
105105

106-
- I have to optimize the Union-find algorithm for cycle detection, the version I have right now
107-
does not seem to be perfect, as I still do many operations to connect two distinct
108-
connected components.
109-
110106
- No matter how hard I tried, I am stuck on understanding the block Wiedemann algorithm. For
111107
now, the best I can do is the scalar one, with some optimizations. Namely, I use binary
112108
encoding of the blocks of vectors to compute matrix-vector product very efficiently.

‎config/config.ini‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ lanczos=True
55
square_root_couveignes=False
66
large_primes_constant=100
77
block_size=8
8-
poly_search_nb_poly_coarse_eval=1000
9-
poly_search_nb_poly_precise_eval=200
8+
poly_search_nb_poly_coarse_eval=100
9+
poly_search_nb_poly_precise_eval=50
1010
poly_search_prime_bound=300
1111
poly_search_nb_roots=3
1212
poly_search_multiplier=1
1313
NB_CPU_POLY_SELECTION=4
14-
NB_CPU_SIEVE=1
14+
NB_CPU_SIEVE=4

‎src/compute_solutions.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def compute_factors(pairs_used, vec, n, primes, f_x, g, g_prime, g_prime_sq, g_p
167167
else:
168168
x,y = create_solution(pairs_used,vec,n,len(primes),primes,g,g_prime,m0,m1,inert_set[-1],g_prime_sq,leading_coeff,g_prime_eval,2*M)
169169

170-
print(math.gcd(x-y,n), math.gcd(x+y,n))
170+
# print(math.gcd(x-y,n), math.gcd(x+y,n))
171171

172172
if x != y and math.gcd(x-y,n) != 1 and math.gcd(x+y,n) != 1:
173173
print_final_message(x, y, n, time_1, LOG_PATH)

‎src/mono_cpu_sieve.py‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
def find_relations(f_x, leading_coeff, g, primes, R_p, Q, B_prime, divide_leading, prod_primes, pow_div, pairs_used,
1414
const1, const2, logs, m0, m1, M, d, n, flag_use_batch_smooth_test, LOG_PATH):
1515
fp, pf = {}, {}
16-
connected_components_fp, connected_components_pf = {}, {}
17-
node_component_fp, node_component_pf = {}, {}
18-
index_component_fp, index_component_pf = 0, 0
16+
parent_fp, parent_pf = {}, {}
1917
full_found = 0
2018
partial_found_fp, partial_found_pf = 0, 0
2119
size_fp, size_pf = 0, 0
@@ -62,10 +60,10 @@ def find_relations(f_x, leading_coeff, g, primes, R_p, Q, B_prime, divide_leadin
6260
full_found += 1
6361

6462
elif z[4] > 1 and z[2] == 1:
65-
pairs_used, fp, graph_fp, size_fp, index_component_fp, cycle_len, full_found, partial_found_fp = handle_large_fp(tmp,z,pairs_used,fp,graph_fp,size_fp,connected_components_fp,node_component_fp,index_component_fp,g,divide_leading,cycle_len,full_found,partial_found_fp)
63+
pairs_used, fp, graph_fp, size_fp, parent_fp, cycle_len, full_found, partial_found_fp = handle_large_fp(tmp,z,pairs_used,fp,graph_fp,size_fp,parent_fp,g,divide_leading,cycle_len,full_found,partial_found_fp)
6664

6765
elif z[4] == 1 and z[2] > 1:
68-
pairs_used, pf, graph_pf, size_pf, index_component_pf, cycle_len, full_found, partial_found_pf = handle_large_pf(tmp, z, pairs_used, pf, graph_pf, size_pf, connected_components_pf, node_component_pf, index_component_pf, g, divide_leading, cycle_len, full_found, partial_found_pf)
66+
pairs_used, pf, graph_pf, size_pf, parent_pf, cycle_len, full_found, partial_found_pf = handle_large_pf(tmp, z, pairs_used, pf, graph_pf, size_pf, parent_pf, g, divide_leading, cycle_len, full_found, partial_found_pf)
6967

7068
sys.stdout.write('\r'+"b = "+str(b)+" "+str(len(pairs_used))+"/("+str(V)+"+10) ; full relations = "+str(full_found)+" | partial found fp = "+str(partial_found_fp)+" ("+str(size_fp)+") | partial found pf = "+str(partial_found_pf)+" ("+str(size_pf)+")")
7169
b += 1

‎src/multi_cpu_sieve.py‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ def siever(b_queue, tmp_pairs, f_x, primes, R_p, prod_primes, m0, m1, d, b, M, l
4545
def find_relations(f_x, leading_coeff, g, primes, R_p, Q, B_prime, divide_leading, prod_primes, pow_div, pairs_used,
4646
const1, const2, logs, m0, m1, M, d, n, flag_use_batch_smooth_test, LOG_PATH, NB_CPU):
4747
fp, pf = {}, {}
48-
connected_components_fp, connected_components_pf = {}, {}
49-
node_component_fp, node_component_pf = {}, {}
50-
index_component_fp, index_component_pf = 0, 0
48+
parent_fp, parent_pf = {}, {}
5149
full_found = 0
5250
partial_found_fp, partial_found_pf = 0, 0
5351
size_fp, size_pf = 0, 0
@@ -100,10 +98,10 @@ def find_relations(f_x, leading_coeff, g, primes, R_p, Q, B_prime, divide_leadin
10098
full_found += 1
10199

102100
elif z[4] > 1 and z[2] == 1:
103-
pairs_used, fp, graph_fp, size_fp, index_component_fp, cycle_len, full_found, partial_found_fp = handle_large_fp(tmp,z,pairs_used,fp,graph_fp,size_fp,connected_components_fp,node_component_fp,index_component_fp,g,divide_leading,cycle_len,full_found,partial_found_fp)
101+
pairs_used, fp, graph_fp, size_fp, parent_fp, cycle_len, full_found, partial_found_fp = handle_large_fp(tmp,z,pairs_used,fp,graph_fp,size_fp,parent_fp,g,divide_leading,cycle_len,full_found,partial_found_fp)
104102

105103
elif z[4] == 1 and z[2] > 1:
106-
pairs_used, pf, graph_pf, size_pf, index_component_pf, cycle_len, full_found, partial_found_pf = handle_large_pf(tmp, z, pairs_used, pf, graph_pf, size_pf, connected_components_pf, node_component_pf, index_component_pf, g, divide_leading, cycle_len, full_found, partial_found_pf)
104+
pairs_used, pf, graph_pf, size_pf, parent_pf, cycle_len, full_found, partial_found_pf = handle_large_pf(tmp, z, pairs_used, pf, graph_pf, size_pf, parent_pf, g, divide_leading, cycle_len, full_found, partial_found_pf)
107105

108106
sys.stdout.write('\r'+"b = "+str(b)+" "+str(len(pairs_used))+"/("+str(V)+"+10) ; full relations = "+str(full_found)+" | partial found fp = "+str(partial_found_fp)+" ("+str(size_fp)+") | partial found pf = "+str(partial_found_pf)+" ("+str(size_pf)+")")
109107

‎src/relations.py‎

Lines changed: 70 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def combine_fp(pair, pairs_used, fp, path, divide_leading, g):
8585
pairs_used.append(tmp)
8686

8787
# Master function, keeps the partial_relations and possible_smooth lists sorted, find the matching large primes, create the full relations from large primes
88-
def handle_large_fp(pair, large_primes, pairs_used, fp, graph_fp, size_fp, connected_components_fp, node_component_fp, index_component_fp, g, divide_leading, cycle_len, full_found, partial_found_fp):
88+
def handle_large_fp(pair, large_primes, pairs_used, fp, graph_fp, size_fp, parent_fp, g, divide_leading, cycle_len, full_found, partial_found_fp):
8989
pair[4] = [large_primes[3]]
9090

9191
if large_primes[3] == large_primes[4]:
@@ -94,98 +94,104 @@ def handle_large_fp(pair, large_primes, pairs_used, fp, graph_fp, size_fp, conne
9494

9595
elif not bool(fp):
9696
pair[4].append(large_primes[4])
97-
fp[large_primes[3]] = {}
98-
fp[large_primes[3]][large_primes[4]] = pair
9997

100-
graph_fp[large_primes[3]] = [large_primes[4]]
101-
graph_fp[large_primes[4]] = [large_primes[3]]
98+
small_p, big_p = large_primes[3], large_primes[4]
10299

103-
connected_components_fp[index_component_fp] = set((large_primes[3], large_primes[4]))
104-
node_component_fp[large_primes[3]] = index_component_fp
105-
node_component_fp[large_primes[4]] = index_component_fp
100+
fp[small_p] = {}
101+
fp[small_p][big_p] = pair
102+
103+
graph_fp[small_p] = [big_p]
104+
graph_fp[big_p] = [small_p]
105+
106+
parent_fp[small_p] = small_p
107+
parent_fp[big_p] = small_p
106108

107109
size_fp += 1
108-
index_component_fp += 1
109110

110111
else:
111-
flag_small_prime = large_primes[3] in graph_fp
112+
small_p, big_p = large_primes[3], large_primes[4]
113+
114+
flag_small_prime = small_p in graph_fp
112115

113116
# If the smallest prime has not already been seen
114117
if not flag_small_prime:
115-
graph_fp[large_primes[3]] = [large_primes[4]]
118+
graph_fp[small_p] = [big_p]
116119

117120
# Find where in partial relations it is needed to insert the new partial relation
118-
pair[4].append(large_primes[4])
119-
fp[large_primes[3]] = {}
120-
fp[large_primes[3]][large_primes[4]] = pair
121+
pair[4].append(big_p)
122+
123+
fp[small_p] = {}
124+
fp[small_p][big_p] = pair
121125

122126
size_fp += 1
123127

124128
# Find if largest prime has already been seen
125-
flag_big_prime = large_primes[4] in graph_fp
129+
flag_big_prime = big_p in graph_fp
126130

127131
if flag_big_prime: # if seen add the smallest prime to the list of links of the largest prime
128-
graph_fp[large_primes[4]].append(large_primes[3])
132+
graph_fp[big_p].append(small_p)
133+
134+
parent_fp[small_p] = parent_fp[big_p]
129135

130-
connected_components_fp[node_component_fp[large_primes[4]]].add(large_primes[3])
131-
node_component_fp[large_primes[3]] = node_component_fp[large_primes[4]]
132136
else: # If it has not been seen, append it
133-
graph_fp[large_primes[4]] = [large_primes[3]]
137+
graph_fp[big_p] = [small_p]
134138

135-
connected_components_fp[index_component_fp] = set((large_primes[3], large_primes[4]))
136-
node_component_fp[large_primes[3]] = index_component_fp
137-
node_component_fp[large_primes[4]] = index_component_fp
138-
index_component_fp += 1
139+
parent_fp[small_p] = small_p
140+
parent_fp[big_p] = small_p
139141

140142
# If the smallest prime has already been seen
141143
else:
142-
flag_big_prime = large_primes[4] in graph_fp
144+
flag_big_prime = big_p in graph_fp
143145

144146
# If big prime has not been seen
145147
if not flag_big_prime:
146-
graph_fp[large_primes[3]].append(large_primes[4]) # Append the largest prime to the list of links of the smallest prime
147-
graph_fp[large_primes[4]] = [large_primes[3]] # Create the large prime in the graph
148-
149-
connected_components_fp[node_component_fp[large_primes[3]]].add(large_primes[4])
150-
node_component_fp[large_primes[4]] = node_component_fp[large_primes[3]]
148+
graph_fp[small_p].append(big_p) # Append the largest prime to the list of links of the smallest prime
149+
graph_fp[big_p] = [small_p] # Create the large prime in the graph
151150

151+
parent_fp[big_p] = parent_fp[small_p]
152152

153-
pair[4].append(large_primes[4])
153+
pair[4].append(big_p)
154154
# Find where to insert the partial relation
155-
if large_primes[3] not in fp:
156-
fp[large_primes[3]] = {}
155+
if small_p not in fp:
156+
fp[small_p] = {}
157157

158-
fp[large_primes[3]][large_primes[4]] = pair
158+
fp[small_p][big_p] = pair
159159

160160
size_fp += 1
161161

162162
# If the largest prime has been seen, ie if both primes have already been seen
163163
else:
164-
if node_component_fp[large_primes[3]] != node_component_fp[large_primes[4]]:
165-
graph_fp[large_primes[3]].append(large_primes[4])
166-
graph_fp[large_primes[4]].append(large_primes[3])
167164

168-
connected_components_fp[node_component_fp[large_primes[3]]] = connected_components_fp[node_component_fp[large_primes[3]]].union(connected_components_fp[node_component_fp[large_primes[4]]])
165+
parent_small_p = parent_fp[small_p]
166+
while parent_fp[parent_small_p] != parent_small_p:
167+
parent_fp[parent_small_p], parent_small_p = parent_fp[parent_fp[parent_small_p]], parent_fp[parent_small_p]
169168

170-
for node in connected_components_fp[node_component_fp[large_primes[4]]]:
171-
node_component_fp[node] = node_component_fp[large_primes[3]]
169+
parent_big_p = parent_fp[big_p]
170+
while parent_fp[parent_big_p] != parent_big_p:
171+
parent_fp[parent_big_p], parent_big_p = parent_fp[parent_fp[parent_big_p]], parent_fp[parent_big_p]
172172

173-
pair[4].append(large_primes[4])
173+
if parent_small_p != parent_big_p:
174+
graph_fp[small_p].append(big_p)
175+
graph_fp[big_p].append(small_p)
176+
177+
parent_fp[parent_big_p] = parent_small_p
178+
179+
pair[4].append(big_p)
174180
# Find where to insert the partial relation
175-
if large_primes[3] not in fp:
176-
fp[large_primes[3]] = {}
181+
if small_p not in fp:
182+
fp[small_p] = {}
177183

178-
fp[large_primes[3]][large_primes[4]] = pair
184+
fp[small_p][big_p] = pair
179185

180186
size_fp += 1
181187
else:
182-
path_cycle = find_cycle_fp(graph_fp, large_primes[3:5])
188+
path_cycle = find_cycle_fp(graph_fp, [small_p, big_p])
183189
if len(path_cycle) < 11: cycle_len[len(path_cycle)-2] += 1
184190
else: cycle_len[-1] += 1
185191
combine_fp(pair,pairs_used,fp,path_cycle,divide_leading,g)
186192
partial_found_fp += 1
187193

188-
return pairs_used, fp, graph_fp, size_fp, index_component_fp, cycle_len, full_found, partial_found_fp
194+
return pairs_used, fp, graph_fp, size_fp, parent_fp, cycle_len, full_found, partial_found_fp
189195

190196
def find_cycle_pf(graph, init):
191197
if init[0] == (1, 1): return DFS_pf(graph, init)
@@ -278,7 +284,7 @@ def combine_pf(pair, pairs_used, pf, path, divide_leading, g):
278284

279285
pairs_used.append(tmp)
280286

281-
def handle_large_pf(pair, large_primes, pairs_used, pf, graph_pf, size_pf, connected_components_pf, node_component_pf, index_component_pf, g, divide_leading, cycle_len, full_found, partial_found_pf):
287+
def handle_large_pf(pair, large_primes, pairs_used, pf, graph_pf, size_pf, parent_pf, g, divide_leading, cycle_len, full_found, partial_found_pf):
282288
if large_primes[1] == 1:
283289
tmp = (1, 1) # [smallest_prime, r_smallest]
284290
pair[2] = [tmp]
@@ -303,10 +309,8 @@ def handle_large_pf(pair, large_primes, pairs_used, pf, graph_pf, size_pf, conne
303309
graph_pf[tmp2] = {}
304310
graph_pf[tmp2][tmp[0]] = [tmp]
305311

306-
connected_components_pf[index_component_pf] = set((tmp, tmp2))
307-
node_component_pf[tmp] = index_component_pf
308-
node_component_pf[tmp2] = index_component_pf
309-
index_component_pf += 1
312+
parent_pf[tmp] = tmp
313+
parent_pf[tmp2] = tmp
310314

311315
else:
312316
flag_small_prime = tmp in graph_pf
@@ -329,17 +333,14 @@ def handle_large_pf(pair, large_primes, pairs_used, pf, graph_pf, size_pf, conne
329333
else:
330334
graph_pf[tmp2][tmp[0]] = [tmp]
331335

332-
connected_components_pf[node_component_pf[tmp2]].add(tmp)
333-
node_component_pf[tmp] = node_component_pf[tmp2]
336+
parent_pf[tmp] = tmp2
334337

335338
else: # If it has not been seen, create it in the graph
336339
graph_pf[tmp2] = {}
337340
graph_pf[tmp2][tmp[0]] = [tmp]
338-
339-
connected_components_pf[index_component_pf] = set((tmp, tmp2))
340-
node_component_pf[tmp] = index_component_pf
341-
node_component_pf[tmp2] = index_component_pf
342-
index_component_pf += 1
341+
342+
parent_pf[tmp] = tmp
343+
parent_pf[tmp2] = tmp
343344

344345
# If [smallest_prime, r_smallest] has already be seen
345346
# We look for [largest_prime, r_largest]
@@ -355,8 +356,7 @@ def handle_large_pf(pair, large_primes, pairs_used, pf, graph_pf, size_pf, conne
355356
graph_pf[tmp2] = {}
356357
graph_pf[tmp2][tmp[0]] = [tmp] # Create the large prime in the graph
357358

358-
connected_components_pf[node_component_pf[tmp]].add(tmp2)
359-
node_component_pf[tmp2] = node_component_pf[tmp]
359+
parent_pf[tmp2] = tmp
360360

361361
pair[2].append(tmp2)
362362
# Find where to insert the partial relation
@@ -368,7 +368,15 @@ def handle_large_pf(pair, large_primes, pairs_used, pf, graph_pf, size_pf, conne
368368
size_pf += 1
369369

370370
else:
371-
if node_component_pf[tmp] != node_component_pf[tmp2]:
371+
parent_tmp = parent_pf[tmp]
372+
while parent_pf[parent_tmp] != parent_tmp:
373+
parent_pf[parent_tmp], parent_tmp = parent_pf[parent_pf[parent_tmp]], parent_pf[parent_tmp]
374+
375+
parent_tmp2 = parent_pf[tmp2]
376+
while parent_pf[parent_tmp2] != parent_tmp2:
377+
parent_pf[parent_tmp2], parent_tmp2 = parent_pf[parent_pf[parent_tmp2]], parent_pf[parent_tmp2]
378+
379+
if parent_tmp != parent_tmp2:
372380
if tmp2[0] in graph_pf[tmp]:
373381
graph_pf[tmp][tmp2[0]].append(tmp2)
374382
else:
@@ -379,10 +387,7 @@ def handle_large_pf(pair, large_primes, pairs_used, pf, graph_pf, size_pf, conne
379387
else:
380388
graph_pf[tmp2][tmp[0]] = [tmp]
381389

382-
connected_components_pf[node_component_pf[tmp]] = connected_components_pf[node_component_pf[tmp]].union(connected_components_pf[node_component_pf[tmp2]])
383-
384-
for node in connected_components_pf[node_component_pf[tmp2]]:
385-
node_component_pf[node] = node_component_pf[tmp]
390+
parent_pf[parent_tmp2] = parent_tmp
386391

387392
pair[2].append(tmp2)
388393

@@ -395,10 +400,9 @@ def handle_large_pf(pair, large_primes, pairs_used, pf, graph_pf, size_pf, conne
395400

396401
else:
397402
path_cycle = find_cycle_pf(graph_pf, [tmp, tmp2])
398-
#path_cycle = DFS_pf(graph_pf,[tmp, tmp2])
399403
if len(path_cycle) < 11: cycle_len[len(path_cycle)-2] += 1
400404
else: cycle_len[-1] += 1
401405
combine_pf(pair,pairs_used,pf,path_cycle,divide_leading,g)
402406
partial_found_pf += 1
403407

404-
return pairs_used, pf, graph_pf, size_pf, index_component_pf, cycle_len, full_found, partial_found_pf
408+
return pairs_used, pf, graph_pf, size_pf, parent_pf, cycle_len, full_found, partial_found_pf

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /