My guitar homework
Q derives from the mathematical notation Ken Iverson developed at Harvard. Years before, when Ken was a young man in Alberta, a farmer he worked for asked him if he knew how to use a certain tool. Ken didn’t. “Well,” said the farmer, “you won’t learn it younger.”
Amending past folly, I hired someone to teach me guitar at last. Part of my homework is to map notes to the frets on the guitar neck.
The six strings of the guitar are E, A, D, G, B, E.
The ‘progression’ of notes along the E string goes E, F, F#, G, G#, A, A#, B, C, C#, D, D#. The progression is a cycle, so the corresponding notes on the A string are A, A#, B, … , G#.
My guitar homework is to map the notes on the guitar fretboard, from E, A, D, G, B, E at the top (‘open tuning’) to D#, G#, … on the thirteenth fret – where the cycle repeats.
Of course, I wanted to do my homework in q.
Projection
My teacher made something of C# also being D♭, so
q)progress: `$"`"vs"C`C#|Db`D`D#|Eb`E`F`F#|Gb`G`G#|Ab`A`A#|Bb`B"
q)notes0:{flip(x?`$'y)rotate\:x}[progress;]
q)notes0 "EADGBE"
E A D G B E
F A#|Bb D#|Eb G#|Ab C F
F#|Gb B E A C#|Db F#|Gb
G C F A#|Bb D G
G#|Ab C#|Db F#|Gb B D#|Eb G#|Ab
A D G C E A
A#|Bb D#|Eb G#|Ab C#|Db F A#|Bb
B E A D F#|Gb B
C F A#|Bb D#|Eb G C
C#|Db F#|Gb B E G#|Ab C#|Db
D G C F A D
D#|Eb G#|Ab C#|Db F#|Gb A#|Bb D#|Eb
Composition
The progression here is a terse notation.1 C is followed by C#, D by D#, E by F.
q)progression:"C#D#EF#G#A#B"
notes
function is an elegant sequence of unaries.
q)notes: flip progression mod[;13] til[12]+/: progression?
q)notes "EADGBE"
"EADGBE"
"F###CF"
"#BEA##"
"GCF#DG"
"###B##"
"ADGCEA"
"####F#"
"BEAD#B"
"CF##GC"
"##BE##"
"DGCFAD"
"######"
"EADGBE"
Also works for alternative tunings:
notes”DADGBE” // Drop D
notes”DADGAD” // DADGAD
Exercises
-
Shorten
notes0
by one character.Answer
The trailing semicolon marks the projection’s missing right argument. It could be removed, though it is good style to leave it.
note0:{flip(x?`$'y)rotate\:x}[progress]
-
The result of
notes
is brutally terse. Make it as easy to read asnotes0
.Answer
The composition works just as well on
progress
as onprogression
, provided its argument is first cast to symbols.progression: progress notes: flip progression mod[;12] til[13]+/: progression? `$'
-
Thanks to Cillian Reilly for the composition. ↩