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 logb(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 Z/pZ and Z/qZ via modular inverses (p1modq and q1modp, 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 logb(a) for b>1, a>0, by iteratively generating a sequence of reduced terms rx without directly computing logarithms. For each step x=0,1,2,:
  • Chain and Fold: Compute rx=axbyx, where yx is an integer chosen such that rx[1,b). This adjusts ax by multiplying or dividing by powers of b, and the total number of adjustments across all steps is tracked as p=|yx|.
  • Bounds and Commas: Maintain dynamic bounds L (initially 1) and U (initially b). After computing rx, if L<rx<U, calculate the commas c0=rx/L and c1=U/rx. Evaluate the ratio: Ratio=max(c0,c1)1min(c0,c1)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=rx if rx<H, or U=rx if rx>H, where H=b/r1 is the initial comma established after the first step.
Optimization: MLA avoids storing the full sequence of rx values by dynamically updating L and U, and it chains computations from the reduced rx 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αmod1. The theorem dictates that the gaps between consecutive sorted points (kα)mod1 for k=1,,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 α.

The MLA operates analogously in a multiplicative setting, examining the sequence rx=axbyx within [1,b), akin to (x×logb(a))mod1. While a full analysis would track all gaps between all sorted rx 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 rx 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(c0,c1)1)/(min(c0,c1)1)<2, applied locally to the interval [L,U] split by rx, 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 c0 or c1 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 axbyx 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 rx for each p/q unveils cyclic group structures in the exponents:
  • x-Sequence: When rx values are sorted by magnitude, their corresponding exponents xk form the cyclic group Z/qZ, generated by p1modq. For the convergent 19/12 of log2(3), q=12, p=19, p1=7mod12, yielding the sequence 0,7,2,9,4,11,6,1,8,3,10,5.  
  • y-Sequence: The exponents yxk (adjustments by powers of b), taken modulo p, form the first q elements of Z/pZ, generated by q1modp. For 19/12, q1=8mod19, producing 0,11,3,14,6,17,9,1,12,4,15,7.  
This duality emerges from the approximation aqbp, linking the algorithm’s musical origins to modular arithmetic.

rx Ratio x yx
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 log2(3), rx=3x2yx, 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 logb(a×bk) highlighting the algorithm’s focus on periodic, fractional components rather than the integer part.

Figure 1: Visualizes the convergent 7/12 for log2(3/2). A 12-sided regular polygon represents Z/12Z, 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)x2y folded into [1,2]. The inner star is labeled {7,4,1,5,2,6,3}, representing exponents y in Z/7Z 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 log2(3/2).



