The number of digits of n!: 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 computing the number of digits in n!.

Part 1: Introduction – my own childhood explorations.

Part 2: Why a power-law fit is inappropriate.

Part 3: The correct answer, using Stirling’s formula.

Part 4: An elementary derivation of the first three significant terms of Stirling’s formula.

Schoolhouse Rock and Calculus

After presenting the Fundamental Theorem of Calculus to my calculus students, I make a point of doing the following example in class:

\displaystyle \int_0^4 \frac{1}{4} x^2 \, dx

Hopefully my students are able to produce the correct answer:

\displaystyle \int_0^4 \frac{1}{4} x^2 \, dx = \displaystyle \left[ \frac{x^3}{12} \right]^4_0

= \displaystyle \frac{(4)^3}{12} - \frac{(0)^3}{12}

= \displaystyle \frac{64}{12}

= \displaystyle \frac{16}{3}

Then I tell my students that they’ve probably known the solution of this one since they were kids… and I show them the classic video “Unpack Your Adjectives” from Schoolhouse Rock. They’ll watch this video with no small amount of confusion (“How is this possibly connected to calculus?”)… until I reach the 1:15 mark of the video below, when I’ll pause and discuss this children’s cartoon. This never fails to get an enthusiastic response from my students.

If you have no idea what I’m talking about, be sure to watch the first 75 seconds of the video below. I think you’ll be amused.

Two ways of doing an integral: Index

I’m using the Twelve Days of Christmas (and perhaps a few extra days besides) to do 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 different ways of computing the integral \displaystyle \int \frac{dx}{\sqrt{4x-x^2}}.

Part 1: The two “different” answers.

Part 2: Explaining why the two “different” answers are really equivalent.

 

 

 

Day One of My Calculus Class: Index

I’m using the Twelve Days of Christmas (and perhaps a few extra days besides) to do 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 what I teach my students on the first day of calculus in order to start the transition from Precalculus and to get them engaged for what we’ll be doing throughout the semester.

Part 1: The two themes of calculus: Approximating curved things by straight things and passing to limits.

Part 2: Using the distance-rate-time formula to estimate how fast an accelerating object lands when dropped from a tall building.

Part 3: Passing to limits to precisely calculate the above velocity.

Part 4: Using rectangles to estimate the area under a parabola.

Part 5: Passing to limits to precisely calculate the area under a parabola.

Part 6: Final comments: these two questions apparently have nothing to do with each other, but are in fact highly interrelated. The connection between these two topics, the Fundamental Theorem of Calculus, is one of greatest discoveries in the history of mankind, which my students are now privileged to understand at the ripe old age of 18 or 19 years old.

 

 

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.

Different definitions of e (Part 11): Numerical computation

In this series of posts, we have seen that the number e can be thought about in three different ways.

1. e defines a region of area 1 under the hyperbola y = 1/x.logarea2. We have the limits

e = \displaystyle \lim_{h \to 0} (1+h)^{1/h} = \displaystyle \lim_{n \to \infty} \left(1 + \frac{1}{n} \right)^n.

These limits form the logical basis for the continuous compound interest formula.

3. We have also shown that \frac{d}{dx} \left(e^x \right) = e^x. From this derivative, the Taylor series expansion for e^x about x = 0 can be computed:

e^x = \displaystyle \sum_{n=0}^\infty \frac{x^n}{n!}

Therefore, we can let x = 1 to find e:

e = \displaystyle \sum_{n=0}^\infty \frac{1}{n!} = \displaystyle 1 + 1 + \frac{1}{2} + \frac{1}{6} + \frac{1}{24} + \dots

green line

Let’s now consider how the decimal expansion of e might be obtained from these three different methods.

1. Finding e using only the original definition is a genuine pain in the neck. The only way to approximate e is by trapping the value of e using various approximation. For example, consider the picture below, showing the curve y = 1/x and trapezoidal approximations on the intervals [1,1.8] and [1.8,2.6]. (Because I need a good picture, I used Mathematica and not Microsoft Paint.)

approx_e_lower

Each trapezoid has a (horizontal) height of h = 0.8. Furthermore, the bases of the first trapezoids have length \displaystyle \frac{1}{1} = 1 and \displaystyle \frac{1}{1.8}, while the bases of the second trapezoid of length \displaystyle \frac{1}{1.8} and \displaystyle \frac{1}{2.6}. Notice that the trapezoids extend above the hyperbola, so that

\displaystyle \int_1^{2.6} \frac{dx}{x} < \displaystyle \frac{0.8}{2} \left( 1 + \frac{1}{1.8} \right) + \frac{0.8}{2} \left( \frac{1}{1.8} + \frac{1}{2.6} \right)

\displaystyle \int_1^{2.6} \frac{dx}{x} < 0.9983 < 1

However, the number e is defined to be the place where the area under the curve is exactly equal to 1, and so

