Showing posts with label LaTeX. Show all posts
Showing posts with label LaTeX. Show all posts

Tuesday, 20 January 2026

Newton's Approximation For Pi

I watched an interesting YouTube video about how Newton approximated \( \pi \) and I thought it would be an interesting exercise to get Gemini to access the video and recreate the steps outlined. Once Gemini had created its response, I then got it to create a HTML version of the information for easy pasting into Blogger. Here is what it came up with and it's really quite impressive:

Based on the video provided, specifically the section starting around [00:06:50], here is the step-by-step derivation of Newton’s approximation of $\pi$.

Newton's method combines two different ways of calculating the area of a specific portion of a circle: using calculus (integration of an infinite series) and geometry. By equating these two results, he solved for $\pi$.

Step 1: The Equation of the Circle

Newton started with the equation of a unit circle centered at the origin:

$$x^2 + y^2 = 1$$

Solving for $y$ gives the function for the upper semicircle:

$$y = \sqrt{1 - x^2} = (1 - x^2)^{\frac{1}{2}}$$

Newton wanted to find the area under this curve from $x = 0$ to $x = \frac{1}{2}$. This can be expressed as the definite integral:

$$\text{Area} = \int_{0}^{\frac{1}{2}} (1 - x^2)^{\frac{1}{2}} \, dx$$

Step 2: Binomial Expansion

Since calculus was in its infancy, Newton applied his generalized binomial theorem to expand $(1 - x^2)^{\frac{1}{2}}$ into an infinite series. The general form for $(1+u)^n$ is:

$$(1+u)^n = 1 + nu + \frac{n(n-1)}{2!}u^2 + \frac{n(n-1)(n-2)}{3!}u^3 + \dots$$

By substituting $u = -x^2$ and $n = \frac{1}{2}$, he derived the series for the circle's equation:

$$(1 - x^2)^{\frac{1}{2}} = 1 - \frac{1}{2}x^2 - \frac{1}{8}x^4 - \frac{1}{16}x^6 - \frac{5}{128}x^8 - \dots$$

Step 3: Term-by-Term Integration

Newton then found the area (fluxion) by integrating the series term by term:

$$\int \left( 1 - \frac{1}{2}x^2 - \frac{1}{8}x^4 - \frac{1}{16}x^6 - \dots \right) \, dx$$

This yields the algebraic formula for the area:

$$\text{Area}(x) = x - \frac{1}{6}x^3 - \frac{1}{40}x^5 - \frac{1}{112}x^7 - \frac{5}{1152}x^9 - \dots$$

Step 4: Calculating the Area for $x = \frac{1}{2}$

Newton improved efficiency by choosing the limit $x = \frac{1}{2}$ (instead of 1), which makes the powers of $x$ shrink very rapidly. Substituting $x = \frac{1}{2}$ into the series:

$$\text{Area} \approx \frac{1}{2} - \frac{1}{6}\left(\frac{1}{2}\right)^3 - \frac{1}{40}\left(\frac{1}{2}\right)^5 - \frac{1}{112}\left(\frac{1}{2}\right)^7 - \dots$$

Simplifying the fractions:

$$\text{Area} \approx \frac{1}{2} - \frac{1}{48} - \frac{1}{1280} - \frac{1}{14336} - \dots$$

This sum gives a numerical value for the area.

Step 5: Equating to Geometry



Screenshot from video

Geometrically, the area under the unit circle from $x=0$ to $x=\frac{1}{2}$ corresponds to a slice of the circle. As described in the video, this region consists of two shapes:

  1. A triangle with base $\frac{1}{2}$ and height $\frac{\sqrt{3}}{2}$ (since $y = \sqrt{1 - (0.5)^2} = \sqrt{0.75} = \frac{\sqrt{3}}{2}$).
  2. A circular sector of $30^{\circ}$ (or $\frac{\pi}{6}$ radians).

The total geometric area is:

