# Stacking property

This is an interactive short essay. I noticed an interesting stacking property of elements on a grid. I made some computer simulations to explore their behavior, followed by a discussion on interactive thinking tools.

Consider the following grid:

o o oxo o o oyo o o o o o o o o o o

Let’s assume that:

- The grid has a constant width of
*n*elements, - The elements flow left-to-right, top-to-bottom,
- New elements are added from the top left.

Web designers will recognize the classic grid where new items are added at the start of the list. Now here’s what I find interesting: ** x will stay on top of y whenever we add a new item**. In fact, all vertical stacking is conserved.

Here’s the grid after we add *z*:

zo o oxo o o oyo o o o o o o o o o o

Next we add *1*:

1zo o oxo o o oyo o o o o o o o o o o

Notice how *x* is still on top of *y*. And I bet that *1*, *x* and *y* will remain vertically aligned as well. I find this remarkable! I noticed this behavior while I was adding new items on my homepage. I don’t have a proof for this, nor do I know of which general structure is this a property. This smells very mathy, and a generalization most certainly exists.

I’ll intentionally keep my naive perspective and explore this behavior with computer simulations.

## Experiment 1

Let’s start with a grid of 5 x 10 elements, and color some of them black to display the letter *A*. What happens if we add a new element to the grid every given time?

Interesting! The letter *A* seems to move on an infinite Pacman-like grid while retaining its shape. Click “show” to see the new elements being added in grey. Note that previous elements get pushed out of the grid at the bottom.

## Experiment 2

Now, could we move the shape *A* smoothly from top to bottom to get a scrolling effect? We could think of a shifting mechanism that would compensate for the lateral scrolling of the shape. But that would require additional logic to our setup. A simpler idea would be to play on the number of new elements we add at each step. Let’s try adding 5 new elements at each tick:

There’s the scrolling effect! Notice that 5 is the width of the grid. We are effectively adding a new line at each step, which neatly shifts the shape the way we want.

But that is obvious. Yet, there is something intriguing that’s still puzzling me about the stability of the grid. What is it?

## Experiment 3

Let’s unwrap the grid. Press “Unwrap” to lay out all elements over one contiguous line, then run experiments 1 & 2 on one dimension:

Oh! With this visual setup, we can see that:

- The only difference between experiment 1 and 2 is how fast the pattern is shifting.
- Once unwrapped, the stability of the pattern becomes obvious: two elements that are 2 tiles apart will stay 2 tiles apart no matter how many or how fast we add new elements.

I think this is what I find intriguing: when we move from a one dimensional line to a two dimensional grid, we can compose phenomenologically richer shapes, while still logically operating on a one dimensional infinite line.

## Playground

We can try various behaviors on the grid below. Select a preset, or click any cell to toggle its color:

The grid is 14*14 elements, and we can specify the following:

**Amount**: how many elements are added to the grid in total**Increment**: how many elements are added at each step**Interval**: the time lapse between each step**Show added elements**: display new elements with a different color

The algorithm runs until the total amount of elements is added, then it removes all the added elements and goes back to the starting position.

Press “Play” to run. Press “Stop” to go back to the starting position. Press “Clear” to clear the grid.

## Discussion

There are 2 aspects that these experiments make me think about.

**1. Mathematics**. While observing the spatial behavior of elements on a grid, I can see what keeps a mathematician awake: there is a mechanical necessity in the relations between the elements that begs to be resolved. We can feel that the behavior is not random, and that there must be a logical point of view from which the phenomenological results can be derived (phenomenologically means “how things appear”).

**2. Thinking tools**. Up until this point, I still don’t know which mathematical framework generalizes and captures the behavior I saw in the simulations. I wrote an algorithm and I ran a computer program with various parameters, which was fun, tedious (any programming is), and thought-provoking. But I still lack a deeper understanding of what is happening. This argument is developed by Evan Miller in a piece called Don’t Kill Math

, in which he criticizes an article written by Bret Victor called Kill Math

.

Evan Miller’s argument develops in two steps: 1) Bret Victor argues that mathematical writing and analytical symbolism are phenomenologically a poor medium, and therefore the richness of mathematical structures is reserved for a subset of population who have a weird knack for arcane notations. Bret Victor suggests that interactive computer simulations give a better discoverability and intuition of such structures. 2) Evan Miller then argues that computer simulations do not provide the deeper understanding that analytical forms do, because analytical forms distill the behavior into a pure and generalized form that tell us why and when such behavior is possible.

And indeed, playing with the simulations above is not enough to understand the system. Further creative thinking is required.

What would have a mathematician done? Maybe they would have setup different configurations to inform their own thinking, and guide them toward an analytical understanding of the system. A capable mathematician would do that, informed by a considerable knowledge and hooks that they have learned from experience.

What did I do with these computer simulations? I tried to make interesting animated sequences, because that’s what I love. My process was similar to what people do in computer graphics or in the demoscene world, where ingenious or serendipitous algorithms produce remarkable results. Even though we could compress a behavior into abstract logical rules, it doesn’t, in my view, capture nor describe the phenomenological experience we have of it. The latter is ultimately what matters the most to me.

The computer quite naturally turns the math back into phenomena. — Alan Kay

A lot of the value of computer simulations is in the setup. This setup is called the user interface. It includes the programming language, the environment it runs on, and how the output is displayed. The user interface both directs and mirrors the user’s thinking. We can go anywhere with computer simulations: we can use them to inform analytical thinking, to visualize an established body of knowledge, to produce an artistic result, or some combination of all of the above.

## Links:

- Mathematics Stack Exchange answer, 2017. I asked on Stack Exchange and emailed Evan Miller about which mathematical framework is most suited for my interrogations. Modular arithmetic seems to be the best formalization of the behavior studied above.
- Modular arithmetics, Wikipedia.
**Bret Victor**, Kill Math, 2011.**Evan Miller**, Don’t Kill Math, 2012.**Alan Kay’s quote**is from Our Human Condition “From Space” (PDF), Viewpoints Research Institute, 2003.**Michael Nielsen**, Toward an exploratory medium for mathematics, 2016.