Tuesday, August 20, 2024

The Interval Matrix


DRAFT
This article introduces the concept of the interval matrix from a traditional music theory perspective, alongside a software tool designed to create and visualize these matrices. In this context, intervals refer to proportions or ratios between numbers.

The interval matrix is built from all possible representations of a set's values under an equivalence relation, using each element as a base, resulting in a numerical or geometrical table—a matrix—that represents this expansion.

These matrices are not initially intended for conventional matrix operations; the focus lies in the geometric structure that emerges from different sets and their elements' relationships.

Interval Matrix software. Prime numbers up to 19(set to periodic), with equivalence 1:2 (octave-space)
\(\mathbf{Ä}_{1:2}(P_{19})\)


For an infinite set, the matrix cannot be fully generated. However, if the set has a repeating pattern (period), a minimal generating set can be identified. The matrix is then built and completed using this minimal set, (n-by-n) as seen in a common musical tuning system (a set of pitches or rhythms used to create or perform music).

This period typically becomes the primary equivalence relation (equave) parameter in the set's function for constructing the matrix and analyzing the intervals within.

The matrix can be constructed for a finite set that isn't meant to repeat. For example, in music, this approach can be used to analyze notes on an instrument where there's no indication to continue calculating additional pitches. This method applies to any finite set. In a finite matrix, each row contains one element less than the previous row.

Set and matrix construction:

For analyzing a set \(S\) that is already normalized and within the desired range—such as in any pre-calculated musical tuning system—the set remains unaltered, and the matrix is built directly \(\mathbf{A}(S)\). The only required parameter is its periodicity: Is the given set a minimal generating set of an infinite set, or does it represent a fixed, finite number of elements?

Most examples here will use periodic matrices. To denote matrix periodicity or non-periodicity, we might use different notation, such as \(\mathbf{Ä}\) for periodic matrices and \(\mathbf{A}\) for non-periodic ones.

The generalization of the interval matrix construction allows us to relate different sets and reductions, enabling us to find congruences between systems. The reduction function (which corresponds to the chroma function when the space is the octave, 1:2) for a real matrix, where the set consists of any real numbers, operates as follows:

The absolute value of each element is taken, and the function then returns this value, reduced or remapped (if necessary) by an equivalence relation:

For a value \(s_x\) larger or smaller than the chosen equivalence relation \(r\), it is reduced to a new element \(\tilde{s}_x\) by applying the operation:

\(\tilde{s}_x = |s_x| \bmod 1:r\)

(This uses the mod symbol because it effectively returns the intervallic remainder. This process involves repeatedly multiplying or dividing \(s_x\) by \(r\) until \(s_x\) falls into \((1, r]\) space. This page has details about interval reduction.)

Since the matrix is defined by reinterpreting the set values with each element as the base, all rows inherently start with 1. Consequently, the reduction, or normalization, is consistently performed as \(\bmod 1:r\)

Optional: A constant \(\delta\) may be applied to each element of the set before performing the base change.(this in relevant for other uses explained in other article)

The reduction can be notated and performed for sets \(S_{1:r}\) without considering any matrix. It can also be used in constructing the matrix, \(\mathbf{A}_{1:r}(S)\), which implies both reduction and base shifting.

Example: If \(S\) = {1, 2, 3, 5}, then \(S_{1:2}\) ​= {1, 3/2, 5/4, 2}, and \(\mathbf{Ä}_{1:2}(S)\) would yield [{...},{...},{...},{...}]. (reduced and periodic)

Interval Matrix Definitions:

  • Full Interval Matrix: \(\mathbf{A} = \mathbf{A}_{s_n}^{\delta}\)
    This matrix uses the last or largest element of its generating set as the equivalence relation.
  • Local Interval Matrix: \(\mathbf{A}_{s_i}^{\delta}\)
    This matrix uses any element within the generating set as the equivalence relation, except for the largest one.
  • External Interval Matrix: \(\mathbf{A}_{x}^{\delta}\)
    This matrix uses a value outside the generating set as the equivalence relation. 


A full interval matrix built from a periodic set is inherently a symmetric matrix.

A full or local interval matrix is not "useful" for isotropic sets (where the chosen period or relation is a member of the set). This leads to identical and overlapping shifts of the elements.

Musical Interpretation:
For example, the 12-tone equal temperament \(\text{12ed2}\) guitar is an interval matrix (incomplete) representing the infinite set generated by the constant \(2^{1/12}\). Each row is shifted by five elements from the previous row (except between \(\text{G}\) and \(\text{B}\), where the shift is four). The matrix is trivial for this set's intervallic analysis, as columns (frets) are always aligned regardless of the shift or element taken as base.

Interval matrices are tipically shifted by one element until they are complete.

Consider this group: \(\langle 2, 3 \mid 3^2 = 1 \rangle \). This represents a set of infinite fifths and octaves. One of its minimal generating sets is \(S\) = (1, 3/2, 2]. The resulting matrix \(\mathbf{Ä}_{1:2}(S)\) has only two rows:

(1,  3/2,  2]
(1,  4/3,  2]

Interval Matrix Accumulation: \(\text{Acc}(\mathbf{A}(S))\)

This is a new set with all the representations of the elements under the set equivalence relation, which unfiltered, might repeat values, helping to find prevalent proportions. Isotropic sets always have an accumulation identical to any of their matrix rows. (The accumulation is a vectorization or flattening of the matrix)

In this case, the infinite set generated by \(\langle 2, 3 \mid 3^2 = 1\rangle\) = { ..., 1/2, 2/3, 1, 3/2, 2, ...} has an interval accumulation (under the equivalence 1:2):  (1, 4/3, 3/2, 2].

The distinction between full, local and external interval accumulations reflects the matrix type.

For example, consider a local matrix \(\mathbf{A}_{1:2}(S)\) constructed from the set {1, 2, 3, 4} in octave space (with an equivalence relation of 1:2). The local accumulation would be:

\(\text{Acc}(\mathbf{A}_{1:2}(S))\) = {1, 4/3, 3/2, 2} (filtered, with non-repeated values)

To obtain the global or full accumulation, the space is set to the largest element in the set. Thus, the matrix built from the set {1, 2, 3, 4} under the equivalence relation 1:4 would yield:

\(\text{Acc}(\mathbf{A}(S))\) = {1, 4/3, 3/2, 2, 3, 8/3, 4} (filtered)

For larger and more complex sets, the accumulation also provides a method for finding a possible natural mode of the set, if any.

Let’s take the pentatonic \(\langle 2, 3 \mid 3^5 = 1 \rangle\)
a minimal generating set is { (1, 9/8, 81/64, 3/2, 27/16, 2/1] }, its full matrix (omitting 1):

{9/8,  81/64, 3/2,    27/16, 2/1}
{9/8,    4/3, 3/2,    27/16, 2/1}
{9/8,    4/3, 3/2,    16/9,  2/1} Natural Mode
{32/27,  4/3, 3/2,    16/9,  2/1}
{32/27,  4/3, 128/81, 16/9,  2/1}

