The Kolmogorov Complexity of Irish traditional dance music

Michael McGettrick [email protected] School of Mathematical and Statistical Sciences, University of Galway, Galway H91 TK33, Ireland. Paul McGettrick [email protected] Department of Creative Arts, Media and Music, School of Informatics & Creative Arts, Dundalk Institute of Technology, Dundalk A91 K584 Ireland.
(June 14, 2024)
Abstract

We estimate the Kolmogorov complexity of melodies in Irish traditional dance music using Lempel-Ziv compression. The “tunes” of the music are presented in so-called “ABC notation” as simply a sequence of letters from an alphabet: We have no rhythmic variation, with all notes being of equal length. Our estimation of algorithmic complexity can be used to distinguish “simple” or “easy” tunes (with more repetition) from “difficult” ones (with less repetition) which should prove useful for students learning tunes. We further present a comparison of two tune categories (reels and jigs) in terms of their complexity.

1 Introduction

The Kolmororov Complexity [2, 5] of s sequence of letters is defined to be the length of the shortest program which will output that sequence of letters. As such, it is known to be uncomputable. Nonetheless, it can be estimated in a reliable way using lossless compression techniques such as Lempel-Ziv compression [8]. Li and Sleep [3, 4] show how these ideas can be used to estimate the similarity between different melodies.

2 Kolmogorov (algorithmic) complexity via Lempel-Ziv (LZ) compression

The Lempel-Ziv (family) of lossless compression algorithms is known to be asymptotically optimal [6]. In the following sections, we examine the compression of a common reel Sally Gardens using two Lempel-Ziv variants: LZ77 and LZ78.

2.1 LZ78 [7] compression of the reel Sally Gardens

In Table 1 we present the reel Sally Gardens and in Table 2 its compression using LZ78. The compressed version has 56 “tokens”/“words” with a compression ration of approximately 2.3.

ggdg bbgb DbEb Dbab DDbD EFGE Dbab gede
ggdg bbgb DbEb Dbab DDbD EFGE Dbab gggg
DGGF GGDG GGBG AGFG EAAG AAEA AABG AGEG
DGGF GGDG GGBG AGFG DDbD EFGE Dbab gggg
Table 1: The reel Sally Gardens written in ABC notation. For ease of reading, the tune is written in 4 lines, but from an information theory viewpoint, one ignores all spaces and new line characters and simply regards the tune as a sequence of characters/letters from the alphabet {a,b,c,d,e,f,g,A,B,C,D,E,F,G}. Here, lower/upper case letters are in the lower/upper octave respectively. We have taken standard musical liberty with the notation, representing all f\musSharp/F\musSharp as f/F respectively.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Uncompressed string: g gd gb b gbD bE bD ba bDD bDE F G E D bab ge
Compressed string: g 1d 1b b 3D 4E 4D 4a 7D 7E F G E D 8b 1e
Cumulative note count: 1 3 5 6 9 11 13 15 18 21 22 23 24 25 28 30

\ \bullet\ \bullet∙ ∙

\bullet\ \bullet\ ∙ ∙ 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 d e gg dg bb gbDb Eb Db a bDDb DE FG ED babg ggg DG GF d e 1g 17g 4b 5b 13b 14b a 9b 14E 11G 13D 15g 19g 14G 12F 31 32 34 36 38 42 44 46 47 51 53 55 57 61 64 66 68 \ \bullet\ \bullet∙ ∙

\bullet\ \bullet\ ∙ ∙ 34 35 36 37 38 39 40 41 42 43 44 45 46 47 GG DGG GB GA GFG EA A GAA EAA AB GAG EG DGGF GGD 12G 32G 12B 12A 33G 13A A 37A 39A 40B 37G 13G 35F 34D 70 73 75 77 80 82 83 86 89 91 94 96 100 103 \ \bullet\ \bullet∙ ∙

\bullet\ \bullet\ ∙ ∙ 48 49 50 51 52 53 54 55 56 GGG DGA GFGD DbD EF GE Dba bg ggg 34G 32A 38D 24D 13F 12E 24a 4g 19g 106 109 113 116 118 120 123 125 128

Table 2: LZ78 compression of Sally Gardens (see Table 1). Each letter represents a quaver in the original melody. The compression ratio is 128/5612856128/56128 / 56 or approximately 2.3. For illustrative purposes, one particular entry is highlighted in color. Entry GFGD in column 50 is D appended to GFG. In turn, GFG in column 38 is G appended to GF. In turn GF in column 33 is F appended to G. Finally G is in column 12.

