Log In Sign Up

Mathematics and Flamenco: An Unexpected Partnership

In this paper, we present a series of mathematical problems which throw interesting lights on flamenco music. More specifically, these are problems in discrete and computational mathematics suggested by an analytical (not compositional) examination of flamenco “cante” (singing). As a consequence, since the problems are taken from a culturally specific context, the examples can make more effective mathematics education.


page 9

page 18


Adventures in Mathematical Reasoning

"Mathematics is not a careful march down a well-cleared highway, but a j...

A Detailed Analysis of Quicksort Algorithms with Experimental Mathematics

We study several variants of single-pivot and multi-pivot Quicksort algo...

The human quest for discovering mathematical beauty in the arts

In the words of the twentieth-century British mathematician G. H. Hardy,...

Charles Babbage, Ada Lovelace, and the Bernoulli Numbers

This chapter makes needed corrections to an unduly negative scholarly vi...

The Physicalization of Metamathematics and Its Implications for the Foundations of Mathematics

Both metamathematics and physics are posited to emerge from samplings by...

Complexity Science for Simpletons

In this article, we shall describe some of the most interesting topics i...

Current Trends in the Use of Eye Tracking in Mathematics Education Research: A PME Survey

Eye tracking (ET) is a research method that receives growing interest in...

1 Introduction

In this paper, we present a series of mathematical problems which throw interesting lights on flamenco music. More specifically, these are problems in discrete and computational mathematics suggested by an analytical (not compositional) examination of flamenco “cante” (singing). As a consequence, since the problems are taken from a culturally specific context, the examples can make more effective mathematics education. There is a vast literature dealing with the relationship between culture and mathematics, much of it concerning the term ethnomathematics [1, 2, 28].

The questions analyzed here are a selection of problems that arose in the course of the COFLA project111COFLA: COmputational analysis of FLAmenco music. Some of them have already been examined, while others are open problems currently being worked on. Their difficulty spans a considerable range, some being suitable for assignments in mathematics classes and others for research projects, depending on the level of mathematical sophistication and knowledge required to tackle them.

Flamenco music was born in Andalusia and is well known around the world. It has been declared an Intangible World Heritage by UNESCO222 Flamenco music is a unique musical genre with an identity and originality worthy of scientific study. In this article, we pose several problems which arose during a research project which analyzes flamenco rhythms and melodies. We propose several possible answers based on a study that uses mathematics as a codifying operator, focused around three basic questions:

  1. What musical properties are preferred by flamenco aficionados; what do they find most interesting in a piece?

  2. How can flamenco rhythms be compared automatically? Or, to put it another way, how can the similarity between two pieces be quantified?

  3. How can a piece of flamenco music be simplified or transcribed at a lower level of complexity?

The search for preferred properties in music in the oral tradition leads to the field of ethnomusicology, a scientific discipline formerly called comparative musicology. By “preferred properties” we mean here the preferences of flamenco aficionados, who are linked specifically to the cultural aspects of the people or region the music belongs to. For more information about ethnomusicology and computational ethnomusicology we recommend the monographs [27] and [22], respectively.

The study of musical similarity is part of the fields of music technology, musicology, and psychology. It is related on one hand to the acoustical properties fundamental frequency, harmonics and energy among other aspects, and on the other, to musical properties such as rhythm, harmony and phrasing. It also takes into account psycho-social variables such as emotion, character and sociocultural aspects. Some notable work in this area can be found in [20] and [29].

Lastly, the problem of automatic transcription involves such areas as signal processing, musical psychology, and musical information retrieval (MIR). For more information about automatic transcription of flamenco cante, see [12, 24].

In addition, these types of questions are suitable for student assignments and interested readers, both in music and mathematics at various levels. They can be used to broaden the perspective of the general public about mathematics, and also about flamenco, often considered a minor genre by those not familiar with it.

2 A short note about flamenco cante

In this section, we give a brief introduction to the world of flamenco music for readers not previously familiar with it. Being in the oral tradition, flamenco music is created, composed, and transmitted in a different way than Western or classical music. Flamenco has its own rules and its own terminology. Moreover, its standards for evaluating and performing are not necessarily the same as those for other types of music.

Since the problems presented in this paper are derived from a study of cante rhythm and melodies, the basic concepts we will treat here relate only to these aspects. For a more detailed description of other elements such as harmony, structure, form, metrics and themes, readers are referred to the manual [11]. Some of the fundamental aspects of flamenco music are compás (beat or measure), ornamentation and improvisation. An essential element of the genre is the seemingly paradoxical blending of “obligation” with “freedom.” This will be explained in detail but without technical rigor.

On compás: The flamenco cante (note that this is different from canto, a Spanish word for “singing”) uses a meter (compás) in which the accented beats are distributed in a particular pattern in a short sequence that repeats at regular intervals. The singer must adjust the phrases of the music to this periodic cycle of accents and, in fact, one of the worst criticisms that flamenco aficionados can make of a singer is to say that they “lag behind,” meaning that they are not keeping up with the pattern of the compás. When the performer has “interiorized” the rhythm, they can play with the timing, using musical resources such as rests and longer phrases that enhance the rhythmic color of the performance. The rhythm is thus a blend of freedom and restriction.

