Semantic Polymorphism: explaining abstract concepts using buttons, tape, and string

Ryan Vandersmith
7 min readFeb 7, 2020

We humans seem to like concrete, tangible examples to more easily understand highly abstract concepts. My approach to learning has always been to explore lots of examples before learning the underlying theory, rather than the other way around. This was presumably the idea behind “word problems” in math class, although I personally find it more interesting to learn from real-world examples relevant to my interests and hobbies.

This process of learning patterns from examples relies on generalization, which our brains are very, very good at compared to modern artificial intelligence. This is also the basic idea behind mathematics — we can more efficiently solve complex problems by stripping away the context and focusing on important details.

In fact, several branches of mathematics are even devoted to logically generalizing mathematical structures themselves. Universal algebra is a slightly obscure but rather important field of study for understanding basic concepts such as addition or multiplication in the same logical framework as more intricate ideas such as vectors or fields.

Conveniently for those who haven’t heard of universal algebra, this article will treat you to a nice, consistent, tangible way of thinking about any discrete mathematical concept, and then share some of the theory behind it. If you’d like to follow along yourself, here is what you’ll need:

Materials:

  • One pair of scissors
  • Two or more buttons (or pins, or whatever else is available)
  • An infinite amount of string
  • Imagination and enthusiasm
  • Masking tape and a marker

Time to break out the collection of stray buttons that my family has hoarded over the eons.

Let’s start with some numbers. Buttons and string don’t necessarily have a way of counting themselves. You can hold a certain quantity of buttons or cut a specific length of string, but we ultimately need a human to interpret how these correspond to actual numbers. For instance, if you line up your buttons from left to right, their order will reverse if you view them from the opposite direction. Likewise, the numeric length of your string suddenly changes when you use a different unit of measurement.

Our goal here is to find a way to assign a unique, unambiguous counting number to every piece of string without any “loops.” In other words, each string must directly attach two different buttons or strings to each other.

Here’s the solution I came up with. While we can approach this in a variety of ways, this one is particularly interesting to mathematicians because it is equivalent to the inductive definition of natural numbers.

We begin by attaching two buttons together with a string, and labeling each button with masking tape to clarify its purpose within our system.

The leftmost button represents the start of our counting system, namely zero. The button on the right corresponds to the concept of incrementing a number by one.

Next, we need to find a nice way to represent numbers greater than zero. We will consider each string to represent the logical combination of the concepts on each end. In the case of our string between the buttons (0) and (+1), we can label the connection (0)(+1) or (0+1).

As humans, we usually think of this concept as the number one, meaning that we have just defined a number using a string between two buttons.

We’re making progress, but how do we create additional numbers after zero and one? The key idea is to treat strings themselves as possible endpoints. In our case, we can now attach (0)(+1) to the original (+1) as shown below:

This new string corresponds to ((0)(+1))(+1), or as the cool kids are calling it, two. We can now take this string and repeat the process forever:

This pattern creates a nice visual representation of the natural numbers, forming a spiral around the (+1) button as we continue to extend our model.

From here, things get very interesting. We can start adding more buttons to describe progressively more complex ideas, such as adding two arbitrary numbers together (rather than just incrementing the number by one).

As you might notice, this piece of art becomes rather complicated and difficult to understand after about a dozen strings. The world will also eventually run out of string and masking tape if we do this properly, so perhaps it might be worth enlisting a computer to do the heavy lifting instead.

Because computers are (currently) our unquestioning subordinates, we can just tell them what each button is supposed to represent and they will happily churn out the strings for us. All we need to do is clearly explain how the buttons and strings should attach to one another.

How about this: let’s define a “rule” that for every string (S) connected to the button (+1), we want a new string between (S) and (+1). This way, if we add the string (0)(+1), all other numbers immediately exist, since the rule continues repeating on the strings defined by itself. This process is called recursion and is fundamental to theoretical computer science and inductive mathematical proofs.

Now we are ready to tie everything back to our discussion at the beginning of this article. Most branches of mathematics focus on removing context and focusing on specific details. However, in some cases (especially with artificial intelligence), we run into the issue of losing contextual information that could indirectly help solve a problem. As humans, we each have a personal ocean of memories and knowledge that we can leverage in these situations, whereas modern computers tend to have trouble learning the vast amounts of experiential information required to do this efficiently.

This desire for context has been formalized in the field of category theory, which is a mathematical foundation for viewing abstract concepts based on transformations of their high-level structure. While extraordinarily powerful and useful, category theory can be daunting to learn outside of specific theory-driven applications. Along with other mathematical foundations such as set theory, it is also rather challenging to implement this type of high-level reasoning on a computer without being weighed down by the arbitrary structure designed for our mere mortal human brains.

This is where universal algebra comes into play — in particular, an algebraic structure that we nerds fondly refer to as a “free commutative magma.” Let’s break that down one word at a time, in reverse order. A magma is just a very general type of algebra; all you need is a set of objects and a binary operation which takes two objects and picks any one object as result. If you have a commutative magma, the order of the input objects does not matter (similar to addition and multiplication). Finally, a free magma just means that each output has its own object, generating a self-similar fractal-like structure.

When we put this all together, we end up with a set “M” in which every element corresponds to a possible button or string in our above model, and vice versa. As a result, every button-string masterpiece represents a specific subset of M.

It turns out that we can represent literally any possible discrete concept by choosing a subset of M and providing a reference frame with which to understand the meaning of each element. In our button-string analogy, the quantity and labels of our buttons together determine how strings correspond to elements in the set.

Here is where we begin to arrive at the use case for artificial intelligence. Let’s take a look at the recursive “rule” we defined for the natural numbers: if a string (S) is attached by another string to the (+1) button, then we add a new string between (S) and (+1). Usually, we only have one string, (0)(+1), before applying this rule. However, as soon as we add a new button (B) and the string (B)(+1), we suddenly transfer all of the properties of the natural numbers to whatever concept we want (B) to represent.

In my opinion, this is mind-bendingly fascinating. It only takes one extra element, i.e. string, in our model to generalize the entire concept of countable numbers to a completely unrelated context. Furthermore, by increasing the complexity of the model, it becomes trivial to “cross-pollinate” concepts from otherwise completely unrelated domains. This is exactly what modern approaches to machine learning so badly need — an efficient abstract reasoning framework to complement modern data-oriented machine learning techniques.

If you would like to delve further into this idea, be sure to check out this Google Colab notebook, which explains “semantic polymorphism” in greater depth and covers many other examples using a tiny programming language.

Please share this article with your favorite technical (and/or artist) friends! This is a very new and subtle mathematical concept, so I hope that this article will reach at least one or two people who are intrigued enough to contribute their knowledge and ideas to this research frontier.

Thanks for reading. Cheers!

--

--

Ryan Vandersmith

Enthusiastic programming language designer and full-stack Progressive Web App developer.