\displaystyle \int_1^{2.6} \frac{dx}{x} < \displaystyle \int_1^{e} \frac{dx}{x}

In other words, we know that the area between 1 and 2.6 is strictly less than 1, and therefore a number larger than 2.6 must be needed to obtain an area equal to 1.

Great, so e > 2.6. Can we do better? Sadly, with two equal-sized trapezoids, we can’t do much better. If the height of the trapezoids was h and not 0.8, then the sum of the areas of the two trapezoids would be

\displaystyle \frac{h}{2} \left( 1 + \frac{2}{1+h} + \frac{1}{1+2h} \right)

By either guessing and checking — or with the help of Mathematica — it can be determined that this function of h is equal to 1 at approximately h \approx 0.8019, thus establishing that e > 1 + 2h \approx 2.6039.

e_twotrapezoids

We can try to better with additional trapezoids. With four trapezoids, we can establish that e > 2.6845.

e_fourtrapezoids

With 100 trapezoids, we can show that e > 2.71822.

e_hundredtrapezoidsHowever, trapezoids can only provide a lower bound on e because the original trapezoids all extend over the hyperbola.

green lineTo obtain an upper bound on e, we will use a lower Riemann sum to approximate the area under the curve. For example, notice the following picture of 19 rectangles of width h = 0.1 ranging from x =1 to x = 2.9.

approx_e_upperThe rectangles all lie below the hyperbola. The width of each one is h = 0.1, and the heights vary from \frac{1}{1.1} to \frac{1}{2.9}. Therefore,

\displaystyle \int_1^{2.9} \frac{dx}{x} > \displaystyle 0.1 \left( \frac{1}{1.1}+ \frac{1}{1.2} + \dots + \frac{1}{2.9} \right)

\displaystyle \int_1^{2.9} \frac{dx}{x} > 1.0326 > 1

In other words, we know that the area between 1 and 2.9 is strictly greater than 1, and therefore a number smaller than 2.9 must be needed to obtain an area equal to 1. So, in a nutshell, we’ve shown that e < 2.9.

Once again, additional rectangles can provide better and better upper bounds on e. However, since rectangles do not approximate the hyperbola as well as trapezoids, we expect the convergence to be much slower. For example, with 100 rectangles of width h, the sum of the areas of the rectangles would be

h \displaystyle \left( \frac{1}{1+h} + \frac{1}{1+2h} + \dots + \frac{1}{1+100h} \right)

It then becomes necessary to plug in numbers for h until we find something that’s decently close to 1 yet greater than 1. Or we can have Mathematica do the work for us:

e_hundredrectanglesSo with 100 rectangles, we can establish that e < 2.7333. With 1000 rectangles, we can establish that e < 2.71977.

Clearly, this is a lot of work for approximating e. With all of the work shown in this post, we have shown that e = 2.71\dots, but we’re not yet sure if the next digit is 8 or 9.

In the next post, we’ll explore the other two ways of thinking about the number e as well as their computational tractability.

The one problem I missed, 30 years ago, on my final exam in calculus

It’s been said that we often remember our failures more than our successes. In this instance, the adage rings true, because I can still remember, clear as a bell, the one problem that I got wrong on my high school calculus final that I took 30 years ago. Here it is:

\displaystyle \int (x^2+1)^2 dx

I tried every u-substitution under the sun, with no luck. I tried u = x^2+1. However, du would be equal to 2x \, dx, and there was no extra x in the integrand.

I believe I tried every crazy, unorthodox u-substitution possible given the time constraints of the exam: u = \sqrt{x}, u = \sqrt{x^2+1}, u = 1/x. Nothing worked.

We had learned trigonometric substitutions in my class, and so I also tried those. I started with x = \tan u, so that x^2 + 1 = \tan^2 x + 1 = \sec^2 x. This looked promising. However, dx = \sec^2 u \, du, so the integral became \displaystyle \int \sec^4 u \, du. From there, I was stuck. (Now that I’m older, I know that the logical train actually goes in the reverse direction than what I attempted as a student.)

I wasn’t taught integration by parts in this first course in calculus, so I didn’t even know to try it. Had I known this technique, I probably would’ve broken through my conceptual barrier to finally get the right answer. (In other words, integration by parts will yield the correct answer, but it’s a lot of work!) But I didn’t know about it then, and so I get to tell the story now.

Exasperated, I turned in my exam when time was called, and I asked my teacher how this integral was supposed to be solved.

Easy, she told me: just square out the inside:

\displaystyle \int (x^2+1)^2 dx = \displaystyle \int (x^4 + 2x^2 + 1) \, dx = \displaystyle \frac{x^5}{5} + \frac{2x^3}{3} + x + C

At the time, I was unbelievably annoyed at myself. Now, I love telling this anecdote to my students as I relate to their own frustrations as they practice the art of integration.