2048 and algebra: Index

I’m doing something that I should have done a long time ago: collect past series of posts into a single, easy-to-reference post. The following posts formed my series on using algebra to study the 2048 game… with a special focus on reaching the event horizon of 2048 which cannot be surpassed.

2048-0Part 1: Introduction and statement of problem

Part 2: First insight: How points are accumulated in 2048

Part 3: Second insight: The sum of the tiles on the board

Part 4: Algebraic formulation of the two insights

Part 5: Algebraic formulation applied to a more complicated board

Part 6: Algebraic formulation applied to the event horizon of 2048

Part 7: Calculating one of the complicated sums in Part 6 using a finite geometric series

Part 8: Calculating another complicated sum in Part 6 using a finite geometric series

Part 9: Repeating Part 8 by reversing the order of summation in a double sum

Part 10: Estimating the probability of reaching the event horizon in game mode

 

 

 

 

2048 and algebra (Part 9)

In this series of posts, I consider how algebra can be used to answer a question about the 2048 game: From looking at a screenshot of the final board, can I figure out how many moves were needed to reach the final board? Can I calculate how many new 2-tiles and 4-tiles were introduced to the board throughout the course of this game? In this post, we consider the event horizon of 2048, which I reached after about four weeks of intermittent doodling:

2048-0

In yesterday’s post, we developed a system of two equations in two unknowns to solve for t and f, the number of 2-tiles and 4-tiles (respectively) that appeared throughout the course of the game:

2t + 4f = \displaystyle \sum_{n=2}^{17} 2^n.

2t + \displaystyle \sum_{n=1}^{15} n \cdot 2^{n+2} = 3,867,072

In this post and tomorrow’s post, I consider how the two sums in the above equations can be obtained without directly adding the terms.

In yesterday’s post, we used the formula for the sum of a finite geometric series to calculate the second sum:

\displaystyle \sum_{n=1}^{15} n \cdot 2^{n+2} = 14 \times 2^{18} + 2^3 = 3,670,024

In this post, I perform this calculation again, except symbolically and more compactly. The key initial steps are writing the series as a double sum and then interchanging the order of summation (much like reversing the order of integration in a double integral). This is a trick that I’ve used again and again in my own research efforts, but it seems that the students that I teach have never learned this trick. Here we go:

\displaystyle \sum_{n=1}^{15} n \cdot 2^{n+2} = \displaystyle \sum_{n=1}^{15} \sum_{k=1}^n 2^{n+2} = \displaystyle \sum_{k=1}^{15} \sum_{n=k}^{15} 2^{n+2}

The inner sum is a finite geometric series with 15-k+1 terms, common ratio of 2, and initial term 2^{k+2}. Therefore,

\displaystyle \sum_{n=1}^{15} n \cdot 2^{n+2} = \displaystyle \sum_{k=1}^{15} \frac{ 2^{k+2} \left(1 - 2^{15-k+1} \right) }{1 - 2}

= \displaystyle \sum_{k=1}^{15} \left(2^{18} - 2^{k+2} \right)

= \displaystyle \sum_{k=1}^{15} 2^{18} -\sum_{k=1}^{15} 2^{k+2}

 The first sum is merely the sum of a constant. The second sum is another finite geometric series with 15 terms, common ratio of 2, and initial term 2^3. So

\displaystyle \sum_{n=1}^{15} n \cdot 2^{n+2} = 15 \times 2^{18} - \displaystyle \frac{ 2^3 \left(1 - 2^{15} \right) }{1 - 2}

\displaystyle \sum_{n=1}^{15} n \cdot 2^{n+2} = 15 \times 2^{18} - \left( 2^{18} - 2^3 \right)

\displaystyle \sum_{n=1}^{15} n \cdot 2^{n+2} = 14 \times 2^{18} + 2^3

\displaystyle \sum_{n=1}^{15} n \cdot 2^{n+2} = 3,670,024

2048 and algebra (Part 8)

In this series of posts, I consider how algebra can be used to answer a question about the 2048 game: From looking at a screenshot of the final board, can I figure out how many moves were needed to reach the final board? Can I calculate how many new 2-tiles and 4-tiles were introduced to the board throughout the course of this game? In this post, we consider the event horizon of 2048, which I reached after about four weeks of intermittent doodling:

