From the archive: Trireme

(I’m bored, and I’m tired of talking about the Wuhan virus. So let’s delve into my personal code archive. First, of course, we need a prologue, so bear with me.)

For as long as I can remember, I have been interested in recreational mathematics. And that phrasing is entirely literal: I’m 36, and I have memories from my early childhood involving numbers, math problems, and the fascination that the field produced in me. From a young age, I read through math textbooks for fun (algebra at age 4-5, calculus as early as 9), but I was more drawn to the strange and wonderful ways people used numbers. Puzzles involving math were great fun. I read condensed versions of The Phantom Tollbooth and Flatland while my contemporaries were struggling through Dr. Seuss. My aunt had a kind of children’s encyclopedia, where each volume revolved around a different topic; to this day, I have no idea what was in the other 12 or so, because I only ever read the math one.

Naturally, that led me to computers early on, and you could say that my career as a programmer started when I was 8, the day the teacher of my gifted class handed me a black binder, pointed me towards the Apple II in the back of the room, and sent me on my way into the world of 10 PRINT "MICHAEL RULES!"; 20 GOTO 10. I was hooked, and nearly three decades have not dimmed that fire one bit.

But I still have a passion for numbers, for mathematics in the recreational sense. As an adult, I discovered Donald Knuth’s The Art of Computer Programming, the seminal (and unfinished after some 50 years!) text on the underlying mathematics of programming, and that connected the twin loves of my online life.

Honestly, the books aren’t much help for learning how to code. The edition I have uses a positively ancient assembly language for its examples, and it’s easier for me to understand the concepts from the prose descriptions. But the lessons are still usable today…assuming you need them. Or, in my case, want them.

Chapter 4 is my favorite, as it discusses, well, numbers. A significant chunk of the chapter (itself half a book long) is concerned with the representation of numbers, whether in writing or in computer circuitry, and it was here that I rediscovered the spark of my childhood. And that leads me to one of my solo projects from 2019: Trireme.

What in the world?

Trireme is, to put it simply, a simulation of a fictitious CPU that uses non-binary arithmetic. Now, that doesn’t mean it rejects society’s notions of sexuality. Instead, it rejects society’s notion of how a computer should work. You see, all computers in use today deal in binary numbers. Base-2. 1s and 0s. (Sometimes, you’ll hear talk of hexadecimal, but that’s a human conceit: a single hex digit is nothing more than a group of 4 binary bits.)

But it wasn’t always that way. In the early days of computing, binary wasn’t a given. Quite a few computers from the 50s and 60s used decimal arithmetic. That was harder on the designers, and they often cheated by using some kind of binary-coded decimal scheme internally. (Even today’s x86 processors, such as the one you most likely have in your PC, still have instructions for this kind of number, but they’re disabled most of the time.)

Decimal’s fine. It’s what we use in the real world, so putting it in the virtual world isn’t too big a stretch. What I learned from Knuth’s book, then expanded upon in my online research much later, is that some people went for something even stranger. The Soviets, ever ready to be different from the US, had a weird little machine called Setun. It didn’t use binary numbers. It didn’t use decimal. No, its designers chose something called balanced ternary arithmetic: base-3, but instead of using 0, 1, and 2 as digits (like you’d expect), you use 0, 1, and -1. It’s crazy.

And, in my opinion, beautiful.

I’m a big fan of symmetry. To me, it is the largest component of what makes something aesthetically pleasing. Balanced ternary is a symmetric number system, and thus I find it more intrinsically beautiful than computer binary, where negative numbers have to be represented using either a sign bit (which gives you the possibility of a negative zero) or two’s complement arithmetic (where the maximum negative value doesn’t have a positive counterpart).

Eye of the beholder

I first read about Setun in the Knuth book, as he devotes a small section to balanced ternary for the same aesthetic reasons. From there, I learned the rudiments of the number system, how arithmetic works when some digits are negative by their very nature. And I thought little of it for a decade after that.

