Figurate Numbers
Figurate Numbers is the most comprehensive and specialized library for figurate numbers, developed 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
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.
The sequences are organized following the structure of the Figurate Numbers book:
- PlaneFigurateNumbers: 79 sequences (2D)
- SpaceFigurateNumbers: 86 sequences (3D)
- MultiDimensionalFigurateNumbers: 70 sequences (4D and beyond)
- Zoo of figurate-related numbers: 6 additional sequences (included in the MultiDimensional module)
- ArithTransform: p-adic transformations and other arithmetic operations
See detailed list of sequences below
How to use in Ruby
Version 1.5.0
require 'figurate_numbers'
## Using take(integer)
FigurateNumbers.pentatope.take(10)
## Storing and iterating
f = FigurateNumbers.centered_octagonal_pyramid
f.next
f.next
f.next
Starting from version 1.5.0, figurate_numbers
not only supports global access via FigurateNumbers
and the use of specific classes for separate access, but also introduces new p-adic transformations and other mathematical operations that can be applied directly to sequences.
PlaneFigurateNumbers.polygonal(19)
SpaceFigurateNumbers.rhombic_dodecahedral
MultiDimensionalFigurateNumbers.six_dimensional_hyperoctahedron
seq = MultiDimensionalFigurateNumbers.five_dimensional_hypercube.take(15)
ArithTransform.ring_padic_val(seq, 3)
How to use in Sonic Pi
Simply copy the entry point path from the lib/figurate_numbers.rb
file where the gem is installed.
require "<PATH>"
pol_num = FigurateNumbers.polygonal(8)
350.times do
play pol_num.next % 12 * 7 # Some mathematical function or transformation
sleep 0.125
end
amp_seq = SpaceFigurateNumbers.centered_hendecagonal_pyramidal
100.times do
sample :bd_sone, amp: ArithTransform.padic_norm(amp_seq.next, 3) # p-adic amplitude control
sleep 0.25
end
Version 1.3.0 (legacy)
The main change introduced after version 1.3.0 is that you must now import the file using require instead of run_file; otherwise, it will not function.
See discussion in the Sonic Pi community thread right here!
List of Sequences and Arithmetic Transformations Methods
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]
4. 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
5. Arithmetic Transformations
ArithTransform.n_residue(n, pow, mod)
ArithTransform.pc_inversion(n, mod)
ArithTransform.padic_val(n, p)
ArithTransform.ring_padic_val(seq, p)
ArithTransform.padic_norm(n, p)
ArithTransform.ring_padic_norm(seq, p)
ArithTransform.padic_expansion(n, p, precision = 11, reverse: false)
ArithTransform.ring_padic_expansion(seq, p, precision = 11, reverse: false)
Book Errata
Chapter 1, page 6: The formula for Square in the table is given as:
1/2 (n^2 - 0 * n)
It should be corrected to:1/2 (2n^2 - 0 * n)
Chapter 1, page 51: The formula for Centered icosihexagonal numbers is listed as:
1/3n^2 - 13n + 1
with values546, 728, 936, 1170
. The correct formula and values are:13n^2 - 13n + 1
with values547, 729, 937, 1171
.Chapter 1, page 51: The value for Centered icosiheptagonal number is given as
972
. The correct value is973
.Chapter 1, page 51: The value for Centered icosioctagonal number is given as
84
. The correct value is85
.Chapter 1, page 65: The term polite numbers is misspelled as:
inpolite numbers
It should read:impolite numbers
Chapter 1, page 72: The formula for truncated centered pentagonal numbers (TCSS_5) is:
TCSS_5(n) = (35n^2 - 55n) / 2 + 3
It should be:TCSS_5(n) = (35n^2 - 55n) / 2 + 11
Chapter 2, page 92: The formula for octagonal pyramidal numbers is stated as:
n(n+1)(6n-1) / 6
The correct formula is:n(n+1)(6n-3) / 6
Chapter 2, page 140: The sequence for centered square pyramidal numbers is listed as:
1, 6, 19, 44, 85, 111, 146, 231, ...
The number111
should be excluded, resulting in:1, 6, 19, 44, 85, 146, 231, ...
Chapter 2, page 155: The formula for generalized centered tetrahedron numbers (S_3^3) is:
S_3^3(n) = ((2n - 1)(n^2 + n + 3)) / 3
It should include a negative sign:S_3^3(n) = ((2n - 1)(n^2 - n + 3)) / 3
Chapter 2, page 156: The formula for generalized centered square pyramid numbers (S_4^3) is:
S_4^3(n) = ((2n - 1)(n^2 - n + 2)^2) / 3
The correct formula is:S_4^3(n) = ((2n - 1)(n^2 - n + 2)) / 2
Chapter 3, page 188: The term hyperoctahedral numbers is incorrectly called:
hexadecahoron numbers
It should be:hexadecachoron numbers
Chapter 3, page 190: The term hypericosahedral numbers is incorrectly written as:
hexacisihoron numbers
It should be:hexacosichoron numbers