The natural mode of any set is the particular representation that includes the most frequent values appearing after shifts; it is the most faithful or weighted representation of the set.


How the Interval Matrix App Works

It accepts a list of numbers, treating them always as a minimal generating set(for now).

If the list/set is an already a reduced tuning system, the matrix is full and the equave(period, interval of equivalence) parameter should initially be set to match that of the set, typically the last and largest value. It does not adjust it automatically.

The matrix displays for each element in each row: the original value inserted, the reduced value(if it was reduced), a delta value(if it was displaced), and a rational approximation of the value.

The delta value comes from the delta parameter, usually 0. This value is added to every element in the original set before the rest of the calculations. This is useful for understanding how a minimal set, while maintaining its original absolute difference between members, shapes through this change.

For example, you can start with period/equave 1:2, and this set {1,2,3} reduces to {1, 3/2, 2}, but with delta = 3, it becomes {4, 5, 6}, and reduced, {1, 5/4, 3/2, (2)}.

Prime numbers up to 19. Delta = -1, octave-space.
\(\mathbf{Ä}_{1:2}^{-1}(P_{19})\)

The rational approximation has an adjustable tolerance value.

On top of the interval matrix, there is a configurable equal division ruler that helps with intervallic/ratio measures.

The chroma matrix has a fixed equivalence relation of an octave and, by default, starts at red. You can select whether the chromas displayed are absolute or relative to each row. When selecting relative, the full spectrum located in the bottom UI expands to display all the possible chroma shifts. (The full spectrum isn’t really "full"—you set a maximum space to occupy, with a logical maximum of the human hearing range.)

This last part is the most important when dealing with musical tuning systems; practical tuning systems have a simpler chroma matrix.

Unlike Scala files, the 1 must be inserted (remove it to understand what happens). You can, if you want, omit the equave in this list; it will be added (invisibly) from the equave parameter. However, it’s useful to keep it too, for example, when analyzing a non-octave tuning using an equave 3 (tritave). You can omit it, but if you want to inspect these intervals reduced to an octave, you might want to keep it and track it. So if when the set has an element equal to the equave, you will find two identical rows in the matrix.

Future Development

If you paid close attention to the code of this app and the SFINX app, you may have noticed that they use the same engine. That’s because, as I have pointed out, a guitar is essentially an interval matrix by string length.

My goal is to finally reunite both apps—SFINX was developed to aid in the graphic and diagram generation of scales for microtonal guitars, while the Interval Matrix was developed ideally for geometric analysis of sets and chromas.

(DRAFT)

Link to the apps:

jbcristian.github.io/xeneize/




Saturday, August 3, 2024

Mesopotamian Logarithm Algorithm

It's been some time since I wrote this article, and upon re-reading it, I’d like to clarify something to avoid potential misinterpretation: I’ve named it the Mesopotamian Logarithm Algorithm because the algorithm and visualizations I used are inspired by Mesopotamian music theory. While I analyze some of the cuneiform tablets and replicate their logic, this is a modified version of their scale generation method. It is not a claim that they used this process for calculating logarithms.
Draft: MLA.pdf

Logarithmic Convergents: A Musical Algorithm Reveals Dual Group Structures

This paper introduces the Mesopotamian Logarithm Algorithm (MLA), a method for computing logarithmic convergents inspired by traditional musical scale construction techniques. Diverging from standard continued fraction approaches, the MLA utilizes a musically intuitive "chaining and reduction" process, driven by the identification of musical commas (near-alignments), to determine convergents of \(\log_b(a)\) without explicit logarithm computation. A central contribution of this work is the discovery that this algorithm, rooted in historical practice, unveils a fundamental dual cyclic group structure underlying the convergents. Specifically, for a convergent \(p/q\), the exponents associated with the algorithm's sorted intermediate terms generate the cyclic groups \(\mathbb{Z}/p\mathbb{Z}\) and \(\mathbb{Z}/q\mathbb{Z}\) via modular inverses (\(p^{-1} \mod q\) and \(q^{-1} \mod p\), respectively). Optimized for musical analysis, the MLA thus not only provides a practical tool but also bridges ancient tuning methodologies with contemporary algebraic structures, offering novel perspectives on both.

Introduction

The computation of logarithms via continued fractions is a well-established mathematical technique. However, an analogous process is evident in musical tuning theory, wherein scales are generated through the iterative stacking and reduction of intervals within a defined period (e.g., the octave). This paper introduces the Mesopotamian Logarithm Algorithm (MLA), a methodology grounded in the traditional "chaining and reduction" technique prevalent in Pythagorean, Chinese (sanfen-sunyi), and Mesopotamian music theory. While exhibiting superficial similarities to established continued fraction algorithms, such as Shanks' logarithm algorithm, this approach adopts a distinctly musical framework. Rather than computing intermediate terms of the continued fraction, MLA operates on musical intervals, directly identifying convergents of the logarithm, thereby circumventing its explicit calculation. Specifically, MLA generates convergents by identifying musical commas(1), which are small rational intervals signifying near-cyclical alignment.

(1): In Western music theory, commas denote relative intervals (e.g., \(4/3\) from \(3/2\) to \(2/1\)); here, the algorithm targets the comma indicating near alignment of the base and argument sequences.

Although the algorithm may not demonstrate superior computational efficiency across all scenarios, it incorporates a range of optimizations within its design.

Beyond its musical and computational utility, MLA reveals inherent group structures within the exponent sequences, establishing a connection between historical musical intuition and modern algebraic concepts. This paper focuses on the algorithm's design, its mathematical implications, and its relevance to music theory.

Algorithm Description

The Mesopotamian Logarithm Algorithm (MLA) identifies convergents of \(\log_b(a)\) for \(b > 1\), \(a > 0\), by iteratively generating a sequence of reduced terms \(r_x\) without directly computing logarithms. For each step \(x = 0, 1, 2, \ldots\):
  • Chain and Fold: Compute \(r_x = a^x \cdot b^{y_x}\), where \(y_x\) is an integer chosen such that \(r_x \in [1, b)\). This adjusts \(a^x\) by multiplying or dividing by powers of \(b\), and the total number of adjustments across all steps is tracked as \(p = \sum |y_x|\).
  • Bounds and Commas: Maintain dynamic bounds \(L\) (initially 1) and \(U\) (initially \(b\)). After computing \(r_x\), if \(L < r_x < U\), calculate the commas \(c_0 = r_x / L\) and \(c_1 = U / r_x\). Evaluate the ratio: \[  \text{Ratio} = \frac{\max(c_0, c_1) - 1}{\min(c_0, c_1) - 1}   \] If this ratio is less than 2, a convergent \(p/q\) is identified, where \(q = x + 1\).
  • Update Bounds}: If the ratio condition is satisfied, update the bounds: set \(L = r_x\) if \(r_x < H\), or \(U = r_x\) if \(r_x > H\), where \(H = b / r_1\) is the initial comma established after the first step.