2.2 LZ77 [8] compression of the reel Sally Gardens

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Uncompressed string: g g d g b b gb D b E bDb a bD Db D E F G
Compressed string: g g d g b b 4,2 D b E 8,3 a 8,2 9,2 D E F G
Cumulative note count: 1 2 3 4 5 6 8 9 10 11 14 15 17 19 20 21 22 23

\ \bullet\ \bullet∙ ∙

\bullet\ \bullet\ ∙ ∙ 19 20 21 22 23 24 25 26 27 28 29 30 31 E Dbab g e d e ggdgbbgbDbEbDbabDDbDEFGEDbabg gg g D G G FG E 13,4 g e d e 1,29 1,2 g D G G 22,2 24 28 29 30 31 32 61 63 64 65 66 67 69 \ \bullet\ \bullet∙ ∙

\bullet\ \bullet\ ∙ ∙ 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 G DGG GDG A GFG E A AG AA EAA A B GAG E GDGG G 65,3 70,3 A 67,3 E A 77,2 82,2 81,3 A B 76,3 E 70,4 70 73 76 77 80 81 82 84 86 89 90 91 94 95 99 \ \bullet\ \bullet∙ ∙

\bullet\ \bullet\ ∙ ∙ 47 48 FGGDGGGDGAGFG DDbDEFGEDbabgggg 68,13 49,16 112 128

Table 3: LZ77 compression of Sally Gardens (see Table 1). Each letter represents a quaver in the original melody. In the third row of the table, the notation i,j𝑖𝑗i,jitalic_i , italic_j means one should go back to position i𝑖iitalic_i in the melody (position given in the fourth row of the table) and copy j𝑗jitalic_j notes/letters. The compression ratio is 128/4812848128/48128 / 48 or approximately 2.7.

Comparing Tables 1 and 2 we observe, from a musical viewpoint, clearly repeated phrases are not picked up by the LZ78 compression. The second line in Table 1 is in fact the same as the first line except for the last three notes ‘ggg’.

In Table 2, columns 19 to 30, we could have just issued an instruction to repeat columns 1 to 15 (with an added ‘g’ at the end): It is clear better compression is possible. 111A fundamental limitation with the LZ78 protocol is that the entries in the dictionary can only increase by one symbol at a time.

In LZ77, we do not use a dictionary, instead a sliding window is used, which will pick up (much) larger blocks of repeated letters/notes. In Table 3 we present the LZ77 compression of the same reel Sally Gardens. Once can see immediately (columns 25, 47, 48) the significantly larger blocks of letters (musical phrases) that are identified as occuring previously.

3 Compression ratios for reels

We select a (musically) representative sample of 60 reels from the online database [1]. The most common key for reels is D (about 45%), the second most common G (about 30%), with the remaining 25% in a variety of keys. We examined tunes from across the key spectrum. To enable fair comparison, we only examined “standard” length reels, i.e. ones with exactly two parts: In our representation this corresponds to a sequence of 128 letters. In summary,

  • Each reel has two parts

  • Each part has exactly 64 (quaver) notes

  • Each bar has exactly 8 (quaver) notes

  • Any longer notes are written as sequences of quavers adding up to the same note length. So, any crotchet in the tune is written as two identical quavers, any dotted crotchet as three quavers, etc.

  • Each part of the tune has 8 bars, and overall the tune has 16 bars

X: 1

T: Sally Gardens, The

Z: Jeremy

S: https://thesession.org/tunes/98#setting98

R: reel

M: 4/4

L: 1/8

K: Gmaj

|:G2GA BAGB|dBeB dBAB|d2Bd efge|dBAB GEDE|

GFGA BAGB|d2eB dBAB|d2Bd efge|dBAB G4:|

|:dggf g2de|g2bg ageg|eaag a2eg|a2bg ageg|

dggf g2de|g2bg ageg|d2Bd efge|dBAB G4:|

(a) The reel Sally Gardens in “abc” notation, taken verbatim from [1]

GGGABAGBdBeBdBABddBdefgedBABGEDEGFGABAGBddeBdBABddBdefgedBABGGGG
dggfggdeggbgagegeaagaaegaabgagegdggfggdeggbgagegddBdefgedBABGGGG

(b) Representation of the tune using 128 quavers (colour/shading only for purposes of legibility)

