Brute-force Music Composition

byHughRistik10y22nd May 200932 comments


Follow-up to: Heuristic is not a bad word

When I was in high school, I wanted to compose music. I wanted to write the music that I wanted to hear. There was only one problem: I have good aural imagination, but I don't have world-class aural imagination. I can look at sheet music and hear it in my head. I can hear chords. I can hear two-part harmony. Yet my aural imagination wasn't developed enough to generate novel music, except when I was in certain moods or about to fall asleep. And most of what I could hear in my head I found impossible to transcribe.

Nevertheless, I wanted to write cool music. I know what I like when I hear it. I had the ability to critique music; the only problem was creating it. So I developed my own technique for writing music: I composed using brute force. Before I describe how this worked, and how successful it was, I would like to talk more generally about brute force as a method for problem-solving.

Brute force: the null heuristic

In the language of heuristic, the art and science of discovery, brute-force search is the crudest method of heuristic there is, which is why I think it's a good place to start discussing heuristic methods. According to Wikipedia, "brute-force search or exhaustive search, also known as generate and test, is a trivial but very general problem-solving technique that consists of systematically enumerating all possible candidates for the solution and checking whether each candidate satisfies the problem's statement." Throw everything at the wall until something sticks.

Given a particular problem, imagine all possible solutions as points in space. In the terms of heuristic, this is the search space of the problem. Heuristic is about navigating through search space until you find the actual solution. Brute-force search proceeds by analyzing each point in search space, one at a time. On the Heuristic Wiki, Ben Kovitz refers to brute force as the "null heuristic":

Nearly all thought in heuristic pertains to how to find a solution, an optimum, or a pretty good combination without searching every point in the design space. Thus brute-force search is the null heuristic. It's what you do when you don't know of any heuristic that could simplify the problem. That said, though, brute force always has the last word. However you whittle down your search space, you still must examine one possibility at a time, even in your much-reduced search space.

Kovitz observes that even though many problems cannot be solved by brute force (such as a full chess game), sometimes you can solve part of a problem with brute-force (such as a chess endgame). This process—of using brute force once you have narrowed your search space as much as possible—is how I composed.

Brute force musical composition

When composing, I didn't use complete brute force. Doing so would have required exploring a massive search space of all possible combinations of sound. My search space was whittled down by certain factors. I was writing tonal music in the major or minor key in a neo-Romantic style on the piano. Furthermore, I composed only 2-4 measures at a time, one or two chords at a time, and I recapitulated themes and motifs.

My method was to plink around on the piano for a few measures, and then decide if I like what I heard . If I didn't, then I would back up and plink some more until I found something I did like. I would play the entire phrase or section now including the new two bars, to hear if I still liked them in context, and to prepare for writing the next two bars. The other name for brute-force search, "generate and test," sounds very appropriate: I generated a segment by pianistic experimentation (rather than from my aural imagination), then I tested it in context.

Messing around with the piano keys wasn't completely random. My fingers were proceeding with logical chord patterns, generally trying all consonant chords or chromatically nearby dissonant chords that I felt were consistent with the style I was going for. I realized that when I didn't have a basis to decide the next chord in my harmony (such as the need for a cadence, or borrowing a chord progression from another composer), the space of subsequent pianistic neo-Romantic-sounding candidate chords was low enough that I could brute-force my way through it: perhaps 4-10 points in chordal search space depending on what had already occurred in the phrase. I didn't even need to try them all; I just needed to try a bunch until I found something that I liked.


Brute force composition was slow and tedious. But it worked surprisingly well for harmony. It just wasn't very good for melody and rhythm, which involved a much larger search space.

For a melody, the number of stylistically plausible subsequent notes within one octave of the current note might be 4 to 16. The number of stylistically plausible durations for holding a note (e.g. whole note, half note, quarter note, eighth note, sixteenth note, and intermediate durations such as dotted quarter note, etc...) might be be 2 to 8 depending on the phrase. This leads to a search space of 8-128 possibilities per note. Yet while I can compose a harmony one chord at a time, it doesn't work so well to compose a melody one note at a time. I have to work with combinations of notes, which is difficult to do linearly on a piano, and which enlarges the search space even more. Based on the previous assumptions, 4-16 plausible tones X 2-8 plausible durations X 4 notes = 32-512. And while I usually only have a few chords per 2 bars, I will usually have more than 4 notes. The minimum search space for melodies (representing relatively less creative composition) was an order of magnitude or two too big to brute-force through if I wanted to finish my opus before my death.

Since I couldn't hear complete melodies in my head, I had to lower my standards for what constituted a satisfactory melodic solution to cut down the search space until it was brute-forcible. Most of the time,  I used strings of notes with the same duration (e.g. eights, triplets, sixteenths) in scales and arpeggios, more like Baroque music than like Romantic music. I used simple rhythms, themes, and motifs, and repeated them. Unfortunately, I had to cut out parts of the search space where some of the best solutions were lying, because I sacrificed melodies with notes of more varied duration that didn't proceed by scales or arpeggios. The result of my brute-force composing was harmonically interesting, but melodically and rhythmically lacking.

In case you are wondering what this music sounded like, I've uploaded a composition to YouTube from a performance during sophomore or junior year of high school. Turn up your volume a little, and keep in mind that I was a better composer than pianist, because I spent most of my time on the piano composing two bars at a time rather than actually practicing.

Does it sound how you expected?


For my initial problem, "how do I compose some music that sounds cool to me given that I don't hear new music in my head?" I arrived at a successful solution: I cut down the problem to a size where I could brute-force it. Brute force worked as long as I could keep the possibilities I had to plink through down to a manageable number. Yet after creating several compositions, I eventually tired of this methodology because brute-forcing two measures at a time was very tedious. Secondly, my standards rose, and I wanted to be able to do melody, not just harmony. As my desired solution became more complex, the search space I had to seek it in grew larger, until it was eventually impossible to traverse with brute force. Thirdly, I got better at other pursuits where I was able to achieve better results with my time. In the end, I abandoned composition, but some days I still plink around on the piano.

What is a problem that you have attempted to solve using brute force, and how well did it work? What kinds of problems seem amenable to brute force, and what kinds don't?