<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>John D. Cook</title>
	<atom:link href="http://www.johndcook.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.johndcook.com/blog</link>
	<description>Applied Mathematics Consulting</description>
	<lastBuildDate>Tue, 10 Sep 2024 14:41:11 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.1</generator>

<image>
	<url>https://www.johndcook.com/wp-content/uploads/2020/01/cropped-favicon_512-32x32.png</url>
	<title>John D. Cook</title>
	<link>https://www.johndcook.com/blog</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Separable functions in different contexts</title>
		<link>https://www.johndcook.com/blog/2024/09/10/separable-functions/</link>
					<comments>https://www.johndcook.com/blog/2024/09/10/separable-functions/#respond</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Tue, 10 Sep 2024 14:41:11 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Combinatorics]]></category>
		<category><![CDATA[Differential equations]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245718</guid>

					<description><![CDATA[<p>I was skimming through the book Mathematical Reflections [1] recently. He was discussing a set of generalizations [2] of the Star of David theorem from combinatorics. The theorem is so named because if you draw a Star of David by connecting points in Pascal&#8217;s triangle then each side corresponds to the vertices of a triangle. [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/09/10/separable-functions/">Separable functions in different contexts</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>I was skimming through the book Mathematical Reflections [1] recently. He was discussing a set of generalizations [2] of the <a href="https://www.johndcook.com/blog/2008/12/21/star-of-david-theorem/">Star of David theorem</a> from combinatorics.</p>
<p><img decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/sod.svg" alt="\gcd\left(\binom{n - 1}{r - 1}, \binom{n}{r+1}, \binom{n+1}{r}\right) = \gcd\left(\binom{n-1}{r}, \binom{n+1}{r+1}, \binom{n}{r-1}\right) " width="508" height="48" /></p>
<p>The theorem is so named because if you draw a Star of David by connecting points in <a href="https://www.johndcook.com/blog/2024/08/29/negative-binomial-pascals-triangle/">Pascal&#8217;s triangle</a> then each side corresponds to the vertices of a triangle.</p>
<p><img fetchpriority="high" decoding="async" class="aligncenter" src="https://www.johndcook.com/star-of-david.jpg?w=337&amp;h=348" alt="diagram illustrating the Star of David Theorem" width="224" height="224" /></p>
<p>One such theorem was the following.</p>
<p><img decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/gsod.svg" alt="\binom{n - \ell}{r - \ell} \binom{n - k}{r} \binom{n - k - \ell}{r - k} = \binom{n-k}{r-k} \binom{n - \ell}{r} \binom{n - k - \ell}{r - \ell}" width="441" height="48" /></p>
<p>This theorem also has a geometric interpretation, connecting vertices within Pascal&#8217;s triangle.</p>
<p>The authors point out that the binomial coefficient is a separable function of three variables, and that their generalized Star of David theorem is true for <strong>any separable function</strong> of three variables.</p>
<p>The binomial coefficient C(<em>n</em>, <em>k</em>) is a function of two variables, but you can think of it as a function of three variables: <em>n</em>, <em>k</em>, and <em>n</em> − <em>k</em>. That is</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/gsod2.svg" alt="{n \choose k} = f(n) \, g(k) \, g(n-k)" width="197" height="48" /></p>
<p>where <em>f</em>(<em>n</em>) = <em>n</em>! and <em>g</em>(<em>k</em>) = 1/<em>k</em>!.</p>
<p>I was surprised to see the term <em>separable function</em> outside of a PDE context. My graduate work was in partial differential equations, and so when I hear <em>separable function</em> my mind goes to separation of variables as a technique for solving PDEs.</p>
<p>Coincidentally, I was looking a separable coordinate systems recently. These are coordinate systems in which the Helmholtz equation can be solved by separable function, i.e. a coordinate system in which the separation of variables technique will work. The <a href="https://www.johndcook.com/blog/2021/06/14/laplacian/">Laplacian</a> can take on very different forms in different coordinate systems, and if possible you&#8217;d like to choose a coordinate system in which a PDE you care about is separable.</p>
<h2>Related posts</h2>
<ul>
<li class='link'><a href='https://www.johndcook.com/blog/2024/01/18/separable-function/'>When is a function of two variables separable?</a></li>
<li class='link'><a href='https://www.johndcook.com/blog/2021/06/12/justifying-separation-of-variables/'>Justifying separation of variables</a></li>
<li class='link'><a href='https://www.johndcook.com/blog/2022/11/09/elliptic-coordinates/'>Laplace&#8217;s equation in elliptical coordinates</a></li>
</ul>
<p>[1] Peter Hilton, Derek Holton, and Jean Pedersen. Mathematical Reflections. Springer, 1996.</p>
<p>[2] Hilton <em>et al</em> refer to a set of theorems as generalizations of the Star of David theorem, but these theorems are not strictly generalizations in the sense that the original theorem is clearly a special case of the generalized theorems. The theorems are related, and I imagine with more effort I could see how to prove the older theorem from the newer ones, but it&#8217;s not immediately obvious.</p>The post <a href="https://www.johndcook.com/blog/2024/09/10/separable-functions/">Separable functions in different contexts</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/09/10/separable-functions/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Body roundness index</title>
		<link>https://www.johndcook.com/blog/2024/09/07/body-roundness-index/</link>
					<comments>https://www.johndcook.com/blog/2024/09/07/body-roundness-index/#comments</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Sun, 08 Sep 2024 01:12:54 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Geometry]]></category>
		<category><![CDATA[Science]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245715</guid>

					<description><![CDATA[<p>Body Roundness Index (BRI) is a proposed replacement for Body Mass Index (BMI) [1]. Some studies have found that BRI is a better measure of obesity and a more effective predictor of some of the things BMI is supposed to predict [2]. BMI is based on body mass and height, and so it cannot distinguish [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/09/07/body-roundness-index/">Body roundness index</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p><strong>Body Roundness Index</strong> (BRI) is a proposed replacement for Body Mass Index (BMI) [1]. Some studies have found that BRI is a better measure of obesity and a more effective predictor of some of the things BMI is supposed to predict [2].</p>
<p>BMI is based on body mass and height, and so it cannot distinguish a body builder and an obese man if both have the same height and weight. BRI looks at body shape more than body mass.</p>
<p>The basic idea behind Body Roundness Index is to draw an ellipse based on a person&#8217;s body and report how close that ellipse is to being a circle. The more a person looks like a circle, higher his BRI. The formula for BRI is</p>
<p style="padding-left: 40px;">BRI = 364.2 − 365.5 <em>e</em></p>
<p>where <em>e</em> is the eccentricity of the ellipse.</p>
<p>Now what is this ellipse we&#8217;ve been talking about? It&#8217;s roughly an ellipse whose major axis runs from head to toe and whose minor axis runs across the person&#8217;s width.</p>
<p>There are a couple simplifications here.</p>
<ol>
<li>You don&#8217;t actually measure how wide someone is. You measure the circumference of their waist and find the diameter of a circle with that circumference.</li>
<li>You don&#8217;t actually measure how high their waist is [3]. You assume their waist is at exactly half their height.</li>
</ol>
<p>It&#8217;s conventional to describe an ellipse in terms of its semi-major axis <em>a</em> and semi-minor axis <em>b</em>. For a circle, <em>a</em> = <em>b</em> = radius. But in general an ellipse doesn&#8217;t have a single radius and <em>a</em> &gt; <em>b</em>. You could think of <em>a</em> and <em>b</em> as being the maximum and minimum radii.</p>
<p>So to fit an ellipse to our idealized model of a person, the major axis, 2<em>a</em>, equals the person&#8217;s height.</p>
<p style="padding-left: 40px; text-align: center;"><em>a</em> = <em>h</em>/2</p>
<p>The minor axis <em>b</em> is the radius of a circle of circumference <em>c</em> where <em>c</em> is the circumference of the person&#8217;s waist (or hips [3]).</p>
<p style="padding-left: 40px; text-align: center;"><em>b</em> = <em>c</em> / 2π</p>
<p>As explained <a href="https://www.johndcook.com/blog/2022/10/14/eccentricity-flatness-aspect/">here</a>, eccentricity is computed from <em>a</em> and <em>b </em>by</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/eccentricity2.svg" alt="e = \sqrt{1 - \frac{b^2}{a^2}}" width="104" height="48" /></p>
<p>As an example, consider a man who is 6 foot (72 inches) tall and has a 34 inch waist. Then</p>
<p style="padding-left: 40px;"><em>a</em> = 36<br />
<em>b</em> = 17/π = 5.4112<br />
<em>e</em> = √(1 − <em>b</em>²/<em>a</em>²) = 0.9886<br />
BRI = 364.2 − 365.5 <em>e</em> = 2.8526</p>
<p>Note that the man&#8217;s weight doesn&#8217;t enter the calculation. He could be a slim guy weighing 180 pounds or a beefier guy weighing 250 pounds as long as he has a 34 inch waist. In the latter case, the extra mass is upper body muscle and not around his waist.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-medium" src="https://www.johndcook.com/bsi.png" alt="thin ellipse graph" width="110" height="360" /></p>
<h2>Related posts</h2>
<ul>
<li class="link"><a href="https://www.johndcook.com/blog/2022/10/20/eccentricity/">How eccentricity matters</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2023/05/28/approximate-ellipse-perimeter/">Approximations for ellipse perimeter</a></li>
</ul>
<p>[1] Diana M. Thomas et al. Relationships Between Body Roundness with Body Fat and Visceral Adipose Tissue Emerging from a New Geometrical Model. Obesity (2013) 21, 2264–2271. doi:10.1002/oby.20408.</p>
<p>[2] Researchers argue over which number to reduce a person to: BMI, BRI, or some other measure. They implicitly agree that a person must be reduced to a number; they just disagree on which number.</p>
<p>[3] Or waist. There are two versions of BRI, one based on waist circumference and one based on hip circumference.</p>The post <a href="https://www.johndcook.com/blog/2024/09/07/body-roundness-index/">Body roundness index</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/09/07/body-roundness-index/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>A couple more variations on an ancient theme</title>
		<link>https://www.johndcook.com/blog/2024/09/07/aryabhata/</link>
					<comments>https://www.johndcook.com/blog/2024/09/07/aryabhata/#respond</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Sat, 07 Sep 2024 22:32:40 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[History]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245714</guid>

					<description><![CDATA[<p>I&#8217;ve written a couple posts on the approximation by the Indian astronomer Aryabhata (476–550). The approximation is accurate for x in [−π/2, π/2]. The first post collected a Twitter thread about the approximation into a post. The second looked at how far the coefficients in Aryabhata&#8217;s approximation are from the optimal approximation as a ratio [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/09/07/aryabhata/">A couple more variations on an ancient theme</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>I&#8217;ve written a couple posts on the approximation</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/aryabhata4.svg" alt="\cos x \approx \frac{\pi^2 - 4x^2}{\pi^2 + x^2}" width="137" height="45" /></p>
<p>by the Indian astronomer Aryabhata (476–550). The approximation is accurate for <em>x</em> in [−π/2, π/2].</p>
<p>The <a href="https://www.johndcook.com/blog/2024/08/31/sine-approx/">first</a> post collected a Twitter thread about the approximation into a post. The <a href="https://www.johndcook.com/blog/2024/09/03/optimal-rational-approximation/">second</a> looked at how far the coefficients in Aryabhata&#8217;s approximation are from the optimal approximation as a ratio of quadratics.</p>
<p>This post will answer a couple questions. First, what value of π did Aryabhata have and how would that effect the approximation error? Second, how bad would Aryabhata&#8217;s approximation be if we used the approximation π² ≈ 10?</p>
<h2>Using Aryabhata&#8217;s value of π</h2>
<p>Aryabhata knew the value 3.1416 for π. We know this because he said that a circle of diameter 20,000 would have circumference  62,832. We don&#8217;t know, but it&#8217;s plausible that he knew π to more accuracy and rounded it to the implied value.</p>
<p>Substituting 3.1416 for π changes the sixth decimal of the approximation, but the approximation is good to only three decimal places, so 3.1416 is as good as a more accurate approximation as far as the error in approximating cosine is concerned.</p>
<h2>Using π² ≈ 10</h2>
<p>Substituting 10 for π² in Aryabhata&#8217;s approximation gives an approximation that&#8217;s convenient to evaluate by hand.</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/aryabhata5.svg" alt="\cos x \approx \frac{10 - 4x^2}{10 + x^2}" width="136" height="45" /></p>
<p>It&#8217;s very accurate for small values of <em>x</em> but the maximum error increases from 0.00163 to 0.01091. Here&#8217;s a plot of the error.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-medium" src="https://www.johndcook.com/aryabhata6.png" width="480" height="360" /></p>
<h2></h2>The post <a href="https://www.johndcook.com/blog/2024/09/07/aryabhata/">A couple more variations on an ancient theme</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/09/07/aryabhata/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Finding pi in the alphabet</title>
		<link>https://www.johndcook.com/blog/2024/09/07/finding-pi-in-the-alphabet/</link>
					<comments>https://www.johndcook.com/blog/2024/09/07/finding-pi-in-the-alphabet/#respond</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Sat, 07 Sep 2024 19:00:16 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245712</guid>

					<description><![CDATA[<p>Write the letters of the alphabet around a circle, then strike out the letters that are symmetrical about a vertical line. The remaining letters are grouped in clumps of 3, 1, 4, 1, and 6 letters. I&#8217;ve heard that this observation is due to Martin Gardner, but I don&#8217;t have a specific reference. In case [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/09/07/finding-pi-in-the-alphabet/">Finding pi in the alphabet</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>Write the letters of the alphabet around a circle, then strike out the letters that are symmetrical about a vertical line. The remaining letters are grouped in clumps of 3, 1, 4, 1, and 6 letters.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-medium" src="https://www.johndcook.com/alphabet_pi.png" width="375" height="375" /></p>
<p>I&#8217;ve heard that this observation is due to Martin Gardner, but I don&#8217;t have a specific reference.</p>
<p>In case you&#8217;re interested, here&#8217;s the Python script I wrote to make the image above.</p>
<pre>
    from numpy import *
    import matplotlib.pyplot as plt
    
    for i in range(26):
        letter = chr(ord('A') + i)
        if letter in "AHIMOTUVWXY":
            latex = r"$\equiv\!\!\!\!\!" + letter + "$"
        else:
            latex = f"${letter}$"
        theta = pi/2 - 2*pi*i/26
        pt = (0.5*cos(theta), 0.5*sin(theta))
        plt.plot(pt[0], pt[1], ' ')
        plt.annotate(latex, pt, fontsize="xx-large")
    plt.axis("off")
    plt.gca().set_aspect("equal")
    plt.savefig("alphabet_pi.png")
</pre>The post <a href="https://www.johndcook.com/blog/2024/09/07/finding-pi-in-the-alphabet/">Finding pi in the alphabet</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/09/07/finding-pi-in-the-alphabet/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Optimal rational approximation</title>
		<link>https://www.johndcook.com/blog/2024/09/03/optimal-rational-approximation/</link>
					<comments>https://www.johndcook.com/blog/2024/09/03/optimal-rational-approximation/#respond</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Tue, 03 Sep 2024 12:33:28 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Optimization]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245711</guid>

					<description><![CDATA[<p>A few days ago I wrote about the approximation for cosine due to the Indian astronomer Aryabhata (476–550) and gave this plot of the error. I said that Aryabhata&#8217;s approximation is &#8220;not quite optimal since the ripples in the error function are not of equal height.&#8221; This was an allusion to the equioscillation theorem. Chebyshev [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/09/03/optimal-rational-approximation/">Optimal rational approximation</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>A few days ago I <a href="https://www.johndcook.com/blog/2024/08/31/sine-approx/">wrote</a> about the approximation</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/aryabhata4.svg" alt="\cos x \approx \frac{\pi^2 - 4x^2}{\pi^2 + x^2}" width="137" height="45" /></p>
<p>for cosine due to the Indian astronomer Aryabhata (476–550) and gave this plot of the error.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-medium" src="https://www.johndcook.com/aryabhata3.png" width="480" height="360" />I said that Aryabhata&#8217;s approximation is &#8220;not quite optimal since the ripples in the error function are not of equal height.&#8221; This was an allusion to the equioscillation theorem.</p>
<p>Chebyshev proved that an optimal polynomial approximation has an error function that has equally large positive and negative oscillations. Later this theorem was generalized to rational approximations through a sequence of results by de la Vallée Poussin, Walsh, and Achieser. Here&#8217;s the formal statement of the theorem from [1] in the context of real-valued rational approximations with numerators of degree <em>m</em> and denominators of degree <em>n</em></p>
<p style="padding-left: 40px;"><strong>Theorem 24.1. Equioscillation characterization of best approximants</strong>. A real function <em>f</em> in <em>C</em>[−1, 1] has a unique best approximation <em>r</em>*, and a function <em>r</em> is equal to <em>r</em>* if and only if <em>f</em> − <em>r</em> equioscillates between at least <em>m</em> + <em>n</em> + 2 − <em>d</em> extremes where <em>d</em> is the defect of <em>r</em>.</p>
<p>When the theorem says the error equioscillates, it means the error alternately takes on ± its maximum absolute value.</p>
<p>The defect is non-zero when both numerator and denominator have less than maximal degree, which doesn&#8217;t concern us here.</p>
<p>We want to find the optimal rational approximation for cosine over the interval [−π/2, π/2]. It doesn&#8217;t matter that the theorem is stated for continuous functions over [−1, 1] because we could just rescale cosine. We&#8217;re looking for approximations with (<em>m</em>, <em>n</em>) = (2, 2), i.e. ratios of quadratic polynomials, to see if we can improve on the approximation at the top of the post.</p>
<p>The equioscillation theorem says our error should oscillate at least 6 times, and so if we find an approximation whose error oscillates as required by the theorem, we know we&#8217;ve found the optimal approximation.</p>
<p>I first tried finding the optimal approximation using Mathematica&#8217;s <code>MiniMaxApproximation</code> function. But this function tries to optimize <em>relative</em> error and I&#8217;m trying to minimize absolute error. Minimizing relative error creates problems because cosine evaluates to zero at the ends of interval ±π/2. I tried several alternatives and eventually decided to take another approach.</p>
<p>Because the cosine function is even, the optimal approximation is even. Which means the optimal approximation has the form</p>
<p style="padding-left: 40px;">(<em>a</em> + <em>b</em><em>x</em>²) / (<em>c</em> + <em>d</em><em>x</em>²)</p>
<p>and we can assume without loss of generality that <em>a</em> = 1. I then wrote some Python code to minimize the error as a function of the three remaining variables. The results were <em>b</em> = −4.00487004, <em>c</em> = 9.86024544, and <em>d</em> = 1.00198695, very close to Aryabhata&#8217;s approximation that corresponds to <em>b</em> = −4, <em>c</em> = π², and <em>d</em> = 1.</p>
<p>Here&#8217;s a plot of the error, the difference between cosine and the rational approximation.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-medium" src="https://www.johndcook.com/optimal_cos_approx.png" width="640" height="480" /></p>
<p>The absolute error takes on its maximum value seven times, alternating between positive and negative values, and so we know the approximation is optimal. However sketchy my approach to finding the optimal approximation may have been, the plot shows that the result is correct.</p>
<p>Aryabhata&#8217;s approximation had maximum error 0.00163176 and the optimal approximation has maximum error 0.00097466. We were able to shave about 1/3 off the maximum error, but at a cost of using coefficients that would be harder to use by hand. This wouldn&#8217;t matter to a modern computer, but it would matter a great deal to an ancient astronomer.</p>
<h2>Related posts</h2>
<ul>
<li class="link"><a href="https://www.johndcook.com/blog/2010/02/18/economizing-approximations/">Economizing approximations</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2020/03/11/chebyshev-approximation/">Chebyshev approximation</a></li>
</ul>
<p>[1] <a href="https://amzn.to/2jGlnKs">Approximation Theory and Approximation Practice</a> by Lloyd N. Trefethen</p>The post <a href="https://www.johndcook.com/blog/2024/09/03/optimal-rational-approximation/">Optimal rational approximation</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/09/03/optimal-rational-approximation/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Pell is to silver as Fibonacci is to gold</title>
		<link>https://www.johndcook.com/blog/2024/09/01/pell-numbers/</link>
					<comments>https://www.johndcook.com/blog/2024/09/01/pell-numbers/#respond</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Mon, 02 Sep 2024 01:32:02 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Number theory]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245708</guid>

					<description><![CDATA[<p>As mentioned in the previous post, the ratio of consecutive Fibonacci numbers converges to the golden ratio. Is there a sequence whose ratios converge to the silver ratio the way ratios of Fibonacci numbers converge to the golden ratio? (If you&#8217;re not familiar with the silver ratio, you can read more about it here.) The [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/09/01/pell-numbers/">Pell is to silver as Fibonacci is to gold</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>As mentioned in the previous post, the ratio of consecutive Fibonacci numbers converges to the golden ratio. Is there a sequence whose ratios converge to the <strong>silver ratio</strong> the way ratios of Fibonacci numbers converge to the golden ratio?</p>
<p>(If you&#8217;re not familiar with the silver ratio, you can read more about it <a href="https://www.johndcook.com/blog/2009/05/20/the-silver-ratio/">here</a>.)</p>
<p>The Pell numbers <em>P</em><sub><em>n</em></sub> start out just like the Fibonacci numbers:</p>
<p style="padding-left: 40px;"><em>P</em><sub>0</sub> = 0<br />
<em>P</em><sub>1</sub> = 1.</p>
<p>But the recurrence relationship is slightly different:</p>
<p style="padding-left: 40px;"><em>P</em><sub><em>n</em>+2</sub> = 2<em>P</em><sub><em>n</em>+1</sub> + <em>P</em><sub><em>n</em></sub>.</p>
<p>So the Pell numbers are 0, 1, 2, 5, 12, 29, ….</p>
<p>The ratios of consecutive Pell numbers converge to the silver ratio.</p>
<h2>Metallic ratios</h2>
<p>There are more analogs of the golden ratio, such as the bronze ratio and more that do not have names. In general the <em>k</em>th metallic ratio is the larger root of</p>
<p style="padding-left: 40px;"><em>x</em>² − <em>kx</em> − 1 = 0.</p>
<p>The cases <em>n</em> = 1, 2, and 3 correspond to the gold, silver, and bronze ratios respectively.</p>
<p>The quadratic equation above is the characteristic equation of the recurrence relation</p>
<p style="padding-left: 40px;"><em>P</em><sub><em>n</em>+2</sub> = <em>kP</em><sub><em>n</em>+1</sub> + <em>P</em><sub><em>n</em></sub>.</p>
<p>which suggests how we construct a sequence of integers such that consecutive ratios converge to the <em>n</em>th metallic constant.</p>
<p>So if we use <em>k</em> = 3 in the recurrence relation, we should get a sequence whose ratios converge to the bronze ratio. The results are</p>
<p style="padding-left: 40px;">0, 1, 3, 10, 33, 109, 360, 1189, 3927, 12970, …</p>
<p>The following code will print the ratios.</p>
<pre>    def bronze(n):
        if n == 0: return 0
        if n == 1: return 1
        return 3*bronze(n-1) + bronze(n-2)

    for n in range(2, 12):
        print( bronze(n)/bronze(n-1) )
</pre>
<p>Here&#8217;s the output.</p>
<pre>    3.0
    3.3333333333333335
    3.3
    3.303030303030303
    3.302752293577982
    3.3027777777777776
    3.302775441547519
    3.3027756557168324
    3.302775636083269
    3.3027756378831383
</pre>
<p>The results are converging to the bronze ratio</p>
<p style="padding-left: 40px;">(3 + √13)/2 = 3.302775637731995.</p>
<h2>Plastic ratio</h2>
<p>The <a href="https://www.johndcook.com/blog/2021/05/27/plastic-number-feels-plastic/">plastic ratio</a> is the real root of <em>x</em>³ − <em>x</em> − 1 = 0. Following the approach above, we can construct a sequence of integers whose consecutive ratios converge to the plastic ratio with the recurrence relation</p>
<p style="padding-left: 40px;"><em>S</em><sub><em>n</em>+3</sub> = <em>S</em><sub><em>n</em>+1</sub> + <em>S</em><sub><em>n</em></sub></p>
<p>Let&#8217;s try this out with a little code.</p>
<pre>    def plastic(n):
        if n &lt; 3: return n
        return plastic(n-2) + plastic(n-3)

    for n in range(10, 20):
        print( plastic(n)/plastic(n-1) )
</pre>
<p>This prints</p>
<pre>    1.3
    1.3076923076923077
    1.3529411764705883
    1.3043478260869565
    1.3333333333333333
    1.325
    1.320754716981132
    1.3285714285714285
    1.3225806451612903
</pre>
<p>which shows the ratios are approaching the plastic constant 1.324717957244746.</p>
<h2>Related posts</h2>
<ul>
<li class="link"><a href="https://www.johndcook.com/blog/2023/04/14/metallic-ratios/">Gold, Silver, and Bronze Ratios</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2014/02/23/imaginary-gold-silver-bronze/">Imaginary gold, silver, and bronze</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2017/03/26/plastic-powers/">Plastic powers</a></li>
</ul>The post <a href="https://www.johndcook.com/blog/2024/09/01/pell-numbers/">Pell is to silver as Fibonacci is to gold</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/09/01/pell-numbers/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Miles to kilometers</title>
		<link>https://www.johndcook.com/blog/2024/09/01/miles-to-kilometers/</link>
					<comments>https://www.johndcook.com/blog/2024/09/01/miles-to-kilometers/#comments</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Sun, 01 Sep 2024 11:41:49 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Number theory]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245701</guid>

					<description><![CDATA[<p>The number of kilometers in a mile is k = 1.609344 which is close to the golden ratio φ = 1.6180334. The ratio of consecutive Fibonacci numbers converges to φ, and so you can approximately convert miles to kilometers by multiplying by a Fibonacci number and dividing by the previous Fibonacci number. For example, you [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/09/01/miles-to-kilometers/">Miles to kilometers</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>The number of kilometers in a mile is <em>k</em> = 1.609344 which is close to the golden ratio φ = 1.6180334.</p>
<p>The ratio of consecutive Fibonacci numbers converges to φ, and so you can approximately convert miles to kilometers by multiplying by a Fibonacci number and dividing by the previous Fibonacci number. For example, you could multiply by 8 and divide by 5, or you could multiply by 13 and divide by 8.</p>
<p>As you start going down the Fibonacci sequence, consecutive ratios get closer to <em>k</em> and closer to φ. But since the ratios converge to φ, at some point the ratios get closer to φ and further from <em>k</em>. That means there&#8217;s an optimal Fibonacci ratio for converting miles to kilometers.</p>
<p>I was curious what this optimal ratio is, and it turns out to be 21/13. There we have</p>
<p style="padding-left: 40px;">|<em>k</em> − 21/13| = 0.0060406</p>
<p>and so the error in the approximation is 0.375%. The error is about a third smaller than using φ as the conversion factor.</p>
<p>The Lucas numbers satisfy the same recurrence relation as the Fibonacci numbers, but start with <em>L</em><sub>0</sub> = 2 and <em>L</em><sub>1</sub> = 1. The ratio of consecutive Lucas numbers also converges to φ, and so you could also use Lucas numbers to convert miles to kilometers.</p>
<p>There is an optimal Lucas ratio for converting miles to kilometers for the same reasons there is an optimal Fibonacci ratio. That ratio turns out to be 29/18, and</p>
<p style="padding-left: 40px;">|<em>k</em> − 29/18| = 0.001767</p>
<p>which is about 4 times more accurate than the best Fibonacci ratio.</p>The post <a href="https://www.johndcook.com/blog/2024/09/01/miles-to-kilometers/">Miles to kilometers</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/09/01/miles-to-kilometers/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Ancient accurate approximation for sine</title>
		<link>https://www.johndcook.com/blog/2024/08/31/sine-approx/</link>
					<comments>https://www.johndcook.com/blog/2024/08/31/sine-approx/#comments</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Sat, 31 Aug 2024 17:33:40 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[History]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245700</guid>

					<description><![CDATA[<p>This post started out as a Twitter thread. The text below is the same as that of the thread after correcting an error in the first part of the thread. I also added a footnote on a theorem the thread alluded to. *** The following approximation for sin(x) is remarkably accurate for 0 &#60; x [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/08/31/sine-approx/">Ancient accurate approximation for sine</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>This post started out as a <a href="https://x.com/AnalysisFact/status/1829626508006051905">Twitter thread</a>. The text below is the same as that of the thread after correcting an error in the first part of the thread. I also added a footnote on a theorem the thread alluded to.</p>
<p style="text-align: center;">***</p>
<p>The following approximation for sin(<em>x</em>) is remarkably accurate for 0 &lt; x &lt; π.</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/aryabhata1.svg" alt="\sin(x) \approx \frac{16x(\pi - x)}{5\pi^2 - 4x(\pi - x)}" width="209" height="46" /></p>
<p>The approximation is so good that you can&#8217;t see the difference between the exact value and the approximation until you get outside the range of the approximation.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-medium" src="https://www.johndcook.com/aryabhata2.png" width="480" height="360" /></p>
<p>Here&#8217;s a plot of just the error.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-medium" src="https://www.johndcook.com/aryabhata3.png" width="480" height="360" /></p>
<p>This is a very old approximation, dating back to Aryabhata I, around 500 AD.</p>
<p>In modern terms, it is a rational approximation, quadratic in the numerator and denominator. It&#8217;s not quite optimal since the ripples in the error function are not of equal height [1], but the coefficients are nice numbers.</p>
<p style="text-align: center;">***</p>
<p>As pointed out in the comments, replacing <em>x</em> with π/2 − <em>x</em> in order to get an approximation for cosine gives a much nicer equation.</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/aryabhata4.svg" alt="\cos x \approx \frac{\pi^2 - 4x^2}{\pi^2 + x^2}" width="137" height="45" /></p>
<p style="text-align: center;">***</p>
<p>[1] The equioscillation theorem says that the optimal approximation will have ripples of equal positive and negative amplitude. <a href="https://www.johndcook.com/blog/2024/09/03/optimal-rational-approximation/">This post</a> explores the equioscillation theorem further and finds how far Aryabhata&#8217;s is from optimal.</p>The post <a href="https://www.johndcook.com/blog/2024/08/31/sine-approx/">Ancient accurate approximation for sine</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/08/31/sine-approx/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Mentally multiply by π</title>
		<link>https://www.johndcook.com/blog/2024/08/31/mentally-multiply-by-pi/</link>
					<comments>https://www.johndcook.com/blog/2024/08/31/mentally-multiply-by-pi/#respond</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Sat, 31 Aug 2024 12:16:13 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Mental math]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245684</guid>

					<description><![CDATA[<p>This post will give three ways to multiply by π taken from [1]. Simplest approach Here&#8217;s a very simple observation about π : π ≈ 3 + 0.14 + 0.0014. So if you need to multiply by π, you need to multiply by 3 and by 14. Once you&#8217;ve multiplied by 14 once, you can [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/08/31/mentally-multiply-by-pi/">Mentally multiply by π</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>This post will give three ways to multiply by π taken from [1].</p>
<h2>Simplest approach</h2>
<p>Here&#8217;s a very simple observation about π :</p>
<p style="padding-left: 40px;">π ≈ 3 + 0.14 + 0.0014.</p>
<p>So if you need to multiply by π, you need to multiply by 3 and by 14. Once you&#8217;ve multiplied by 14 once, you can reuse your work.</p>
<p>For example, to compute 4π, you&#8217;d compute 4 × 3 = 12 and 4 × 14 = 56. Then</p>
<p style="padding-left: 40px;">4π ≈ 12 + 0.56 + 0.0056 = 12.5656.</p>
<p>The correct value is 12.56637… and so the error is .00077.</p>
<h2>First refinement</h2>
<p>Now of course π = 3.14159… and so the approximation above is wrong in the fourth decimal place. But you can squeeze out a little more accuracy with the observation</p>
<p style="padding-left: 40px;">π ≈ 3 + 0.14 + 0.0014 + 0.00014 = 3.14154.</p>
<p>Now if we redo our calculation of 4π we get</p>
<p style="padding-left: 40px;">4π ≈ 12 + 0.56 + 0.0056 + 0.00056 = 12.56616.</p>
<p>Now our error is .00021, which is 3.6 times smaller.</p>
<h2>Second refinement</h2>
<p>The approximation above is based on an underestimate of π. We can improve it a bit by adding half of our last term, based on</p>
<p style="padding-left: 40px;">π ≈ 3 + 0.14 + 0.0014 + 0.00014 + 0.00014/2 = 3.14157</p>
<p>So in our running example,</p>
<p style="padding-left: 40px;">4π ≈ 12 + 0.56 + 0.0056 + 0.00056 + 00028 = 12.5656 = 12.56654.</p>
<p>which has an error of 0.00007, which is three times smaller than above.</p>
<h2>Related posts</h2>
<ul>
<li class="link"><a href="https://www.johndcook.com/blog/mental-functions/">Mentally compute common functions</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2023/06/22/mentally-approximating-factorials/">Mentally approximating factorials</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2022/05/07/day-of-the-week/">Mentally calculating the day of the week</a></li>
</ul>
<p>[1] Trevor Lipscombe. Mental mathematics for multiples of π. The Mathematical Gazette, Vol. 97, No. 538 (March 2013), pp. 167–169</p>The post <a href="https://www.johndcook.com/blog/2024/08/31/mentally-multiply-by-pi/">Mentally multiply by π</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/08/31/mentally-multiply-by-pi/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>A better integral for the normal distribution</title>
		<link>https://www.johndcook.com/blog/2024/08/31/craigs-formula/</link>
					<comments>https://www.johndcook.com/blog/2024/08/31/craigs-formula/#respond</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Sat, 31 Aug 2024 11:45:09 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Integration]]></category>
		<category><![CDATA[Probability]]></category>
		<category><![CDATA[SciPy]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245683</guid>

					<description><![CDATA[<p>For a standard normal random variable Z, the probability that Z exceeds some cutoff z is given by If you wanted to compute this probability numerically, you could obviously evaluate its defining integral numerically. But as is often the case in numerical analysis, the most obvious approach is not the best approach. The range of [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/08/31/craigs-formula/">A better integral for the normal distribution</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>For a standard normal random variable <em>Z</em>, the probability that <em>Z</em> exceeds some cutoff <em>z</em> is given by</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/craig1.svg" alt="\mbox{Prob}(Z \geq z) = Q(z) = \frac{1}{\sqrt{2\pi}} \int_z^\infty \exp(-x^2/2)\, dx" width="389" height="47" /></p>
<p>If you wanted to compute this probability numerically, you could obviously evaluate its defining integral numerically. But as is often the case in numerical analysis, the most obvious approach is not the best approach. The range of integration is unbounded and it varies with the argument.</p>
<p>J. W. Craig [1] came up with a better integral representation, better from the perspective of numerical integration. The integration is always over the same finite interval, with the argument appearing inside the integrand. The integrand is smooth and bounded, well suited to numerical integration.</p>
<p>For positive <em>z</em>, Craig&#8217;s integer representation is</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/craig2.svg" alt="Q(z) = \frac{1}{\pi} \int_0^{\pi/2} \exp\left( -\frac{z^2}{2\sin^2 \theta} \right) \, d\theta" width="285" height="50" /></p>
<h2>Illustration</h2>
<p>To show that the Craig&#8217;s integral is easy to integrate numerically, we&#8217;ll evaluate it using Gaussian quadrature with only 10 integration points.</p>
<pre>    from numpy import sin, exp, pi
    from scipy import integrate
    from scipy.stats import norm

    for x in [0.5, 2, 5]:
        q, _ = integrate.fixed_quad(
            lambda t: exp(-x**2 / (2*sin(t)**2))/pi,
            0.0, pi/2, n=10)
        print(q, norm.sf(x))
</pre>
<p>(SciPy uses <code>sf</code> (&#8220;survival function&#8221;) for the CCDF. More on that <a href="https://www.johndcook.com/blog/distributions_scipy/">here</a>.)</p>
<p>The code above produces the following.</p>
<pre>    0.30858301 0.30853754
    0.02274966 0.02275013
    2.86638437e-07 2.86651572e-07
</pre>
<p>So with 10 integration points, we get four correct figures. And the accuracy seems to be consistent for small, medium, and large values of <em>x</em>. (Five standard deviations is pretty far out in the tail of a normal distribution, as evidenced by the small value of the integral.)</p>
<h2>Related posts</h2>
<ul>
<li class="link"><a href="https://www.johndcook.com/blog/2023/04/29/golden-integration/">Golden integration</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2023/11/26/numerical-integral-with-a-singularity/">Numeric integral with a singularity</a></li>
<li class="link"><a href="https://www.johndcook.com/OrthogonalPolynomials.pdf">Orthogonal polynomials and Gaussian quadrature</a></li>
</ul>
<p>[1] J. W. Craig, A new, simple and exact result for calculating the probability of error for two-dimensional signal constellations, in TEEE MILCOM&#8217;91 Conf. Rec., Boston, MA (1991) рр. 25.2.1-25.5.5.</p>The post <a href="https://www.johndcook.com/blog/2024/08/31/craigs-formula/">A better integral for the normal distribution</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/08/31/craigs-formula/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Drawing with a compass on a globe</title>
		<link>https://www.johndcook.com/blog/2024/08/30/compass-on-globe/</link>
					<comments>https://www.johndcook.com/blog/2024/08/30/compass-on-globe/#comments</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Fri, 30 Aug 2024 13:09:19 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Geometry]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245681</guid>

					<description><![CDATA[<p>Take a compass and draw a circle on a globe. Then take the same compass, opened to the same width, and draw a circle on a flat piece of paper. Which circle has more area? If the circle is small compared to the radius of the globe, then the two circles will be approximately equal [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/08/30/compass-on-globe/">Drawing with a compass on a globe</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>Take a compass and draw a circle on a globe. Then take the same compass, opened to the same width, and draw a circle on a flat piece of paper. Which circle has more area?</p>
<p>If the circle is small compared to the radius of the globe, then the two circles will be approximately equal because a small area on a globe is approximately flat.</p>
<p>To get an idea what happens for larger circles, let&#8217;s a circle on the globe as large as possible, i.e. the equator. If the globe has radius <em>r</em>, then to draw the equator we need our compass to be opened a width of √2 <em>r</em>, the distance from the north pole to the equator along a straight line cutting through the globe.</p>
<p>The area of a hemisphere is 2π<em>r</em>². If we take our compass and draw a circle of radius √2 <em>r</em> on a flat surface we also get an area of 2π<em>r</em>². And by continuity we should expect that if we draw a circle that is nearly as big as the equator then the corresponding circle on a flat surface should have approximately the same area.</p>
<p>Interesting. This says that our compass will draw a circle with the same area whether on a globe or on a flat surface, at least approximately, if the width of the compass sufficiently small or sufficiently large. In fact, we get <em>exactly</em> the same area, regardless of how wide the compass is opened up. We haven&#8217;t proven this, only given a plausibility argument, but you can find a proof in [1].</p>
<p>Note that the width <em>w</em> of the compass is the radius of the circle drawn on a flat surface, but it is <strong>not</strong> the radius of the circle drawn on the globe. The width <em>w</em> is greater than the radius of the circle, but less than the distance <em>along the sphere</em> from the center of the circle. In the case of the equator, the radius of the circle is <em>r</em>, the width of the compass is √2 <em>r</em> , and the distance along the sphere from the north pole to the equator is <em>πr</em>/2.</p>
<h2>Related posts</h2>
<ul>
<li class="link"><a href="https://www.johndcook.com/blog/2023/08/09/hypersphere-cap/">Area and volume of hypersphere cap</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2023/04/14/hendecagon/">How Dürer drew an 11-sided figure</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2016/08/28/duality-in-spherical-trigonometry/">Duality in spherical trig</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2023/05/10/map-distortion/">How faithful can a map be?</a></li>
</ul>
<p>[1] Nick Lord. On an alternative formula for the area of a spherical cap. The Mathematical Gazette, Vol. 102, No. 554 (July 2018), pp. 314–316</p>The post <a href="https://www.johndcook.com/blog/2024/08/30/compass-on-globe/">Drawing with a compass on a globe</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/08/30/compass-on-globe/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>The negative binomial distribution and Pascal&#8217;s triangle</title>
		<link>https://www.johndcook.com/blog/2024/08/29/negative-binomial-pascals-triangle/</link>
					<comments>https://www.johndcook.com/blog/2024/08/29/negative-binomial-pascals-triangle/#respond</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Thu, 29 Aug 2024 14:54:01 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Probability and Statistics]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245680</guid>

					<description><![CDATA[<p>The Poisson probability distribution gives a simple, elegant model for count data. You can even derive from certain assumptions that data must have a Poisson distribution. Unfortunately reality doesn&#8217;t often go along with those assumptions. A Poisson random variable with mean λ also has variance λ. But it&#8217;s often the case that data that would [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/08/29/negative-binomial-pascals-triangle/">The negative binomial distribution and Pascal’s triangle</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>The Poisson probability distribution gives a simple, elegant model for count data. You can even derive from certain assumptions that data <em>must</em> have a Poisson distribution. Unfortunately reality doesn&#8217;t often go along with those assumptions.</p>
<p>A Poisson random variable with mean λ also has variance λ. But it&#8217;s often the case that data that would seem to follow a Poisson distribution has a variance greater than its mean. This phenomenon is called <b>over-dispersion</b>: the dispersion (variance) is larger than a Poisson distribution assumption would allow.</p>
<p>One way to address over-dispersion is to use a negative binomial distribution. This distribution has two parameters, <em>r</em> and <em>p</em>, and has the following probability mass function (PMF).</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/negbinom.svg" alt="P(X = x) = \binom{r + x - 1}{x} p^r(1-p)^x" width="272" height="48" /></p>
<p>As the parameter <em>r</em> goes to infinity, the negative binomial distribution converges to a Poisson distribution. So you can think of the negative binomial distribution as a generalization of the Poisson distribution.</p>
<p><a href="https://www.johndcook.com/negative_binomial.pdf">These notes</a> go into the negative binomial distribution in some detail, including where its name comes from.</p>
<p>If the parameter <em>r</em> is a non-negative integer, then the binomial coefficients in the PMF for the negative binomial distribution are on the (<em>r</em>+1)st diagonal of Pascal&#8217;s triangle.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-medium" src="https://www.johndcook.com/pascaltriangle.png" alt="Pascal's triangle" width="400" height="329" /></p>
<p>The case <em>r</em> = 0 corresponds to the first diagonal, the one consisting of all 1s. The case <em>r</em> = 1 corresponds to the second diagonal consisting of consecutive integers. The case <em>r</em> = 2 corresponds to the third diagonal, the one consisting of triangular numbers. And so forth.</p>
<h2>Related posts</h2>
<ul>
<li class='link'><a href='https://www.johndcook.com/blog/2016/07/05/distribution-of-numbers-in-pascals-triangle/'>Distribution of numbers in Pascal&#8217;s triangle</a></li>
<li class='link'><a href='https://www.johndcook.com/blog/2020/06/28/the-ubiquitous-sierpinski/'>Five places the Sierpiński triangle shows up</a></li>
<li class='link'><a href='https://www.johndcook.com/blog/2009/09/22/negative-binomial-distribution/'>Three views of the negative binomial distribution</a></li>
</ul>The post <a href="https://www.johndcook.com/blog/2024/08/29/negative-binomial-pascals-triangle/">The negative binomial distribution and Pascal’s triangle</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/08/29/negative-binomial-pascals-triangle/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>A strange take on the harmonic series</title>
		<link>https://www.johndcook.com/blog/2024/08/29/strange-harmonic-series/</link>
					<comments>https://www.johndcook.com/blog/2024/08/29/strange-harmonic-series/#comments</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Thu, 29 Aug 2024 12:11:24 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Math]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245679</guid>

					<description><![CDATA[<p>It is well known that the harmonic series 1 + ½ + ⅓ + ¼ + … diverges. But if you take the denominators as numbers in base 11 or higher, the series converges [1]. I wonder what inspired this observation. Maybe Brewster was bored, teaching yet another cohort of students that the harmonic series [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/08/29/strange-harmonic-series/">A strange take on the harmonic series</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>It is well known that the harmonic series</p>
<p style="padding-left: 40px;">1 + ½ + ⅓ + ¼ + …</p>
<p>diverges. But if you take the denominators as numbers in base 11 or higher, the series converges [1].</p>
<p>I wonder what inspired this observation. Maybe Brewster was bored, teaching yet another cohort of students that the harmonic series diverges, and let his mind wander.</p>
<h2>Proof</h2>
<p>Let <em>f</em>(<em>n</em>) be the function that takes a positive integer <em>n</em>, writes it in base 10, then reinterprets the result as a number in base <em>b</em> where <em>b</em> &gt; 10. Brewster is saying that the sum of the series 1/<em>f</em>(<em>n</em>) converges.</p>
<p>To see this, note that the first 10 terms are less than or equal to 1. The next 100 terms are less than 1/<em>b</em>. The next 1000 terms are less than 1/<em>b</em>², and so on. This means the series is bounded by the geometric series 10 (10/<em>b</em>)<sup><em>m</em></sup>.</p>
<h2>Python</h2>
<p>Incidentally, despite being an unusual function, <em>f</em> is very easy to implement in Python:</p>
<pre>   def f(n, b): return int(str(n), b)</pre>
<h2>Citation</h2>
<p>Brewster&#8217;s note was so brief that I will quote it here in full.</p>
<blockquote><p>The [harmonic series] is divergent. But if the denominators of the terms are read as numbers in scale 11 or any higher scale, the series is convergent, and the sum is greater than 2.828 and less than 26.29. The convergence is rather slow. I estimate that, to find the last number by direct addition, one would have to work out 10<sup>90</sup> terms, to about 93 places of decimals.</p></blockquote>
<p>[1] G. W. Brewster. An Old Result in a New Dress. The Mathematical Gazette, Vol. 37, No. 322 (Dec., 1953), pp. 269&ndash;270.</p>The post <a href="https://www.johndcook.com/blog/2024/08/29/strange-harmonic-series/">A strange take on the harmonic series</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/08/29/strange-harmonic-series/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Variance matters more than mean in the extremes</title>
		<link>https://www.johndcook.com/blog/2024/08/26/variance-in-the-extemes/</link>
					<comments>https://www.johndcook.com/blog/2024/08/26/variance-in-the-extemes/#comments</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Mon, 26 Aug 2024 16:18:12 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Probability and Statistics]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245678</guid>

					<description><![CDATA[<p>Suppose you have two normal random variables, X and Y, and that the variance of X is less than the variance of Y. Let M be an equal mixture of X and Y. That is, to sample from M, you first chose X or Y with equal probability, then you choose a sample from the [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/08/26/variance-in-the-extemes/">Variance matters more than mean in the extremes</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>Suppose you have two normal random variables, <em>X</em> and <em>Y</em>, and that the variance of <em>X</em> is less than the variance of <em>Y</em>.</p>
<p>Let <em>M</em> be an equal mixture of <em>X</em> and <em>Y</em>. That is, to sample from <em>M</em>, you first chose <em>X</em> or <em>Y</em> with equal probability, then you choose a sample from the random variable you chose.</p>
<p>Now suppose you&#8217;ve observed an extreme value of <em>M</em>. Then it is more likely the that the value came from <em>Y</em>. The means of <em>X</em> and <em>Y</em> don&#8217;t matter, other than determining the cutoff for what &#8220;extreme&#8221; means.</p>
<h2>High-level math</h2>
<p>To state things more precisely, there is some value <em>t</em> such that the posterior probability that a sample <em>m</em> from <em>M</em> came from <em>Y</em>, given that |<em>m</em>| &gt; <em>t</em>, is greater than the posterior probability that <em>m</em> came from <em>X</em>.</p>
<p>Let&#8217;s just look at the right-hand tails, even though the principle applies to both tails. If <em>X</em> and <em>Y</em> have the variance, but the mean of <em>X</em> is greater, then larger values of <em>Z</em> are more likely to have come from <em>X</em>. Now suppose the variance of <em>Y</em> is larger. As you go further out in the right tail of <em>M</em>, the posterior probability of an extreme value having come from <em>Y</em> increases, and eventually it surpasses the posterior probability of the sample having come from <em>Y</em>. If <em>X</em> has a larger mean than <em>Y</em> that will delay the point at which the posterior probability of <em>Y</em> passes the posterior probability of <em>X</em>, but eventually variance matters more than mean.</p>
<h2>Detailed math</h2>
<p>Let&#8217;s give a name to the random variable that determines whether we choose <em>X</em> or <em>Y</em>. Let&#8217;s call it <em>C</em> for coin flip, and assume <em>C</em> takes on 0 and 1 each with probability 1/2. If <em>C</em> = 0 we sample from <em>X</em> and if <em>C</em> = 1 we sample from <em>Y</em>. We want to compute the probability P(<em>C</em> = 1 | <em>M</em> ≥ <em>t</em>).</p>
<p>Without loss of generality we can assume <em>X</em> has mean 0 and variance 1. (Otherwise transform <em>X</em> and <em>Y</em> by subtracting off the mean of <em>X</em> then divide by the standard deviation of <em>X</em>.) Denote the mean of <em>Y</em> by μ and the standard deviation by σ.</p>
<p>From Bayes&#8217; theorem we have</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/xy1.svg" alt="\text{P}(C = 1 \mid M \geq t) = \frac{ \text{P}(Y \geq t) }{ \text{P}(X \geq t) + \text{P}(Y \geq t) } = \frac{\Phi^c\left(\frac{t-\mu}{\sigma}\right)}{\Phi^c(t) + \Phi^c\left(\frac{t-\mu}{\sigma}\right)}" width="488" height="80" /></p>
<p>where Φ<sup><em>c</em></sup>(<em>t</em>) = P(<em>Z</em> ≥ <em>t</em>) for a standard normal random variable.</p>
<p>Similarly, to compute P(<em>C</em> = 1 | <em>M</em> ≤ <em>t</em>) just flip the direction of the inequality signs replace Φ<sup><em>c</em></sup>(<em>t</em>) = P(<em>Z</em> ≥ <em>t</em>) with Φ(<em>t</em>) = P(<em>Z</em> ≤ <em>t</em>).</p>
<p>The calculation for P(<em>C</em> = 1  |  |<em>M</em>| ≥ <em>t</em>) is similar</p>
<h2>Example</h2>
<p>Suppose <em>Y</em> has mean −2 and variance 10. The blue curve shows that a large negative sample from <em>M</em> very likely comes from <em>Y</em> and the orange line shows that large positive sample very likely comes from <em>Y</em> as well.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-medium" style="background-color: white;" src="https://www.johndcook.com/xy2.svg" width="614" height="461" /></p>
<p>The dip in the orange curve shows the transition zone where <em>Y</em>&#8216;s advantage due to a larger mean gives way to the disadvantage of a smaller variance. This illustrates that the posterior probability of <em>Y</em> increases <em>eventually</em> but not necessarily monotonically.</p>
<p>Here&#8217;s a plot showing the probability of a sample having come from <em>Y</em> depending on its absolute value.</p>
<p><img loading="lazy" decoding="async" class="size-medium aligncenter" style="background-color: white;" src="https://www.johndcook.com/xy3.svg" width="614" height="461" /></p>
<h2>Related posts</h2>
<ul>
<li class="link"><a href="https://www.johndcook.com/blog/2022/04/13/how-flat-is-a-normal-mixture-on-top/">How flat is a normal mixture on top?</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2015/03/09/why-isnt-everything-normally-distributed/">Why isn&#8217;t everything normally distributed?</a></li>
</ul>The post <a href="https://www.johndcook.com/blog/2024/08/26/variance-in-the-extemes/">Variance matters more than mean in the extremes</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/08/26/variance-in-the-extemes/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Increasing speed due to friction</title>
		<link>https://www.johndcook.com/blog/2024/08/24/increasing-speed-due-to-friction/</link>
					<comments>https://www.johndcook.com/blog/2024/08/24/increasing-speed-due-to-friction/#comments</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Sat, 24 Aug 2024 15:52:29 +0000</pubDate>
				<category><![CDATA[Science]]></category>
		<category><![CDATA[Orbital mechanics]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245675</guid>

					<description><![CDATA[<p>Orbital mechanics is fascinating. I&#8217;ve learned a bit about it for fun, not for profit. I seriously doubt Elon Musk will ever call asking me to design an orbit for him. [1] One of the things that makes orbital mechanics interesting is that it can be counter-intuitive. For example, atmospheric friction can make a satellite [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/08/24/increasing-speed-due-to-friction/">Increasing speed due to friction</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>Orbital mechanics is fascinating. I&#8217;ve learned a bit about it for fun, not for profit. I seriously doubt Elon Musk will ever call asking me to design an orbit for him. [1]</p>
<p>One of the things that makes orbital mechanics interesting is that it can be counter-intuitive. For example, atmospheric <strong>friction can make a satellite move faster</strong>. How can this be? Doesn&#8217;t friction always slow things down?</p>
<p>Friction does reduce a satellite&#8217;s tangential velocity, causing it to move into a lower orbit, which increases its velocity. It&#8217;s weird to think about, but the details are worked out in [2].</p>
<p>Note the date on the article: May 1958. The paper was written in response to Sputnik 1 which launched in October 1957. Parkyn&#8217;s described the phenomenon of acceleration due to friction in general, and how it applied to Sputnik in particular.</p>
<h2>Related posts</h2>
<ul>
<li class="link"><a href="https://www.johndcook.com/blog/2020/06/15/hohmann-transfer-orbit/">Hohmann transfer orbit</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2020/02/08/arenstorf-orbit/">Arenstorf&#8217;s orbit</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2022/12/15/sphere-of-infuence/">Sphere of influence</a></li>
</ul>
<p>[1] I had a lead on a project with NASA once, but it wasn&#8217;t orbital mechanics, and the lead didn&#8217;t materialize.</p>
<p>[2] D. G. Parkyn. The Effect of Friction on Elliptic Orbits. The Mathematical Gazette. Vol. 42, No. 340 (May, 1958), pp. 96-98</p>The post <a href="https://www.johndcook.com/blog/2024/08/24/increasing-speed-due-to-friction/">Increasing speed due to friction</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/08/24/increasing-speed-due-to-friction/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Ptolemy&#8217;s theorem</title>
		<link>https://www.johndcook.com/blog/2024/08/24/ptolemys-theorem/</link>
					<comments>https://www.johndcook.com/blog/2024/08/24/ptolemys-theorem/#respond</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Sat, 24 Aug 2024 13:42:06 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Geometry]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245673</guid>

					<description><![CDATA[<p>Draw a quadrilateral by pick four arbitrary points on a circle and connecting them cyclically. Now multiply the lengths of the pairs of opposite sides. In the diagram below this means multiplying the lengths of the two horizontal-ish blue sides and the two vertical-ish orange sides. Ptolemy&#8217;s theorem says that the sum of the two [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/08/24/ptolemys-theorem/">Ptolemy’s theorem</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>Draw a quadrilateral by pick four arbitrary points on a circle and connecting them cyclically.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-medium" src="https://www.johndcook.com/ptolemy0.png" alt="inscribed quadrilateral" width="480" height="360" /></p>
<p>Now multiply the lengths of the pairs of opposite sides. In the diagram below this means multiplying the lengths of the two horizontal-ish blue sides and the two vertical-ish orange sides.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-medium" src="https://www.johndcook.com/ptolemy1.png" alt="quadrilateral with opposite sides colored" width="480" height="360" /></p>
<p>Ptolemy&#8217;s theorem says that the sum of the two products described above equals the product of the diagonals.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-medium" src="https://www.johndcook.com/ptolemy2.png" alt="inscribed quadrilateral with diagonals" width="480" height="360" /></p>
<p>To put it in colorful terms, the product of the blue sides plus the product of the orange sides equals the product of the green diagonals.</p>
<p>The converse of Ptolemy&#8217;s theorem also holds. If the relationship above holds for a quadrilateral, then the quadrilateral can be inscribed in a circle.</p>
<p>Note that if the quadrilateral in Ptolemy&#8217;s theorem is a rectangle, then the theorem reduces to the Pythagorean theorem.</p>
<h2>Related posts</h2>
<ul>
<li class="link"><a href="https://www.johndcook.com/blog/2024/02/25/quadrilateral-area-determinant/">Area of a quadrilateral as a determinant</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2023/01/23/van-aubels-theorem/">Van Aubel&#8217;s theorem</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2014/11/23/compute-trig-tables/">Ptolemy and trig tables</a></li>
</ul>The post <a href="https://www.johndcook.com/blog/2024/08/24/ptolemys-theorem/">Ptolemy’s theorem</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/08/24/ptolemys-theorem/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Rule for converting trig identities into hyperbolic identities</title>
		<link>https://www.johndcook.com/blog/2024/08/20/osborn-rule/</link>
					<comments>https://www.johndcook.com/blog/2024/08/20/osborn-rule/#respond</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Tue, 20 Aug 2024 14:14:31 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245669</guid>

					<description><![CDATA[<p>There is a simple rule of thumb for converting between (circular) trig identities and hyperbolic trig identities known as Osborn&#8217;s rule: stick an h on the end of trig functions and flip signs wherever two sinh functions are multiplied together. Examples For example, the circular identity sin(θ + φ) = sin(θ) cos(φ) + cos(θ) sin(φ) [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/08/20/osborn-rule/">Rule for converting trig identities into hyperbolic identities</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>There is a simple rule of thumb for converting between (circular) trig identities and hyperbolic trig identities known as Osborn&#8217;s rule: stick an <em>h</em> on the end of trig functions and flip signs wherever two sinh functions are multiplied together.</p>
<h2>Examples</h2>
<p>For example, the circular identity</p>
<p style="padding-left: 40px;">sin(θ + φ) = sin(θ) cos(φ) + cos(θ) sin(φ)</p>
<p>becomes the hyperbolic identity</p>
<p style="padding-left: 40px;">sinh(θ + φ) = sinh(θ) cosh(φ) + cosh(θ) sinh(φ)</p>
<p>but the identity</p>
<p style="padding-left: 40px;">2 sin(θ) sin(φ) = cos(θ − φ) − cos(θ + φ)</p>
<p>becomes</p>
<p style="padding-left: 40px;">2 sinh(θ) sinh(φ) = cosh(θ + φ) − cosh(θ − φ)</p>
<p>because there are two sinh terms.</p>
<h2>Derivation</h2>
<p>Osborn&#8217;s rule isn&#8217;t deep. It&#8217;s a straight-forward application of Euler&#8217;s theorem:</p>
<p style="padding-left: 40px;">exp(<em>i</em>θ) = cos(θ) + <em>i</em> sin(θ).</p>
<p>More specifically, Osborn&#8217;s rule follows from two corollaries of Euler&#8217;s theorem:</p>
<p style="padding-left: 40px;">sin(<em>i</em>θ) = <em>i</em> sinh(θ)<br />
cos(<em>i</em>θ) = cosh(θ)</p>
<h2>Why bother?</h2>
<p>The advantage of Osborn&#8217;s rule is that it saves time, and perhaps more importantly, it reduces the likelihood of making a mistake.</p>
<p>You could always derive any identity you need on the spot. All trig identities—circular or hyperbolic—are direct consequences of Euler&#8217;s theorem. But it saves time to work at a higher level of abstraction. And as I&#8217;ve often said in the context of more efficient computer usage, the advantage of doing things faster is not so much the time directly saved but the decreased probability of losing your train of thought.</p>
<h2>Caveats</h2>
<p>Osborn&#8217;s rule included <em>implicit</em> expressions of sinh, such as in tanh = sinh / cosh. So, for example, the circular identity</p>
<p style="padding-left: 40px;">tan(2θ) = 2 tan(θ) / (1 − tan²(θ))</p>
<p>becomes</p>
<p style="padding-left: 40px;">tanh(2θ) = 2 tanh(θ) / (1 + tanh²(θ))</p>
<p>because the tanh² term implicitly contains two sinh terms.</p>
<h2>Original note</h2>
<p>Osborn&#8217;s original note [1] from 1902 is so short that I include the entire text below:</p>
<p><img loading="lazy" decoding="async" src="https://www.johndcook.com/osborn.png" width="1136" height="581" class="aligncenter size-medium" /></p>
<h2>Related posts</h2>
<ul>
<li class='link'><a href='https://www.johndcook.com/blog/2023/10/04/hyperbolic-trig/'>Geometric derivation of hyperbolic functions</a></li>
<li class='link'><a href='https://www.johndcook.com/blog/2023/10/06/hyperbolic-tangent-sum/'>Hyperbolic tangent sum</a></li>
<li class='link'><a href='https://www.johndcook.com/blog/2009/09/21/gudermannian/'>Mercator and Gudermann</a></li>
</ul>
<p>[1] G. Osborn. Mnemonic for Hyperbolic Formulae. The Mathematical Gazette, Vol. 2, No. 34 (Jul., 1902), p. 189</p>The post <a href="https://www.johndcook.com/blog/2024/08/20/osborn-rule/">Rule for converting trig identities into hyperbolic identities</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/08/20/osborn-rule/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Interpolation and the cotanc function</title>
		<link>https://www.johndcook.com/blog/2024/08/19/tanc-and-cotanc/</link>
					<comments>https://www.johndcook.com/blog/2024/08/19/tanc-and-cotanc/#respond</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Mon, 19 Aug 2024 11:25:29 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Interpolation]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245667</guid>

					<description><![CDATA[<p>This weekend I wrote three posts related to interpolation: Compression and interpolation Bessel, Everett, and Lagrange interpolation Binomial coefficients with non-integer arguments The first post looks at reducing the size of mathematical tables by switching for linear to quadratic interpolation. The immediate application is obsolete, but the principles apply to contemporary problems. The second post [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/08/19/tanc-and-cotanc/">Interpolation and the cotanc function</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>This weekend I wrote three posts related to interpolation:</p>
<ul>
<li class="link"><a href="https://www.johndcook.com/blog/2024/08/17/compression-and-interpolation/">Compression and interpolation</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2024/08/18/bessel-everett/">Bessel, Everett, and Lagrange interpolation</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2024/08/18/real-binomial-coefficients/">Binomial coefficients with non-integer arguments</a></li>
</ul>
<p>The first post looks at reducing the size of mathematical tables by switching for linear to quadratic interpolation. The immediate application is obsolete, but the principles apply to contemporary problems.</p>
<p>The second post looks at alternatives to Lagrange interpolation that are much better suited to hand calculation. The final post is a tangent off the middle post.</p>
<h2>Tau and sigma functions</h2>
<p>In the process of writing the posts above, I looked at <a href="https://archive.org/details/chamberssixfigur0000ljco/page/n5/mode/2up">Chambers Six Figure Mathematical Tables</a> from 1964. There I saw a couple curious functions I hadn&#8217;t run into before, functions the author called τ and σ.</p>
<p style="padding-left: 40px;">τ(<em>x</em>) = <em>x</em> cot <em>x</em><br />
σ(<em>x</em>) = <em>x</em> csc <em>x</em></p>
<p>So why introduce these two functions? The cotangent and cosecant functions have a singularity at 0, and so its difficult to tabulate and interpolate these functions. I touched on something similar in my recent post on <a href="https://www.johndcook.com/blog/2024/08/08/interpolating-gamma/">interpolating the gamma function</a>: because the function grows rapidly, linear interpolation gives bad results. Interpolating the log of the gamma function gives much better results.</p>
<p>Chambers tabulates τ(<em>x</em>) and σ(<em>x</em>) because these functions are easy to interpolate.</p>
<h2>The cotanc function</h2>
<p>I&#8217;ll refer to Chambers&#8217; τ function as the cotanc function. This is a whimsical choice, not a name used anywhere else as far as I know. The reason for the name is as follows. The sinc function</p>
<p style="padding-left: 40px;">sinc(<em>x</em>) = sin(<em>x</em>)/<em>x</em></p>
<p>comes up frequently in signal processing, largely because it&#8217;s the Fourier transform of the indicator function of an interval. There are a few other functions that tack a <em>c</em> onto the end of a function to indicate it has been divided by <em>x</em>, such as the <a href="https://www.johndcook.com/blog/2012/02/01/jinc-function/">jinc function</a>.</p>
<p>The function tan(<em>x</em>)/<em>x</em> is sometimes called the tanc function, though this name is far less common than sinc. The cotangent function is the reciprocal of the tangent function, so I&#8217;m calling the reciprocal of the tanc function the cotanc function. Maybe it should be called the cotank function just for fun. For category theorists this brings up images of a tank that fires backward.</p>
<h2>Practicality of the cotanc function</h2>
<p>As noted above, the cotangent function is ill-behaved near 0, but the cotanc function is very nicely behaved near 0. The cotanc function has singularities at non-zero multiples of π but multiplying by <em>x</em> removes the singularity at 0.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-medium" src="https://www.johndcook.com/cotank.png" width="640" height="480" /></p>
<p>As noted <a href="https://www.johndcook.com/blog/2024/08/17/compression-and-interpolation/">here</a>, interpolation error depends on the size of the derivatives of the function being interpolated. Since the cotanc function is flat and smooth, it has small derivatives and thus small interpolation error.</p>The post <a href="https://www.johndcook.com/blog/2024/08/19/tanc-and-cotanc/">Interpolation and the cotanc function</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/08/19/tanc-and-cotanc/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Binomial coefficients with non-integer arguments</title>
		<link>https://www.johndcook.com/blog/2024/08/18/real-binomial-coefficients/</link>
					<comments>https://www.johndcook.com/blog/2024/08/18/real-binomial-coefficients/#respond</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Sun, 18 Aug 2024 21:25:38 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Interpolation]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245666</guid>

					<description><![CDATA[<p>When n and r are positive integers, with n ≥ r, there is an intuitive interpretation of the binomial coefficient C(n, r), namely the number of ways to select r things from a set of n things. For this reason C(n, r) is usually pronounced &#8220;n choose r.&#8221; But what might something like C(4.3, 2)? [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/08/18/real-binomial-coefficients/">Binomial coefficients with non-integer arguments</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>When <em>n</em> and <em>r</em> are positive integers, with <em>n</em> ≥ <em>r</em>, there is an intuitive interpretation of the binomial coefficient <em>C</em>(<em>n</em>, <em>r</em>), namely the number of ways to select <em>r</em> things from a set of <em>n</em> things. For this reason <em>C</em>(<em>n</em>, <em>r</em>) is usually pronounced &#8220;<em>n</em> choose <em>r</em>.&#8221;</p>
<p>But what might something like <em>C</em>(4.3, 2)? The number of ways to choose two giraffes out of a set of 4.3 giraffes?! There is no combinatorial interpretation for binomial coefficients like these, though they regularly come up in applications.</p>
<p>It is possible to define binomial coefficients when <em>n</em> and <em>r</em> are real or even complex numbers. These more general binomial coefficients are in this liminal zone of topics that come up regularly, but not so regularly that they&#8217;re widely known. I wrote an <a href="https://www.johndcook.com/blog/binomial_coefficients/">article</a> about this a decade ago, and I&#8217;ve had numerous occasions to link to it ever since.</p>
<p>The <a href="https://www.johndcook.com/blog/2024/08/18/bessel-everett/">previous post</a> implicitly includes an application of general binomial coefficients. The post alludes to coefficients that come up in Bessel&#8217;s interpolation formula but doesn&#8217;t explicitly say what they are. These coefficients <em>B</em><sub><em>k</em></sub> can be defined in terms of the Gaussian interpolation coefficients, which are in turn defined by binomial coefficients with non-integer arguments.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-medium" style="background-color: white;" src="https://www.johndcook.com/bessel_coeff.svg" alt="\begin{eqnarray*} G_{2n} &amp;=&amp; {p + n - 1 \choose 2n} \\ G_{2n+1} &amp;=&amp; {p + n \choose 2n + 1} \\ B_{2n} &amp;=&amp; \frac{1}{2}G_{2n} \\ B_{2n+1} &amp;=&amp; G_{2n+1} - \frac{1}{2} G_{2n} \end{eqnarray*} " width="238" height="202" /></p>
<p>Note that 0 &lt; <em>p</em> &lt; 1.</p>
<p>The coefficients in Everett&#8217;s interpolation formula can also be expressed simply in terms of the Gauss coefficients.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-medium" style="background-color: white;" src="https://www.johndcook.com/everett_coeff.svg" alt="\begin{eqnarray*} E_{2n} &amp;=&amp; G_{2n} - G_{2n+1} \\ F_{2n} &amp;=&amp; G_{2n+1} \\ \end{eqnarray*} " width="202" height="50" /></p>The post <a href="https://www.johndcook.com/blog/2024/08/18/real-binomial-coefficients/">Binomial coefficients with non-integer arguments</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/08/18/real-binomial-coefficients/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Bessel, Everett, and Lagrange interpolation</title>
		<link>https://www.johndcook.com/blog/2024/08/18/bessel-everett/</link>
					<comments>https://www.johndcook.com/blog/2024/08/18/bessel-everett/#respond</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Sun, 18 Aug 2024 20:26:42 +0000</pubDate>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Interpolation]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245665</guid>

					<description><![CDATA[<p>I never heard of Bessel or Everett interpolation until long after college. I saw Lagrange interpolation several times. Why Lagrange and not Bessel or Everett? First of all, Bessel interpolation and Everett interpolation are not different kinds of interpolation; they are different algorithms for carrying out the same interpolation as Lagrange. There is a unique [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/08/18/bessel-everett/">Bessel, Everett, and Lagrange interpolation</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>I never heard of Bessel or Everett interpolation until long after college. I saw Lagrange interpolation several times. Why Lagrange and not Bessel or Everett?</p>
<p>First of all, Bessel interpolation and Everett interpolation are not different <strong>kinds</strong> of interpolation; they are different <strong>algorithms</strong> for carrying out the same interpolation as Lagrange. There is a unique polynomial of degree <em>n</em> fitting a function at <em>n</em> + 1 points, and all three methods evaluate this same polynomial.</p>
<p>The advantages of Bessel&#8217;s approach or Everett&#8217;s approach to interpolation are practical, not theoretical. In particular, these algorithms are practical when interpolating functions from tables, by hand. This was a lost art by the time I went to college. Presumably some of the older faculty had spent hours computing with tables, but they never said anything about it.</p>
<p>Bessel interpolation and Everett interpolation are minor variations on the same theme. This post will describe both at such a high level that there&#8217;s no difference between them. This post is high-level because that&#8217;s exactly what seems to be missing in the literature. You can easily find older books that go into great detail, but I believe you&#8217;ll have a harder time finding a survey presentation like this.</p>
<p>Suppose you have a function <em>f</em>(<em>x</em>) that you want to evaluate at some value <em>p</em>. Without loss of generality we can assume our function has been shifted and scaled so that we have tabulated <em>f</em> at integers our value <em>p</em> lies between 0 and 1. </p>
<p>Everett&#8217;s formula (and Bessel&#8217;s) cleanly separates the parts of the interpolation formula that depend on <em>f</em> and the parts that depend on <em>p</em>. </p>
<p>The values of the function <em>f</em> enter through the differences of the values of <em>f</em> at consecutive integers, and differences of these differences, etc. These differences are easy to calculate by hand, and sometimes were provided by the table publisher. </p>
<p>The functions of <em>p</em> are independent of the function being interpolated, so these functions, the coefficients in Bessel&#8217;s formula and Everett&#8217;s formula, could be tabulated as well. </p>
<p>If the function differences are tabulated, and the functions that depend on <em>p</em> are tabulated, you could apply polynomial interpolation without ever having to explicitly evaluate a polynomial. You&#8217;d just need to evaluate a sort of dot product, a sum of numbers that depend on <em>f</em> multiplied by numbers that depend on <em>p</em>.</p>
<p>Another advantage of Bessel&#8217;s and Everett&#8217;s interpolation formulas is that they can be seen as a sequence of refinements. First you obtain the linear interpolation result, then refine it to get the quadratic interpolation result, then add terms to get the cubic interpolation result, etc. </p>
<p>This has several advantages. First, you have the satisfaction of seeing progress along the way; Lagrange interpolation may give you nothing useful until you&#8217;re done. Related to this is a kind of error checking: you have a sense of where the calculations are going, and intermediate results that violate your expectations are likely to be errors. Finally, you can carry out the calculations for the smallest terms in with less precision. You can use fewer and fewer digits in your hand calculations as you compute successive refinements to your result.</p>
<h2>Related posts</h2>
<ul>
<li class='link'><a href='https://www.johndcook.com/blog/2024/08/17/compression-and-interpolation/'>Compression and interpolation</a></li>
<li class='link'><a href='https://www.johndcook.com/blog/2024/06/03/using-a-table-of-logarithms/'>Using a table of logarithms</a></li>
<li class='link'><a href='https://www.johndcook.com/blog/2023/02/18/spline-fit/'>How well does a spline fit a function?</a></li>
</ul>The post <a href="https://www.johndcook.com/blog/2024/08/18/bessel-everett/">Bessel, Everett, and Lagrange interpolation</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/08/18/bessel-everett/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Compression and interpolation</title>
		<link>https://www.johndcook.com/blog/2024/08/17/compression-and-interpolation/</link>
					<comments>https://www.johndcook.com/blog/2024/08/17/compression-and-interpolation/#comments</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Sat, 17 Aug 2024 12:56:36 +0000</pubDate>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Interpolation]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245663</guid>

					<description><![CDATA[<p>Data compression is everywhere. We&#8217;re unaware of it when it is done well. We only become aware of it when it is pushed too far, such as when a photo looks grainy or fuzzy because it was compressed too much. The basic idea of data compression is to not transmit the raw data but to [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/08/17/compression-and-interpolation/">Compression and interpolation</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>Data compression is everywhere. We&#8217;re unaware of it when it is done well. We only become aware of it when it is pushed too far, such as when a photo looks grainy or fuzzy because it was compressed too much.</p>
<p>The basic idea of data compression is to not transmit the raw data but to transmit some of the data along with instructions for how to approximately reconstruct the rest [1].</p>
<p>Fifty years ago scientists were concerned with a different application of compression: reducing the size of mathematical tables. Books of tabulated functions are obsolete now, but the principles used in producing these tables are still very much relevant. We use compression and interpolation far more often now, though it&#8217;s almost always invisibly executed by software.</p>
<h2>Compressing tables</h2>
<p>In this post I want to expand on comments by Forman Acton from his book <em>Numerical Methods That Work</em> on compression.</p>
<blockquote><p>Many persons are unaware of the considerable compression in a table that even the use of quadratic interpolation permits. A table of sin <em>x</em> covering the first quadrant, for example, requires 541 pages if it is to be linearly interpolable to eight decimal places. If quadratic interpolation is used, the same table takes only <em>one</em> page having entries at one-degree intervals with functions of the first and second differences being recorded together with the sine itself.</p></blockquote>
<p>Acton goes on to mention the advantage of condensing shelf space by a factor of 500. We no longer care about saving shelf space, but we may care very much about saving memory in an embedded device.</p>
<p>Quadratic interpolation does allow more compression than linear interpolation, but not by a factor of 500. I admire Acton&#8217;s numerical methods book, but I&#8217;m afraid he got this one wrong.</p>
<h2>Interpolation error bound</h2>
<p>In order to test Acton&#8217;s claim we will need the following theorem on interpolation error [2].</p>
<p>Let <em>f</em> be a function so that <em>f</em><sup>(<em>n</em>+1)</sup> is continuous on [<em>a</em>, <em>b</em>] and satisfies |<em>f</em><sup>(<em>n</em>+1)</sup> (<em>x</em>)| ≤ <em>M</em>. Let <em>p</em> be the polynomial of degree ≤ <em>n</em> that interpolates <em>f</em> at <em>n</em> + 1 equally spaced nodes in [<em>a</em>, <em>b</em>], including the end points. Then on [<em>a</em>, <em>b</em>],</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/interpolationerror2.svg" alt="|f(x) - p(x)| \leq \frac{1}{4(n+1)} M \left(\frac{b-a}{n}\right)^{n+1}" width="311" height="52" /></p>
<h2>Quadratic interpolation error</h2>
<p>Acton claims that quadratic interpolation at intervals of one degree is adequate to produce eight decimal places of accuracy. Quadratic interpolation means <em>n</em> = 2.</p>
<p>We have our function tabulated at evenly spaced points a distance <em>h</em> = π/180 radians apart. Quadratic interpolation requires function values at three points, so <em>b</em> − <em>a</em> = 2<em>h</em> = π/90. The third derivative of sine is negative cosine, so <em>M</em> = 1.</p>
<p>This gives an error bound of 4.43 × 10<sup>−7</sup>, so this would give slightly better than six decimal place accuracy, not eight.</p>
<h2>Linear interpolation error</h2>
<p>Suppose we wanted to create a table of sine values so that linear interpolation would give results accurate to eight decimal places.<br />
In the interpolation error formula we have <em>M</em> = 1 as before, and now <em>n</em> = 1. We would need to tabulate sine at enough points that <em>h</em> = <em>b − a</em> is small enough that the error is less than 5 × 10<sup>−9</sup>. It follows that <em>h</em> = 0.0002 radians. Covering a range of π/2 radians in increments of 0.0002 radians would require 7854 function values. Acton implicitly assumes 90 values to a page, so this would take about 87 pages.</p>
<p><a href="https://www.johndcook.com/blog/2017/02/26/function-on-cover-of-abramowitz-stegun/">Abramowitz and Stegun</a> devotes 32 pages to tabulating sine and cosine at increments of 0.001 radian. This does not always guarantee eight decimal place accuracy using linear interpolation, but it does guarantee at least seven places (more on that <a href="https://www.johndcook.com/blog/2024/06/25/trig-tables/">here</a>), which is better than a table at one degree increments would deliver using quadratic interpolation. So it would have been more accurate for Acton to say quadratic interpolation reduces the number of pages by a factor of 30 rather than 500.</p>
<h2>Cubic interpolation error</h2>
<p>If we have a table of sine values at one degree increments, how much accuracy could we get using cubic interpolation? In that case we&#8217;d apply the interpolation error theorem with <em>n</em> = 3 and <em>b</em> − <em>a</em> = 3(π/180) = π/60. Then the error bound is 5.8 × 10<sup>−9</sup>. This would usually give you eight decimal place accuracy, so perhaps Acton carried out the calculation for cubic interpolation rather than quadratic interpolation.</p>
<h2>Related posts</h2>
<ul>
<li class="link"><a href="https://www.johndcook.com/blog/2021/08/23/naive-compression-of-genetic-data/">Compressing genetic data</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2024/06/03/using-a-table-of-logarithms/">Using a table of logarithns</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2024/08/08/interpolating-gamma/">Interpolating the gamma function</a></li>
</ul>
<p>[1] This is what&#8217;s known as <em>lossy</em> compression; some information is lost in the compression process. Lossless compression also replaces the original data with a description that can be used to reproduce the data, but in this case the reconstruction process is perfect.</p>
<p>[2] Ward Cheney and David Kincaid. Numerical Methods and Computation. Third edition.</p>
<p>&nbsp;</p>The post <a href="https://www.johndcook.com/blog/2024/08/17/compression-and-interpolation/">Compression and interpolation</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/08/17/compression-and-interpolation/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Chebyshev polynomials as distorted cosines</title>
		<link>https://www.johndcook.com/blog/2024/08/15/distorted-cosines/</link>
					<comments>https://www.johndcook.com/blog/2024/08/15/distorted-cosines/#respond</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Fri, 16 Aug 2024 03:13:39 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Special functions]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245661</guid>

					<description><![CDATA[<p>Forman Acton&#8217;s book Numerical Methods that Work describes Chebyschev polynomials as cosine curves with a somewhat disturbed horizontal scale, but the vertical scale has not been touched. The relation between Chebyshev polynomials and cosines is Tn(cos θ) = cos(nθ). Some sources take this as the definition of Chebyshev polynomials. Other sources define the polynomials differently [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/08/15/distorted-cosines/">Chebyshev polynomials as distorted cosines</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>Forman Acton&#8217;s book <em>Numerical Methods that Work</em> describes Chebyschev polynomials as</p>
<blockquote><p>cosine curves with a somewhat disturbed horizontal scale, but the vertical scale has not been touched.</p></blockquote>
<p>The relation between Chebyshev polynomials and cosines is</p>
<p style="padding-left: 40px;"><em>T<sub>n</sub></em>(cos θ) = cos(<em>n</em>θ).</p>
<p>Some sources take this as the definition of Chebyshev polynomials. Other sources define the polynomials differently and prove this equation as a theorem.</p>
<p>It follows that if we let <em>x</em> = cos θ then</p>
<p style="padding-left: 40px;"><em>T<sub>n</sub></em>(<em>x</em>) = cos(<em>n</em> arccos <em>x</em>).</p>
<p>Now sin <em>x</em> = cos(π/2 − <em>x</em>) and for small <em>x</em>, <a href="https://www.johndcook.com/blog/2010/07/27/sine-approximation-for-small-x/">sin <em>x</em> ≈ <em>x</em></a>. This means</p>
<p style="padding-left: 40px;">arccos(<em>x</em>) ≈ π/2 − <em>x</em></p>
<p>for <em>x</em> near 0, and so we should expect the approximation</p>
<p style="padding-left: 40px;"><em>T<sub>n</sub></em>(<em>x</em>) ≈ cos(<em>n</em>(π/2 − <em>x</em>)).</p>
<p>to be accurate near the middle of the interval [−1, 1] though not at the ends. A couple plots show that this is the case.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-medium" src="https://www.johndcook.com/acton5.png" width="480" height="360" /></p>
<p><img loading="lazy" decoding="async" class="aligncenter size-medium" src="https://www.johndcook.com/acton8.png" width="480" height="360" /></p>
<h2>Mote Chebyshev posts</h2>
<ul>
<li class="link"><a href="https://www.johndcook.com/blog/2020/03/15/product-of-chebyshev-polynomials/">Product of Chebyshev polynomials</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2020/05/08/chebyshevs-other-polynomials/">Chebyshev&#8217;s other polynomials</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2020/03/11/chebyshev-approximation/">Chebyshev approximation</a></li>
</ul>The post <a href="https://www.johndcook.com/blog/2024/08/15/distorted-cosines/">Chebyshev polynomials as distorted cosines</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/08/15/distorted-cosines/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Math&#8217;s base 32 versus Linux&#8217;s base 32</title>
		<link>https://www.johndcook.com/blog/2024/08/13/base-32/</link>
					<comments>https://www.johndcook.com/blog/2024/08/13/base-32/#respond</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Tue, 13 Aug 2024 15:27:00 +0000</pubDate>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Math]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245660</guid>

					<description><![CDATA[<p>The convention in math for writing numbers in bases larger than 10 is to insert capital letters after 9, starting with A. So, for example, the digits in base 12 are 0, 1, 2, &#8230;, 9, A, and B. So if you&#8217;re familiar with math but not Linux, and you run across the base32 utility, [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/08/13/base-32/">Math’s base 32 versus Linux’s base 32</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>The convention in math for writing numbers in bases larger than 10 is to insert capital letters after 9, starting with A. So, for example, the digits in <a href="https://www.johndcook.com/blog/2021/04/18/duodecimal/">base 12</a> are 0, 1, 2, &hellip;, 9, A, and B.</p>
<p>So if you&#8217;re familiar with math but not Linux, and you run across the <code>base32</code> utility, you might naturally assume that the command converts numbers to base 32 using the symbols 0, 1, 2, &#038;hellip, 9, A, B, C, &hellip;, V. That&#8217;s a reasonable guess, but it actually uses the symbols A, B, C, &hellip;, Z, 2, 3, 4, 5, 6, and 7. It&#8217;s all described in <a href="https://www.rfc-editor.org/rfc/rfc3548">RFC 3548</a>.</p>
<p>What&#8217;s going on? The purpose of base 32 encoding is to render binary data in a way that is human readable and capable of being processed by software that was originally written with human readable input in mind. The purpose is not to carry out mathematical operations. </p>
<p>Note that the digit 0 is not used, because it&#8217;s visually similar to the letter O. The digit 1 is also not used, perhaps because it looks like a lowercase <code>l</code> in some fonts.</p>
<h2>Related posts</h2>
<ul>
<li class='link'><a href='https://www.johndcook.com/blog/2011/04/09/words-that-are-primes-base-36/'>Words that are prime in base 36</a></li>
<li class='link'><a href='https://www.johndcook.com/blog/2019/03/04/base-58-encoding-and-bitcoin-addresses/'>Base 58</a></li>
<li class='link'><a href='https://www.johndcook.com/blog/2019/03/05/base85-encoding/'>Base 85</a></li>
</ul>The post <a href="https://www.johndcook.com/blog/2024/08/13/base-32/">Math’s base 32 versus Linux’s base 32</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/08/13/base-32/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Editing a file without an editor</title>
		<link>https://www.johndcook.com/blog/2024/08/11/editing-without-an-editor/</link>
					<comments>https://www.johndcook.com/blog/2024/08/11/editing-without-an-editor/#respond</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Sun, 11 Aug 2024 12:30:08 +0000</pubDate>
				<category><![CDATA[Computing]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245659</guid>

					<description><![CDATA[<p>I don&#8217;t use sed very often, but it&#8217;s very handy when I do use it, particularly when needing to make a small change to a large file. Fixing a JSON file Lately I&#8217;ve been trying to fix a 30 MB JSON file that has been corrupted somehow. The file is one very long line. Emacs [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/08/11/editing-without-an-editor/">Editing a file without an editor</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>I don&#8217;t use <code>sed</code> very often, but it&#8217;s very handy when I do use it, particularly when needing to make a small change to a large file. </p>
<h2>Fixing a JSON file</h2>
<p>Lately I&#8217;ve been trying to fix a 30 MB JSON file that has been corrupted somehow. The file is one very long line. </p>
<p>Emacs was unable to open the file. (It might have eventually opened the file, but I killed the process when it took longer than I was willing to wait.) </p>
<p>Emacs can open large files, but it has trouble with long lines. Somewhere its data structures assume lines are not typically millions of characters long. </p>
<p>I used <code>sed</code> to add line breaks after closing brackets</p>
<pre>    sed -i 's/]/]\n/g' myfile.json</pre>
<p>and then I was able to open the file in Emacs.</p>
<p>If the problem with my JSON file were simply a missing closing brace&mdash;it&#8217;s not&mdash;then I could add a closing brace with</p>
<pre>    sed -i 's/$/}/' myfile.json</pre>
<h2>Using sed to find a job</h2>
<p>I had a friend in college who got a job because of a <code>sed</code> script he wrote as an intern. </p>
<p>A finite element program would crash when it attempted to take too large a time step, but the program would not finish by the time the results were needed if it always took tiny time steps. So they&#8217;d let the program crash occasionally, then edit the configuration file with a smaller time step and restart the program.</p>
<p>They were asking engineers to work around the clock so someone could edit the configuration file and restart the finite element program if it crashed in the middle of the night. My friend wrote a shell script to automate this process, using <code>sed</code> to do the file editing. He eliminated the need for a night shift and got a job offer.</p>
<h2>Related posts</h2>
<ul>
<li class='link'><a href='https://www.johndcook.com/blog/2011/04/19/learn-one-sed-command/'>Learn one sed command</a></li>
<li class='link'><a href='https://www.johndcook.com/blog/2023/11/27/unix-linguistics/'>Unix linguistics</a></li>
</ul>The post <a href="https://www.johndcook.com/blog/2024/08/11/editing-without-an-editor/">Editing a file without an editor</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/08/11/editing-without-an-editor/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Interpolating the gamma function</title>
		<link>https://www.johndcook.com/blog/2024/08/08/interpolating-gamma/</link>
					<comments>https://www.johndcook.com/blog/2024/08/08/interpolating-gamma/#respond</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Fri, 09 Aug 2024 03:51:12 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Special functions]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245658</guid>

					<description><![CDATA[<p>Suppose you wanted to approximate Γ(10.3). You know it&#8217;s somewhere between Γ(10) = 9! and Γ(11) = 10!, and linear interpolation would give you Γ(10.3) ≈ 0.7 × 9! + 0.3 × 10! = 1342656. But the exact value is closer to 716430.69, and so our estimate is 53% too high. Not a very good [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/08/08/interpolating-gamma/">Interpolating the gamma function</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>Suppose you wanted to approximate Γ(10.3). You know it&#8217;s somewhere between Γ(10) = 9! and Γ(11) = 10!, and linear interpolation would give you</p>
<p style="padding-left: 40px;">Γ(10.3) ≈ 0.7 × 9! + 0.3 × 10! = 1342656.</p>
<p>But the exact value is closer to 716430.69, and so our estimate is 53% too high. Not a very good approximation.</p>
<p>Now let&#8217;s try again, applying linear interpolation to the log of the gamma function. Our approximation is</p>
<p style="padding-left: 40px;">log Γ(10.3) ≈ 0.7 × log 9! + 0.3 × log 10! = 13.4926</p>
<p>while the actual value is 13.4820, an error of about 0.08%. If we take exponentials to get an approximation of Γ(10.3), not log Γ(10.3), the error is larger, about 1%, but still much better than 53% error.</p>
<p>The gamma function grows very quickly, and so the log gamma function is usually easier to work with.</p>
<p>As a bonus, the Bohr–Mollerup theorem says that log gamma is a convex function. This tells us that not only does linear interpolation give an approximation, it gives us an upper bound.</p>
<p>The Bohr–Mollerup theorem essentially says that the gamma function is the only function that extends factorial from a function on the integers to a log-convex function on the real numbers. This isn&#8217;t quite true since it&#8217;s actually &amp;Gamma(<em>x</em> + 1) that extends factorial. Showing the gamma function is unique is the hard part. In the preceding paragraph we used the easy direction of the theorem, saying that gamma is log-convex.</p>
<h2>Related posts</h2>
<ul>
<li class='link'><a href='https://www.johndcook.com/blog/2021/03/26/simple-gamma-approximation/'>Simple approximation for the gamma function</a></li>
<li class='link'><a href='https://www.johndcook.com/blog/2020/12/07/asymptotic-gamma-ratio/'>Asymptotic series for gamma function ratios</a></li>
<li class='link'><a href='https://www.johndcook.com/blog/2017/02/11/approximate-inverse-of-the-gamma-function/'>Approximate inverse of the gamma function</a></li>
</ul>The post <a href="https://www.johndcook.com/blog/2024/08/08/interpolating-gamma/">Interpolating the gamma function</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/08/08/interpolating-gamma/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Too clever Monte Carlo</title>
		<link>https://www.johndcook.com/blog/2024/08/04/too-clever-monte-carlo/</link>
					<comments>https://www.johndcook.com/blog/2024/08/04/too-clever-monte-carlo/#comments</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Sun, 04 Aug 2024 23:05:54 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Probability]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245647</guid>

					<description><![CDATA[<p>One way to find the volume of a sphere would be to imagine the sphere in a box, randomly select points in the box, and count how many of these points fall inside the sphere. In principle this would work in any dimension. The problem with naive Monte Carlo We could write a program to [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/08/04/too-clever-monte-carlo/">Too clever Monte Carlo</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>One way to find the volume of a sphere would be to imagine the sphere in a box, randomly select points in the box, and count how many of these points fall inside the sphere. In principle this would work in any dimension.</p>
<h2>The problem with naive Monte Carlo</h2>
<p>We could write a program to estimate the volume of a high-dimensional sphere this way. But there&#8217;s a problem: very few random samples will fall in the sphere. The ratio of the volume of a sphere to the volume of a box it fits in goes to zero as the dimension increases. We might take a large number of samples and none of them fall inside the sphere. In this case we&#8217;d estimate the volume as zero. This estimate would have small absolute error, but 100% relative error.</p>
<h2>A more clever approach</h2>
<p>So instead of actually writing a program to randomly sample a high dimensional cube, let&#8217;s <strong>imagine</strong> that we did. Instead of doing a big Monte Carlo study, we could <strong>be clever and use theory</strong>.</p>
<p>Let <em>n</em> be our dimension. We want to draw uniform random samples from [−1, 1]<sup><em>n</em></sup> and see whether they land inside the unit sphere. So we&#8217;d draw <em>n</em> random samples from [−1, 1] and see whether the sum of their squares is less than or equal to 1.</p>
<p>Let <em>X</em><sub><em>i</em></sub> be a uniform random variable on [−1, 1]. We want to know the probability that</p>
<p style="padding-left: 40px;"><em>X</em><sub>1</sub>² + <em>X</em><sub>2</sub>² + <em>X</em><sub>3</sub>² + … + <em>X</em><sub><em>n</em></sub>² ≤ 1.</p>
<p>This would be an ugly calculation, but since we&#8217;re primarily interested in the case of large <em>n</em>, we can approximate the sum using the <a href="https://www.johndcook.com/blog/central_limit_theorems/">central limit theorem</a> (CLT). We can show, using the transformation theorem, that each <em>X</em><sub><em>i</em></sub>² has mean 1/3 and variance 4/45. The CLT says that the sum has approximately the distribution of a normal random variable with mean <em>n</em>/3 and variance 4<em>n</em>/45.</p>
<h2>Too clever by half</h2>
<p>The approach above turns out to be a bad idea, though it&#8217;s not obvious why.</p>
<p>The CLT does provide a good approximation of the sum above, <strong>near the mean</strong>. But we have a sum with mean <em>n</em>/3, with <em>n</em> large, and we&#8217;re asking for the probability that the sum is less than 1. In other words, we&#8217;re asking for the probability <strong>in the tail</strong> where the CLT approximation error is a bad (relative) fit. More on this <a href="https://www.johndcook.com/blog/2018/06/04/relative-error-clt/">here</a>.</p>
<p>This post turned out to not be about what I thought it would be about. I thought this post would lead to a asymptotic approximation for the volume of an <em>n</em>-dimensional sphere. I would compare the approximation to the exact value and see how well it did. Except it did terribly. So instead, this post a cautionary tale about remembering how convergence works in the CLT.</p>
<h2>Related posts</h2>
<ul>
<li class="link"><a href="https://www.johndcook.com/blog/2015/04/01/integration-by-darts/">Integration by darts</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2019/05/26/sums-of-volumes-of-spheres/">Sum of all spheres</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2010/07/02/volumes-of-generalized-unit-balls/">Volume of p-norm spheres</a></li>
</ul>The post <a href="https://www.johndcook.com/blog/2024/08/04/too-clever-monte-carlo/">Too clever Monte Carlo</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/08/04/too-clever-monte-carlo/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Evaluating a class of infinite sums in closed form</title>
		<link>https://www.johndcook.com/blog/2024/08/03/polylog/</link>
					<comments>https://www.johndcook.com/blog/2024/08/03/polylog/#comments</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Sat, 03 Aug 2024 14:38:44 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Special functions]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245645</guid>

					<description><![CDATA[<p>The other day I ran across the surprising identity and wondered how many sums of this form can be evaluated in closed form like this. Quite a few it turns out. Sums of the form evaluate to a rational number when k is a non-negative integer and c is a rational number with &#124;c&#124; &#62; [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/08/03/polylog/">Evaluating a class of infinite sums in closed form</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>The other day I ran across the surprising identity</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/polylog26.svg" alt="\sum_{n=1}^\infty \frac{n^3}{2^n} = 26" width="95" height="54" /></p>
<p>and wondered how many sums of this form can be evaluated in closed form like this. Quite a few it turns out.</p>
<p>Sums of the form</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/polylog0.svg" alt="\sum_{n=1}^\infty \frac{n^k}{c^n}" width="50" height="54" /></p>
<p>evaluate to a rational number when <em>k</em> is a non-negative integer and <em>c</em> is a rational number with |<em>c</em>| &gt; 1. Furthermore, there is an algorithm for finding the value of the sum.</p>
<p>The sums can be evaluated using the <strong>polylogarithm</strong> function Li<sub><em>s</em></sub>(<em>z</em>) defined as</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/polylogdef2.svg" alt="\text{Li}_s(z) = \sum_{n=1}^\infty \frac{z^n}{n^s}" width="123" height="54" /></p>
<p>using the identity</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/polylog1.svg" alt="\sum_{n=1}^\infty \frac{n^k}{c^n} = \text{Li}{-k}\left(\frac{1}{c}\right)" width="150" height="54" /></p>
<p>We then need to have a way to evaluate Li<sub><em>s</em></sub>(<em>z</em>). This cannot be done in closed form in general, but it can be done when <em>s</em> is a negative integer as above. To evaluate Li<sub>−<em>k</em></sub>(<em>z</em>) we need to know two things. First,</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/polylog2.svg" alt="Li_1(z) = -\log(1-z)" width="170" height="18" /></p>
<p>and second,</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/polylog3.svg" alt="\text{Li}_{s-1}(z) = z \frac{d}{dz} \text{Li}_s(z)" width="169" height="41" /></p>
<p>Now Li<sub>0</sub>(<em>z</em>) is a rational function of <em>z</em>, namely <em>z</em>/(1 − <em>z</em>). The derivative of a rational function is a rational function, and multiplying a rational function of <em>z</em> by <em>z</em> produces another rational function, so Li<sub><em>s</em></sub>(<em>z</em>) is a rational function of <em>z</em> whenever <em>s</em> is a non-positive integer.</p>
<p>Assuming the results cited above, we can prove the identity</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/polylog26.svg" alt="\sum_{n=1}^\infty \frac{n^3}{2^n} = 26" width="95" height="54" /></p>
<p>stated at the top of the post.The sum equals Li<sub>−3</sub>(1/2), and</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/polylog4.svg" alt="\text{Li}_{-3}(z) = \left(z \frac{d}{dz}\right)^3 \frac{z}{1-z} = \frac{z(1 + 4z + z^2)}{(1-z)^4}" width="327" height="52" /></p>
<p>The result comes from plugging in <em>z</em>= 1/2 and getting out 26.</p>
<p>When <em>k</em> and <em>c</em> are positive integers, the sum</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/polylog0.svg" alt="\sum_{n=1}^\infty \frac{n^k}{c^n}" width="50" height="54" /></p>
<p>is not necessarily an integer, as it is when <em>k</em> = 3 and <em>c</em> = 2, but it is always rational. It looks like the sum is an integer if <em>c</em>= 2; I verified that the sum is an integer for <em>c</em> = 2 and <em>k</em> = 1 through 10 using the <code>PolyLog</code> function in Mathematica.</p>
<p><strong>Update</strong>: Here is a <a href="https://postimg.cc/zL0dqHyD">proof</a> that the sum is an integer when <em>n</em> = 2. From a comment by Theophylline on Substack.</p>
<p>The sum is occasionally an integer for larger values of <em>c</em>. For example,</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/polylog5.svg" alt="\sum_{n=1}^\infty \frac{n^4}{3^n} = 15" width="95" height="54" /></p>
<p>and</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/polylog6.svg" alt="\sum_{n=1}^\infty \frac{n^8}{3^n} = 17295" width="125" height="54" /></p>
<h2>Related posts</h2>
<ul>
<li class="link"><a href="https://www.johndcook.com/blog/2021/10/26/dirichlet-series/">Dirichlet series generating functions</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2021/08/28/computing-zeta-3/">Computing ζ(3)</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/applied-complex-analysis/">Applied complex analysis</a></li>
</ul>The post <a href="https://www.johndcook.com/blog/2024/08/03/polylog/">Evaluating a class of infinite sums in closed form</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/08/03/polylog/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Sphere spilling out</title>
		<link>https://www.johndcook.com/blog/2024/07/29/sphere-spilling-out/</link>
					<comments>https://www.johndcook.com/blog/2024/07/29/sphere-spilling-out/#respond</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Tue, 30 Jul 2024 02:12:11 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245644</guid>

					<description><![CDATA[<p>Center a small blue sphere on every corner of an n-dimensional unit hypercube. These are the points in ℝn for which every coordinate is either a 0 or a 1. Now inflate each of these small spheres at the same time until they touch. Each sphere will have radius 1/2. For example, the spheres centered at [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/07/29/sphere-spilling-out/">Sphere spilling out</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>Center a small blue sphere on every corner of an <em>n</em>-dimensional unit hypercube. These are the points in ℝ<sup><em>n</em></sup> for which every coordinate is either a 0 or a 1. Now inflate each of these small spheres at the same time until they touch. Each sphere will have radius 1/2. For example, the spheres centered at</p>
<p style="padding-left: 40px;">(0, 0, 0, …, 0)</p>
<p>and</p>
<p style="padding-left: 40px;">(0, 0, 0, …, 1)</p>
<p>can&#8217;t have a radius larger than 1/2 because they&#8217;ll intersect at (0, 0, 0, …, 1/2).</p>
<p>Now center a little red sphere at center, the point where every coordinate equals 1/2, and blow it up until it touches the blue spheres. Which is larger, the blue spheres or the red one?</p>
<p>The answer depends on <em>n</em>. In low dimensions, the blue spheres are larger. But in higher dimensions, the red sphere is larger.</p>
<p>The distance of from the center of the hypercube to any of the vertices is √<em>n</em> / 2 and so the radius of the red sphere is (√<em>n</em> − 1) / 2. When <em>n</em> = 4, the radius of the red sphere equals the radius of the blue spheres.</p>
<p>The hypercube and blue spheres will fit inside a hypercube whose side is length 2. But if <em>n</em> &gt; 9 the red sphere will spill out of this larger hypercube.</p>
<p>This post was motivate by this <a href="https://x.com/aryehazan/status/1817877048053911912?s=61">post</a> by Aryeh Kontorovich on Twitter.</p>
<h2>More on high-dimensional spheres</h2>
<ul>
<li class="link"><a href="https://www.johndcook.com/blog/2011/09/01/multivariate-normal-shell/">Nearly all the volume is in a thin shell</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2017/07/13/concentration_of_measure/">Nearly all the area is near the equator</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2011/09/01/multivariate-normal-shell/">Willie Sutton and the multivariate normal</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2019/04/16/random-projection/">Random projections</a></li>
</ul>The post <a href="https://www.johndcook.com/blog/2024/07/29/sphere-spilling-out/">Sphere spilling out</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/07/29/sphere-spilling-out/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>A variation on Rock, Paper, Scissors</title>
		<link>https://www.johndcook.com/blog/2024/07/26/a-variation-on-rock-paper-scissors/</link>
					<comments>https://www.johndcook.com/blog/2024/07/26/a-variation-on-rock-paper-scissors/#respond</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Fri, 26 Jul 2024 11:00:08 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Combinatorics]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245641</guid>

					<description><![CDATA[<p>Imagine in a game of Rock, Paper, Scissors one player is free to play as usual but the other is required to choose each option the same number of times. That is, in 3n rounds of the game, the disadvantaged player much choose Rock n times, Paper n times, and Scissors n times. Obviously the [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/07/26/a-variation-on-rock-paper-scissors/">A variation on Rock, Paper, Scissors</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>Imagine in a game of Rock, Paper, Scissors one player is free to play as usual but the other is required to choose each option the same number of times. That is, in 3<em>n</em> rounds of the game, the disadvantaged player much choose Rock <em>n</em> times, Paper <em>n</em> times, and Scissors <em>n</em> times.</p>
<p>Obviously the unrestricted player would be expected to win more games, but how many more? At least one, because the unrestricted player knows what the restricted player will do on the last round.</p>
<p>If <em>n</em> is large, then in the early rounds of the game it makes little difference that one of the players is restricted. The restriction doesn&#8217;t give the unrestricted player much exploitable information. But in the later rounds of the game, the limitations on the restricted player&#8217;s moves increase the other players chances of winning more.</p>
<p>It turns out that the if the unrestricted player uses an optimal strategy, he can expect to win <em>O</em>(√<em>n</em>) more rounds than he loses. More precisely, the expected advantage approaches 1.4658√<em>n</em> as <em>n</em> grows. You can find a thorough analysis of the problem in <a href="https://www.combinatorics.org/ojs/index.php/eljc/article/view/v31i2p40" target="_blank" rel="noopener">this paper</a>.</p>
<h2>Related posts</h2>
<ul>
<li class="link"><a href="https://www.johndcook.com/blog/2018/08/07/rock-paper-scissors-lizard-spock/">Rock, Paper, Scissors, Lizard, Spock</a></li>
<li class="link"><a href="https://www.johndcook.com/blog/2019/06/04/rock-paper-scissors-algebra/">The algebra of Rock, Paper, Scissors</a></li>
</ul>The post <a href="https://www.johndcook.com/blog/2024/07/26/a-variation-on-rock-paper-scissors/">A variation on Rock, Paper, Scissors</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/07/26/a-variation-on-rock-paper-scissors/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>q-analog of rising powers</title>
		<link>https://www.johndcook.com/blog/2024/07/23/q-pochhammer/</link>
					<comments>https://www.johndcook.com/blog/2024/07/23/q-pochhammer/#respond</comments>
		
		<dc:creator><![CDATA[John]]></dc:creator>
		<pubDate>Tue, 23 Jul 2024 13:11:37 +0000</pubDate>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Special functions]]></category>
		<guid isPermaLink="false">https://www.johndcook.com/blog/?p=245640</guid>

					<description><![CDATA[<p>The previous post looked at the probability that a random n by n matrix over a finite field of order q is invertible. This works out to be This function of q and n comes up in other contexts as well and has a name that we will get to shortly. Pochhammer symbols Leo August [&#8230;]</p>
The post <a href="https://www.johndcook.com/blog/2024/07/23/q-pochhammer/">q-analog of rising powers</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></description>
										<content:encoded><![CDATA[<p>The <a href="https://www.johndcook.com/blog/2024/07/22/linear-systems-over-finite-fields/">previous post</a> looked at the probability that a random <em>n</em> by <em>n</em> matrix over a finite field of order <em>q</em> is invertible. This works out to be</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-medium" src="https://www.johndcook.com/glnsize2.svg" alt="\prod_{i=1}^n \left(1 - \frac{1}{q^i}\right)" width="78" height="43" /></p>
<p>This function of <em>q</em> and <em>n</em> comes up in other contexts as well and has a name that we will get to shortly.</p>
<h2>Pochhammer symbols</h2>
<p>Leo August Pochhammer (1841–1920) defined the <em>k</em>th rising power of <em>x</em> by</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/pochhammer.svg" alt="(x)_k = x(x + 1)(x + 2)\cdots(x + k - 1)" width="298" height="18" /></p>
<p><a href="https://www.johndcook.com/blog/2021/11/09/rising-and-falling-powers/">Rising and falling powers</a> come up naturally in combinatorics, <a href="https://www.johndcook.com/blog/2009/02/01/finite-differences/">finite difference</a> analogs of calculus, and in the definition of <a href="https://www.johndcook.com/blog/2021/10/28/hypergeometric-functions/">hypergeometric functions</a>.</p>
<h2><em>q</em>-Pochhammer symbols</h2>
<p>The <em>q</em>-analog of the Pochhammer symbol is defined as</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/qpochhammer.svg" alt="(a;q)_n = \prod_{k=0}^{n-1} (1-aq^k)=(1-a)(1-aq)(1-aq^2)\cdots(1-aq^{n-1})" width="520" height="58" /></p>
<p>Like the Pochhammer symbol, the <em>q</em>-Pochhammer symbol also comes up in combinatorics.</p>
<p>In general, <em>q</em>-analogs of various concepts are generalizations that reduce to the original concept in some sort of limit as <em>q</em> goes to 1. The relationship between the <em>q</em>-Pochhammer symbol and the Pochhammer symbol is</p>
<p><img loading="lazy" decoding="async" class="aligncenter" style="background-color: white;" src="https://www.johndcook.com/qpochhammerlimit.svg" alt="\lim_{q\to 1} \frac{(q^x;q)_n}{(1-q)^n} = (x)_n" width="159" height="46" /><br />
For a simpler introduction to <em>q</em>-analogs, see <a href="https://www.johndcook.com/blog/2021/11/12/q-binomial/">this post</a> on <em>q</em>-factorial and <em>q</em>-binomial coefficients.</p>
<h2>Back to our probability problem</h2>
<p>The motivation for this post was to give a name to the function that gives probability a random <em>n</em> by <em>n</em> matrix over a finite field of order <em>q</em> is invertible. In the notation above, this function is (1/<em>q</em>; 1/<em>q</em>)<sub><em>n</em></sub>.</p>
<p>There&#8217;s a confusing notational coincidence here. The number of elements in a finite field is usually denoted by <em>q</em>. The <em>q</em> in <em>q</em>-analogs such as the <em>q</em>-Pochhammer symbol has absolute value less than 1. It&#8217;s a coincidence that they both use the letter <em>q</em>, and the <em>q</em> in our application of <em>q</em>-Pochhammer symbols is the reciprocal of the <em>q</em> representing the order of a finite field.</p>
<p>I mentioned in the previous post that the probability of the matrix being invertible is a decreasing function of <em>n</em>. This probability decreases to a positive limit, varying with the value of <em>q</em>. This limit is (1/<em>q;</em> 1/<em>q</em>)<sub>∞</sub>. Here the subscript ∞ denotes that we take the limit in (1/<em>q;</em> 1/<em>q</em>)<sub><em>n</em></sub> as <em>n</em> goes to infinity. There&#8217;s no problem here because the infinite product converges.</p>
<h2>Mathematica and plotting</h2>
<p>The <em>q</em>-Pochhammer symbol (<em>a</em>; <em>q</em>)<sub><em>n</em></sub> is implemented in Mathematica as <code>QPochhammer[a, q, n]</code> and the special case (<em>q</em>; <em>q</em>)<sub>∞</sub> is implemented as <code>QPochhammer[q]</code>. We can use the latter to make the following plot.</p>
<pre>Plot[QPochhammer[q], {q, -1, 1}]</pre>
<p><img loading="lazy" decoding="async" class="aligncenter size-medium" style="background-color: white;" src="https://www.johndcook.com/QPplot1.svg" width="480" height="301" /></p>
<p>Recall that the <em>q</em> in our motivating application is the reciprocal of the <em>q</em> in the <em>q</em>-Pochhhammer symbol. This says for large fields, the limiting probability that an <em>n</em> by <em>n</em> matrix is invertible as <em>n</em> increases is near 1, but that for smaller fields the limiting probability is also smaller. For <em>q</em> = 2, the probability is 0.288788.</p>
<pre>Plot[QPochhammer[1/q], {q, 2, 100}, PlotRange -&gt; All]</pre>
<p><img loading="lazy" decoding="async" class="aligncenter size-medium" style="background-color: white;" src="https://www.johndcook.com/QPplot2.svg" width="480" height="295" /></p>
<h2>Related posts</h2>
<ul>
<li class='link'><a href='https://www.johndcook.com/blog/2021/10/28/double-factorial-example/'>Hidden double factorial</a></li>
<li class='link'><a href='https://www.johndcook.com/blog/2021/05/17/qlog-tsallis-entropy/'>q-logarithms and entropy</a></li>
</ul>The post <a href="https://www.johndcook.com/blog/2024/07/23/q-pochhammer/">q-analog of rising powers</a> first appeared on <a href="https://www.johndcook.com/blog">John D. Cook</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.johndcook.com/blog/2024/07/23/q-pochhammer/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