$$\text{Area} = \text{Area}_{\text{triangle}} + \text{Area}_{\text{sector}}$$ $$\text{Area} = \left( \frac{1}{2} \cdot \text{base} \cdot \text{height} \right) + \left( \frac{\theta}{2\pi} \cdot \pi r^2 \right)$$ $$\text{Area} = \left( \frac{1}{2} \cdot \frac{1}{2} \cdot \frac{\sqrt{3}}{2} \right) + \left( \frac{\pi/6}{2\pi} \cdot \pi (1)^2 \right)$$ $$\text{Area} = \frac{\sqrt{3}}{8} + \frac{\pi}{12}$$

Step 6: Solving for $\pi$

Finally, Newton equated the Algebraic Area (from Step 4) with the Geometric Area (from Step 5) and solved for $\pi$:

$$\frac{\sqrt{3}}{8} + \frac{\pi}{12} = \text{Series Sum}$$ $$\frac{\pi}{12} = \text{Series Sum} - \frac{\sqrt{3}}{8}$$ $$\pi = 12 \left( \text{Series Sum} - \frac{\sqrt{3}}{8} \right)$$ $$\pi = 12 \left[ \left( \frac{1}{2} - \frac{1}{48} - \frac{1}{1280} - \dots \right) - \frac{\sqrt{3}}{8} \right]$$

Using just the first few terms of the series, Newton achieved an approximation of $\pi \approx 3.14161$.

Monday, 21 April 2025

Quadruple Seven

There has been an uncharacteristic hiatus in my posts during April. My last post was on April 3rd on the occasion of my 76th birthday, and I've been ill ever since. However, today is a very special day and marks the appearance of four sevens in the number associated with my diurnal age. The number is \( \textbf{27777} \).


This number has some interesting properties. Firstly, it is the last so-called \( \textbf{iban} \) number till 40000. The definition follows:

A number is called iban if its name (in English) does not contain the letter "i". Assuming that the name of every power of 10 greater than \(10^5\) ends in "-illion" (like million, billion, trillion, etc.), then the iban numbers are finite. Counting 0 (zero) there are 30276 of them, the largest being 777777. Iban numbers belong to the same family as aban numbers, eban numbers, oban numbers, and uban numbers. See my blog post Iban Numbers.

