The Universe of Discourse
https://blog.plover.com
The Universe of Discourse (Mark Dominus Blog)enSnow White in German
https://blog.plover.com/2021/01/03#Snow-White
<p>Tonight I was thinking of</p>
<blockquote>
<p>Mirror, mirror, on the wall <br />
Who is the fairest of them all?</p>
</blockquote>
<p>I remembered that the original was in German and wondered whether it
had always rhymed. It turns out that it had:</p>
<blockquote>
<p>Spieglein, Spieglein an der Wand, <br />
Wer ist die Schönste im ganzen Land?</p>
</blockquote>
<p>The English is a pretty literal translation.</p>
<p>When the <em>wunderbare Spiegel</em> gives the Queen the bad news, it says:</p>
<blockquote>
<p>Frau Königin, Ihr seid die Schönste hier, <br />
Aber Schneewittchen ist tausendmal schöner als Ihr.</p>
</blockquote>
<p>(“Queen, you are the fairest one <em>here</em>, but Little Snow White is a
thousand times as fair as you.”)</p>
<p>When the dwarfs see Snow White in one of their beds, they cry</p>
<blockquote>
<p>Ei, du mein Gott!</p>
</blockquote>
<p>which is German for “zOMG”.</p>
<p>Later the Queen returns to the mirror, expecting a better answer, but
she gets this:</p>
<blockquote>
<p>Frau Königin, Ihr seid die Schönste hier, <br />
Aber Schneewittchen über den Bergen <br />
Bei den sieben Zwergen <br />
Ist noch tausendmal schöner als Ihr.</p>
</blockquote>
<p>(“Queen, you are the fairest <em>here</em>, but Little Snow White up on the
mountain with the seven dwarfs is still a thousand times as fair as
you.”)</p>
<p>I like the way this poem here interpolates the earlier version, turning
the A-A rhyme into A-B-B-A. The English version I have has “in the
glen / little men” in place of “über den Bergen / sieben Zwergen”.
The original is much better, but I am not sure English has any good
rhymes for “dwarfs”. Except “wharfs”, but putting the dwarfs by the
wharfs is much worse than putting them in the glen.</p>
<p>[ Thanks to Gaal Yahas for correcting my translation of <em>noch</em> and to
Mario Lang for correcting my German grammar. ]</p>
My big mistake about dense sets
https://blog.plover.com/2021/01/01#dense-sets
<p>I made a big mistake in a Math Stack Exchange answer this week. It
turned out that I believed something that was completely wrong.</p>
<p>Here's the question,
<a href="https://math.stackexchange.com/q/3958985/25554">are terminating decimals dense in the reals?</a>.
It asks if the terminating decimals (that is, the rational numbers of
the form <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cfrac%20m%7b10%5en%7d%24">) are dense in the reals. “Dense in the
reals” means that if an adversary names a real number <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24r%24"> and a
small distance <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24d%24">, and challenges us to find a terminating decimal
<img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24t%24"> that is closer than <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24d%24"> to point <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24r%24">, we can always do it.
For example, is there a terminating decimal <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24t%24"> that is within
<img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%240%2e0000001%24"> of <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5csqrt%202%24">? There is: <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cfrac%7b14142135%7d%7b10%5e7%7d%20%3d%0a1%2e4142135%24"> is closer than that; the difference is less than
<img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%240%2e00000007%24">.</p>
<p>The answer to the question is ‘yes’ and the example shows why: every
real number has a decimal expansion, and if you truncate that
expansion far enough out, you get a terminating decimal that is as
close as you like to the original number. This is the obvious and
straightforward way to prove it, and it's just what the top-scoring
answer did.</p>
<p>I thought I'd go another way, though. I said that it's enough to show
that for any two terminating decimals, <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24a%24"> and <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24b%24">, there is
another one that lies between them. I remember my grandfather telling
me long ago that this was a sufficient condition for a set to be dense
in the reals, and I believed him. But it isn't sufficient, as Noah
Schweber kindly pointed out.</p>
<p>(It is, of course, necessary, since if <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24S%24"> is a subset of
<img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cBbb%20R%24">, and
<img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24a%2cb%5cin%20S%24"> but no element of <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24S%24"> between these, then
there is no element of <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24S%24"> that is less than distance
<img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cfrac%7bb%2da%7d2%24"> of <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cfrac%7ba%2bb%7d2%24">. Both <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24a%24"> and <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24b%24"> are <em>at</em> that
distance, and no other point of <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24S%24"> is closer.)</p>
<p>The counterexample that M. Schweber pointed out can be explained
quickly if you know what the
<a href="https://en.wikipedia.org/wiki/Cantor_set">Cantor middle-thirds set</a> is: construct the Cantor
set, and consider the set of
<i>midpoints</i> of the deleted intervals; this set of midpoints has
the property that between any two there is another, but it is not
dense in the reals. I was going to do a whole thing
with diagrams for people who don't know the Cantor set, but I think
what follows will be simpler.</p>
<p>Consider the set of real numbers between 0 and 1. These can of course
be represented as decimals, some terminating and some not. Our
counterexample will consist of all the terminating decimals that end
with <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%245%24">, and before that final <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%245%24"> have nothing but zeroes and
nines. So, for example, <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%240%2e5%24">. To the left and right of <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%240%2e5%24">,
respectively, are <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%240%2e05%24"> and <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%240%2e95%24">.</p>
<p>In between (and around) these three are:
$$\begin{array}{l}
\color{darkblue}{ 0.005 }\\
0.05 \\
\color{darkblue}{ 0.095 }\\
0.5 \\
\color{darkblue}{ 0.905 }\\
0.95 \\
\color{darkblue}{ 0.995 }\\
\end{array}$$</p>
<p>(Dark blue are the new ones we added.)</p>
<p>And in between and around these are:</p>
<p>$$\begin{array}{l}
\color{darkblue}{ 0.0005 }\\
0.005 \\
\color{darkblue}{ 0.0095 }\\
0.05 \\
\color{darkblue}{ 0.0905 }\\
0.095 \\
\color{darkblue}{ 0.0995 }\\
0.5 \\
\color{darkblue}{ 0.9005 }\\
0.905 \\
\color{darkblue}{ 0.9095 }\\
0.95 \\
\color{darkblue}{ 0.9905 }\\
0.995 \\
\color{darkblue}{ 0.9995 }\\
\end{array}$$</p>
<p>Clearly, between any two of these there is another one, because around
<img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%240%2e%3f%3f%3f%3f5%24"> we've added <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%240%2e%3f%3f%3f%3f05%24"> before and <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%240%2e%3f%3f%3f%3f95%24"> after, which
will lie between <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%240%2e%3f%3f%3f%3f5%24"> and any decimal with fewer <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%3f%24"> digits before it
terminates. So this set does have the between-each-two-is-another
property that I was depending on.</p>
<p>But it should also be clear that this set is <em>not</em> dense in the reals,
because, for example, there is obviously no number of this type that is
near <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%240%2e7%24">.</p>
<p>(This isn't the midpoints of the middle-thirds set, it's the midpoints
of the middle-four-fifths set, but the idea is exactly the same.)</p>
<p>Happy New Year, everyone!</p>
Benjamin Franklin and the Exercises of Ignatius
https://blog.plover.com/2020/12/30#exercises
<p>Recently I learned of the <a href="https://en.wikipedia.org/wiki/Spiritual_Exercises_of_Ignatius_of_Loyola"><em>Spiritual
Exercises</em></a> of
St. Ignatius. Wikipedia says (or quotes, it's not clear):</p>
<blockquote>
<p>Morning, afternoon, and evening will be times of the
examinations. The morning is to guard against <strong>a particular sin or
fault</strong>, the afternoon is a fuller examination of the same sin or
defect. There will be <strong>a visual record with a tally</strong> of the frequency
of sins or defects during each day. In it, the letter 'g' will
indicate days, with 'G' for Sunday. Three kinds of thoughts: "my
own" and two from outside, one from the "good spirit" and the other
from the "bad spirit".</p>
</blockquote>
<p>This reminded me very strongly of Chapter 9 of Benjamin
Franklin's
<a href="https://en.wikipedia.org/wiki/The_Autobiography_of_Benjamin_Franklin"><em>Autobiography</em></a>, in
which he presents “A Plan for Attaining Moral Perfection”:</p>
<blockquote>
<p>My intention being to acquire the <em>habitude</em> of all these virtues, I
judg'd it would be well not to distract my attention by attempting
the whole at once, but <strong>to fix it on one of them at a time</strong>…
Conceiving then, that, agreeably to the advice
of Pythagoras in his <em>Golden Verses</em>, daily examination would be
necessary, I contrived the following method for conducting that
examination.</p>
<p>I made a little book, in which I allotted a page for each of the
virtues. I rul'd each page with red ink, so as to have seven
columns, one for each day of the week, marking each column with a
letter for the day. I cross'd these columns with thirteen red lines,
marking the beginning of each line with the first letter of one of
the virtues, on which line, and in its proper column, <strong>I might mark,
by a little black spot, every fault</strong> I found upon examination to have
been committed respecting that virtue upon that day.</p>
<p>I determined to give a week's strict attention to each of the
virtues successively. Thus, in the first week, my great guard was to
avoid every the least offense against <em>Temperance</em>, leaving the
other virtues to their ordinary chance, only marking every evening
the faults of the day.</p>
</blockquote>
<p>So I wondered: was Franklin influenced by the <em>Exercises</em>? I don't
know, but it's possible. Wondering about this I consulted the Mighty
Internet, and found two items in the <a href="https://en.wikipedia.org/wiki/Woodstock_Letters">Woodstock
Letters</a>, a 19th-century Jesuit periodical,
wondering the same thing:</p>
<blockquote>
<p>The following extract from Franklin’s <em>Autobiography</em> will prove of
interest to students of the Exercises: …
Did Franklin learn of our method of Particular Examen from some of
the old members of the Suppressed Society?</p>
</blockquote>
<p>(<a href="https://jesuitonlinelibrary.bc.edu/?a=d&d=wlet19050901-01.1.95&e=-------en-20--1--txt-txIN-------">“Woodstock
Letters” Volume XXXIV #2 (Sep 1905) p.311–313</a>)</p>
<p>I can't guess at the main question, but I can correct one small
detail: although this part of the <em>Autobiography</em> was <em>written</em> around
1784, the time of which Franklin was writing, when he actually made
his little book, was around 1730, well before the suppression of the
Society.</p>
<p>The following issue takes up the matter again:</p>
<blockquote>
<p>Another proof that Franklin was acquainted with the Exercises is
shown from a letter he wrote to Joseph Priestley from London in
1772, where he gives the method of election of the Exercises. …</p>
</blockquote>
<p>(<a href="https://jesuitonlinelibrary.bc.edu/?a=d&d=wlet19051201-01.2.16&e=-------en-20--1--txt-txIN-------">“Woodstock Letters” Volume XXXIV #3 (Dec 1905) p.459–461</a>)</p>
<p>Franklin describes making a decision by listing, on a divided sheet of
paper, the reasons for and against the proposed action. And then a
variation I hadn't seen: balance arguments for and arguments against,
and cross out equally-balanced sets of arguments. Franklin even
suggests evaluations as fine as matching two arguments for with three
slightly weaker arguments against and crossing out all five together.</p>
<p>I don't know what this resembles in the <em>Exercises</em> but it certainly
was striking.</p>
Basterma
https://blog.plover.com/2020/12/26#basterma
<p><a
href="https://twitter.com/RMFifthCircuit/status/1342645283742736385"><img
src="https://pic.blog.plover.com/lang/etym/basterma/rmf.png" class="center" alt="Screenshot of a tweet.
It says “Keys for me: kibbe, cheese pie, spinach pie, stuff grape
leaves (no meat), olives, cheeses, soujuk (spicy lamb sausage),
basterma (err, spicy beed prosciutto), hummous, baba g., taramasalata,
immam bayadi”"/></a></p>
<p>This tweet from Raffi Melkonian describes the appetizer plate at his
house on Christmas. One item jumped out at me:</p>
<blockquote>
<p>basterma (err, spicy beef prosciutto)</p>
</blockquote>
<p>I wondered what that was like, and then I realized I do have some
idea, because I recognized the word. <em>Basterma</em> is not an
originally Armenian word, it's a Turkish loanword, I think canonically
spelled <em>pastırma</em>. And from Turkish it made a long journey through
Romanian and Yiddish to arrive in English as… <em>pastrami</em>…</p>
<p>For which “spicy beef prosciutto” isn't a bad description at all.</p>
Master of the Pecos River
https://blog.plover.com/2020/12/15#pecos-river
<p>The world is so complicated! It has so many things in it that I could
not even have imagined.</p>
<p>Yesterday I learned that since 1949 there has been a compact between
New Mexico and Texas about how to divide up the water in the Pecos
River, which flows from New Mexico to Texas, and then into the Rio Grande.</p>
<p><img src="https://pic.blog.plover.com/law/pecos-river/map.png" class="center" alt="Map of the above,
showing the Pecos River and Rio Grande, both flowing roughly from
northwest to southeast. The Grande flows south past Albuquerque, NM,
and then becomes the border between Texas and Mexico. The Pecos flows
through New Mexico past Brantley Lake and Carlsbad, then into the
Texas Red Bluff Reservoir, and eventually into the Amistad Reservoir
on the Texas-Mexico border."/></p>
<p>New Mexico is not allowed to use all the water before it gets to
Texas. Texas is entitled to receive a certain amount.</p>
<p>There have been disputes about this in the past
(<a href="https://www.scotusblog.com/case-files/cases/texas-v-new-mexico/">the Supreme Court case</a>
has been active since 1974), so in 1988 the Supreme Court appointed
<a href="https://www.engr.colostate.edu/ce/facultystaff/grigg/index.shtml">Neil S. Grigg</a>,
a hydraulic engineer and water management expert from Colorado, to be
“River Master of the Pecos River”, to mediate the disputes and account
for the water. The River Master has
<a href="https://www.ose.state.nm.us/Compacts/Pecos/PDF/pecos_river_master_manual.pdf">a rulebook, which you can read online</a>.
I don't know how much Dr. Grigg is paid for this.</p>
<p>In 2014, <a href="https://en.wikipedia.org/wiki/Hurricane_Odile">Tropical Storm Odile</a> dumped a lot of
rain on the U.S. Southwest. The Pecos River was flooding, so Texas
asked NM to hold onto the Texas share of the water until later. (The
rulebook says they can do this.) New Mexico arranged for the water
that was owed to Texas to be stored in the
<a href="https://en.wikipedia.org/wiki/Brantley_Lake">Brantley Reservoir</a>.</p>
<p>A few months later Texas wanted their water. "OK," said New Mexico.
“But while we were holding it for you in our reservoir, some of it
evaporated. We will give you what is left.”</p>
<p>“No,” said Texas, “we are entitled to a certain amount of water from
you. We want it all.”</p>
<p>But the rule book says that even though the water was in New Mexico's
reservoir, it was Texas's water that evaporated. (Section C5, “Texas
Water Stored in New Mexico Reservoirs”.)</p>
<p><a href="https://www.supremecourt.gov/opinions/20pdf/22o65_dc8e.pdf">Too bad Texas!</a></p>
The corner of Pennsylvania
https://blog.plover.com/2020/12/10#three-corners-3
<p><a href="https://blog.plover.com/misc/three-corners.html">A while back I wrote</a>:</p>
<blockquote>
<p>I see that the Pennsylvania-Delaware-Maryland triple border is near
White Clay Creek State Park, outside of Newark, DE. That sounds
nice, so perhaps I will stop by and take a look, and see if there
really is white clay in the creek.</p>
</blockquote>
<p>I had some free time yesterday, so that is what I did. The creek is
pretty. I did not see anything that appeared to be white clay. Of
course I did not investigate extensively, or even closely, because the
weather was too cold for wading. But the park was beautiful.</p>
<p>There is a walking trail in the park that reaches the tripoint
itself. I didn't walk the whole trail. The park entrance is at the
other end of the park from the tripoint. After wandering around in the
park for a while, I went back to the car, drove to the Maryland end of
the park, and left the car on the side of the Maryland Route 896 (or
maybe Pennsylvania Route 896, it's hard to be sure). Then I cut
across private property to the marker.</p>
<p><a href="https://pic.blog.plover.com/misc/three-corners-3/satellite.png"><img class="center"
src="https://pic.blog.plover.com/misc/three-corners-3/satellite-th.png" alt="Satellite photograph of the
vicinity of the tripoint. The Pennsylvania border stretches east-west
across the picture with the monument marking the place where Maryland
becomes Delaware. Route 896 crosses the border a little bit west of
the tripoint. In between these are a field and a large building of some sort." /></a></p>
<p>The marker itself looks like this:</p>
<div class="center" style="align: center"><a href="https://pic.blog.plover.com/misc/three-corners-3/monument-1.jpg">
<img style="margin-left: auto; margin-right: auto;"
src="https://pic.blog.plover.com/misc/three-corners-3/monument-1-th.jpg" alt="Resting on the floor of a
forest is a block of gray granite,
around two feet tall and eighteen inches square, with a slightly
pointed top. The edges might have been sharp once but are now worn
and rounded. Two side faces of the block are visible. On the left
one is cut a large capital P, and on the right, an M. Under the P is
the date 1849, although part of the 1 has crumbled away." /></a>
<a href="https://pic.blog.plover.com/misc/three-corners-3/monument-2.jpg"><img
src="https://pic.blog.plover.com/misc/three-corners-3/monument-2-th.jpg" alt="The other side of the marker,
this time from higher up. There are another M and P, the M on the
left and the P on the right. There is an engraved brass disc set into
the top of the block." /></a>
</div>
<p>As you see, the Pennsylvania sides of the monument are marked with ‘P’
and the Maryland side with ‘M’. The other ‘M’ is actually in
Delaware.
<a href="https://www.newarkpostonline.com/news/article_a5ec3a04-fe1a-58d4-a317-93c3e887c863.html">This Newark Post article</a>
explains why there is no ‘D’:</p>
<blockquote>
<p>The marker lists only Maryland and Pennsylvania, not Delaware, because
in 1765, Delaware was part of Pennsylvania.</p>
</blockquote>
<p>This does not explain the whole thing. The point was first marked in
1765 by <a href="https://en.wikipedia.org/wiki/Mason%e2%80%93Dixon_line">Mason and Dixon</a> and at that time
Delaware was indeed part of Pennsylvania. But as you see the stone
marker was placed in 1849, by which time Delaware had been there for
some time. Perhaps the people who installed the new marker were
trying to pretend that Delaware did not exist.</p>
<p>[ Addendum 20201218: Daniel Wagner points out that even if the 1849
people were trying to depict things as they were in 1765, the marker
is still wrong; it should have three ‘P’ and one ‘M’, not two of each.
I did read that the surveyors who originally placed the 1849 marker
put it in the wrong spot, and it had to be moved later, so perhaps
they were just not careful people. ]</p>
<p>Theron Stanford notes that this point is also the northwestern corner
of <a href="https://en.wikipedia.org/wiki/Wedge_%28border%29">the Wedge</a>. This sliver of land was east of
the Maryland border, but outside the
<a href="https://en.wikipedia.org/wiki/Twelve%2dMile_Circle">Twelve-Mile Circle</a> and so formed an odd
prodtrusion from Pennsylvania. Pennsylvania only reliquinshed claims to it
in 1921 and it is now agreed to be part of Delaware. Were the Wedge
still part of Pennsylvania, the tripoint would have been at its
southernmost point.</p>
<p>Looking at the map now I see that to get to the marker, I must have driven
within a hundred yards of the westmost point of the Twelve-Mile Circle
itself, and there is a (somewhat more impressive) marker there. Had I
realized at the time I probably would have tried to stop off.</p>
<p><a href="https://plover.com/~mjd/pictures/blog/misc/three-corners-3/pa-de-md-monument/">I have some other pictures of the marker</a>
if you are not tired of this yet.</p>
<p>[ Addendum 20201211: Tim Heany asks “Is there no sign at the border on
896?” There probably is, and this observation is a strong argument
that I parked the car in Maryland. ]</p>
<p>[ Addendum 20201211: Yes, ‘prodtrusion’ was a typo, but it is a gift from the Gods of Dada and should be treasured, not thrown in the trash. ]</p>
Testing for divisibility by 19
https://blog.plover.com/2020/11/21#divisibility-by-19
<p>[ Previously, <a href="https://blog.plover.com/math/divisibility-by-7.html">Testing for divisibility by 7</a>. ]</p>
<p>A couple of nights ago I was keeping Katara company while she revised
an essay on <em>The Scarlet Letter</em> (ugh) and to pass the time one of the
things I did was tinker with the tests for divisibility rules by 9
and 11. In the course of this I discovered the following method for
divisibility by 19:</p>
<blockquote>
<p>Double the last digit and add the next-to-last. <br />
Double that and add the next digit over. <br />
Repeat until you've added the leftmost digit.</p>
</blockquote>
<p>The result will be a smaller number which is a multiple of 19 if and
only if the original number was.</p>
<p>For example, let's consider, oh, I don't know, 2337. We calculate:</p>
<ul>
<li>7·2+3 = 17</li>
<li>17·2 + 3 = 37</li>
<li>37·2 + 2 = 76</li>
</ul>
<p>76 is a multiple of 19, so 2337 was also. But if you're not sure
about 76 you can compute 2·6+7 = 19 and if you're not sure about that
you need more help than I can provide.</p>
<p>I don't claim this is especially practical, but it is fun, not
completely unworkable, and I hadn't seen anything like it before.
You can save a lot of trouble by reducing the intermediate values mod
19 when needed. In the example above
above, after the first step you get to 17, which you can reduce mod 19
to -2, and then the next step is -2·2+3 = -1, and the final step is
-1·2+2 = 0.</p>
<p><a href="https://blog.plover.com/math/divisibility-by-7.html">Last time I wrote about this</a>
Eric Roode sent me a whole compendium of divisibility tests, including
one for divisibility by 19. It's a little like mine, but in reverse:
group the digits in pairs, left to right; multiply each pair by 5 and
then add the next pair. Here's 2337 again:</p>
<ul>
<li>23·5 + 37 = 152</li>
<li>1·5 + 52 = 57</li>
</ul>
<p>Again you can save a lot trouble by reducing mod 19 before the
multiplication. So instead of the first step being 23·5 + 37 you can
reduce the 23·5 to 4·5 = 20 and then add the 37 to get 57 right away.</p>
<p>[ Addendum: Of course this was discovered long ago, and in fact <a href="https://en.wikipedia.org/wiki/Divisibility_rule%23Divisibility_rules_for_numbers_1%25E2%2580%259330">Wikipedia mentions it</a>. ]</p>
<p>[ Addendum 20201123: An earlier version of this article claimed that
the double-and-add step I described preserves the mod-19 residue. It does not, of
course; the doubling step doubles it. It is, however, true that it is
zero afterward if and only if it was zero before. ]</p>
(Untitled)
https://blog.plover.com/2020/11/21#four-seasons
<p><img class="center" border=0 src="https://pic.blog.plover.com/misc/four-seasons/Four%20Seasons.jpg"
alt="I am smiling in front of the main entrance of Four Seasons Total
Landscaping in the Tacony neighborhood of Philadelphia. I am wearing
a gray cap and sweater, jeans, and a blue denim jacket. I have a red
paper Wawa coffee cup in one hand, and am giving a thumbs up with the
other." /></p>
A better way to do remote presentations
https://blog.plover.com/2020/11/02#slide-download-2
<p>A few months ago I wrote an article about a strategy I had tried when
giving a talk via videochat. Typically:</p>
<blockquote>
<p>The slides are presented by displaying them on the speaker's screen,
and then sharing the screen image to the audience.</p>
</blockquote>
<p>I thought I had done it a better way:</p>
<blockquote>
<p>I published the slides on my website ahead of time,
and sent the link to the attendees. They had the option to follow
along on the web site, or to download a copy and follow along in their
own local copy.</p>
</blockquote>
<p>This, I thought, had several advantages:</p>
<ol>
<li><p>Each audience person can adjust the monitor size, font size, colors
to suit their own viewing preferences.</p></li>
<li><p>The audience can see the speaker. Instead of using my outgoing
video feed to share the slides, I could share my face as I spoke.</p></li>
<li><p>With the slides under their control, audience members can go back
to refer to earlier material, or skip ahead if they want. </p></li>
</ol>
<p>When I brought this up with my co-workers, some of them had a very good
objection:</p>
<blockquote>
<p>I am too lazy to keep clicking through slides as the talk
progresses. I just want to sit back and have it do all the work.</p>
</blockquote>
<p>Fair enough! I have done this.</p>
<p>If you package your slides with
<a href="https://github.com/mjdominus/page-turner">page-turner</a>, one instance
becomes the “leader” and the rest are “followers”. Whenever the
leader moves from one slide to the next, a very simple backend server
is notified. The followers periodically contact the server to find
out what slide they are supposed to be showing, and update themselves
accordingly. The person watching the show can sit back and let it do
all the work.</p>
<p>But! If an audience member wants to skip ahead, or go back, that
works too. They can use the arrow keys on their keyboard. Their
follower instance will stop synchronizing with the leader's slide.
Instead, it will display a box in the corner of the page, next to the
current slide's page number, that says what slide the leader is
looking at. The number in this box updates dynamically, so the
audience person always knows how far ahead or behind they are.</p>
<table align=center>
<tr>
<td style="text-align: center"><img src="https://pic.blog.plover.com/talk/slide-download-2/locked.png">
<td style="text-align: center"><img src="https://pic.blog.plover.com/talk/slide-download-2/unlocked.png">
<tr><td style="text-align: center">Synchronized <td style="text-align: center">Unsynchronized
</table>
<p>At left, the leader is displaying slide 3, and the follower is there
also. When the leader moves on to slide 4, the follower instance will
switch automatically.</p>
<p>At right, the follower is still looking at slide 3, but is detached
from the leader, who has
moved on to slide 007, as you can see in the gray box.</p>
<p>When the audience member has finished their excursion, they can click
the gray box and their own instance will immediately resynchronize
with the leader and follow along until the next time they want to
depart.</p>
<p>I used this to give a talk to the Charlotte Perl Mongers last week and
it worked. Responses were generally positive even though the UI is a
little bit rough-looking.</p>
<h3>Technical details</h3>
<p>The back end is a tiny server, written in Python 3 with
<a href="https://palletsprojects.com/p/flask/">Flask</a>. The server is really
tiny, only about 60 lines of code. It has only two endpoints: for
getting the leader's current page, and for setting it. Setting
requires a password.</p>
<pre><code> @app.route('/get-page')
def get_page():
return { "page": app.server.get_pageName() }
@app.route('/set-page', methods=['POST'])
def set_page():
…
password = request.data["password"]
page = request.data["page"]
try:
app.server.update_pageName(page, password)
except WrongPassword:
return failure("Incorrect password"), status.HTTP_401_UNAUTHORIZED
return { "success": True }
</code></pre>
<p>The front end runs in the browser. The user downloads the front-end
script, <code>pageturner.js</code>, from the same place they are getting the
slides. Each slide contains, in its <code>head</code> element:</p>
<pre><code> <LINK REL='next' HREF='slide003.html' TYPE='text/html; charset=utf-8'>
<LINK REL='previous' HREF='slide001.html' TYPE='text/html; charset=utf-8'>
<LINK REL='this' HREF='slide002.html' TYPE='text/html; charset=utf-8'>
<script language="javascript" src="pageturner.js" >
</script>
</code></pre>
<p>The <code>link</code> elements tell <code>page-turner</code> where to go when someone uses
the arrow keys. (This could, of course, be a simple counter, if your
slides are simply numbered, but my slide decks often have
<code>slide002a.html</code> and the like.) Most of <code>page-turner</code>'s code
is in
<a href="https://github.com/mjdominus/page-turner/blob/main/client/pageturner.js"><code>pageturner.js</code></a>,
which is a couple hundred lines of JavaScript.</p>
<p>On page switching, a tiny amount of information is stored in the
browser window's <code>sessionStorage</code> object. This is so that after the
new page is loaded, the program can remember whether it is supposed to
be synchronized.</p>
<p>If you want page-turner to display the leader's slide number when the
follower is desynchronized, as in the example above, you include an
element with class <code>phantom_number</code>. The <code>phantom_click</code> handler
resynchronizes the follower:</p>
<pre><code> <b onclick="phantom_click()" class="phantom_number"></b>
</code></pre>
<p>The password for the <code>set-page</code> endpoint is embedded in the
<code>pageturner.js</code> file. Normally, this is null, which means that the
instance is a follower. If the password is null, <code>page-turner</code> won't
try to update <code>set-page</code>. If you want to be the leader, you change</p>
<pre><code> "password": null,
</code></pre>
<p>to</p>
<pre><code> "password": "swordfish",
</code></pre>
<p>or whatever.</p>
<p>Many improvements are certainly possible. It could definitely look a
lot better, but I leave that to someone who has interest and aptitude
in design.</p>
<p>I know of one serious bug: at present the server doesn't handle SSL,
so must be run at an <code>http://…</code> address; if the slides reside at an
<code>https://…</code> location, the browser will refuse to make the AJAX
requests. This shouldn't be hard to fix.</p>
<h3>Source code download</h3>
<p><a href="https://github.com/mjdominus/page-turner">page-turner</a></p>
<p>Patches welcome.</p>
<h3>License</h3>
<p>The software is licensed under the <a href="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0
license (CC BY 4.0)</a>.</p>
<p>You are free to share (copy and redistribute the software in any
medium or format) and adapt (remix, transform, and build upon the
material) for any purpose, even commercially, so long as you give
appropriate credit, <a href="https://creativecommons.org/licenses/by/4.0/legalcode">provide a link to the
license</a>, and
indicate if changes were made. You may do so in any reasonable manner,
but not in any way that suggests the licensor endorses you or your
use.</p>
<p>Share and enjoy.</p>
Newton's Method and its instability
https://blog.plover.com/2020/10/18#newton-instability
<p>While messing around with Newton's method for
<a href="https://blog.plover.com/math/newton-mediants.html">last week's article</a>, I built this
Desmos thingy:</p>
<iframe src="https://www.desmos.com/calculator/mqkfdoyno9?embed"
width="100%" height="500px" style="border: 1px solid #ccc"
frameborder=0></iframe>
<p>The red point represents the initial guess; grab it and drag it
around, and watch how the later iterations change. Or, better, visit
the Desmos site and
<a href="https://www.desmos.com/calculator/mqkfdoyno9">play with the slider yourself</a>.</p>
<p>(The curve here is <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24y%20%3d%20%28x%2d2%2e2%29%28x%2d3%2e3%29%28x%2d5%2e5%29%24">; it has a local maximum at
around <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%242%2e7%24">, and a local minimum at around <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%244%2e64%24">.)</p>
<p>Watching the attractor point jump around I realized I was arriving at
a much better understanding of the instability of the convergence.
Clearly, if your initial guess happens to be near an extremum of
<img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24f%24">, the next guess could be arbitrarily far away, rather than a
small refinement of the original guess. But even if the original
guess is pretty good, the <em>refinement</em> might be near an extremum, and then the
following guess will be somewhere random. For example, although <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24f%24">
is quite well-behaved in the interval <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5b4%2e3%2c%204%2e35%5d%24">, as the
initial guess <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24g%24"> increases across this interval, the refined guess
<img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5chat%20g%24"> decreases from <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%242%2e74%24"> to <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%242%2e52%24">, and in between these
there is a local maximum that kicks the ball into the weeds. The
result is that at <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24g%3d4%2e3%24"> the method converges to the largest of the
three roots, and at <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24g%3d4%2e35%24">, it converges to the smallest.</p>
<p>This is where the <a href="https://en.wikipedia.org/wiki/Newton_fractal">Newton
basins</a> come from:</p>
<p><a href="https://pic.blog.plover.com/math/newton-instability/basins.png"><img class="center" border=0
src="https://pic.blog.plover.com/math/newton-instability/basins.png" alt="Julia set for the rational function
associated to Newton's method for ƒ:z→z³−1. The plane is divided
symmetrically into three regions, colored red, green, and blue. The
boundary of each two regions (red and green, say) is inhabited by a
series of leaf shapes of the third color (blue), and the boundaries
between the main regions (green, say) and the (blue) leaves are
inhabited by smaller leaves again of the other color (red), and so on
ad infinitum. The boundaries are therefore an infinitely detailed
filigree of smaller and smaller leaves of all three colors."/></a></p>
<p>Here we are considering the function <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24f%3az%5cmapsto%20z%5e3%20%2d1%24"> in the
complex plane. Zero is at the center, and the obvious root, <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24z%3d1%24">
is to its right, deep in the large red region. The other two roots
are at the corresponding positions in the green and blue regions.</p>
<p>Starting at any red point converges to the <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24z%3d1%24"> root. Usually, if
you start near this root, you will converge to it, which is why all
the points near it are red. But some nearish starting points are near
an extremum, so that the next guess goes wild, and then the iteration
ends up at the green or the blue root instead; these areas are the
rows of green and blue leaves along the boundary of the large red
region. And some starting points on the boundaries of those leaves
kick the ball into one of the <em>other</em> leaves…</p>
<p>Here's the corresponding basin diagram for the polynomial <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24y%20%3d%0a%28x%2d2%2e2%29%28x%2d3%2e3%29%28x%2d5%2e5%29%24"> from earlier:</p>
<p><a href="https://pic.blog.plover.com/math/newton-instability/myfractal.png"><img class="center" border=0
src="https://pic.blog.plover.com/math/newton-instability/myfractal.png" style="width: 100%" alt="Julia set for
the function (x-2.2)(x-3.3)(x-5.5). There is a large pink region on
the left, a large yellow region on the right, and in between a large
blue hourglass-shaped region. The boundary of yellow region is decorated
with pink bobbles that protrude into the blue region, and similarly
the boundary of the pink region is decorated with yellow
bobbles. Further details are in the text below." /></a></p>
<p>The real axis is the horizontal hairline along the middle of the
diagram. The three large regions are the main basins of attraction to
the three roots (<img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24x%3d2%2e2%2c%203%2e3%24">, and <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%245%2e5%24">) that lie within them.</p>
<p>But along the boundaries of each region are smaller intrusive bubbles
where the iteration converges to a surprising value. A point moving
from left to right along the real axis passes through the large pink
<img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%242%2e2%24"> region, and then through a very small yellow bubble,
corresponding to the values right around the local maximum near
<img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24x%3d2%2e7%24"> where the process unexpectedly converges to the <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%245%2e5%24">
root. Then things settle down for a while in the blue region,
converging to the <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%243%2e3%24"> root as one would expect, until the value
gets close to the local minimum at <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%244%2e64%24"> where there is a pink
bubble because the iteration converges to the <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%242%2e2%24"> root instead.
Then as <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24x%24"> increases from <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%244%2e64%24"> to <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%245%2e5%24">, it leaves the pink
bubble and enters the main basin of attraction to <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%245%2e5%24"> and stays
there.</p>
<p>If the picture were higher resolution, you would be able to see that
the pink bubbles all have tiny yellow bubbles growing out of them (one
is 4.39), and the tiny yellow bubbles have even tinier pink bubbles,
and so on forever.</p>
<p>(This was generated by the
<a href="http://usefuljs.net/fractals/">Online Fractal Generator at usefuljs.net</a>;
the labels were added later by me. The labels’ positions are only approximate.)</p>
<p>[ Addendum: Regarding complex points and <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24f%20%3a%20z%5cmapsto%20z%5e3%2d1%24"> I said
“some nearish starting points are near an extremum”. But this isn't
right; <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24f%24"> has no extrema. It has an inflection point at <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24z%3d0%24">
but this doesn't explain the instability along the lines
<img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5ctheta%20%3d%20%5cfrac%7b2k%2b1%7d%7b3%7d%5cpi%24">. So there's something going on
here with the complex derivative that I don't understand yet. ]</p>
Fixed points and attractors, part 3
https://blog.plover.com/2020/10/18#attractors-3
<p>Last week I wrote about <a href="https://blog.plover.com/math/newton-mediants.html">a super-lightweight variation on Newton's
method</a>, in which one takes this function:
$$f_n : \frac ab \mapsto \frac{a+nb}{a+b}$$</p>
<p>or equivalently</p>
<p>$$f_n : x \mapsto \frac{x+n}{x+1}$$</p>
<p>Iterating <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24f_n%24"> for a suitable initial value (say, <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%241%24">) converges
to <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5csqrt%20n%24">:</p>
<p>$$
\begin{array}{rr}
x & f_3(x) \\ \hline
1.0 & 2.0 \\
2.0 & 1.667 \\
1.667 & 1.75 \\
1.75 & 1.727 \\
1.727 & 1.733 \\
1.733 & 1.732 \\
1.732 & 1.732
\end{array}
$$</p>
<p>Later I remembered that
a few months back I wrote a couple of articles about a more general method
that includes this as a special case:</p>
<ul>
<li><a href="https://blog.plover.com/math/attractors.html">How to calculate the square root of 2</a></li>
<li><a href="https://blog.plover.com/math/attractors-2.html">More about fixed points and attractors</a></li>
</ul>
<p>The general idea was:</p>
<blockquote>
<p>Suppose we were to pick a function <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24f%24"> that had <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5csqrt%202%24"> as a
fixed point. Then <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5csqrt%202%24"> might be an attractor, in which case
iterating <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24f%24"> will get us increasingly accurate approximations to
<img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5csqrt%202%24">.</p>
</blockquote>
<p>We can see that <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5csqrt%20n%24"> is a fixed point of <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24f_n%24">:</p>
<p>$$
\begin{align}
f_n(\sqrt n) & = \frac{\sqrt n + n}{\sqrt n + 1} \\
& = \frac{\sqrt n(1 + \sqrt n)}{1 + \sqrt n} \\
& = \sqrt n
\end{align}
$$</p>
<p>And in fact, it is an
attracting fixed point, because if <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24x%20%3d%20%5csqrt%20n%20%2b%20%5cepsilon%24"> then</p>
<p>$$\begin{align}
f_n(\sqrt n + \epsilon)
& = \frac{\sqrt n + \epsilon + n}{\sqrt n + \epsilon + 1} \\
& = \frac{(\sqrt n + \sqrt n\epsilon + n) - (\sqrt n -1)\epsilon}{\sqrt n + \epsilon + 1} \\
& = \sqrt n - \frac{(\sqrt n -1)\epsilon}{\sqrt n + \epsilon + 1}
\end{align}$$</p>
<p>Disregarding the <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cepsilon%24"> in the denominator we obtain
$$f_n(\sqrt n + \epsilon) \approx
\sqrt n - \frac{\sqrt n - 1}{\sqrt n + 1} \epsilon
$$</p>
<p>The error term <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%2d%5cfrac%7b%5csqrt%20n%20%2d%201%7d%7b%5csqrt%20n%20%2b%201%7d%20%5cepsilon%24"> is
strictly smaller than the original error <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cepsilon%24">, because <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%240%20%3c%0a%5cfrac%7bx%2d1%7d%7bx%2b1%7d%20%3c%201%24"> whenever <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24x%3e1%24">. This shows that the fixed point
<img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5csqrt%20n%24"> is attractive.</p>
<p>In the previous articles I considered several different simple
functions that had fixed points at <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5csqrt%20n%24">, but I didn't think to
consider this unusally simple one. I said at the time:</p>
<p><blockquote>
<p>I had meant to write about Möbius transformations, but that
will have to wait until next week, I think.<p></p>
</blockquote></p>
<p>but I never did get around to the Möbius transformations, and I have long since forgotten
what I planned to say. <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24f_n%24"> is an example of a Möbius transformation, and I wonder if
my idea was to systematically find all the Möbius transformations that have <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5csqrt%20n%24">
as a fixed point, and see what they look like. It is probably
possible to automate the analysis of whether the fixed point is
attractive, and if not to apply one of the transformations from the
previous article to make it attractive.</p>
Newton's Method but without calculus — or multiplication
https://blog.plover.com/2020/10/13#newton-mediants
<p>Newton's method goes like this: We have a function <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24f%24"> and we want
to solve the equation <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24f%28x%29%20%3d%200%2e%24"> We guess an approximate solution,
<img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24g%24">, and it doesn't have to be a very good guess.</p>
<p><img class="center" src="https://pic.blog.plover.com/math/newton-mediants/graph1.png" alt="The graph of a wiggly
polynomial girve with roots between 2 and 2.5, between 3 and 3.5, and
between 5 and 6. The middle root is labeled with a question mark.
One point of the curve, not too different from the root, is marked in
blue and labeled “⟨g,f(g)⟩”." /></p>
<p>Then we calculate
the line <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24T%24"> tangent to <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24f%24"> through the point <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5clangle%20g%2c%0af%28g%29%5crangle%24">. This line intersects the <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24x%24">-axis at some new point
<img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5clangle%20%5chat%20g%2c%200%5crangle%24">, and this new value, <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5chat%20g%24">, is a better
approximation to the value we're seeking.</p>
<p><img class="center" src="https://pic.blog.plover.com/math/newton-mediants/graph2.png" alt="The same graph as
before, but with a tangent to the curve drawn through the blue point.
It intersects the x-axis quite close to the root. The intersection
point is labeled “ĝ”." /></p>
<p><a href="https://pic.blog.plover.com/math/newton-mediants/graph3.png"><img style="float: left; width: 15%;
margin-right: 1em;" src="https://pic.blog.plover.com/math/newton-mediants/graph3.png" alt="In the left
margin, a close-up detail of the same curve as before, this time
showing the tangent line at ⟨ĝ,f(ĝ)⟩. The diagram is a close-up
because the line intersects the x-axis extremely close to the actual
root." /></a></p>
<p>Analytically, we have:</p>
<p>$$\hat g = g - \frac{f(g)}{f'(g)}$$</p>
<p>where <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24f%27%28g%29%24"> is the derivative of <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24f%24"> at <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24g%24">.</p>
<p>We can repeat the process if we like, getting better and better
approximations to the solution. (See detail at left; click to
enlarge. Again, the blue line is the tangent, this time at <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5clangle%0a%5chat%20g%2c%20f%28%5chat%20g%29%5crangle%24">. As you can see, it intersects the axis very close
to the actual solution.)</p>
<p><br clear="right" /></p>
<p>In general, this requires calculus or something like it, but in any
particular case you can avoid the calculus. Suppose we would like to
find the square root of 2. This amounts to solving the equation
$$x^2-2 = 0.$$ The function <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24f%24"> here is <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24x%5e2%2d2%24">, and <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24f%27%24"> is
<img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%242x%24">. Once we know (or guess) <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24f%27%24">, no further calculus is
needed. The method then becomes: Guess <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24g%24">, then calculate $$\hat g
= g - \frac{g^2-2}{2g}.$$ For example, if our initial guess is <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24g%20%3d%0a1%2e5%24">, then the formula above tells us that a better guess is <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5chat%20g%0a%3d%201%2e5%20%2d%20%5cfrac%7b2%2e25%20%2d%202%7d%7b3%7d%20%3d%201%2e4166%5cldots%24">, and repeating the process
with <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5chat%20g%24"> produces <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%241%2e41421%5cmathbf%7b5686%7d%24">, which is very close
to the correct result <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%241%2e41421%5cmathbf%7b3562%7d%24">. If we want the square
root of a different number <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24n%24"> we just substitute it for the <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%242%24">
in the numerator.</p>
<p>This method for extracting square roots works well and requires no
calculus. It's called the <a href="https://en.wikipedia.org/wiki/Babylonian_method">Babylonian
method</a> and while there's no evidence that it
was actually known to the Babylonians, it is quite ancient; it was
first recorded by Hero of Alexandria about 2000 years ago.</p>
<p>How might this have been discovered if you didn't have calculus? It's
actually quite easy. Here's a picture of the number line. Zero is at
one end, <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24n%24"> is at the other, and somewhere in between is <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5csqrt%20n%24">,
which we want to find.</p>
<p><img class="center" src="https://pic.blog.plover.com/math/newton-mediants/numberline1.svg" alt="A line with
the left enpoint marked “0”, the right endpoint marked “n”, and a
point in between marked “square root of n”." /></p>
<p>Also somewhere in between is our guess <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24g%24">. Say we guessed too low,
so <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%240%20%5clt%20g%20%3c%20%5csqrt%20n%24">. Now consider <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cfrac%20ng%24">. Since <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24g%24"> is
too small to be <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5csqrt%20n%24"> exactly, <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cfrac%20ng%24"> must be too large. (If
<img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24g%24"> and <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cfrac%20ng%24"> were both smaller than <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5csqrt%20n%24">, then their
product would be smaller than <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24n%24">, and it isn't.)</p>
<p><img class="center" src="https://pic.blog.plover.com/math/newton-mediants/numberline2.svg" alt="The previous
illustration, with green points marked “g” and “\frac{n}{g}”. The
first of these it to the left of the square root of n, the second to
its right." /></p>
<p>Similarly, if the guess <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24g%24"> is too large, so that <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5csqrt%20n%20%3c%20g%24">, then <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cfrac%20ng%24"> must be less than <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5csqrt%20n%24">. The
important point is that <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5csqrt%20n%24"> is <em>between</em> <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24g%24"> and <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cfrac%0ang%24">. We have narrowed down the interval in which <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5csqrt%20n%24"> lies,
just by guessing.</p>
<p>Since <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5csqrt%20n%24"> lies in the interval between <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24g%24"> and <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cfrac%20ng%24">
our next guess should be somewhere in this smaller interval.
The most obvious thing we
can do is to pick the point halfway in the middle of <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24g%24"> and <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cfrac%0ang%24">,
So if we guess the average, $$\frac12\left(g + \frac ng\right),$$ this will probably be
much closer to <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5csqrt%20n%24"> than <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24g%24"> was:</p>
<p><img class="center" src="https://pic.blog.plover.com/math/newton-mediants/numberline3.svg" alt="The previous
illustration, but the point exactly midway between g and \frac{n}{g}
is marked in blue. It is quote close to the point marked “square root
of n”." /></p>
<p>This average is exactly what Newton's method would have calculated,
because
$$\frac12\left(g + \frac ng\right) =
g - \frac{g^2-n}{2g}.$$</p>
<p>But we were able to arrive at the same computation with no calculus at
all — which is why this method could have been, and was, discovered 1700 years
before Newton's method itself.</p>
<p>If we're dealing with rational numbers then we might write <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24g%3d%5cfrac%0aab%24">, and then instead of replacing our guess <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24g%24"> with a better
guess <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cfrac12%5cleft%28g%20%2b%20%5cfrac%20ng%5cright%29%24">, we could think of it as
replacing our guess <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cfrac%20ab%24"> with a better guess
<img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cfrac12%5cleft%28%5cfrac%20ab%20%2b%20%5cfrac%20n%7b%5cfrac%20ab%7d%5cright%29%24">. This simplifies
to</p>
<p>$$\frac ab \Rightarrow \frac{a^2 + nb^2}{2ab}$$</p>
<p>so that for example, if we are calculating <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5csqrt%202%24">, and we start
with the guess <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24g%3d%5cfrac32%24">, the next guess is
$$\frac{3^2 + 2\cdot2^2}{2\cdot3\cdot 2} = \frac{17}{12} = 1.4166\ldots$$ as we saw
before. The approximation after that is
<img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cfrac%7b289%2b288%7d%7b2%5ccdot17%5ccdot12%7d%20%3d%20%5cfrac%7b577%7d%7b408%7d%20%3d%0a1%2e41421568%5cldots%24">. Used this way, the method requires only integer
calculations, and converges very quickly.</p>
<p>But the numerators and denominators increase rapidly, which is good in
one sense (it means you get to the accurate approximations quickly)
but can also be troublesome because the numbers get big and also
because you have to multiply, and multiplication is hard.</p>
<p>But remember how we figured out to do this calculation in the first
place: all we're really trying to
do is find a number in between <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24g%24"> and <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cfrac%20ng%24">. We did that
the first way that came to mind, by
averaging. But perhaps there's a simpler operation that we could use
instead, something even easier to compute?</p>
<p>Indeed there is! We can calculate the
<a href="https://en.wikipedia.org/wiki/mediant_%28mathematics%29"><em>mediant</em></a>. The mediant of <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cfrac%20ab%24">
and <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cfrac%20cd%24"> is simply $$\frac{a+c}{b+d}$$ and it is very easy to
show that it lies between <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cfrac%20ab%24"> and <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cfrac%20cd%24">, as we want.</p>
<p>So instead of the relatively complicated $$\frac ab \Rightarrow \frac{a^2 + nb^2}{2ab}$$
operation, we can try the very simple and quick
$$\frac ab \Rightarrow \operatorname{mediant}\left(\frac ab,
\frac{nb}{a}\right) = \frac{a+nb}{b+a}$$ operation.</p>
<p>Taking <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24n%3d2%24"> as before, and starting with <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cfrac%2032%24">, this produces:</p>
<p>$$ \frac 32
\Rightarrow\frac{ 7 }{ 5 }
\Rightarrow\frac{ 17 }{ 12 }
\Rightarrow\frac{ 41 }{ 29 }
\Rightarrow\frac{ 99 }{ 70 }
\Rightarrow\frac{ 239 }{ 169 }
\Rightarrow\frac{ 577 }{ 408 }
\Rightarrow\cdots$$</p>
<p>which you may recognize as the
<a href="https://en.wikipedia.org/wiki/Continued_fraction%23Infinite_continued_fractions_and_convergents">convergents</a>
of <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5csqrt2%24">. These are actually the rational
approximations of <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5csqrt%202%24"> that are optimally accurate relative to the sizes of their
denominators. Notice that <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cfrac%7b17%7d%7b12%7d%24"> and <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cfrac%7b577%7d%7b408%7d%24">
are in there as they were before, although it takes longer to get to them.</p>
<p>I think it's cool that you can view it as a highly-simplified version
of Newton's method.</p>
<hr />
<p>[ Addendum: An earlier version of the last paragraph claimed:</p>
<blockquote>
<p>None of this is a big surprise, because it's well-known that you
can get the convergents of <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5csqrt%20n%24"> by applying the transformation
<img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cfrac%20ab%5cRightarrow%20%5cfrac%7ba%2bnb%7d%7ba%2bb%7d%24">, starting with <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5cfrac11%24">.</p>
</blockquote>
<p>Simon Tatham pointed out that this was mistaken. It's true when
<img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24n%3d2%24">, but not in general. The sequence of fractions that you get
does indeed converge to <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5csqrt%20n%24">, but it's not usually the
convergents, or even in lowest terms. When <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24n%3d3%24">, for example, the numerators and denominators are all even. ]</p>
<p>[ Addendum: Newton's method as I described it, with the crucial <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24g%20%e2%86%92%20g%20%2d%0a%5cfrac%7bf%28g%29%7d%7bf%27%28g%29%7d%24"> transformation, was actually invented in 1740
by <a href="https://en.wikipedia.org/wiki/Thomas_Simpson">Thomas Simpson</a>. Both Isaac Newton and Thomas
Raphson had earlier described only special cases, as had several Asian
mathematicians, including <a href="https://en.wikipedia.org/wiki/Seki_K%c5%8dwa">Seki Kōwa</a>. ]</p>
<p>[ Previous discussion of convergents: <a href="https://blog.plover.com/math/sqrt-3.html">Archimedes and the square root
of 3</a>; <a href="https://blog.plover.com/math/60-degree-angles.html">60-degree angles on a
lattice</a>. A different <a href="https://blog.plover.com/math/attractors-2.html">variation
on the Babylonian method</a>. ]</p>
<p>[ Note to self: Take a look at what the AM-GM inequality has to say
about the behavior of <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5chat%20g%24">. ]</p>
<p>[ Addendum 20201018: A while back I discussed the general method of
picking a function <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24f%24"> that has <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24%5csqrt%202%24"> as a fixed point, and
iterating <img src="https://chart.apis.google.com/chart?chf=bg,s,00000000&cht=tx&chl=%24f%24">. <a href="https://blog.plover.com/math/attractors.html">This is yet another example of such a function</a>. ]</p>