Figurate Numbers
Figurate Numbers is the most comprehensive and specialized gem for figurate numbers written in Ruby to date.
It implements 241 infinite number sequences inspired by the groundbreaking work Figurate Numbers by Elena Deza and Michel Deza, published in 2012.
Installation
Install it from the gem repository:
gem install figurate_numbers
Features
This implementation uses the Enumerator class to handle infinite sequences.
It is intended for use in mathematical projects and with Sonic Pi.
Following the order of the book, the methods are divided into 3 types according to the spatial dimension (see complete list below):
- PlaneFigurateNumbers figurate numbers implemented =
79
- SpaceFigurateNumbers figurate numbers implemented =
86
- MultiDimensionalFigurateNumbers figurate numbers implemented =
70
- Zoo of figurate-related numbers implemented =
6
(included in MultiDimensional module)
How to use in Ruby
require 'figurate_numbers'
FigurateNumbers.pentatope.take(10)
f = FigurateNumbers.centered_octagonal_pyramid
f.next
f.next
f.next
If the sequence is defined with lazy
, to make the numbers explicit we must include the converter method to_a
at the end.
Since version 1.4.0, you can alternatively call from the classes
PlaneFigurateNumbers.polygonal(3)
SpaceFigurateNumbers.rhombic_dodecahedral
MultiDimensionalFigurateNumbers.six_dimensional_hyperoctahedron
This ensures that you only use the numbers belonging to each geometric dimension.
How to use in Sonic Pi
figurate_numbers - Version 1.4.0
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.
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.
require "<PATH>"
Simply copy the entry point path from the lib/figurate_numbers.rb
file where the gem is installed.
figurate_numbers - Version 1.3.0
You can read and comment in the Sonic Pi community thread right here!
- Locate or download the file in the path
lib/figurate_numbers.rb
- Drag the file to a buffer in Sonic Pi (this generates the
<PATH>
)
run_file "<PATH>"
sleep 1
pol_num = FigurateNumbers.polygonal_numbers(8)
80.times do
play pol_num.next % 12 * 7
sleep 0.25
end
sleep 1
#to allow figurate_numbers to complete load and setup otherwise first run can give error (Robin Newman - Sonic Pi Core Team)
List of implemented sequences
- Note that
=
means that you can call the same sequence with different names.
1. Plane Figurate Numbers
polygonal(m)
triangular
square
pentagonal
hexagonal
heptagonal
octagonal
nonagonal
decagonal
hendecagonal
dodecagonal
tridecagonal
tetradecagonal
pentadecagonal
hexadecagonal
heptadecagonal
octadecagonal
nonadecagonal
icosagonal
icosihenagonal
icosidigonal
icositrigonal
icositetragonal
icosipentagonal
icosihexagonal
icosiheptagonal
icosioctagonal
icosinonagonal
triacontagonal
centered_triangular
centered_square
= diamond
(equality only by quantity)centered_pentagonal
centered_hexagonal
centered_heptagonal
centered_octagonal
centered_nonagonal
centered_decagonal
centered_hendecagonal
centered_dodecagonal
= star
(equality only by quantity)centered_tridecagonal
centered_tetradecagonal
centered_pentadecagonal
centered_hexadecagonal
centered_heptadecagonal
centered_octadecagonal
centered_nonadecagonal
centered_icosagonal
centered_icosihenagonal
centered_icosidigonal
centered_icositrigonal
centered_icositetragonal
centered_icosipentagonal
centered_icosihexagonal
centered_icosiheptagonal
centered_icosioctagonal
centered_icosinonagonal
centered_triacontagonal
centered_mgonal(m)
pronic
= heteromecic
= oblong
polite
impolite
cross
aztec_diamond
polygram(m)
= centered_star_polygonal(m)
pentagram
gnomic
truncated_triangular
truncated_square
truncated_pronic
truncated_centered_pol(m)
= truncated_centered_mgonal(m)
truncated_centered_triangular
truncated_centered_square
truncated_centered_pentagonal
truncated_centered_hexagonal
= truncated_hex
generalized_mgonal(m, left_index = 0)
generalized_pentagonal(left_index = 0)
generalized_hexagonal(left_index = 0)
generalized_centered_pol(m, left_index = 0)
generalized_pronic(left_index = 0)
2. Space Figurate Numbers
r_pyramidal(r)
triangular_pyramidal = tetrahedral
square_pyramidal = pyramidal
pentagonal_pyramidal
hexagonal_pyramidal
heptagonal_pyramidal
octagonal_pyramidal
nonagonal_pyramidal
decagonal_pyramidal
hendecagonal_pyramidal
dodecagonal_pyramidal
tridecagonal_pyramidal
tetradecagonal_pyramidal
pentadecagonal_pyramidal
hexadecagonal_pyramidal
heptadecagonal_pyramidal
octadecagonal_pyramidal
nonadecagonal_pyramidal
icosagonal_pyramidal
icosihenagonal_pyramidal
icosidigonal_pyramidal
icositrigonal_pyramidal
icositetragonal_pyramidal
icosipentagonal_pyramidal
icosihexagonal_pyramidal
icosiheptagonal_pyramidal
icosioctagonal_pyramidal
icosinonagonal_pyramidal
triacontagonal_pyramidal
triangular_tetrahedral [finite]
triangular_square_pyramidal [finite]
square_tetrahedral [finite]
square_square_pyramidal [finite]
tetrahedral_square_pyramidal_number [finite]
cubic = perfect_cube != hex_pyramidal (equality only by quantity)
tetrahedral
octahedral
dodecahedral
icosahedral
truncated_tetrahedral
truncated_cubic
truncated_octahedral
stella_octangula
centered_cube
rhombic_dodecahedral
hauy_rhombic_dodecahedral
centered_tetrahedron = centered_tetrahedral
centered_square_pyramid = centered_pyramid
centered_mgonal_pyramid(m)
centered_pentagonal_pyramid != centered_octahedron (equality only in quantity)
centered_hexagonal_pyramid
centered_heptagonal_pyramid
centered_octagonal_pyramid
centered_octahedron
centered_icosahedron = centered_cuboctahedron
centered_dodecahedron
centered_truncated_tetrahedron
centered_truncated_cube
centered_truncated_octahedron
centered_mgonal_pyramidal(m)
centered_triangular_pyramidal
centered_square_pyramidal
centered_pentagonal_pyramidal
centered_hexagonal_pyramidal = hex_pyramidal
centered_heptagonal_pyramidal
centered_octagonal_pyramidal
centered_nonagonal_pyramidal
centered_decagonal_pyramidal
centered_hendecagonal_pyramidal
centered_dodecagonal_pyramidal
hexagonal_prism
mgonal_prism(m)
generalized_mgonal_pyramidal(m, left_index = 0)
generalized_pentagonal_pyramidal(left_index = 0)
generalized_hexagonal_pyramidal(left_index = 0)
generalized_cubic(left_index = 0)
generalized_octahedral(left_index = 0)
generalized_icosahedral(left_index = 0)
generalized_dodecahedral(left_index = 0)
generalized_centered_cube(left_index = 0)
generalized_centered_tetrahedron(left_index = 0)
generalized_centered_square_pyramid(left_index = 0)
generalized_rhombic_dodecahedral(left_index = 0)
generalized_centered_mgonal_pyramidal(m, left_index = 0)
generalized_mgonal_prism(m, left_index = 0)
generalized_hexagonal_prism(left_index = 0)
3. Multidimensional figurate numbers
pentatope = hypertetrahedral = triangulotriangular
k_dimensional_hypertetrahedron(k) = k_hypertetrahedron(k) = regular_k_polytopic(k) = figurate_numbers_of_order_k(k)
five_dimensional_hypertetrahedron
six_dimensional_hypertetrahedron
biquadratic
k_dimensional_hypercube(k) = k_hypercube(k)
five_dimensional_hypercube
six_dimensional_hypercube
hyperoctahedral = hexadecachoron = four_cross_polytope = four_orthoplex
hypericosahedral = tetraplex = polytetrahedron = hexacosichoron
hyperdodecahedral = hecatonicosachoron = dodecaplex = polydodecahedron
polyoctahedral = icositetrachoron = octaplex = hyperdiamond
four_dimensional_hyperoctahedron
five_dimensional_hyperoctahedron
six_dimensional_hyperoctahedron
seven_dimensional_hyperoctahedron
eight_dimensional_hyperoctahedron
nine_dimensional_hyperoctahedron
ten_dimensional_hyperoctahedron
k_dimensional_hyperoctahedron(k) = k_cross_polytope(k)
four_dimensional_mgonal_pyramidal(m) = mgonal_pyramidal_numbers_of_the_second_order(m)
four_dimensional_square_pyramidal
four_dimensional_pentagonal_pyramidal
four_dimensional_hexagonal_pyramidal
four_dimensional_heptagonal_pyramidal
four_dimensional_octagonal_pyramidal
four_dimensional_nonagonal_pyramidal
four_dimensional_decagonal_pyramidal
four_dimensional_hendecagonal_pyramidal
four_dimensional_dodecagonal_pyramidal
k_dimensional_mgonal_pyramidal(k, m) = mgonal_pyramidal_of_the_k_2_th_order(k, m)
five_dimensional_mgonal_pyramidal(m)
five_dimensional_square_pyramidal
five_dimensional_pentagonal_pyramidal
five_dimensional_hexagonal_pyramidal
five_dimensional_heptagonal_pyramidal
five_dimensional_octagonal_pyramidal
six_dimensional_mgonal_pyramidal(m)
six_dimensional_square_pyramidal
six_dimensional_pentagonal_pyramidal
six_dimensional_hexagonal_pyramidal
six_dimensional_heptagonal_pyramidal
six_dimensional_octagonal_pyramidal
centered_biquadratic
k_dimensional_centered_hypercube(k)
five_dimensional_centered_hypercube
six_dimensional_centered_hypercube
centered_polytope
k_dimensional_centered_hypertetrahedron(k)
five_dimensional_centered_hypertetrahedron(k)
six_dimensional_centered_hypertetrahedron(k)
centered_hyperoctahedral = orthoplex
nexus(k)
k_dimensional_centered_hyperoctahedron(k)
five_dimensional_centered_hyperoctahedron
six_dimensional_centered_hyperoctahedron
generalized_pentatope(left_index = 0)
generalized_k_dimensional_hypertetrahedron(k = 5, left_index = 0)
generalized_biquadratic(left_index = 0)
generalized_k_dimensional_hypercube(k = 5, left_index = 0)
generalized_hyperoctahedral(left_index = 0)
generalized_k_dimensional_hyperoctahedron(k = 5, left_index = 0) [even or odd dimension only changes sign]
generalized_hyperdodecahedral(left_index = 0)
generalized_hypericosahedral(left_index = 0)
generalized_polyoctahedral(left_index = 0)
generalized_k_dimensional_mgonal_pyramidal(k, m, left_index = 0)
generalized_k_dimensional_centered_hypercube(k, left_index = 0)
generalized_k_dimensional_centered_hypertetrahedron(k, left_index = 0)[provisional symmetry]
generalized_k_dimensional_centered_hyperoctahedron(k, left_index = 0)[provisional symmetry]
generalized_nexus(k, left_index = 0) [even or odd dimension only changes sign]
6. Zoo of figurate-related numbers
cuban_numbers = cuban_prime_numbers
quartan_numbers [Needs to improve the algorithmic complexity for n > 70]
pell_numbers
carmichael_numbers [Needs to improve the algorithmic complexity for n > 20]
stern_prime_numbers(infty = false) [Quick calculations up to 8 terms]
apocalyptic_numbers
Errata
-
Chapter 1, formula in the table on page 6 says:
Name | Formula | |
---|
Square | 1/2 (n^2 - 0 * n) | |
It should be:
Name | Formula | |
---|
Square | 1/2 (2n^2 - 0 * n) | |
-
Chapter 1, formula in the table on page 51 says:
Name | Formula | |
---|
Cent. icosihexagonal | 1/3n^2 - 13 * n + 1 | 546, 728, 936, 1170 |
It should be:
Name | Formula | |
---|
Cent. icosihexagonal | 1/3n^2 - 13 * n + 1 | 547, 729, 937, 1171 |
-
Chapter 1, formula in the table on page 51 says:
Name | Formula | |
---|
Cent. icosiheptagonal | | 972 |
It should be:
Name | Formula | |
---|
Cent. icosiheptagonal | | 973 |
-
Chapter 1, formula in the table on page 51 says:
Name | Formula | |
---|
Cent. icosioctagonal | | 84 |
It should be:
Name | Formula | |
---|
Cent. icosioctagonal | | 85 |
-
Chapter 1, page 65 (polite numbers) says:
inpolite numbers
It should read:
impolite numbers
-
Chapter 1, formula (truncated centered pentagonal numbers) on page 72 says:
TCSS_5(n) = (35n^2 - 55n) / 2 + 3
It should be:
TCSS_5(n) = (35n^2 - 55n) / 2 + 11
-
Chapter 2, formula of octagonal pyramidal number on page 92 says:
n(n+1)(6n-1) / 6
It should be:
n(n+1)(6n-3) / 6
-
Chapter 2, page 140 says:
centered square pyramidal numbers are 1, 6, 19, 44, 85, 111, 146, 231, ...
This sequence must exclude the number 111:
centered square pyramidal numbers are 1, 6, 19, 44, 85, 111, 146, 231, ...
-
Chapter 2, page 155 (generalized centered tetrahedron numbers) says:
S_3^3(n) = ((2n - 1)(n^2 + n + 3)) / 3
Formula must have a negative sign:
S_3^3(n) = ((2n - 1)(n^2 - n + 3)) / 3
-
Chapter 2, page 156 (generalized centered square pyramid numbers) says:
S_4^3(n) = ((2n - 1) * (n^2 - n + 2)^2) / 3
Formula must write:
S_4^3(n) = ((2n - 1) * (n^2 - n + 2)) / 2
-
Chapter 3, page 188 (hyperoctahedral numbers) says:
hexadecahoron numbers
It should read:
hexadecachoron numbers
-
Chapter 3, page 190 (hypericosahedral numbers) says:
hexacisihoron numbers
It should read:
hexacosichoron numbers