G GG A B A G B d B e BdB AB d dB d e f g e dBAB G E D E G F GABAGBd de BdBABddBdefgedBABG
GGG d g g fg g de gg b g a ge ge a ag aa eg aa bgageg dggfggdeggbgageg ddBdefgedBABGGGG

(c) Compressed version: Contiguous letters are counted as one unit
 G,[0, 2],A,B,A,G,B,d,B,e,[7, 3],[3, 2],d,[8, 2],d,e,f,g,e,[12, 4],G,E,D,E,G,F,[2, 7],[19, 2],
 [11, 18],[0, 3],d,g,g,[21, 2],g,[19, 2],[65, 2],b,g,a,[22, 2],[22, 2],a,[76, 2],[81, 2],
 [71, 2], [81, 2],[74, 6],[64, 16],[48, 16]
(d) Compressed version: Every block of 2 or more letters is represented by [i,j], meaning “go back to position i and copy j letters” Note here, as is common in programming, we count from 0. This representation is of length 50.
Figure 1: Our python code processes the tune (initially in “abc” notation, (a)), though intermediate stages to reach the compressed version (d)

Our analysis of the representative sample of 60 reels gives an average compression ratio of 2.79 (to two decimal places) with standard deviation 0.46.

3.1 Example: Comparison of reels with high and low complexity

From the 60 tunes analyzed, the maximum and minimum compression ratios obtained were

  • maximum compression ratio of 4.92absent4.92\approx 4.92≈ 4.92 for The Concertina Reel

  • minimum compression ratio of exactly 2 for The Star of Munster

The details for this comparison are shown in Table 4. The reader is encouraged to observe for themselves how much more repetitive The Concertina Reel is compared to The Star of Munster.

Name Notes Compression Compressed length
The Concertina Reel AAFABAFA AAFABAFA BBBABBBA BBBABAFA AAFABAFA AAFABAFA FABcdddA BAFEDDDD AdddAddd AddABAFA BBBABBBA BBBABAFA AdddAddd AddABAFA FABcdddA BAFEDDDD A A F A B [1, 3] [0, 8] B [16, 2] [15, 10] [5, 11] [0, 8] [2, 3] c d [52, 2] [3, 4] E D [60, 3] A [52, 4] [65, 6] [11, 22] [65, 15] [48, 16] 26
The Star of Munster ccAcBBGB AGEFGEDG EAABcBcd eaafgfed cBAcBAGB AGEFGEDG EAABcded cABGAAAA eaabageg agbgagef gfgagfef gfafgfdf eaabageg agbgagef gggeaaga bgafgeee c c A c B B G B A G E F [9, 2] D [9, 2] A A B [3, 2] c d e a a f g f e d [3, 2] [2, 3] [8, 2] [7, 14] [23, 2] [31, 2] [18, 2] G [17, 2] [17, 2] [24, 3] b a g e g [68, 2] b [71, 3] e [27, 3] [71, 3] [29, 2] [27, 3] [26, 4] d [29, 2] [65, 16] [112, 2] [24, 3] [71, 2] [74, 3] [27, 2] e [125, 2] 64
Table 4: Comparison of two reels with very low and very high Kolmogorov Complexity (shading/coloring only for purposes of legibility)

4 Compression ratios for jigs

From the same database [1] we select a (musically) representative sample of 60 jigs. We examined tunes from across the key spectrum. To enable fair comparison, we only examined “standard” length jigs, i.e. ones with exactly two parts: In our representation this corresponds to a sequence of 96 letters. In summary,

  • Each jig has two parts

  • Each part has exactly 48 (quaver) notes

  • Each bar has exactly 6 (quaver) notes

  • Any longer notes are written as sequences of quavers adding up to the same note length. So, any crotchet in the tune is written as two identical quavers, any dotted crotchet as three quavers, etc.

  • Each part of the tune has 8 bars, and overall the tune has 16 bars

Our analysis of the representative sample of 60 jigs gives an average compression ratio of 2.61 (to two decimal places) with standard deviation 0.40.

5 Discussion of results

Refer to caption
(a) Distribution of compression ratios for 60 reels. The outlier with largest compression ratio (4.92absent4.92\approx 4.92≈ 4.92) is The Concertina Reel
Refer to caption
(b) Distribution of compression ratios for 60 jigs.
Figure 2: Compression ratios for jigs and reels

In Figure 2 we display our results, where we use 20 bins for the different compression ratios.