Optimization: MLA avoids storing the full sequence of \(r_x\) values by dynamically updating \(L\) and \(U\), and it chains computations from the reduced \(r_x\) to prevent the need for large exponents, preserving numerical precision.

Theoretical Basic: Connection to The Three Gap Theorem

The heuristic threshold of 2 for this ratio finds its justification in the principles of the Three-Gap Theorem (Steinhaus Theorem) concerning the distribution of points \(n\alpha \mod 1\). The theorem dictates that the gaps between consecutive sorted points \((k\alpha) \mod 1\) for \(k = 1, \ldots, N\) take on at most three distinct lengths, and the specific structure of these gaps changes predictably as \(N\) increases, particularly as it passes values corresponding to the denominators \(q\) of the continued fraction convergents \(p/q\) of \(\alpha\).

The MLA operates analogously in a multiplicative setting, examining the sequence \(r_x = a^x b^{y_x}\) within \([1, b)\), akin to \((x \times log_b(a)) \mod 1\). While a full analysis would track all gaps between all sorted \(r_x\) terms generated so far, the MLA employs dynamic bounds \(L\) and \(U\) for efficiency. These bounds track the immediate multiplicative neighbors of the potential next term's location, effectively focusing on the local region where the most significant gap subdivision is anticipated when approaching a new convergent.

The insertion of a term \(r_x\) corresponding to a new convergent p/q is precisely the moment that triggers a structural reorganization of the gaps, often involving the subdivision of the largest existing gap type. The ratio condition \((max(c_0, c_1) - 1) / (min(c_0, c_1) - 1) < 2\), applied locally to the interval \([L, U]\) split by \(r_x\), acts as an efficient proxy for detecting this event. It identifies when the subdivision of this critical local region becomes relatively balanced (neither new multiplicative gap \(c_0\) or \(c_1\) is disproportionately larger than the other). This balanced local subdivision is an indicator that the global gap structure is undergoing the characteristic reorganization associated with reaching a best rational approximation \(p/q\), signalling that a convergent has been found.

Therefore, the MLA leverages the underlying principles of uniform distribution and gap structure described by the Three-Gap Theorem, but uses a localized, efficient test. It identifies convergents by detecting the balanced subdivision event characteristic of their appearance, operating directly on the multiplicative sequence \(a^x b^{y_x}\) without needing explicit logarithms or tracking all intermediate gaps. This unique approach simultaneously facilitates the discovery of the dual cyclic group structures within the exponents (\(p\) and \(q\)) associated with these identified convergents.

Dual Group Structures

The MLA’s sequence of reduced terms \(r_x\) for each \(p/q\) unveils cyclic group structures in the exponents:
  • \(x\)-Sequence: When \(r_x\) values are sorted by magnitude, their corresponding exponents \(x_k\) form the cyclic group \(\mathbb{Z}/q\mathbb{Z}\), generated by \(p^{-1} \mod q\). For the convergent \(19/12\) of \(\log_2(3)\), \(q = 12\), \(p = 19\), \(p^{-1} = 7 \mod 12\), yielding the sequence \(0, 7, 2, 9, 4, 11, 6, 1, 8, 3, 10, 5\).  
  • \(y\)-Sequence: The exponents \(y_{x_k}\) (adjustments by powers of \(b\)), taken modulo \(p\), form the first \(q\) elements of \(\mathbb{Z}/p\mathbb{Z}\), generated by \(q^{-1} \mod p\). For \(19/12\), \(q^{-1} = 8 \mod 19\), producing \(0, -11, -3, -14, -6, -17, -9, -1, -12, -4, -15, -7\).  
This duality emerges from the approximation \(a^q \approx b^p\), linking the algorithm’s musical origins to modular arithmetic.

\( \approx r_x \) Ratio \( x \) \( y_x \)
1.000 1 0 0
1.068 2048:2187 7 -11
1.125 8:9 2 -3
1.201 16384:19683 9 -14
1.266 64:81 4 -6
1.352 131072:177147 11 -17
1.424 512:729 6 -9
1.500 2:3 1 -1
1.602 4096:6561 8 -12
1.688 16:27 3 -4
1.802 32768:59049 10 -15
1.898 128:243 5 -7
Reduced chain for \(\log_2(3)\), \(r_x = 3^x \cdot 2^{y_x}\), \(q=12\)


Visualizations and Applet

The following figures, generated by an extended MLA implementation, replicate the interval and scale generation logic of Mesopotamian tablet CBS1766, exposing group-theoretic properties through geometric dials. This emulation draws the same figure for any \(log_b(a\times b^k)\) highlighting the algorithm’s focus on periodic, fractional components rather than the integer part.

Figure 1: Visualizes the convergent \(7/12\) for \(\log_2(3/2)\). A 12-sided regular polygon represents \(\mathbb{Z}/12\mathbb{Z}\), with vertices labeled 1 to 12 counterclockwise. Inside, an irregular 7-pointed star (heptagram) connects the first 7 elements generated by 7 modulo 12, tracing the outer sequence \(\{12, 7, 2, 9, 4, 11, 6\}\). These correspond to exponents \(x\) in the first 7 of 12 terms of \((3/2)^x \cdot 2^y\) folded into \([1, 2]\). The inner star is labeled \(\{7, 4, 1, 5, 2, 6, 3\}\), representing exponents \(y\) in \(\mathbb{Z}/7\mathbb{Z}\) with generator 4. The final connection from 6 to 12 (outer) is dashed, indicating an incomplete cycle of the group.

7-pointed star within a 12-sided polygon for \(7/12\) of \(\log_2(3/2)\).



Figure 2: Shows the convergent 6/23 for \(\log_3(4/3)\). A 23-sided regular polygon represents \(\mathbb{Z}/23\mathbb{Z}\), labeled 1 to 23 counterclockwise. Inside, a 6-sided irregular polygon connects the points \(\{23, 4, 8, 12, 16, 20\}\), the first 6 exponents generated by 4 modulo 23, corresponding to sorted terms \(r_x = (4/3)^x \cdot 3^{y_x}\) in \([1, 3)\). This contrasts with Figure 1's overlapping heptagram, as the lines here do not intersect, highlighting the algorithm's flexibility across different bases and periods.

6-sided polygon within a 23-sided polygon for \(6/23\) of \(\log_3(4/3)\).


Music Theory Insights

In musical contexts, the denominators of logarithmic convergents represent equal divisions of a base interval \(b\), approximating intervals generated by powers of \(a\) within \([1, b)\). However, not all convergents are equally effective for this purpose. For example, while \(\frac{65}{41}\) follows \(\frac{19}{12}\) as a convergent of \(\log_2(3)\), a 41-fold equal division of the octave (\(2^{1/41}\)) poorly approximates the sequence of 41 reduced fifths (\(3^x \cdot 2^{y_x}\)). In contrast, the subsequent convergent \(\frac{84}{53}\) yields a more accurate alignment. A variant of MLA replaces the ratio threshold of 2 with the golden ratio (\(\phi \approx 1.618\)) to select convergents with uniformly distributed commas, enhancing their utility for microtonal approximations.

