# Questions on get a chord's name

I have an algorithm to determine a chord's name. A chord is a set of notes, like `A B C`. I'd like to improve the algorithm and have several questions.

First of all, I'm aware of this thread but that's not what I want. Also please let's omit information stated in this answer. So I just need answers on the following straightforward questions:

1. A chord and all of its inversions can be resolved to the same name, yes? So `C E G`, `C G E`, `E C G`, `E G C`, `G C E`, `G E C` are all the `Cmaj` chord, right?
2. If a notes collection has the same notes, can we throw duplicates away? So `A B C` and `A B B C` and `A A B C C` are all just `A B C`?
3. Does that work for adjacent notes only? Are `A B C A` and `A B C` the same chords or different ones?
4. Am I right that all inversions of a chord is a collection of all permutations of the chord's notes (which gives us `n!` possible permutations)? Or we can reduce somehow the number of possible variants?

EDIT:

Well, here answers on your questions (that have no relation to my post so we're all just wasting our time, but... why not?):

1. Yes, the same notes (well, pitches) can designate multiple chords names. In this case I just return all detected names. My algorithm returns a collection of names, not a single name.
2. I wrote "My current algorithm works fine for users needs" and the question has appeared: "could you add a description of these assumed needs in the question?". Well, those needs are not "assumed", they are real ones that have been satisfied several years ago. The problem now is how I can improve performance of the algorithm (the task has been raised from this user's message). That's why I've asked the questions above.

So I don't ask how to build the algorithm, what music theory details are exist around the chord theory and so on. I have specific questions and want answers on them only.

Anyway I got the information I needed. Thank you!

• I feel like all of your questions are things you should know before starting on such an app. We could answer all these questions but you’ll probably have more questions and gaps in your understanding of music theory that will make the app hard to finish. Commented Oct 25, 2023 at 15:17
• @ToddWilcox - so very true! Lack of (basic) information/knowledge/understanding will make app-making an unsuccessful task.
– Tim
Commented Oct 25, 2023 at 15:26
• Meh - my brain was in a bucket in a corner:\ I used to work with algorithms like this - which were so secret even 25 years later I can't tell you what they are. [btw, as you could see from my original, now deleted, comment - I wasn't the one to devise them;)) Commented Oct 25, 2023 at 15:32
• @Tetsujin - I'll leave the comment for those coming behind to ponder upon... for a little while!
– Tim
Commented Oct 25, 2023 at 16:06
• see this answer, Python implementation included music.stackexchange.com/questions/125891/… I suppose you assume a style of music where people consider tertian harmony as a norm. There are others. You should explicate the intended target audience and usage purpose of these "chord names". For whom does your algorithm produce output, and for what purpose? Commented Oct 25, 2023 at 16:59

I have an algorithm to determine a chord's name. A chord is a set of notes, like A B C.

This is a problem right off the bat. Sometimes a set of notes could be explained in more than one way. It's as if you said, "I have an algorithm to determine the meaning of a word. A word is a set of letters, like B A R K." But "bark" can mean "the sound a dog makes," or "the outside layer of a tree," or even "an archaic word for a boat." We choose between these meanings by analyzing context. So sometimes "E G C" is an inverted C chord, and sometimes it's actually an E minor chord that has had the top note suspended from an earlier C and is about to resolve to a B. To print a chord in staff notation is to make a simple, specific, objective statement: These pitches sound at the same time. To label it with a roman numeral or letter name is an act of analysis. Sometimes the analysis is straightforward and obvious, but it still happens.

A chord and all of its inversions can be resolved to the same name, yes? So `C E G`, `C G E`, `E C G`, `E G C`, `G C E`, `G E C` are all the Cmaj chord, right?

IF we're already sure that this IS a C chord, then you're right. If we have decided that we're looking at a C chord, then it doesn't matter how the pitches are distributed throughout octaves or voices, or which note is on the bottom. These are both C major chords:

However, there's no guarantee that those notes are always a C chord; see my warning in the first paragraph. There are plenty of situations where the most obvious chord name for a certain stack of notes is not actually the right way to explain the situation. For instance, in this bit, the reasonable analysis is that there are only two chords, an E minor and an F:

So here, in the last 8th note of the first measure, we have `E G C`, but it is not a C chord, just an anticipation. It would still be true if it were written like this:

Similarly, chord naming relies more on context once we start adding notes, jazz-style. For instance, is `C E G A` a C chord with an added 6th? Or is it in fact a first inversion A minor 7th chord? Only context can tell.

If a notes collection has the same notes, can we throw duplicates away?