In 2009, I was bored (are you sensing a theme yet?), and I got one of my borderline-insane ideas. What if we made a balanced ternary computer today? What would it look like? Setun was a stack-based machine; I won’t go into the details here, but suffice to say, I find stack machines ugly and unwieldy. I much prefer load-store architectures similar to those I’ve programmed in the past: AVR, 6502, etc.

So I designed one. Recall that I have no formal training in CPU design or even electronics. I was just a man with a dream, and I got surprisingly far, considering what little I had to work with. I even went to the most fundamental level, designing logic circuits that could detect and operate on electrical signals that came in three levels, including positive and negative voltage.

(You’d be surprised how well it works. Two transistors of the right type can create a balanced ternary signal. A flip-flop—basically a memory cell—takes fewer than ten. A half adder? Not much bigger. With today’s miniaturization, we could do it, and it wouldn’t be too inefficient.)

In the end, however, I’m a programmer, so my main interest lay in the software to emulate this hypothetical architecture. My first attempt, a decade ago, was…not good. Okay, it wasn’t bad, but it could use a lot of work. The code was not organized well. It relied too much on what are now considered suboptimal structures, and it just didn’t do everything I wanted. Still, I called it a partial success, because I proved to myself that it was possible to make a modern-style processor using non-binary numbers, and that I could do it.

Fast forward

Skip ahead another decade, and I read a forum post mentioning Setun, even linking to an article written about a nearly forgotten experiment from behind the Iron Curtain. That hit me at the right time to rekindle the fire. It’s nothing more than coincidence, really. Perfect timing to snipe my mind.

Trireme was born that night. I chose the name because I wanted something that evoked the number 3 (to represent the ternary aspect), and I didn’t think Trident worked. Plus, I’m a big Civilization fanboy; the trireme is an iconic unit for the series, so why not honor it in this way?

With ten more years of experience, I was smarter about both aspects of the project. I understood more about computer architecture, what worked and what didn’t. As well, I’m a better programmer today than I was then, with much more breadth, and a better grasp on how to write code other people could stand to read.

I wrote the code in Modern C++, because I wanted something fast, but also because I really like the language. (I know, I’m weird that way.) It’s a real program, too, complete with a command-line interface, a rough outline of a plugin system, and a few bells and whistles. Is it complete? Not at all. I’d love to do more with it. Given the chance, I’d like to add more to what’s currently a microcontroller; Trireme needs simulated peripherals, an OS, and much, much more. Despite that, I’m proud to say that it’s mine.

The purpose of Trireme, in as much as it has one, is to answer one question: How much of modern computer science relies on computers using binary arithmetic? As it turns out, quite a lot. Many of our common algorithms are tuned to binary, for instance, as our most of the standards upon which our modern world is built. But I think that’s where something like Trireme can come in handy as a pedagogical tool. It’s always good to think outside the box. Studying such an “alien” computer might give us insight into how to improve our own.

If you’d like to check it out, I’ve put the code for Trireme up as a Github repository. It’s free and open source, and I would love to talk to people who are interested in it. Yes, it needs a lot of improvement, but that’s on the back burner as I work on a few more practical projects. Once I have the spare time, I do want to return to it, make it better.

Why? Because I love numbers. And, strange as it may seem, I have rarely had as much fun programming as when I was working on Trireme. Isn’t that enough?

Heal me, I’m broken

I’m almost ready to give up.

The world has gone completely insane, as you may have noticed. Now I wonder whether I was already there. What I don’t wonder, however, is whether I should care. Because I don’t. Not anymore.

For years I have mostly kept my political leanings off Prose Poetry Code, because I felt it just wasn’t the place. Yes, I did the “Social Liberty” thing a long time ago, but that was about it. Even those posts never actually advocated a particular ideology; they were nothing more than a thought experiment where I tried to derive the inalienable rights of the Constitution from a set of first principles.

