# iterated algorithms: over and over and over

Recently, my mind has been in a bit of a disarray.

A large part of it is because I'm at this precipice in my life where lots of changes are happening very quickly. My family and I just moved into a new house after living in the same apartment for ten years. I'm going to head off to college in the fall, 500 miles away from my twin sister, and I've never been apart from her for more than a couple days. My brother's moving in July for his new job. And there's just the general instability that comes with depression, plus my natural discomfort with big changes. (I think everyone is a little afraid of big changes. Humans are rather complacent creatures in that way).

Whenever I'm feeling so disarrayed, I like to fall back on science.

I'm sure some of you don't see science and math as very comforting hahaha. For me, science and math are concrete and stable; they're distanced enough from emotion that I can use them to process my feelings in a sort of calm and rational manner—which is what I'm going to attempt to do in this post. I'm keeping the science and math jargon very simple, but if I'm being honest, the ideas I'm presenting here are very intuitive, so I don't think anyone will have any trouble following along. I realize that it *might* be a bit boring for people who aren't as STEM-oriented, so I've included some really pretty gifs and images to entertain you

In my English class this year, I read a fantastic play by Tom Stoppard called *Arcadia.* *Arcadia* is about... *many* things, but one of the topics it discusses is iterated algorithms.

I think the phrase "iterated algorithm" is another example of Scientists Making Things Sound Unnecessarily Complicated, so I'll break it down. The word "algorithm" has been convoluted so much by Scientists Making Things Sound Unncessarily Complicated; we've forgotten how to define it in simplistic terms because our view is completely clouded by computer scientists going insane with all sorts of crazy formulas. In very simple terms, an algorithm is just a series of step—a procedure. Generally algorithms are supposed to solve problems, but I have a sort of algorithm for procrastinating on homework, so that's certainly not always the case The word "iterated" is probably much more familiar to everyone. In conjunction, an iterated algorithm is just a series of steps that continuously repeats, or a cycle, where what you get out, you put back in.

Here's a very simple example of an iterated algorithm, written in functional notation:

f_{n+1 }= f_{n} + f_{n-1}, n > 2, f_{0} = 0, f_{1} = 1

That's an example of Mathematicians Making Things Look Unnecessary Complicated. All that notation means is that in the sequence, every term is the sum of the two terms before it. (I probably could've just written that, but I really love functional notation. That's a post for another day, though.)

If you're unfamiliar with the sequence, it goes like this:

f_{0} = 0

f_{1} = 1

f2 = 1

f3 = 2

f4 = 3

The sequence should be coming together now—if you've never seen it before, this sequence is called the Fibonacci Sequence, and it's a pretty famous seqeunce. If you plot it, it sort of looks like this:

Remarkably, this pattern is found *everywhere *in nature: in the spiral of a sunflower, in the petals of a rose, in the shape of the Milky Way, in your face—the list goes on! (Sidenote: this (Youtube, so M) is a really cool video describing how to find Fibonacci spirals in pinecones!)

If you ever needed proof that science is magical, you don't need to look further than the Fibonacci sequence. I find there's some beauty in the fact that all these different objects in nature can be united by a sequence—a very simple sequence too, if you recall the functional notation. That's kind of amazing—and really comforting, that amidst all the complexity and mess in my life, there's something that can be as simple and beautiful as the Fibonacci sequence.

But the Fibonacci sequence is just one example of an iterated algorithm. There's *so many* others, and I'd just like to highlight a few others (with more pretty pictures!).

There's this misconception that math can't be beautiful (bah!) and I'm here to forever dispel that idea. My evidence: fractals!

if you don't know what a fractal is, here's an example:

(Let's be honest—you cannot objectively say that that isn't absolutely beautiful.)

Fractals are geometric curves that are "self-similar" across all scales, which means that if you were to zoom into that image, you'd see the same pattern. That means that it's cyclical, a never-ending pattern—which means that fractals are created by iterated algorithms. Each iteration of the algorithm plots a new point, and with enough points, you get a pretty image. The below gif demonstrates this with a fractal called the Koch snowflake. The gif demonstrates how to draw it, but the simple algorithm is this: you draw an equilateral triangle. Then, on each side, draw another, smaller equiltateral triangle, with the side of the original as its base. Then repeat with each new equilateral triangle. With enough iterations, you'll get something that resembles a snowflake! (You should try drawing it, it's super easy and requires no artistic talent whatsoever!)