Figure 3: visualizes interval alignment for three convergents of \(\log_2(3)\), with rows A, B, and C:
  • A: 12-EDO: The interval \([1, 2]\) with the first 12 terms of \(3^x \cdot 2^{y_x} \in [1, 2]\) (blue) aligns closely with 12 equal divisions (red, step size \(2^{1/12}\)), reflecting the phase coherence of \(\frac{19}{12}\) in standard equal temperament.
  • B: 41-EDO: The first 41 terms (blue) diverge significantly from 41 equal divisions (red, step size \(2^{1/41}\)), indicating the poor approximation of \(\frac{65}{41}\) due to non-uniform comma distribution.
  • C: 53-EDO: The first 53 terms (blue) align well with 53 equal divisions (red, step size \(2^{1/53}\)), demonstrating the efficacy of \(\frac{84}{53}\).    
The geometric contrast underscores that \(\frac{19}{12}\) and \(\frac{84}{53}\) outperform \(\frac{65}{41}\), with the latter exhibiting greater error and reduced suitability for musical tuning due to its irregular comma distribution.

Geometric Representation of Interval Alignment


Conclusion and Future Directions

This paper introduced the Mesopotamian Logarithm Algorithm (MLA), a different method for computing logarithmic convergents rooted in the "chaining and reduction" principles observed in ancient musical scale construction across various cultures. By operating directly on interval relationships and identifying musical commas, the MLA bypasses explicit logarithm evaluation, offering a computationally distinct approach compared to conventional continued fraction algorithms like Shanks'. Its optimization for musical applications, focusing on the sequence of reduced terms within a base interval (e.g., the octave), reflects historical tuning practices.

Beyond its practical utility in generating musically relevant approximations, the most interesting contribution of this work lies in unveiling the inherent algebraic structure encoded within the algorithm's process. For a given logarithmic convergent \(p/q\) of \(log_b(a)\), the MLA implicitly reveals a dual cyclic group structure within the exponents. Specifically, when the intermediate terms \(r_x = a^x b^{y_x}\) (reduced to the interval \([1, b)\)) are sorted by magnitude, their corresponding a-exponents \((x)\) generate the cyclic group \(\mathbb{Z}/q\mathbb{Z}\) via \(p^{-1} \mod q\), while the associated b-exponents \((y_x)\) map to the initial elements of \(\mathbb{Z}/p\mathbb{Z}\) with generator \(q^{-1} \mod p\). This discovery establishes a formal bridge between the iterative, intuitive procedures of historical tuning systems and the abstract framework of modern group theory.

The implications of this connection are potentially far-reaching. For music theory, it provides a new algebraic lens through which to analyze scale generation and comma distribution, and the underlying mathematical coherence of tuning systems. For mathematics, it offers a concrete algorithmic context for observing these dual group structures related to Diophantine approximation of logarithms.

Future research stemming from this work presents several compelling avenues:

Generalization to Other Irrationals: A primary direction is to investigate whether this dual cyclic group structure is a more general phenomenon associated with continued fraction convergents \(p/q\) of other irrational numbers. Exploring analogues for sequences derived from approximations of constants like \(\theta/(2\pi)\) (related to trigonometric functions and rotations on the circle group \(S^1\)) or other fundamental irrationals could reveal similar underlying algebraic patterns. This involves defining appropriate "reduction" processes and analyzing the resulting index and 'overflow' sequences.

Analysis of Historical Systems: The group-theoretic framework developed here could be applied to analyze other historical mathematical and musical systems. Examining algorithms like Ptolemy's geometric tuning methods or other ancient approximation techniques through this lens might uncover similar, or perhaps distinct, algebraic structures, deepening our understanding of their mathematical foundations.

Algorithmic Refinements and Applications: Further exploration of MLA variants, such as incorporating different comma selection criteria (e.g., the golden ratio threshold) for optimizing comma distribution in microtonal contexts, warrants investigation. Connections to uniform distribution theory and dynamical systems may also yield further insights.

In summary, the MLA serves not only as an efficient algorithm tailored for musical contexts but also as a potent example of how practical, historically-inspired procedures can illuminate fundamental mathematical structures. It underscores the deep, often hidden, connections between music, mathematics, and the history of computation, opening fertile ground for future interdisciplinary exploration.

A  Python Implementation
This implementation ignores integer convergents and provide musical meaningful approximations.

def mla(a, b, max_q):
    if b <= 1 or a <= 0:
        return []
    if a == 1:
        return ["0/1"]  # log_b(1) = 0
    if a == b:
        return ["1/1"]  # log_b(b) = 1
    if a < 1: #handles a in (0,1)
        a = 1 / a
        results = mla(a, b, max_q)
        return [f"-{p.split('/')[0]}/{p.split('/')[1]}" if '/' in p else f"-{p}" for p in results]
    results = []
    link, lower, upper = a, 1, b
    p, q = 1, 1
    while q < max_q:
        while link < 1:
            link *= b; p += 1
        while link > b:
            link /= b; p += 1
        if q == 1:
            H = b / link; p += p - 1
        q += 1
        if link == b:
            results.append(f"{p-1}/1"); break
        if lower < link < upper:
            commas = [link/lower, upper/link]
            if (max(commas) - 1) / (min(commas) - 1) <= 2:
                results.append(f"{p}/{q}")
            lower, upper = (link, upper) if link < H else (lower, link)
        link *= a
    return results


-------

old article:

A Musical Approach to Convergents of Continued Fractions

This article explores a method for calculating logarithms deeply rooted in musical principles first documented in ancient Mesopotamian cuneiform tablets. While superficially similar to existing methods involving continued fractions, such as Shanks' logarithm algorithm, this approach takes a fundamentally musical perspective. Instead of directly computing intermediate terms of the continued fraction, it operates on musical intervals, directly identifying convergents of the logarithm, bypassing its computation, that is, the algorithm directly generate convergents without calculating the logarithm first. This connection between music and logarithms emerges from the traditional musical concept of the "comma." Although this algorithm might not surpass existing methods in efficiency across all cases, it incorporates various optimizations within its design. What makes this algorithm particularly intriguing is the surprisingly early demonstration of modern mathematical concepts in the context of ancient Mesopotamian music theory.


Musical Theory Background

Music theory is a diverse field with various schools of thought, ranging from traditional to experimental approaches. This diversity mirrors the essence of music itself, which defies a singular, absolute definition. At its core, music is deeply connected with human expression, art, and culture. Despite philosophical differences, certain processes in music, particularly in tuning theory, are universally grounded in mathematical concepts.

A commonly used technique for constructing tuning systems, known as "chaining/stacking and reducing/folding," forms the basis of the algorithm discussed in this article. This approach has been utilized by various cultures throughout history, notably in the Pythagorean scale. Documented by Boethius, Ptolemy, and others, this scale was later expanded upon by the medieval music theorist Guido d'Arezzo. Remarkably, this identical pitch calculation and scale generation process is also found in Chinese music theory under the name sanfen-sunyi, or up-down generation in English. And an even earlier application of this method is apparent in Mesopotamian music, highlighting the universality of interval reduction and equivalence concepts.