Yes. These are both C chords (assuming context tells us they're C chords):

Does that work for adjacent notes only? Are A B C A and A B C the same chords or different ones?

It seems as if all these questions are coming from the same misunderstanding. A chord name dictates a set of pitch classes, not specific pitches. Those pitch classes may be distributed in any order across any octaves, and all may be doubled (or omitted!). So yes, those are the same chord (assuming the same context).

Am I right that all inversions of a chord is a collection of all permutations of the chord's notes (which gives us n! possible permutations)? Or we can reduce somehow the number of possible variants?

The important word here is "inversion." We don't have to worry about all the permutations of which notes go in which order, just what's in the bass. There are only as many inversions as there are pitch classes in the chord, because "inversion" is just a fancy word for "which note is on the bottom." There can be no more and no fewer inversions than there are unique pitches classes in the chord. "C E G" has three possible notes to be on the bottom. Or, in other words, these are both a first-inversion C chords:

• Thanks you a lot for such a detailed description! But this statement is unclear for me: "Well, the number of inversions is equal to the number of pitch classes in the chord". The number of inversions for `CEG` is `3` or `6`? Yes, there are three possible notes in the bottom, but for each such variant there are two options how other two notes can be placed, right? Commented Oct 25, 2023 at 15:34
• Only the bottom note determines the inversion. "E G C" and "E C G" are both first-inversion C chords. To reverse-engineer that statement: If I say "Play a 1st-inversion C chord," all I've specified is which note is in the bass. You have many many options of how to voice the rest of it. Commented Oct 25, 2023 at 15:38
• @Maxim Specialized term here is “voicing,” meaning “how you arrange the members of the chord.“ So “three inversions, each with an infinite number of voicings.“ Commented Oct 25, 2023 at 17:03
• @phoog Yeah, I was speaking without assuming a finite set of voices, since Maxim appears to be dealing in the abstract. And Maxim, I've avoided mentioning it until now, but there could be even more "variants" because you could even have some chord members missing and still analyze the chord; e.g. you could have only "C E" and be certain from context that it's a C chord. In fact, you could argue that the trumpet's first C note in Also Sprach Zarathustra is already a "C chord," with only one pitch (largely because of the big picture of where things are headed). Commented Oct 25, 2023 at 17:31
• It looks to me that the OP doesn't really know what his end-users actually do with the chord names, and this question is trying to get an answer to that, without asking from the actual users. Commented Oct 26, 2023 at 9:44
1. Since the second quarter of the 18th century, yes, but with the advent of jazz theory, perhaps around the second quarter of the 20th century, not necessarily. For example, on a lead sheet you might find `Am7/C` (A minor seventh with C in the bass) and you might find `C6` (C major with an added sixth). Both chords contain the same set of pitches, but some might argue that they are different in some theoretical sense.

2. Yes. Duplicate pitches do not change the identity of a chord.

3. Not at all; `C-E-G-C` is C major and so are `C-E-G-G` and `C-G-C-E`.

4. Inversion is determined only by the bass note. `E-G-C` is a C major chord in first inversion, and so is `E-C-G`.

As others have noted, passing tones and other non-chord tones can complicate an algorithm of this sort. Or, more likely, they certainly will. Sometimes lead sheets pay too much attention to non-chord tones, which makes them confusing and difficult to read.

For example, consider the beginning of "Joy to the World," which consists of a descending major scale, the first four notes of which are over a tonic chord. Mostly, assuming the key is C, you just have a C chord during the first measure, but a naive algorithm will probably come up with `C - Cmaj7 - C6 - C` or, worse, `C - Cmaj7 - Am7/C - C`

• @Tim I don't understand. The two examples I gave are the same two you're suggesting, aren't they? (Albeit in the opposite order.) Commented Oct 25, 2023 at 18:26
• Sorry, not sure what I meant there! Deleted. What's the difference between C6 and Cadd6?
– Tim
Commented Oct 26, 2023 at 7:46
• @Tim one is less ambiguous? My exposure to lead sheet usage is in the receding past, and this particular chord is tainted by figured bass practice where 6 means a sixth with no fifth. I've taken out the "add." Commented Oct 26, 2023 at 13:07

I have looked at this a few times but I didn't get very far. There are lots of references on the web. Google Scholar is a good place to search.

One problem is that there are simultaneously sounding notes that are not really chords. Take a simple country walking bass, that I will abbreviate with slash notation: C, C/B, C/A, G. The second and third chords are still C chords; the pattern C-B-A-G is just a scale-wise descent in the bass and should be analyzed as a quasi-independent component.

It might help (though I haven't looked) to preprocess music to extract the melody, bass line, and bunch of strummed chords. This isn't that simple to do algorithmically as the melody may have a varying number of voices.

• My algorithm is a simple one that just tackles with notes (pitches) offsets from the root. Slash chords are also supported. Thanks for the answer! Commented Oct 26, 2023 at 8:48
• the lowest note is note always the root. i wonder how you are determining what the root is.
– user94972
Commented Oct 27, 2023 at 6:20

1. yes, but then your algo will miss some subtleties that are important in Music. And therefore your analysis will be of limited musical value.

2. yes, duplicate notes do not change chord quality or name.
I wonder though, what is this "notes collection" you speak of? If the notes are not sounding at the same time, then you are not dealing with chords.

3. yes, again, duplicates do not change chord quality.

4. sounds like you are complicating things. A chord with 3 notes, made up of its root, third, and fifth, (a triad), CEG, has a root position, 1st inversion and a second inversion. 3 combinations. A chord with 4 notes (a seventh chord) CEGB likewise has root position plus 3 inversions. Again, I don't know what your "notes collection" looks like or where you are getting them from, but simply looking at any 4 different notes does not imply a seventh chord, nor would it imply it has inversions. Inversions as I understand them are limited to having either the 3rd, 5th, and or 7th (of those said triads or seventh chords) in the bass. Distance between the notes is important though. ABC is not a chord, it's a cluster. ACB, spanning the interval of a 9th implies a chord, but we could not name it without context of what comes before and after.

I should add that your opening statement should actually be a question. "A chord is a set of notes". By your definition, it is clear that some understanding is missing. To start on the right track, you should really be looking for a proper definition first, which some of the other answers here should have touched upon. A chord is NOT a set of notes. That's just too imprecise a sentence. A set is a collection, and a collection can be something like 'the first note from each measure in a piece'. That's a nice set of notes, but it's not a chord. If your goal is to analyze things that way, then that's a different story, and maybe your particular use case makes sense in a way specifically outside of normal musical analysis.

Maybe if you explained the reason behind what your larger goal is, you could get some wider direction that would help you with aspects you are not even going to know that you need to ask about. It sounds a little bit like what you are not telling us is that you want to analyze a set of notes (or some sequence other than a vertically aligned chord on a staff), such as a melodic phrase and figure out what chord is implied. Correct me if I'm wrong.