A Finite State Dance Machine

To cover a lot of ground in dance class, focus on the number of dance moves explored rather than the distance travelled. In dance, I think of the distance between two positions in terms of the number of moves I make rather than my displacement. A complicated sequence of steps is conceptually longer than a basic promenade that travels the same physical distance. A dance can look like a single chain of moves where each chainlink is a specific action, but what you’re really witnessing is a path through a network of all possible moves for a chosen dance style. The structure of dance starts to take shape when we model dance as a finite state machine.

At first, dance looked like a continuous blur of motion, but, over time, I learned to discretize the blur into individual moves. As my vocabulary of dance moves grew, so did my ability to recognize the words of a kinaesthetic poem. The challenge of dancing is not merely knowing the moves, but understanding how to string them together elegantly. The difficultly of this task had not dawned on me until I reflected on one of the most valuable dance tutorials I’ve ever attended.

It was a quiet Friday evening at the University of Waterloo when I attended one of the UW Breaker’s style development workshops. Most students had left campus for the weekend, but the breakers had gathered for a workshop before the weekly dance session. Today’s lesson? How to keep it fresh.

In hip-hop, being fresh means having novel moves and style. Freshness is respected on the dance floor because it’s a show of skill and creativity. To keep one’s dance looking fresh, the guest teacher gave us seemingly simple advice: “always know three ways in and three ways out”. For any given position, you should know three ways to get into and out of said position. As we randomly picked positions and played with this rule, we soon realized it wasn’t easy to come up with new moves. We spent the entirety of the class inventing, drilling, and discussing ways to transition between positions. As the tiring practise session drew to a close, we sat down and reflected.

During the reflection, one of my classmates mentioned that dance looked like a jigsaw puzzle to him. Not all pieces fit together, but there were particular pieces that just clicked together. For him, there was a particular sense of accomplishment in “solving a dance”. As I grappled with this mode of thinking, the puzzle I visualized faintly resembled some planar graph diagrams I’ve seen in a graph theory course. That’s when it hit me: dancing can be thought of as a graph.

six_step_fsm

In a dance graph, nodes represent individual moves and the edges represent the transitions between them. Typical nodes are positions and named moves that can be distinctly identified. Edges are movements you make to get to another node. Edges are bidirectional only if you can transition back to the previous position using the same action, but this property is not guaranteed. Some edges are one-way because they cannot be done in reverse. For example, one cannot reverse knee drop because of the power required to overcome gravity on the way up. You must find another edge to transition back to a standing position. A dance can be thought of as a traversal of this graph where the resulting path is the performance you witness. 

There appear to be an infinite number of nodes to visit, but, in practise, dancers only work with the subset defined by their school of dance. Within the context of a dance style, there are exists a finite set of valid moves. Membership in this set is sometimes strictly defined like for specific styles in International Standard Ballroom, whereas umbrella categories like hip-hop can contain many sub-styles that are all loosely related by family resemblance. When a dance move happens out of context, like doing a Charleston during a waltz, the invalid move looks very out of place. Without exploring dance taxonomy, we will assume that boundaries exist and that they outline the finite set of moves we want to examine. By narrowing down the universe of valid states a dancer can be in, it makes it feasible to model a dance as a finite state machine.

The topology of a dance graph is shaped by physical constraints and stylistic rules. Some dance nodes form clusters because they’re physically easy to transition between. For example, toprock and floorwork are two large clusters that naturally form in breakdancing because of the energy required to transition between standing and ground positions. Certain dances styles, like ballet, have foundational positions that act as central nodes in the graph. There can also be relatively sparse graphs like in Foxtrot where the style dictates a specific sequence of moves to perform. Each dance style has a unique graph, but so does every dancer trained in the same style.

Dances are unique on a personal level. Though moves are heavily shaped by teachers and peers, dancers must ultimately adapt the dance into movements that best fit their body composition. Height, musculature, centre of gravity, and many additional factors affect how dancers go about executing moves. It is through a combination of external influences and bodily factors that a personal style is created. A personal dance graph encompasses the moves one knows and the sequences one is likely to perform.

Mapping out your dance graph is helpful for introspection into your style. The shape of the graph can tell you a lot about how one dances and areas to focus on. If you notice your dance graph has several poorly connect clusters, you can focus on learning moves to bridge these clusters together. You can also figure out how many steps it takes to reach your signature move from anywhere in the graph. For example, I can traverse the path below, catalog my moves, and then experiment with different shortcuts between these moves. This knowledge is especially useful when your school of dance prizes novelty.