Well, what I’ve learned lately is that nothing in the modern world is apolitical. And so PPC can’t be, either. At this point, I believe I have nothing left to lose by throwing my opinion up here. What’s going to happen? I’ll lose my job? Nope. Don’t have one, and I doubt I’ll be getting one in the near future, despite my best efforts. Put on a watchlist? Already there, most likely. My girlfriend will leave me? That presumes I would have a chance of keeping her otherwise, and that assumption is hanging on by the thinnest of threads.

In other words, I’m already a broken man. This can’t break me any more than I already am, so why bother keeping my opinions bottled up?

Panic

Let’s start with the only news story we’ve had for the past month: coronavirus. No, I’m not one of those people who think it’s a hoax, a conspiracy to cover up the “real” truth of 5G towers and chemtrails and whatever else the Alex Jones types have come up with. It’s a real virus that’s affecting real people.

That most emphatically does not mean it’s all the media has made it out to be. Slowly but surely, solid numbers are coming out, and they very often show just how overblown the danger is. Asymptomatic rates of 20-50%, if not higher. Antibody presence in 15% or more of a random sample. An actual fatality rate closer to 0.3% than the 2-7% we were initially told.

And it doesn’t take much looking (though you do have to go off the beaten path of mainstream media and celebrity Twitter feeds) to find reports from everywhere in the US—with the notable exceptions of the New York and Detroit metro areas—of half-empty hospitals, of doctors and nurses being laid off or furloughed, of a growing realization that this was not the apocalyptic disease we were told to expect. The “best” model, the IHME model from the University of Washington, overshot Tennessee’s cases by a factor of 20! Minnesota’s special snowflake model is calling for a 30,000% increase in coronavirus deaths (from approximately 70 to over 20,000) between now and the end of summer!

Supporters of the draconian measures we have endured will say that those worst-case scenarios are if we don’t lock everything down, lock everyone up. But that’s simply not true. The IHME model takes into account “social distancing” measures (and that phrase disgusts me on many levels, but I digress) as of April 1, though its cheerleaders don’t seem to notice or care.

Pandemic

The problem, as ever, is polarization. If anything, I consider that far more of a threat to our nation than any virus, because it’s a much more insidious disease. Even today, you can take a look anywhere, whether online or real life, and see America increasingly divided into two camps that seem to be inhabiting two different realities.

On the left, you hear cries to keep the lockdowns until there are no more coronavirus deaths. Which is unrealistic, even if you discount the fact that hospitals are overcounting those deaths in an attempt to make back some of the money they’re losing by postponing elective surgeries. Add in the very real possibility that a vaccine might be years away (assuming it’s even possible—we don’t have one for the common cold, and that’s sometimes caused by a coronavirus), and…what’s the plan? We become the Morlocks, never seeing the sun except when we brave it to scrounge for a meal?

Every day you extend what we can only call the imprisonment of millions of Americans only makes the situation worse. Mental health is declining sharply—my own included. Suicides are rising, and I have no doubt that they will outnumber legitimate coronavirus deaths by the end of this year; whether I’m included in that tally is, I’ll be honest, an open question. For those fortunate enough to have families, they’re seeing increased incidence of domestic violence, child abuse, and other nastiness. Those are sure to take yet more lives. And that’s not even counting the lives that may never be, thanks to this isolation.

But the right isn’t any better, because they can only look at things through one lens: economy. Yes, it’s bad, and getting worse. Small businesses are failing, and big business is no longer booming. Unemployment is off the charts. Literally, as in the charts, much like the unemployment applications, were never made to handle such a vast segment of the workforce applying for benefits at the same time. Yet those wounds can be healed in time. We recovered from the Great Depression. We recovered from the Spanish Flu. Both of those were far more damaging, whether to our economy or our populace, than this virus.

Focusing on the economy, however, minimizes the impacts the lockdowns are having in other areas. Humans are social animals, and we evolved to socialize in person. Face to face, not through a computer or phone screen. Technology is wonderful. It’s the mark of progress, the symbol of all we have achieved. But it can’t replace the real world yet. To say that Zoom or FaceTime or Duo can substitute for actually being in the same room as a loved one, for actually having the chance to hold your newborn nephew, for actually doing the things you enjoy doing, is laughable. To say it’s more important to reopen the barbershop down the street is dehumanizing. It makes us nothing more than cogs in a machine.

