Math for Music Games

This article is a draft. You can help expanding it by editing or discussing in the comments.

click here to edit!

Mathematics understood as proving theorems will not be the focus of our considerations here. You may be inspired by any field, and also incorporate it in your music games, here however, we list specific areas for a general use in music game design.

Disciplinary shout-outs

Tuning system is a topic that shows up the quickest when talking about math in music. It's an ancient observation that you need to shorten the musical string in half to arrive at the octave from the open string. Pythagoreans concluded that most "rounded" ratios (1:2, 1:3…) give the most pleasant intervals (consonance) and built the system of music around their investigations. Currently most popular system, 12-tone temperament, resolved the matter of pitches within the octave similarly but differently by using different math.

Using tuning systems as a music game mechanic is a challenge, because it requires instruments not fixed within a specific tuning, and high level of listening skill from the players. As an area of exploration it might be most promising as an app-assisted solo game (with a tuner).

Probability, on the other hand, is the math subfield that finds maybe the most usage in games. Not only may it be used by players, but designers often wish to check how frequently some situations during the game might happen. For example when you use the deck of cards, and playtesting showed that having two specific cards together in a starting hand leads to sad downtime, you have a choice:

  • remake a portion of the game (a lot of work)
  • add a trouble-shooting, inelegant rule to avoid the bad situation, or
  • accept that on average one in N players might be reasonably critical towards the game.

But what exactly is this N? It depends on the size of the deck (D) and the amount of cards drawn at the start (H). Before calculating, you may leave the purity of mathematics for a moment and consider using a Monte Carlo method, which is a repeated simulation of the problem at hand. It's often done with a short program, but might be attempted with a spreadsheet. If you generate 1000 random hands drawn from your deck, you will arrive at the estimated probability for your situation. It's often useful, because you may easily check the chance of more complex situations than our relatively simple example.

(1)
\begin{align} N = \frac{D(D-1)}{H(H-1)} \end{align}

The result for N (provided above without explanation, sorry, on the basis of probability theory) means that if you deal 7 cards from a standard 52-card deck. One in about 63 players will have a sub-par experience in our considered game. Unfortunately, neither mathematics nor game design will tell you how to use this information in practice.

Integer sequences

Let's start with facts drawn from number theory. Integers ("whole numbers") form some of the well known sequences used in music and games. Fibonacci sequence is one of those, and it's the one where the next item is a sum of two previous ones, starting with two 1s, so it's:

1, 1, 2, 3, 4, 7, 11, 18…

It will serve as a useful example soon, let's not go into details, but the Fibonacci sequence was used so often in music, arts and memes, that it provoked one of the Composition Exercises to read:

Don't use a Fibonacci sequence

Another sequence that only grows is beloved by game designers. Triangular numbers increase by minimally larger amount on each step going: 1, 3, 6, 10, 15… These are often used as points benchmarks because their growth is slow and steady and nicely represents the increase in challenge in sync with the development of the game.

Providing for players such a challenge that uses numbers growing with an algorithm will test their memory and skill in arithmetic. But such monotone sequences, will end quickly with broad audiences, unless they are given tokens or other aids. There is seemingly more potential in using sequences that may both grow and diminish. They not only are more handy, but may behave in a quite surprising manner. Let's see how this could be achieved and a bit of formality may help now us (not much).

We will deal with integer sequences defined recursively. It means that we show how to calculate the value of the next number on the list by relating it to the previous numbers. To do this we'll use symbols $a_1, a_2, a_n$ which will mean the first, second, n-th number of the sequence respectively. If we want to know the value of $a_n$ we may need to use the value of the previous number in the sequence, $a_{n-1}$. For example, here is the rule for the Fibonacci sequence1:

(2)
\begin{equation} a_n=a_{n-1}+a_{n-2} \end{equation}

Two earlier numbers are to be summed into our current number, so after establishing that $a_1=1, a_2=1$ we'll have a Fibonacci sequence considered in its infinite entirety. For comparison the rule for triangular numbers will be:

(3)
\begin{equation} a_n=a_{n-1}+n \end{equation}

Now let's look at:

