numb 0.184.0 → 0.185.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.184.0
1
+ 0.185.0
data/lib/numb/divisors.rb CHANGED
@@ -472,7 +472,7 @@ class Integer
472
472
  # 56.xgcd(72) #=> [8, 4, -3]
473
473
  #
474
474
  # @param [Integer] b the number `self` is divided by
475
- # @returns [Array<Integer>] GCD, `x`, and `y`
475
+ # @return [Array<Integer>] GCD, `x`, and `y`
476
476
  def xgcd b
477
477
  a = self
478
478
  x, y, u, v = 0, 1, 1, 0
@@ -0,0 +1,113 @@
1
+ # -*- coding: utf-8 -*-
2
+ class Integer
3
+ # Returns the Kronecker symbol for `self`/`b`
4
+ #
5
+ # The Kronecker symbol is an extension of the Jacobi symbol to all
6
+ # integers.
7
+ #
8
+ # 2.kronecker 3 #=> -1
9
+ # -8.kronecker 3 #=> 1
10
+ # 6.kronecker 7 #=> -1
11
+ #
12
+ # @param [Integer] b The "denominator"
13
+ # @return [Integer] -1, 0, 1
14
+ def kronecker b
15
+ # The following algorithm is excerpted from Henri Cohen's A Course
16
+ # in Computational Algebraic Number Theory, 3rd. ed. It appears on
17
+ # page 48, and is entitled "Algorithm 1.4.12 (Kronecker-Binary).
18
+
19
+ # Given a, b ∈ ℤ, this algorithm computes the Kronecker symbol
20
+ # (a/b) (hence the Legendre symbol when b is an odd prime).
21
+ raise ArgumentError unless b.is_a?(Integer)
22
+
23
+ a = self
24
+ # The following Array is a lookup table for computing (-1)^(a^2 -
25
+ # 1)/8 (Cohen, p. 29)
26
+ tab2 = [0, 1, 0, -1, 0, -1, 0, 1]
27
+
28
+ # 1. [Test b = 0] If b = 0, then output 0 if |a| ≠ 1, 1 if |a| = 1
29
+ # and terminate the algorithm
30
+ return a.abs == 1 ? 1 : 0 if b.zero?
31
+
32
+ # 2. [Remove 2's from b] If a and b are both even, output 0 and
33
+ # terminate the algorithm. Otherwise, set v ← 0 and while b is
34
+ # even set v ← v + 1 and b ← b/2. Then if v is even set k ← 1,
35
+ # otherwise set k ← (-1)^(a^2 - 1)/8 (by table lookup, not by
36
+ # computing (a^2 - 1)/8). Finally, if b < 0 set b ← -b, and if in
37
+ # addition a < 0 set k ← -k.
38
+ return 0 if a.even? and b.even?
39
+ v, k = 0, nil
40
+ while b.even?
41
+ v += 1
42
+ b = b.quo(2).to_i
43
+ end
44
+ k = v.even? ? 1 : tab2[a&7]
45
+ if b < 0
46
+ b = -b
47
+ k =-k if a < 0
48
+ end
49
+
50
+ # 3. [Reduce size once] (Here b is odd and b > 0.) Set a ← a mod b
51
+ raise unless b.odd? and b > 0
52
+ a %= b
53
+
54
+ loop do
55
+ # 4. [Finished?] If a = 0, output 0 if b > 1, k if b = 1, and
56
+ # terminate the algorithm
57
+ return (b > 1) ? 0 : k if a.zero?
58
+
59
+ # 5. [Remove powers of 2] Set v ← 0 and, while a is even, set v ←
60
+ # v + 1 and a ← a/2. If v is odd, set k ← (-1)^((b^2 - 1)/8) * k
61
+ v = 0
62
+ while a.even?
63
+ v += 1
64
+ a = a.quo(2).to_i
65
+ end
66
+ k = ((-1)**((b**2).pred.quo 8) * k).to_i if v.odd?
67
+
68
+ # 6. [Subtract and apply reciprocity] (Here a and b are odd.) Set
69
+ # r ← b - a. If r > 0, then set k ← (-1)^((a-1)(b-1)/4) * k (using
70
+ # if statements), b ← a and a ← r, else set a ← -r. Go to step 4.
71
+ raise unless a.odd? and b.odd?
72
+ r = b - a
73
+ if r > 0
74
+ # The optimisation below is from Cohen, p. 29
75
+ k = -k unless (a & b & 2).zero?
76
+ b = a
77
+ a = r
78
+ else
79
+ a = -r
80
+ end
81
+ end
82
+ end
83
+
84
+ # Returns the Legendre symbol for `self`/`p`
85
+ #
86
+ # The Legendre symbol is a multiplicative function with values 1,
87
+ # −1, 0: its value on a (nonzero) quadratic residue mod `p` is 1 and
88
+ # on a quadratic non-residue is −1. It is defined only when `p` is
89
+ # an odd prime.
90
+ #
91
+ # 12345.legendre 331 #=> -1
92
+ # 0.legendre 83 #=> 0
93
+ # 55.legendre 10 #=> nil
94
+ # 6.legendre 7 #=> -1
95
+ #
96
+ # @param [Integer] p The "denominator"
97
+ # @return [Integer, nil] -1, 0, 1, or `nil`
98
+ def legendre p
99
+ kronecker(p) if p.odd? and p > 2 and p.prime?
100
+ end
101
+
102
+ # Returns the Jacobi symbol for `a`/`n`
103
+ #
104
+ # For any integer `a` and any positive odd integer `n` the Jacobi
105
+ # symbol is defined as the product of the Legendre symbols
106
+ # corresponding to the prime factors of `n`.
107
+ #
108
+ # @param [Integer] p The "denominator"
109
+ # @return [Integer, nil] -1, 0, 1, or `nil`
110
+ def jacobi n
111
+ kronecker(n) if n.odd? and n > 0
112
+ end
113
+ end
@@ -0,0 +1,65 @@
1
+ # -*- coding: utf-8 -*-
2
+ describe Integer, "#jacobi" do
3
+
4
+ @seq = {
5
+ # A165591
6
+ 59701 => [0,1,-1,1,1,1,-1,-1,-1,1,-1,1,1,-1,1,1,1,-1,-1,-1,
7
+ 1,-1,-1,1,-1,1,1,1,-1,-1,-1,-1,-1,1,1,-1,1,-1,1,
8
+ -1,-1,1,1,1,1,1,-1,-1,1,1,-1,-1,-1,-1,-1,1,1,-1,1,
9
+ -1,1,-1,1,-1,1,-1,-1,1,-1,1,1,-1,-1,-1,1,1,-1,-1,
10
+ 1,-1,1],
11
+ # A165596
12
+ 59881 => [0,1,1,1,1,1,1,-1,1,1,1,-1,1,1,-1,1,1,-1,1,-1,1,
13
+ -1,-1,1,1,1,1,1,-1,1,1,1,1,-1,-1,-1,1,-1,-1,1,1,1,
14
+ -1,1,-1,1,1,1,1,1,1,-1,1,1,1,-1,-1,-1,1,-1,1,-1,1,
15
+ -1,1,1,-1,-1,-1,1,-1,-1,1,-1,-1,1,-1,1,1,-1,1,1,1,
16
+ 1,-1,-1],
17
+ }
18
+
19
+ @seq.each do |a, ns|
20
+ ns.each_with_index do |j, n|
21
+ it "returns #{j} for #{a}.jacobi(#{n})" do
22
+ n.jacobi(a).should == j
23
+ end
24
+ end
25
+ end
26
+
27
+ # A077009
28
+ [1,-1,1,-1,0,-1,1,1,1,-1,0,-1,0,0,1,-1,-1,-1,1,0,
29
+ 1,-1,0,-1,0,-1,1,0,0,-1,1,0,-1,-1,1,-1,1,0,1,-1,0,
30
+ -1,1,1,1,-1,0,1,1,0,1,-1,0,-1,1,0,1,1,0,1,0,-1,0,
31
+ -1,0,-1,1,0,1,-1,1,-1,-1,0,1,-1,0,0,1,1,1,-1,0,-1,
32
+ 0,0,1,0,-1,-1,1,0,1,1,0,-1,1,0,1,-1].each_with_index do |j, n|
33
+ n = (2 * n).succ
34
+ a = n.φ
35
+ it "returns #{j} for #{a}.jacobi(#{n})" do
36
+ a.jacobi(n).should == j
37
+ end
38
+ end
39
+
40
+ # A077010
41
+ [1,1,1,1,1,1,1,0,1,1,-1,1,1,1,1,1,0,1,1,-1,1,1,0,
42
+ 1,1,0,1,1,-1,1,1,-1,-1,1,0,1,1,1,1,1,1,1,1,0,1,0,
43
+ -1,0,1,0,1,1,0,1,1,-1,1,1,0,1,1,0,1,1,-1,1,1,0,1,
44
+ 1,0,1,0,0,1,1,0,1,1,0,-1,1,0,1,1,-1,1,-1,0,1,1,-1,
45
+ 1,1,1,1,1,0,1,1].each_with_index do |j, n|
46
+ n = (2 * n).succ
47
+ a = n.σ
48
+ it "returns #{j} for #{a}.jacobi(#{n})" do
49
+ a.jacobi(n).should == j
50
+ end
51
+ end
52
+
53
+ [2, 10, -4, 0].each do |n|
54
+ 10.times do |a|
55
+ it "returns nil for #{a}.jacobi(#{n})" do
56
+ a.jacobi(n).should be_nil
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+
63
+
64
+
65
+
@@ -0,0 +1,76 @@
1
+ describe Integer, "#kronecker" do
2
+ @seq = {
3
+ # A109017
4
+ -6 => [0,1,0,0,0,1,0,1,0,0,0,1,0,-1,0,0,0,-1,0,-1,0,0,0,
5
+ -1,0,1,0,0,0,1,0,1,0,0,0,1,0,-1,0,0,0,-1,0,-1,0,0,
6
+ 0,-1,0,1,0,0,0,1,0,1,0,0,0,1,0,-1,0,0,0,-1,0,-1,0,
7
+ 0,0,-1,0,1,0,0,0,1,0,1,0,0,0,1,0,-1,0,0,0,-1,0,-1,
8
+ 0,0,0,-1,0,1,0,0,0,1,0,1,0].map.with_index,
9
+ # -5..-2 are extracted from <http://mathworld.wolfram.com/KroneckerSymbol.html>
10
+ -5 => [1, -1, 1, 1, 0, -1, 1, -1, 1, 0, -1, 1, -1, -1, 0, 1, -1,
11
+ -1, -1, 0].map.with_index(1),
12
+ -4 => [1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0,
13
+ -1, 0].map.with_index(1),
14
+ -3 => [1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0,
15
+ 1, -1].map.with_index(1),
16
+ -2 => [1, 0, 1, 0, -1, 0, -1, 0, 1, 0, 1, 0, -1, 0, -1, 0, 1, 0,
17
+ 1, 0].map.with_index(1),
18
+ # A034947
19
+ -1 => [1,1,-1,1,1,-1,-1,1,1,1,-1,-1,1,-1,-1,1,1,1,-1,1,
20
+ 1,-1,-1,-1,1,1,-1,-1,1,-1,-1,1,1,1,-1,1,1,-1,-1,1,
21
+ 1,1,-1,-1,1,-1,-1,-1,1,1,-1,1,1,-1,-1,-1,1,1,-1,
22
+ -1,1,-1,-1,1,1,1,-1,1,1,-1,-1,1,1,1,-1,-1,1,-1,-1,
23
+ 1,1].map.with_index(1),
24
+ # 0..1 are extracted from <http://mathworld.wolfram.com/KroneckerSymbol.html>
25
+ 0 => [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
26
+ 0].map.with_index(1),
27
+ 1 => [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1].map.with_index(1),
28
+ # A091337
29
+ 2 => [1,0,-1,0,-1,0,1,0,1,0,-1,0,-1,0,1,0,1,0,-1,0,-1,
30
+ 0,1,0,1,0,-1,0,-1,0,1,0,1,0,-1,0,-1,0,1,0,1,0,-1,
31
+ 0,-1,0,1,0,1,0,-1,0,-1,0,1,0,1,0,-1,0,-1,0,1,0,1,
32
+ 0,-1,0,-1,0,1,0,1,0,-1,0,-1,0,1,0,1,0,-1,0,-1,0,1,
33
+ 0,1,0,-1,0,-1,0,1,0,1,0,-1,0,-1,0,1,0,1].map.with_index(1),
34
+ # A091338
35
+ 3 => [1,-1,0,1,-1,0,-1,-1,0,1,1,0,1,1,0,1,-1,0,-1,-1,0,
36
+ -1,1,0,1,-1,0,-1,-1,0,-1,-1,0,1,1,0,1,1,0,1,-1,0,
37
+ -1,1,0,-1,1,0,1,-1,0,1,-1,0,-1,1,0,1,1,0,1,1,0,1,
38
+ -1,0,-1,-1,0,-1,1,0,1,-1,0,-1,-1,0,-1,-1,0,1,1,0,
39
+ 1,1,0,-1,-1,0,-1,1,0,-1,1,0,1,-1,0,1,-1,0].map.with_index(1),
40
+ # A080891
41
+ 5 => [0,1,-1,-1,1,0,1,-1,-1,1,0,1,-1,-1,1,0,1,-1,-1,1,
42
+ 0,1,-1,-1,1,0,1,-1,-1,1,0,1,-1,-1,1,0,1,-1,-1,1,0,
43
+ 1,-1,-1,1,0,1,-1,-1,1,0,1,-1,-1,1,0,1,-1,-1,1,0,1,
44
+ -1,-1,1,0,1,-1,-1,1,0,1,-1,-1,1,0,1,-1,-1,1,0,1,
45
+ -1,-1,1,0,1,-1,-1,1,0,1,-1,-1,1,0,1,-1,-1,1,0].map.with_index,
46
+ # The below is extracted from <http://mathworld.wolfram.com/KroneckerSymbol.html>
47
+ 6 => [1, 0, 0, 0, 1, 0, -1, 0, 0, 0, -1, 0, -1, 0, 0, 0, -1, 0, 1,
48
+ 0].map.with_index(1)
49
+ }
50
+
51
+ @seq.each do |a, bs|
52
+ bs.each do |k, b|
53
+ it "returns #{k} for #{a}.kronecker(#{b})" do
54
+ a.kronecker(b).should == k
55
+ end
56
+ end
57
+ end
58
+
59
+ # A071935, A071936
60
+ [1,-1,1,1,1,-1,1,1,1,-1,-1,1,1,-1,1,1,1,-1,1,1,1,
61
+ -1,-1,1,1,-1,-1,1,1,-1,1,1,1,-1,1,1,1,-1,1,1,1,-1,
62
+ -1,1,1,-1,-1,1,1,-1,1,1,1,-1,-1,1,1,-1,-1,1,1,-1,
63
+ 1,1,1,-1,1,1,1,-1,1,1,1,-1,-1,1,1,-1,1,1,1,-1,1,1,
64
+ 1,-1,-1,1,1,-1,-1,1,1,-1,-1,1,1,-1,1,1,1,-1,1,1,1,
65
+ -1,-1].map.with_index(1){|k, n| [n, n.succ, k]} + \
66
+ [1,-1,1,1,1,1,1,1,1,-1,1,1,1,1,1,1,1,-1,1,1,1,1,1,
67
+ 1,1,-1,1,1,1,1,1,1,1,-1,1,1,1,1,1,1,1,-1,1,1,1,1,
68
+ 1,1,1,-1,1,1,1,1,1,1,1,-1,1,1,1,1,1,1,1,-1,1,1,1,
69
+ 1,1,1,1,-1,1,1,1,1,1,1,1,-1,1,1,1,1,1,1,1,-1,1,1,
70
+ 1,1,1,1,1,-1,1,1,1,1,1,1,1,-1,1,1,1,1,1,1,1,-1,1,
71
+ 1,1,1,1,1].map.with_index(1){|k, n| [n.succ, n, k]}.each do |a, b, k|
72
+ it "returns #{k} for #{a}.kronecker(#{b})" do
73
+ a.kronecker(b).should == k
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,142 @@
1
+ describe Integer, "#legendre" do
2
+
3
+ @seq = {
4
+ # A011582
5
+ 11 => [0,1,-1,1,1,1,-1,-1,-1,1,-1,0,1,-1,1,1,1,-1,-1,-1,
6
+ 1,-1,0,1,-1,1,1,1,-1,-1,-1,1,-1,0,1,-1,1,1,1,-1,
7
+ -1,-1,1,-1,0,1,-1,1,1,1,-1,-1,-1,1,-1,0,1,-1,1,1,
8
+ 1,-1,-1,-1,1,-1,0,1,-1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,1,1,-1,-1,-1,-1,1,-1,1,1,-1,1,1,1,
112
+ -1,-1,-1,1],
113
+ # A165586
114
+ 514229 => [0,1,-1,-1,1,1,1,1,-1,1,-1,1,-1,1,-1,-1,1,1,-1,-1,
115
+ 1,-1,-1,1,1,1,-1,-1,1,1,1,1,-1,-1,-1,1,1,1,1,-1,
116
+ -1,-1,1,1,1,1,-1,1,-1,1,-1,-1,1,-1,1,1,-1,1,-1,-1,
117
+ -1,1,-1,1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,
118
+ 1,1,1,1],
119
+ # A165581
120
+ 524287 => [0,1,1,-1,1,-1,-1,-1,1,1,-1,-1,-1,1,-1,1,1,-1,1,
121
+ -1,-1,1,-1,-1,-1,1,1,-1,-1,1,1,1,1,1,-1,1,1,1,-1,
122
+ -1,-1,1,1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,-1,1,-1,1,1,
123
+ 1,1,-1,1,-1,1,-1,1,1,-1,1,1,1,1,1,1,-1,-1,1,-1,1,
124
+ -1,1,1,-1],
125
+ }
126
+
127
+ @seq.each do |p, as|
128
+ as.each_with_index do |l, a|
129
+ it "returns #{l} for #{a}.legendre(#{p})" do
130
+ a.legendre(p).should == l
131
+ end
132
+ end
133
+ end
134
+
135
+ [1, 2, 4].each do |b|
136
+ 100.times do |a|
137
+ it "returns nil for #{a}.legendre(#{b})" do
138
+ a.legendre(b).should be_nil
139
+ end
140
+ end
141
+ end
142
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 184
7
+ - 185
8
8
  - 0