While these three distinct cultures developed and recorded this system, they likely influenced one another through historical interactions like Greek visits to Egypt or Magi priests traveling to China. Similar scales have been discovered in other geographically distant cultures. Although the process wasn't explicitly documented, pre-Columbian American and West African instruments feature diatonic or pentatonic scales.

The Mesopotamian Musical Tuning System

This ancient civilization not only calculated the same 3-limit 12-tone system, the diatonic scale, and its modes, but their methods and visualizations align with modern mathematical concepts from group theory and modular arithmetic, incorporating intervals and class matrices. A comprehensive analysis of cuneiform tablets, their translations, and their relation to cosmology extends far beyond the scope of this text. For a detailed study, refer to this excellent paper on the topic. Here i provide a concise overview pertinent to the algorithm.

The tablet features a dial and a table, both of which have modern counterparts in music theory. The table corresponds to what we now call a "class matrix," used for analyzing chords, scales, modes, and tuning patterns on instruments. This is the same purpose it serves on the tablet. It differs from the "interval matrix," which doesn't indicate exact pitches but rather their classes after construction. The dial serves as another method for displaying interval relationships, similar to the circle of fifths.  Many modern virtual synthesizers utilize a similar user interface for displaying microtonal scales.

While the tablet doesn't explicitly mention octaves (1:2) or fifths (2:3), the dial displays the names of the strings on a lyre. A corresponding tablet provides step-by-step instructions for tuning this lyre to achieve all the diatonic scale modes found in the table. This suggests a clear understanding of string length ratios and harmonics, a concept further supported by the earliest lutes, which also featured movable frets.

There is, however, no consensus on the regularity of the heptagon star depicted on the tablet. If the points were equidistant, the tuning instructions would be incorrect and unnecessary, as the scales would be congruent. In my opinion, the heptagon star is irregular, and the double circle within which it is inscribed likely represents an octave – a common practice in dial user interfaces to indicate the period.

It's crucial to recognize that we are considering three heptagon stars. One is regular, and rotating it leads to an identical star, which would correspond to 7-EDO (7 equal divisions of the octave) if octaves were our focus. The other two are irregular, with minimal differences, barely perceptible in a perfect graphic, which emerge from the comma. We are comparing the 3-limit 12-tone system and the 12-tone temperament. Studying these congruences involves the use of interval matrices, which lies outside the initial goal of this text.  We will revisit this topic after explaining the "chain" and "reduce" operations.

The tablet shows three possible star shapes. The first, a regular heptagon, corresponds to 7edo. Tuning instructions suggest adjusting two strings to achieve different modes, which in 7edo results in arriving at notes already present, effectively removing notes rather than changing step sizes. These instructions don’t apply to this star, which involves locating the tritone, transforming it to a fifth, and relocating the tritone on another string, keeping five strings in tune with a different base to achieve a new diatonic mode.
The second star, irregular, is constructed by connecting seven points on a 12-sided polygon by fifths, returning to the origin in the last step. This generates the first seven elements in Z/12Z+ with generator 7. The instructions apply to this star and the group perspective. Starting with a set generated by 7: {7, 2, 9, 4, 11, 6, 1}, shifting all elements by -2 results in five numbers remaining the same: {5, 0, 7, 2, 9, 4, 11}.
The third star, another irregular shape, is generated in the circle group with generator log2(3). The group is infinite, and seven steps are drawn, with the last step highlighting the Pythagorean comma misalignment. There is no direct evidence that Mesopotamians knew this exact value; their theory was more practical than technical. The second star is the most likely representation.
While these historical materials might predate the formalization of group theory in modern math, CBS1766 reveals how a similar understanding of musical principles, utilizing cyclical patterns, generators, and group shifts, might have already existed in Mesopotamian musical practices.


Interval/Ratio Reduction

Considering the inverse relationship between string length and frequency, the process remains similar regardless of the starting point, with arithmetic operations adjusted accordingly. I will utilize the frequency interpretation and Western music terminology (octave, fifth, third, scale, tuning, comma, etc.)

While the generalization of this scaling operation is not limited to specific values and can even extend to complex numbers, musical intervals are real numbers, often rational. For pitch calculations, we categorize them into subharmonics \((0,1)\), fundamental \([1]\), and harmonics \((1, +∞)\). The concept of interval reduction stems from human perception and the notion of octave equivalence, which aligns with the modern concept of chroma, recognizing pitches in a 1:2 ratio as possessing the same "color."

For example, we identify the fifth (2:3) as a representative of the third harmonic (1:3) but reduced to the octave (1:2). Similarly, a major third (4:5) is the octave representative of the fifth harmonic (1:5).  Reduction separates intervals, or numbers, into classes. The fifth (2:3) not only represents the third harmonic (1:3) in octave space, but it also represents the sixth (1:6), twelfth (1:12), twenty-fourth (1:24), etc.

This universal operation in music can be represented using various notations. In modern music theory, this may be notated with the mod operator, as it returns a remainder – in this case, a ratio or intervallic remainder.

The classic mod operator can be defined as:

\(a \bmod b = \tilde{a}\),
Subtract \(b\) from \(a\) until \(a < b\). For example: \(14 \bmod 5 = 4\).

The normalized ratio mod operator can be defined as:

\(a \bmod 1:b = \tilde{a}\),
Multiply or divide \(a\) by \(b\) until \(a\) falls within the range \((1, b]\).  For example: \(48 \bmod 1:2 = 1.5\).

This bears a strong resemblance to the first part of Shanks' algorithm (although there is no evidence of his interest in music theory).  He describes this aspect of the process for integers \(b > a > 1\) as finding \(a^n < b < a^{n+1}\), essentially the same reduction or scaling process: \(2^5 < 48 < 2^6\), so  \( 48/2^5 = 1.5\)

Generalizing reduction, it can be seen as a mapping, transforming a number into another range. While you can perform this operation with other ranges, normalization is required.  For example, \(7 \bmod 4:5\) is calculated as \(7 \bmod 1:5/4 = 1.12\).

The Chain/Stack

The chaining operation mathematically corresponds to an exponential sequence.  A chain of third harmonics, expressed in terms of frequency ratios, is represented by \(\{3^0, 3^1, 3^2, 3^3, 3^4, \ldots\}\).  These numbers, as musical intervals, form a 1:3 ratio, representing consecutive third harmonics: \(\{1, 3, 9, 27, 81, \ldots\}\).

The 12-tone Pythagorean/Chinese/Mesopotamian scale, constructed in this manner, is known in modern theory as the 3-limit 12-tone system. It chains 12 fifths (or third harmonics) and reduces them by the octave. Its tempered/truncated modern version is the 12-EDO (12 equal divisions of the octave) or 12-tone equal temperament, created to compensate for the emergence of commas – a crucial component of the algorithm in both Shanks' and Mesopotamian methods.