The terms compás (beat, pulse, or musical measure) and rhythm have a specific meaning in flamenco. The compás is the pattern of accents (the sequence of handclaps or taps) that is repeated throughout the whole cante, and can be heard in the guitar and percussion accompaniment. Rhythm is a broader concept, referring to how the cante, toque or baile is performed, which may involve “playing” with the timing over the base laid down by the strict meter or compás.

Flamenco rhythms have three types of measures or distributions of accents: binary (a strong accent every 2 or 4 beats), ternary (every 3 beats), and amalgamated 12-beat rhythms. Figures 2 and 2 show flamenco ternary rhythmic patterns in box and numerical notation (used in dancing schools) respectively. The strong accents are placed as shown. The reader can play them by clapping louder where there are dots or bold numbers and softer otherwise. Each compás is labelled with the name of the flamenco style or palo that uses it, although the compases are not unique to the styles indicated. For example, the fandango compás is also used in sevillanas and sometimes in bulerías. The soleá compás is also used in alegrías, and the guajira compás in peteneras333A brief introduction and listening can be found at our website

Figure 1: Box notation. Five 12-beat rhythmic patterns.
[1 2 3 4 5 6 7 8 9 10 11 12]-fandango [1 2 3 4 5 6 7 8 9 10 11 12]- soleá [1 2 3 4 5 6 7 8 9 10 11 12]-bulería [1 2 3 4 5 6 7 8 9 10 11 12]-seguiriya [1 2 3 4 5 6 7 8 9 10 11 12]-guajira
Figure 2: Numerical notation of 12-beat flamenco rhythmics.

On melody: Little is known about the origins of flamenco melodies. Some are derived from popular or folk songs that were adapted to flamenco by flamenco singers, while others were composed by the singers themselves. Examples of the former include the petenera melody, and of the latter, personal fandangos which may be named for the place where they were composed or for the singer or supposed composer. Examples include the fandango de Huelva, de Alosno, fandango del Niño Gloria, del Carbonerillo, and fandango de Chocolate, among others.

A notable feature of flamenco melodies is the abundant use of ornamentation, melisma (multiple notes sung on a single syllable) and the apparent lack of a steady rhythm. The last feature is due to the fact that the melodic rhythm of the cante generally does not strictly follow the meter or compás played by the percussion and guitar, although the melodic phrase must synchronize with the compás at the end of each cycle. Moreover, although there is an established melodic pattern for each cante, the melodies are performed with variations on the base pattern that depend on the abilities and esthetic preferences of the singer or the school of cante to which the performer adheres. The same cante with the same words will sound differently performed by, say, Antonio Mairena than by Chano Lobato444Two audios can be listen at This is due in large part to their individual use of phrasing (organization of the phrases), ornamentations, and timbre, which give flamenco cante a readily recognizable esthetic that also distinguishes it from other types of songs. In any case, flamenco music has certain types of ornamental motifs and phrasing in common that make it an interesting subject of musicological study. Lastly, from the point of view of music technology (the study of music by means of computers), the elaborate ornamentation of flamenco makes it difficult to automate the separation of the notes of the melodic pattern from the melismatic ornamentation [15, 13, 14]. An example can be displayed on the videos and

3 Geometric representation of rhythm and melody

3.1 Compás

In order to study flamenco music mathematically, we need to codify the musical parameters that we wish to analyze. In the previous section, we saw two different notations for rhythmic patterns; numeric and box notations. We will now show two geometric notations (transcriptions), chronotonic and polygonal representations.

Chronotonic or histogram representation was first proposed for automatic voice recognition [18]. Let us consider the rhythmic pattern of the seguiriya, which is given by [1 2 3 4 5 6 7 8 9 10 11 12]. This numerical representation does not indicate the relative durations between two consecutive beats. The time between one accent (musical attack or onset) and the next defines the dynamics of the rhythm. For a visual representation that conserves information about time, we depict the time between every pair of accents in two dimensions as shown in Figure 3. Note that the time between every pair of accents is shown in two dimensions (horizontal and vertical), and the representation starts at the beginning of the rhythmic pattern. Observe that Soleá and Seguiriya share in common the absence of accent on the first beat (anacrusis) and then the number of steps increases in one with respect to the other representations. Each duration between accents (rhythmic interval) is represented by a two-dimensional box, and both axes, and , represent the length of time of an interval. The representations in Figure crono can be seen as step functions meaning the temporal profile or behavior of the compás with respect to the “waiting time” between two consecutive attacks.

Figure 3: Chronotonic representation of ternary flamenco patterns.

The polygonal representation depicts the twelve beats of the compás as equidistant points arranged around a circle. We could imagine it as a necklace of white (weak) and black (strong) beads (accents) arranged like the numbers on a clock (Figure 4). If we join each pair of successive strong accents, we draw a polygon whose vertices are exactly the black beads. In the polygonal representation shown in Figure 4, the “1” indicates the position where the rhythmic pattern begins, and the vertices are the strong accents. Note that the chronotonic codification starts at the “1” indicated in Figure 4 and takes into account the times to the next event. A notation which represented the notes of a musical scale by a polygon in a clock diagram appeared as early as 1937 in an article by E. Krenek [23]. We apply it here to visually depict flamenco compás.

Figure 4: Five ternary flamenco compases.

3.2 Melody

Melody is the parameter that defines and distinguishes a particular song. In fact, the word “melody” comes from the Greek word meloidía () which means “choral song” and is identified with the song itself.555Interestingly, in the mariachi music of Mexico, the word “melodía” (“melody”) is used in a similar way to mean a song.

