-
Notifications
You must be signed in to change notification settings - Fork 0
/
special_factors.sf
61 lines (47 loc) · 1.7 KB
/
special_factors.sf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/ruby
# Find special factors for FactorDB, given a list of numbers.
define(
USE_BATCH_GCD = false
TRIAL_DIVISION = false
TRIAL_LIMIT = 1e7 # trial division limit
)
var seen = Set()
for file in (ARGV) {
var nums = File(file).open_r.lines.map{.nums.last}.grep { defined(_) && (_ > 1e19) }.sort.uniq.grep{!seen.has(_)}
var gcds = (USE_BATCH_GCD ? Math.batch_gcd(nums...).uniq : [])
seen << nums...
for n in (nums) {
#~ var f = [n]\
#~ .map { .cop_factor(100)... }\
#~ .map { .is_prime ? _ : .trial_factor(1e7)... }\
#~ .map { (.is_prime || .len>=200) ? _ : .cyclotomic_factor... }\
#~ .map { .factor { .fermat_factor(1e3) }... }\
#~ .map { .factor { .holf_factor(1e3) }... }\
#~ .map { .factor { .pell_factor(1e3) }... }\
#~ .map { .factor { .flt_factor(1e3) }... }\
#~ .map { .is_prime ? _ : .miller_factor... }\
#~ .map { .is_prime ? _ : .lucas_factor... }\
#~ .map { .factor { .pm1_factor(1e5) }... }\
#~ .map { .factor { .pp1_factor(1e4) }... }\
#~ .map { .factor { .chebyshev_factor(1e4) }... }\
#~ .map { .factor { .dop_factor(200) }... }\
#~ .map { .factor { .cyclotomic_factor(2, 10) }... }
#~ f = Math.gcd_factors(n, f + gcds)
#~ f = f.first(-1)
var f = []
var t = n
if (TRIAL_DIVISION) {
f += TRIAL_LIMIT.smooth_part(n).factor
n = idiv(n, f.prod)
}
f += if (USE_BATCH_GCD) {
Math.gcd_factors(n, gcds + n.special_factors).first(-1)
}
else {
n.special_factors.first(-1)
}
f = f.uniq
f || next
say "#{t} = #{f.join(' * ')}"
}
}