2048-0

In yesterday’s post, we developed a system of two equations in two unknowns to solve for t and f, the number of 2-tiles and 4-tiles (respectively) that appeared throughout the course of the game:

2t + 4f = \displaystyle \sum_{n=2}^{17} 2^n.

2t + \displaystyle \sum_{n=1}^{15} n \cdot 2^{n+2} = 3,867,072

In this post and tomorrow’s post, I consider how the two sums in the above equations can be obtained without directly adding the terms.

In yesterday’s post, we showed that the formula for the sum of a finite geometric series can be used to calculate the first sum:

\displaystyle \sum_{n=2}^{17} 2^n = \displaystyle \frac{4(1-2^{16})}{1-2} = 4(2^{15} - 1) = 262,140

Let’s now consider the second (and more complicated) sum, which can be written as

2^3 + 2 \cdot 2^4 + 3 \cdot 2^5 + \cdot + 15 \cdot 2^{17}

For reasons that will become clear shortly, this sum can be written in expanded form as

2^3

+ 2^4 + 2^4

+ 2^5 + 2^5 + 2^5

\vdots

+ 2^{17} + 2^{17} + 2^{17} + \dots + 2^{17}

 Let’s now rearrange the terms of this sum. We will do this by adding along the diagonals instead of along the rows. In this way, the above sum can be rearranged as

2^3 + 2^4 + 2^5 + \dots + 2^{17}

+ 2^4 + 2^5 + \dots + 2^{17}

+ 2^5 + \dots + 2^{17}

\vdots

+ 2^{17}

Each of these new rows (or the original diagonals) is a geometric series and can be calculated using the formula:

2^3 + 2^4 + 2^5 + \dots + 2^{17} = \displaystyle \frac{2^3 (1-2^{15})}{1-2} = 2^{18} - 2^3

2^4 + 2^5 + \dots + 2^{17} = \displaystyle \frac{2^4 (1-2^{14})}{1-2} = 2^{18} - 2^4

2^5 + \dots + 2^{17} = \displaystyle \frac{2^5 (1-2^{13})}{1-2} = 2^{18} - 2^5

\vdots

2^{17} = (2-1) \cdot 2^{17} = 2^{18} - 2^{17}

So, thus far in the calculation, we have established that

\displaystyle \sum_{n=1}^{15} n \cdot 2^{n+2} = \displaystyle \sum_{n=3}^{17} \left( 2^{18} - 2^n \right).

Simplifying,

\displaystyle \sum_{n=1}^{15} n \cdot 2^{n+2}=\displaystyle \sum_{n=3}^{17} 2^{18} - \sum_{n=3}^{17} 2^n

The first sum on the right is the sum of a constant being added to itself 15 times:

\displaystyle \sum_{n=3}^{17} 2^{18} = 15 \times 2^{18}

The second sum on the right is yet another geometric series. Indeed, it’s the same geometric  series from the first diagonal above:

\sum_{n=3}^{17} 2^n = \displaystyle \frac{2^3 (1-2^{15})}{1-2} = 2^{18} - 2^3

Therefore,

\displaystyle \sum_{n=1}^{15} n \cdot 2^{n+2} = 15 \times 2^{18} - \left(2^{18} - 2^3 \right)

\displaystyle \sum_{n=1}^{15} n \cdot 2^{n+2} = 14 \times 2^{18} + 2^3

\displaystyle \sum_{n=1}^{15} n \cdot 2^{n+2} = 3,670,024

Not surprisingly, this matches the sum that was found via direct addition.

2048 and algebra (Part 7)

In this series of posts, I consider how algebra can be used to answer a question about the 2048 game: From looking at a screenshot of the final board, can I figure out how many moves were needed to reach the final board? Can I calculate how many new 2-tiles and 4-tiles were introduced to the board throughout the course of this game? In this post, we consider the event horizon of 2048, which I reached after about four weeks of intermittent doodling:

2048-0

In yesterday’s post, we developed a system of two equations in two unknowns to solve for t and f, the number of 2-tiles and 4-tiles (respectively) that appeared throughout the course of the game:

