Skip to content

Commit 6f0fba2

Browse files
committed
new file: Math/powerfree_divisors.sf
1 parent 62aab90 commit 6f0fba2

File tree

6 files changed

+52
-8
lines changed

6 files changed

+52
-8
lines changed

Math/continued_fraction_factorization_method.sf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func check_factor (n, g, factors) {
7575
func next_multiplier (k) {
7676
k += 2
7777

78-
while (!k.is_square_free) {
78+
while (!k.is_squarefree) {
7979
++k
8080
}
8181

Math/digamma_function.sf

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#!/usr/bin/ruby
22

33
# Daniel "Trizen" Șuteu
4-
# License: GPLv3
54
# Date: 14 December 2016
65
# https://github.com/trizen
76

8-
# Implementation for the digamma(n) function.
7+
# Simple implementation of the digamma(n) function.
98

109
# See also:
1110
# https://en.wikipedia.org/wiki/Digamma_function
@@ -18,4 +17,11 @@ func digamma(n) {
1817
})
1918
}
2019

21-
say digamma(100) #=> 4.60016185273808740019860558557585072686681279076853
20+
func digamma_from_harmonic(n) {
21+
-γ + ::sum(1 ..^ n, { |k|
22+
1/k
23+
})
24+
}
25+
26+
say digamma(100) #=> 4.60016185273808740019860558557585072686681279076853
27+
say digamma_from_harmonic(100) #=> 4.60016185273808740019860558557585072686681279076853

Math/farey_factorization_method.sf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func check_factor (n, g, factors) {
6565
func next_multiplier (k) {
6666
k += 2
6767

68-
while (!k.is_square_free) {
68+
while (!k.is_squarefree) {
6969
++k
7070
}
7171

Math/is_prob_squarefree.sf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func find_random_factor(n, small=true, trial=false) {
5454
func is_prob_squarefree(r, tries=50) {
5555

5656
if (r.len <= 50) {
57-
return r.is_square_free
57+
return r.is_squarefree
5858
}
5959

6060
return false if r.is_power
@@ -79,7 +79,7 @@ func is_prob_squarefree(r, tries=50) {
7979
var len = r.len
8080

8181
if (len <= 50) {
82-
return r.is_square_free
82+
return r.is_squarefree
8383
}
8484

8585
if (len <= 10_000) {
@@ -97,7 +97,7 @@ func is_prob_squarefree(r, tries=50) {
9797
return false
9898
}
9999

100-
p.is_square_free || return false
100+
p.is_squarefree || return false
101101

102102
p.factor.each { |z|
103103
if (z*z `divides` r) {

Math/powerfree_divisors.sf

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/ruby
2+
3+
# Daniel "Trizen" Șuteu
4+
# Date: 05 October 2021
5+
# https://github.com/trizen
6+
7+
# Generate all the k-powerfree divisors of n.
8+
9+
func powerfree_divisors (n, k=2) {
10+
11+
var d = [1]
12+
var pp = n.factor_exp
13+
14+
for p,e in (pp) {
15+
16+
e = min(e, k-1)
17+
18+
var r = 1
19+
d << gather {
20+
e.times {
21+
r *= p
22+
d.each { |u|
23+
take(u*r)
24+
}
25+
}
26+
}...
27+
}
28+
29+
d.sort
30+
}
31+
32+
say powerfree_divisors(5040, 2)
33+
say powerfree_divisors(5040, 3)
34+
35+
__END__
36+
[1, 2, 3, 5, 6, 7, 10, 14, 15, 21, 30, 35, 42, 70, 105, 210]
37+
[1, 2, 3, 4, 5, 6, 7, 9, 10, 12, 14, 15, 18, 20, 21, 28, 30, 35, 36, 42, 45, 60, 63, 70, 84, 90, 105, 126, 140, 180, 210, 252, 315, 420, 630, 1260]

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ A nice collection of day-to-day Sidef scripts.
444444
* [Pomerance condition for bpsw counter-example](./Math/pomerance_condition_for_bpsw_counter-example.sf)
445445
* [Power of 2 plus 3 primes lucas-lehmer](./Math/power_of_2_plus_3_primes_lucas-lehmer.sf)
446446
* [Power of 2 plus 5 primes lucas-lehmer](./Math/power_of_2_plus_5_primes_lucas-lehmer.sf)
447+
* [Powerfree divisors](./Math/powerfree_divisors.sf)
447448
* [Primality precheck](./Math/primality_precheck.sf)
448449
* [Primality testing fermat fourier](./Math/primality_testing_fermat_fourier.sf)
449450
* [Primality testing wilson fourier](./Math/primality_testing_wilson_fourier.sf)

0 commit comments

Comments
 (0)