Pan-democratic

We are more than that. We are human. And, as Jefferson wrote, all humans are endowed with certain inalienable rights, chief among them life, liberty, and the pursuit of happiness. Nothing in the Constitution says those rights are invalid in a time of crisis, because the very idea that we should protect them, enshrine them, rose from a time of crisis.

If police can stop a peaceful protest because the protestors are standing too close together, then why even have a right to assemble? If it takes federal intervention to stop a state from scanning the license plates of cars sitting in a church parking lot on Easter Sunday, how is that free exercise of religion?

The greatest thing about the Bill of Rights, I have long felt, is its purpose. Jefferson, Madison, and the other Founding Fathers did not create a document that said the government granted these rights. Not at all. Instead, they made a list of the most important rights that we have just by being born, then said, “Let’s make sure these can’t be taken away.” The First Amendment starts with the words “Congress shall make no law…” because the writers knew that Congress would eventually try to make those laws. (In fact, they barely had to wait: the Alien and Sedition Acts came about during John Adams’ presidency!) All through the Bill of Rights, you can see that this is not a list of what the people can do, but what the government can’t.

Yet they are. And in a much more dangerous fashion than in the dark days after 9/11, the days of the Patriot Act, of “extraordinary rendition” and the TSA and a hundred other small cuts. Now, it’s easier to point out the amendments still intact, because they number one: the Third. And I’d wager that’s only because state governors haven’t found a way to put the National Guard in peoples’ homes to make sure they stay far enough apart.

We can change this. We can end the tyranny if we all work together, if we cast aside our petty tribalism. Forget about Team Red versus Team Blue. Think about Team Red, White, and Blue. Stand up to those seeking ever more power over your life, your livelihood, the things you hold dear, the things that make you who you are.

We have an election in November. I had intended to run for the office of state representative, but the coronavirus stopped that. I couldn’t go from door to door for petition signatures to get on the ballot. But I still have a voice and a vote. Anyone, regardless of party affiliation, who supports a continued lockdown based on faulty data, media hysteria, and wishful thinking will receive no help from me. Those who wish to deny me freedom are my enemies. It’s as simple as that.

I may be broken, but maybe I can help others put their pieces back together.

Another review

Once again, I feel compelled to review a bit of media. In particular, it’s an album. Call it a sign of the times, I guess.

I first discovered Nightwish in 2004, based on a recommendation from…Slashdot, I think. If I recall correctly (for something that long ago, I can’t say I do), it was the same “smart kids like metal” article that got me interested in the genre as a whole. But I kept seeing them at the top of a few favorites lists, so I checked out Once.

I was blown away. This was the kind of music I never knew I’d been looking for. My only real experience with symphonic metal before then was Metallica’s S&M live album, which was actually really good. Too bad the band immediately lost any goodwill by suing its fans, but I digress. Once left me hooked on not only a band, but an entire subgenre of music, and that hook has stayed in me for a generation.

Last week saw the release of Nightwish’s ninth studio album, cumbersomely titled Human. :II: Nature. (For the sake of clarity, I’ll discard the extraneous punctuation for the rest of this post.) Naturally, I’ve listened to it a few times already, and now I’d like to talk about it.

Music

This one’s actually 2 CDs, not that “CD” means much when almost everyone is going to listen to it in MP3 or Youtube video format. The first disc leads with “Music” as its opening track. We get a fairly long symphonic intro—always a nice touch, in my opinion—before what I see as a fairly traditional Nightwish track: upbeat, with lifting vocals that mix with the orchestral and metal music to create something that overpowers your ears while still sounding beautiful.

“Noise” follows, and it’s a sharp contrast. Where “Music” is almost soft, “Noise” is overtly harsh. The singing is closer to screaming, and there’s more…shredding. Which fits the lyrics, full of references to Black Mirror and allusions to the cacophony that is our modern life.