Commas

Traditionally, the term "comma" refers to a small and "problematic" interval, a famous example is known as the "Pythagorean comma." This arises when constructing a scale using the octave (1:2) and the third harmonic (1:3).  After stacking and reducing 12 notes, the next calculated note almost returns to the starting point \(3^{12} \bmod 1:2 = 3^{12}/2^{19} = 531441/524288\), making the set of pitches nearly cyclical. This happens because no integers \(n\) and \(m\) exist such that \(2^n = 3^m\), as both 2 and 3 are prime numbers.

However, the concept of a comma has been expanded to define relative ratios within a set, not necessarily small. For example, in the set {1, 2, 3, 4, 5}, the consecutive commas are {1:2, 2:3, 3:4, 4:5}, representing the ratio between consecutive intervals but it can refer to any pair of intervals in the set. This includes consecutive intervals, but also, for instance, the comma 3:5, 2:4, 2:5, etc... within that set.

For this algorithm, we are focusing on detecting the traditional comma, indicating an almost-perfect alignment of the exponential sequences of the base and the argument. This alignment signifies the discovery of a convergent.

The Algorithm: Example and Convergents

Before explaining how convergents are obtained, some implications are examined. Although the examples might focus on \(\log_2(3)\), this is done for clarity and for those already familiar with the method. The 3-limit 12-tone scale will make it easier to follow, and then the general case is presented.

Let's examine \(\log_2(3)\) using the convergent \(\frac{19}{12}\), the octave (1:2), the third harmonic (1:3), and the chromatic scale.

Consider the denominator of the convergent as the order of an additive group \(\mathbb{Z/12Z}\) and the numerator as a generator (19%12 = 7) , the sequence of elements matches the exponents in the size-ordered reduced links in the chain of \(3^x\). Specifically, if you calculate the first 12 powers of \(3\), reduce them by \(1:2\), and order them by size as \((3^x \times 2^y)\), the sequence of \(x\)'s corresponds to the elements in \(\mathbb{Z/12Z}\) generated by \(7\). Similarly, the sequence of \(y\)'s corresponds to the first 12 elements in \(\mathbb{Z/19Z}\) generated by in this case \(8\). (See below)

                                                    log2(3)                                     log2(3/2)
~Decimal  Ratio           3 ^ x   *   2 ^ y    |  (3/2) ^ x   *   2 ^ (y%x)
1
1.014     524288:531441   3 ^ 12  *   2 ^ -19  |  (3/2) ^ 12  *   2 ^ -7    Comma
1.068     2048:2187       3 ^ 7   *   2 ^ -11  |  (3/2) ^ 7   *   2 ^ -4    
1.125     8:9             3 ^ 2   *   2 ^ -3   |  (3/2) ^ 2   *   2 ^ -1    
1.201     16384:19683     3 ^ 9   *   2 ^ -14  |  (3/2) ^ 9   *   2 ^ -5    ♂︎
1.266     64:81           3 ^ 4   *   2 ^ -6   |  (3/2) ^ 4   *   2 ^ -2    
1.352     131072:177147   3 ^ 11  *   2 ^ -17  |  (3/2) ^ 11  *   2 ^ -6    
1.424     512:729         3 ^ 6   *   2 ^ -9   |  (3/2) ^ 6   *   2 ^ -3    ♀︎
1.5       2:3             3 ^ 1   *   2 ^ -1   |  (3/2) ^ 1   *   2 ^  0    
1.602     4096:6561       3 ^ 8   *   2 ^ -12  |  (3/2) ^ 8   *   2 ^ -4
1.688     16:27           3 ^ 3   *   2 ^ -4   |  (3/2) ^ 3   *   2 ^ -1
1.802     32768:59049     3 ^ 10  *   2 ^ -15  |  (3/2) ^ 10  *   2 ^ -5
1.898     128:243         3 ^ 5   *   2 ^ -7   |  (3/2) ^ 5   *   2 ^ -2
2                         

\(\mathbb{Z/12Z}\) = 7,  2,  9, 4, 11, 6, 1,  8, 3, 10, 5, 0
\(\mathbb{Z/19Z}\) = -11, -3, -14, -6, -17, -9, -1, -12, -4, -15, -7, ...


Understanding the Setup

For \(\log_2(3)\), the convergent \(19/12\) gives us \(p = 19\) and \(q = 12\), where \(p\) and \(q\) are coprime. This convergent approximates \(\log_2(3) \approx 1.58496\), so \(3^{12} \approx 2^{19}\). We compute the first \(q\) powers of \(a\):
  • \(r_x = 3^x \cdot 2^{y_x}\), for \(x = 0, 1, \ldots, q-1 = 11\),
where \(y_x\) is chosen to “reduce” the value into the interval \([1, b) = [1, 2)\). Specifically:
  • \(y_x = -\lfloor x \log_2(3) \rfloor\),
ensuring \(r_x = 3^x \cdot 2^{y_x} \in [1, 2)\). We then sort these \(r_x\) values in increasing order, which permutes the indices \(x\) and their corresponding \(y_x\).

General Rule

For a convergent \(p/q\) of \(\log_b(a)\):
  • \(x\) sequence: Sorting \(r_x\) orders the fractional parts \(\{x \cdot \log_b(a)\} \approx \{x \cdot (p/q)\}\), giving \(x_k = k \cdot p^{-1} \mod q\), forming \(\mathbb{Z}/q\mathbb{Z}\) with generator \(p^{-1}\).
  • \(y\) sequence: The corresponding \(y_{x_k} = -\lfloor (k \cdot p^{-1} \mod q) \cdot \log_b(a) \rfloor\), when taken modulo \(p\), forms the first \(q\) elements of \(\mathbb{Z}/p\mathbb{Z}\) with generator \(q^{-1} \mod p\). This arises because \(y_x \approx -x \cdot (p/q)\), and the permutation by \(p^{-1}\) interacts with the approximation.

For \(19/12\):
  • \(q = 12\), \(p = 19\), \(p \equiv 7 \mod 12\), \(p^{-1} = 7\), \(x\): \(k \cdot 7 \mod 12\),
  • \(p = 19\), \(q = 12\), \(q^{-1} = 8 \mod 19\), \(y \mod 19\): \(k \cdot 8 \mod 19\).

In conclusion both sequences are group-related:
  • The \(x\) exponents form \(\mathbb{Z}/q\mathbb{Z}\) generated by \(p^{-1} \mod q\) (here, 7).
  • The \(y\) exponents, modulo \(p\), form the first \(q\) elements of \(\mathbb{Z}/p\mathbb{Z}\) generated by \(q^{-1} \mod p\) (here, 8).
The generator for the \(y\) sequence emerges from the inverse relationship due to \(a^q \approx b^p\), reflecting a duality in the convergent’s structure. For \(19/12\), it’s 8 because \(12^{-1} \equiv 8 \mod 19\).


This live demo calculates a few example convergents and renders a simple one, illustrating the tablet logic.


