Counting Chords and List Manipulation

Steven Goldman
Sgoldman101@qc.cuny.edu

Introduction:
   This Mathematica file investigates different methods of list manipulation.  The question that It attempts to answer is how many distinct chords can you play on a six stringed guitar (this question deals with a branch of discrete math known as combinatorics).  A chord will be defined as any combination of one or more notes played simultaneously.   A distinct chord is defined as a chord in which a note is allowed to appear at most once.  For example, the chord {A, A, B}  is not distinct, while {A,B,C} is.  
      All together there are twelve possible notes you can play.  The twelve notes are known as {A, A#, B, C, C#, D, D#, E, F, F#, G, G#}.  For the purpose of this exercise, we will denote them as {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}, respectively.  It is also important to note that you can only play one note at a time on any given string.  The six strings, {1, 2, 3, 4, 5, 6}, will be denoted by {a, b, c, d, e, f}.

First, we need to define the notes on each string that we are going to deal with.   We will start our investigation with the first four frets.  One reason for this is that all twelve notes appear in the first four frets. This is given below.  We can later alter this to suit our needs and get different results.
[Note: It doesn't necessarily matter what order we put the notes in on a string, as long as we include all the notes on that string].

a=Range[9,12];
b=Range[4,7];
c={12,3,2,1};
d=Range[7,10];
e=Range[2,5];
f=Range[9,12];
MatrixForm[{a,b,c,d,e,f}]

Next, we need a function to calculate all possible distinct chords that could be played given twelve notes, since all twelve notes appear in these strings.  In the following function,  x is the number of notes in the chord.  Since there are six strings (and we can only pick one note per string), we know that   1 ≤ x ≤ 6.

PDC[x_?(1≤#≤6&)]:=Subsets[Range[12],{x}]

Next, we will have to define a function that creates all chords possible (including the non-distinct ones) given the frets we are using.  We can do this using the Tuples function.  We want the chords to be in numerical order from least to greatest in order to be easy to use and compare to the list of possible distinct chords.  In order to do this, we use the Sort function.  Again, x is the number of notes in the chord.  Also, in order to remove nested lists and copies of chords, we use Flatten and Union.  [Note:  when creating the lists using PDC and NDC, you might want to suppress the lists from being written out, since they can be quite long at times.]

NDC[x_]:=Union[
Map[Sort[#,Less]&,
Flatten[Map[Tuples[#]&,Subsets[{a,b,c,d,e,f},{x}]],1]]]

The intersection of these two lists, PDC and NDC, will give us the list of all distinct chords that can actually be played within the frets we've chosen.  By counting this intersection, we count the distinct chords.

DC[x_,x_]:=Length[Intersection[PDC[x],NDC[x]]]

Now, we can create a table of these values, where the first entry, x, is the number of notes in the chord and the second is the number of distinct chords with x amount of notes.

T1=Table[{x,DC[x,x]},{x,1,6}]
T2=Table[DC[x,x],{x,1,6,1}]

We can use Manipulate to help us view all possibilities for x.

Manipulate[DC[x,x],{{x,1,"Number of Notes"},1,6,1},{{x,1,"Number of Notes"},Range[6]}]

We can also graph the six points in order to see how they change as the number of notes allowed in a chord changes.

Show[ListLinePlot[T2],
ListPlot[T2]]

In order to get the total number of all distinct chords, we can use the Sum function.

Sum[DC[x,x],{x,1,6}]

Now that we have defined a way to count the distinct chords over a given range, we can change the frets we initially used to investigate further.  We can also change the number of frets that we used or skip over certain frets.  For example, we could use the first three frets (here, too, all twelve notes appear).

a1=Range[9,11];
b1=Range[4,6];
c1={12,1,2};
d1=Range[7,9];
e1=Range[2,4];
f1=Range[9,11];
MatrixForm[{a1,b1,c1,d1,e1,f1}]

(* Adjusting the functions yields: *)
NDC1[x_]:=Union[Map[Sort[#,Less]&,Flatten[Map[Tuples[#]&,Subsets[{a1,b1,c1,d1,e1,f1},{x}]],1]]]
DC1[x_,x_]:=Length[Intersection[PDC[x],NDC1[x]]]
TT1=Table[{x,DC1[x,x]},{x,1,6}]
Sum[DC1[x,x],{x,1,6}]