So whether we write "twenty seven thousand seven hundred seventy seven" (American style) or "twenty seven thousand seven hundred and seventy seven" (British style", the iban property is unaffected.

A second, related property of the number is that it is a member of OEIS A002810 with \(n=16\).


 A002810: smallest number containing \(n\) syllables in UK English.

The associated sequence in American English is OEIS A045736 where the "and" is omitted and thus the number of syllables required is one less. There is an interesting paradox associated with this OEIS sequence that goes like this (to quote from the OEIS comments) and involves one of its members (1117777):

a(19) = 111777 is precisely the number used for Berry's paradox. In UK English the name of the number 111777 requires 19 syllables -- "one hundred and eleven thousand seven hundred and seventy-seven" -- and it's exactly the smallest number containing 19 syllables in UK English.

The paradox occurs when we consider that this integer is "the least integer not nameable in fewer than nineteen syllables" yet 111777 has just now been defined in eighteen syllables with this last sentence. So there is a contradiction, because the smallest integer expressible in no fewer than nineteen syllables can be expressed in eighteen syllables. This contradiction is Berry's paradox.

It can be noted that 27777, though not prime itself, contains only prime digits (2 and 7). Interestingly we have:$$ \sqrt{27777}  \approx 166.66 \dots $$Thus there is a run of four sixes in the decimal expression of the square root.

While composing this post I ran into a problem with getting the vertical bar to cover the number. This was part of a broader problem with my LaTeX displaying properly on my Macbook Air when using Chrome. For example, mathematical variables would not display in italics but remained upright. These were just two of several other minor glitches and so I got Gemini to examine my HTML code and suggest a solution. It did and the fix worked just fine.

However, another problem soon emerged in that the new line command wasn't working and was being ignored in my updated MathJax code. Again, Gemini was quick to offer a solution.

Using \\ outside a Multi-Line Environment: 

If you're just putting \\ inside $ ... $ or $$...$$ without an environment, MathJax will likely ignore it because those delimiters are meant for single mathematical expressions, even if they span multiple lines of code.

Solution: 
You need to wrap your multi-line math content in an appropriate environment. Common ones supported by MathJax are (see Figure 1):
  • align: For aligning equations at a specific point (e.g., the equals sign).
  • gather: For centering multiple equations without alignment.
  • array: For creating arrays or matrices, where \\ separates rows. 


Figure 1

Again very helpful and just another example of the usefulness of AI. I'm hoping that soon I'll be able to use Gemini to organize, in various ways, the hundreds of posts that I've made in this Mathematics blog over the years. On a humorous note it was instructive to discover my ignorace about Blogger's user interface despite having used it for so many years.

You've hit upon a common point of confusion with website editors like Blogger. The composing window where you write your posts is part of Blogger's administrative interface. The styles (like fonts, sizes, and sometimes even line spacing) you see while typing in that editor are controlled by Blogger's own styling for the editor itself, not by the theme you apply to your public blog.

Think of it like writing a document in a word processor (the Blogger editor) versus how that document looks when you save it as a PDF or print it (your live blog). The word processor might use a default font for typing, but the final output uses the fonts you've specified in the document's formatting.

Therefore, you cannot directly change the font used within the Blogger post composing window by editing your blog's theme HTML or CSS. That part of the interface is controlled by Blogger's platform and is not customizable by individual users.

The good news is that this is purely a visual difference while you're working. Even though the text might not appear in Ubuntu while you're typing or editing, it will display correctly in Ubuntu 12px (or whatever styles you've set in your theme) when you save or publish the post and view it on your actual blog.

So, you don't need to worry that the editor font is different; it won't affect how your readers see your posts.

Saturday, 17 December 2022

Integration Practice

For some reason I was pondering the integration of the function:$$ \frac{x}{\sqrt{1-x^2}}$$the other day and decided to give it a try. I spend so much time on number theory that I know my integration skills are atrophying so this was an opportunity to get in a little practice both with integration and with honing my LaTeX skills. Given that the function is undefined at \(x=1\), I decided that I would integrate between 0 and 1 and thus I was confronted with the integral:$$  \int_0^1 \! \frac{x}{\sqrt{1-x^2}} \, dx$$This of course is a very easy integral once we make the substitution \(x=\sin \theta\) where \(dx=\cos \theta \, d\theta\). The integration limits will change and become 0 to \(\pi/2\). The integral thus becomes:$$ \begin{align} \int_0^{\pi/2} \! \frac{\sin \theta \cdot \cos \theta}{\sqrt{1-\sin^2 \theta}} \, d\theta &= \int_0^{\pi/2} \! \frac{\sin \theta \cdot \cos \theta}{\cos \theta} \, d\theta \\&= \int_0^{\pi/2} \! \sin \theta \, d\theta \\ &= - \biggl [ \cos \theta \biggr ]_0^{\pi/2} \\ &=1 \end{align}$$It's interesting to note that whatever power \(x\) is raised to, the denominator will always disappear after the substitution. That is to say that for an integer \(n>0\) we have:$$\int_0^1 \! \frac{x^n}{\sqrt{1-x^2}} \, dx=\int_0^{\pi/2} \! \sin^n \theta \, d\theta$$Referring to a very useful site - https://www.integral-calculator.com/ - I was reminded of the famous reduction formula for this type of integral, namely: $$ \int \! \sin^n \theta \, d\theta = \frac{n-1}{n} \int \! \sin^{n-2} \, d\theta - \frac{ \cos \theta \cdot \sin^{n-1} \theta}{n}$$Let's apply this formula progressively for \(n\)=2, 3 and 4.

The case of \(n=2\):$$ \begin{align} \int_0^{\pi/2} \! \sin^2 \theta \, d\theta &=\frac{1}{2}\int_0^{\pi/2} \! 1\, d\theta - \biggl [ \frac{ \cos \theta \cdot \sin \theta }{2} \biggr ]_0^{\pi/2}\\&=\frac{\pi}{4} \end{align} $$What we notice is that there will always be a \( \sin \theta \cdot \cos \theta \) term on the far right as the reduction proceeds but this can be ignored because of our limits: the result will always be zero. This simplification means that we now have:$$ \int_0^{\pi/2} \! \sin^n \theta \, d\theta = \frac{n-1}{n} \int_0^{\pi/2} \! \sin^{n-2} \theta \, d\theta$$Let's test this out for the case of \(n=3\) and \(n=4\):

The case of \(n=3\):$$ \begin{align}  \int_0^{\pi/2} \! \sin^3 \theta \, d\theta &= \frac{2}{3} \int_0^{\pi/2} \! \sin \theta \, d\theta \\ &= \frac{2}{3} \end{align}$$The case of \(n=4\):$$ \begin{align}  \int_0^{\pi/2} \! \sin^4 \theta \, d\theta &= \frac{3}{4} \int_0^{\pi/2} \! \sin^2 \theta \, d\theta \\ &= \frac{3 \pi}{16} \end{align}$$The integral calculator site not only provides the steps but also a graph. Figure 1 shows the area under the curve for:$$  \int_0^1 \! \frac{x^4}{\sqrt{1-x^2}} \, dx$$


Figure 1

It's easy to take the integral calculator for granted but it does a rather remarkable job.


Here is a description of how it works, quoted from the website:
For those with a technical background, the following section explains how the Integral Calculator works.

First, a parser analyzes the mathematical function. It transforms it into a form that is better understandable by a computer, namely a tree (see figure below). In doing this, the Integral Calculator has to respect the order of operations. A specialty in mathematical expressions is that the multiplication sign can be left out sometimes, for example we write "5x" instead of "5*x". The Integral Calculator has to detect these cases and insert the multiplication sign.

The parser is implemented in JavaScript, based on the Shunting-yard algorithm, and can run directly in the browser. This allows for quick feedback while typing by transforming the tree into LaTeX code. MathJax takes care of displaying it in the browser.

When the "Go!" button is clicked, the Integral Calculator sends the mathematical function and the settings (variable of integration and integration bounds) to the server, where it is analyzed again. This time, the function gets transformed into a form that can be understood by the computer algebra system Maxima.
Maxima takes care of actually computing the integral of the mathematical function. Maxima's output is transformed to LaTeX again and is then presented to the user. The antiderivative is computed using the Risch algorithm, which is hard to understand for humans. That's why showing the steps of calculation is very challenging for integrals.

In order to show the steps, the calculator applies the same integration techniques that a human would apply. The program that does this has been developed over several years and is written in Maxima's own programming language. It consists of more than 17000 lines of code. When the integrand matches a known form, it applies fixed rules to solve the integral (e. g. partial fraction decomposition for rational functions, trigonometric substitution for integrands involving the square roots of a quadratic polynomial or integration by parts for products of certain functions). Otherwise, it tries different substitutions and transformations until either the integral is solved, time runs out or there is nothing left to try. The calculator lacks the mathematical intuition that is very useful for finding an antiderivative, but on the other hand it can try a large number of possibilities within a short amount of time. The step by step antiderivatives are often much shorter and more elegant than those found by Maxima.

The "Check answer" feature has to solve the difficult task of determining whether two mathematical expressions are equivalent. Their difference is computed and simplified as far as possible using Maxima. For example, this involves writing trigonometric/hyperbolic functions in their exponential forms. If it can be shown that the difference simplifies to zero, the task is solved. Otherwise, a probabilistic algorithm is applied that evaluates and compares both functions at randomly chosen places. In the case of antiderivatives, the entire procedure is repeated with each function's derivative, since antiderivatives are allowed to differ by a constant.

The interactive function graphs are computed in the browser and displayed within a canvas element (HTML5). For each function to be graphed, the calculator creates a JavaScript function, which is then evaluated in small steps in order to draw the graph. While graphing, singularities (e. g. poles) are detected and treated specially. The gesture control is implemented using Hammer.js.

If you have any questions or ideas for improvements to the Integral Calculator, don't hesitate to write me an e-mail.

Saturday, 5 June 2021

Hands On With The Integral Calculator

I watched a YouTube video today featuring the following integration result:$$\int_0^{2\pi} \frac{1}{3+2\sin(x)} \mathrm{d}x=\frac{2\pi}{\sqrt{5}}$$The method of solving it involved complex analysis involving contour integrals, L'Hospital's Rule, and the Residue Theorem. Here is a link to the video. It is well explained but I was left wondering if there is a way to solve it that does not require the use of complex numbers.

I decided to use a recently discovered resource:


I entered this result and then copied the result, which is shown below:

Problem:
∫12sin(x)+3dx
Prepare for tangent half-angle substitution (Weierstrass substitution):
=∫14tan(x2)tan2(x2)+1+3dx
Substitute u=tan(x2) ⟶ dudx=sec2(x2)2 (steps) ⟶ dx=2sec2(x2)du =2u2+1du:
=2∫13u2+4u+3 du

Now solving:
∫13u2+4u+3du
Complete the square:
=∫1(√3u+2√3)2+53du
Substitute v=3u+2√5 ⟶ dvdu=3√5 (steps) ⟶ du=√53dv:
=∫√53(5v23+53)dv
Simplify:
=1√5∫1v2+1dv

Now solving:
∫1v2+1dv
This is a standard integral:
=arctan(v)

Plug in solved integrals:
1√5∫1v2+1dv
=arctan(v)√5
Undo substitution v=3u+2√5:
=arctan(3u+2√5)√5

Plug in solved integrals:
2∫13u2+4u+3 du
=2arctan(3u+2√5)√5
Undo substitution u=tan(x2):
=2arctan(3tan(x2)+2√5)√5

The problem is solved:
∫12sin(x)+3 dx
=2arctan(3tan(x2)+2√5)√5+C

*****************************************

The definite integral result is then given in LaTeX format: \( \dfrac{2{\pi}}{\sqrt{5}} \). 

Unfortunately, it doesn't appear possible to export the actual steps in LaTex but the copy and paste operation seems to have worked well enough, the elements are editable and the provided links are functional. However, the HTML is an absolute nightmare. It makes the page slow to load and there's no way to remove the coloured vertical bars on the left.

The site also provides a graph of the integral. See Figure 1.


Figure 1

There is a Derivative Calculator as well. I wasn't familiar with the Weierstrass substitution but I won't go into that in this post. It deserves a post of its own which I'll hopefully get around to doing in the near future. 

I thought I'd experiment with applying the MathPix Snipping Tool to the Integral Calculator. I wrote about the former in an eponymous post on March 31st 2021. Here are the results for the initial snipping (with a little tinkering to remove excessive white space):$$\int \frac{1}{2 \sin (x)+3} \mathrm{~d} x$$Prepare for tangent half-angle substitution (Weierstrass substitution):$$\begin{aligned}&=\int \frac{1}{\frac{4 \tan \left(\frac{x}{2}\right)}{\tan ^{2}\left(\frac{x}{2}\right)+1}+3} \mathrm{~d} x \\\text { Substitute } u=\tan \left(\frac{x}{2}\right) \longrightarrow \frac{\mathrm{d} u}{\mathrm{~d} x} &=\frac{\sec ^{2}\left(\frac{x}{2}\right)}{2}(\text { steps }) \longrightarrow \mathrm{d} x=\frac{2}{\sec ^{2}\left(\frac{x}{2}\right)} \mathrm{d} u=\frac{2}{u^{2}+1} \mathrm{~d} u: \\
&=2 \int \frac{1}{3 u^{2}+4 u+3} \mathrm{~d} u
\end{aligned}$$Now solving:$$\int \frac{1}{3 u^{2}+4 u+3} \mathrm{~d} u$$Complete the square:$$\begin{array}{c}
=\int \frac{1}{\left(\sqrt{3} u+\frac{2}{\sqrt{3}}\right)^{2}+\frac{5}{3}} \mathrm{~d} u \\
\text { Substitute } v=\frac{3 u+2}{\sqrt{5}} \longrightarrow \frac{\mathrm{d} v}{\mathrm{~d} u}=\frac{3}{\sqrt{5}}(\text { steps }) \longrightarrow \mathrm{d} u=\frac{\sqrt{5}}{3} \mathrm{~d} v \text { : }


\end{array}$$I only snipped the initial part of the steps. The reproduction from the original page is perfect but I would have set the initial LaTeX out differently. However, the result is editable and thus can be tweaked if desired. An alternative is to produce a PNG but that of course is not then editable. I'm currently using the free version of MathPix Snipping Tool that allows for 50 snips per month which is more than sufficient for casual personal use.