2t + 4f = \displaystyle \sum_{n=2}^{17} 2^n.

2t + \displaystyle \sum_{n=1}^{15} n \cdot 2^{n+2} = 3,867,072

In this post and tomorrow’s post, I consider how the two sums in the above equations can be obtained without directly adding the terms.

The first sum is certainly the easiest to handle, as it requires the sum of a finite geometric series:

a + ar + ar^2 + \dots + a r^{n-1} = \displaystyle \sum_{i=1}^n a r^{i-1} = \displaystyle \frac{a(1-r^n)}{1-r}

For the geometric series

\displaystyle \sum_{n=2}^{17} 2^n,

there are 16 terms (after all, there are 16 tiles on the board). The first term is 4, and the common ratio is 2. Therefore,

\displaystyle \sum_{n=2}^{17} 2^n = \displaystyle \frac{4(1-2^{16})}{1-2}

\displaystyle \sum_{n=2}^{17} 2^n = 4(2^{15} - 1)

\displaystyle \sum_{n=2}^{17} 2^n = 262,140

We’ll consider the more complicated sum in tomorrow’s post.

 

Inverse Functions: Logarithms and Complex Numbers (Part 30)

Ordinarily, there are no great difficulties with logarithms as we’ve seen with the inverse trigonometric functions. That’s because the graph of y = a^x satisfies the horizontal line test for any 0 < a < 1 or a > 1. For example,

e^x = 5 \Longrightarrow x = \ln 5,

and we don’t have to worry about “other” solutions.

However, this goes out the window if we consider logarithms with complex numbers. Recall that the trigonometric form of a complex number z = a+bi is

z = r(\cos \theta + i \sin \theta) = r e^{i \theta}

where r = |z| = \sqrt{a^2 + b^2} and \tan \theta = b/a, with \theta in the appropriate quadrant. This is analogous to converting from rectangular coordinates to polar coordinates.

Over the past few posts, we developed the following theorem for computing e^z in the case that z is a complex number.

Definition. Let z = r e^{i \theta} be a complex number so that -\pi < \theta \le \theta. Then we define

\log z = \ln r + i \theta.

Of course, this looks like what the definition ought to be if one formally applies the Laws of Logarithms to r e^{i \theta}. However, this complex logarithm doesn’t always work the way you’d think it work. For example,

\log \left(e^{2 \pi i} \right) = \log (\cos 2\pi + i \sin 2\pi) = \log 1 = \ln 1 = 0 \ne 2\pi i.

This is analogous to another situation when an inverse function is defined using a restricted domain, like

\sqrt{ (-3)^2 } = \sqrt{9} = 3 \ne -3

or

\sin^{-1} (\sin \pi) = \sin^{-1} 0 = 0 \ne \pi.

The Laws of Logarithms also may not work when nonpositive numbers are used. For example,

\log \left[ (-1) \cdot (-1) \right] = \log 1 = 0,

but

\log(-1) + \log(-1) = \log \left( e^{\pi i} \right) + \log \left( e^{\pi i} \right) = \pi i + \pi i = 2\pi i.

green line

This material appeared in my previous series concerning calculators and complex numbers: https://meangreenmath.com/2014/07/09/calculators-and-complex-numbers-part-21/

 

 

 

Inverse Functions: Arcsecant (Part 29)

We now turn to a little-taught and perhaps controversial inverse function: arcsecant. As we’ve seen throughout this series, the domain of this inverse function must be chosen so that the graph of y = \sec x satisfies the horizontal line test. It turns out that the choice of domain has surprising consequences that are almost unforeseeable using only the tools of Precalculus.

The standard definition of y = \sec^{-1} x uses the interval [0,\pi] — or, more precisely, [0,\pi/2) \cup (\pi/2, \pi] to avoid the vertical asymptote at x = \pi/2 — in order to approximately match the range of \cos^{-1} x. However, when I was a student, I distinctly remember that my textbook chose [0,\pi/2) \cup [\pi,3\pi/2) as the range for \sec^{-1} x.

