Saturday, September 26, 2009

Forgetful Loops

Consider a software algorithm that builds a tree in a computer program. Typically when you build a tree you would have a recursive loop in which tree nodes are created and connected. The loop will have an entry and an exit point.



You might also recycle the same tree builder algorithm to build a parallel tree, an almost identical tree with only its target context being different. For example tree1 is supposed to be an observer of explorer style representation, whereas tree2 observes a column based representation. So the nodes of each tree might have a different type, their properties are determined and their behavior are dictated by the context they live in.



Let us now assume that we are living in a universe UR.

One way of comprehending our universe is thinking of it as a gigantic Hilbert Space. A vector-space that represents the state-spaces of quantum mechanical systems is also a Hilbert Space.

Think about every atomic particle that makes you, they have a certain position and momentum at any given time, i.e. they can be represented as vectors. And when I say 'at any given time' I mean the time of our vector space. Together with other quantum mechanical systems, such as the coffee mug, the earth, the sun, the milky way galaxy and so on, we are all part of one big vector space.

Another way of visualizing our universe is thinking it as a space-time sheet or fabric, on which every vector stays on the same fabric, moving in random directions and changing their magnitude all the time.

Returning back to our tree building problem, there is no reason why you would not build parallel trees by running the tree-builder algorithm sequentially, so you build the tree1 first followed by the tree2 and so forth.

After all our program runs in the realm of our universe, in the same space-time fabric. So the loops building these trees would occupy different localities on our universe's space-time since they are built at different times, nevertheless they lie on the same sheet of space-time.

Suppose now that there is a glitch in your program so that while executing the first loop to build tree1, the program suddenly switches its context, enters into the second loop and starts building tree2.



You may be surprised to find that when the program finishes building the second tree, and returns control to the loop of tree1, instead of the iteration continues where it left, it might leave the loop prematurely with tree1 left incomplete.

Suppose also that the glitch causing your program to suddenly leave the first loop at the first place is not avoidable. This also implies that your trees are NOT built sequentially contrary to your intention (design).

The only way to fix this software problem is to SAVE the loop's iterator prior to leaving the first loop, and RESTORE it back when the control is returned prior to the loop iterator is incremented.

The loop needs memory of where it left prior to making the jerky switch, otherwise it fails to restore itself.

This is a remarkably common pattern in mathematics, theoretical physics and literature no matter how speculative its representation might turn out to be.  Think about wormholes, multiverses, Alice's Adventures in Wonderland, The Magician's Nephew, and The Lion the Witch and the Wardrobe.

The loop is like consciousness. Suddenly leaving the realm of loop1 is like entering into a shortcut, a wormhole and finding yourself in the realm of loop2, a different consciousness in a different universe.

However there is one crucial difference. In literature we are biased to think that the heroes maintain their consciousness. They remember other realms when they return. This gives the audience a comforting cozy feeling.

I tend to think though there seems no need to remember your previous conscious presence in one realm or the other. All you need is a functioning anchor when you return. You might pretty much succeed as a forgetful loop provided that your anchor works.

2 comments:

Bob MacNeal said...

"All you need is a functioning anchor when you return." Could be. It's fun to think about. The hand-drawings are quite nice.

Ergun Çoruh said...

Thanks Bob. Incidentally I had a real problem at work that looked like this, a complex recursive loop which took a sudden shortcut, and we fixed it by save/restore iterator trick. Then I couldn't help but inspired :)