A melody can be represented symbolically (a string of characters) or by audio (a frequency curve or amplitudes from the audio signal). Common symbolic representations are score transcriptions and MIDI files. We term such symbolic formats discrete (a finite amount of data), and audio representations continuous (since they are given by a frequency curve), respectively. Since discrete representations lend themselves better to musical analysis, various different “simplifications” of melodies have been proposed, depending on the analysis to be carried out. For example, the same level of detail in the transcription of a melody is not required to distinguish between two songs as between two performances of the same song. The simplest symbolic representation of a melody is a string of alphabetic symbols corresponding to the notes; for example, “CDE.”

A melody can be defined discretely as a series of sounds with particular pitches and durations; that is, a series of sound frequencies with an associated rhythm that is perceived as single identity. By this definition, a melody can have a simplified representation as a succession of pairs , , where is identified as the length of the melody. Since this representation is not invariant to changes in pitches or tempo, a representation by intervals is also used; that is, and so . The importance of the representation by intervals is that the melodic direction matters for some analyses. If we joint the points of the discrete set , we obtain a polygonal curve termed the melodic contour. Note that the peaks or extreme points of the polygonal function (piecewise linear) are a key characteristic of the melody. Let us examine the monophonic flamenco cante, the deblaEn el barrio de Triana” as an example. Figure 5 shows the audio signal (upper diagram) and the fundamental frequency (lower diagram). The lower part shows a segmentation (simplification of the melody). The data for this segmentation in the time interval ; that is, the first phrase of the melody, are M={(0.2, 385), (0.4, 407), (2.2, 407), (3, 385), (3.3, 407), (4.3, 385), (4.7, 407), (5.2, 385), (5.8, 407), (6.1, 385), (6.5, 330)}. In interval notation, each two-dimensional point is of the form , and we can draw the melodic profile by joining the points.

In summary, a melody can be represented in a variety of ways depending on the information we wish to extract; by a continuous function, a step function (lower part of Figure 5) or polygonal function that is monotone respect to the -coordinate.

Figure 5: Automatic transcription of a phrase of a flamenco melody.

4 Regular rhythms: Optimization problems

4.1 Maximum area rhythms

One of the properties that musicologists and mathematicians have observed in music in various oral traditions is what is called regularity of the rhythm (or of the musical scale) [31]. Regular rhythms have been defined as those which maximize a particular geometric measure. For example, in the polygonal representation of a rhythm, we can use as measures of regularity the sum of the distances between each pair of strong accents (black beads in the necklace) or the area of the rhythm polygon. This suggests the following question:

Problem 1 (Inscribed pentagon of maximum regularity)

Given some measure of regularity (e.g., area, sum, or other) and 12 points uniformly distributed around a circle, what choice of five of these points will maximize regularity by the specified measure?

Problems of this type involve areas of mathematics such as combinatorics and geometry, and have been studied by mathematicians for some time. In 1956, the Hungarian mathematician F. Tóth [30] examined the continuous case. He proved that the set of points on the circle that maximizes the sum of the distances between each pair of consecutive points is precisely the vertices of a regular polygon with sides. To put it another way, the vertices are distributed as regularly as possible in the circumference of the circle. If the criterion of maximum area is considered, it can be proved using basic geometry that for (three points), a triangle inscribed in a circle has maximum area when it is regular; that is, an equilateral triangle666This can be proved formally by a reductio ad absurdum argument in high school.. The general case; that is: The -vertex polygon of maximum area inscribed in a circle is the regular -gon, can be proved using geometric arguments. The proof will be omitted here.

In applying this problem to music, the case of interest is the discrete version of the problem; that is, choosing the vertices of the polygon drawn on a set of fixed points (Problem 1). The general discrete problem is:

Problem 2 (Inscribed polygon of maximum area)

Consider a circle with points located evenly around its circumference. How should of the points be selected in such a way that the polygon whose vertices are the points will have maximum area of all such possible -gons?

We consider here only the case relevant to flamenco music, and , although the arguments can easily be generalized. The proof that the polygon corresponding to the soleá compás (and consequently, seguiriya and guajira as well) is the pentagon of maximum area is as follows. Since the 12 points are distributed uniformly around the circumference of the unit circle, the area of any inscribed polygon based on the points can be written as the sum of triangles anchored to the center of the circle (Figure 6

). These triangles are isosceles because the radius of the circle forms two of their sides. The interior angle of the vertex in the center of the circle is, in fact, 30 degrees. Thus the distribution of the 5 black points chosen from the set of 12 can be encoded as a vector giving the number of triangles between each pair of consecutive accents. For example,

is a soleá and is a bulería. To see that the soleá has a greater area than the bulería, it is sufficient to observe the inequality between the marked subpolygons in Figure 6 (since the area of the rest of the polygon is the same for both cases). We note that although it is visually evident, a formal proof is still needed, since appearances can be deceiving. The formal proof uses basic trigonometry. It is easy to prove that the area of triangle (the triangle whose vertices are the center and points 7 and 8) is exactly half the sine of degrees; that is, . Similarly, the area of triangle is . Thus the area of the polygon drawn for the soleá is

and the polygon for the bulería

Figure 6: Soleá has greater area than bulería.

