“Supposing, for instance, that the fundamental relations of pitched sounds in the science of harmony and of musical composition were susceptible of such expression and adaptations, the engine might compose elaborate and scientific pieces of music of any degree of complexity or extent.” Ada Lovelace, 1843

The first stage in this interactive demonstration is to **generate**
a sequence of numbers using an algorithm that might have been run on
the Analytical Engine.
In stage 2 you **reduce** these numbers to a smaller range
of numbers, using 'clock arithmetic'. Then
in stage 3, you can visualize and **play** the number sequence
interactively, and explore the mapping of the numbers to musical notes.
If this is your first visit, try the green buttons.
NB This program has been developed and tested in Chrome and Firefox
browsers.

Fibonacci

Each number is the sum of the previous two. If we start with 0, 1 we
get the sequence commonly known as the
Fibonacci numbers
0, 1, 1, 2, 3, 5, 8, 13, ... (could also start 1, 1). If we start with 2, 1
we get the
Lucas numbers
2, 1, 3, 4, 7, 11, 18, ... (could also start 1, 3).
The sequences are described mathematically by the relation
F_{k,n+1} = kF_{k,n} + F_{k,n-1} where k = 1.

*n0:*
*n1:*
*k:*

Powers

The sequence of powers of 2 is 2^{0}, 2^{1},
2^{2}, 2^{3}, ... i.e. 1, 2, 4, 8, 16, 32 etc. Here
you can generate the sequence of powers of 2 or any other number,
known as the *base*.

* base:*

Other Algorithms

How might Ada Lovelace have calculated these?

Tribonacci

Like Fibonacci, but each number is the sum of the previous three. Another of many variations on Fibonacci.

*n0:*
*n1:*
*n2:*

Triangular and Factorials

Triangular numbers are the sequence of sums 1, 1 + 2, 1 + 2 + 3, 1 + 2 + 3 + 4, ....

Factorial numbers are the sequence of products 1, 1 x 2, 1 x 2 x 3, 1 x 2 x 3 x 4, ...

Sinusoidal

This is an approximation to a sine wave, the sequence described by the
equation *a + a.sin(rθ)*

*a:*
*r:*

Bernoulli

Bernouill numbers are generated here using the algorithm described by Ada Lovelace. The numbers are a sequence of fractions, so we provide a sequence of numerators or a sequence of denominators.

Modulo

We reduce each of the numbers in the sequence using
modular arithmetic
(clock arithmetic). We divide each number by *mod* and keep the
remainder, so all the numbers will be between 0 and *mod - 1*.

*mod:*

Logarithms

Logarithms are included here to help visualize the growth of the sequences.
Log_{10} of 10 is 1, 100 is 2, 1000 is 3, etc
(logs of zero or negative numbers will appear as 0).

length | |

mod | |

period |

*Display* to show a 'number roll' visualization of the
sequence, with time from left to right and numbers going up.
The mapping of numbers to notes can be modified as you wish using the
buttons below the number roll.
Press the *Play* button to play the sequence as eighth notes (quavers),
or the *4* or *2* buttons to play quarter or half notes, with
piano or
xylophone sounds.
The mouse selects a subset of notes to be played, and holding the shift key
down modifies the current selection.
*Sust* causes notes to be sustained so that you can hear them alongside
each other. You can also change the tempo (beats per minute).
The *Life* button produces the next generation of the number
roll according to the rules of the
Game of Life (devised 1970), and the
*Cat* button transforms a square iteratively (inspired by
Arnold's Cat, 1960s) so that it returns to normal after a
Pisano period.
Pressing *Display* resets the display at any time.

Choose which pitch and octave the number 0 corresponds to (e.g. C1), then click on a scale or generate one from intervals (e.g. 2 2 1 2 2 2 1, or WWHWWWH, or TTSTTTS). Pressing any buttons will regenerate the mapping table, which comes into effect next time you play.

*Generate PDF*
and *Generate MIDI* buttons, which open a new browser window.
Metadata specified here (e.g. a title) is included in the exported files, and
you can also generate a provenance graph which describes how your output
was generated.

This tool was developed to generate Fibonacci numbers and reduce them with
clock arithmetic, generating a periodic sequence which is then
mapped to notes, and the music explored by selecting fragments to play
(Lagrange noted periodic functions in Fibonacci numbers in 1774, and
the period is known as the *Pisano period*).
Additional algorithms have been added to stimulate discussion of
mathematical calculations on the Analytical Engine, contemplating what
Ada Lovelace and Charles Babbage might have done if the engine had been
built. *Powers* is included as it is the example in the
*Ada sketches* operatic work composed by Emily Howard.
The other examples are:

- Pi
- Pi was calculated by hand to 100 decimal places in 1706 using Machin's algorithm. The same algorithm is used here—note that algorithms existed before computers. Pi is believed to be a 'normal number' which means any possible musical sequence appears somewhere in its digits.
- Golden Ratio
- This is the number that the ratio of successive Fibonacci numbers converges to (1.618...) and it's calculated using a square root function. Although the square root algorithm we use is known today as Newton's method, it goes back to 1st century Greece or Babylonian times (incidentally the Babylonians worked in sexagesimal i.e. base 60).
- Prime numbers
- Calculated here using the
*Sieve of Eratosthenes*, but how might this have been coded for the Analytical Engine? The size of the sieve is estimated using a 1798 result by Legendre, and in those days 1 was considered to be a prime. - Random
- How could random numbers have been generated on the Analytical Engine? Musical dice games (Musikalisches Würfelspiel) were popular in the 1700s. Today we analyse and generate music using probabilities of note and chord transitions, using a mathematical approach due to Markov born in 1856.
- Factorials
- We see triangle numbers created by adding, and Factorials by multiplying, hence that the factorial sequence goes up much more rapidly. The notation for factorial, e.g. 20!, was introduced in 1808. 20! can be stored in a 64 bit integer before we run out of bits, but the analytical engine could go up to 41! with its support for 50 decimal digits.
- Sine
- The sin trig function is used here to generate an integer sequence approximating a sinusoidal wave. The Analytical Engine could have been used for creating trignometric tables. This also illustrates another way of generating sounds, by generating a waveform (but how might that have been converted to sound?)
- Bernoulli
- Ada Lovelace is famed for the algorithm to generate Bernoulli numbers. Here we generate the numerator and denominator sequences separately. Only short sequences are generated because it is quite computationally intensive, using a rational arithmetic library. How long would the algorithm have taken to run on the Analytical Engine?

**
Please email Numbers into Notes with
any questions, bug reports, and suggestions for new features.
This application is currently only supported on Chrome and Firefox.
**

Written by David De Roure, December 2015, for the *Ada Lovelace
Symposium* and as an interactive demonstration to encourage discussion
about music, mathematics, and programming at the time of Ada Lovelace.
Thanks to Emily Howard and Lasse Rempe-Gillen for their inspiration
through *Ada sketches*, to Pip Willcox for jointly organising
the *Numbers into Notes* project, and to all our colleagues for
feedback and ideas. This research is supported by the
Transforming Musicology
project funded by the Arts and Humanities Research Council, and the
FAST
project funded by the Engineering and Physical Sciences Research Council.

When this application is run online, the logs maintained by the server include the IP address of the client, the referring web page, and the user agent (browser). This information is used for debugging and developing the software, and may be summarised in aggregate form to report usage in publicly available documents. We do not use cookies. When export format conversion functionality is enabled, exported Lilypond and MIDI files are stored on the server on a temporary basis and are available to anyone with the appropriate URLs: they are stored for access, to assist with debugging and demonstrating the operation of the program, and in order to analyse and report on usage.