Farther down the line, “Harvest” is the 4th track, and I would call it a masterpiece. Poetic lyrics, a melodic sound, and a general feeling of goodness permeate the song. Between its content and the chorus of band members singing, I have to admit that I was, for some reason, reminded of “Baba Yetu” by Christopher Tin, the theme song of Civilization IV. “Harvest” just struck that same chord within me.

“How’s the Heart?” is another that left me feeling better. In a way, it’s kind of a sequel to the previous album’s “Elan”. (A common theme, as Human II Nature as a whole seems to be envisioned as a sequel to Endless Forms Most Beautiful.) But it stands alone just fine, and I see it as one of the most meaningful tracks on the album. My interpretation of the lyrics is simple. We’re all human. We all have needs, and ranking high among them is the need for socialization. In these times where that need, like so many others, has been forcibly suppressed, “How’s the Heart?” asks a question I can only answer in one way: it could be a lot better.

“Procession” immediately follows, and I look at it as another “sequel” to a song on Endless Forms Most Beautiful, this time “Edema Ruh”. There seems to be a common theme in these two albums of…watchers. Call them ancestors, angels, aliens, or animist spirits, but someone is watching humanity, as though we were performing for their benefit. They were here before us, they’ll be here when we’re gone. Above all, though, they’re curious. They want to see what we’ll do next. In “Procession”, they sound as though they’re getting tired of our petty squabbles and lack of inspiration. And I agree.

Disc 1 concludes with “Endlessness”, the only track with primarily male vocals. That’s one of the downsides of the album, in my opinion, but I understand. The band’s always been more female-fronted in its singing. Although I won’t say this is the best song on the disc, it holds its own, despite being fairly long. It’s a grand finale, and it does succeed at that. You feel like you’re at the end of a journey when it begins to fade.

But the journey is only halfway done.

The second disc is technically a single song, divided into eight parts collectively titled “All the Works of Nature Which Adorn the World”. It’s entirely instrumental, apart from the occasional choral vocals and a spoken word section at the beginning and the end, and…it’s a metal symphony. There’s no other word for it. “Vista” and “Aurorae” are stirring, “Moors” makes me long for…something. I’m not sure what, but it’s there. “Anthropocene” is a term I generally loathe, considering it a pejorative, but here it comes off as inspiring—if this be the age of humans, let us make it ours. (To top it off, this movement of the symphony even includes a version of the Hurrian Hymn to Nikkal, the world’s oldest known musical work.)

“Ad Astra” closes the book on Human II Nature, and let me tell you this right now: nothing could have prepared me for it. Not only does the music build to a perfect crescendo, creating the sense that, while this story is done, ours hasn’t even begun, but the spoken section is moving, inspiring. It’s a passage from Carl Sagan’s Pale Blue Dot, where he muses over the picture of the same name, a photograph of Earth as seen from billions of miles away.

Our whole planet doesn’t even take up a whole pixel of the image. Everything we know, everything we are, is nothing more than a dot, “a mote of dust suspended in a sunbeam.” For Sagan, that’s a call to protect and cherish what we have. For me, it’s something different. Yes, we must ensure that our environment continues to support not only our lives, but also (and this is where so many environmentalists go wrong) our livelihoods and our standard of living.

To me, the pale blue dot is the beginning. It must be, because otherwise it would be our end. And that, I think, sums up my feelings on the meaning of Human II Nature. We were born of nature, yes, we are of nature, but we have outgrown it. Tsiolkovsky said it best:

Earth is the cradle of humanity, but one cannot live in a cradle forever.

“Ad astra,” the song’s title says. To the stars. At a time when tens of millions of Americans aren’t even allowed to leave their homes, we can yet dream of better times to come. We don’t have to be chained to the indignities of the present, the ghosts of our past. We can make a future that is greater.

Why? Because we’re human. We’re not the disease. We’re the cure.