I believe that this definition has fallen out of favor today. However, for the purpose of today’s post, let’s just run with this definition and see what happens. This portion of the graph of y = \sec x is perhaps unorthodox, but it satisfies the horizontal line test so that the inverse function can be defined.

arcsec3

Let’s fast-forward a couple of semesters and use implicit differentiation (see also https://meangreenmath.com/2014/08/08/different-definitions-of-logarithm-part-8/ for how this same logic is used for other inverse functions) to find the derivative of y = \sec^{-1} x:

x = \sec y

\displaystyle \frac{d}{dx} (x) = \displaystyle \frac{d}{dx} (\sec y)

1 = \sec y \tan y \displaystyle \frac{dy}{dx}

\displaystyle \frac{1}{\sec y \tan y} = \displaystyle \frac{dy}{dx}

 At this point, the object is to convert the left-hand side to something involving only x. Clearly, we can replace \sec y with x. As it turns out, the replacement of \tan y is a lot simpler than we saw in yesterday’s post. Once again, we begin with one of the Pythagorean identities:

1 + \tan^2 y = \sec^2 y

\tan^2 y = \sec^2 y - 1

\tan^2 y = x^2 - 1

\tan y = \sqrt{x^2 - 1} \qquad \hbox{or} \tan y = -\sqrt{x^2 - 1}

So which is it, the positive answer or the negative answer? In yesterday’s post, the answer depended on whether x was positive or negative. However, with the current definition of \sec^{-1} x, we know for certain that the answer is the positive one! How can we be certain? The angle y must lie in either the interval [0,\pi/2) or else the interval [\pi,3\pi/2). In either interval, \tan y is positive. So, using this definition of \sec^{-1} x, we can simply say that

\displaystyle \frac{d}{dx} \sec^{-1} x = \displaystyle \frac{1}{x \sqrt{x^2-1}},

and we don’t have to worry about |x| that appeared in yesterday’s post.

green line

arcsec2Turning to integration, we now have the simple formula

\displaystyle \int \frac{dx}{x \sqrt{x^2 -1}} = \sec^{-1} x + C

that works whether x is positive or negative. For example, the orange area can now be calculated correctly:

\displaystyle \int_{-2}^{-2\sqrt{3}/3} \frac{dx}{x \sqrt{x^2 -1}} = \sec^{-1} \left( - \displaystyle \frac{2\sqrt{3}}{3} \right) - \sec^{-1} (-2)

= \displaystyle \frac{7\pi}{6} - \frac{4\pi}{3}

= \displaystyle -\frac{\pi}{6}

So, unlike yesterday’s post, this definition of \sec^{-1} x produces a simple integration formula.

green line

So why isn’t this the standard definition for \sec^{-1} x? I’m afraid the answer is simple: with this definition, the equation

\sec^{-1} x = \cos^{-1} \left( \displaystyle \frac{1}{x} \right)

is no longer correct if x < -1. Indeed, I distinctly remember thinking, back when I was a student taking trigonometry, that the definition of \sec^{-1} x seemed really odd, and it seemed to me that it would be better if it matched that of \cos^{-1} x. Of course, at that time in my mathematical development, it would have been almost hopeless to explain that the range [0,\pi/2) \cup [\pi,3\pi/2) had been chosen to simplify certain integrals from calculus.

So I suppose that The Powers That Be have decided that it’s more important for this identity to hold than to have a simple integration formula for \displaystyle \int \frac{dx}{x \sqrt{x^2 -1}}

Inverse Functions: Arcsecant (Part 28)

We now turn to a little-taught and perhaps controversial inverse function: arcsecant. As we’ve seen throughout this series, the domain of this inverse function must be chosen so that the graph of y = \sec x satisfies the horizontal line test. It turns out that the choice of domain has surprising consequences that are almost unforeseeable using only the tools of Precalculus.

The standard definition of y = \sec^{-1} x uses the interval [0,\pi], so that

\sec^{-1} x = \cos^{-1} \left( \displaystyle \frac{1}{x} \right)

Why would this be controversial? Yesterday, we saw that \tan x is both positive and negative on the interval [0,\pi], and so great care has to be used to calculate the integral:

\displaystyle \int \frac{dx}{x \sqrt{x^2 -1}}

Here’s another example: let’s use trigonometric substitution to calculate

\displaystyle \int_{-6}^{-3} \frac{ \sqrt{x^2-9} }{x} dx

The standard trick is to use the substitution x = 3 \sec \theta. With this substitution:

  • x^2 - 9 = 9 \sec^2 \theta - 9 = 9 \tan^2 \theta, and
  • dx = 3 \sec \theta \tan \theta \, d\theta
  • x = -3 \quad \Longrightarrow \quad \sec \theta = -1 \quad \Longrightarrow \quad \theta = \sec^{-1} (-1) = \pi
  • x = -6 \quad \Longrightarrow \quad \sec \theta = -2 \quad \Longrightarrow \quad \theta = \sec^{-1} (-2) = \displaystyle \frac{2\pi}{3}

Therefore,

\displaystyle \int_{-6}^{-3} \frac{ \sqrt{x^2-9} }{x} dx = \displaystyle \int_{2\pi/3}^{\pi} \frac{ \sqrt{9 \tan^2 \theta}} { 3 \sec \theta} 3 \sec \theta \tan \theta \, d\theta

At this point, the common mistake would be to replace \sqrt{9 \tan^2 \theta} with 3 \tan \theta. This is a mistake because

\sqrt{9 \tan^2 \theta} = |3 \tan \theta|

Furthermore, for this particular problem, \tan \theta is negative on the interval [2\pi/3,\pi]. Therefore, for this problem, we should replace \sqrt{9 \tan^2 \theta} with -3 \tan \theta.

Continuing the calculation,

\displaystyle \int_{-6}^{-3} \frac{ \sqrt{x^2-9} }{x} dx = \displaystyle \int_{2\pi/3}^{\pi} \frac{ -3 \tan \theta} { 3 \sec \theta} 3 \sec \theta \tan \theta

= \displaystyle \int_{2\pi/3}^{\pi} -3\tan^2 \theta \, d\theta

= \displaystyle \int_{2\pi/3}^{\pi} -3(\sec^2 \theta-1) \, d\theta

= \displaystyle \int_{2\pi/3}^{\pi} (3-3 \sec^2 \theta) \, d\theta

= \displaystyle \bigg[ 3 \theta - 3 \tan \theta \bigg]_{2\pi/3}^{\pi}

= \displaystyle \left[ 3 \pi - 3 \tan \pi \right] - \left[ 3 \left( \frac{2\pi}{3} \right) - 3 \tan \left( \frac{2\pi}{3} \right) \right]

= \displaystyle 3\pi - 0 - 2\pi + 3(-\sqrt{3})

= \pi - 3\sqrt{3}

So if great care wasn’t used to correctly simplify \sqrt{9 \tan^2 \theta}, one would instead obtain the incorrect answer 3\sqrt{3} - \pi.

Inverse Functions: Arcsecant (Part 27)

We now turn to a little-taught and perhaps controversial inverse function: arcsecant. As we’ve seen throughout this series, the domain of this inverse function must be chosen so that the graph of y = \sec x satisfies the horizontal line test. It turns out that the choice of domain has surprising consequences that are almost unforeseeable using only the tools of Precalculus.

The standard definition of y = \sec^{-1} x uses the interval [0,\pi], so that

\sec^{-1} x = \cos^{-1} \left( \displaystyle \frac{1}{x} \right)

Why would this be controversial? Let’s fast-forward a couple of semesters and use implicit differentiation (see also https://meangreenmath.com/2014/08/08/different-definitions-of-logarithm-part-8/ for how this same logic is used for other inverse functions) to find the derivative of y = \sec^{-1} x:

x = \sec y

\displaystyle \frac{d}{dx} (x) = \displaystyle \frac{d}{dx} (\sec y)

1 = \sec y \tan y \displaystyle \frac{dy}{dx}

\displaystyle \frac{1}{\sec y \tan y} = \displaystyle \frac{dy}{dx}

 At this point, the object is to convert the left-hand side to something involving only x. Clearly, we can replace \sec y with x. However, doing the same with \tan y is trickier. We begin with one of the Pythagorean identities:

1 + \tan^2 y = \sec^2 y

\tan^2 y = \sec^2 y - 1

\tan^2 y = x^2 - 1

\tan y = \sqrt{x^2 - 1} \qquad \hbox{or} \tan y = -\sqrt{x^2 - 1}

So which is it, the positive answer or the negative answer? The answer is, without additional information, we don’t know!

  • If 0 \le y < \pi/2 (so that x = \sec y \ge 1), then \tan y is positive, and so \tan y = \sqrt{\sec^2 y - 1}.
  • If \pi/2 < y \le \pi (so that x = \sec y \le 1), then \tan y is negative, and so \tan y = -\sqrt{\sec^2 y - 1}.

We therefore have two formulas for the derivative of y = \sec^{-1} x:

\displaystyle \frac{d}{dx} sec^{-1} x = \displaystyle \frac{1}{x \sqrt{x^2-1}} \qquad \hbox{if} \qquad x > 1

\displaystyle \frac{d}{dx} sec^{-1} x = \displaystyle -\frac{1}{x \sqrt{x^2-1}} \qquad \hbox{if} \qquad x < 1

These may then be combined into the single formula

\displaystyle \frac{d}{dx} sec^{-1} x = \displaystyle \frac{1}{|x| \sqrt{x^2-1}}

green lineIt gets better. Let’s now find the integral

\displaystyle \int \frac{dx}{x \sqrt{x^2 -1}}

arcsec2

Several calculus textbooks that I’ve seen will lazily give the answer

\displaystyle \int \frac{dx}{x \sqrt{x^2 -1}} = \sec^{-1} x + C

This answer works as long as x > 1, so that |x| reduces to simply x. For example, the red signed area in the above picture on the interval [2\sqrt{3}/3,2] may be correctly computed as

\displaystyle \int_{2\sqrt{3}/3}^2 \frac{dx}{x \sqrt{x^2 -1}} = \sec^{-1} 2 - \sec^{-1} \displaystyle \frac{2\sqrt{3}}{3}

= \cos^{-1} \left( \displaystyle \frac{1}{2} \right) - \cos^{-1} \left( \displaystyle \frac{\sqrt{3}}{2} \right)

= \displaystyle \frac{\pi}{3} - \frac{\pi}{6}

= \displaystyle \frac{\pi}{6}

However, the orange signed area on the interval [-2,-2\sqrt{3}/3]  is incorrectly computed using this formula!

\displaystyle \int_{-2}^{-2\sqrt{3}/3} \frac{dx}{x \sqrt{x^2 -1}} = \sec^{-1} \left( - \displaystyle \frac{2\sqrt{3}}{3} \right) - \sec^{-1} (-2)

= \cos^{-1} \left( -\displaystyle \frac{\sqrt{3}}{2} \right) -\cos^{-1} \left( \displaystyle \frac{1}{2} \right)

= \displaystyle \frac{5\pi}{6} - \frac{2\pi}{3}

= \displaystyle \frac{\pi}{6}

This is patently false, as the picture clearly indicates that the above integral has to be negative. For this reason, careful calculus textbooks will often ask students to solve a problem like

\displaystyle \int \frac{dx}{x \sqrt{x^2 -1}}, \qquad x > 1

and the caveat x > 1 is needed to ensure that the correct antiderivative is used. Indeed, a calculus textbook that doesn’t include such caveats are worthy of any scorn that an instructor cares to heap upon it.

Inverse Functions: Arcsecant (Part 26)

We now turn to a little-taught and perhaps controversial inverse function: arcsecant. As we’ve seen throughout this series, the domain of this inverse function must be chosen so that the graph of y = \sec x satisfies the horizontal line test. It turns out that the choice of domain has surprising consequences that are almost unforeseeable using only the tools of Precalculus.

The standard definition of y = \sec^{-1} x uses the interval [0,\pi] — or, more precisely, [0,\pi/2) \cup (\pi/2, \pi] to avoid the vertical asymptote at x = \pi/2. This portion of the graph of y = \sec x satisfies the horizontal line test and, conveniently, matches almost perfectly the domain of y = \cos^{-1} x. This is perhaps not surprising since, when both are defined, \cos x and \sec x are reciprocals.

arcsec1

 

Since this range of \sec^{-1} x matches that of \cos^{-1} x, we have the convenient identity

\sec^{-1} x = \cos^{-1} \left( \displaystyle \frac{1}{x} \right)

To see why this works, let’s examine the right triangle below. Notice that

\cos \theta = \displaystyle \frac{x}{1} \qquad \Longrightarrow \qquad \theta = \cos^{-1} x.

Also,

\sec\theta = \displaystyle \frac{1}{x} \qquad \Longrightarrow \qquad \theta = \cos^{-1} \left( \displaystyle \frac{1}{x} \right).

This argument provides the justification for 0 < \theta < \pi/2 — that is, for x > 1 — but it still works for x = 1 and x \le -1.

So this seems like the most natural definition in the world for \sec^{-1} x. Unfortunately, there are consequences for this choice in calculus, as we’ll see in tomorrow’s post.

Inverse Functions: Arctangent and Angle Between Two Lines (Part 25)

The smallest angle between the non-perpendicular lines y = m_1 x + b_1 and y = m_1 x + b_2 can be found using the formula

\theta = \displaystyle \tan^{-1} \left( \left| \frac{m_1 - m_2}{1 + m_1 m_2} \right| \right).

A generation ago, this formula used to be taught in a typical Precalculus class (or, as it was called back then, analytical geometry). However, I find that analytic geometry has fallen out of favor in modern Precalculus courses.

Why does this formula work? Consider the graphs of y = m_1 x and y = m_1 x + b_1, and let’s measure the angle that the line makes with the positive x-axis.

dotproduct5The lines y = m_1 x + b_1 and y = m_1 x are parallel, and the x-axis is a transversal intersecting these two parallel lines. Therefore, the angles that both lines make with the positive x-axis are congruent. In other words, the + b_1 is entirely superfluous to finding the angle \theta_1. The important thing that matters is the slope of the line, not where the line intersects the y-axis.

The point (1, m_1) lies on the line y = m_1 x, which also passes through the origin. By definition of tangent, \tan \theta_1 can be found by dividing the y- and x-coordinates:

\tan \theta_1 = \displaystyle \frac{m}{1} = m_1.

green linedotproduct6

 

We now turn to the problem of finding the angle between two lines. As noted above, the y-intercepts do not matter, and so we only need to find the smallest angle between the lines y = m_1 x and y = m_2 x.

The angle \theta will either be equal to \theta_1 - \theta_2 or \theta_2 - \theta_1, depending on the values of m_1 and m_2. Let’s now compute both \tan (\theta_1 - \theta_2) and \tan (\theta_2 - \theta_1) using the formula for the difference of two angles:

\tan (\theta_1 - \theta_2) = \displaystyle \frac{\tan \theta_1 - \tan \theta_2}{1 + \tan \theta_1 \tan \theta_2}

\tan (\theta_2 - \theta_1) = \displaystyle \frac{\tan \theta_2 - \tan \theta_1}{1 + \tan \theta_2 \tan \theta_1}

Since the smallest angle \theta must lie between 0 and \pi/2, the value of \tan \theta must be positive (or undefined if \theta = \pi/2… for now, we’ll ignore this special case). Therefore, whichever of the above two lines holds, it must be that

\tan \theta = \displaystyle \left| \frac{\tan \theta_1 - \tan \theta_2}{1 + \tan \theta_1 \tan \theta_2} \right|

We now use the fact that m_1 = \tan \theta_1 and m_2 = \tan \theta_2:

\tan \theta = \displaystyle \left| \frac{m_1 - m_2}{1 + m_1 m_2} \right|

\theta = \tan^{-1} \left( \displaystyle \left| \frac{m_1 - m_2}{1 + m_1 m_2} \right| \right)

green line

The above formula only applies to non-perpendicular lines. However, the perpendicular case may be remembered as almost a special case of the above formula. After all, \tan \theta is undefined at \theta = \pi/2 = 90^\circ, and the right hand side is also undefined if 1 + m_1 m_2 = 0. This matches the theorem that the two lines are perpendicular if and only if m_1 m_2 = -1, or that the slopes of the two lines are negative reciprocals.