This proves that the area of the polygon representing the soleá is greater than the area representing the bulería. In fact, it is not difficult to prove that 33222 is associated with the greatest possible area up to permutations (the area of 32322 is the same as that of 33222 because it is only a question of permuting two triangles). Note that a distribution different from one that contains two 3’s and three 2’s must contain one 4 and one 1. If the triangles corresponding to the 4 and the 1 are placed next to each other, they can be transformed into a “3” triangle and a “2” triangle, which, as we have seen, add up to a greater area. As a consequence, the 33222 and 32322 are the distributions of five points with the greatest area. The soleá, seguiriya and guajira rhythms all correspond to 33222; the difference between them is where on the circle the compás starts. The soleá, seguiriya and guajira have the maximum area, but the bulería does not. The fandango rhythm also corresponds to the maximum area over all choices of four points out of twelve equidistant points arranged around the circumference.

In conclusion, turning to the musicological application of this finding, most flamenco rhythms have the “maximum area” property, and the bulería777It is interesting to note that this rhythmic meter, known as the “modern soniquete”, is basically sung using the bulería por soleá, a hybrid of the bulería and soleá. does not have the regularity of the others. Further research could test human subjects (flamenco aficionados and others) to confirm or refute the theory that the maximum area property characterizes preferred flamenco rhythms.

Although an etnomusicological study is beyond the scope of this paper, we include two comments that can be inferred from the study above. First, although the origin of the flamenco rhythmic patterns has not yet been established one can think that the oldest one is the 4/12 (3/4) pattern used in fandangos and the other compound patterns were derived form the 4/12 while maintaining the regularity property. However, in [6] it is claimed that guajira pattern seems to be the “genetic forbear” of the 5/12 flamenco rhythmic patterns. See also the subsection 5.2. Secondly, the pattern used in bulería (and bulería por soleá, alegría, etc.) can be interpreted as a syncopation phenomenon on the soleá pattern. The recent emergence of this pattern in flamenco recordings also supports that idea. Anyway, these and other insights suggested from a mathematical study poses a possible ethnomusicology research project to confirm these theories. For a description of preferred properties in flamenco music, see [5].

4.2 Minimizing the maximum rest: The minmax problem

Let us now examine the maximum area problem as a geometric problem of approximating polygons. Given the regular polygon whose vertices are the 12 points of the clock diagram, we can see how it differs from the soleá polygon. Figure 7 shows the difference in area between these two polygons (the regular and the soleá polygons). The difference in area can be expressed as a sum of the areas between each pair of vertices of the soleá. We call “ears” to the polygons given these areas. Note that maximizing the area of a polygon with 5 vertices is equivalent to minimizing the sum of the areas of its ears. If we denote ear polygons by their end vertices, in Figure 7 this means minimizing the area . We call this criterion minsum because it seeks to minimize the sum of the areas that are left outside the polygon.

Let us now consider another criterion (as we often do in geometrical optimization) known as the minmax criterion. Its goal is to minimize the maximum; that is, to minimize the area of the largest ear. Musically, this can be interpreted as having the shortest possible rest, or time between two consecutive notes. Clearly the bulería rhythmic pattern does not meet the minmax criterion because its largest ear has 5 vertices, and there are other rhythms whose largest ear has a smaller area – the soleá, seguiriya and guajira. The mathematical problem in this section is the following.

Problem 3 (Largest minimum rest)

Consider a circle with points dispersed evenly around its circumference. How can of these points be chosen so that the polygon drawn on these vertices minimizes the area of the largest ear from among all possible choices of points?

Figure 7: The soleá has a smaller maximum rest (ear) than the bulería.

It is clear that the soleá polygon (also but also guajira and seguiriya) is the solution to the problem for and , since there can be no configuration of 5 vertices with all ears having less than 4 vertices. In general, for any and , it is easy to see how to find the polygons that satisfy the minmax criterion. We show it here for the case of and , and leave the general problem to the reader.

Given a polygon with vertices inscribed in a circle on the given points, we say that has length if the longest substring of points between two consecutive vertices of has exactly vertices. In our example, the soleá has length 3 and the bulería has length 4. In fact, the length is the same as one less than the number of vertices (we do not count the last vertex). With points, substrings (ears) and the remainder theorem, we have with , and, in this case, . The pigeonhole principle (Dirichlet principle), says that if we have pigeons to fit into boxes, at least one box must hold pigeons. To apply this in our case, we take the black beads as boxes and all the beads as pigeons. Then at least one black bead must be followed by at least two white beads. To state it another way, there must be an ear of length 3, and so any combination of five vertices for which 3 is the maximum length is an optimal polygon; that is, a polygon that minimizes the maximum ear. Thus any distribution of 5 points with two 3’s and three 2’s will work; for example, 33222 (soleá) or 32322 (not a flamenco rhythm).

5 Mathematical measures of similarity: Comparing two flamenco rhythms

Musical similarity becomes a crucial problem to investigate the origin and evolution of music in an oral tradition. It is also useful for classification of musical styles. The analysis of similarity is an exciting area of research where we can find many interesting mathematical problems. Degree of similarity is calculated using a measure of the distance between two musical interpretations, and the concept of distance between two objects is amply formalized in mathematics. In practice, the calculation of similarity is a difficult problem, since subjective elements such as perception and socio-cultural context come into play. To have an idea of the importance of applications of this concept outside of mathematics, we cite the example of its use in the resolution of legal copyright conflicts in the United States [4]. Although mathematical measures of similarity have been proposed, it should be noted that theoretical definitions are not enough; perceptual validation is also required; that is, experiments with groups of people that show that the measures correspond to listeners’ perception of similarity. One study of mathematical measures of similarity of rhythms can be found in [21, 16].

