Computer music at New Mexico Tech
Around this time last year, my friend Eric Sewell said he was going to teach a computer music class at New Mexico Tech. I had been thinking about taking a class, probably a math class like linear algebra, but on a lark I decided this would probably be interesting. I’ve always loved music, but never really learned an instrument, and I thought, maybe if I involve the computer I can get further than if it’s about dexterity and years of tedious practice.
I started the class with no real expectations. We’d be using Csound. The lectures were a mixture of technical stuff about using Csound, basic concepts of synthesis, and listening to works by pioneering composers and musicians in the realm of computer music and synthesis. I didn’t enjoy many of those works except on an intellectual level, but they were all fascinating, and a few I have listened to a couple times since, like The Bull by Morton Subotnik.
I had a “haha embarassing” moment when I realized I could probably replicate the sound from the opening of Regular Show with Csound, and talked to my friend the professor about it. With a hardware synth, this is just opening and closing the filter on a simple saw wave.
Hardware synthesis - Uno Synth
I think I was in class for 3-5 weeks before I realized we were actually talking about synthesizers. I started to think it would be much easier to make music if I had a hardware synthesizer and thus could turn knobs rather than having to create envelopes in Csound, run Csound, listen to the output, and then go back and try to guess what settings had been interesting. So mid-February I bought an Uno synth. If you want to know how it sounds, here’s Jade Wii playing it.
I choose this synth mainly because it had a nice analog sound, was inexpensive, did not have a real keyboard, and wasn’t a Korg. At the time, I was doing a lot of synth hardware comparisons and very nearly got a Korg Monologue, but decided the sound was too clean and cold. I was also intimidated by real keyboards because I had no formal music training, wasn’t planning on getting any formal music training and just wanted to make interesting sound. My friend Drew Medlin came over with his synths and I found myself quite unable to do anything interesting with him, partly because I just had no familiarity with the keyboard.
I found that I did greatly prefer interacting with the synth via the knobs, so much so that I found it very hard to be excited about using Csound again. When Covid hit, I had a nice excuse to drop the class, which was going to culminate in making some kind of 2-minute composition I was also terrified of. I also felt like Csound was so wide-open in terms of what it would let you do that it was impossible to figure out how to do rhythm effectively, and so there was no way to structure a song. I had to basically draw out on paper what I thought I wanted, program it in, compile/run, then tweak it and try again. It was reminding me too much of programming. I decided I wanted to escape from the computer altogether, and get deeper into an instrument.
Do I recommend the Uno Synth?
I realize some people reading this may be looking for reinforcement on the idea that maybe they should get the Uno synth. It is, after all, the one of the most affordable analog synthesizers out there.
I do not recommend the Uno synth. I say that without hate. There are aspects of the design of the Uno that make it hard to enjoy. One is that you want to power it with batteries, because if you use USB you get noise. But there are parameters in the patches that can only be reached by the companion applications, which must connect to it over USB. Ironically, the noise setting does not appear to “stick” unless you reach it from the companion application.
The USB connection, on the other hand, draws a large amount of power—this is an analog synthesizer, after all. Well, I found that the power draw was enough to damage my cheap Aukey USB-C port dongle thing. Maybe you could just power it over batteries? Yes, except the thing has a runtime of 1-2 hours on 4 AA batteries, and they strongly recommend against rechargable batteries. That makes sense, the power draw on this thing is enormous, and it starts acting funny in all sorts of surprising ways when the batteries start going low.
You can get around the USB noise problem by buying a USB isolator (?) for $40. Thanks.
My kids dropped it once, and that was enough to dislodge something in the battery case, so that now it can no longer really take AA batteries. I have worked around that by stuffing a wad of aluminum foil in there, but guess what, I now have noise issues in AA battery power mode.
I think it has a good sound, on the filthy side which I like, but I found these little frustrations depleting, and even getting around these, I started to see that it wasn’t really for me, although I made other mistakes first.
I think you were me, just starting out, and your budget is $200, you should probably allocate your funds elsewhere for your synthesis journey.
Elektron Model:Cycles
In April, I became aware of the Elektron Model:Cycles. I was very intrigued by FM synthesis from the class, and really felt like the complete absense of anything like a rhythm primitive in Csound was driving me away. This device appeared and was built around both FM synthesis and a very powerful rhythm concept, capable of doing polymeter or polyrhythms easily. Online, people talk about “the Elektron workflow” a lot and it was intriguing to me. Plus, it would keep me away from the computer. And then I saw this video, which basically sold me on the sound of it.
I made quite a few songs (or at least songish performances) with the Cycles, which you can find on Soundcloud if you really want to suffer. I didn’t realize it at the time, but it has a feature that novices greatly appreciate: it appears as a USB audio device when you plug it into a computer, and no hardware audio interface is needed for you to record it! This is a significant benefit for sharing what you do without having to throw out another $100–200.
I dove into the Cycles pretty hard for a month or so. I became a little disillusioned that I couldn’t make anything as nice as Jeremy from Red Means Recording, as if a guy playing music for a month on one device really had a chance to catch up to a professional with decades of experience. I didn’t realize it until months later, but a blank pattern on the cycles has one of each “machine,” which kind of implicitly guided me towards trying to make songs with one kick, one snare, one cymbal, one tom, one chord progression, and one melody line. In fact, I ran into the same obstacle as with the Uno pretty quickly, that it does not really have a keyboard and I didn’t really know how to play a keyboard even if it had one, so the beautiful melodic lines that Jeremy and others are able to make on these devices were just out of reach for me unless I bumbled into one on accident, which mostly I did not. I expected that I could make a decent drum line (there was a Pocket Operator PO-12 “Rhythm” purchase that I forgot to mention somewhere between the January and May), and I could, so most of the frustration came from the melody/chord side of the house. And the keyboard problem was getting untenable.
Do I recommend the Model:Cycles?
I have mixed feelings about the Model:Cycles today. I do use it from time to time, but although the presets show you a really wide variety of sounds, I mostly feel like the stuff I am making is all sounding about the same. I find FM synthesis fascinating and thought the kiddie pool version of it in the Cycles would be both powerful and easy to use. That thesis is wrong, but whether it’s because I’m too immature or it’s not that powerful, I don’t know.
I assumed because I enjoyed using the PO-12 that the “Elektron workflow” would be a natural fit for me. I did not find that to be the case. At the time I was trying to avoid using the computer as much as possible and my assumption was that by being marooned away from the computer would force me to get better at playing the instrument. I think considerable effort must go into programming a track on the Model:Cycles. I’m quite open to the possibility that it just requires more work from me than I have been willing to put in.
If you are curious about the Elektron workflow, both the Model:Cycles and the Model:Samples are affordable ways to find out if it’s for you. The instrument is sort of a curiosity for me now. I think of it more as a drum machine, but I don’t enjoy using it as much as the PO-12.
Syntorial
Subtractive synthesis is just one type of synthesis, but it’s widely used in hardware, especially analog synthesizers and analog-modelling digital synthesizers. The “four part” subtractive synth is a classic design, and something that I eagerly tried to replicate in Csound for the class. The idea that presets could create so many distinct and amazingly different sounds from just a few parameters fascinated to me. I discovered Syntorial, which is basically ear training for subtractive synthesis, and became enamored with the concept of hearing a patch and being able to recreate it just by knowing which knobs to twist.
I emailed Joe shortly after the pandemic started asking if he was offering discounts, and indeed, he gave me a discount immediately and then did a big public offer. I got Syntorial, and am about halfway through it now. A major lesson of this year has been that there just isn’t enough time for my hobbies, and I have a burgeoning pile of tutorial material I still need to get through, and Syntorial is in that pile.
I enjoyed taking what I was learning from Syntorial and applying it on the Uno synth, but the Uno synth was showing its limits. I started thinking about a larger synthesizer, one with a real keyboard that would enable me to actually learn how to play a little bit, or at least understand some music theory. I waffled between wanting something small that I could use on the couch, like the Yamaha Reface CS, and something larger, like the Arturia MatrixBrute. But then something awful happened.
I fell in love with the Moog sound.
If it isn’t a Moog, is it really a synthesizer? — Tyler Cecil
Moog Matriarch
I saw two ways forward: I could buy one synth and be done buying synths for my life, or I could screw around with a small one, and keep getting larger ones and spending more and more until eventually I just couldn’t postpone it any more. Thankfully Liz understood and there was a big sale, so in June I got the Matriarch. Here’s Lisa Bella Donna playing it, and here’s another excellent 15 minute demo if you want a sense of the sound.
Syntorial had taught me enough that I knew my way around the synth immediately, as far as sound design. I still did not know how to play the keyboard. And I began to feel an intense guilt that I had this miraculous instrument that I couldn’t really play.
I contacted Eric and he agreed to give me some lessons, not oriented towards piano performance, but more towards music theory, basic chords, scales and dexterity for playing the synth. We did this for a few months. I got to where I can do the scales in various keys, play a major chord in various keys, and improvise in a way that sounds good to me. I am a lot less embarassed now than I was, although I should of course pour more time into this.
Following this, I realized it was pretty dumb to avoid the keyboard just because I did not know how to play it. Even if you can’t play it, music theory is written on the keyboard, and it will make more tactile sense than having capacitive pads, and more musical sense than a totally linear arrangement of keys as on the Model:Cycles.
Do I recommend the Moog Matriarch?
Yes, unquestionably. The sound is just unbelievable. At the time I got it I was also thinking about modular synthesis, and the idea of being able to safely and freely rewire things physically was really alluring to me. I liked the idea of doing extensive modulation through patch cables. Since then, I am mostly satisfied with the built-in routing and I don’t really see much need for manual cable patching, at least so far. The sound is just great, and it looks fucking awesome.
I’m no longer significantly interested in modular synths. I see the appeal. But I just don’t see myself spending $400 on a boutique oscillator or filter or delay module. That said, I don’t think Moog has a model of synth I would rather have at a similar price point. I could see the value of being able to store presets, but I kind of like that I have to turn the knobs to get the sound I want, and “debug” the patch when it doesn’t sound right. The “init patch” doesn’t scare me at all. More than presets, I think I would like having an internal mod matrix. The Sequential Pro 3 has a fun mod matrix routing mechanism that is appealing to me, but the sound isn’t as good to my ears. Moog One has something cool for this too, but it’s $6500 for the 8-voice model. I don’t think I could ever drop that kind of money on a synth. So around this price point, there just isn’t anything comparable in my opinion, and if you think you might want it, you probably do.
ORCΛ
When I was in my early-mid teens, before MP3 really became a thing, I discovered these MIDI files on my computer. You could open one of them and the computer would play a song; no lyrics, but it was pretty fun anyway. So you see why until this year I thought MIDI was a file format for music notes. This is a big misunderstanding. MIDI is actually a protocol for high-level music communication, at the abstract level of notes and parameter changes, and it has a central role in synthesis because it wires everything together.
I became aware of the fact that Csound had MIDI support during the in-person portion of the class, but this didn’t turn into any sort of useful information. It started to dawn on me that to make use of MIDI one needed a controller—a physical keyboard—and since I developing a shine for hardware synths, it seemed irrelevant.
Once I got the Model:Cycles, I noticed that in the manual there was information about both sending MIDI to the Cycles and receiving MIDI on the Cycles. So the Cycles could control other synths, like a keyboard, but it could also be controlled by a MIDI controller. This was a bit of a noodle baker for me. I also began to notice that there were, broadly speaking, two groups of people doing YouTube videos about synthesizers: the larger category of people like Andrew Huang who talked about “music production” and, while they maybe had and used hardware synthesizers, they tended to bring everything back into their digital audio workstation (DAW). I had no idea what a DAW was, other than some kind of software, and that meant it was going to be like Csound and therefore garbage and bad. If I was going to use a computer to make music, it would be like programming, and it would be precise and therefore good, but I didn’t want it to be like programming, at least not yet. So I tended to focus on the second group, the so-called “DAWless producers.” But even they were using MIDI and talking about how useful it was, so clearly something was missing.
The first piece of software I used that gave me the feeling I could actually make songs was ORCΛ. It was this program that finally drove home for me what MIDI was about. I could wire up ORCΛ to Pilot, the companion synth, or I could wire it up to GarageBand, or, I discovered, I could wire it up to the Model:Cycles and record the output in GarageBand. So I did this and made a few little demonstrations.
ORCΛ is really fun, but kind of a terrible environment for composition. An interesting idea. Not quite right for me though.
Bitwig Studio
At some point this year I started chatting with Drew Medlin about synths and synth stuff, and he has exerted a small but unyielding amount of pressure on me, to produce bits fit for sharing with him, and to keep the conversation going about music and synthesis. Early on, we were both using GarageBand to record. He invested in different things than me, so he wound up with a flagship OB-6 synthesizer and a couple Roland desktop recreations, a KeyStep Pro and was willing to play software instruments. So to him the DAW was something that existed mainly to crop the performance, which was mostly a one-shot affair with one instrument. I was ardently avoiding the computer because I wanted to allow myself some time to develop depth with the keyboard and synthesis, in fear that it if I involved the computer it would turn into another kind of programming for me.
In November I guess I came around the corner on that and decided that it was time to figure out a DAW. I wasn’t so much interested in software instruments, but in the idea of combining several recordings into one. I had used an iPhone app called Koala Sampler to play some simple sample-based stuff. I started to wonder what a DAW does, if it could be more than a way of gluing together recordings, and what else it could do and how. Andrew Huang’s channel, especially the “four-producers, one sample” videos like this one, was starting to convince me that there was something interesting going on.
I dinked around with Ableton Live and immediately saw something greatly more powerful than GarageBand. The clip launcher seemed like such an obvious improvement. I have no desire to play live music but as a way of organizing the composition into phrases, it made a lot of sense. I was starting to enjoy the idea of it, and then my Mac’s battery died and I was without a Mac for two weeks over the week of Thanksgiving. So I took the opportunity to try and see if there was anything out there for Linux.
I discovered several options. The hideous but widely-loved Reaper, the beautiful but incomprehensible Waveform, and Bitwig Studio. I spent a few days “used car shopping” between these alternatives and I tried them all out, and the only one that survived the process was Bitwig. I wound up actually buying the $30 tutorial course for beginners by Thavius Beck before buying the program itself, which is one of the best decisions I made all year. Simply having someone patiently tell you what all the panels do, how the shortcuts work, and the overall approach to using the program, made a huge difference in my comfort and understanding.
Like Live, Bitwig has a clip launcher/timeline dichotomy. It’s also more cross-platform, and it looks very beautiful. It handled the display resolution in Linux perfectly (Waveform did too). But it was when I started to learn more about it that I became convinced it was not only a powerful and useful program, but actually an amazing feat of engineering that would provide a powerful basis for experimentation long into the future for me.
The sense I get from other DAWs is that, most of your work is going to be done by loading various plugins to do the work. Many of the flagship software synthesizers out there have their own internal LFO and modulation system. Bitwig, on the other hand, understands modulation on a very deep level, so the necessity just isn’t there for you to rely on other soft synths to provide it. Bitwig also is highly recursive. Tracks can be groups of tracks, recursively; instruments can be instrument layers; devices can contain other devices or effects, there are note effects that come before audio effects and can be chained. Many devices have internal effects chains as well. I sense the presense of powerful and intuitive data structures underlying the system, and that makes it very natural to me as a programmer.
The coup de grâce is Poly Grid, which is a fully modular synthesis environment. I had tried VCV Rack and Voltage Modular at some point and found them unintuitive and one of them seemed kind of like a money pit. The Bitwig Grid eliminates a great deal of pain thanks to pre-cords, the ability to swap components out by right-clicking on them, and a plethora of excellent built-in components. It’s not trying to imitate a Eurorack modular synthesizer package, so visually it’s much clearer to see what’s going on. Polymer also makes it easy to convert a configured 4-function synth into a grid setup for further tinkering. The community of youtube people who actually use Bitwig are extremely smart and creative, and their video tutorials are just amazing: Tâsche Teaches on Euclidean Rhythms is a great example, along with Polarity Music on creating chords.
Seeing the world with new eyes
I have sort of a twenty year gap in my musical taste. I would characterize my parents taste in music as Woodstock. They loved the Beatles, and from my early childhood they are the first band I really think about liking. I grew up in the 80s, by the way. By high school I had made it into the early 70s and became quite obsessed with Led Zeppelin. By the time I graduated, my favorite band was Blue Öyster Cult, and I was starting to develop a taste for metal. In college, I had a friend who was into metal, so I discovered Death, who are responsible for one of my favorite songs and the eponym of the site, and had gotten in fairly deep with Megadeth, developed a real love for the band Mekong Delta (I was an early member of their internet forum), and was playing Primal Fear for my friends, who hated it but did begrudgingly admit that the musicians were more talented than Metallica. So it would be safe to say that I had a profound love of electric guitar. I made a point of trying to inculcate in my kids an appreciation of how amazing it is, that this instrument works through electromagnetism and not sound, the pickups are not microphones.
Beneath all that rock and metal, there had been a subterranean current of electronica. Before my friend helped me get deeper into metal at college, my big discovery had been Astral Projection, I had loved Juno Reactor. The first CD I bought with my own money was Ace of Base, which is the sort of deeply embarassing thing you don’t admit to your wife until you’ve been married for a year or so. I had owned albums by Aphex Twin. And by the time I did meet my wife, I was warming to pop music. That has become a full-fledged love, to the point I would say to people for the past ten years or so, that I love metal and pop and that was about it. This last year, for instance, I mostly listened to Charli XCX’s how i’m feeling now, which I think summarized the year for me.
So it came as a bit of a shock to discover this year, that many of the pop bands that I loved, I loved because of their use of synthesizers. Devo, CHVRCHES, Charli XCX, The Naked and Famous. It is blindingly obvious, but I didn’t really realize it until this year, that in fact I have loved the synthesizer for most of my life without realizing it, with considerable ignorance. I had often wondered at amazing “sounds” in different songs, but apparently not deeply enough to figure out how they were made. Even probably my favorite all time metal album, Rising by Rainbow, opens with a lengthy Moog synthesizer solo and has duelling solos between synth and guitar in the final act of the final song.
Musically, this year has been a constant moment of awe and discovery for me. The wonder of it all. And I owe this to Eric Sewell in first for opening my eyes, and to Drew Medlin in second for urging me on to keep them open. And to Tyler Cecil, probably the only one to actually read this blog, for providing guidance and counterpoint at various critical moments, and making it so that this actually gets written down. And to my wife Liz, who has supported my interest with patient ears, financial flexibility, and tolerated many YouTube videos on these topics. Whatever pleasing sounds I have learned to make are only in my mind because she delights me.
There is one official Toki Pona orthography, which is the one based on the lowercase Latin alphabet. There are two others: sitelen pona, the script, and sitelen sitelen, which looks like Mayan hieroglyphs. For instance, ale li jo e tenpo (everything has a time) renders in sitelen sitelen as the rather large:
And this is rendered in sitelen pona as ale li jo e tenpo.
Radicals in sitelen pona are an interesting idea. The color triangle forms a radical:
- kasi kasi (plant) + kule - color → laso - green/blue (plant color)
- uta uta (lip) + kule → loje - red (lip/mouth color)
- suno suno (sun) + kule → jelo - yellow (sun color)
Another radical is three lines emanating up, which seems to represent taking something and making it active somehow.
- luka (hand) → pana (give)
- lipu (document) → sona (knowledge)
- ijo (thing) → toki (speak)
There are a few more that use luka (hand) as a radical:
- luka + ilo ilo (tool) = kepeken kepeken - use
- luka + ijo ijo (thing) = pali pali - work
- luka + uta uta (mouth) = moku moku - eat/food
Most of the prepositions are formed by placing a box-like radical with a dot indicating placement:
- poki poki - container
- anpa anpa - below
- poka poka - next to
- insa insa - inside
- monsi monsi - behind
- sinpin sinpin - in front of
Sometimes the circle seems to be more like a personhood radical:
- jan jan - person
- jo jo - have
- lape lape - sleep/rest
- lawa lawa - head/leader
- mama mama
- wawa wawa - power
- mije mije - male
- meli meli - female
It also seems to have that connotation in the pronouns:
- mi mi - I, me, we
- sina sina - you
- ona ona - he/she/it/they
I also like the “nesting” composition for compound words. Several of the words (especially jan, ijo and tomo) are great for it: “the boss gave poison to his workers in the war room” might be jan-lawa li pana e ijo-moli tawa jan-pali lon tomo-utala. The nesting makes the content words darker than the syntactic words (li, e , tawa, lon) making it easier to see which concepts are together. This should make it easier to read Toki Pona in cases where two words are meant to be taken together as a compound.
Here’s a large list for this font:
linja pona compounds and roots
Many things which are unappealing about sitelen pona are addressed by this font, Linja Pona. For instance, ko ko has a pretty ambiguous definition, but looks more like a character here. Also, olin olin looks significantly better in Linja Pona than in pu (the official Toki Pona book “pu”).
I also find the cartouche idea interesting, where the first sound of each word in the cartouche tells you a letter in a name. So “jan Elena” becomes something like jan [_esun_len_en_nasa_alasa].
The above “radicals” suggest simplifications for Toki Pona, which is not something one would expect could be simplified much further.
Now I have some criticism.
Several characters seem to be intentionally unstructured. The worst offender is jaki jaki, followed by ko ko, which is at least improved in this font.
The only difference between lili lili and suli suli is the size of the glyph. Because of this, only the idea of smallness can be composed inside another glyph, bigness will always have to be written alongside. Your jan-lili (children) will not understand the sona suli (big idea).
Related to the suli / lili situation, lete lete (cold) can be embedded in other glyphs but seli seli (hot) cannot. Enjoy your telo-lete (ice water) but not your telo seli (hot water).
There are also a lot of characters that are liable to be confused with each other, especially the pronouns mi mi, sina sina and ona ona. You could say the same thing is a problem in the Latin alphabet with d b q p I suppose though.
There seems to be a relationship between sin sin (new) and namako namako (extra/spice) but I don’t get it.
kin kin follows the pattern set by a and o , except that the asterisk-shape should imply cold because of lete lete. I’m also not sure it’s a good idea to derive word characters from punctuation, especially punctuation from another language.
The prepositions seem like the kind of thing one would have trouble writing or remembering, which is compounded because many of them have senses that are different from their visual interpretation. For instance, anpa can mean defeat, and lon lon is used for a variety of purposes including “is here”, “exists” or “is true.”
Several characters seem to be taken whole from other orthographies without any real reason: nanpa for nanpa (number), esun esun, which means commerce or market. Also sewi sewi, which means high or divine seems like it should be a dot above the poki poki box for consistency with the other prepositions, although it does have this important meaning as well. ken ken (can, able to), I guess is so abstract there isn’t a more direct graphic way of conveying it.
I see some of these as playfully messing with Western-American sensibilities (the £ for money instead of $, Arabic for “Allah” as divine or above) but at least sewi misses an opportunity for more consistency while also illuminating the missed opportunity for the other prepositions, to come up with something more distinctive than dots near boxes.
I am thoroughly confused about why selo is selo yet sijelo is sijelo. The former means “surface, peel” and the latter means “body” or “physical state.” I have no idea how either of these glyphs is supposed to invoke these senses.
I kind of think a stack of lawa noka would have been good for sijelo, to represent a body as “from head to toe.” I think selo should probably have been concentric circles, which are currently the glyph for sike sike. Why is the glyph for circle two circles? Because ijo ijo is one circle. This gets reinforced by glyphs like pali pali which compound the idea of thing (pali, work, here recalling “make thing with hands”). Except it is already somewhat undermined because in many complex glyphs, the circle stands in for “person” rather than “thing” (mama mama being the best example).
Overall, I like sitelen pona a lot. Despite the shortcomings, it seems to be used quite a bit. The availability of this very nice font I think helps a lot.
Decreasing sequences
It occurred to me that I could think of two ways to generate a decreasing sequence. The built-in i.
will do this:
i. _7
6 5 4 3 2 1 0
But I could see a way to do it with self-reference $:
or with iterate ^:
:
(<:^:*^:a:) 7
7 6 5 4 3 2 1 0
This essentially says “iterate gathering results” ^:a:
“while non-zero” ^:*
“decrement” <:
. This differs slightly from i. _7
because it includes the number 7, but whatever.
The self-reference $:
method is a little longer:
0:`(, $:@<:) @.* 7
7 6 5 4 3 2 1 0
Like any recursive function, we need a base case and an inductive case. Sentences like
f`g@.t
in J give you case analysis, so a sentence like:
0:`f @.*
is a strong clue that your base case maps 0 to 0 and runs all positive numbers through f
, and that’s what’s happening here. So the next step is understanding , $:@<:
. This is about as simple as self-reference can get: we’re making a hook (it means the same as ] , $:@<:
if forks make more sense to you than hooks) basically using ,
to append the current value with the result of the recursive call. $:@<:
says “apply myself after decrementing the argument”.
This suggests an obvious way to get the increasing list, by just flipping around the arguments to ,
append:
0:`($:@<: , ]) @.* 7
0 1 2 3 4 5 6 7
I’m sure the self-reference version is worse in performance terms, but there isn’t as straightforward a way to flip it around like this, so this counts as an advantage here.
Detecting palindromes
This is one thing where Prolog usually has a significant advantage over other languages, because you can make the relationship between palindromes and reflection explicit:
palindrome(X) :- reverse(X, X).
However, J is still able to beat this:
palindrome =: -: |.
Match the value with its reflection.
We can improve slightly on the Collatz examples of Chapter 10 of Learning J by noting that, while taking a function power of infinity produces the fixed-point, taking a function power of boxed infinity (or simply the empty box) also gives us back the intermediate values. Let’s start by bringing back the function itself:
collatz =. -:`(1 + 3 * ])@.(2&|)
To review briefly, we can treat f`g@.t as
false`true @. test
In other words, this is a very condensed version of what in C would look something like:
(test x) ? (true x) : (false x)
So the overall expression says “if odd” (2&|
) “then multiply by 3 and add one” ((1 + 3 * ])
) “otherwise halve” (:-
), . The @.
causes the evaluation of cases and the backtick combines the cases.
As it happens there are some other J idioms that happen around this @.
function, whose name is “agenda:”
<zero-case>`<non-zero case> @. *
This exploits the fact that the monadic *
gives you 0 for 0 and 1 for all other positive numbers. And indeed we find over a hundred instances of this in the distribution, especially in the math addons. There are several other idioms in the standard library, such as @.(*@#)
, which can be read:
<empty array case>`<non-empty array case> @. (*@#)
or
<not length-N case>`<length N case> @. (N=#)
or
<not square matrix case>`<square matrix case> @. (=/@$)
The trick here being that reducing by equality against the shape will only be true if all the dimensions are the same.
The next step of Collatz is to build something that applies the function multiple times and gives us back the result. In Learning J we see that iterated application will gives 1 eventually, but we don’t see that using the ace will give us all those intermediates at once:
hailstones =. collatz^:(1&~:)^:a:
So there’s basically two tricks going on here. The ^:a:
is literally, to the power of empty box, which means in J, to the power of infinity, but give me all the results. The function being applied thusly is collatz^:(1&~:)
, which you can read as collatz, while it isn't equal to 1
. This is because our definition has a stupid loop in it, from 1 to 4 to 2 to 1:
collatz 1
4
collatz 4
2
collatz 2
1
collatz 1
4
With it the change, we see that it works:
hailstones 9
9 28 14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
A note about the pattern ^:a:
, it occurs pretty rarely in the library, only 9 times, mostly in dissect. ^:_
is not terribly common either. Looking through the code, I see a very large number of occurrences of ^:_1
to access inverse or obverse functions. +:^:_2
is a pattern for square root (which has its own primitive, %:
) and *:^:_2
seems to be a pattern for 4th-root (why you would need this is beyond me).
One interesting thing happens if we try to apply our hailstones
monad to an array:
hailstones i. 4
|rank error: collatz
| hailstones i.4
This is because the rank of our functions appears to be wrong:
hailstones b. 0
_ _ _
collatz b. 0
_ _ _
At rank infinity, these are hoping to apply to the whole array at once, which obviously will not work. We can improve our definition of collatz by adding an explicit rank, and then the problem with hailstones will go away, or we can just apply a rank to hailstones when we call it:
hailstones"0 i. 4
0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0
2 1 0 0 0 0 0 0
3 10 5 16 8 4 2 1
Now this is also surprising. We have a matrix with a bunch of zeros, and the answers are in the non-zero cells. This turns out to be something J and APL do to fill in when vectors of inequal length are combined to form a matrix. A better solution would probably be to box them.
(<@hailstones)"0 i. 4
┌─┬─┬───┬─────────────────┐
│0│1│2 1│3 10 5 16 8 4 2 1│
└─┴─┴───┴─────────────────┘
But, it might be more interesting to see how many iterations were necessary, rather than what those were, and just count them up:
(#@hailstones)"0 i. 4
1 1 2 8
Now we can just walk through the first hundred and find the one with the largest number of hops:
(] i. >./) ((#@hailstones)"0 i.100)
97
The >./
says, “maximum” and dyadic i.
finds the index of a value. So, the train ] i. >./
means, give me the index of the maximum value of this array. The answer is 97.
hailstones 97
97 292 146 73 220 110 55 166 83 250 125 376 188 94 47 142 71 214 107 322 161 484 242 121 364 182 91 274 137 412 206 103 310 155 466 233 700 350 175 526 263 790 395 1186 593 1780 890 445 1336 668 334 167 502 251 754 377 1132 566 283 850 425 1276 638 319 958...
# hailstones 97
119
There are 119 skips for #97. Wow!
Let’s talk about ΩeΩ = 1. Here’s a great blackpenredpen video about calculating this value:
This got me thinking about J, because it has some interesting “adverbs” for doing these sorts of calculations. For starters, there is a built-in numerical derivative operator D., and the power adverb, which has a note that giving an infinite power computes the limit. I think of it as a fixed-point operator: it repeatedly feeds the output back in as an input until the input and output are equal, which is a fixed point. The power adverb turns out to be a hugely useful control construct in several ways—you can use it to describe various kinds of conditions as well as loops.
The first problem in J is figuring out how to express the function ΩeΩ - 1 = 0. A little help from 13 :
produced this: 1 -~ ] * ^
. As usual, you read J from right to left. Start with the fork ] * ^
. ]
is effectively id
for functional programmers. ^
is exponentiation; the dyadic form, such as 2^3
calculates 23, for instance, and the monadic form ^x
computes ex. The fork trick being that the result of applying the left and the right are fed in as the left and right arguments to the center verb, ] * ^
is exactly xex. 1 -~
exploits a little trick about J, that constants can occur in certain positions of a fork or hook and act as values instead of functions, and because ~
flips the arguments of a verb, 1 -~ ...
at the start of a train is a great way to signify “… - 1” in a formula.
xex = 1 -~ ] * ^
.
There turns out to be no need to determine the derivative, because we can use the D.
adverb. In fact, there is an essay about Newton’s method on the J software site; I wound up having to change d.
to D.
for reasons I don’t understand. In the end, we wind up with this adverb definition: N =. 1 : '- u % u D. 1'
. Applying this once looks like:
(1 -~ ] * ^) N ] 1
0.68394
Applying it two more times looks like:
(1 -~ ] * ^) N ] 0.68394
0.577455
(1 -~ ] * ^) N ] 0.57745
0.56723
But, we can just let the power adverb iterate it for us until we converge:
(1 -~ ] * ^) N^:_ ] 1
0.567143
Not enough precision? We can always ask for more:
0j50 ": (1 -~ ] * ^) N^:_ ] 1
0.56714329040978384011140178699861280620098114013672
In the end the whole program is these two lines:
N =. 1 : '- u % u D. 1
0j50 ": (1 -~ ] * ^) N^:_ ] 1
0.56714329040978384011140178699861280620098114013672
Unbelievable.
Curious how many iterations it took? If you give a boxed value to ^:
, it will give you all the intermediates. So we can use #
to count them up and <_
to produce an infinity in a box and find out:
# 0j50 ": (1x -~ ] * ^) N^:(<_) ] 1x
317
For six places, it only takes 6 tries:
# (1x -~ ] * ^) N^:(<_) ] 1x
6
(1x -~ ] * ^) N^:(<_) ] 1x
1 0.68394 0.577454 0.56723 0.567143 0.567143
Update on D.
and d.
There are a few differences between D.
and d.
in modern J. The version of Newton’s method on the wiki page actually does work for this definition of ΩeΩ = 1: <:@(] * ^)
. There is not a huge difference between this and 1 -~ ] * ^
, just that in the original case we are performing an argument-swapped subtraction with 1. In the new case we are composing a decrement function. The derivative operator d.
is able to symbolically differentiate this definition, probably by simply discarding increment and decrement in composition since such things would fall off in general according to the power rule:
<:@(] * ^) d. 1
^ + ] * ^
(] * ^) d. 1
^ + ] * ^
This is just the fact that d/dx(xex - 1) = d/dx(xex) = xex + ex.
In short, the differences between D.
and d.
are:
d.
performs symbolic differentiationD.
performs numeric approximation of a derivativeD.
has different rankD.
can be used to produce partial derivatives as well
The following books have made an impression on me and my beliefs.
Biblical Literacy by Rabbi Joseph Telushkin. This book gives you a synopsis of the bible, and Telushkin draws your attention to the moments and ideas that are important in Judaism. In a similar vein, How to Read the Jewish Bible by Marc Brettler, also surveys the content of the Bible and helps to put it into a modern Jewish perspective. Robert Alter’s translation of the Hebrew bible The Five Books of Moses, as well as its continuation in several more volumes, is also a vital resource to me. Alter brings an incredible amount of knowledge of Hebrew and related languages to bear on his translation and has copious notes about the decisions to be made, as well as point out puns or inside jokes that would not be apparent in the English translation. Bringing this edition to Bible study is worth a lot. Etz Hayim is the Conservative movement’s official chumash; the translation is bland, but you get 2:1 notes to text, which is wonderful, including a lot of very interesting tangential material. I found the combination of these two books to be very effective for bible study.
In a different vein, Chuang Tzu, translated by Burton Watson. The inner chapters in particular are both powerful and beautiful, but there are lots of gems in the remaining chapters as well, if you can ignore some repetition. I find a lot of compelling ideas in Taoism, especially Chuang Tzu’s version of it, but there is beauty in Tao Te Ching, the Addiss/Lombardo translation being the one I have.
The Rise of Christianity by Rodney Stark. This book shines a light on the darkness between 70 CE and the moment Christianity became the religion of the Roman Empire. Where did it come from, how did it grow so quickly? This book gave me a deeper appreciation of what it is about Christianity that made it change the world, and gave me more compassion for my Christian friends. Similarly but for Islam, Introduction to Islam for Jews by Reuven Firestone clarified things greatly, by showing ways that Judaism and Islam are similar and different. I think this book would work with a non-Jewish audience.
The Other God by Yuri Stoyanov is a fascinating deep-dive into the history of dualist thought, from ancient Egypt, through Zoroastrianism to defunct and mostly lost religions like Manichaeism and Catharism. Similarly, Ancient Mystery Cults is a deep dive into Mithraism and the Eleusian mysteries, what is known anyway, and the book was an effective antidote to tropes like “Christianity is just Mithraism dressed-up.” The Indo-European ideas that reappeared in Mithraism were also the bedrock of Iranian religion, where the dualist religion of Zoroastrianism was born and many other religions underwent change: the topic of the book Religions of Iran by Richard Foltz. Although not so much about religion, Genghis Khan and the Making of the Modern World by Jack Weatherford illustrates how many modern ideas were born by the Mongols and the fruit of their conquest, in the neighborhood.
In the Dust of This Planet and volume 2 of the same series, Starry Speculative Corpse are excellent overviews of a lot of areas of inquiry. I hesitate to come down hard as a pessimist but negative theology conceptually is very appealing to me and my understanding of it comes from these two books, which are short and approachable. I also got a lot out of Emerson, especially “Self-Reliance” and “Circles.”
Two other philosophers made deep impressions on me: Henri Bergson, whose Creative Evolution kept me struggling in college but whose ideas about time, duration, evolution and intuition have stuck with me in some bastard form, and Jiddu Krishnamurti, who really only had one thing to say (paraphrased “you don’t need a teacher, which is handy because you can’t have one anyway”) but said it so audaciously and powerfully that he wound up attracting a following and having to say it repeatedly. Try Freedom from the Known. (He deserves bonus points for dissolving the cult he was brought up to lead.)
In more depth with Judaism, we must discuss Heschel, whose books are so powerful I haven’t finished any of them. God in Search of Man is the one I most want to finish, The Sabbath is one I actually have finished, I Asked for Wonder is to my recollection, quotes, but even his quotes are great.
Some dimensions of Jewish practice that are worth discussion: Everyday Holiness teaches the practice of mussar, which is a form of Jewish-religious self-help; an interesting topic for someday when I’m bored. Jewish Meditation is what it says on the tin, and Rabbi Kaplan also did translations of other important Kabbalistic works, especially the purported manual for making golems Sefer Yetzirah and proto-Zohar Bahir, both of which are only approachable thanks to his copious notes. Notes outweigh source matter by about 10:1 in each of those.
Some more comparative religion, The Sikhs by Patwant Singh is a nice overview introduction to the religion I read before Wikipedia. Ofudesaki is the holy text of a fairly obscure Japanese religion, Tenrikyo; I never made it further than about 10 pages.
More crap—I mean, stuff—in the Western esoteric traditions: The Secret Doctrine of the Rosicrucians explains their “philosophy” of vibrations and magnetism and whatever. Similarly, Alchemy Rediscovered and Restored gives you more of the wider story of “spiritual alchemy” rather than just the Rosicrucian “version” of it. Feel free to go full stupid with Practical Qabalah and The Mystical Qabalah, but be sure to pick up Aleister Crowley’s books at some point.