In breakdancing, originality is highly valued. If you are caught copying someone else’s moves, your opponent will call you out with the biting gesture. Accusations of plagiarism are injurious to one’s standing in battle and are thus taken very seriously. Furthermore, if you repeat moves within the same battle, opponents will use the counting fingers gesture to signal how many times they’ve seen you repeat said move. Not only should you not plagiarize other people, but copying yourself makes you unoriginal. With this context in mind, the dance graph framework becomes particularly useful for generating unique paths.

To keep it fresh, mathematically speaking, dancers need to keep traversing unique paths in their dance graph. You can increase the number of unique paths by learning new moves, but a more effective approach is to learn additional transitions between moves you already know. The rationale behind the three ways in and out rule is that it makes your existing graph more connected. Nodes get more edges connecting to other nodes that also receive more edges. If you strictly obey the three ways in and out rule, Menger’s theorem states that you should be able to dance three unique paths between two arbitrary nodes in your graph. I suspect that dance graphs also have some interesting planarity and colouring properties, but I will leave that experimentation as exercise for the reader. The most important exercise for you to complete, though, is to pick positions you know and apply the three ways in and out rule.

three_ways

As you challenge yourself to find three ways in and out of positions, you will realize that it also helps with style development. When you run out of moves to satisfy the challenge, you start to invent your own moves. This is how your personal style develops. The benefits extend beyond just knowing new moves. Over time, you start to develop hunches about how to find the next puzzle piece. Your approach to making new moves is an integral part of a unique style. However, this advice has limited use for other schools of dance which may have more rigid stylistic rules.

Not all dance genres are as freeform as hip-hop. Some dances dictate specific move sequences to perform. The nature of the dance is reflected in the interesting shapes their graphs take. Through my brief exposure to other styles, I would like to speculate on what some other dance graphs might look like.

If you are a dancer, I would like to see what your dance graphs look like!

As with any abstraction, modelling dance as a finite state machine is reductive. There is much nuance that this model does not capture. For example, it makes no distinction between a move that is performed with an aggressive style and the same move performed in a tight, controlled style. Some forms might not even be describable using a graphical model. One could introduce additional properties, but I will save such complexity for another post.

Dancing is a creative endeavour whose beauty is not just visual, but structural. The structure of your dance is undoubtedly shaped by the move graph you are exploring so it’s important to curate it. As the possibility space of all viable moves collapses into a single timeline, you may notice that some paths are more worn than others. To keep things fresh, try to explore the lesser known paths or, better yet, forge new ones. There is a lot of novelty hiding between the ideas you have not yet connected.

It’s Juggling Time

If you lead a busy life, you should learn how to juggle. The physical activity is great for stress relief, but I also mean juggling in the sense of multitasking. Knowing how to efficiently allocate time between tasks is a valuable skill to have. We juggle jobs, tasks, family, and friends as if they were tangible things that we could throw and catch. Though just a figure of speech, delving into juggling as metaphor reveals some interesting ways to think about concurrent tasks.

Juggling, like music, is steeped in patterns that can be described using math. From siteswap to temporal logic, there are many ways to think about juggling patterns. One of the more obscure descriptions I wanted to explore is Shannon’s juggling theorem. I was first introduced to this formula when it was offhandedly mentioned during a weekly juggling session at the UW Juggling Club. The equation is as follows:

(F + D) H = (V + D) B

where

F = Flight time of a ball

D = Dwell time that a ball spends in a hand

V = Vacant time that a hand spends empty

B = Number of balls

H = Number of hands

Formulated by Claude Shannon, this equation describes how the collective time of the balls relates to the collective time of the hands. If we examine one juggling cycle (i.e. one iteration where every ball passes through each hand) and trace through said cycle from the hand and the ball perspective, we can derive the equation. Without the insight to watch just a ball or just a hand, it’s hard to decipher the relationship from merely watching someone juggle.

JugglingLoop
3 Ball Cascade

I could never fully grasp the equation by juggling until I started to imagine the time values as coloured bars of varying length. To show you what I see, I’ve coded up a visualizer to illustrate the timing of all the juggling events happening in the clip above.

3BallCascade

The diagram consists of three ball timelines and two hand timelines.

