Skip to main content
Mental Models

Reverse Engineering

Reverse engineering works backward from an observed output to possible inputs or causes. Algebra illustrates the difficulty: computing a result can be straightforward, while recovering what produced it may require a different method and yield more than one answer.

THE IDEA

REVERSE ENGINEERING, OR, WHY ALGEBRA IS HARD

There are two moments in the course of education where a lot of kids fall off the math train. The first comes in the elementary grades, when fractions are introduced. Until that moment, a number is a natural number, one of the figures 0, 1, 2, 3 . . . It is the answer to a question of the form "how many."[*] To go from this notion, so primitive that many animals are said to understand it, to the radically broader idea that a number can mean "what portion of," is a drastic philosophical shift. ("God made the natural numbers," the nineteenth-century algebraist Leopold Kronecker famously said, "and all the rest is the work of man.")

The second dangerous twist in the track is algebra. Why is it so hard? Because until algebra shows up, you're doing numerical computations in a straightforwardly algorithmic way. You dump some numbers into the addition box, or the multiplication box, or even, in traditionally minded schools, the long-division box, you turn the crank, and you report what comes out the other side.

Algebra is different. It's computation backward. When you're asked to solve

x + 8 = 15

you know what came out of the addition box (namely, 15) and you're being asked to reverse-engineer what, along with the 8, went in.

In this case, as your seventh-grade math teacher no doubt once told you, you can flip things over to get things right-side round again:

x = 15 - 8

at which point you can just toss 15 and 8 in the subtraction box (making sure now to keep track of which one you toss first . . .) and find that x must be 7.

But it's not always so easy. You might need to solve a quadratic equation, like

x^2 - x = 1.

Really? (I hear you cry.) Might you? Other than that your teacher asked you to, why would you?

Consider the missile example from Ellenberg’s chapter 2:

Maybe you know that the missile launched from 100 meters above ground level, with upward velocity of 200 meters per second. If there was no such thing as gravity, the missile would just keep on rising along a straight line in accordance with Newton's laws, getting 200 meters higher each second, and its height after x seconds would be described by the linear function

height = 100 + 200x.

But there is such a thing as gravity, which bends the arc and forces the missile to curve back toward earth. It turns out that the effect of gravity is described by adding a quadratic term:

height = 100 + 200x - 5x^2

where the quadratic term is negative just because gravity pushes missiles down, not up.

There are a lot of questions you might ask about a missile heading toward you, but one of particularly great import is: When will it land? To answer this is just to answer the question: When will the height of the missile be zero? That is, for what value of x is it the case that

100 + 200x - 5x^2 = 0?

It is by no means clear how you're supposed to "flip" this equation around and solve for x. But maybe you don't have to. Trial and error is a very powerful weapon. If you plug x = 10 into the above formula, to see how high the missile is after 10 seconds, you get 1,600 meters. Plug in x = 20 and you get 2,100 meters, so it looks like the missile may still be rising. When x = 30, you get 1,600 again: promising; we must be past the peak. At x = 40 the missile is once again just 100 meters above the ground. We could walk forward 10 more seconds, but when we're so close to impact already that's surely overdoing it. If you plug in x = 41 you get -105 meters, which doesn't mean you're predicting the missile has actually begun burrowing under the earth's surface, but rather that impact has already happened, so that your nice, clean model of the missile's motion is, as we say in ballistics, no longer operative.

So if 41 seconds is too long, what about 40.5? That gives -1.25 meters, just a little bit below 0. Turn back the clock a little to 40.4, and you get 19.2m, so impact hasn't happened yet. 40.49? Very close, just 0.8m above the ground. . . .

You can see that by playing the trial and error game, carefully turning the time knob back and forth, you can approximate the time of impact as closely as you like.

But have we "solved" the equation? You're probably hesitant to say you have—after all, even if you keep fine-tuning your guesses until you get the time of impact pinned down to

40.4939015319 . . .

seconds after launch, you don't know the answer, but just an approximation of the answer. In practice, though, it doesn't help you to time the impact to the millionth of a second, does it? Probably just saying "about 40 seconds" is enough. Try to generate an answer any more precise than that and you're wasting your time, and you'll probably be wrong, besides, because our very simple model of the missile's progress fails to take into account many other factors, like air resistance, the variation in air resistance coming from weather, the spin of the missile itself, and so on. These effects may be small, but they're surely big enough to keep you from knowing down to the microsecond when the projectile will show up for its appointment with the ground.

If you want a satisfyingly exact solution, never fear—the quadratic formula is here to help. You may well have memorized this formula once in your life, but unless you have an unusually gifted memory or you are twelve, you don't have it in mind just at the moment. So here it is: if x is a solution to

c + bx + ax^2 = 0

where a, b, and c are coefficients and a is nonzero, then

x = (-b ± sqrt(b^2 - 4ac)) / (2a)

In the case of the missile, c = 100, b = 200, and a = -5. So what the quadratic formula has to say about x is that