In the center of the first fractal image is one of my favorite fractals; it's called the Mandelbrot set. I'm always a little amused when I see it because it sort of resembles a snowman with little baby hands, heh. The gif below demonstrates the "self-similar" aspect of the Mandlebrot set:

The equation for the Mandelbrot set is the following:

z_{n+1} = z_{n}^{2} + C, where z_{0} = C and C is the number of points in the complex plane for which the orbit of z_{n+1} does not tend to infinity

Erm.... yeah, I would try to translate that, but I don't fully understand it myself. It's rather complex (haha, math pun!). But the beauty of iterated algorithms is that the exact equation doesn't *really* matter. The process for drawing it is still the same. You take an x-value, plug it into the equation, and then plot the y-value. Then you take your y-value and set that as your new x-value, and repeat the process on and on. All that changes is the equation in the middle—it can be as simple as the equation for the Fibonacci sequence, or as complicated as the above equation for the Mandelbrot set. The below gif demonstrates how the Mandelbrot set is created:

With enough iterations, the image of the Mandelbrot set becomes clearer and clearer—just like with the Koch snowflake, demonstrating that this process really is universal.

The thing about the Mandelbrot set, and the Koch snowflake, is that there's a limitation to how many iterations you can go through by hand. If you tried to draw out the Koch snowflake, you'd quickly run into a space problem that would thus limit the number of iterations that you can do. The Mandelbrot set has a similar complexity problem; it didn't become clearly defined until the 1950s, when computers started taking off and suddenly humans had much more power in their hands.

Sometimes, this idea is really frustrating to me. Iterated algorithms are supposed to be never-ending—they are supposed to be inherently limitless. But that's all *theoretically.* Nothing bears out in practice what it promises incipiently—there's always factors beyond our control. As a scientist, this is unbearingly frustrating; can you imagine running an experiment *knowing* that there were factors you couldn't control that could possibly invalidate all of your findings? As a *human, *this is unbearingly frustrating. I've always struggled to come to term with the fact that free will is, honestly, a bit of an illusion; *anything* could happen anytime, and even if I don't meet my untimely demise in the next week, there's always the ominous promise of an inescapable death. There's always that thought in the back of my head that there just isn't enough time—which makes all the changes I'm experiencing at the moment all the more terrifying.

It's okay, though—iterated algorithms are slowly helping me to come to terms with the spontaneity and disorder of life and how much is generally beyond my control.

Think of it this way: beyond the realm of STEM, what other processes emulate iterated algorithms?

I started to think about this and was amazed by the number of things I could think of. In *Arcadia,* the final scene features a waltz between the characters—the waltz is a perfect example of an iterated algorithm. You start off where you end, and continue, seamlessly, gracefully. On a larger scope, isn't history a sort of an iterated algorithm? After all, history repeats itself. This phrase is often used as negatively, as a warning. "Great, the Nazis are back again—history really does repeat itself." But I think that there's some sort of comfort to be found in this idea, too, that things that are lost are bound to turn up again because history repeats itself. There might not be enough time in *my* life, but everything I discover and learn and experience will be picked up by future generations, and the search for meaning will continue.

This also means that change isn't final—because you can always retrace the algorithm. Everything I've lost isn't actually lost; it's just hiding somewhere in the algorithm. This gives me comfort as a means of fighting the impermanence of life.

So, I guess, that begs the question of what to do now, in my life at this exact moment, where so many things are spiraling and so many uncontrollable forces are acting on me.

I think that all that's left to do is keep on iterating. Keep drawing, and keep looking for the larger pattern, the beauty in what I'm creating—and keep trusting that a greater pattern will indeed emerge.

I didn't mean to get so nihilistic at the end and I think this post also spiraled out of control at some point. This is my near-midnight brain talking now, haha. I hope some of this was entertaining/interesting/hopefully also comforting to any of you, and would love to hear your thoughts. Do you know of any other iterated algorithms? (Remember: broaden your mind. They're *everywhere.*) Do you have general advice for dealing with lots of monumental changes happening very quickly? Does anyone else find comfort like this in math and science, or am I just weird? Did you like the pretty pictures?!

(...okay, I'm shutting up now. Thanks for reading. <3)

- 4