9
- version: 0.184.0
9
+ version: 0.185.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Run Paint Run Run
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-17 00:00:00 +01:00
17
+ date: 2010-10-18 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -110,6 +110,7 @@ files:
110
110
  - lib/numb/keith.rb
111
111
  - lib/numb/knodel.rb
112
112
  - lib/numb/knuth.rb
113
+ - lib/numb/kronecker.rb
113
114
  - lib/numb/kynea.rb
114
115
  - lib/numb/lah.rb
115
116
  - lib/numb/leonardo.rb
@@ -286,14 +287,17 @@ files:
286
287
  - spec/numb/interprime_spec.rb
287
288
  - spec/numb/inv_mod_spec.rb
288
289
  - spec/numb/isqrt_spec.rb
290
+ - spec/numb/jacobi_spec.rb
289
291
  - spec/numb/jacobsthal_lucas_spec.rb
290
292
  - spec/numb/k_perfect_spec.rb
291
293
  - spec/numb/kaprekar_spec.rb
292
294
  - spec/numb/keith_spec.rb
293
295
  - spec/numb/knodel_spec.rb
294
296
  - spec/numb/knuth_spec.rb
297
+ - spec/numb/kronecker_spec.rb
295
298
  - spec/numb/kynea_spec.rb
296
299
  - spec/numb/lah_spec.rb