We describe two measures of distance from [6, 7] which give good results when applied to flamenco compás; chronotonic distance and permutation distance.

5.1 Calculating area: Chronotonic distance

Chronotonic distance was proposed by Gustafson [17] in the area of phonetics to measure the similarity between two speech recordings (voice recognition). If we have two rhythmic patterns represented in chronotonic form as in Figure 3, the chronotonic distance is defined as the area of the difference between the two curves. Let us look at an example: if we superimpose the chronotonic representations of the fandango and the seguiriya, the area between them is 6 (see Figure 8). The chronotonic distance or dissimilarity between any two flamenco rhythms, , is calculated in this way, and Table 1 gives information on the dissimilarity between different pairs of flamenco compases using this measure.

Figure 8: Chronotonic distance between fandango and seguiriya.
Soleá Bulería Seguiriya Guajira Fandango
Soleá 0 6 8 4 10
Bulería 6 0 12 8 14
Seguiriya 8 4 0 8 6
Guajira 4 8 8 0 6
Fandango 10 14 6 6 0
28 40 34 26 36
Max 10 14 12 8 14
Table 1: Table of chronotonic distances.

If we add up the columns in the similarity matrix, we obtain the distance of each respective rhythmic pattern from the others. This quantity, labeled in the table, gives us a numeric value for the “nearness” or “distance” of one rhythmic distribution from the others.

By this means, using the criterion of the sum of distances, the bulería rhythm can be said to be “farther” from the others, and the guijira compás “closer.”

Another criterion, instead of the sum of distances, is the maximum, labeled Max in Table 1. One possible musical interpretation of this method is that the guajira is a sort of prototype representing the identity of flamenco rhythms. However, this is merely a preliminary study of rhythmic patterns; a full musical study supported by historical and cultural data would be required for such a conclusion.

5.2 Calculating exchanges: Permutation distance

A permutation can involve two terms (not necessarily consecutive) in a series. If two consecutive elements are permuted, we call it a swap or exchange. Note that the pattern of the bulería differs from that of the soleá by a swap between elements 6 and 7 (Figure 9).

Figure 9: One swap is sufficient to change to another compás.

This small operation produces a significant change in the musical perception of the piece, so it not surprising that the two patterns are considered different flamenco styles. We will use precisely this operation (swap) to study the mechanisms of rhythmic similarity. It should be noted that the “modern soniquete,” the pattern which we have labeled bulería (which is common in bulería por soleá), has a particular artistic effect, since the swap creates a rest from positions 3 to 7, followed by a state of tension with the two consecutive strong accents on 7 and 8. This distribution of the accents (percussive phrasing) gives the handclaps a sequence of tension and resolution that gives the cante, toque, and baile a unique “flamenco flavor.” These types of changes are found in the compositions of innovators such as Paco de Lucía (Figure 11) and other flamenco guitarists.

This discussion has laid the grounds for the definition of permutation distance proposed in [6, 7]. The permutation distance between two rhythmic patterns and is defined as the minimum number of swaps needed to transform one compás into another. The concept is in the spirit of the Hamming distance, proposed to solve problems in applications of information theory [19]. R. W. Hamming (1915–1998) was an American mathematician whose work had many implications for advances in computer science and telecommunications888During World War II, R. W. Hamming joined the Manhattan Project to solve some equations posed by physicists working on the project. The objective was to determine whether detonating the atomic bomb could ignite the atmosphere. The results of the calculations showed that this would not happen, paving the way for the United States to use the bomb, first in tests in New Mexico and shortly after in Hiroshima and Nagasaki. (Figure 11).

Figure 10: R. W. Hamming.
Figure 11: Camarón de la Isla and Paco de Lucía.

The Hamming distance between two strings of codes of the same length is the number of substitutions that would be required to transform one string into the other. Let us consider an example: if we have the binary strings and , the Hamming distance between them is . The basic operation which is the counting unit is substitution. In the context of flamenco music, in [6] the basic operation was swap or permutation between consecutive beats, and the permutation distance between two compases was the minimum number of swaps need to transform one compás into the other. If we represent the soleá and bulería patterns with ones and zeros, they can be written as and . The Hamming distance between them is 2 and the permutation distance is 1.

: Once we have two rhythms in binary representation, a certain skill is required to efficiently calculate the permutation distance between them. Here we will treat only the case where the binary strings (compases) have the same number of strong accents (ones). The flamenco rhythms soleá, bulería, seguiriya and guajira all have five strong accents. The general problem we wish to solve is the following.

Problem 4 (Calculating the permutation distance)

Consider two binary strings of digits (for arbitrary ) with the same number of ones (and therefore the same number of zeros). Design a procedure to calculate the permutation distance between them efficiently.

