Chapter eleven
There is a specific shape of anxious thinking that the previous chapter did not quite catch, and that I want to give a chapter to on its own, because it is, in my honest estimation, the single most exhausting thing the human mind can do to itself.
The shape goes like this. You start with a small concrete worry. Call it the seed. The seed is, on its own, a perfectly reasonable thing to think about. I have not heard back from my friend in three days. Your mind, as minds do, reaches for the next thought. The next thought is, but what if she is upset with me? This is also, on its own, a reasonable thought. You can imagine answering it. You could ask her. You could wait. You could let it go. Many futures are available.
The trouble is that your mind, in this particular mode, does not pause at the second thought to answer it. It generates a third thought immediately. But what if she is upset with me about that thing I said last Tuesday? Now there is a third question on the table, and the third question has not been answered either. Your mind generates a fourth thought, derived from the unanswered third. But what if she has been thinking about it all week, and it has gotten worse in her head, the way these things do? The fifth thought arrives before the fourth has been examined. But what if she has decided, by this point, that I am not the kind of person she wants to be friends with at all? The sixth. But what if she has been telling other friends, and now they are starting to think the same thing? The seventh. But what if my entire social world is, right now, quietly recalibrating its opinion of me without my knowledge?
You are, at this point, in a state of considerable distress, and you have moved, in seven thoughts, from a friend not having texted you back to a comprehensive social catastrophe. None of the seven thoughts has been resolved. Each of them is, in a strict technical sense, still open. Your mind is holding all of them at once, each one a half-finished sub-problem waiting for an answer that will never arrive, because the answer to each one requires you to first resolve the next one, which requires you to first resolve the one after that.
This is, in the most precise possible sense, a stack overflow. The thing your brain is doing has a name in computer science, and the name is unflatteringly accurate, and the name comes with a body of literature that will, by the end of this chapter, give you a slightly better way of holding it.
Let me explain what the stack is, because the word is doing real technical work and the metaphor will repay being made literal.
When a program calls a function, the computer has to remember where it was, so that when the function finishes, the program can pick up exactly where it left off. The place where it remembers is called the call stack. It is, structurally, exactly what it sounds like: a stack, in the sense of a pile of plates, where the most recent thing is on top, and you cannot get to anything below the top until you have removed everything above it. Each function call adds a plate to the top. Each function return removes one. The stack grows when you go deeper. The stack shrinks when you come back up.
If the function calls itself, this is called recursion, and it is, in computer science, one of the most elegant ideas humans have come up with. A function that knows how to solve a small instance of a problem can, by calling itself, solve a slightly larger instance, by reducing the larger to the smaller. The classic example, taught in every textbook, is the factorial function. To compute n!, you compute n × (n-1)!, where (n-1)! is computed by the same function, recursively, with a smaller argument. Eventually the argument reaches 1, at which point the function returns 1 without recursing further, and the whole stack of pending multiplications unwinds, each one returning its result to the call below it, until the original call has its answer.
This works because of one specific, load-bearing feature, which is called a base case. The base case is the condition under which the function does not recurse. It is the point at which the function says, I have a direct answer to this small version of the problem, so I do not need to call myself again. The base case is the floor. The base case is what stops the recursion from going forever.
If you remove the base case, you have a function that calls itself, forever, with no exit. Each call adds a new plate to the stack. The stack grows. The stack grows. The stack grows. Eventually the system has allocated all the memory it has for tracking function calls, and the program crashes with the specific, melodramatic error message stack overflow. The program was not wrong. The program was, in every individual step, doing exactly what it was told. The program simply forgot to ever stop, and the consequence of forgetting to stop is that the system runs out of room to remember how it got here.
The picture is worth drawing.
Figure 11.1 The stack of unfinished worries, each one calling the next. The seed at the bottom is small and concrete. By the top, the worries have nothing to do with the seed at all.
Notice what the figure is showing. The seed, at the bottom, is a perfectly ordinary observation about the world. She has not texted me back. The second frame is still in some sense about her. The third frame is still in some sense about her, though now it has wandered to last Tuesday. By the seventh frame, the conversation is no longer about her at all. The conversation is about whether the speaker is loveable. The original concrete observation has been replaced, through six recursive steps, by an abstract metaphysical worry about the speaker's own worth, and the speaker has, somewhere along the way, stopped noticing that this happened.
This is the fundamental property of stack overflow as a model of anxious thought. Each recursive call moves the conversation slightly further from the seed. The function does not call itself with the same argument. The function calls itself with a more abstract argument, a more general argument, an argument that subsumes the original and inflates it. The argument grows. The stack grows. The system, eventually, has nowhere left to put new frames, and the entire process freezes in a kind of stuck overwhelm that you, on a Wednesday evening at nine o'clock, would describe in plain English as I cannot think about this anymore, and I also cannot stop.
Here is a piece of code that demonstrates the failure, because seeing it overflow in Python is, I have found, oddly liberating.
def what_if(worry, depth=0):
"""
Take a worry. Generate the next worry, one level more
abstract. Then worry about that. Recursively.
No base case. This is the bug.
"""
print(f"{' ' * depth * 2}depth {depth}: {worry}")
# Generate the next, slightly more catastrophic worry.
next_worry = "but what if " + escalate(worry)
# Recurse, with no condition under which we stop.
return what_if(next_worry, depth + 1)
def escalate(worry):
"""
Make the worry slightly more general. Slightly more
abstract. Slightly more about who you are, rather than
what is happening.
"""
# In real life this function is implemented by the
# anxious brain, which is alarmingly good at it.
return worry.replace("this thing", "everything").replace(
"today", "always")
try:
what_if("she has not texted me back today")
except RecursionError as e:
print(f"\n--- stack overflow at depth ~{1000} ---")
print("the brain has run out of room to hold any more"
" what-ifs, and the entire system is now frozen,"
" unable to think but also unable to stop.")
print("this is the moment you stare at the wall.")
The Python interpreter will, on a typical system, allow this function to recurse approximately one thousand times before it raises a RecursionError and halts. The human brain, having no such safety mechanism, will keep going. It will not crash with a polite Python exception. It will continue allocating new mental frames for new what-ifs until something else, usually exhaustion or sleep, eventually drops the stack. The brain that finally falls asleep at three in the morning has not solved any of the what-ifs. The brain has simply lost consciousness while still holding them open. They will, in many cases, be there waiting in the morning, on top of the stack, ready to be resumed.
Now I want to turn to the fix, because the chapter would be cruel without one.
The fix, in computer science, is the base case. The base case is the condition under which the function does not recurse. The trick of writing recursive functions is, in fact, almost entirely the trick of writing the right base case. The recursion itself is the easy part. The hard part is knowing when to stop.
The anxious mind, in its what if cascades, has no base case. There is no condition under which it says I have now thought about this enough, I am done, the function returns. The function just keeps calling itself, with arguments that get steadily more abstract and more catastrophic. The fix is not to think faster. The fix is not to think harder. The fix is to install a base case.
The base case for human worry, in my experience, is one of a small number of stopping conditions. I have asked the actual question to the actual person. I have written down the worry in one sentence. The worry has become more abstract than the seed, which is a sign that the recursion has left the seed behind. I have taken one concrete action that responds to the worry, even if the action is small. Any of these can be a base case. The point of the base case is not that it resolves the worry. The point of the base case is that it gives the function permission to return.
The most useful base case, in my experience, is the third one. The worry has become more abstract than the seed. When you notice that you started with she has not texted me back and you have ended up at I am the kind of person nobody wants to be friends with, the gap between the seed and the current frame is the diagnostic. The current frame is no longer about the seed. The current frame is doing something else. You are, in technical terms, no longer running the original computation. You are running a computation that is decoupled from its inputs, and the responsible move is to return, and start over, with the original question only.
This is, I want to suggest, what good therapists do. The therapist's role, in the moment of an active cascade, is not to answer any individual what if. The therapist's role is to gently insist that the conversation return to the seed. Wait. Let us go back to the beginning. You said she has not texted you back. What is actually true about that? The therapist is, in computer science terms, popping all the abstract frames off the stack and returning the conversation to the only frame that contains an actual question with an actual answer. The therapist is supplying, from outside the function, the base case that the function did not have.
If you do not have a therapist available, you can be your own. The act of writing down, on paper, the original seed, in one sentence, with no what if attached, is one of the most powerful base-case interventions available. It forces the function to return to the bottom of the stack and start over with only the original argument. The towers of recursive elaboration collapse. The question is once again the question. Whatever answer the question has, in the world, will at least now be on the same axis as the question.
I want to make one observation about why the anxious mind is so prone to recursion without a base case, because the observation is not flattering but it is, I think, important.
The anxious mind, particularly in childhood, learned that the world contained dangers it could not see in advance. Real dangers, in many cases. The mind responded by developing the habit of looking around corners. Looking around the corner is, in computer science terms, exactly the what if operation. You take a current situation, you generate a hypothetical alternative, you examine the alternative for threats. This is a useful operation. Performed once, it is the foundation of foresight. Performed twice, it is prudent. Performed three times, it is good planning.
Performed, however, with no base case, it is the engine that generates a stack overflow on a Wednesday evening over a friend who has not texted back. The same mechanism that, in childhood, kept you safe from real threats is now, in adulthood, running unbounded on small social ambiguities, and the same mechanism that does not know when to stop is the mechanism that has, in your earlier life, sometimes kept you alive.
I want to say this clearly, because it matters. The recursion is not a failure of you. The recursion is a feature that has, in your case, lost its base case somewhere along the way. The function was given to you, by evolution and by experience, with the base case implicitly there. The base case said, more or less, stop when you have generated enough hypotheticals to be safe. In some childhoods, the condition safe never reliably arrived, so the base case never triggered, so the function never learned where to stop. The adult inherits a function that recurses without limit. The adult has to learn, deliberately, to install a base case that the original training did not provide.
The base case is not, in this sense, a denial of the legitimate caution. The base case is the maturity that says: I have looked around enough corners. I am now in adult life, where most of the corners are empty. I am permitted to stop looking around them at some point. I am permitted to return from the recursive call, with whatever partial answer I have, and to live with the answer rather than continue to refine it.
A small exercise
Find the seed.
The next time you catch yourself in a what if cascade, do not try to answer any of the what ifs. The answers are not where the exit is. The exit is at the bottom of the stack.
Find a piece of paper. Write down the seed. The actual, original, concrete observation that started the cascade. She has not texted me back. The meeting was rescheduled. I noticed my boss looked tired. The bill is higher than I expected. Whatever it actually was. Write it in one sentence. Use no abstract nouns. Use no what if.
Then read the sentence. Notice that the sentence is, on its own, small. Notice that you have, in the last hour, been thinking about something that is much larger than this sentence, and that this sentence is the only piece of the situation that is, in fact, in the world.
Then ask: what is the smallest possible response to this sentence? Send the text. Ask the question. Pay the bill. Take the small action that the seed actually calls for. The action will not resolve the cascade. But the action will give the function its base case, and the recursive elaboration, denied its fuel, will, with surprising speed, begin to subside.
Chapter 12 returns to the founder from Chapter 2, and to the question of why the man who could not let his designers do their work was running, in technical terms, a greedy algorithm: a procedure that makes the locally optimal choice at every step and ends up, with mathematical reliability, at a globally catastrophic destination. The chapter will introduce dynamic programming, which is the official mathematical fix for greedy algorithms, and which is, in my honest opinion, one of the most beautiful pieces of computer science a person can learn at any age.
For now, the page closes here. The stack has a base case. The base case is the seed. The seed is the only frame that contains an answerable question. The function is, with patience, allowed to return.