Obtaining Convergents

The implementation (detailed below) includes optimizations that may make its logic less clear. Here’s a simplified explanation:

It iteratively computes a chain of powers (exponential sequence) from the input value (the argument), and each "link" is reduced to fall within the interval range \((1, \text{base}]\). The distances between consecutive reduced links, the commas, are then passed to a condition: if the ratio of the normalized largest/smallest commas is less than \(2\), a convergent is found. The current step of the iteration provides the denominator, while the numerator is obtained by counting how many times the links were multiplied or divided until they fell within the range.

One optimization involves readjusting the upper and lower bounds of the links being evaluated, reducing the need to keep and test every comma except two. When commas pass, the previous reduced link approximates the comma between the first reduced link and the base. For clarity:

As an example take \(\log_2(10)\),

the first reduced link is \( 10^1/2^3 \), the comma ( \(H\) in the code) is \(\frac{2}{1} / \frac{10}{8} = \frac{8}{5} = 1.6 \)

As each convergent for \(\log_2(10) ≈ \frac{10}{3} ≈ \frac{93}{28} ≈ \frac{196}{59}\ldots\) indicates that,

\(10^{3}/2^{10} ≈ 10^{28}/2^{93} ≈ 10^{59}/2^{196} ≈ 1\) (progressively better)

The previous link added, indicates

\( 10^{2}/2^{6} ≈ 10^{27}/2^{89} ≈ 10^{58}/2^{192} ≈ 1.6 \),

And the next link, for example \( 10^{29} \bmod 1:2 = 10^{29} / 2^{96} ≈ \frac{10}{8} = 1.25\), approximates the first link again.

Knowing this the evaluated link becomes a new bound, lower or upper depending on which side of this value \(H\) fell.

Another optimization addresses precision, for example, to compute \(\log_2(5)\) as \(4495889/1936274\) using the simple logic explained above, you would need to calculate \(5^{1936274}\), which exceeds 32-bit integer limits. The solution is to continue the chain from its reduced link, preserving the order of commas and avoiding such exponents. This allows precision to be maintained longer.

Variations for Precision and Musical Applications

While the denominators in a convergent of \(\log_b(a)\) in music are used as an equal division of \(b\) approximating intervals generated by \(a\) in \(b\), not all work for this purpose. For example, the next convergent of \(\log_2(3)\) after \(\frac{19}{12}\) is \(\frac{65}{41}\), but 41 equal divisions of the octave don't approximate 41 consecutive reduced fifths. The subsequent convergent, \(\frac{84}{53}\), does function as needed. A variation of the algorithm uses the golden ratio (Φ) instead of 2 in the condition, selecting convergents that correspond only to uniformly distributed commas. Another way to visualize it is that a chain of \(2^{1/53}\) keeps a close approximation, in phase, with the powers of \(3\) up to \(3^{53}\) and powers of \(2\) up to \(2^{84}\).

41 fifths don't fill the octave:


as 12 fifths:


or 53 fifths:


Essentially, this variation ignores convergents with poor approximations, implicitly constructs additive groups, and identifies their generators.


Python Implementation




(Another slight optimization, which is not implemented, avoids the use of the min and max functions in every iteration when the condition is met. The indices of the minimum and maximum values, once found, remain the same. Therefore, these indices can be calculated in the first step and then reused. However, since the functions are performed on an array of two elements, saving any sort-like function has minimal impact on speed; it just interrupts the flow of the code.)
(DRAFT)

Thursday, August 1, 2024

The Average Tuning System: Scala Archive Statistics

Introduction: The Average Tuning System (ATS)

The Average Tuning System (ATS) represents a set of pitches derived from a descriptive statistical analysis of the extensive Scala Archive, a renowned database encompassing a vast collection of global tunings. The primary objective of this investigation was to identify common structural elements and tendencies across diverse historical and contemporary tuning practices, seeking a statistically informed representation of shared characteristics.

A core aspect of the analysis involved interpreting the data under the assumption that most tuning systems within the archive function as periodic pitch sets. To comprehensively assess the interval content, an interval matrix expansion was performed for each tuning file. The rationale for this step is crucial: cyclic permutation and base changes inherent in periodic sets mean that the initially presented sequence of intervals (the "key") may not fully reveal the system's most prominent interval relationships. Matrix expansion calculates all possible intervals generated within the set, providing a complete picture independent of the starting note. This process revealed that while some systems appear distinct initially, expansion shows they are permutations of the same underlying structure (torsors), often highlighting strong internal interval preferences (like the perfect fifth) not explicit in the original file listing.

Despite the potential for the matrix expansion to alter perceived interval prominence, key statistical findings remained remarkably consistent whether analyzing the initial keys directly or the fully expanded interval matrices. The average (mean), median, and mode for the number of notes per system, as well as the ranking of the most frequent intervals (top 10), showed strong convergence in both scenarios, indicating powerful underlying tendencies within the archive.

The analysis navigated inherent challenges related to data representation, including precision issues arising from converting between fractional ratios and cent values, the limitations of decimal representations for logarithmic pitch data, and the effects of necessary truncation and clustering. While acknowledging these potential sources of error (and noting that analysis on a logarithmic scale would be optimal), the fundamental trends in interval popularity and system size proved robust even when accounting for these factors.

Therefore, while not an exhaustive machine learning approach, this descriptive statistical analysis confidently identifies key features:
Dominant Equave: The octave (2/1) serves as the interval of equivalence in over 95% of the analyzed systems.
Common System Size: The statistical average size was 17 notes, with 12 being the median and clear mode. For the ATS, this was refined to 14 notes, considering practical application constraints (e.g., guitar fretting).
Most Prominent Intervals: The analysis yielded a set of the 14 most frequent intervals, forming the basis of the ATS:
 
{16/15, 10/9, 7/6, 6/5, 5/4, 4/3, √2, 3/2, 8/5, 5/3, 12/7, 9/5, 15/8, 2/1}

The ATS, constructed from these statistically prevalent components, offers a unique perspective—a tuning system reflecting the central tendencies found within the diverse tapestry of the Scala Archive.

Further details of the analysis, including specific statistical distributions, graphical representations, data processing considerations, and comparisons, are presented in the following draft analysis section. Further research avenues, potentially involving more sophisticated correlation analyses, remain possible.

DRAFT: 

This tuning system is a simple descriptive statistical representation of the scala archive, a renowned curated database of global tunings, seeking common ground and practical use among diverse world tunings.

Interval    Traditional Western Name
16/15       minor diatonic semitone
10/9        minor whole tone
7/6         septimal minor third
6/5         minor third
5/4         major third
4/3         perfect fourth
√2
3/2         perfect fifth
8/5         minor sixth
5/3         major sixth
12/7        septimal major sixth
9/5         just minor seventh
15/8        classic major seventh
2/1         octave


Statistics and tuning construction:

Out of the 5,176 files, the range of system sizes extends from 2 to 579. The average system size is 17, with a median of 12. The mode is also 12, appearing 1,546 times, followed by 7-note size tunings with 715 occurrences. This signifies a diverse collection, albeit with a notable concentration of systems hovering around the 12-note mark.

Top 5 Sizes

Size  Occurrences
12    1546
7     715
5     231
19    218
8     206


While some files span multiple octaves or include non-reduced intervals below the unison, these instances are relatively rare. Most are periodic tunings in alignment with the octave, the archive's most common interval. (Note: rather than relatively rare, some are intentionally wrong, since scala file definition specifies the omission of the 1, and conclude with the equave, implementations may totally ignore those values)

In a direct analysis of the files, the first key from each tuning, totaling 87,558 notes, reveals the octave as the most common, appearing with its exact representation in 4,481 total files and with close variations in practically all tunings.

The perfect fifth emerges as the second most popular interval, succeeded by the perfect fourth and major third.

Distribution of intervals. The two graphics depict identical data. The first graphic displays both vertical and horizontal axes on a linear scale, while the second utilizes a logarithmic scale for the vertical axis. This logarithmic scale highlights intervals that occur only once, significantly beyond the octave, as well as those appearing below a value of 1.

Top 5 Intervals

Interval  Name              Occurrences
2/1       octave            4481
3/2       perfect fifth     2001
4/3       perfect fourth    1743
5/4       major third       1290
9/8       major whole tone  1095



Assuming all tunings are periodic, cyclical pitch sets, the octave is identified as the interval of equivalence in 4,379 tuning files. The next most common equave is the twelfth, with only 93 files.

When calculating all added tones, the complete interval matrix only for the octave-ending tunings yields a total of 2,641,310 intervals, and the list of the most frequent remains largely unchanged.


The two graphics present distinct datasets. The first graphic represents the scan of the initial key in each file, while the second illustrates the scan subsequent to computing all matrices. Both graphics showcase the top 17 intervals, which exhibit remarkable similarity. Each graph encompasses a single octave, with both vertical and horizontal axes set to a logarithmic scale.


(Why is it important to calculate the interval matrix and added tones to determine the most common intervals?

Take this periodic tuning, for example: 16/15 6/5 8/5 9/5 2/1.

If you're not very familiar with intervals, simply seeing the initial key doesn't tell you anything. However, upon computing the matrix for this 5-note periodic tuning, it reveals 14 unique intervals. Among these, the most common intervals are the fifth (3/2), the fourth (4/3), the major whole tone (9/8), and the Pythagorean minor seventh (16/9) – all of which aren't explicitly mentioned in the "first" key.)

There are precision issues affecting interval categorization, resulting from the conversion of fractions and cents, the dual languages of scala files, to a common decimal representation. This inherits machine number problems. When calculating the complete matrix of equal division systems, where a size of any given number should imply the same diversity, the precision nuances in floating-point arithmetic may lead to some being counted as different.

Another problem arises in categorizing cent tunings. Some files may refer to the same note, but due to differences in the amount of digits in their definitions, no program will consider them equal. (701.955 != 701.95)

You can attempt to correct this by equally limiting the number of digits, which would effectively reduce the number of individual distinct intervals. However, since truncation occurs in their decimal format, an uneven definition loss of musical notes is observed due to their original distribution, which is nonlinear (without repetitions).

The graph represents the tuning space horizontally and accumulates identical exact repetitions vertically.


Both graphics portray identical data, but the second one illustrates the data after truncation (with a maximum error of approximately 0.2 cents). Both visuals display the top 17 intervals, which remained consistent even after truncation. This reduction resulted in 242,538 unique intervals being compressed to just 9,997. The logarithmic view in the graphic also highlights the uneven definition loss of musical notes post-truncation, which was executed on the decimal data.


Progressively truncating the notes in this way, doesn't significantly alter popularity, even a 2-cent error proved insufficient to dislodge any peak prominence.

Additionally, the graph experiences intrinsic truncation due to its fixed resolution, significantly lower than the data range. Consequently, different notes are depicted on the same pixel, this is used to add a third dimension to the graph, highlighting note concentrations, which are always very close to some of the already favored intervals. For example, the perfect fifth has a concentration of notes next to it, hinting at systems like 12-tone equal temperament, where the fifth is 700 cents. However, without altering the graphical scale, these clusters won't even be apparent.


Both graphics represent the analysis of the initial keys, displaying the same dataset. However, the first graphic features a vertical logarithmic scale, while the second employs a linear scale. Presented as a heat map, red areas denote note concentrations (which are not visible in the linear view), while blue indicates fewer notes.

The generated systems employing the 17 most frequent intervals, are symmetric in both cases, reflecting a mirror image via the square root of 2. They comprise half superparticular intervals and half their reduced inversions, the perfect fourth and fifth, major third and minor sixth, minor third and major sixth, etc.

Nonetheless, some of these intervals are very small in practice, which poses minimal concerns for keyboard or synthesizer configurations but imposes constraints upon the guitar's limited space, among other factors that make it less suitable for very precise tunings; and 17 was just the average system size.

The final generated system consists of 13 notes, or 14 when including the square root of 2. This selection exhibits near-complete coverage of the tuning space. Graphically, their common-tone aggregate resembles the added tones for the entire collection, which is interesting. The intervals that were left out from the average 17 due to their proximity haven't disappeared entirely; they remain popular, even surpassing those included, although the major whole-tone was removed from the main key, it still exists in some of the others.


The first image corresponds to the analysis of the full archive's interval matrix, showcasing the 17 most popular intervals. The second image depicts the same graphic process, computing the interval matrix and accumulating the repetitions vertically, but on the newly generated tuning system. The general contour of both is similar, this type of tuning analysis typically provides the fingerprint for a tuning. This means the 14-note system generates a similar fingerprint to the entire database of 2.5 million notes.

The system does not match any of the existing files.

Analysis using subsets of the archive—half or a third selected randomly—still yielded the same most frequent intervals. However, for a more accurate representation of an average world tuning system, it's essential to curate the data better. This would involve handpicking the most well-known tunings that are or were actually in use, rather than relying on the full Scala archive, which contains numerous modern tunings seldom used.


Composition with the average system


Improvisation with the average system


TODO: Additional statistics:

The first ~500 most frequent intervals comprise just, rational, and integer ratio intervals before cent-defined intervals like the octave at 1200 cents appear.

How to:

The program developed for this analysis is open-source and available at [LINK]. It's designed for straightforward usage—simply load any .scl file or files, and it will promptly conduct and showcase statistics on them. The analysis comes in two modes: 'direct' examines files as they are, focusing on the first key, while 'full' generates interval matrices for all files. Notably, the 'full' analysis uses a fixed equave of 2:1, a setting implemented after discovering that 95% of the database concludes with a 2:1 equave. This equave parameter can be adjusted within the code for further exploration and customization.

Diophantine Limits in Quantum Search: A Three Gap Theorem Perspective

The Rhythms of Chance The application of Grover's quantum search algorithm to solve specific Diophantine equations within bounded intege...