Note that when is small, as in the flamenco, where , the permutation distance can be calculated by simple observation. Figure 12 shows the minimum number of swaps needed to transform the seguiriya compás into the guajira compás. But if we think of the general problem for strings of codes of many elements, for example , it is clear that we can not do it by hand. To solve the problem, we use the following idea. Let us represent each string by a vector of the positions of the ones. For example, the seguiriya is represented by and the guajira by . We now observe that we obtain the minimum number of swaps needed by adding the absolute values of the differences between the elements of these auxiliary vectors. What is then the maximum number of operations required to calculate the permutation distance between two strings of elements?

Figure 12: The black dots represent loud claps and the white dots are soft claps. .

In general, when we want to transform one string into another that does not have the same number of ones as the first string, the following restrictions apply (an example is shown in Figure 13):

  1. The rhythm with more strong accents (seguiriya in the example) is transformed to the rhythm with fewer strong accents (fandango in the example).

  2. Each accent (loud clap) in must move to an accent in .

  3. Each accent in (fandango in the example) must receive at least one accent from (seguiriya).

  4. The accents can not cross the end of the string and wrap around to the beginning.

The general problem of calculating the permutation distance between any two long binary strings requires a more complex analysis which is beyond the scope of this work. We note that the assignment of accents for the case of strings with the same number of ones is a (one-to-one) bijection. However, for the case of strings with different numbers of ones, the assignment must be non-injective (several-to-one) or surjective. Readers who wish to know more about this topic may see [3].

Figure 13: The rhythm with more strong accents is transformed into the rhythm with fewer accents. .

Similarly to the way we compared compases using chronotonic distance, we can now obtain the permutation distance between all the ternary flamenco rhythms as shown in Table 2.

Soleá Bulería Seguiriya Guajira Fandango
Soleá 0 1 11 7 7
Bulería 1 0 12 8 8
Seguiriya 11 12 0 4 4
Guajira 7 8 4 0 2
Fandango 7 8 4 2 0
26 29 34 21 21
Max 11 12 12 8 8
Table 2: Table of permutation distances.

We observe that for this similarity measure, when we take the sum of the distances, , as the nearness criterion, the seguiriya is the most dissimilar to the others, and the guajira and fandango are tied as the nearest. A relatively small sum indicates the rhythm is very similar to all the others, whereas a relatively large sum means it is distinct. In a musicological study, more similar to others can be interpreted as oldest in evolution. If we use the maximum distance, Max, then the bulería is again the most dissimilar compás (), as is the seguiriya999This casts doubt on the theory advanced in [26] that the seguiriya is the primal flamenco compás..

This similarity analysis could be applied in investigations of the origins of flamenco rhythms that interpret them as “living beings” that evolve over time under the influence of social parameters such as preferences and fashions. Following this metaphor, we can use bioinformatic techniques, putting the data into a similarity matrix in a phylogenetic tree that can be drawn using tools such as SplitsTree101010 In Figures 15 and 15, we have drawn the phylogenetic trees (in general, graphs are required) of the chronotonic and permutation distances respectively. The “living organisms” (flamenco palos in our case) are the nodes, and the distances between the nodes in the trees are the values given in the respective distance matrix. This methodology can be generalized to other musical parameters and used for a scientific analysis of the evolution and/or classification of flamenco styles111111These tools should be used with caution and the interpretation of their results used merely to supplement analyses carried out from other scientific points of view such as historiography and anthropology..

Figure 14: Phylogenetic tree using chronotonic distance.
Figure 15: Phylogenetic tree using permutation distance.

6 Approximating functions: Melodic simplification

As we noted above, a melodic phrase extracted from a set of audio data can be a string made up of a large number of characters (pitches or notes). In flamenco music, many of the elements of these strings are the result of ornamentation or melismas, and only a few come from the underlying basic melody of the cante; that is, from the skeleton of notes that define the melody. In fact, a manual transcription or score is merely an approximation of the melody containing the few notes chosen as the representative notes that define the melody to the transcriber.

Manual transcription is expensive and subjective. If we forego this and use the audio signal, we must extract a discrete approximation of the continuous signal, representing the cante by a discrete series of notes or pitches. Figure 5 shows the audio signal of a debla and its approximation by a series of pitches. In this operation, we must deal with a fundamental concept in mathematics that has been extensively studied, as it has been used in a great number of real-world applications; namely, approximation theory.

The definitions of “approximate” in the Random House Dictionary are “to approach closely, to bring near, to estimate.” In mathematics, to approximate means to come as close as necessary to achieve a desired result. In our context, the goal is to obtain results as close as possible with the purpose of working with functions that are simpler than the complicated exact functions. A good approximation is a representation that, although not exact, is sufficiently close to be useful for the problem at hand (for example, melodic similarity in flamenco cantes.)

6.1 Approximating a continuous function by a step function

A step function is a piecewise constant function having only finitely many pieces. function in which the image of each element in the domain is a constant. Each of these constant values is called a step of the function. For example, the function in each interval for is a step function defined on the entire positive real line.

Problem 5 (Similarity distance between step functions)

Given two step functions and that represent two melodies defined on the same time interval, design a measure of distance that represents the dissimilarity between the two melodies in some way. Two melodies with a small distance between them should correspond to similar songs.

Problem 6 (Approximation by a step function)

Given a set of points on the plane and an error value , construct a step function that approximates with error (defined as ) no greater than , using the minimum number of horizontal segments.