x = (-200 ± sqrt(200^2 - 4*(-5)100)) / (2(-5))

Most of the symbols in there are things you could type in your calculator, but there's one funny outlier, the ±. It looks like a plus sign and a minus sign that love each other very much, and this isn't so far off. It indicates that, although we started our mathematical sentence, all confidence, with

x =

we end up in a state of ambivalence. The ±, something like a blank Scrabble tile, can be read as either a + or a -, as we choose. Each choice we make produces a value of x that makes the equation 100 + 200x - 5x^2 = 0 hold. There is no single solution to this equation. There are two.

That there are two values of x which satisfy the equation can be made apparent to the eye, even if you long ago forgot the quadratic formula. You can draw a graph of the equation y = 100 + 200x - 5x^2 and get a nice upside-down parabola. The horizontal line is the x-axis, those points on the plane whose y-coordinate is 0. When the curve y = 100 + 200x - 5x^2 meets the x-axis, it must be the case both that y is 100 + 200x - 5x^2 and that y = 0; so 100 + 200x - 5x^2 = 0, precisely the equation we were trying to solve, now given geometric form as a question about the intersection between a curve and a horizontal line.

And geometric intuition demands that if such a parabola noses its way above the x-axis at all, it must strike the x-axis in exactly two places, no more, no fewer. In other words, there are two values of x such that 100 + 200x - 5x^2 = 0.

So what are these two values?

After simplifying the formula, one root is

x = 20 + 2√105

which is 40.4939015319 . . . , the same answer we came up with by trial and error. The other root is

x = 20 - 2√105

which is -0.4939015319 . . .

As an answer to our original question, this is somewhat nonsensical. The answer to "When is that missile going to hit me?" can't be "Half a second ago."

Yet this negative value of x is a perfectly good solution to the equation, and when math tells us something we should at least try to listen. What does the negative number mean? Here's one way to understand it. We said the missile was launched from 100 meters off the ground, at a velocity of 200 meters per second. But all we really used was that, at time 0, the missile was traveling upward at that velocity from that position. What if that wasn't actually the launch? Maybe the launch took place not at time 0, from 100 meters up, but at some earlier time, directly from the ground. What time?

The computation tells us there are exactly two times when the missile is at ground level. One time is 0.4939 . . . seconds ago. That would be the launch time if the same model applied before the initial observation. The other time is 40.4939 . . . seconds from now. That’s when the model predicts the missile lands.

Perhaps it doesn't seem so troubling, especially if you're used to the quadratic formula, to get two answers to the same question. But when you're twelve it represents a real philosophical shift. You've spent six long years in grade school figuring out what the answer is, and now, suddenly, there is no such thing.

And those are just quadratic equations! What if you have to solve

x^3 + 2x^2 - 11x = 12?

This is a cubic equation, which is to say it involves x raised to the third power. Fortunately, there is a cubic formula that allows you to figure out, by a direct computation, what values of x could have gone in the box to make 12 fall out when you turn the crank. But you didn't learn the cubic formula in school, and the reason you didn't learn it in school is that it's kind of a mess, and wasn't worked out until the late Renaissance, when itinerant algebraists roamed across Italy, engaging one another in fierce public equation-solving battles with money and status on the line. The few people who knew the cubic formula kept it to themselves or wrote it down in cryptic rhymed verse.

Long story. The point is, reverse engineering is hard.

Inference poses the same kind of difficulty. When we are scientists, or Torah scholars, or toddlers gaping at the clouds, we are presented with observations and asked to build theories—what went into the box to produce the world that we see? Inference is a hard thing, maybe the hardest thing. From the shape of the clouds and the way they move we struggle to go backward, to solve for x, the system that made them.

When to use it

  • Debugging software by tracing errors back to their root cause.

  • Analyzing a historical event by working backward from known outcomes to identify contributing factors.

  • Reverse engineering a product to understand its design and manufacturing process.

  • Solving a mystery by deducing the sequence of events from physical evidence.

FROM THEORY TO EVERYDAY LIFE

In practice

01

Solving a Quadratic Equation for Missile Impact

Given the equation height = 100 + 200x - 5x^2, we want to find when the missile hits the ground (height=0). Using trial and error, we approximate the impact time. The quadratic formula gives exact solutions: x=20 ± 2√105, yielding about 40.5 seconds for impact and -0.5 seconds for the earlier ground crossing if the same model is extended backward.

✳

A MOMENT TO REFLECT

Put it to work.

  1. How can reverse engineering be applied to understand a complex system you interact with daily?

  2. What are the potential pitfalls of relying solely on trial and error for reverse engineering?

  3. In what ways is scientific inference similar to solving an algebraic equation?

Connected ideas

Another lens can bring the same problem into focus.

Often confused with

CONTINUE THE CONVERSATION

Source texts

  • How Not to Be Wrong The Power of Mathematical Thinking (Ellenberg, Jordan)
← More mental models