figurate_numbers 1.4.1 β†’ 1.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a19370a4ba2a14d8dad926f3041c2f3f13be439c9b983b6a8d917ce796ad3342
4
- data.tar.gz: dd218f8d7c47aa04945175c694ee46f8e899d310d8601dca7e46d12d87367b8f
3
+ metadata.gz: a286c4ec17f817140054ae0c0b0aba3b3b7f8a47204fb4813eba687f6e1cba15
4
+ data.tar.gz: 85f689294ce5b0e7fc30a06ba001cb7dda5d8fb70bbcfa92e5e5ecc249540607
5
5
  SHA512:
6
- metadata.gz: 2c7cad43ef8f91511a91517077f6e709f7692c6039731203084190f562e774544ad391f7faf245b1e206392fffff5f8b2b1bbbf64fc511e7c4abbcfd4c15b5f3
7
- data.tar.gz: a6f5862ee08fe407786f8145a8412129a02d5d310980c97db00ea00d8073d0ba0562dd513fb6346420d17f65da3273255d6b078d54bd57aec408e40a18542933
6
+ metadata.gz: c9ca9a1809ea6760cf8e2d6bcfead0eabc270bcfc2678e8c891921376514405d32d59e90a1187b4143e983f865765d9cfe258df736b93630189dbd695fabea1e
7
+ data.tar.gz: bacbbc4997f8da85f48962149a9b118bd1f857843c41d0a43e085560540ac4770b3ed10439758e7214e14007643bd05ac7a919d3fcfe58c9d668e610e584c91c
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Edgar Armando Delgado Vega
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/docs/ERRATA.md ADDED
@@ -0,0 +1,71 @@
1
+ # Errata
2
+
3
+ - **Chapter 1, page 6:**
4
+ The formula for *Square* in the table is given as:
5
+ `1/2 (n^2 - 0 * n)`
6
+ It should be corrected to:
7
+ `1/2 (2n^2 - 0 * n)`
8
+
9
+ - **Chapter 1, page 51:**
10
+ The formula for *Centered icosihexagonal* numbers is listed as:
11
+ `1/3n^2 - 13n + 1`
12
+ with values `546, 728, 936, 1170`.
13
+ The correct formula and values are:
14
+ `13n^2 - 13n + 1`
15
+ with values `547, 729, 937, 1171`.
16
+
17
+ - **Chapter 1, page 51:**
18
+ The value for *Centered icosiheptagonal* number is given as `972`.
19
+ The correct value is `973`.
20
+
21
+ - **Chapter 1, page 51:**
22
+ The value for *Centered icosioctagonal* number is given as `84`.
23
+ The correct value is `85`.
24
+
25
+ - **Chapter 1, page 65:**
26
+ The term *polite numbers* is misspelled as:
27
+ `inpolite numbers`
28
+ It should read:
29
+ `impolite numbers`
30
+
31
+ - **Chapter 1, page 72:**
32
+ The formula for truncated centered pentagonal numbers (TCSS_5) is:
33
+ `TCSS_5(n) = (35n^2 - 55n) / 2 + 3`
34
+ It should be:
35
+ `TCSS_5(n) = (35n^2 - 55n) / 2 + 11`
36
+
37
+ - **Chapter 2, page 92:**
38
+ The formula for octagonal pyramidal numbers is stated as:
39
+ `n(n+1)(6n-1) / 6`
40
+ The correct formula is:
41
+ `n(n+1)(6n-3) / 6`
42
+
43
+ - **Chapter 2, page 140:**
44
+ The sequence for centered square pyramidal numbers is listed as:
45
+ `1, 6, 19, 44, 85, 111, 146, 231, ...`
46
+ The number `111` should be excluded, resulting in:
47
+ `1, 6, 19, 44, 85, 146, 231, ...`
48
+
49
+ - **Chapter 2, page 155:**
50
+ The formula for generalized centered tetrahedron numbers (S_3^3) is:
51
+ `S_3^3(n) = ((2n - 1)(n^2 + n + 3)) / 3`
52
+ It should include a negative sign:
53
+ `S_3^3(n) = ((2n - 1)(n^2 - n + 3)) / 3`
54
+
55
+ - **Chapter 2, page 156:**
56
+ The formula for generalized centered square pyramid numbers (S_4^3) is:
57
+ `S_4^3(n) = ((2n - 1)(n^2 - n + 2)^2) / 3`
58
+ The correct formula is:
59
+ `S_4^3(n) = ((2n - 1)(n^2 - n + 2)) / 2`
60
+
61
+ - **Chapter 3, page 188:**
62
+ The term *hyperoctahedral numbers* is incorrectly called:
63
+ `hexadecahoron numbers`
64
+ It should be:
65
+ `hexadecachoron numbers`
66
+
67
+ - **Chapter 3, page 190:**
68
+ The term *hypericosahedral numbers* is incorrectly written as:
69
+ `hexacisihoron numbers`
70
+ It should be:
71
+ `hexacosichoron numbers`
data/docs/METHODS.md ADDED
@@ -0,0 +1,274 @@
1
+ # List of Sequences in `figurate_numbers` and Arithmetic Transformations Methods
2
+
3
+ ### Table of Contents
4
+ - 🟦 [Plane Figurate Numbers](#1-plane-figurate-numbers)
5
+ - πŸŸ₯ [Space Figurate Numbers](#2-space-figurate-numbers)
6
+ - 🟨 [Multidimensional Figurate Numbers](#3-multidimensional-figurate-numbers)
7
+ - 🧬 [Zoo of figurate-related numbers](#4-zoo-of-figurate-related-numbers)
8
+ - βš™οΈ [Arithmetic Transformations](#5-arithmetic-transformations)
9
+
10
+ > Note that `=` means that you can call the same sequence with different names.
11
+
12
+ ## 1. Plane Figurate Numbers
13
+
14
+ 1. `polygonal(m)`
15
+ 2. `triangular`
16
+ 3. `square`
17
+ 4. `pentagonal`
18
+ 5. `hexagonal`
19
+ 6. `heptagonal`
20
+ 7. `octagonal`
21
+ 8. `nonagonal`
22
+ 9. `decagonal`
23
+ 10. `hendecagonal`
24
+ 11. `dodecagonal`
25
+ 12. `tridecagonal`
26
+ 13. `tetradecagonal`
27
+ 14. `pentadecagonal`
28
+ 15. `hexadecagonal`
29
+ 16. `heptadecagonal`
30
+ 17. `octadecagonal`
31
+ 18. `nonadecagonal`
32
+ 19. `icosagonal`
33
+ 20. `icosihenagonal`
34
+ 21. `icosidigonal`
35
+ 22. `icositrigonal`
36
+ 23. `icositetragonal`
37
+ 24. `icosipentagonal`
38
+ 25. `icosihexagonal`
39
+ 26. `icosiheptagonal`
40
+ 27. `icosioctagonal`
41
+ 28. `icosinonagonal`
42
+ 29. `triacontagonal`
43
+ 30. `centered_triangular`
44
+ 31. `centered_square` = `diamond` (equality only by quantity)
45
+ 32. `centered_pentagonal`
46
+ 33. `centered_hexagonal`
47
+ 34. `centered_heptagonal`
48
+ 35. `centered_octagonal`
49
+ 36. `centered_nonagonal`
50
+ 37. `centered_decagonal`
51
+ 38. `centered_hendecagonal`
52
+ 39. `centered_dodecagonal` = `star` (equality only by quantity)
53
+ 40. `centered_tridecagonal`
54
+ 41. `centered_tetradecagonal`
55
+ 42. `centered_pentadecagonal`
56
+ 43. `centered_hexadecagonal`
57
+ 44. `centered_heptadecagonal`
58
+ 45. `centered_octadecagonal`
59
+ 46. `centered_nonadecagonal`
60
+ 47. `centered_icosagonal`
61
+ 48. `centered_icosihenagonal`
62
+ 49. `centered_icosidigonal`
63
+ 50. `centered_icositrigonal`
64
+ 51. `centered_icositetragonal`
65
+ 52. `centered_icosipentagonal`
66
+ 53. `centered_icosihexagonal`
67
+ 54. `centered_icosiheptagonal`
68
+ 55. `centered_icosioctagonal`
69
+ 56. `centered_icosinonagonal`
70
+ 57. `centered_triacontagonal`
71
+ 58. `centered_mgonal(m)`
72
+ 59. `pronic` = `heteromecic` = `oblong`
73
+ 60. `polite`
74
+ 61. `impolite`
75
+ 62. `cross`
76
+ 63. `aztec_diamond`
77
+ 64. `polygram(m)` = `centered_star_polygonal(m)`
78
+ 65. `pentagram`
79
+ 66. `gnomic`
80
+ 67. `truncated_triangular`
81
+ 68. `truncated_square`
82
+ 69. `truncated_pronic`
83
+ 70. `truncated_centered_pol(m)` = `truncated_centered_mgonal(m)`
84
+ 71. `truncated_centered_triangular`
85
+ 72. `truncated_centered_square`
86
+ 73. `truncated_centered_pentagonal`
87
+ 74. `truncated_centered_hexagonal` = `truncated_hex`
88
+ 75. `generalized_mgonal(m, left_index = 0)`
89
+ 76. `generalized_pentagonal(left_index = 0)`
90
+ 77. `generalized_hexagonal(left_index = 0)`
91
+ 78. `generalized_centered_pol(m, left_index = 0)`
92
+ 79. `generalized_pronic(left_index = 0)`
93
+
94
+ ## 2. Space Figurate Numbers
95
+
96
+ 1. `r_pyramidal(r)`
97
+ 2. `triangular_pyramidal = tetrahedral`
98
+ 3. `square_pyramidal = pyramidal`
99
+ 4. `pentagonal_pyramidal`
100
+ 5. `hexagonal_pyramidal`
101
+ 6. `heptagonal_pyramidal`
102
+ 7. `octagonal_pyramidal`
103
+ 8. `nonagonal_pyramidal`
104
+ 9. `decagonal_pyramidal`
105
+ 10. `hendecagonal_pyramidal`
106
+ 11. `dodecagonal_pyramidal`
107
+ 12. `tridecagonal_pyramidal`
108
+ 13. `tetradecagonal_pyramidal`
109
+ 14. `pentadecagonal_pyramidal`
110
+ 15. `hexadecagonal_pyramidal`
111
+ 16. `heptadecagonal_pyramidal`
112
+ 17. `octadecagonal_pyramidal`
113
+ 18. `nonadecagonal_pyramidal`
114
+ 19. `icosagonal_pyramidal`
115
+ 20. `icosihenagonal_pyramidal`
116
+ 21. `icosidigonal_pyramidal`
117
+ 22. `icositrigonal_pyramidal`
118
+ 23. `icositetragonal_pyramidal`
119
+ 24. `icosipentagonal_pyramidal`
120
+ 25. `icosihexagonal_pyramidal`
121
+ 26. `icosiheptagonal_pyramidal`
122
+ 27. `icosioctagonal_pyramidal`
123
+ 28. `icosinonagonal_pyramidal`
124
+ 29. `triacontagonal_pyramidal`
125
+ 30. `triangular_tetrahedral [finite]`
126
+ 31. `triangular_square_pyramidal [finite]`
127
+ 32. `square_tetrahedral [finite]`
128
+ 33. `square_square_pyramidal [finite]`
129
+ 34. `tetrahedral_square_pyramidal_number [finite]`
130
+ 35. `cubic = perfect_cube != hex_pyramidal (equality only by quantity)`
131
+ 36. `tetrahedral`
132
+ 37. `octahedral`
133
+ 38. `dodecahedral`
134
+ 39. `icosahedral`
135
+ 40. `truncated_tetrahedral`
136
+ 41. `truncated_cubic`
137
+ 42. `truncated_octahedral`
138
+ 43. `stella_octangula`
139
+ 44. `centered_cube`
140
+ 45. `rhombic_dodecahedral`
141
+ 46. `hauy_rhombic_dodecahedral`
142
+ 47. `centered_tetrahedron = centered_tetrahedral`
143
+ 48. `centered_square_pyramid = centered_pyramid`
144
+ 49. `centered_mgonal_pyramid(m)`
145
+ 50. `centered_pentagonal_pyramid != centered_octahedron (equality only in quantity)`
146
+ 51. `centered_hexagonal_pyramid`
147
+ 52. `centered_heptagonal_pyramid`
148
+ 53. `centered_octagonal_pyramid`
149
+ 54. `centered_octahedron`
150
+ 55. `centered_icosahedron = centered_cuboctahedron`
151
+ 56. `centered_dodecahedron`
152
+ 57. `centered_truncated_tetrahedron`
153
+ 58. `centered_truncated_cube`
154
+ 59. `centered_truncated_octahedron`
155
+ 60. `centered_mgonal_pyramidal(m)`
156
+ 61. `centered_triangular_pyramidal`
157
+ 62. `centered_square_pyramidal`
158
+ 63. `centered_pentagonal_pyramidal`
159
+ 64. `centered_hexagonal_pyramidal = hex_pyramidal`
160
+ 65. `centered_heptagonal_pyramidal`
161
+ 66. `centered_octagonal_pyramidal`
162
+ 67. `centered_nonagonal_pyramidal`
163
+ 68. `centered_decagonal_pyramidal`
164
+ 69. `centered_hendecagonal_pyramidal`
165
+ 70. `centered_dodecagonal_pyramidal`
166
+ 71. `hexagonal_prism`
167
+ 72. `mgonal_prism(m)`
168
+ 73. `generalized_mgonal_pyramidal(m, left_index = 0)`
169
+ 74. `generalized_pentagonal_pyramidal(left_index = 0)`
170
+ 75. `generalized_hexagonal_pyramidal(left_index = 0)`
171
+ 76. `generalized_cubic(left_index = 0)`
172
+ 77. `generalized_octahedral(left_index = 0)`
173
+ 78. `generalized_icosahedral(left_index = 0)`
174
+ 79. `generalized_dodecahedral(left_index = 0)`
175
+ 80. `generalized_centered_cube(left_index = 0)`
176
+ 81. `generalized_centered_tetrahedron(left_index = 0)`
177
+ 82. `generalized_centered_square_pyramid(left_index = 0)`
178
+ 83. `generalized_rhombic_dodecahedral(left_index = 0)`
179
+ 84. `generalized_centered_mgonal_pyramidal(m, left_index = 0)`
180
+ 85. `generalized_mgonal_prism(m, left_index = 0)`
181
+ 86. `generalized_hexagonal_prism(left_index = 0)`
182
+
183
+ ## 3. Multidimensional figurate numbers
184
+
185
+ 1. `pentatope = hypertetrahedral = triangulotriangular`
186
+ 2. `k_dimensional_hypertetrahedron(k) = k_hypertetrahedron(k) = regular_k_polytopic(k) = figurate_numbers_of_order_k(k)`
187
+ 3. `five_dimensional_hypertetrahedron`
188
+ 4. `six_dimensional_hypertetrahedron`
189
+ 5. `biquadratic`
190
+ 6. `k_dimensional_hypercube(k) = k_hypercube(k)`
191
+ 7. `five_dimensional_hypercube`
192
+ 8. `six_dimensional_hypercube`
193
+ 9. `hyperoctahedral = hexadecachoron = four_cross_polytope = four_orthoplex`
194
+ 10. `hypericosahedral = tetraplex = polytetrahedron = hexacosichoron`
195
+ 11. `hyperdodecahedral = hecatonicosachoron = dodecaplex = polydodecahedron`
196
+ 12. `polyoctahedral = icositetrachoron = octaplex = hyperdiamond`
197
+ 13. `four_dimensional_hyperoctahedron`
198
+ 14. `five_dimensional_hyperoctahedron`
199
+ 15. `six_dimensional_hyperoctahedron`
200
+ 16. `seven_dimensional_hyperoctahedron`
201
+ 17. `eight_dimensional_hyperoctahedron`
202
+ 18. `nine_dimensional_hyperoctahedron`
203
+ 19. `ten_dimensional_hyperoctahedron`
204
+ 20. `k_dimensional_hyperoctahedron(k) = k_cross_polytope(k)`
205
+ 21. `four_dimensional_mgonal_pyramidal(m) = mgonal_pyramidal_numbers_of_the_second_order(m)`
206
+ 22. `four_dimensional_square_pyramidal`
207
+ 23. `four_dimensional_pentagonal_pyramidal`
208
+ 24. `four_dimensional_hexagonal_pyramidal`
209
+ 25. `four_dimensional_heptagonal_pyramidal`
210
+ 26. `four_dimensional_octagonal_pyramidal`
211
+ 27. `four_dimensional_nonagonal_pyramidal`
212
+ 28. `four_dimensional_decagonal_pyramidal`
213
+ 29. `four_dimensional_hendecagonal_pyramidal`
214
+ 30. `four_dimensional_dodecagonal_pyramidal`
215
+ 31. `k_dimensional_mgonal_pyramidal(k, m) = mgonal_pyramidal_of_the_k_2_th_order(k, m)`
216
+ 32. `five_dimensional_mgonal_pyramidal(m)`
217
+ 33. `five_dimensional_square_pyramidal`
218
+ 34. `five_dimensional_pentagonal_pyramidal`
219
+ 35. `five_dimensional_hexagonal_pyramidal`
220
+ 36. `five_dimensional_heptagonal_pyramidal`
221
+ 37. `five_dimensional_octagonal_pyramidal`
222
+ 38. `six_dimensional_mgonal_pyramidal(m)`
223
+ 39. `six_dimensional_square_pyramidal`
224
+ 40. `six_dimensional_pentagonal_pyramidal`
225
+ 41. `six_dimensional_hexagonal_pyramidal`
226
+ 42. `six_dimensional_heptagonal_pyramidal`
227
+ 43. `six_dimensional_octagonal_pyramidal`
228
+ 44. `centered_biquadratic`
229
+ 45. `k_dimensional_centered_hypercube(k)`
230
+ 46. `five_dimensional_centered_hypercube`
231
+ 47. `six_dimensional_centered_hypercube`
232
+ 48. `centered_polytope`
233
+ 49. `k_dimensional_centered_hypertetrahedron(k)`
234
+ 50. `five_dimensional_centered_hypertetrahedron(k)`
235
+ 51. `six_dimensional_centered_hypertetrahedron(k)`
236
+ 52. `centered_hyperoctahedral = orthoplex`
237
+ 53. `nexus(k)`
238
+ 54. `k_dimensional_centered_hyperoctahedron(k)`
239
+ 55. `five_dimensional_centered_hyperoctahedron`
240
+ 56. `six_dimensional_centered_hyperoctahedron`
241
+ 57. `generalized_pentatope(left_index = 0)`
242
+ 58. `generalized_k_dimensional_hypertetrahedron(k = 5, left_index = 0)`
243
+ 59. `generalized_biquadratic(left_index = 0)`
244
+ 60. `generalized_k_dimensional_hypercube(k = 5, left_index = 0)`
245
+ 61. `generalized_hyperoctahedral(left_index = 0)`
246
+ 62. `generalized_k_dimensional_hyperoctahedron(k = 5, left_index = 0) [even or odd dimension only changes sign]`
247
+ 63. `generalized_hyperdodecahedral(left_index = 0)`
248
+ 64. `generalized_hypericosahedral(left_index = 0)`
249
+ 65. `generalized_polyoctahedral(left_index = 0)`
250
+ 66. `generalized_k_dimensional_mgonal_pyramidal(k, m, left_index = 0)`
251
+ 67. `generalized_k_dimensional_centered_hypercube(k, left_index = 0)`
252
+ 68. `generalized_k_dimensional_centered_hypertetrahedron(k, left_index = 0)[provisional symmetry]`
253
+ 69. `generalized_k_dimensional_centered_hyperoctahedron(k, left_index = 0)[provisional symmetry]`
254
+ 70. `generalized_nexus(k, left_index = 0) [even or odd dimension only changes sign]`
255
+
256
+ ### 4. Zoo of figurate-related numbers
257
+
258
+ 1. `cuban_numbers = cuban_prime_numbers`
259
+ 2. `quartan_numbers [Needs to improve the algorithmic complexity for n > 70]`
260
+ 3. `pell_numbers`
261
+ 4. `carmichael_numbers [Needs to improve the algorithmic complexity for n > 20]`
262
+ 4. `stern_prime_numbers(infty = false) [Quick calculations up to 8 terms]`
263
+ 5. `apocalyptic_numbers`
264
+
265
+ ### 5. Arithmetic Transformations
266
+
267
+ 1. `ArithTransform.n_residue(n, pow, mod)`
268
+ 2. `ArithTransform.pc_inversion(n, mod)`
269
+ 3. `ArithTransform.padic_val(n, p)`
270
+ 4. `ArithTransform.ring_padic_val(seq, p)`
271
+ 5. `ArithTransform.padic_norm(n, p)`
272
+ 6. `ArithTransform.ring_padic_norm(seq, p)`
273
+ 7. `ArithTransform.padic_expansion(n, p, precision = 11, reverse: false)`
274
+ 8. `ArithTransform.ring_padic_expansion(seq, p, precision = 11, reverse: false)`
@@ -0,0 +1,47 @@
1
+ require_relative './utils/padic_utils'
2
+ require_relative './utils/modn_utils'
3
+
4
+ module FigurateNumbers
5
+ # Provides arithmetic methods for transforming and analyzing figurate number sequences.
6
+ module ArithTransform
7
+ extend self
8
+
9
+ def n_residue(n, pow, mod)
10
+ ModNUtils.q_residues(n, pow, mod)
11
+ end
12
+
13
+ def pc_inversion(n, mod)
14
+ ModNUtils.inversion(n, mod)
15
+ end
16
+
17
+ def padic_val(n, p)
18
+ PAdicUtils.padic_valuation(n, p)
19
+ end
20
+
21
+ def ring_padic_val(seq, p)
22
+ seq.map do |delta|
23
+ PAdicUtils.padic_valuation(delta, p)
24
+ end
25
+ end
26
+
27
+ def padic_norm(n, p)
28
+ PAdicUtils.padic_norm(n, p)
29
+ end
30
+
31
+ def ring_padic_norm(seq, p)
32
+ seq.map do |delta|
33
+ PAdicUtils.padic_norm(delta, p)
34
+ end
35
+ end
36
+
37
+ def padic_expansion(n, p, precision = 11, reverse: false)
38
+ PAdicUtils.padic_expansion(n, p, precision, reverse)
39
+ end
40
+
41
+ def ring_padic_expansion(seq, p, precision = 11, reverse: false)
42
+ seq.map do |delta|
43
+ PAdicUtils.padic_expansion(delta, p, precision, reverse)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,23 @@
1
+ module FigurateNumbers
2
+ # Provides modular arithmetic methods (mod n) for transforming figurate number sequences.
3
+ module ModNUtils
4
+ extend self
5
+
6
+ def n_power(n, power)
7
+ n.pow(power)
8
+ end
9
+
10
+ def mod_reduc(n, mod)
11
+ n % mod
12
+ end
13
+
14
+ def q_residues(n, power, mod)
15
+ mod_reduc(n_power(n, power), mod)
16
+ end
17
+
18
+ def inversion(n, mod)
19
+ inv = n * -1
20
+ mod_reduc(inv, mod)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,54 @@
1
+ require 'prime'
2
+
3
+ module FigurateNumbers
4
+ # Module providing p-adic methods for transforming
5
+ # sequences of figurate numbers.
6
+ module PAdicUtils
7
+ extend self
8
+
9
+ def padic_valuation(base_ten_number, p)
10
+ raise "#{p} is not a prime number" unless Prime.prime?(p)
11
+
12
+ index = 0
13
+ return index if base_ten_number < 1
14
+
15
+ while base_ten_number % (p**index) == 0 # rubocop:disable Style/NumericPredicate,Style/WhileUntilModifier
16
+ index += 1
17
+ end
18
+ index - 1
19
+ end
20
+
21
+ def padic_norm(base_ten_number, p)
22
+ return 0 if base_ten_number == 0 # rubocop:disable Style/NumericPredicate
23
+
24
+ power = padic_valuation(base_ten_number, p)
25
+ 1.0 / p**power
26
+ end
27
+
28
+ def padic_expansion(base_ten_number, p, precision = 11, reverse_trim = false) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Style/OptionalBooleanParameter
29
+ inverse_limit_arr = []
30
+ (1...precision).each do |index|
31
+ power = p**index
32
+ inverse_limits = ((base_ten_number % power) + power) % power
33
+ inverse_limit_arr << inverse_limits
34
+ end
35
+ p_adic_expansion_array = [inverse_limit_arr[0]]
36
+
37
+ (0...(precision - 2)).each do |index|
38
+ a1 = inverse_limit_arr[index + 1]
39
+ a0 = inverse_limit_arr[index]
40
+ power = p**(index + 1)
41
+ digits = (a1 - a0) / power
42
+ p_adic_expansion_array << digits
43
+ end
44
+
45
+ if reverse_trim
46
+ reversed = p_adic_expansion_array.reverse
47
+ first_nonzero_index = reversed.index { |digit| digit != 0 } || 0
48
+ reversed[first_nonzero_index..-1]
49
+ else
50
+ p_adic_expansion_array
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FigurateNumbers
4
- VERSION = '1.4.1'
4
+ VERSION = '1.5.0'
5
5
  end
@@ -2,13 +2,16 @@ require_relative 'figurate_numbers/version'
2
2
  require_relative 'figurate_numbers/plane_figurate_numbers'
3
3
  require_relative 'figurate_numbers/space_figurate_numbers'
4
4
  require_relative 'figurate_numbers/multidimensional_figurate_numbers'
5
+ require_relative 'figurate_numbers/arith_transform'
5
6
 
6
7
  module FigurateNumbers
7
8
  extend PlaneFigurateNumbers
8
9
  extend SpaceFigurateNumbers
9
10
  extend MultiDimensionalFigurateNumbers
11
+ extend ArithTransform
10
12
  end
11
13
 
12
14
  PlaneFigurateNumbers = FigurateNumbers::PlaneFigurateNumbers
13
15
  SpaceFigurateNumbers = FigurateNumbers::SpaceFigurateNumbers
14
16
  MultiDimensionalFigurateNumbers = FigurateNumbers::MultiDimensionalFigurateNumbers
17
+ ArithTransform = FigurateNumbers::ArithTransform
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: figurate_numbers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edgar Armando Delgado Vega
@@ -18,21 +18,27 @@ email:
18
18
  executables: []
19
19
  extensions: []
20
20
  extra_rdoc_files:
21
- - README.md
21
+ - "./LICENSE"
22
+ - docs/ERRATA.md
23
+ - docs/METHODS.md
22
24
  files:
23
- - README.md
25
+ - "./LICENSE"
26
+ - docs/ERRATA.md
27
+ - docs/METHODS.md
24
28
  - lib/figurate_numbers.rb
29
+ - lib/figurate_numbers/arith_transform.rb
25
30
  - lib/figurate_numbers/multidimensional_figurate_numbers.rb
26
- - lib/figurate_numbers/p_adic_utils/p_adic_utils.rb
27
31
  - lib/figurate_numbers/plane_figurate_numbers.rb
28
32
  - lib/figurate_numbers/space_figurate_numbers.rb
33
+ - lib/figurate_numbers/utils/modn_utils.rb
34
+ - lib/figurate_numbers/utils/padic_utils.rb
29
35
  - lib/figurate_numbers/utils/utils.rb
30
36
  - lib/figurate_numbers/version.rb
31
37
  homepage: https://github.com/edelveart/figurate_numbers
32
38
  licenses:
33
39
  - MIT
34
40
  metadata:
35
- documentation_uri: https://www.rubydoc.info/gems/figurate_numbers
41
+ documentation_uri: https://www.rubydoc.info/gems/figurate_numbers/
36
42
  source_code_uri: https://github.com/edelveart/figurate_numbers/
37
43
  homepage_uri: https://github.com/edelveart/figurate_numbers
38
44
  rdoc_options:
data/README.md DELETED
@@ -1,92 +0,0 @@
1
- <h1 align="center"> Figurate Numbers </h1>
2
-
3
- **Figurate Numbers** is the most comprehensive and specialized library for figurate numbers, developed in Ruby to date.
4
- It implements **241 infinite number sequences** inspired by the groundbreaking work [*Figurate Numbers*](https://books.google.com.pe/books/about/Figurate_Numbers.html?id=ERS7CgAAQBAJ&redir_esc=y) by Elena Deza and Michel Deza, published in 2012.
5
-
6
- <p align="center">
7
- <img src="https://img.shields.io/gem/v/figurate_numbers" alt="Gem Version">
8
- <img src="https://img.shields.io/gem/dt/figurate_numbers" alt="Gem Total Downloads">
9
- <img src="https://img.shields.io/github/stars/edelveart/figurate_numbers" alt="GitHub Repo stars">
10
- <img src="https://img.shields.io/github/license/edelveart/figurate_numbers" alt="GitHub License">
11
- </p>
12
-
13
- [![figurate numbers image](https://raw.githubusercontent.com/edelveart/figurate_numbers/main/figurate_numbers.png)](https://rubygems.org/gems/figurate_numbers)
14
-
15
-
16
- ## πŸ’Ž Installation
17
-
18
- Install it from the gem repository:
19
-
20
- ```rb
21
- gem install figurate_numbers
22
- ```
23
-
24
- ## 🧊 Features
25
-
26
- Figurate Numbers implements 241 infinite sequences using the Enumerator class in Ruby, each categorized by its geometric dimension. It is ideal for use in mathematical modeling, algorithmic composition, and integration with tools like Sonic Pi.
27
-
28
- The sequences are organized following the structure of the *Figurate Numbers* book:
29
-
30
- - 🟦 **PlaneFigurateNumbers** – 79 sequences (2D)
31
- - πŸŸ₯ **SpaceFigurateNumbers** – 86 sequences (3D)
32
- - 🟨 **MultiDimensionalFigurateNumbers** – 70 sequences (4D and beyond)
33
- - 🧬 **Zoo of figurate-related numbers** – 6 additional sequences *(included in the MultiDimensional module)*
34
-
35
- > πŸ“š Explore the detailed list of figurate numbers [here πŸ”.](docs/METHODS.md)
36
-
37
- ## 🧰 How to use in Ruby
38
-
39
- ```rb
40
- require 'figurate_numbers'
41
-
42
- ## Using take(integer)
43
- FigurateNumbers.pentatope.take(10)
44
-
45
- ## Storing and iterating
46
- f = FigurateNumbers.centered_octagonal_pyramid
47
- f.next
48
- f.next
49
- f.next
50
- ```
51
-
52
- Starting with version **1.4.0**, you can also call methods directly from their respective classes. This allows you to work with figurate numbers grouped by their geometric dimension:
53
-
54
- ```rb
55
- PlaneFigurateNumbers.polygonal(3)
56
- SpaceFigurateNumbers.rhombic_dodecahedral
57
- MultiDimensionalFigurateNumbers.six_dimensional_hyperoctahedron
58
- ```
59
-
60
- ## 🎢 How to use in Sonic Pi
61
-
62
- ### Version 1.4.0
63
-
64
- Starting from version **1.4.0**, you can use the library globally through `FigurateNumbers`to access all sequences, or you can use the specific classes mentioned above for separate access.
65
- The main change compared to version **1.3.0** is that you now need to import the file using **require** instead of **run_file**; otherwise, it will not function.
66
-
67
- ```rb
68
- require "<PATH>"
69
- pol_num = FigurateNumbers.polygonal(8)
70
- 350.times do
71
- play pol_num.next % 12 * 7 # Some mathematical function or transformation
72
- sleep 0.125
73
- end
74
- ```
75
-
76
- Simply copy the entry point path from the `lib/figurate_numbers.rb` file where the *gem* is installed.
77
-
78
- ### Version 1.3.0 (legacy)
79
-
80
- See discussion in the [**Sonic Pi community thread right here!**](https://in-thread.sonic-pi.net/t/figurate-numbers-for-sonic-pi-new-ruby-gem-for-infinite-number-sequences-and-patterns/8962)
81
-
82
- ## πŸ“š List of Implemented Sequences in `figurate_numbers`
83
-
84
- Explore the complete list of figurate number sequences and their Ruby methods:
85
-
86
- - [View all implemented methods and sequences πŸ”](docs/METHODS.md)
87
-
88
- ## πŸ“ Book Errata
89
-
90
- Corrections to formulas and data found in *Figurate Numbers* (2012):
91
-
92
- - [See full list of known errata πŸ”](docs/ERRATA.md)
@@ -1,27 +0,0 @@
1
- # module PAdicUtils
2
- # def self.potence(exponent)
3
- # # Este mΓ©todo modificarΓ‘ el arreglo de nΓΊmeros aplicando la potencia
4
- # map { |num| num**exponent }
5
- # end
6
- # def self.p_adic_valuation(base_ten_number, base_p_number)
7
- # m = 0
8
- # return m if base_ten_number < 1
9
- # while base_ten_number % (base_p_number ** m) == 0
10
- # m += 1
11
- # end
12
- # m - 1
13
- # end
14
-
15
- # def self.to_p_adic_valuation(arr, p)
16
- # arr.lazy.collect { |fignum| p_adic_valuation(fignum, p) }
17
- # end
18
- # end
19
-
20
-
21
- # puts PAdicUtils.p_adic_valuation(96, 2)
22
- # # export const pAdicValuation = (baseTenNumber: number, baseNumber: number): number => {
23
- # # let index = 0;
24
- # # if (baseTenNumber < 1) return index;
25
- # # while (baseTenNumber % (baseNumber ** index) === 0) index++;
26
- # # return index - 1;
27
- # # }