The vertical distance of a point (where is in the domain of ) from a function is defined as . The problem is thus one of designing an efficient procedure to solve this approximation problem. In music, the interpretation of the problem is as follows. A melodic curve can be approximated by a step function. This is called segmentation in music technology. Given that the range of the flamenco voice is normally limited to one octave, values of the error term equal to a full or half tone should be suitable for extracting the melodic skeleton of a given cante. Thus the melody is encoded as a vector containing the steps of the approximation. These problems are related to the classification of flamenco cantes [10].

Figure 16: Construction of a step function to fit a flamenco melodic curve.

We now describe a method given in [9] that can be used to give an efficient solution to Problem 6. Given a set of points and a tolerance error , let us draw vertical segments of height centered at each point as in Figure 16. The restriction that the vertical distance of each point from the value of the step function may be no more than is the same as asking that intersects all the segments of length . We proceed from left to right placing a step that intersects the greatest number of consecutive vertical segments possible, then another step, and so on. A vertical segment is defined as an interval of the variable , say , where and denote the coordinates of the low and high point respectively. Continuing from left to right, it is sufficient to maintain the intersection with the vertical segments until reaching a segment that does not intersect with , in which case the current step ends and a new step is begun at , updating to (Figure 16). It is not difficult to prove that the number of operations is a linear function of , the number of points in , and the process results in a step function that fulfills the requirements of having a minimum number of steps and an error that does not exceed .

Figure 17:

Before segmentation: well-defined groups, with one outlier; the debla by Chocolate.

Figure 18: After segmentation: well-defined groups, with two outliers: the deblas by Chocolate and Rafael Romero.

To find out whether approximation by step functions gives the desired result for flamenco music, we tested it on a corpus of flamenco cantes containing two styles, deblas and martinetes121212The used dataset is a subset of the TONAS collection available at, creating a phylogenetic tree from the similarity matrix of similarity distances. Details on the computation of the similarity matrix can be seen in [10]. The segmentation algorithm spends less than one second to compute the step functions of the considered melodies collection and speeds up both the time and space complexity of the standard calculation of the similarity matrix on the raw contours without segmentation. The results are shown in Figures 17 and 18 where it can be seen that the clusters before and after simplification are similar, which validates the approximation method used.

7 Some final observations

This article has presented a small collection of problems that could be used in mathematics teaching and research. The singular aspect of this corpus of problems is its origin. The fact that these problems arose naturally in the study of flamenco, a folk art supposedly very different from mathematics, makes it a good candidate for introducing formal mathematical concepts in the classroom using appealing examples, such as the concept of permutation or swap (exchange) of characters in a string and the formal definition of distance (these would be suitable for teaching at the high school level), or dynamic programming and other algorithmic paradigms (in university courses).

The set of problems examined here could be extended to other relevant problems such as the design of search algorithms to recognize musical patterns, useful for classifying styles or variants. We describe an example that illustrates this problem: If we detect that a distinctive

fandango de Valverde

pattern is present in a set of audio data, there is a high probability that it is a

fandango de Huelva cante. We refer the reader to the paper [ismir2012-aggelos] for a recent study of this problem. Other problems in music technology that require further scientific research include:

  • Design a robust algorithm to separate out the voice part of a flamenco recording (most recordings do not separate guitar, percussion and voice) [13].

  • Design a method to estimate the pitch and segmentation of musical notes [12].

  • Design algorithms to automatically detect melodic motifs or ornamentation [15].

  • Study the mathematical properties of preference in the sphere of flamenco music [5].

The main objective that leads us to develop mathematical and computational techniques such as those described in this article is to provide an objective tool to complement and contrast results with those from other scientific fields. Moreover, the multidisciplinary nature of research into flamenco music means that scientific progress can be made in research not only in mathematics, but in other areas as diverse as anthropology, engineering, education and musicology [8].

In conclusion, we note that in addition to the scientific and academic progress this would entail, it is not difficult to imagine potential commercial applications for the software that would emerge from the new music technology that would be developed in the course of such a research program – music recommendation systems, on-line recognition of musical styles, and automatic classification of styles, to name a few examples.