Figure 2: Shows the convergent 6/23 for log3(4/3). A 23-sided regular polygon represents Z/23Z, 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 rx=(4/3)x3yx 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 log3(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 6541 follows 1912 as a convergent of log2(3), a 41-fold equal division of the octave (21/41) poorly approximates the sequence of 41 reduced fifths (3x2yx). In contrast, the subsequent convergent 8453 yields a more accurate alignment. A variant of MLA replaces the ratio threshold of 2 with the golden ratio (ϕ1.618) to select convergents with uniformly distributed commas, enhancing their utility for microtonal approximations.

Figure 3: visualizes interval alignment for three convergents of log2(3), with rows A, B, and C:
  • A: 12-EDO: The interval [1,2] with the first 12 terms of 3x2yx[1,2] (blue) aligns closely with 12 equal divisions (red, step size 21/12), reflecting the phase coherence of 1912 in standard equal temperament.
  • B: 41-EDO: The first 41 terms (blue) diverge significantly from 41 equal divisions (red, step size 21/41), indicating the poor approximation of 6541 due to non-uniform comma distribution.
  • C: 53-EDO: The first 53 terms (blue) align well with 53 equal divisions (red, step size 21/53), demonstrating the efficacy of 8453.    
The geometric contrast underscores that 1912 and 8453 outperform 6541, 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 logb(a), the MLA implicitly reveals a dual cyclic group structure within the exponents. Specifically, when the intermediate terms rx=axbyx (reduced to the interval [1,b)) are sorted by magnitude, their corresponding a-exponents (x) generate the cyclic group Z/qZ via p1modq, while the associated b-exponents (yx) map to the initial elements of Z/pZ with generator q1modp. 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 θ/(2π) (related to trigonometric functions and rotations on the circle group S1) 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:

amodb=˜a,
Subtract b from a until a<b. For example: 14mod5=4.

The normalized ratio mod operator can be defined as:

amod1:b=˜a,
Multiply or divide a by b until a falls within the range (1,b].  For example: 48mod1: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 an<b<an+1, essentially the same reduction or scaling process: 25<48<26, so  48/25=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, 7mod4:5 is calculated as 7mod1: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 {30,31,32,33,34,}.  These numbers, as musical intervals, form a 1:3 ratio, representing consecutive third harmonics: {1,3,9,27,81,}.

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 312mod1:2=312/219=531441/524288, making the set of pitches nearly cyclical. This happens because no integers n and m exist such that 2n=3m, 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 log2(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 log2(3) using the convergent 1912, 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 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 3x. Specifically, if you calculate the first 12 powers of 3, reduce them by 1:2, and order them by size as (3x×2y), the sequence of x's corresponds to the elements in Z/12Z generated by 7. Similarly, the sequence of y's corresponds to the first 12 elements in 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                         

Z/12Z = 7,  2,  9, 4, 11, 6, 1,  8, 3, 10, 5, 0
Z/19Z = -11, -3, -14, -6, -17, -9, -1, -12, -4, -15, -7, ...


Understanding the Setup

For log2(3), the convergent 19/12 gives us p=19 and q=12, where p and q are coprime. This convergent approximates log2(3)1.58496, so 312219. We compute the first q powers of a:
  • rx=3x2yx, for x=0,1,,q1=11,
where yx is chosen to “reduce” the value into the interval [1,b)=[1,2). Specifically:
  • yx=xlog2(3),
ensuring rx=3x2yx[1,2). We then sort these rx values in increasing order, which permutes the indices x and their corresponding yx.

General Rule

For a convergent p/q of logb(a):
  • x sequence: Sorting rx orders the fractional parts {xlogb(a)}{x(p/q)}, giving xk=kp1modq, forming Z/qZ with generator p1.
  • y sequence: The corresponding yxk=(kp1modq)logb(a), when taken modulo p, forms the first q elements of Z/pZ with generator q1modp. This arises because yxx(p/q), and the permutation by p1 interacts with the approximation.

For 19/12:
  • q=12, p=19, p7mod12, p1=7, x: k7mod12,
  • p=19, q=12, q1=8mod19, ymod19: k8mod19.

In conclusion both sequences are group-related:
  • The x exponents form Z/qZ generated by p1modq (here, 7).
  • The y exponents, modulo p, form the first q elements of Z/pZ generated by q1modp (here, 8).
The generator for the y sequence emerges from the inverse relationship due to aqbp, reflecting a duality in the convergent’s structure. For 19/12, it’s 8 because 1218mod19.


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,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 log2(10),

the first reduced link is 101/23, the comma ( H in the code) is 21/108=85=1.6

As each convergent for log2(10)103932819659 indicates that,

103/2101028/2931059/21961 (progressively better)

The previous link added, indicates

102/261027/2891058/21921.6,

And the next link, for example 1029mod1:2=1029/296108=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 log2(5) as 4495889/1936274 using the simple logic explained above, you would need to calculate 51936274, 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 logb(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 log2(3) after 1912 is 6541, but 41 equal divisions of the octave don't approximate 41 consecutive reduced fifths. The subsequent convergent, 8453, 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 21/53 keeps a close approximation, in phase, with the powers of 3 up to 353 and powers of 2 up to 284.

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




#xcjb.blogspot.com
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:
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 d == 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
#phila(3,2, 1000) # output: ['(3/2)', '(8/5)', '(19/12)', '(84/53)', '(485/306)', '(1054/665)']
#mla(3,2, 1000) # output: ['(3/2)', '(8/5)', '(19/12)', '(65/41)','(84/53)', '(485/306)', '(1054/665)']
view raw mla.py hosted with ❤ by GitHub
(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)

No comments:

Post a Comment

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...