In order to be able to account for differences in the (approximation to the) Kolmogorov complexity of reels versus jigs, we need to take in to account the different lengths of these melodies / alphabet strings. It should be clear that, for finite fixed alphabet size, the compression ratio will in general be larger for longer strings (for longer strings, letters will repeat more often). In our case, the comparison is between strings of length 96 (jigs) and length 124 (reels). We would expect, all other things being equal, a slightly higher compression ration for the longer string (reels). To account for this effect (which is not intrinsic to the music), we generate sequences of random letters from the 13 letter alphabet A={a,b,c,d,e,f,g,h,i,j,k,l,m}𝐴𝑎𝑏𝑐𝑑𝑒𝑓𝑔𝑖𝑗𝑘𝑙𝑚A=\{a,b,c,d,e,f,g,h,i,j,k,l,m\}italic_A = { italic_a , italic_b , italic_c , italic_d , italic_e , italic_f , italic_g , italic_h , italic_i , italic_j , italic_k , italic_l , italic_m }. This corresponds to the lower octave, and most of the higher octave in the tunes considered (the highest note in the high octave is not used).

For strings of length [50,100,150,200]50100150200[50,100,150,200][ 50 , 100 , 150 , 200 ] we get average compression ratios of [1.13,1.24,1.33,1.40]1.131.241.331.40[1.13,1.24,1.33,1.40][ 1.13 , 1.24 , 1.33 , 1.40 ] respectively. In the region of interest (lengths between 96 and 128), the dependence of compression ratio on string length is approximately linear. In particular, for random strings of length 96/128 chosen from the alphabet A𝐴Aitalic_A, we get average compression ratios of 1.23/1.29 respectively. We use this to normalize the results from Sections 4 and 3 to calculate what we would expect the average compression ratio for jigs to be, were they of the same length as reels: 1.291.23(2.61)2.731.291.232.612.73\frac{1.29}{1.23}(2.61)\approx 2.73divide start_ARG 1.29 end_ARG start_ARG 1.23 end_ARG ( 2.61 ) ≈ 2.73.

Our result therefore is to conclude reels have slightly less intrinsic (Kolmogorov) complexity than jigs, given the two averaged, normalized compression ratios of approximately 2.79 and 2.73 respectively. Separately from comparing categories such as reels and jigs, our estimations of Kolmogorov complexity can be used to distinguish more repetitive tunes from less repetitive ones. This should be of use to those learning Irish traditional dance music, who may want to start with tunes of low Kolmogorov complexity. We emphasize that we are not concerned with efficiency issues in actually compressing the sequences considered, and in fact the compression algorithms described may be very inefficient. We are only concerned with the size (length) of the resulting compression, how we can minimize that to get the best estimate of Kolmogorov complexity, and what that size can tell us about the tune being compressed.

In future work, we plan to apply this analysis to other (large) families of tunes, such as hornpipes and polkas. We are also exploring how Kolmogorov complexity, and other techniques from information theory can be applied to harmonic music (for which there is a much larger corpus).

References

  • [1] Jeremy Keith. Traditional Irish tunes on The Session — thesession.org. https://thesession.org/tunes. [Accessed 29-04-2024].
  • [2] A. N. Kolmogorov. Three approaches to the quantitative definition of information. Problems of Information Transmission, 1:1–7, 1965.
  • [3] Ming Li and Ronan Sleep. Improving melody classification by discriminant feature extraction and fusion. In ISMIR 2004, 5th International Conference on Music Information Retrieval, Barcelona, Spain, October 10-14, 2004, Proceedings, 2004.
  • [4] Ming Li and Ronan Sleep. Melody classification using a similarity metric based on kolmogorov complexity. In Journées d’informatique musicale, 2004.
  • [5] Paul Vitányi Ming Li. An Introduction to Kolmogorov Complexity and Its Applications. Springer, 1997.
  • [6] A.D. Wyner and J. Ziv. The sliding-window lempel-ziv algorithm is asymptotically optimal. Proceedings of the IEEE, 82(6):872–877, 1994.
  • [7] J. Ziv and A. Lempel. Compression of individual sequences via variable-rate coding. IEEE Transactions on Information Theory, 24(5):530–536, 1978.
  • [8] Jacob Ziv and Abraham Lempel. A universal algorithm for sequential data compression. IEEE Trans. Inf. Theory, 23(3):337–343, 1977.