We would like to thank the Junta de Andalucía (Consejería de Innovación, Ciencia y Empresas) under grants P09-TIC-4840 and P12-TIC-1362, and the FEDER funds of the European Union for supporting this research. Special thanks are also extended to Margaret Schroeder for her help in writing this paper. An anonymous referee also deserves our thanks for a careful reading of the manuscript and for many valuable suggestions and comments.


  • [1] M. Ascher (2000). Ethnomathematics for the Geometry Curriculum. MAA NOTES, 59–63.
  • [2] B. Barton (1996). Making sense of ethnomathematics: Ethnomathematics is making sense. Educational Studies in Mathematics, 31(1-2), 201–233.
  • [3] J. Colannino, M. Damian, F. Hurtado, J. Iacono, H. Meijer, S. Ramaswami, G.T. Toussaint (2006). An -time algorithm for the restriction scaffold assignment problem. Journal of Computational Biology, 13(4), 979–989.
  • [4] C. Cronin (1998). Concepts of Melodic Similarity in Music-Copyright Infringement Suits. Computing in Musicology (ed. Walter B. Hewlett, Eleanor Selfridge-Field). MIT Press, Cambridge.
  • [5] J.M. Díaz-Báñez, F.J. Escobar-Borrego (2010). La modulación tonal en las formas musicales del Flamenco: propiedades de preferencia e hibridación armónica. Itamar. Revista de Investigación Musical: Territorios para el Arte, 261–266.
  • [6] J.M. Díaz-Báñez, G. Farigu, F. Gómez, D. Rappaport, G.T. Toussaint (2004). El Compás Flamenco: A Phylogenetic Analysis, Proceedings of BRIDGES: Mathematical Connections in Art, Music, and Science, Winfield, KS, 61–70.
  • [7] J.M. Díaz-Báñez , G. Farigu, F. Gómez, D. Rappaport, G.T. Toussaint (2005). Similaridad y evolución en la rítmica del flamenco: una incursión de la matemática computacional. La Gaceta de la Real Sociedad Matemática Española, 8(2), 489–509.
  • [8] F. Gómez, J.M. Díaz-Báñez, E. Gómez, E., J. Mora (2014). Flamenco music and its Computational Study. In Proceedings of Bridges 2014: Mathematics, Music, Art, Architecture, Culture, 119-126. Tessellations Publishing.
  • [9] J.M. Díaz-Báñez, J.A. Mesa (2001). Fitting rectilinear polygonal curves to a set of points in the plane. European Journal of Oper. Research, 130(1), 214–222.
  • [10] J.M. Díaz-Báñez, J.C. Rizo (2014). An Efficient DTW-Based Approach for Melodic Similarity in Flamenco Singing. In Similarity Search and Applications (pp. 289-300). Springer International Publishing.
  • [11] J.M. Gamboa (2005). Una historia del flamenco. Espasa-Calpe, Madrid.
  • [12] E. Gómez, J. Bonada (2013). Towards computer-assisted flamenco transcription: An experimental comparison of automatic transcription algorithms as applied to a cappella singing. Computer Music Journal, 35(1), 73–90.
  • [13] E. Gómez, F. Cañadas, J. Salamon, J. Bonada, P. Vera, P. Cabañas (2012). Predominant fundamental frequency estimation vs singing voice separation for the automatic transcription of accompanied flamenco singing. Proc. 13th International Society for Music Information Retrieval Conference (ISMIR 2012).
  • [14] F. Gómez, J. Mora, E. Gómez, J.M. Díaz-Báñez (2016). Melodic Contour and Mid-Level Global Features Applied to the Analysis of Flamenco Cantes. Journal of New Music Research, 45 (2), 1–15.
  • [15]

    F. Gómez, A. Pikrakis, J. Mora, J.M. Díaz-Báñez, E. Gómez (2011). Automatic detection of ornamentation in flamenco music. Proc. 4th International Workshop on Machine Learning and Music: Learning from Musical Structure, Granada, Spain.

  • [16] C. Guastavino, F. Gómez, G.T. Toussaint, F. Marandola, E. Gómez (2009). Measuring similarity between flamenco rhythmic patterns. Journal of New Music Research, 38(2), 174–176.
  • [17] K. Gustafson (1987). A new method for displaying speech rhythm, with illustrations from some Nordic languages. Nordic Prosody IV, eds. K. Gregersen, H. Basboll, 105–114, Odense University Press.
  • [18] K. Gustafson (1988). The graphical representation of rhythm, in (PROPH) Progress Report from Oxford Phonetics, 3, 6–26, University of Oxford.
  • [19] R.W. Hamming (1986). Coding and Information Theory. Prentice Hall, Englewood Cliffs NJ.
  • [20] W.B. Hewlett, E. Selfridge-Field, eds. (1998). Melodic Similarity: Concepts, Procedures, and Applications. MIT Press.
  • [21] L. Hofmann-Engl (2002). Rhythmic similarity: A theoretical and empirical approach. Proc. of the Seventh International Conference on Music Perception and Cognition, eds. C. Stevens, D. Burnham, G. McPherson, E. Schubert, J, Renwick, 564–567, Sidney, Australia.
  • [22] A. Holzapfel (2010). Similarity methods for computational ethnomusicology. PhD thesis, Computer Science Department. University of Crete.
  • [23] E. Krenek (2002) Über Neue Musik. Chapter Musik und Mathematik. Verlag der Ringbuchhandlung, Vienna, 71–89, 1937.
  • [24] N. Kroher, E. Gómez, E. (2016). Automatic transcription of flamenco singing from polyphonic music recordings. IEEE/ACM Transactions on Audio, Speech, and Language Processing, 24(5), 901–913.
  • [25] V. I. Levenshtein (1966). Binary codes capable of correcting deletions, insertions and reversals. In Soviet physics doklady (Vol. 10, p. 707).
  • [26] R. Molina, A. Mairena (1963). Mundo y formas del cante flamenco. Ed. Revista de Occidente, Madrid.
  • [27] B. Nettl (1983) The study of ethnomusicology: Twenty-nine issues and concepts (No. 39). University of Illinois Press.
  • [28] N. Presmeg (2007). The role of culture in teaching. Second Handbook of Research on Mathematics Teaching and Learning: A Project of the National Council of Teachers of Mathematics, 1, 435.
  • [29] M. Schmuckler (1999). Testing models of melodic contour similarity. Music Perception, 16, 109–150.
  • [30] L.F. Tóth (1956). On the sum of distances determined by a pointset. Acta. Math. Acad. Sci. Hungar. 7(3) 97–101.
  • [31] G. T. Toussaint (2010). Computational geometric aspects of rhythm, melody, and voice-leading. Computational Geometry: Theory and Applications, 43(1), 2–22.