(4)
\begin{align} a_{n+1} = \left\{ \begin{array}{ll} \frac{a_{n}}{2} \ \ \text{for even } a_n \\ 3a_{n}+1 \ \ \text{for odd } a_n \end{array} \right. \end{align}

The above equation sets the value of a sequence element based on the previous elements and uses a condition, having a different calculation for odd and even numbers. It defines not only a single sequence, but multiple (depending on the value of first element). Consider the result when starting from a few first numbers.

1, 4, 2, 1, 4, 2, 1, …
2, 1, 4, 2, 1, 4, …
3, 10, 5, 16, 8, 4, 2, 1, …
4, 2, 1, 4, 2, 1, …

You may spot a few recognizable patterns. As the assignment is deterministic whenever it stumbles on a familiar number it will always have a known further sequence, reaching 1 in all of the examples above, and then looping between 4, 2, and 1 again. This is actually an open (and "cursed") area of mathematics, to prove if all starting numbers follow the algorithm towards 1. The humanity doesn't know that, although huge amounts of numbers were already checked and confirmed to always reach 1.

This is called Collatz problem and if it doesn't seem interesting for you yet, let's investigate the length of the pattern as the number of steps from the starting number to 1. As you see above, so far we had lengths of 0, 1, 7, 2 for starting numbers 1 to 4. The lengths for next starting numbers are 5, 8, 16, and 3.

1920px-Collatz5.svg.png

For all 16 steps of the sequence when starting with 7, the values jumped up to 52. And just for our viewing pleasure, let's see what happens if you start a Collatz sequence from 27, which is pictured on the graph to the right — a long run with huge leaps, right? Did you expect this (seeing it for the first time)? This demonstration may point to one potential usage of mathematics to explore, that is to help us generate results that are on one hand relatively "unpredictable" to the naked eye, but also deterministic, and guided by simple rules. In short, it helps to achieve emergent complexity. We will stay with the effect of this type for two more sections, before moving to different design opportunities.

Modular arithmetic

clock-3035731__480.jpg

In modular arithmetic you go back to 0 upon reaching your modulus (a one-upper of your max. number). The usual example is a clock, where you arrive at 4 after adding 6 to 10.

(5)
\begin{equation} 10 +_{12} 6 = 4 \end{equation}

You can use a modulus of 12 or 24 or 60 for clock time, but you can use 12 also if you would like to translate a chromatic scale to numbers, or other numbers for other set of pitch classes you choose, and also for other parameters. In practice the result in modulo arithmetic may be evaluated as a remainder of a division. This on one hand may lead to problems with mental arithmetic and it also includes the value "zero", which is not a very useful result in the context of how things are usually numbered in music (starting with 1). Workarounds might be needed, but some amusing results might be achieved with "number of notes" parameter, where zero is allowed, like in this example.

Modulo Game

The simplest variant as for timing is with a conductor established before the game. This person should be able to mark the tempo of their choice.

Conductor: You will signal the entries for 5 rounds; after that please signal informally that the game has ended. Show the downbeat (when everyone should enter) according to the conventions within your genre, if none, it might for example be done with two sharp nods, with the intention that sounds start after the second nod, following the rhythm of nodding. Agree on this signal with players and demonstrate. Before the game starts, give to the players two "seeding" numbers of your choice in 0-4 range. For example "3 and 3" or "4 and 0" — the order of non-equal numbers is important!

Players: In every round you will play X even notes in a tempo given by the conductor for this round. Pitches and timbres are up to you. Each time, the X is the same for every player and your main goal in the game is to play the notes in sync and without mistake in the length of your phrase. The calculation for your X starts with numbers given by the conductor, we'll call them A and B.

You calculate X in the following way:

  1. increase A by 2
  2. increase B by 1
  3. multiply A and B and increase by 2; C=A*B+2
  4. X is a remainder of C divided by 5.

For every next round you will use previous B as your new A, and just calculated number X as your new B.

Example 1 — A=3, B=3

round A B calculation result (X)
1. 3 3 (3+2)*(3+1)+2=5*4+2=22 2
2. 3 2 (3+2)*(2+1)+2=5*3+2=17 2
3. 2 2 (2+2)*(2+1)+2=14 4
4. 2 4 (2+2)*(4+1)+2=22 2
5. 4 2 (4+2)*(2+1)+2=20 0

With these starting numbers, no-one should make a sound in the last round.

Example 2 — A=4, B=0

round A B calculation result (X)
1. 4 0 (4+2)*(0+1)+2=6*1+2=8 3
2. 0 3 (0+2)*(3+1)+2=2*4+2=10 0
3. 3 0 (3+2)*(0+1)+2=7 2
4. 0 2 (0+2)*(2+1)+2=8 3
5. 2 3 (2+2)*(3+1)+2=18 3

With these starting numbers, no-one should make a sound in the second round.

Cellular automata

The next method of planting chaos into your games doesn't even use numbers. Cellular automata were popular in mathematics since after the war, but they are also close to the pioneers of informatics. The basic form of such an automaton is a collection of cells with at least two states, usually "on" and "off" and rules on switching the state according to the state of "neighboring" cells. The spatial relations between cells might differ between specific automatons. In every "time step" every cell sets its next state independently and rules should be deterministic — each time a cell has the same situation in its surroundings, it should it should behave in the same way.

This few features leave a lot of possibilities of configuration that we will now examine in relation to potential music-making usage. If you are interested further in the basic topic, the most famous historical example to check elsewhere will be Game of Life or, generally, Cellular automaton. The most notable examples share the feature of providing interesting behavior of the whole system, while being based on a simple rules.

The most straightforward application of CA for music could be constellation games (ones that don't limit the played material, only the line-up). Here, let's consider a player to be a cell with two states: "playing" and "not playing". There will be N players standing in the circle. Everyone has only two "neighboring cells": left and right. Of course when constructing your own system, you may place players in many ways (change the number of neighbors) and give them more states (like "sitting" etc.). But if you want to keep it a proper cellular automaton, you should aim for conformity in your setup, players at the edge of the orchestra shouldn't play by different rules than those in the middle.

There is one last consideration that is important for Cellular Automata: starting pattern. When you run your rules from the state of all cells being "off" it is impossible to arrive at any interesting result. When all cells behave exactly the same, your only options are "staying off", "turn on and stay that way", or some form "blinking together". But if you have one cell "on", you already have three types of cells: "on", "off and away", and "off in the neighborhood of on". Still, a single cell is a perfectly symmetrical pattern, and naturally, the asymmetrical ones will yield more interesting results.

Cellular Constellation

Conductor: You will signal round changes to the ensemble for about 15 rounds. After that, signal the ending of the game after, or (if you wish) do it earlier, at any time you notice that exactly the same set of people is playing as in some previous round. Before the start of the game point to some players (at least one, but not everyone) that will be playing in the first round.

Player: There will be rounds, signaled by the conductor, but not everyone is playing all the time. You play in the starting line-up if the conductor points at you just before the first round. Then, you follow this rules:

  1. If you are not playing now, play in the next round if any of your neighbor is playing now.
  2. If you are playing now, stop playing in the next round if any of your neighbor is playing now.

In other words:

If any of your neighbor is playing, change your playing state in the next round.

The length of such a game is arbitrary, not only because the timing depends on the conductor, but the number of rounds could theoretically be set at any number. Nevertheless, if we were to continue this game indefinitely, it is certain that at some point we repeat the constellation that have already played and, because the rules are constant, the game would have to proceed in the same way as before. You can experiment with many rules, player counts, and starting constellations in the Constellation Game app.

For example, if you set the single rule as in our example above. And have a "play-pause-play-play" starting constellation (a smallest non-symmetrical pattern), during the course of the game you will have 172 unique constellations and then the algorithm will loop by repeating constellations that already happened. Here is what you need to set up for this result, before clicking the "run" button:

constellation-example.jpg

Graph theory

Discreet elements ans links between them is the domain of graph theory. Like before we could use it to analyze the situation of players (and their possible reacting to each other), but more often in music games, nodes of the graph represent stages of the piece and an edge between the nodes mean that one stage may be played after another ("availability"). For maybe the best example in the wiki library, see: Apocalypse. Such structures are mathemathically graphs, but they might be casually considered as "maps", "schemas", etc.

Graph theory may first and foremost provide many pieces of useful vocabulary ("directed" graph, "planar" graph, "bipartite" graph) and some methods of achieving wanted features within a graph. The field is vast, so a few examples presented are honorable mentions, given without proof.

Konigsberg_Bridge.png
— You cannot cross all pictured bridges without repeating the trip on some of them (this was a puzzle that started the whole theory),
— You can color a map with only 4 colors,
— You can draw a graph without crossing its lines, if it doesn't contain any of the subgraphs seen below:
kuratowski-theorem-graphs.png

Basis of graph theory seems far from the usual domain of math: numbers. But these are incorporated swiftly, most naturally by counting how many edges are connected to a given node, or by "weighting" the edges, or by considering numbers of colors needed to achieve a specific coloring.

Game theory

We will finish this presentation with a relatively new, post-war theory that combines graphs and probability at it's basis, but soon arrives at the usage of matrices and some other areas of advanced mathematics. We will focus solely on "normal game forms" presented like this maybe the most famous example, Prisoner's Dilemma.

The story goes: two thieves were caught and there's evidence against them that will make each serve 1 year in prison. The investigator knows there's more to prove, so when interrogating them separately gives each thief a deal: "Confess, and if your accomplice denies guilt, you may go free. But denying guilt when you are denounced will give you 3 years in prison." The vanilla game theory says, that given this situation, the result should be: both confess (which ends in 2 years for both). We are going to explain why, but first see how the notation for this game might look:

(-1, -1) (-3, 0)
(0, -3) (-2, -2)

https://www.youtube.com/embed/9uDUv1TpGxI

Also

Oumupo

Examples of explicit math presence
like in Scratch Orchestra's CCQR133

Links

http://oeis.org/

http://musicalgorithms.ewu.edu/resources.html


Toggle sections editing

Mark for clarification

Mark for decoration

Unless stated otherwise Content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License. See licensing details