Week 2: “An Eternal Golden Braid”
March 17, 2023
My last post highlighted one example of an Esoteric Programming Language, Piet. In general, the purpose of most esolangs isn’t for pure functionality, but there are many different unique purposes, whether creating something for art, as a joke, or something else entirely.
I’ve been interested in the mechanics and variety of esolangs for a few years now, and I wanted this project to really be a deep-dive into that community. So I’m not just involving Piet, but also a language called BrainF. Here’s an example of the same “Hello world!” program in BrainF (in fact, it’s generated specifically from a Piet program, and I’ll explain later how I did this):
BrainF is even more simple than Piet. In BrainF there are 8 possible characters. As a program is ran, the interpreter makes a simple action on an array based on the command given by the character. For example take a simple program: ,>,[-<+>]<.
In order it executes these commands first: , (take input) > (move forward in the array) , (take input)
If the user inputs the numbers 3 and 2, the array would like like this: [3][2][0][0][0][0][0]…
The square brackets indicate a loop, which exits when the cell being pointed to has a value of 0. The program then executes these instructions while looping:
[3][2][0][0][0][0][0]…
– [3][1][0][0][0][0][0]…
< [3][1][0][0][0][0][0]…
+ [4][1][0][0][0][0][0]…
> [4][1][0][0][0][0][0]…
– [4][0][0][0][0][0][0]…
< [4][0][0][0][0][0][0]…
+ [5][0][0][0][0][0][0]…
> [5][0][0][0][0][0][0]…
The pointer now looks at the number 0, so the loop is exited. The final commands executed are < (move back) and . (read output), which outputs the number 5. This is an example of a basic adding program in BrainF.
After looking at BrainF and Piet, I realized both execute in a similar manner, so I wanted my project to involve both.
The other important aspect is Machine Learning. I’ve been been exploring and taking courses in the field for the past several years, recently even working on creating a spam filter for email inboxes, using Machine Learning. After brainstorming a few ideas related to both esolangs and ML, I thought it would be interesting to create a “translator” from BrainF to Piet. My current plan is to train a model upon equivalent pairs of BrainF and Piet code, so that one can be converted to the other. For every piece of simple BrainF code, there should be many different ways this can be expressed in Piet, because the code can take radically different paths, ultimately creating different pieces of “abstract art.”
For this project to be successful I need to go through several different steps, starting with this week’s, creating the collection of data needed to train the model. I’m in the process of collecting different Piet programs published on the internet. Along with this, I’m writing a program to take the operations that the Piet program runs through, and convert those into corresponding BrainF strings.
First an interpreter runs the Piet program, logging what actions are being taken, which is then processed into a list, where each entry is then converted into a string of BrainF commands.
This is how the “Hello world!” program mentioned earlier in the post was created.
Despite this progress, there are still some issues with my current approach. While talking to my external advisor about the current program I realized that, because of the way that programs implement features like loops and conditionals, the underlying operations being done can vary drastically depending on input. Lets say you take a program that outputs the factorial of any given input, the abstracted logic remains the same. You take the number and multiply its own factorial minus one (n! = n*(n-1)!). So a higher number input will require significantly more operations to complete the task, so the program flow is not consistent without accounting for different user-inputs to the program.
Ultimately the Piet code can take many different paths, but the methods I was using to transcribe it to BrainF only show a facsimile of the true code. It’s much like the cover of one of my favorite books, Godel Escher Bach: an Eternal Golden Braid, by Douglas Hofstadter. The cover depicts an object that has its own unchanging shape, but can project different shadows depending on how you look at it. (the image can be found online, but this video also shows a cool demonstration of this property using LEGOs: https://www.youtube.com/watch?v=mtQ0hkwlDHw)
I also realized that my project was also partially inspired by reading Hofstadter’s book. The book draws many parallels between different fields, whether they be art, music, programming and logic, the biology of the brain, etc… I hope that my project can do similar in exploring these connections, whether between Machine Learning and programming languages, or how it ties in to the art created by Piet.