300
+ - spec/numb/legendre_spec.rb
297
301
  - spec/numb/leonardo_spec.rb
298
302
  - spec/numb/leyland_spec.rb
299
303
  - spec/numb/liouville_spec.rb
@@ -477,6 +481,7 @@ test_files:
477
481
  - spec/numb/woodall_spec.rb
478
482
  - spec/numb/unitary_sociable_spec.rb
479
483
  - spec/numb/refactorable_spec.rb
484
+ - spec/numb/kronecker_spec.rb
480
485
  - spec/numb/maris_mcgwire_sosa_pair_spec.rb
481
486
  - spec/numb/zeisel_spec.rb
482
487
  - spec/numb/q_spec.rb
@@ -589,6 +594,7 @@ test_files:
589
594
  - spec/numb/amicable_spec.rb
590
595
  - spec/numb/bell_spec.rb
591
596
  - spec/numb/super_catalan_spec.rb
597
+ - spec/numb/legendre_spec.rb
592
598
  - spec/numb/motzkin_spec.rb
593
599
  - spec/numb/mobius_spec.rb
594
600
  - spec/numb/chen_prime_spec.rb
@@ -628,6 +634,7 @@ test_files:
628
634
  - spec/numb/nsw_spec.rb
629
635
  - spec/numb/knuth_spec.rb
630
636
  - spec/numb/first_with_n_divisors_spec.rb
637
+ - spec/numb/jacobi_spec.rb
631
638
  - spec/numb/isqrt_spec.rb
632
639
  - spec/numb/inrt_spec.rb
633
640
  - spec/numb/nexus_spec.rb