We can observe that the ball has two states: in a hand and in the air. On a ball timeline, the time a ball spends in a hand (D) is coloured and the time the ball is in the air (F) is left blank. As for the hands, we can observe that it also has two states: holding a ball and empty. When the hand is holding a ball (D), the timeline is coloured using the colour of the ball being held. The rest of the hand timeline is blank (V) meaning the hand is empty.

With this diagram, we can start to play around with the timing relationships. In one cycle, we can see that a ball is thrown and caught once by each hand (i.e. “(F + D) H” meaning a ball trip happens H times) and a hand throws and catches each ball once (i.e. “(V + D) B” meaning a hand trip happens B times). The coloured area in all the ball timelines is equivalent to the coloured area in all the hand timelines because the time a ball spends in a hand is the same as the time a hand spends holding a ball. As we play with this equation, we can see how various aspects of the juggling pattern are temporally related.

3BallCascadeLongFlight

If we start throwing the balls higher, the coloured portions of the ball timeline will proportionally shrink as the ball spends more time in the air and, consequently, the hands will spend more time empty.

5BallCascade

If we add two more balls, we will see flight times increase because the balls will be thrown higher. On the other hand, there will be less vacant time as the juggler gets busy trying to accommodate the new balls.

This is a neat observation that does not have any practical value, but it is an interesting way to think about juggling. Coincidentally, I learned about Shannon’s juggling theorem around the same time I was attending lectures on concurrent programming. I developed a hunch that juggling and concurrency were related, but didn’t explore the relationship much. It wasn’t until a few semesters later that I was reminded of the topic during a lecture on computer systems performance analysis. The arithmetic used in the lecture felt somewhat similar to the juggling formula so I decided to revisit it.

Let’s reframe the equation I described in terms of computation.

3ThreadCascade

Let’s say there are three threads and two processors.

For simplicity, we can observe that the thread has two states: processing and suspended. On a thread timeline, the time a thread spends in a processor is coloured in and the time a thread is suspended is left blank.

As for the processors, we can observe that it also has two states: processing and idle. When it is processing a thread, I have coloured in the timeline using the colour of the thread it identifies. The rest of the processor timeline is blank meaning the processor is not processing a thread.

The coloured area of all the thread timelines is equivalent to the coloured area of all the processor timelines because the time a thread spends in execution is the same as the time a processor spends processing it.

The concepts map onto this problem domain nicely. You could also apply the math on other scenarios involving two interacting parties. Let’s say there is a group of patients at a hospital that need to go through a fixed set of medical examinations. If you reframe patients as balls and examination rooms as hands, you can start to apply the same intuition to it. However, the equation wouldn’t exactly work in this case because of some assumptions we have made.

Shannon’s Juggling Theorem is a succinct equation because it is meant to describe a cascade pattern where every ball cycles through each hand. It assumes that there is at most one ball in a hand at any given time. The equation does not account for multiplexing where multiple balls are thrown and caught at the same time. Additionally, if we changed the pattern so that some balls are thrown higher than others, then the ball trips would not have a uniform length. Simply multiplying by the number of trips would instead become a sum of all the trip times. Even though the equation requires throws of equal height (i.e. round-robin scheduling) to work, the intuition behind it still holds in the case there balls are thrown different heights.

Hypothetical31Timeline

You could generalize this intuition to any two sided system where each side has a set amount of time interacting and not interacting. This works because of double-counting  the set of time from each perspective and equating the two sides. It makes sense when you start manipulating the variables at the aggregate level. For example, if you add more patients to the hospital scenario above while holding the number of examination rooms the same, you will increase the aggregate wait time of the patients. This increase is especially apparent if you view the system from patients’ perspective.

My takeaway from Shannon’s insight is to think in the other perspective. Given what you know about your side of the equation, you might be able to imagine what it’s like on the other side of the system. Whether you’re figuring out multitasking with processors or multitasking with daily life, I recommend thinking not just in terms of the juggler, but also the juggled. Think not only of your schedule, but that of others. Hopefully, this perspective will help you navigate the juggling patterns of life. After all, life is a juggling act.

Additional Reading:

The Science Of Juggling
Peter J. Beek and Arthur Lewbel in Scientific American, Vol. 18, Issue 4, pages 92-97; November 1995.

The Operational Analysis of Queueing Network Models
Peter J. Denning and Jeffrey P. Buzen in ACM Computing Surveys, Vol. 10, Issue 3, pages 225-261; September 1978.