<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Max Shinn's blog</title>
    <description>Max Shinn's blog.</description>
    <link>/</link>
    <atom:link href="/zfeed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Sun, 17 Mar 2024 21:07:34 +0000</pubDate>
    <lastBuildDate>Sun, 17 Mar 2024 21:07:34 +0000</lastBuildDate>
    <generator>Jekyll v3.9.5</generator>
    
      <item>
        <title>Which word is the bird?
</title>
        <description>&lt;p&gt;What do you call a turkey in Turkey?  An india!  So what do you call an india in
India?  A peru!  English isn’t the only language that likes to name its birds
after countries.&lt;/p&gt;

&lt;p&gt;Before you ask what you call a peru in Peru, just look at the chart:&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;a href=&quot;/res/turkey/turkey_chart.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;/res/turkey/turkey_chart.jpg&quot; /&gt;&lt;/a&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;The name for turkey in many different languages.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;It turns out most languages name this bird after a foreign country.  And when
you trace the names from country to country, you almost always end up in Peru.&lt;/p&gt;

&lt;h2 id=&quot;is-that-right&quot;&gt;Is that right?&lt;/h2&gt;

&lt;p&gt;Well… no, the diagram above is not quite correct.  The most important links in
the diagram are over-simplified.  In particular:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Turkish was not the only widespread language in Turkey when turkeys came to
Europe.&lt;/strong&gt; Three languages were widespread in Turkey at the time: Turkish,
Mesopotamian Arabic, and Kurmanji Kurdish.  Turkish has two words for “turkey”:
one refers to India, and the other is &lt;em&gt;culuk&lt;/em&gt;, from an Ottoman word for
“woodcock”.  Mesopotamian Arabic and Kurmanji Kurdish both have onomatopoeia
names: &lt;em&gt;alu alu&lt;/em&gt; and &lt;em&gt;elok&lt;/em&gt;, respectively.  So while some people from Turkey
would eventually call a turkey an “india”, not everybody would.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;India has many languages.&lt;/strong&gt; If we exclude Malayalam (see below), many of the
most widespread Indian languages call the turkey a “peru”.  However, some of
them also call it a turkey.  And some do not refer to a place at all.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The dominant language in Calicut (now Kozhikode) is Malayalam, not Hindi.&lt;/strong&gt;
Many of the references to India are actually references to the city of Kozhikode
(formerly known as Calicut) where Malayalam is the dominant language.  Malayalam
has different words for turkey than most Indian languages.  Three words are in
common use: &lt;em&gt;vaan kozhi&lt;/em&gt; (literally “mouth chicken”), &lt;em&gt;thurki kozhi&lt;/em&gt; (literally
“Turkey chicken”) or &lt;em&gt;kalkkam&lt;/em&gt;, which comes from the Dutch word, meaning
“Calicut”.  So, in Kozhikode, they don’t actually call the bird a peru.  They
call it a mouth chicken, a turkey, or… a kozhikode.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Historically, “India” could have also meant the West Indies.&lt;/strong&gt; The languages
of the pre-Columbian West Indies primarily derived from the Arawakan language
family.  The most widely spoken of these languages was Taíno.  Since it
continued to be spoken for many years after colonization, we know the word for
turkey was &lt;em&gt;guanaho&lt;/em&gt;.  (Modern Cuban Spanish still uses the word &lt;em&gt;guanajo&lt;/em&gt;,
based on the Taíno word.)  The proto-Arawakan root for the word “turkey” is
thought to be
&lt;a href=&quot;https://en.wiktionary.org/wiki/Appendix:Proto-Arawakan_reconstructions&quot;&gt;*mara-dii&lt;/a&gt;,
which would have been either modified or replaced in the various Arawakan
languages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Spanish has many words for turkey.&lt;/strong&gt; Today, the dominant language in Peru is
Spanish, but Spanish has many different words for turkey.  The Castilian
Spanish word &lt;em&gt;pavo&lt;/em&gt; comes from the Latin for peacock, but other names include
&lt;em&gt;chompipe&lt;/em&gt;, &lt;em&gt;chumpe&lt;/em&gt;, &lt;em&gt;gallina de la tierra&lt;/em&gt;, &lt;em&gt;gánso&lt;/em&gt;, &lt;em&gt;guanajo&lt;/em&gt;, &lt;em&gt;guajolote&lt;/em&gt;, &lt;em&gt;kókono&lt;/em&gt;, 
&lt;em&gt;picho&lt;/em&gt;, &lt;em&gt;pisco&lt;/em&gt;, and &lt;em&gt;pípila&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Historically, “Peru” referred to the regions of South America colonized by the
Spanish.&lt;/strong&gt;  The area called “Peru” roughly coincided with the Inca Empire, but
did not include Mexico, which fell within New Spain.  Turkeys were domesticated
throughout the Americas long before the arrival of the Spanish.  Therefore,
instead of Spanish, we need to look at the languages of pre-colonial Peru.
While most of these languages are now extinct, two such languages are still
spoken today: Quechua and Aymara.  The Quechua word for turkey is &lt;em&gt;qallqatu&lt;/em&gt;,
but it is unclear if this is a modern loan word referring to Kozhikode.  The
Aymara word for turkey is &lt;em&gt;pawu&lt;/em&gt;, and again, it is unknown whether this word
existed in pre-Columbian times, whether it derived from the modern Spanish word
&lt;em&gt;pavo&lt;/em&gt;, or whether it refers to “Peru”, another self-reference.  Since turkeys
are not native to Peru, the name for turkey may not have even been standardised
in these regions.&lt;/p&gt;

&lt;p&gt;So, using all of this information, we can construct a more accurate chart.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;a href=&quot;/res/turkey/turkey_chart_accurate.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;/res/turkey/turkey_chart_accurate.jpg&quot; /&gt;&lt;/a&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;The more accurate name for turkey in many different languages.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;This time, the flow through languages can go in loops and circles, and there is
no single country at the end.&lt;/p&gt;

&lt;h2 id=&quot;so-where-are-turkeys-actually-from&quot;&gt;So where are turkeys actually from?&lt;/h2&gt;

&lt;p&gt;Turkeys are not native to Peru.  In fact, they are not native to &lt;em&gt;any&lt;/em&gt; of the
lands they are named after.  Turkeys are native to North and Central America.
By 700 AD, wild turkeys (&lt;em&gt;Meleagris gallopavo gallopavo&lt;/em&gt;) were domesticated in
Southern Mexico, and by 1500, this domesticated breed of turkey was widespread
throughout Mexico, Central America, and parts of northern South America.  This
is the domesticated breed that the Spanish brought back to Europe in 1511.&lt;/p&gt;

&lt;p&gt;Turkeys grew to be very popular in Europe and were widespread by the 1550s.
They were so popular that the English colonists brought turkeys with them to New
England in the early 1600s.  These domesticated turkeys interbred with the much
larger wild turkeys in eastern North America (&lt;em&gt;Meleagris gallopavo
silvestris&lt;/em&gt;). The hybrid turkey, now known as the &lt;a href=&quot;https://en.wikipedia.org/wiki/Bronze_turkey&quot;&gt;American
Bronze&lt;/a&gt;, was then exported from the
Americas back to Europe, and from Europe around the world.  The hybrid turkeys
became even more popular than the original domesticated Mexican turkeys, and are
the same turkeys we enjoy today.&lt;/p&gt;

&lt;h3 id=&quot;appendix-turkey-naming-trivia&quot;&gt;Appendix: Turkey naming trivia&lt;/h3&gt;

&lt;p&gt;In Farsi, one word for turkey is &lt;em&gt;bughalamun&lt;/em&gt;, the same as the word for
“chameleon”.  This word used to be the name of a colourful fabric (a
&lt;a href=&quot;https://en.wikipedia.org/wiki/Damask&quot;&gt;damask&lt;/a&gt;).  Like chameleons, male turkeys
can change the colour of the skin on their head to red, blue, or white.  &lt;a href=&quot;https://link.springer.com/article/10.1557/mrs.2014.64&quot;&gt;This
is due to the arrangement of collagen and blood vessels in their
skin&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In Farsi, another word for turkey translates to “elephant bird”, a translation
shared with Burmese and Thai.  Male turkeys have a
“&lt;a href=&quot;https://en.wikipedia.org/wiki/Turkey_(bird)#Anatomy&quot;&gt;snood&lt;/a&gt;”, a long, narrow,
dangly flap of skin which hangs over the top of their beak.  If you squint, this
might resemble an elephant’s trunk.  This snood can also contract to form a
small horn, resembling a unicorn.  All of these colours and shapes on its face
earned it the name “seven faced bird” in Japanese and Korean.&lt;/p&gt;

&lt;p&gt;In Greek, the translation is literally “French bird”, but the origin of the term
“French” is unrelated to France.  The Greek name for turkey is &lt;em&gt;galopoula&lt;/em&gt;.  The
suffix &lt;em&gt;poula&lt;/em&gt; is a feminine suffix (and &lt;em&gt;pouli&lt;/em&gt; can also mean bird), but &lt;em&gt;galo&lt;/em&gt;
originates from romance languages, meaning cockerel.  It is probably a
&lt;a href=&quot;[https://el.wiktionary.org/wiki/%CE%B3%CE%B1%CE%BB%CE%BF%CF%80%CE%BF%CF%8D%CE%BB%CE%B1&quot;&gt;shortened loan word from old romance languages, &lt;em&gt;galo
d’India&lt;/em&gt;&lt;/a&gt;.
But in Greek, &lt;em&gt;galo&lt;/em&gt; can also mean “French”.  So, the Greek the reference to
France is just a coincidence, and may truly be a reference to India.&lt;/p&gt;

&lt;p&gt;Likewise, in Pennsylvania German, reference to Wales is a coincidence.  The
literal translation of &lt;em&gt;Welschhinkel&lt;/em&gt; is “foreign chicken”, not “Welsh chicken”.
In Pennsylvania German, &lt;em&gt;Welsch&lt;/em&gt; does not mean Wales, it simply means “foreign”.
By coincidence, the word for “foreign” bears an uncanny resemblance to the name
of a country, even though the etymologies are different.&lt;/p&gt;

&lt;p&gt;Finally, the best false etymology of all: in Malayalam, Kozhikode translates to
“chicken castle” (from &lt;em&gt;kozhi&lt;/em&gt; and &lt;em&gt;kota&lt;/em&gt;)!&lt;/p&gt;

&lt;h3 id=&quot;appendix-words-for-turkey&quot;&gt;Appendix: Words for turkey&lt;/h3&gt;

&lt;p&gt;The following is a list of different translations of the word “turkey”.  I have
left out any words which are named after India, Kozhikode, Turkey, and Peru.
Some of the languages below may have a second word named after one of these four
places, which do not appear in the table, even if those names are more popular
than the listed names.&lt;/p&gt;

&lt;p&gt;I have confirmed each of these words through multiple sources.  When a source is
not obvious, I have linked to it.&lt;/p&gt;

&lt;h4 id=&quot;places-with-no-native-turkeys&quot;&gt;Places with no native turkeys&lt;/h4&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Language&lt;/th&gt;
      &lt;th&gt;English translation&lt;/th&gt;
      &lt;th&gt;Word (latin script)&lt;/th&gt;
      &lt;th&gt;Word (original script)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Albanian&lt;/td&gt;
      &lt;td&gt;Sea rooster&lt;/td&gt;
      &lt;td&gt;Gjel Deti&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Arabic (Egyptian)&lt;/td&gt;
      &lt;td&gt;Greek (Byzantine) rooster&lt;/td&gt;
      &lt;td&gt;Dik rumi&lt;/td&gt;
      &lt;td&gt;ديك رومي&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Arabic (Levantine)&lt;/td&gt;
      &lt;td&gt;Ethiopian (Abyssinian) rooster&lt;/td&gt;
      &lt;td&gt;Dik al-habas&lt;/td&gt;
      &lt;td&gt;دِيك الْحَبَش⁩&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Arabic (Mesopotamian)&lt;/td&gt;
      &lt;td&gt;(Onomatopoeia)&lt;/td&gt;
      &lt;td&gt;Alou alou&lt;/td&gt;
      &lt;td&gt;علوعلو&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Arabic (Moroccan)&lt;/td&gt;
      &lt;td&gt;Baby&lt;/td&gt;
      &lt;td&gt;Bibi&lt;/td&gt;
      &lt;td&gt;بيبي⁩&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Breton&lt;/td&gt;
      &lt;td&gt;Spanish chicken&lt;/td&gt;
      &lt;td&gt;Yar-Spagn&lt;sup id=&quot;fnref:bre&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:bre&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Burmese&lt;/td&gt;
      &lt;td&gt;Elephant fowl&lt;/td&gt;
      &lt;td&gt;Krakhcang&lt;/td&gt;
      &lt;td&gt;ကြက်ဆင်&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Chechen&lt;/td&gt;
      &lt;td&gt;Moscow&lt;/td&gt;
      &lt;td&gt;Moscal&lt;/td&gt;
      &lt;td&gt;москал&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Chinese&lt;/td&gt;
      &lt;td&gt;Fire chicken&lt;/td&gt;
      &lt;td&gt;Huǒjī (Mandarin), Fo gai (Cantonese)&lt;/td&gt;
      &lt;td&gt;火雞&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Cornish&lt;/td&gt;
      &lt;td&gt;Guinea chicken&lt;/td&gt;
      &lt;td&gt;Yar Gyni&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Czech&lt;/td&gt;
      &lt;td&gt;Rooster (from Proto-Slavic)&lt;/td&gt;
      &lt;td&gt;Krocan&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Farsi&lt;/td&gt;
      &lt;td&gt;Chameleon, colourful fabric&lt;/td&gt;
      &lt;td&gt;Buqalamun&lt;/td&gt;
      &lt;td&gt;بوقلمون&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Farsi&lt;/td&gt;
      &lt;td&gt;Elephant bird&lt;/td&gt;
      &lt;td&gt;Fill Murgh&lt;/td&gt;
      &lt;td&gt;فیل‌مرغ&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;German&lt;/td&gt;
      &lt;td&gt;(Onomatopoeia)&lt;/td&gt;
      &lt;td&gt;Pute&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;German&lt;/td&gt;
      &lt;td&gt;Rooster that says “trut”&lt;/td&gt;
      &lt;td&gt;Truthahn&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Greek&lt;/td&gt;
      &lt;td&gt;“French” bird&lt;/td&gt;
      &lt;td&gt;Galopoula&lt;/td&gt;
      &lt;td&gt;γαλοπούλα&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Ingush&lt;/td&gt;
      &lt;td&gt;Moscow&lt;/td&gt;
      &lt;td&gt;Moscal&lt;/td&gt;
      &lt;td&gt;москал&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Italian&lt;/td&gt;
      &lt;td&gt;(Onomatopoeia)&lt;/td&gt;
      &lt;td&gt;Tacchino&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Japanese&lt;/td&gt;
      &lt;td&gt;Seven-faced bird&lt;/td&gt;
      &lt;td&gt;Shichimenchō&lt;/td&gt;
      &lt;td&gt;七面鳥&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Khmer&lt;/td&gt;
      &lt;td&gt;French (European) chicken&lt;/td&gt;
      &lt;td&gt;Mŏən baarang&lt;/td&gt;
      &lt;td&gt;មាន់បារាំង&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Korean&lt;/td&gt;
      &lt;td&gt;Seven-faced bird&lt;/td&gt;
      &lt;td&gt;Chilmyeonjo&lt;/td&gt;
      &lt;td&gt;칠면조&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Kurdish (Kurmanji)&lt;/td&gt;
      &lt;td&gt;(Onomatopoeia)&lt;/td&gt;
      &lt;td&gt;Elok &lt;sup id=&quot;fnref:kurd&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:kurd&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;2&lt;/a&gt;&lt;/sup&gt;&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Luxembourgish&lt;/td&gt;
      &lt;td&gt;Snot hen&lt;/td&gt;
      &lt;td&gt;Schnuddelhong&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Macedonian&lt;/td&gt;
      &lt;td&gt;Egypt&lt;/td&gt;
      &lt;td&gt;Misir&lt;/td&gt;
      &lt;td&gt;мисир&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Malay&lt;/td&gt;
      &lt;td&gt;Dutch chicken&lt;/td&gt;
      &lt;td&gt;Ayam belanda&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Pennsylvania German&lt;/td&gt;
      &lt;td&gt;Foreign (Welsh) chicken&lt;/td&gt;
      &lt;td&gt;Welschhinkel&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Quechua&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;Qallqatu&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Romanian&lt;/td&gt;
      &lt;td&gt;Rooster (from Proto-Slavic)&lt;/td&gt;
      &lt;td&gt;Curcan&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Scots&lt;/td&gt;
      &lt;td&gt;(Onomatopoeia)&lt;/td&gt;
      &lt;td&gt;Bubbly-jock&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Scottish Gaelic&lt;/td&gt;
      &lt;td&gt;French rooster&lt;/td&gt;
      &lt;td&gt;Coileach-Frangach&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Scottish Gaelic&lt;/td&gt;
      &lt;td&gt;Warrior&lt;/td&gt;
      &lt;td&gt;Pulaidh&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Serbian&lt;/td&gt;
      &lt;td&gt;Rooster (from Proto-Slavic)&lt;/td&gt;
      &lt;td&gt;Ćurka&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Slovak&lt;/td&gt;
      &lt;td&gt;Sea/sailor&lt;/td&gt;
      &lt;td&gt;Moriak&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Spanish (Colombia)&lt;/td&gt;
      &lt;td&gt;Bird (from Quechua)&lt;/td&gt;
      &lt;td&gt;Pisco&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Spanish (Cuba)&lt;/td&gt;
      &lt;td&gt;(From Taino)&lt;/td&gt;
      &lt;td&gt;Guanajo&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Spanish (El Salvador)&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;Chumpe&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Spanish (Guatemala)&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;Chompipe&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Spanish (Mexico)&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;Picho&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Spanish (Mexico)&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;Pípila&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Spanish (Mexico)&lt;/td&gt;
      &lt;td&gt;(From Nahuatl)&lt;/td&gt;
      &lt;td&gt;Guajolote&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Spanish (Mexico, historic)&lt;/td&gt;
      &lt;td&gt;Local chicken&lt;/td&gt;
      &lt;td&gt;&lt;a href=&quot;https://www.jstor.org/stable/44938411?seq=3&quot;&gt;Gallina de la tierra&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Spanish (New Mexico)&lt;/td&gt;
      &lt;td&gt;(From Nahuatl “turkey chick”)&lt;/td&gt;
      &lt;td&gt;&lt;a href=&quot;https://www.jstor.org/stable/44938411?seq=2&quot;&gt;Kókono&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Spanish (New Mexico)&lt;/td&gt;
      &lt;td&gt;Goose&lt;/td&gt;
      &lt;td&gt;&lt;a href=&quot;https://www.jstor.org/stable/44938411?seq=2&quot;&gt;Gánso&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Spanish (Spain)&lt;/td&gt;
      &lt;td&gt;Peacock (from Latin)&lt;/td&gt;
      &lt;td&gt;Pavo&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Swahili&lt;/td&gt;
      &lt;td&gt;Cannon duck&lt;/td&gt;
      &lt;td&gt;Bata mzinga&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Tamil&lt;/td&gt;
      &lt;td&gt;Sky chicken&lt;/td&gt;
      &lt;td&gt;Van koli&lt;/td&gt;
      &lt;td&gt;வான்கோழி&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Taíno&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;Guanaho&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Telugu&lt;/td&gt;
      &lt;td&gt;Foreign/border chicken&lt;/td&gt;
      &lt;td&gt;Seemakodi&lt;/td&gt;
      &lt;td&gt;సీమకోడి&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Turkish&lt;/td&gt;
      &lt;td&gt;(from the word for woodcock)&lt;/td&gt;
      &lt;td&gt;Culuk&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Vietnamese&lt;/td&gt;
      &lt;td&gt;Foreign (French) chicken&lt;/td&gt;
      &lt;td&gt;Gà tây&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h4 id=&quot;places-with-native-turkeys&quot;&gt;Places with native turkeys&lt;/h4&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Language&lt;/th&gt;
      &lt;th&gt;English translation&lt;/th&gt;
      &lt;th&gt;Word (latin script)&lt;/th&gt;
      &lt;th&gt;Word (original script)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Abenaki&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;Nahama&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Aymara&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;Pawu&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Blackfoot&lt;/td&gt;
      &lt;td&gt;Big bird&lt;/td&gt;
      &lt;td&gt;Ómahksipi’kssíí&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Catawba&lt;/td&gt;
      &lt;td&gt;Big chicken&lt;/td&gt;
      &lt;td&gt;&lt;a href=&quot;https://catawba-archive.maxarchiveservices.co.uk/index.php/image-01-24&quot;&gt;Watkątru&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Cherokee&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;Gvna&lt;/td&gt;
      &lt;td&gt;ᎬᎾ&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Chickasaw&lt;/td&gt;
      &lt;td&gt;(Onomatopoeia)&lt;/td&gt;
      &lt;td&gt;Chaloklowaꞌ&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Choctaw&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;&lt;a href=&quot;https://fichikshohmalali.wordpress.com/2016/10/02/how-turkey-lost-its-name-part-i/&quot;&gt;fakit&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Choctaw&lt;/td&gt;
      &lt;td&gt;Tall chicken&lt;/td&gt;
      &lt;td&gt;&lt;a href=&quot;https://dictionary.choctawnation.com/word?_sf_s=%22aka%CC%B1k%20chaha%22&quot;&gt;Aka̱k chaha&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Dakota&lt;/td&gt;
      &lt;td&gt;(Suffix “taŋka” means “big”)&lt;/td&gt;
      &lt;td&gt;&lt;a href=&quot;https://dictionary.swodli.com/&quot;&gt;Waglekṡuŋtaŋka&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Dakota&lt;/td&gt;
      &lt;td&gt;(Suffix “taŋka” means “big”)&lt;/td&gt;
      &lt;td&gt;&lt;a href=&quot;https://reader.library.cornell.edu/docviewer/digital?id=hunt0083#page/274/mode/1up&quot;&gt;żicataŋka&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Mayan (Classic)&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;Ak’ach&lt;/td&gt;
      &lt;td&gt;(See &lt;a href=&quot;https://mayadecipherment.com/2020/08/01/yesterdays-moon-a-decipherment-of-the-classic-mayan-adverb-akbiiy/&quot;&gt;here&lt;/a&gt; or &lt;a href=&quot;https://www.mesoweb.com/pari/publications/journal/1604/OcellatedTurkey.pdf&quot;&gt;here, figure 3&lt;/a&gt;)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Mayan (Q’eqchi)&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;&lt;a href=&quot;https://aztli.files.wordpress.com/2013/10/vocabulario20qeqchi.pdf&quot;&gt;Ak’ach&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Mayan (Kʼicheʼ)&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;&lt;a href=&quot;https://www.taterenner.com/engkiche.pdf&quot;&gt;no’s&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Mayan (Yucatec)&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;Tzo’&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Mayan (Yucatec)&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;Ulum&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Mayan (Yucatec)&lt;/td&gt;
      &lt;td&gt;(Ocellated turkey)&lt;/td&gt;
      &lt;td&gt;Kutz&lt;sup id=&quot;fnref:yuc&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:yuc&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;3&lt;/a&gt;&lt;/sup&gt;&lt;/td&gt;
      &lt;td&gt;(See &lt;a href=&quot;https://www.mayaarchaeologist.co.uk/school-resources/maya-world/maya-writing-system/&quot;&gt;here&lt;/a&gt; or &lt;a href=&quot;https://ancientmayalife.blogspot.com/2018/04/the-ocellated-turkey.html&quot;&gt;here&lt;/a&gt;)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Miami&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;Pileewa&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Mohawk&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;Skaweró:wane&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Mohegan-Pequot&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;Náham&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Munsee&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;Pŭléew&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Nahuatl&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;&lt;a href=&quot;https://www.jstor.org/stable/44938411?seq=3&quot;&gt;Huexolotl&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Nahuatl&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;&lt;a href=&quot;https://www.jstor.org/stable/44938411?seq=3&quot;&gt;Totollin&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Navajo&lt;/td&gt;
      &lt;td&gt;(from “to peck”)&lt;/td&gt;
      &lt;td&gt;Tązhii&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Ojibwe&lt;/td&gt;
      &lt;td&gt;Big bird&lt;/td&gt;
      &lt;td&gt;Gichi-bine&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Ojibwe&lt;/td&gt;
      &lt;td&gt;Big bird&lt;/td&gt;
      &lt;td&gt;Mizise&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Shawnee&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;Pelewa&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Shoshoni&lt;/td&gt;
      &lt;td&gt;(from “to pick with teeth”)&lt;/td&gt;
      &lt;td&gt;Guyungiyaa&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Unami&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;Chikënëm&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;sources&quot;&gt;Sources&lt;/h3&gt;

&lt;p&gt;History of turkey domestication and etymology:
&lt;a href=&quot;https://dialnet.unirioja.es/servlet/articulo?codigo=278695&quot;&gt;Crawford (1992)&lt;/a&gt;, 
&lt;a href=&quot;https://www.amazon.co.uk/Wild-Turkey-Its-History-Domestication/dp/080611097X&quot;&gt;Schorger (1966)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://en.wiktionary.org/wiki/turkey&quot;&gt;Wiktionary translations&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Names for Turkey in Spanish:
&lt;a href=&quot;https://www.jstor.org/stable/44938411&quot;&gt;Kiddle (1951)&lt;/a&gt; (South America), 
&lt;a href=&quot;https://www.jstor.org/stable/44942079&quot;&gt;du Bois (1979)&lt;/a&gt; (New Mexico)&lt;/p&gt;

&lt;p&gt;Sources for names were numerous and mostly included reputable online
dictionaries.  Where possible, I cross-checked this real usage based on internet
forum posts including:
&lt;a href=&quot;https://www.reddit.com/r/todayilearned/comments/eahkt/comment/c16mkl7/&quot;&gt;1&lt;/a&gt;
&lt;a href=&quot;https://www.reddit.com/r/etymology/comments/keo15s/yes_the_bird_turkey_is_named_for_the_country/&quot;&gt;2&lt;/a&gt;
&lt;a href=&quot;https://www.reddit.com/r/MapPorn/comments/5vx7jl/the_crazy_origins_of_the_word_turkey_the_bird_in/&quot;&gt;3&lt;/a&gt;
&lt;a href=&quot;https://www.reddit.com/r/todayilearned/comments/5g12hs/til_the_bird_americans_call_a_turkey_is_called_an/&quot;&gt;4&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I did not take much information from modern secondary source summaries because I
found them to be less accurate, but here are some of them anyway:
&lt;a href=&quot;https://www.globelanguage.org/turkey-noun&quot;&gt;1&lt;/a&gt;
&lt;a href=&quot;https://www.nationalgeographic.com/culture/article/fowl-play-the-twisted-linguistics-of-turkey&quot;&gt;2&lt;/a&gt;
&lt;a href=&quot;https://eatyourselfgreek.com/a-bird-from-elsewhere-turkey-stuffing/&quot;&gt;3&lt;/a&gt;
&lt;a href=&quot;https://www.npr.org/2008/11/27/97541602/why-a-turkey-is-called-a-turkey&quot;&gt;4&lt;/a&gt;
&lt;a href=&quot;https://vividmaps.com/he-word-turkey-bird-in-various-european/&quot;&gt;5&lt;/a&gt;
&lt;a href=&quot;https://web.archive.org/web/20230000000000*/https://en.wikipedia.org/wiki/List_of_names_for_turkey&quot;&gt;6&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bonus! Some cartoons:
&lt;a href=&quot;https://www.reddit.com/r/polandball/comments/3txxna/eating_turkey/&quot;&gt;Polandball&lt;/a&gt;, 
&lt;a href=&quot;https://www.itchyfeetcomic.com/2015/11/ameribird.html?m=1&quot;&gt;Itchy Feet&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you find any mistakes or possible additions, please let me know and I will
update the article!&lt;/em&gt;&lt;/p&gt;

&lt;h3 id=&quot;footnotes&quot;&gt;Footnotes&lt;/h3&gt;
&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:bre&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;In Breton, the bird’s name is widely cited to be &lt;em&gt;yar-Spagn&lt;/em&gt; (“Spanish
chicken”), but this word appears to be rare.  The much more common name is
&lt;em&gt;yar-Indez&lt;/em&gt; (“Indian chicken”). &lt;a href=&quot;#fnref:bre&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:kurd&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;Kurmanji Kurdish Wikipedia claims a few more country names, including
Misri (Egyptian, çûkê Misirê) and Shami (Demascus/Syria, çûkê Şamê), but I
cannot seem to verify these names. &lt;a href=&quot;#fnref:kurd&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:yuc&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;I have included the Yucatec Mayan word “kutz”, even though this word
refers specifically to the ocellated turkey, a different (but closely
related) species found only on the Yucatan peninsula. &lt;a href=&quot;#fnref:yuc&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;
</description>
        <pubDate>Sun, 17 Mar 2024 00:00:00 +0000</pubDate>
        <link>/2024/03/17/which-word-is-the-bird.html</link>
        <guid isPermaLink="true">/2024/03/17/which-word-is-the-bird.html</guid>
        
        <category>linguistics</category>
        
        
        <category>Other</category>
        
      </item>
    
      <item>
        <title>Beyond the overtone series: the overtone grid
</title>
        <description>&lt;p&gt;The overtone series, also known as the harmonic series, is one of the most
fundamental explanations for what makes music sound pleasant.  Whenever you hear
a note played on a musical instrument, the note isn’t just made of one
frequency.  The tone you perceive is the base frequency (the “fundamental”).
However, the note also consists of overtones, several higher pitched
frequencies, which give each musical instrument its distinct sound (its
“timbre”).  The overtones series is the reason why thick, tightly-voiced chords
sound muddy on low-pitched instruments; why the trombone needs to move its slide
to play different notes; and why the V7 chord desperately wants to resolve
to a I chord.&lt;/p&gt;

&lt;p&gt;This post describes how I turned the overtone series into a grid and composed a
piece of music based on it.  If you just want to hear the piece, you can
&lt;a href=&quot;/res/leaves/music_of_the_leaves.mp3&quot;&gt;download the score&lt;/a&gt; and listen
to a performance by &lt;a href=&quot;https://chiaranaldi.com/informazioni/&quot;&gt;pianist Chiara
Naldi&lt;/a&gt;.&lt;/p&gt;

&lt;figure&gt;
    &lt;center&gt;
        &lt;audio controls=&quot;&quot; src=&quot;/res/leaves/naldi_music_of_the_leaves.mp3&quot;&gt; 
        &lt;a href=&quot;/res/leaves/naldi_music_of_the_leaves.mp3&quot;&gt;Download audio&lt;/a&gt;
        &lt;/audio&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;Music of the leaves performed by Chiara Naldi&lt;/figcaption&gt;
    &lt;/center&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;reminder-the-overtone-series&quot;&gt;Reminder: the overtone series&lt;/h2&gt;

&lt;p&gt;To construct the overtone series, some fundamental frequency \(f_0\) is multiplied
by whole numbers.  So, the first frequency is \(1 \times f_0\), the second is \(2
\times f_0\), the third is \(3 \times f_0\), and so on:&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/leaves/leaves3.png&quot; width=&quot;70%&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Image of piano keys highlighting the overtone series&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;Another way to think about the overtone series is as the vibration of a string.
Suppose we find a string of length \(L_0\) that vibrates at our fundamental
frequency \(f_0\).  Then, we cut the string into equal parts, so that each of
the new short strings has the same length.  If we cut the string in half, each
string has length \(L_0/2\), and if we cut it in thirds, the lengths are
\(L_0/3\), and so on.  More generally, if we cut it into \(N\) equal parts, then
each part has a length of:&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/leaves/leaves5.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Image of cuts of a violin string highlighting the overtone series&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;It turns out that a string cut into two equal parts will vibrate at the
frequency \(2f_0\), three equal parts will vibrate at \(3f_0\), and \(N\) equal
parts will vibrate at \(N f_0\).  So, we have two equivalent ways to think about
the going up the overtone series: as an even multiple of a fundamental frequency,
or as a string being cut.  In both of these cases, we have some number (such as
2, 3, or \(N\) in the examples above) which represents the term of the overtone
series.  We call these the 2nd, 3rd, or \(N\)‘th harmonics.&lt;/p&gt;

&lt;h2 id=&quot;generalising-the-overtone-series&quot;&gt;Generalising the overtone series&lt;/h2&gt;

&lt;p&gt;In the example above, we divided the string into \(N\) different segments, but
we cut each segment to be the same size.  What if, instead, we took more than
one segment at a time?  Now, instead of cutting at every single location where
we marked, we look at all of the string lengths which could be made by
performing some, but not all, of those cuts.  Let’s see what notes could come
out of this type of a scheme.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/leaves/leaves6.png&quot; width=&quot;90%&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Image of different cuts of a violin string highlighting a generalised overtone series&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;So, the first two terms do not change: they are still \(L_0\) and \(L_0/2\),
corresponding to frequencies \(f_0\) and \(2f_0\).  However, the next term will
be a bit different.  In the standard overtone series, we would have \(L_0/3\),
corresponding to a frequency of \(3f_0\).  Here, we have two options: the same
\(L_0/3\) term with a frequency of \(3f_0\), and a new term, \(2L_0/3\),
corresponding to the frequency of \(1.5f_0\).  If we go up one more level to
\(N=4\), we get a new term as well.  We have the familiar \(L_0/4\) term with
frequency \(4f\) from the overtone series, and also \(2L_0/4=L_0/2\), a
frequency of \(2f\).  But we have another new term as well: \(3L_0/4\), with
frequency \(1.33f_0\).  These frequencies line up approximately with the keys of
a piano:&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/leaves/leaves7.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Image of piano keys highlighting a generalised overtone series&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;We notice that there are two relevant numbers now: the number of pieces we
divide the string into (\(N\)), and the number of those pieces we take, which we
will call \(M\).  According to this scheme, instead of cutting into \(1/N\)
segments, we cut into segments of length \(M/N\), where \(M&amp;lt;N\).  (This gives us
a fraction, a &lt;a href=&quot;https://en.wikipedia.org/wiki/Rational_number&quot;&gt;rational number&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Since we have two numbers instead of one, it is a bit awkward to write them in a
list.  Instead, we can organise these pitches on a grid.  Each column of the
grid is \(N\), the number of segments we divide the string into, and each row is
a value of \(M\), the number of consecutive segments we take before we cut.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;a href=&quot;/res/leaves/leaves8.png&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;/res/leaves/leaves8.png&quot; /&gt;&lt;/a&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Grid of piano keys showing the overtone grid&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;Because this generalisation can be arranged on a grid, we obtain not only one
series of pitches, but several.  We can read the grid up and down, side to side,
or diagonally to get lots of different series of notes.  This grid forms the
basis for Music of the Leaves.&lt;/p&gt;

&lt;h2 id=&quot;music-of-the-leaves&quot;&gt;Music of the Leaves&lt;/h2&gt;

&lt;p&gt;“Music of the Leaves” incorporate each row, column, and diagonal pattern from
this grid into a piece of music.  It does this by layering them in one note at a
time.  The piece starts with the first term of the series, the fundamental, and
gradually layers in the different notes.  When all of the notes have been added,
the patterns described above emerge.&lt;/p&gt;

&lt;p&gt;The piece is built exclusively on a repeated four-measure fragment:&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/leaves/leaves_segment.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Repeated four-measure passage in Music of the Leaves&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;The four-measure fragment is made from patterns coming from a traversal of the
grid in each direction. For instance, consider the four columns:&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/leaves/leaves11.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Traversing the overtone grid by columns&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;These are represented as patterns in this four-measure segment here:&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/leaves/rows_notes.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Notes corresponding to the columns of the overtone grid&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;We can do the same thing for the rows:&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/leaves/leaves12.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Traversing the overtone grid by rows&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;These are represented as patterns here:&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/leaves/columns_notes.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Notes corresponding to the rows of the overtone grid&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;And finally for the diagonals:&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/leaves/leaves13.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Traversing the overtone grid by diagonals&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;We see the patterns here:&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/leaves/diagonals_notes.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Notes corresponding to the diagonals of the overtone grid&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;We add in notes to the piece in an order determined by flattening the grid.  We
traverse the columns from left to right, ignoring duplicate notes, as follows:&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/leaves/leaves9.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Procedure for flattening the overtone grid&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;Notes are introduced in this order.  While there many repeated notes, there are
10 unique notes.  We can see the introduction of each new note by looking at the
score where the new note introductions are highlighted:&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/leaves/score_highlighted.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Highlighted positions indicate where a new note in the flattened overtone grid is introduced in the score.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;We also can hear each new note in the recording, see a new unique set of stripes
show up in the spectrogram of the recording when a new note is
introduced.&lt;/p&gt;

&lt;!---
import matplotlib.pyplot as plt
import numpy as np
import scipy.signal
import scipy.io.wavfile
plt.rc('font',**{'family':'sans-serif','sans-serif':['Helvetica Neue LT Std'],'size': 16})
f = scipy.io.wavfile.read(&quot;music_of_the_leaves_studio2.WAV&quot;)
freq,times,spec = scipy.signal.spectrogram(f[1][:,0], fs=f[0], nfft=5096)
plt.figure(figsize=(10, 3))
plt.pcolormesh(times[::8],freq[0:550],np.log(1+spec[0:550,::8]), cmap=&quot;hot&quot;, shading=&quot;gouraud&quot;);
plt.xlabel(&quot;Time (seconds)&quot;)
plt.ylabel(&quot;Frequency (hz)&quot;)
plt.tight_layout()
plt.savefig(&quot;leaves-spectrogram.png&quot;, transparent=True, dpi=300)
plt.show()
--&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;a href=&quot;/res/leaves/leaves-spectrogram.png&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;/res/leaves/leaves-spectrogram.png&quot; /&gt;&lt;/a&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Spectrogram of the recording of Music of the Leaves.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;So, the structure is made up of a flattened version of the overtone grid, and
the notes come from patterns obtained by traversing the grid in different
directions.&lt;/p&gt;

&lt;h2 id=&quot;appendix-patterns-on-the-grid&quot;&gt;Appendix: Patterns on the grid&lt;/h2&gt;

&lt;p&gt;There are several patterns to the overtone grid.  First, notice that the bottom
row is the overtone series.  This is because the bottom row is where \(M=1\), so
\(M/N\) is the same as \(1/N\).&lt;/p&gt;

&lt;p&gt;But interestingly, the second row from the bottom also appears to form an
overtone series, but missing the first note.  If we try to extrapolate it out,
we see that it would be exactly one octave lower.  Mathematically, this is
because if we replace \(L\) with \((2L)\) (i.e., the string length for the tone
one octave lower), then \((2L)/1\), \((2L)/2\), \((2L)/3\), and so on is just
the overtone series for a string of length \(2L\)!&lt;/p&gt;

&lt;p&gt;This same trend continues as we go to higher rows.  In the third row from the
bottom, we have the top of an overtone series which starts on the low F,
corresponding to a string of length \(3L\).  It becomes more difficult to notice
after the third row, but the trend still continues.  This row structure comes
directly from the mathematical definition of the overtone series.&lt;/p&gt;

&lt;p&gt;The columns are even more interesting, giving rise to a reverse of the overtone
series, the &lt;a href=&quot;https://en.wikipedia.org/wiki/Undertone_series&quot;&gt;“undertone
series”&lt;/a&gt;.  In the normal
overtone series, we start with the fundamental frequency, and then go up an
octave, and then a perfect 5th, then a perfect 4th, then a major 3rd, and so on.
In the columns, we do the opposite.  Our “pseudo-fundamental” frequency occurs
on a high note at the bottom of the column.  As we travel upwards in the grid,
we first go down an octave, and then down a perfect 5th, then down a perfect
4th, then a major 3rd, and so on.&lt;/p&gt;

&lt;p&gt;There is also an interesting pattern in the diagonals.  Along each diagonal, the
pitch gets closer and closer to the fundamental frequency at different speeds.
The main diagonal corresponds to the case where \(M=N\), and thus, \(M/N=1\), so
this will always be the value of the fundamental frequency.  But what about the
off-diagonals?  The first diagonal is defined as the combinations of \(M\) and
\(N\) such that \(M-N=1\).  So then, we have \(L\times 2/3\), \(L\times 3/4\),
\(L\times 4/5\), and so on.  As the value of \(N\) gets larger, we will get
closer and closer to the fundamental frequency.&lt;/p&gt;

&lt;h2 id=&quot;acknowledgement&quot;&gt;Acknowledgement&lt;/h2&gt;

&lt;p&gt;Music of the Leaves was based on a conversation 10+ years ago with my former
research advisor Clarence Lehman.  Thank you to Chiara Naldi for recording Music
of the Leaves and including it in her concert series.&lt;/p&gt;

&lt;h3&gt;Code/Data:&lt;/h3&gt;

&lt;ul&gt;

    &lt;li&gt;&lt;a href=&quot;/res/leaves/music_of_the_leaves_score.pdf&quot;&gt;Sheet music&lt;/a&gt;&lt;/li&gt;

    &lt;li&gt;&lt;a href=&quot;/res/leaves/naldi_music_of_the_leaves.mp3&quot;&gt;Recording&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;

</description>
        <pubDate>Sun, 19 Nov 2023 00:00:00 +0000</pubDate>
        <link>/2023/11/19/overtone-grid-music-of-the-leaves.html</link>
        <guid isPermaLink="true">/2023/11/19/overtone-grid-music-of-the-leaves.html</guid>
        
        <category>music</category>
        
        <category>math</category>
        
        
        <category>Music</category>
        
      </item>
    
      <item>
        <title>Does “Flight of the Bumblebee” resemble bumblebee flight?
</title>
        <description>&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=X14kC-sEH0I&quot;&gt;Flight of the Bumblebee&lt;/a&gt; is one of
the rare pieces of classical music which, through its association with bees, has
cemented its place in pop culture. However, it is unclear whether its composer,
Nikolai Rimsky-Korsakov, actually took inspiration from bumblebee flight
patterns. I address this question using new tools from ethology, mathematics,
and music theory.  Surprisingly, the melody line of ``Flight of the Bumblebee’’
mimics a distinctive property of bumblebee flight, a property which was not
formally discovered until decades after Rimsky-Korsakov’s death.  Therefore,
&lt;em&gt;yes, it is very likely&lt;/em&gt;&lt;sup id=&quot;fnref:a&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:a&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt; that Rimsky-Korsakov observed and incorporated
actual bumblebee flight patterns into his music.&lt;/p&gt;

&lt;p&gt;In what follows, I assume the reader has a knowledge of high school level
mathematics and basic music theory (chord changes, intervals, scales, etc.).
&lt;a href=&quot;https://osf.io/preprints/socarxiv/4v6nu/&quot;&gt;This post is based on my recent preprint, available on
SocArXiv.&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;historical-background&quot;&gt;Historical background&lt;/h2&gt;

&lt;p&gt;The piece we now call “Flight of the Bumblebee” actually comes from one
of Rimsky-Korsakov’s operas, “The Tale of Tsar Saltan”.  The opera is based on a
story by Alexander Pushkin, which is in turn based on several folk tales.  The
hero, Prince Gvidon, is cast on a remote island by his jealous aunts.  While
there, he unknowingly saves a Swan Princess from death, so in return, she looks
after his well-being.  To help him to see his father again, she temporarily
transforms him into a bee&lt;sup id=&quot;fnref:b&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:b&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;2&lt;/a&gt;&lt;/sup&gt; so he may fly back to the kingdom (and sting his
aunts).  Eventually, when he is a human again, Prince Gvidon is reunited with
his father and marries the swan princess.&lt;/p&gt;

&lt;p&gt;Flight of the Bumblebee begins towards &lt;a href=&quot;https://youtu.be/iKWGvke7bq8?t=3192&quot;&gt;the end of the first scene of Act
III&lt;/a&gt; after Prince Gvidon is transformed
into a bee.  The first half of the piece serves as background music for the Swan
Princess’ singing as Prince Gvidon flies away.  The second half serves as a
transition from the first to second scene of Act III.  In most renditions of
this piece today, the Swan Princess’ vocal line is removed.  The piece
introduces the “bumblebee” theme, which continues to be a central theme of Act
III as Prince Gvidon flies around the court causing mischief.&lt;/p&gt;

&lt;p&gt;Despite the fact that Flight of the Bumblebee is by far the most recognisable
piece of music Rimsky-Korsakov wrote in his lifetime, he didn’t consider it to
be one of his major works.  In fact, Rimsky-Korsakov didn’t even include it in
his own &lt;a href=&quot;https://imslp.org/wiki/The_Tale_of_Tsar_Saltan_(suite),_Op.57_(Rimsky-Korsakov,_Nikolay)&quot;&gt;suite of highlights from the
opera&lt;/a&gt;&lt;sup id=&quot;fnref:c&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:c&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;3&lt;/a&gt;&lt;/sup&gt;.
This piece was relatively unknown until 1936, when it first&lt;sup id=&quot;fnref:d&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:d&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;4&lt;/a&gt;&lt;/sup&gt; entered pop
culture as the theme song for the radio show “The Green Hornet”.  It only took a
few years to become widely recognisable, in large part due to a &lt;a href=&quot;https://www.youtube.com/watch?v=jxS7llr8x_4&quot;&gt;1941 big band
jazz cover by Harry James&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;bumblebee-flight&quot;&gt;Bumblebee flight&lt;/h2&gt;

&lt;p&gt;In accordance with the cliché “busy as a bee”, bumblebees spend most of their
day looking for food.  So, we can understand bumblebee flight patterns by
understanding how they forage for food.  New miniature radar technology allows
us to &lt;a href=&quot;https://www.youtube.com/watch?v=P575vyxOc2Q&quot;&gt;track the flight of foraging
bumblebees&lt;/a&gt;.  One important
characteristic aspect we have discovered about &lt;a href=&quot;https://doi.org/10.1016/0003-3472(95)80047-6&quot;&gt;insect foraging flight
patterns&lt;/a&gt;, and &lt;a href=&quot;https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0078681&quot;&gt;bumblebee flight
in
particular&lt;/a&gt;,
is the &lt;a href=&quot;https://journals.biologists.com/jeb/article/210/21/3763/17205/Honeybees-perform-optimal-scale-free-searching&quot;&gt;presence of lots of short movements and a few very large
movements&lt;/a&gt;.
At any given point in time, a bee may choose to move in any direction it wants.
Most of the time, it will move a small distance.  However, sometimes, it will
make very large movements. For example, it may &lt;a href=&quot;https://besjournals.onlinelibrary.wiley.com/doi/full/10.1046/j.1365-2664.1999.00428.x&quot;&gt;travel long distances and then
carefully explore a small
patch&lt;/a&gt;.
Relatively speaking, bees will make fewer moderate-sized movements: most
movements will be very small, but those which aren’t small will be very large.
&lt;a href=&quot;https://www.nature.com/articles/44831&quot;&gt;This has been shown to be optimal
behaviour&lt;/a&gt; for bumblebees in many
situations.  In fact, algorithms inspired by this bumblebee behaviour have been
used to tackle &lt;a href=&quot;https://www.tandfonline.com/doi/abs/10.1080/00207721.2015.1010748&quot;&gt;complex engineering
challenges&lt;/a&gt;.
This type of movement is in contrast to, e.g., the movement of spores released
from trees, which tend to drift gently with the wind and not make large, sudden
movements across a pasture.  We will refer to these large movements as “jumps”.&lt;/p&gt;

&lt;p&gt;If you think about it, it makes sense why bees might prefer to sometimes make
very large movements when they are searching for food.  If they always take
small steps, they may never get to the large food source that is on the other
side of the meadow.  Indeed, this strategy is used by a &lt;a href=&quot;https://www.cambridge.org/core/books/physics-of-foraging/B009DE42189D3A39718C2E37EBE256B0&quot;&gt;wide range of
animals&lt;/a&gt;
beyond bumblebees&lt;sup id=&quot;fnref:e&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:e&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;5&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;

&lt;h2 id=&quot;mathematical-analysis-of-bumblebee-flight&quot;&gt;Mathematical analysis of bumblebee flight&lt;/h2&gt;

&lt;p&gt;To represent these flight patterns, we need to build an extremely simple model
which is easy to work with and can be applied to a melody line.  First, we need
a way to relate the notes in a melody line to the location of a bee.  One
natural way is to assume that the ups and downs of the melody line correspond to
movements of the bee.  We can do this by assigning a numerical value to each
note in the melody line, where 0 is the lowest note on the piano keyboard and
each half step interval is 1 higher than the previous.  Then, tracking the note
in the melody line is the same as tracking the location of the bee.  With this
representation, a small movement for a bee is equivalent to a small interval in
the melody line.  Likewise, a “jump” for the bee is analogous to a “jump” in the
melody line, or a large interval.&lt;/p&gt;

&lt;p&gt;Now we can think about how a simple bumblebee flight model might operate.  The
“small steps and large jumps” behaviour we described in the previous section
depends only on the sizes of the steps the bee takes at subsequent points in
time, not on the direction.  So without making assumptions about the direction
of each step, we can specify the probability of having steps of different sizes.
Then, we can assume that the bee goes in a random direction at each step.  This
model, known as a random walk, is used to model a &lt;a href=&quot;https://en.wikipedia.org/wiki/Random_walk#Applications&quot;&gt;huge number of
phenomena&lt;/a&gt; in the
natural world.&lt;/p&gt;

&lt;p&gt;We will compare two models for choosing our step sizes in the random walk&lt;sup id=&quot;fnref:f&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:f&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;6&lt;/a&gt;&lt;/sup&gt;.
The first, the “geometric” model, is a good representation for most types of
data.  It posits that steps become proportionally less frequent as they get
larger.  So, if 50% of steps are of size 1, 25% will be of size 2, 12.5% will be
of size 3, and so on.  This means that large step sizes are extremely
infrequent: if we continue the pattern forward, a step size of one octave (12)
will only occur once every 4000 steps, and a step of two octaves (24) will occur
once every 16 million steps!&lt;/p&gt;

&lt;p&gt;By contrast, we can also use a “powerlaw” model for step sizes.  Here, the
probability of having a step of a given size is proportional to a power of the
size of the step.  This is harder to do in our head, so I worked out these
numbers for us: if 50% of steps are of size 1, then only 15% of steps are of
size 2, and 7% are of size 3.  But, if we go out to larger steps, a one-octave
jump will occur once every 146 steps, and a two octave jump will occur once
every 485 steps!  So, compared to the geometric model, the powerlaw model allows
large jumps to happen much more frequently, with relatively fewer medium-sized
jumps.  Both of these models have only one parameter, describing the scale on
which they operate.&lt;/p&gt;

&lt;p&gt;Here is a simulation of what a bumblebee’s flight path might be under each
model.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/bumblebee/random-processes-2d.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Example 2-dimensional flight trajectories from a geometric or powerlaw random walk model.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;As you can see, the powerlaw model involves several large jumps, whereas the
geometric model doesn’t.  You can compare this to some &lt;a href=&quot;https://doi.org/10.1371/journal.pone.0078681.s003&quot;&gt;example bumblebee
flight trajectories measured by Juliet Osborne and
colleagues&lt;/a&gt;, which show
patterns which more closely resemble the powerlaw model than the geometric
model.&lt;/p&gt;

&lt;p&gt;While bumblebees fly in three dimensions, our melody line is only measured in
one dimension.  So, we need to convert these models into one dimension in order
to compare them to Flight of the Bumblebee.  First, let’s simulate these models
and compare them to the actual melody line.  These simulations try to match the
qualitative character of the jumps of the melody line, rather than the exact
“flight path” of the melody line.  Here are example flight paths from the
one-dimensional versions of these models, as well as the one derived from the
melody of Flight of the Bumblebee:&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/bumblebee/random-processes-1d.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Example
1-dimensional “flight” trajectories from a geometric or powerlaw random walk
model, compared to the melody line from Flight of the Bumblebee.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;The melody line appears to have a more similar “jumpiness” to the powerlaw model
than the geometric model.  We can formalise this by fitting the models directly
to the jump sizes in melody line (through maximum likelihood, see the appendix
on methods for details), and then evaluating the fit to see which model is more
likely given the data.  When we do so, we find that the powerlaw model is \(1.5
\times 10^{72}\) times more likely than the geometric model!&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/bumblebee/model-comparison.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Comparison of geometric and powerlaw model.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;This gives us very, very strong evidence that the Flight of the Bumblebee
follows a pattern involving small steps and large jumps, over a pattern with a
more balanced distribution of small and medium sized jumps.&lt;/p&gt;

&lt;h3 id=&quot;control-analysis&quot;&gt;Control analysis&lt;/h3&gt;

&lt;p&gt;Flight of the Bumblebee is based on the chromatic scale, and the chromatic scale
contains lots of small intervals.  Is it possible that this correspondence to
the powerlaw model is just due to the extensive use of the chromatic scale?  To
test this, we can perform the same analysis on the other&lt;sup id=&quot;fnref:g&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:g&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;7&lt;/a&gt;&lt;/sup&gt; highly-chromatic
piece of classical music widely known in pop culture: Entry of the Gladiators by
Fučík (i.e., &lt;a href=&quot;https://www.youtube.com/watch?v=9ZM-HZDZTc0&quot;&gt;the circus song&lt;/a&gt;).
Entry of the Gladiators also contains lots of chromatic passages and several
large jumps.  However, in stark contrast to Flight of the Bumblebee, given the
melody line in Entry of the Gladiators, the geometric model was 1.8 times more
likely than the powerlaw model.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/bumblebee/model-comparison-gladiators.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Comparison of geometric and powerlaw model on Entry of the Gladiators.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;This means that not all music based on the chromatic scale follows powerlaw step
sizes.&lt;/p&gt;

&lt;p&gt;At first, it may come as a surprise that Entry of the Gladiators isn’t better
fit by powerlaw model.  Like Flight of the Bumblebee, it also has lots of small
intervals and lots of large jumps.  In fact, it has far more large jumps than
Flight of the Bumblebee.  The reason it is not better fit is because Entry of
the Gladiators also contains several intermediate-sized jumps.  These
intermediate-sized jumps aren’t predicted by the powerlaw model or by models of
bumblebee flight.  Flight of the Bumblebee contains almost exclusively chromatic
steps and large jumps, which makes the powerlaw model a better fit.  This means
that Flight of the Bumblebee bears more of a mathematical resemblance to the
behavioural patterns of bumblebee flight than this other highly-chromatic piece.&lt;/p&gt;

&lt;h2 id=&quot;what-did-rimsky-korsakov-intend-to-write&quot;&gt;What did Rimsky-Korsakov intend to write?&lt;/h2&gt;

&lt;p&gt;These analyses raise an important question: is there a music theory explanation
for including large jumps beyond the imagery of bumblebee flight?  Likewise,
which aspects of the piece are intended to invoke the imagery and which are
incorporated for other musical or artistic purposes?&lt;/p&gt;

&lt;p&gt;We know that Rimsky-Korsakov didn’t explicitly implement these mathematical
models in his music.  Not only was there scarce knowledge about insect behaviour
when the Tale of Tsar Saltan premiered in November 1900, but the mathematics on
which the models are based hadn’t even been invented yet!  In order to make a
judgement about step sizes in the melody line, we first must understand what
musical and artistic aspects influenced the melody line.  Let’s explore two
here: the hero’s main theme, and the use of the whole-tone scale.&lt;/p&gt;

&lt;h3 id=&quot;heros-main-theme&quot;&gt;Hero’s main theme&lt;/h3&gt;

&lt;p&gt;One important component of the melody line is the hero Prince Gvidon’s theme&lt;sup id=&quot;fnref:h&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:h&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;8&lt;/a&gt;&lt;/sup&gt;
(&lt;a href=&quot;https://en.wikipedia.org/wiki/Leitmotif&quot;&gt;leitmotif&lt;/a&gt;) within the opera.  This
theme comes from the folksong “Заинька Попляши” (“Zainka Poplyashi”, which
roughly translates to “Dance, bunny, dance!”), a song with which Rimsky-Korsakov was
&lt;a href=&quot;https://imslp.org/wiki/Collection_of_100_Russian_Folksongs%2C_Op.24_(Rimsky-Korsakov%2C_Nikolay)&quot;&gt;intimately
familiar&lt;/a&gt;.
The theme is:&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/bumblebee/gvidon.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Leitmotif of Prince Gvidon’s.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;As you can see below, the character’s theme is clearly represented in main
bumblebee melody line, as indicated by red note heads:&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/bumblebee/leitmotif_melody.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Melody line of Flight of the Bumblebee with highlighted leitmotif.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;What this means is that one of the most common jumps, the jump of a perfect 4th
in the main theme, can be “explained” by this theme.  Since the frequency and
size of jumps is critical in our mathematical analysis, we can repeat the
analysis while ignoring these specific jumps in the melody line.  As we see, doing so
doesn’t ruin the mathematical effect described in the previous section: the
powerlaw model is \(1.8 \times 10^{65}\) times more likely, given the melody
line.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/bumblebee/model-comparison-nofourth.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Comparison of geometric and powerlaw model.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;So, the use of perfect 4th jumps to capture Gvidon’s leitmotif isn’t a major
factor in what makes this melody resemble bumblebee flight.&lt;/p&gt;

&lt;h3 id=&quot;whole-tone-scale&quot;&gt;Whole-tone scale&lt;/h3&gt;

&lt;p&gt;The piece also has a close connection with the whole-tone scale.  While the
whole-tone scale is most closely associated today with the French impressionists
like Debussy and Ravel, it was actually used much earlier by Rimsky-Korsakov’s
contemporaries as a building block of Russian nationalistic music.  In this
school of music, the whole-tone scale is used to represent the magical, the
regal, the ominous, and the surreal.&lt;/p&gt;

&lt;p&gt;Given the magical nature of a human transforming into a bumblebee, it may come
as no surprise that the whole-tone scale plays a prominent role in Flight of the
Bumblebee.  Recall that there are only two whole-tone scales, which contain no
notes in common.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/bumblebee/whole_tone.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;The two whole-tone scales.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;Since the scales contain no notes in common, we can classify any given note as
belonging to one of the two whole-tone scales.&lt;/p&gt;

&lt;p&gt;In Flight of the Bumblebee, almost all of the pitches on the eighth note beats
fall into the C♮ whole-tone scale, and all of the notes on the off-beats fall
into the D♭ whole-tone scale.  This trend is only violated five times.  In three
cases, the piece modulates from A minor to D minor (the subdominant), when the
whole-tone scales switch.  One violation is to make the melody line align
properly at the repeat&lt;sup id=&quot;fnref:i&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:i&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;9&lt;/a&gt;&lt;/sup&gt;, and the final violation is to make sure the final
note of the piece falls on A, the tonic.&lt;/p&gt;

&lt;p&gt;We can visualise this by plotting each on-beat in the melody line of the piece.
The x axis indicates the time at which each note is played, and the y axis
indicates which whole-tone scale the note comes from.  If we show the entire
piece in one plot, the on-beats look like this:&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/bumblebee/whole-tone-melody.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;The whole-tone scale associated with each on-beat in Flight of the Bumblebee.  Individual points appear as lines because they are very close together in time.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;And the off-beats look like this:&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/bumblebee/whole-tone-melody-off.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;The whole-tone scale associated with each off-beat in Flight of the Bumblebee.  Individual points appear as lines because they are very close together in time.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;There aren’t very many switches between whole-tone scales, and those that do
occur have a clear musical purpose.  This appears to be a deliberate use of the
whole-tone scale in the piece.&lt;/p&gt;

&lt;p&gt;An objection one might make to this is that the whole-tone scale is by necessity
connected with the chromatic scale.  Since Flight of the Bumblebee uses the
chromatic scale, this property of the whole-tone scale might arise naturally.&lt;/p&gt;

&lt;p&gt;To show this objection doesn’t apply, we can perform the same analysis on Entry
of the Gladiators.  Here, unlike in Flight of the Bumblebee, we see no
deliberate use of whole-tone scale for the on-beats:&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/bumblebee/whole-tone-melody-gladiators.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;The whole-tone scale associated with each on-beat in Entry of the Gladiators.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;Or for off-beats:&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/bumblebee/whole-tone-melody-gladiators-offbeats.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;The whole-tone scale associated with each off-beat in Entry of the Gladiators.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;This means that the whole-tone scale seems to have been deliberately used by
Rimsky-Korsakov, but not by Fučík, in constructing the melody line.&lt;/p&gt;

&lt;p&gt;Interestingly, this pattern makes it more “difficult” to write a melody line
which includes large jumps.  This is because large jumps can only be included if
they sound nice.  It is musically “easy” to maintain the whole-tone scale
pattern while making medium-sized jumps, because most medium-sized jumps sound
pleasant in many different contexts.  All intervals from minor 2nds to major
6ths are extremely common across a wide range of musical genres.  By contrast,
it is more difficult to make large jumps sound nice.  In most pieces, large
jumps often occur at octave, 9th, 10th, or flat 7th intervals, all of which
would violate the alternating whole-tone scale pattern.  This means that the use
of the whole-tone scale in the melody line actually makes it &lt;em&gt;more difficult&lt;/em&gt; to
have large jumps.  So, because of the whole-tone scale pattern, the presence of
large jumps in Flight of the Bumblebee is even more surprising than the
mathematical analysis suggests.&lt;/p&gt;

&lt;p&gt;Rimsky-Korsakov also left out some medium-sized jumps which fit the whole-tone
scale pattern.  Another “valid” jump under the whole-tone pattern, and one which
is extremely common in other pieces, is the perfect 5th.  However, the perfect
5th, a medium-sized jump, only occurs once in the melody line of Flight of the
Bumblebee.  Two similarly “easy-to-use” intervals which satisfy the whole-tone
pattern, the minor 3rd and the major 6th, don’t occur at all.  The only
medium-sized interval that Rimsky-Korsakov uses is the perfect 4th, which we
already showed was a result of Prince Gvidon’s theme.  So, the use of large
jumps and not medium sized jumps appears to be a deliberate choice by the
composer.&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Flight of the Bumblebee is a much more musically complex piece than it initially
seems.  Rimsky-Korsakov appears to have deliberately mimicked an important
property of bumblebee flight within his music.  Mathematical models to describe
bumblebee flight, invented long after Rimsky-Korsakov’s time, end up providing
an excellent fit to his melody line.  On top of this, he incorporated
interesting features from a music theory perspective, including the main
character’s theme and a whole-tone scale pattern.  These musical features don’t
explain the melody line’s resemblance to bumblebee flight.  While we will never
know if Rimsky-Korsakov actually observed bumblebee flight while composing
Flight of the Bumblebee, it sure is fun to speculate&lt;sup id=&quot;fnref:j&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:j&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;10&lt;/a&gt;&lt;/sup&gt;, isn’t it?&lt;/p&gt;

&lt;h3 id=&quot;appendix-methods&quot;&gt;Appendix: Methods&lt;/h3&gt;

&lt;p&gt;To find the melodic pattern, I downloaded &lt;a href=&quot;https://musescore.com/nicolas/scores/437&quot;&gt;Nicolas Froment’s engraving of the
Rachmaninoff piano arrangement&lt;/a&gt; and
cut out everything except the melody line.  Then, I cross-referenced this to the
&lt;a href=&quot;https://imslp.org/wiki/File:PMLP3170-Rimsky_Saltan_Score.pdf&quot;&gt;score from the original
opera&lt;/a&gt;, page
262-267, to tweak the melody line to ensure it is faithful to that of the opera
rather than the piano arrangement, correcting for octaves, breaks, repeats, etc.
I exported this as MIDI (attached below) and analysed it using a Python script
(attached below).  Likewise, I used &lt;a href=&quot;https://musescore.com/james_brigham/scores/1243801&quot;&gt;James Birgham’s engraving of the piano
reduction of Entry of the
Gladiators&lt;/a&gt; and exported to
MIDI (attached).&lt;/p&gt;

&lt;p&gt;I only used sections of Flight of the Bumblebee which were part of the rapid,
recognisable melody, concatenating across breaks.  Likewise, I excluded the trio
section of Entry of the Gladiators since it isn’t based on chromatics.  Repeated
notes were excluded since a jump of zero in a discrete random walk doesn’t
correspond to any kind of step in a continuous Wiener or Levy process.  I
adjusted the octave down in two cases (penalising the powerlaw model): once for
a two-octave jump in the final run of Flight of the Bumblebee, since it was an
artistic flourish for the finale; and once for a two-octave jump when the melody
line switches from treble to bass in Entry of the Gladiators.&lt;/p&gt;

&lt;p&gt;Model fitting was performed by finding the pairwise distances between
neighbouring points in each timeseries, and then fitting the counts of each to a
geometric or Zipf distribution through maximum likelihood.  A numerical
minimisation routine was used to find parameters which maximised the likelihood
function.&lt;/p&gt;

&lt;p&gt;The music theory analysis was partially my own (whole-tone scale analysis) and
partially based on work from &lt;a href=&quot;https://www.gutenberg.org/files/46587/46587-h/46587-h.htm&quot;&gt;Rosa
Newmarch&lt;/a&gt;, &lt;a href=&quot;https://blog.mymusictheory.com/2009/flight-of-the-bumble-bee/&quot;&gt;Victoria
Williams&lt;/a&gt; and
&lt;a href=&quot;https://helda.helsinki.fi/handle/10138/41117&quot;&gt;John Nelson&lt;/a&gt; (historical and
motivic analysis).  Thank you to Sophie Westacott for helpful comments, and to
the giant bumblebee who regularly hovers outside my window and then darts away
for inspiration.&lt;/p&gt;

&lt;h3&gt;Code/Data:&lt;/h3&gt;

&lt;ul&gt;

    &lt;li&gt;&lt;a href=&quot;/res/bumblebee/fit_models.py&quot;&gt;Analysis script&lt;/a&gt;&lt;/li&gt;

    &lt;li&gt;&lt;a href=&quot;/res/bumblebee/make_plots.py&quot;&gt;Script to generate plots&lt;/a&gt;&lt;/li&gt;

    &lt;li&gt;&lt;a href=&quot;/res/bumblebee/flight_melody.mid&quot;&gt;Flight of the Bumblebee MIDI melody&lt;/a&gt;&lt;/li&gt;

    &lt;li&gt;&lt;a href=&quot;/res/bumblebee/gladiators_melody.mid&quot;&gt;Entry of the Gladiators MIDI melody&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;h3 id=&quot;footnotes&quot;&gt;Footnotes&lt;/h3&gt;

&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:a&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;contrary to Betteridge’s law &lt;a href=&quot;#fnref:a&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:b&quot; role=&quot;doc-endnote&quot;&gt;

      &lt;p&gt;In the Pushkin story, he was also transformed into a mosquito and a fly to
see his father and sting his aunts, for a total of three trips back. &lt;a href=&quot;#fnref:b&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:c&quot; role=&quot;doc-endnote&quot;&gt;

      &lt;p&gt;Due to the piece’s broad recognisability today, many orchestras insert
Flight of the Bumblebee into the suite anyway. &lt;a href=&quot;#fnref:c&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:d&quot; role=&quot;doc-endnote&quot;&gt;

      &lt;p&gt;Contrary to claims from some sources, it didn’t appear in Charlie Chaplin’s
1925 film “Gold Rush” - instead, it appeared in the 1942 version, which used
different music. &lt;a href=&quot;#fnref:d&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:e&quot; role=&quot;doc-endnote&quot;&gt;

      &lt;p&gt;Similarly, when humans seek food, it is occasionally wise to take a large
step and go to the supermarket instead of always looking inside the
refrigerator. &lt;a href=&quot;#fnref:e&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:f&quot; role=&quot;doc-endnote&quot;&gt;

      &lt;p&gt;As a technical note: ideally, we would want to consider the difference
between a Wiener process (Brownian motion) and a Levy process, which is
similar to Brownian motion except the steps are powerlaw-distributed.  Since
our melody line is discrete in pitch (i.e. there are only 12 notes per
octave), we must use a model with discrete steps in order to get a
likelihood which makes sense.  So, we use the geometric distribution and the
discrete powerlaw distribution (zeta or Zipf distribution).  We use the
geometric distribution as a stand-in for the normal distribution, since
there is no well-known discrete half-normal–like distribution with support
on all the natural numbers. &lt;a href=&quot;#fnref:f&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:g&quot; role=&quot;doc-endnote&quot;&gt;

      &lt;p&gt;The use of “the” was deliberate.  I don’t think there are any other pieces
of classical music which are widely known in pop culture and rely so heavily
on chromatics.  The internet doesn’t seem to think so either, but please
correct me if I am wrong!  (Habanera from Carmen doesn’t count, since it
only embeds a descending chromatic scale within a surrounding
not-so-chromatic melody.) &lt;a href=&quot;#fnref:g&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:h&quot; role=&quot;doc-endnote&quot;&gt;

      &lt;p&gt;Prince Gvidon has two main leitmotifs in the opera, but only the one shown
here participates in the melody line.  The other one also appears in Flight
of the Bumblebee but not within the melody line: it is the descending and
ascending staccato line which appears several times in the accompaniment. &lt;a href=&quot;#fnref:h&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:i&quot; role=&quot;doc-endnote&quot;&gt;

      &lt;p&gt;The repeat is only found in the original opera score, not in the popular
piano reduction. &lt;a href=&quot;#fnref:i&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:j&quot; role=&quot;doc-endnote&quot;&gt;

      &lt;p&gt;Speaking of speculation, here is a pretty big leap: Rimsky-Korsakov is known
to have had synesthesia, associating colours with different keys.  While
there is no documented evidence of Rimsky-Korsakov’s associations with the
minor keys, there are descriptions of his associations with the major keys.
While I was unable to find the primary source describing Rimsky-Korsakov’s
colour-key synesthesia, I do believe there to be a primary source in
Russian, because several of the secondary sources use different translations
of the colour names.&lt;/p&gt;

      &lt;p&gt;The parallel and relative major keys actually line up well with bumblebees.
Flight of the Bumblebee is written in A minor, and modulates to D and G minor.
In Rimsky-Korsakov’s classification, the parallel major keys, A, D, and G major,
correspond to rose, yellow and gold, respectively.  These colours evoke the
imagery of a yellow-gold bumblebee flying to bright flowers.  Additionally, the
relative major keys of these minor keys—C major, F major, and Bb
major—correspond to green and white, with no documented correspondance for Bb
major.  These associations, while interesting, are probably a coincidence,
especially without evidence about his colour associations with the minor keys. &lt;a href=&quot;#fnref:j&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;
</description>
        <pubDate>Sat, 04 Jun 2022 00:00:00 +0000</pubDate>
        <link>/2022/06/04/flight-of-the-bumblebee.html</link>
        <guid isPermaLink="true">/2022/06/04/flight-of-the-bumblebee.html</guid>
        
        <category>math</category>
        
        <category>opera</category>
        
        <category>stochastic-processes</category>
        
        <category>modeling</category>
        
        <category>stats</category>
        
        
        <category>Music</category>
        
      </item>
    
      <item>
        <title>Are buffets efficient?
</title>
        <description>&lt;p&gt;I recently attended an academic conference and was struck by the
inefficiency of the buffet-style dinner.  The conference had
approximately 500 attendees, and dinner was scheduled for 6:30 PM
following a 15 minute break in the conference program.  A 15 minute
break is not enough time to go back to the hotel room and take a nap,
and barely enough time to find a quiet corner and get some work done,
but it is a perfect amount of time to crowd around the buffet waiting
for dinner to open.&lt;/p&gt;

&lt;p&gt;When dinner finally opened, all of the food was arranged on a single
table, inviting the attendees to form a single line to serve
themselves.  As you can imagine, this line was quite long.  I was
lucky enough to be one of the first people through the line, but by
the time I finished eating a half hour later, the line was still very
long.  I had been waiting for someone who was towards the middle to
end of the line, and this person still had not made it through yet.&lt;/p&gt;

&lt;p&gt;I found it odd that feeding people should be so slow. From my
experiences in undergraduate dining halls, it is possible to feed more
people in a shorter amount of time.  A key difference between these
situations is that in undergraduate dining halls, food is often served
at individual stations, meaning you only need to wait in line for food
you want to eat.  By contrast, in the catering style, it is often
served all at one table, with diners waiting in a single line and
accessing the dishes one by one. I wanted to examine the efficiency of
these two systems.  This is important not only for minimizing the mean
wait time so that everyone gets their food faster, but also for
minimizing inequality between people at the front and end of the line.
This ensures that everyone has the opportunity to dine together.&lt;/p&gt;

&lt;h2 id=&quot;model&quot;&gt;Model&lt;/h2&gt;

&lt;p&gt;I modeled this situation as a single line in a buffet versus
individual lines for each different dish.  I made the following
assumptions:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Some people may be faster or slower at serving themselves.&lt;/li&gt;
  &lt;li&gt;Some foods can be served faster than other foods.&lt;/li&gt;
  &lt;li&gt;People may not want all of the food which is being served, and each
person wants a different random selection of foods.&lt;/li&gt;
  &lt;li&gt;Only one person can serve themself a particular dish at one time.&lt;/li&gt;
  &lt;li&gt;When dishes have their own individual lines, people look at the
lines for the foods they want to eat and stand in the shortest line
next.&lt;/li&gt;
  &lt;li&gt;People already know what the options are and where they are located.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I calculated the wait time for each person in the simulation as the
total amount of time it took a person to pass through the buffet.  I
then looked at the mean wait time for the group as well as the
inequality in wait time for people in the group, defined as the third
quartile minus the first quartile.  Each simulation was run many times
to ensure accurate statistics.&lt;/p&gt;

&lt;h2 id=&quot;number-of-dishes-wanted&quot;&gt;Number of dishes wanted&lt;/h2&gt;

&lt;p&gt;Let us suppose that not everyone wants the same number of dishes, but
that all dishes are equally attractive.  First we look at the case
when there are a limited number of dishes.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/buffet/wait-ineq-few-dishes.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;100 people serving themselves in a buffet with 6 dishes&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;We see that when there aren’t very many dishes and most people want
all of them, it is faster to have a single line.  This may be
counter-intuitive, but it is due to the fact that people do not
optimally distribute themselves, but instead choose the shortest line.
Suppose for example that one dish is much slower to serve than all of
the others.  People who choose this food last will have to wait
approximately the same amount of time as they would have if there was
a single line and they ended up at the end, because this dish serves
as the bottleneck.  However, the people who are at the front of this
line will still need to wait in more lines for the other dishes,
because other people tried to serve themselves these dishes first.  As
a result, having multiple lines can sometimes increase the amount of
time for the fastest people and not decrease the amount of time for
the slowest people.&lt;/p&gt;

&lt;p&gt;Additionally, there is a large inequality in wait times, i.e. some
people will get through the line quickly, while others will be stuck
in line for a long time.  This is the case for both serving styles,
but is especially pronounced for the case with multiple lines.&lt;/p&gt;

&lt;p&gt;Let us also examine the case when there are many dishes to choose
from.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/buffet/wait-ineq-many-dishes.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;100 people serving themselves in a buffet with 20 dishes&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;When there are many dishes to choose from (here 20), no matter how
many dishes people may want (within reason), individual lines reduce
both the mean wait time and the inequality in wait times compared to a
single line.  Intuitively, this is because people can distribute
themselves and they only have to wait for the dishes they want to eat.&lt;/p&gt;

&lt;p&gt;Additionally, let’s look at the case when there are many people.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/buffet/wait-ineq-many-people.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;500 people serving themselves in a buffet with 6 dishes&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;In this case, we see the counter-intuitive result again: the mean wait
time is quite a bit higher for individual lines when most people want
most of the foods, however inequality is still lower.&lt;/p&gt;

&lt;p&gt;Finally, we can examine the case when there are very few people.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/buffet/wait-ineq-veryfew-people.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;30 people serving themselves in a buffet with 6 dishes&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;In this case, separate lines are better for both mean wait time and
equality.&lt;/p&gt;

&lt;h2 id=&quot;fairness&quot;&gt;Fairness&lt;/h2&gt;

&lt;p&gt;A fair system is one in which the amount of time someone waits is
proportional to the number of dishes they want.  In an unfair
scenario, someone who only wants one dish must wait for the same
amount of time as someone who wants all of the dishes.&lt;/p&gt;

&lt;p&gt;Let’s look at whether this form of fairness holds.  First, we look at
how long someone must wait depending on how many dishes they want.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/buffet/fairness.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Average wait time differs depending on how many dishes a person would like&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;As expected, when there is only one line, everyone must wait for
approximately the same amount of time, no matter how much food they
want to eat.  People who want all of the dishes in a line must wait
for less time on average, but someone who only wants one dish must
wait for a very long time.  By contrast, when there are multiple
lines, the amount of time people wait is proportional to the number of
dishes they want to try.&lt;/p&gt;

&lt;p&gt;Similarly, it might be fairer that someone who can serve themself
quickly has a shorter waiting time than someone who is slower.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/buffet/speed-vs-time.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Points
represent people. There is no significant correlation (\(p&amp;gt;.2\))
between time spent waiting and serving speed&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;Unfortunately this does not seem to be the case in either system.
Rather, people who are slow to serve themselves take approximately the
same amount of time in line as those who are fast.&lt;/p&gt;

&lt;h2 id=&quot;summary-and-conclusions&quot;&gt;Summary and conclusions&lt;/h2&gt;

&lt;p&gt;In summary, when there are a lot of people present, if everyone wants
most of the food at the buffet, a single line counter-intuitively
reduces the mean wait time.  However, this single line substantially
increases inequality in wait times, meaning that some people will have
to wait for a long time while others can go through immediately.
Additionally, people who only want a small amount of food must wait a
long time to serve themselves.  A more fair but slightly less
efficient system is one where there is a separate station for each
dish, but this can be inefficient when most people want most of the
dishes available.&lt;/p&gt;

&lt;p&gt;This analysis leaves out a few factors which are difficult to account
for.  For example, it assumes the amount of time taken to walk from
one food to another is negligible, and that people know &lt;em&gt;a priori&lt;/em&gt;
what food they would like to eat and where it is located.  Both of
these have the potential to slow down serving times in the case with
separate lines.  This analysis also doesn’t account for several other
factors which are important in real life.  For example, it assumes
that space is not an issue.  It also assumes there is enough seating
to accommodate everybody; if only a limited amount of seating is
available, a high inequality is desirable as it prevents everyone from
going to the dining area at one time.&lt;/p&gt;

&lt;p&gt;One method which is often employed to speed up single lines is having
more than one identical line, or two sides on the same line, likewise,
in the case of separate lines, there are sometimes “stations” which
have identical dishes. In both cases, because we assume people balance
themselves by going to the shortest line, doubling the number of
copies of all dishes would be expected to approximately cut the mean
wait time in half.&lt;/p&gt;

&lt;h3&gt;Code/Data:&lt;/h3&gt;

&lt;ul&gt;

    &lt;li&gt;&lt;a href=&quot;/res/buffet/buffet_model.py&quot;&gt;Data analysis script&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;

</description>
        <pubDate>Sat, 02 Mar 2019 00:00:00 +0000</pubDate>
        <link>/2019/03/02/are-buffets-efficient.html</link>
        <guid isPermaLink="true">/2019/03/02/are-buffets-efficient.html</guid>
        
        <category>modeling</category>
        
        <category>food</category>
        
        <category>buffet</category>
        
        <category>queuing-theory</category>
        
        
        <category>Model</category>
        
      </item>
    
      <item>
        <title>Optimality in card shuffling
</title>
        <description>&lt;p&gt;Many powerful minds have devoted countless decades to the academic
study of card games.  However, relatively little attention has been
given to the best way to shuffle a deck of cards.  There are several
different methods that people have developed to shuffle cards:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=O8W9ipOSmWA&quot;&gt;The riffle shuffle&lt;/a&gt;:
The classic shuffling method.  Cut the deck approximately in half.
Take one half in each hand, and let the cards from both decks fall
on top of one another.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=x5tLNHuvf6s&quot;&gt;The overhand shuffle&lt;/a&gt;:
Another very popular method.  Hold the cards in one hand, and take
the cards with your other hand, and let them fall on top.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=0ZXhPWkro9A&quot;&gt;The Hindu shuffle&lt;/a&gt;: A
method popular in India.  It is a different style of performing an
overhand shuffle.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://youtu.be/pnULsmjX4VA?t=26&quot;&gt;The pile shuffle&lt;/a&gt;: Create
several sub-decks of cards, by placing cards one-by-one into a
(potentially random) sub-deck.  Then, combine the sub-decks together.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href=&quot;http://www.ams.org/samplings/feature-column/fcarc-shuffle&quot;&gt;It has been claimed&lt;/a&gt;
that seven, eight, or more riffle shuffles are necessary to obtain
complete randomization.  However, these studies assume that any
difference in probability between a shuffled deck and a fully random
permutation can be exploited by the players.  This is an important
model for casinos where large amounts of money are at stake, but for
games between friends where perfect randomness is not needed, seven or
eight shuffles in between hands causes a substantial delay in the
game.&lt;/p&gt;

&lt;p&gt;Thus, below I describe how many shuffles you need &lt;em&gt;in practice&lt;/em&gt;
instead of &lt;em&gt;in theory&lt;/em&gt;.  My evaluation looks for patterns and
irregularities in hands that would be dealt.  It accounts for three
types of patterns—suits, ranks, and clusters/straights—by looking
at the joint distribution of of these frequencies compared to a null
distribution.  (For instance, a six card hand containing four of one
suit and two of another is highly unlikely.)  I simulate a number of
different shuffling methods and find the probability of obtaining the
arrangements generated by these shuffles in a truly random deck.&lt;/p&gt;

&lt;p&gt;Each of the shuffles starts with either fully ordered decks (i.e. a
new deck of cards), or else with cards in an order representative of a
specific card game.  I compare these to a deck which started out fully
randomized before the shuffle as a control, which is therefore
guaranteed to be fully randomized after the shuffle.  All shuffles
should be compared to the randomized deck, i.e. the red line in the
plots.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/shuffle/legend.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Card game deck patterns used in all figures which follow.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;h2 id=&quot;riffle-shuffle&quot;&gt;Riffle shuffle&lt;/h2&gt;

&lt;p&gt;The riffle shuffle is arguably the most popular shuffling method.  The
standard accepted mathematical model for the Riffle shuffle is called
the
&lt;a href=&quot;https://en.wikipedia.org/wiki/Gilbert%E2%80%93Shannon%E2%80%93Reeds_model&quot;&gt;Gilbert-Shannon-Reeds model&lt;/a&gt;
(GSR model).  (Yes, that’s
&lt;a href=&quot;https://en.wikipedia.org/wiki/Claude_Shannon&quot;&gt;Claude Shannon&lt;/a&gt;.)  This
model assumes that the shuffler is an expert and can dynamically
adjust the rate at which cards are laid down from each hand during the
shuffle.  It states that the probability of putting down a card from
either hand is proportional to the relative size of the deck in that
hand.  For example, if your left hand had 30 cards and your right hand
had 10, you would have a 3/4 probability of the next card coming from
your left hand.&lt;/p&gt;

&lt;p&gt;Hesitant to accept this definition, I developed another model which
includes a skill parameter \(\lambda\).  High \(\lambda\) means that
there is a low probability of two consecutive cards being dealt from
the same hand, whereas low \(\lambda\) means there will be large
bunches of cards from the same hand in the deck.  This is motivated by
the fact that, given the speed at which cards are shuffled, most
people do not have the reaction time necessary to adjust the rate at
which they let cards fall from either hand, and also by the fact that
casino dealers come close to alternating cards from each hand.&lt;/p&gt;

&lt;p&gt;In order to test these models, I collected data from my own shuffles
to determine the most likely model.  I found that my model was
slightly more likely given the data, but if you account for the fact
that my model has a parameter whereas the GSR model has none, the GSR
model is a slightly better fit to the data.&lt;/p&gt;

&lt;p&gt;Because they were close, I decided to test both cases, and also to
vary the skill level \(\lambda\).  I tested four cases: a novice
shuffler (\(\lambda=0.3\)), an average shuffler (\(\lambda=0.45\), the
best fit to my shuffling data), an expert shuffler (\(\lambda=0.8\)),
and the ideal GSR case (which has no parameter).&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/shuffle/riffle.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Effectiveness of riffle shuffles as a function of the number of consecutive shuffles.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;As we can see, people comfortable with a riffle shuffle need
approximately &lt;strong&gt;4 shuffles&lt;/strong&gt; in order to randomize the deck, which is
approximately
&lt;a href=&quot;https://projecteuclid.org/download/pdf_1/euclid.aoap/1177005705&quot;&gt;half of the theoretical recommendation&lt;/a&gt;.
An average card player does not have any advantage over a professional
casino dealer in this regard.  Of course, if you’re not riffle
shuffling very well, it will take far more shuffles to achieve the
same degree of randomness.&lt;/p&gt;

&lt;h2 id=&quot;overhandhindu-shuffle&quot;&gt;Overhand/Hindu shuffle&lt;/h2&gt;

&lt;p&gt;The overhand shuffle is equivalent to dividing the deck into a number
of sub-decks and then recombining those decks in reverse order.  By
watching several YouTube videos of people performing the overhand
shuffle, there is a wide variety in the number of times people will
divide the deck when performing the shuffle.  Most people do it around
5 times, but some people consistently do more or fewer than this.&lt;/p&gt;

&lt;p&gt;Here, we consider the cases of 5 cuts, 3 cuts, and 8 cuts, as these
values covers the typical range of cuts.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/shuffle/overhand.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Effectiveness of overhand shuffles as a function of the number of consecutive shuffles.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;It takes many more overhand shuffles to randomize the deck.  Assuming
an average number of cuts, it takes approximately &lt;strong&gt;25 shuffles&lt;/strong&gt;, which
is 20-60 times less than
&lt;a href=&quot;https://www.math.upenn.edu/~pemantle/papers/overhand2.pdf&quot;&gt;the theoretical result&lt;/a&gt;.
When you only cut the deck 3 times during an overhand shuffle, this
number jumps to almost 40.  Nevertheless, this goes against the
theoretical finding, and suggests that the overhand shuffle is a valid
and useful method, even if it is a bit more time consuming.&lt;/p&gt;

&lt;h2 id=&quot;pile-shuffle&quot;&gt;Pile shuffle&lt;/h2&gt;

&lt;p&gt;The pile shuffle has many variants.  In the strict form, the shuffler
deals all of the cards into some number of piles, and then stacks the
cards on top of each other.&lt;/p&gt;

&lt;p&gt;Clearly this strict form is both deterministic and highly patterned,
and thus it is rather ineffective.  Sometimes, people will add a
slight bit of randomization by picking up the piles in a different
order than they laid them down. More frequently, people will perform
this deal by randomizing the order in which they lay down cards into
the decks.  Sometimes they will do so while keeping the decks
approximately the same size, and sometimes they will disregard deck
size.  (However, note that
&lt;a href=&quot;http://blog.maxshinnpotential.com/2017/07/05/can-humans-generate-random-numbers.html&quot;&gt;people are notoriously bad at randomizing&lt;/a&gt;,
so these should be considered the maximum limits of randomization
rather than the method’s true amount of randomization.)&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/shuffle/piles.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Effectiveness of pile shuffles as a function of the number of piles.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;We see that pile shuffling is not very efficient when only performed
once.  The reason appears to be that this method does not randomize
the ranks in the deck.  If you started with an ordered deck, you can
be nearly certain that if you pick up a 3, the next card will not be
a 2.  Most versions of pile shuffling are ineffective for this reason.
The only version which works is the version which keeps the decks at
an approximately similar size throughout the duration of the shuffle,
while using at least eight decks.  However, this also assumes that the
shuffler is able to generate near-random numbers, which is impossible
without either a random number generator or knowledge of strategies
for generating random numbers without one.&lt;/p&gt;

&lt;h2 id=&quot;miscellaneous-results&quot;&gt;Miscellaneous results&lt;/h2&gt;

&lt;p&gt;I simulated two styles of deals from the shuffled deck: one where the
top 6 cards were taken from the deck, and one where there were 4
players, and 6 cards were dealt to each in a clockwise manner.  Results
were nearly identical for both cases, so only results for the former
are included here.&lt;/p&gt;

&lt;p&gt;I also simulated the mixed case which combines riffle shuffles and
that overhand shuffles, with the hypothesis that adding a few overhand
shuffles could reduce the number of riffle shuffles needed to
randomize the deck.  Unfortunately, this turned out to not be the
case.  Adding one or two overhand shuffles to different places in the
riffle shuffle sequence was not able to reduce the number of riffle
shuffles needed to randomize the deck.&lt;/p&gt;

&lt;p&gt;If we assume that the riffle shuffle takes approximately 5 seconds to
perform and the overhand shuffle takes 2 seconds to perform, it takes
40 seconds to randomize the deck using the overhand shuffle but 20
seconds to randomize it using the riffle shuffle.  If we assume that
four cards can be dealt per second and decks can be straightened and
stacked at a rate of one per subpile, a suitable pile shuffle would
take 21 seconds.  However, this is also assuming suitable
randomization, and thus, cards may not be as randomized as in the
other methods.&lt;/p&gt;

&lt;p&gt;There are other considerations in choosing the shuffling method as
well; for instance, the overhand shuffle is considered to be less
damaging to the cards than a riffle shuffle, which may bend the cards.&lt;/p&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;p&gt;From this analysis, we have learned the following:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The riffle shuffle is highly efficient, requiring only 4 shuffles in
order to make a deck random for most practical purposes.&lt;/li&gt;
  &lt;li&gt;When using 5 deck cuts in the overhand shuffle, about 25 shuffles
are necessary to randomize the deck.  While it takes longer to
perform, it is equally as effective as 4 riffle shuffles after 25
iterations.&lt;/li&gt;
  &lt;li&gt;10 or more riffle shuffles may be required if the shuffler lacks
experience.&lt;/li&gt;
  &lt;li&gt;The pile shuffle should generally be avoided, unless using eight or
more piles, distributing cards randomly, ensuring all piles are
approximately the same size, and ideally finding a way to circumvent
the limitations humans have in generating random numbers.&lt;/li&gt;
  &lt;li&gt;Combining overhand shuffles with riffle shuffles does not increase
randomization compared to just using riffle shuffles.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Code/Data:&lt;/h3&gt;

&lt;ul&gt;

    &lt;li&gt;&lt;a href=&quot;/res/shuffle/cards.py&quot;&gt;Python library for performing these analyses&lt;/a&gt;&lt;/li&gt;

    &lt;li&gt;&lt;a href=&quot;/res/shuffle/make_figures.py&quot;&gt;Python script to make the figures in this post&lt;/a&gt;&lt;/li&gt;

    &lt;li&gt;&lt;a href=&quot;/res/shuffle/analyze_riffle_data.py&quot;&gt;Python script for riffle shuffle experiment&lt;/a&gt;&lt;/li&gt;

    &lt;li&gt;&lt;a href=&quot;/res/shuffle/riffle_data.txt&quot;&gt;Data from riffle shuffle experiment&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;

</description>
        <pubDate>Sun, 05 Nov 2017 00:00:00 +0000</pubDate>
        <link>/2017/11/05/optimality-in-card-shuffling.html</link>
        <guid isPermaLink="true">/2017/11/05/optimality-in-card-shuffling.html</guid>
        
        <category>data</category>
        
        <category>modeling</category>
        
        <category>cards</category>
        
        <category>game</category>
        
        <category>randomness</category>
        
        
        <category>Model</category>
        
      </item>
    
      <item>
        <title>Can humans generate random numbers?
</title>
        <description>&lt;p&gt;It is widely known that humans cannot generate sequences of random
binary numbers
&lt;a href=&quot;http://dx.doi.org/10.1037/h0032060&quot;&gt;(e.g. see Wagenaar (1972))&lt;/a&gt;.  The
main problem is that we see true randomness as being “less random”
than it truly is.&lt;/p&gt;

&lt;p&gt;A fun party trick (if you attend the right parties) is to have one
person generate a 10-15 digit random binary number by herself, and
another generate a random binary sequence using coin flips.  You,
using your magical abilities, can identify which one was generated
with the coin.&lt;/p&gt;

&lt;p&gt;The trick to distinguishing a human-generated sequence from a random
sequence is by &lt;em&gt;finding the number of times the sequence switches
between runs of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0&lt;/code&gt;s and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt;s&lt;/em&gt;.  For instance, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0011&lt;/code&gt; switches once, but
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0101&lt;/code&gt; switches three times.  A truly random sequence will have a switch
probability of 50%.  A human generated sequence will be greater
than 50%.  To demonstrate this, I have generated two sequences
below, one by myself and one with a random number generator:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;(A) 11101001011010100010
(B) 11111011001001011000
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For the examples above, sequence (A) switches 13 times, and sequence
(B) switches 9 times.  As you can guess, sequence (A) was mine, and
sequence (B) was a random number generator.&lt;/p&gt;

&lt;p&gt;However, when there is a need to generate random numbers, is it
possible for humans to use some type of procedure to quickly generate
random numbers?  For simplicity, let us assume that the switch
probability is the only bias that people have when generating random
numbers.&lt;/p&gt;

&lt;h2 id=&quot;can-we-compensate-manually&quot;&gt;Can we compensate manually?&lt;/h2&gt;

&lt;p&gt;If we know that the switch probability is abnormal, it is possible
(but much more difficult than you might expect) to generate a sequence
which takes this into account.  If you have time to sit and consider
the binary sequence you have generated, this can work.  It is
especially effective for short sequences, but is not efficient for
longer sequences.  Consider the following longer sequence, which I
generated myself.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;1101100011011010100
1101010111101011000
0101011110101001011
0100110101011110100
1010010101010111111
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This sequence is 100 digits long, and switches 62 times.  A simple
algorithm which will equalize the number of switches is to replace
digits at the beginning of the string with zero until the desired
number of switches has been obtained.  For example:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;0000000000000000000
0001010111101011000
0101011110101001011
0100110101011110100
1010010101010111111
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;But intuitively, this “feels” much less random.  Why might that be?
In a truly random string, not only will the switch probability be
approximately 50%, but the &lt;em&gt;switch probability of switching&lt;/em&gt; will be
approximately 50%, which we will call “2nd order switching”.  What
exactly is 2nd order switching?  Consider the truly random string:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;01000011011100010000
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now, let’s generate a new binary sequence, where a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0&lt;/code&gt; means that a
switch did not happen at a particular location, and a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt; means a
switch did happen at that location.  This resulting sequence will be
one digit shorter than the initial sequence.  Doing this to the above
sequence, we obtain&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;1100010110010011000
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For reference, notice that the sum of these digits is equal to the
total number of switches.  We define the 2nd order switches as the
number of switches in this sequence of switches.&lt;/p&gt;

&lt;p&gt;We can generalize this to \(n\)‘th order switches by taking the sum of
the sequence once we have recursively found the sequence of switches
\(n\) times.  So the number of 1st order switches is equal to the
number of switches in the sequence, the 2nd order is the number of
switches in the switch sequence, the number of 3rd order switches is
equal to the number of switches in the switch sequence of the switch
sequence, and so on.&lt;/p&gt;

&lt;p&gt;Incredibly, in an infinitely-long truly random sequence, &lt;em&gt;the
percentage of \(n\)‘th order switches will always be 50%, for all
\(n\)&lt;/em&gt;.  In other words, no matter how many times we find the
sequence of switches, we will always have about 50% of the digits be
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Returning to our naive algorithm, we can see why this does not mimic a
random sequence.  The number of 2nd order switches is only 24%.  In a
truly random sequence, it would be close to 50%.&lt;/p&gt;

&lt;h2 id=&quot;is-there-a-better-algorithm&quot;&gt;Is there a better algorithm?&lt;/h2&gt;

&lt;p&gt;So what if we make a smarter algorithm?  In particular, what if our
algorithm is based on the very concept of switch probability?  If we
find the sequence of \(n\)‘th order switches, can we get a random
sequence?&lt;/p&gt;

&lt;p&gt;It would take a very long time to do this by hand, so I have written
some code to do it for me.  In particular, this code specifies a
switch probability, and generates a sequence of arbitrary length based
on this (1st order) switch probability.  Then, it will also find the
\(n\)‘th order switch probability.&lt;/p&gt;

&lt;p&gt;As a first measure, we can check if high order switch probabilities
eventually become approximately 50%.  Below, we plot across the switch
probability the average of the \(n\)‘th order difference, which is
very easy to calculate for powers of 2 (see Technical Notes).&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/randombinary/nthdiffmeans-2powers.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;As we
increase the precision by powers of two, we get sequences that have
\(n\)‘th switch probabilities increasingly close to 50%, no matter what
the 1st order switch probability was.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;From this, it would be easy to conclude that the \(n\)‘th switch
probability of a sequence approximates a random sequence as \(n → ∞\).
But is this true?  What if we do the powers of 2 plus one?&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/randombinary/nthdiffmeans-2powers-plus1.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;As we increase the precision by powers of two plus one, we
get no closer to a random sequence than the 2nd order switch
probability.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;As we see, even though the switch probability approaches 50%, there is
“hidden information” in the second order switch probability which
makes this sequence non-random.&lt;/p&gt;

&lt;h2 id=&quot;is-it-possible&quot;&gt;Is it possible?&lt;/h2&gt;

&lt;p&gt;Mathematicians have already figured out how we can turn biased coins
(i.e. coins that have a \(p≠0.5\) probability of landing heads) into
fair coin flips.  This was
&lt;a href=&quot;https://mcnp.lanl.gov/pdf_files/nbs_vonneumann.pdf&quot;&gt;famously described by Von Neumann&lt;/a&gt;.
(While the Von Neumann procedure is not optimal,
&lt;a href=&quot;http://dl.acm.org/citation.cfm?id=1070587&quot;&gt;it is close&lt;/a&gt;, and its
simplicity makes it appropriate for our purposes as a heuristic
method.)  To summarize this method, suppose you have a coin which
comes up heads with a probability \(p≠0.5\).  Then in order to obtain
a random sequence, flip the coin twice.  If the coins come up with the
same value, discard both values.  If they come up with different
values, discard the second value.  This takes on average
\(n/(p-p^2)\) coin flips to generate a sequence of \(n\) values.&lt;/p&gt;

&lt;p&gt;In our case, we want to correct for a biased switch probability.
Thus, we must generate a sequence of random numbers, find the
switches, apply this technique, and then map the switches back to the
initial choices.  So for example,&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;1011101000101011010100101000010
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;has switches at&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;110011100111110111110111100011
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So converting this into pairs, we have&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;11 00 11 10 01 11 11 01 11 11 01 11 10 00 11
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Applying the procedure, we get&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;1 0 0 0 1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;and mapping it back, we get a random sequence of&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;100001
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;(With a bias of \(p=0.7\) in this example, the predicted length of our
initial sequence of 31 was 6.5.  This is a sequence of length 6.)&lt;/p&gt;

&lt;p&gt;It is possible to recreate this precisely with a sliding window.
However, there is an easier way.  In humans, the speed limiting step
is performing these calculations, not generating biased binary digits.
If we are willing to sacrifice theoretical efficiency (i.e. using as
few digits as possible) for simplicity, we can also look at our initial
sequence in chunks of 3.  We then discard the sequences &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;101&lt;/code&gt;,
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;010&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;111&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;000&lt;/code&gt;, but keep the most frequent digit
in the triple for the other observations, namely keeping a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0&lt;/code&gt; for
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;001&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;100&lt;/code&gt;, or a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt; for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;110&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;011&lt;/code&gt;.
(Note that this is only true because we assume an equal probability of
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt; in the initial sequence.  A more general choice
procedure would be a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0&lt;/code&gt; if we observe &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;110&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;001&lt;/code&gt;, and
a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt; if we observe &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;100&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;011&lt;/code&gt;.  However, this is more
difficult for humans to compute.)  A proof that this method generates
truly random sequences is trivial.&lt;/p&gt;

&lt;p&gt;When we apply this method to the sequences in Figures 1 and 2, we get
the following, which shows both powers of two and powers of two plus
one.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/randombinary/nthdiffmeans-2powers-plus1-triplet.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Using the triplet method, no differences of the sequence show
structure, i.e. the probability of a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt; is approximately 50%
in all differences.  These values mimic those of the two previous
figures.  The variance increases at the edges because the probability
of finding the triplets &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;010&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;101&lt;/code&gt; is high when switch
probability is high, and the triplets &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;000&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;111&lt;/code&gt; is high when
switch probability is low, so the resulting sequence is shorter.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;h2 id=&quot;testing-for-randomness-of-these-methods&quot;&gt;Testing for randomness of these methods&lt;/h2&gt;

&lt;p&gt;While there are many definitions of random sequences, the normalized
&lt;a href=&quot;https://en.wikipedia.org/wiki/Entropy_(information_theory)&quot;&gt;entropy&lt;/a&gt;
is especially useful for our purposes.  In short, normalized entropy
divides the sequence into blocks of size \(k\) and looks at the
probability of finding any given sequence of length \(k\).  If it is a
uniform probability, i.e. no block is any more likely than another
block, the function gives a value of 1, but if some occur more
frequently than others, it gives a value less than 1.  In the extreme
case where only one block appears, it gives a value of 0.&lt;/p&gt;

&lt;p&gt;Intuitively, if we have a high switch probability, we would expect to
see the blocks &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;01&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;10&lt;/code&gt; more frequently than &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;00&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;11&lt;/code&gt;.
Likewise, if we have a low switch probability, we would see more &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;00&lt;/code&gt;
and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;11&lt;/code&gt; blocks than &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;01&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;10&lt;/code&gt;.  Similar relationships extend
beyond blocks of size 2.  Entropy is useful for determining randomness
because it makes no assumptions about the form of the non-random
component.&lt;/p&gt;

&lt;p&gt;As we can see below, the triplet method is identical to random, but
all other methods show non-random patterns.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/randombinary/binary-sequence-entropy.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Using entropy, we can see which methods are able to mimic a
random sequence.  Of those we have considered here, only the triplet
method is able to generate random values, as the normalized entropy is
approximately equal to 1 for all sequence lengths.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;h2 id=&quot;conclusions&quot;&gt;Conclusions&lt;/h2&gt;

&lt;p&gt;Humans are not very effective at generating random numbers.  With
random binary numbers, human-generated random numbers tend to switch
back and forth between sequences of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0&lt;/code&gt;s and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt;s too quickly.  Even
when made aware of this bias, it is difficult to compensate for it.&lt;/p&gt;

&lt;p&gt;However, there may be ways that humans can generate sequences which
are closer to random sequences.  One way is to split the sequence into
three-digit triplets, discarding the entire triplet for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;000&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;111&lt;/code&gt;,
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;010&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;101&lt;/code&gt;, and taking the most frequent number in all other
triplets.  When the key non-random element is switch probability, this
creates an easy-to-compute method for generating a random binary
sequence.&lt;/p&gt;

&lt;p&gt;Nevertheless, this triplet method relies on the assumption that the
only bias humans have when generating random binary numbers is the
switch probability bias.  Since no data were analyzed here, it is
still necessary to look into whether human-generated sequences have
more non-random elements than just a change in switch probability.&lt;/p&gt;

&lt;h2 id=&quot;more-information&quot;&gt;More information&lt;/h2&gt;

&lt;h3 id=&quot;technical-notes&quot;&gt;Technical notes&lt;/h3&gt;

&lt;p&gt;The 1st order switch sequence is also called differencing.  Similarly,
the sequence of \(n\)‘th order switches is equal to the \(n\)‘th
difference.  The 1st difference can also be thought of as a sliding
XOR window, i.e. a parity sliding window of size 2.&lt;/p&gt;

&lt;p&gt;Using the concept of a sliding XOR window raises the idea that the
\(n\)‘th difference can be represented as as sliding parity window of
size greater than 2.  By construction, for a sequence of length \(N\),
a sliding window of size \(k\) would end up producing a sequence of
length \(N-k+1\).  Since the \(n\)‘th difference produces a sequence
of length \(N-n\), this means that a sliding window of length \(k\)
would be limited to only the \((k-1)\)‘th difference.&lt;/p&gt;

&lt;p&gt;It turns out that this can only be shown to hold for window sizes of
powers of two.  The proof by induction that this holds for window
sizes of powers of two is a simple proof by induction.  The 0th
difference corresponds to a window of size 1.  The parity of a single
binary digit is just the digit itself.  So it holds trivially in this
case.&lt;/p&gt;

&lt;p&gt;For the induction step, suppose the \((k-1)\)‘th difference is equal
to the parity for a window of size \(k\) where \(k\) is a power of 2.
Let \(x\) be any bit in at least the \((2k-1)\)‘th difference.  Let
the window of \(x\) be the appropriate window of \(2k\) digits of the
original sequence which determines the value of \(x\).  We need to
show that the parity of the window of \(x\) is equal to the value of
\(x\).&lt;/p&gt;

&lt;p&gt;Without loss of generality, suppose the sequence of bits is of length
\(2k\) (the window of \(x\)), and \(x\) is the single bit that is the
\((2k-1)\)‘th difference.&lt;/p&gt;

&lt;p&gt;Let us split the sequence in half, and apply the assumption to the
first half and then to the second half separately.  We notice that the
parity of the parities of these halves is equal to the parity of the
entire sequence.  Splitting the sequence in half tells us that the
first bit in the \((k-1)\)‘th difference is equal to the parity of the
first half of the bits, and the second bit in the \((k-1)\)‘th
difference is equal to the parity of the second half of the bits.&lt;/p&gt;

&lt;p&gt;We can reason that these two bits would be equal iff the parity of the
\(k\)‘th difference is 0, and different iff the parity of the \(k\)‘th
difference is 1, because by the definition of a difference, we switch
every time there is a 1 in the sequence, so an even number of switches
means that the two bits would have the same parity.  By applying our
original assumption again, we know that if the \(k\)‘th difference is
0, then \(x\) will be 0, and if the \(k\)‘th difference is 1, \(x\)
will be 1.&lt;/p&gt;

&lt;p&gt;Therefore, \(x\) is equal to the parity of a window of size \(2k\),
and hence the \((2k-1)\)‘th difference is equal to the parity of a
sliding window of size \(2k\). QED.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/randombinary/proof.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;A visual version of
the above proof.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;h3&gt;Code/Data:&lt;/h3&gt;

&lt;ul&gt;

    &lt;li&gt;&lt;a href=&quot;/res/randombinary/randombinary.py&quot;&gt;Analysis script&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;

</description>
        <pubDate>Wed, 05 Jul 2017 00:00:00 +0000</pubDate>
        <link>/2017/07/05/can-humans-generate-random-numbers.html</link>
        <guid isPermaLink="true">/2017/07/05/can-humans-generate-random-numbers.html</guid>
        
        <category>randomness</category>
        
        <category>stats</category>
        
        <category>algorithm</category>
        
        
        <category>Psych</category>
        
      </item>
    
      <item>
        <title>When to stop and when to keep going
</title>
        <description>&lt;p&gt;I was recently posed the following puzzle:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Imagine you are offered a choice between two different bets.  In
(A), you must make 2/3 soccer shots, and in (B), you must make
5/8.  In either case, you receive a \($100\) prize for winning the bet.
Which bet should you choose?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Intuitively, a professional soccer player would want to take the
second bet, whereas a hopeless case like me would want to take the
first.  However, suppose you have no idea whether your skill level is
closer to Lionel Messi or to Max Shinn.  The puzzle continues:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;You are offered the option to take practice shots to determine your
skill level at a cost of \($0.01\) for each shot.  Assuming you and
the goalie never fatigue, how do you decide when to stop taking
practice shots and choose a bet?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Clearly it is never advisable to take more than \(100/.01=10000\)
practice shots, but how many &lt;em&gt;should&lt;/em&gt; we take?  A key to this question
is that you do not have to determine the number of shots to take
beforehand.  Therefore, rather than determining a fixed number of
shots to take, we will instead need to determine a decision procedure
for when to stop shooting and choose a bet.&lt;/p&gt;

&lt;p&gt;There is no single “correct” answer to this puzzle, so I have
documented my approach below.&lt;/p&gt;

&lt;h2 id=&quot;approach&quot;&gt;Approach&lt;/h2&gt;

&lt;p&gt;To understand my approach, first realize that there are a finite
number of potential states that the game can be in, and that you can
fully define each state based on how many shots you have made and how
many you have missed.  The sum of these is the total number of shots
you have taken, and the order does not matter.  Additionally, we
assume that all states exist, even if you will never arrive at that
state by the decision procedure.&lt;/p&gt;

&lt;p&gt;An example of a state is taking 31 shots, making 9 of them, and
missing 22 of them.  Another example is taking 98 shots, making 1 of
them and missing 97 of them.  Even though we may have already made a
decision before taking 98 shots, the concept of a state does not
depend on the procedure used to “get there”.&lt;/p&gt;

&lt;p&gt;Using this framework, it is sufficient to show which decision we
should take given what state we are in.  My approach is as follows:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Find a tight upper bound \(B \ll 10000\) on the number of practice
shots to take.  This limits the number of states to work with.&lt;/li&gt;
  &lt;li&gt;Determine the optimal choice based on each potential state after
taking \(B\) total shots.  Once \(B\) shots have been taken, it is
always best to have chosen either bet (A) or bet (B), so choose the
best bet without the option of shooting again.&lt;/li&gt;
  &lt;li&gt;Working backwards, starting with states with \(B-1\) shots and
moving down to \(B-2,...,0\), determine the expected value of each
of the three choices: select bet (A), select bet (B), or shoot
again.  Use this to determine the optimal choice to make at that
position.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The advantage of this approach is that the primary criterion we will
work with is the expected value for each decision.  This means that if
we play the game many times we will maximize the amount of money we
earn.  As a convenient consequence of this, we know much money we can
expect to earn given our current state.&lt;/p&gt;

&lt;p&gt;The only reason this procedure is necessary is because we don’t know
our skill level.  If we could determine with 100% accuracy what are
skill level was, we would never need to take any shots at all.  Thus,
a key part of this procedure is estimating our skill level.&lt;/p&gt;

&lt;h2 id=&quot;what-if-you-know-your-skill-level&quot;&gt;What if you know your skill level?&lt;/h2&gt;

&lt;p&gt;We define skill level as the probability \(p_0\) that you will make a
shot.  So if you knew your probability of making each shot, we could
find your expected payoff from each bet.  On the plot below, we show
the payoff (in dollars) of each bet on the y-axis, and how it changes
with skill on the x-axis.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/soccer/winning_prob_binom.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Assuming
we have a precise knowledge of your skill level, we can find how much
money you can expect to make from each bet.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;The first thing to notice is the obvious: as our skill improves, the
amount of money we can expect to win increases.  Second, we see that
there is some point (the “equivalence point”) at which the bets are
equal; we compute this numerically to be \(p_0 = 0.6658\).  We should
choose bet (A) if our skill level is worse than \(0.6658\), and bet (B) if
it is greater than \(0.6658\).&lt;/p&gt;

&lt;p&gt;But suppose our guess is poor.  We notice that &lt;em&gt;the consequence for
guessing too high is less than the consequence for guessing too low&lt;/em&gt;.
It is better to bias your choice towards (A) unless you obtain
substantial evidence that you have a high skill level and (B) would be
a better choice.  In other words, the potential gains from choosing
(A) over (B) are larger than the potential gains for choosing (B) over
(A).&lt;/p&gt;

&lt;h2 id=&quot;finding-a-tight-upper-bound&quot;&gt;Finding a tight upper bound&lt;/h2&gt;

&lt;p&gt;Quantifying this intuition, we compute the maximal possible gain of
choosing (A) over (B) and (B) over (A) as the maximum distance between
the curves on each side of the equivalence point.  In other words, we
find the skill level at which the incentive is strongest to choose one
bet over the other, and then find what the incentive is at these
points.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/soccer/winning_prob_binom_lines.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;We
see here the locations where the distance between the curves is
greatest, showing the skill levels where it is most advantageous to
choose (A) or (B).&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;This turns out to be \($4.79\) for choosing (B) over (A), and
\($17.92\) for choosing (A) over (B).  Since each shot costs
\($0.01\), we conclude that it is never a good idea to take more than
479 practice shots.  Thus, our upper bound \(B=479\).&lt;/p&gt;

&lt;h2 id=&quot;determining-the-optimal-choice-at-the-upper-bound&quot;&gt;Determining the optimal choice at the upper bound&lt;/h2&gt;

&lt;p&gt;Because we will never take more than 479 shots, we use this as a
cutoff point, and force a decision once 479 shots have been taken.  So
for each possible combinations of successes and failures, we must
find whether bet (A) or bet (B) is better.&lt;/p&gt;

&lt;p&gt;In order to determine this, we need two pieces of information: first,
we need the expected value of bets (A) and (B) given \(p_0\) (i.e. the
curve shown above); second, we need the distribution representing our
best estimate of \(p_0\).  Remember, it is not enough to simply choose
(A) when our predicted skill is less than \(0.6658\) and (B) when it
is greater than \(0.6658\); since we are biased towards choosing (A),
we need a probability distribution representing potential values of
\(p_0\). Then, we can find the expected value of each bet given the
distribution of \(p_0\) (see appendix for more details).  This can be
computed with a simple integral, and is easy to approximate
numerically.&lt;/p&gt;

&lt;p&gt;Once we have performed these computations, in addition to having
information about whether (A) or (B) was chosen, we also know the
expected value of the chosen bet.  This will be critical for
determining whether it is beneficial to take more shots before we have
reached the upper bound.&lt;/p&gt;

&lt;h2 id=&quot;determining-the-optimal-choice-below-the-upper-bound&quot;&gt;Determining the optimal choice below the upper bound&lt;/h2&gt;

&lt;p&gt;We then go down one level: if 478 shots have been taken, with \(k\)
successes and \((478-k)\) failures, should we choose (A), should we
choose (B), or should we take another shot?  Remember, we would like
to select the choice which will give us the highest expected outcome.&lt;/p&gt;

&lt;p&gt;Based on this principle, it is only advisable to take another shot if
it would influence the outcome; in other words, if you would choose
the same bet no matter what the outcome of your next shot, it does not
make sense to take another shot, because you lose \($0.01\) without
gaining any information.  It only makes sense to take the shot if the
information gained from taking the shot increases the expected value
by more than \($0.01\).&lt;/p&gt;

&lt;p&gt;Thus, we would only like to take another shot if the information
gained is worth more than \($0.01\).  We can compute this by finding the
expected value of each of the three options (choose (A), choose (B),
or shoot again).  Using our previous experiments to judge the
probability of a successful shot (see appendix), we can find the
expected payoff of taking another shot.  If it is greater than
choosing (A) or (B), we take the shot.&lt;/p&gt;

&lt;p&gt;Working backwards, we continue until we are on our first shot, where
we assume we have a \(50\)% chance of succeeding.  Once we reach this
point, we have a full decision tree, indicating which action we should
take based on the outcome of each shot, and the entire decision
process can be considered solved.&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Here is the decision tree, plotted in raster form.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/soccer/decision-tree.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Starting at
the point (0,0), go one to the right for every shot that you take, and
one up for every shot that you make.  Red indicates you should shoot
again, blue indicates you should choose (A), and green indicates you
should choose (B).&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;Looking more closely at the beginning, we see that unless you are
really good, you should choose (A) rather quickly.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/soccer/decision-tree-zoomed.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;An
identical plot to that above, but zoomed in near the beginning.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;We can also look at the amount of money you will win on average if you
play by this strategy.  As expected, when you make more shots, you
will have a higher chance of winning more money.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/soccer/value-tree.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;For each point in
the previous figures, these values correspond to the choices.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;We can also look at the zoomed in version.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/soccer/value-tree-zoomed.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;An
identical plot to the one above, but zoomed in near the beginning.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;This algorithm grows in memory and computation time like \(O(B^2)\),
meaning that if we double the size of the upper bound, we quadruple
the amount of memory and CPU time we require.&lt;/p&gt;

&lt;p&gt;This may not be the best strategy, but it seems to be a principled
strategy which works reasonably well with a relatively small runtime.&lt;/p&gt;

&lt;h2 id=&quot;appendix-determining-the-distribution-of-p_0&quot;&gt;Appendix: Determining the distribution of \(p_0\)&lt;/h2&gt;

&lt;p&gt;In order to find the distribution for \(p_0\), we consider the
distribution of \(p_0\) for a single shot.  The chance that we make a
shot is \(100\)% if \(p_0=1\), \(0\)% if \(p_0=0\), \(50\)% if
\(p_0=0.5\), and so on.  Thus, the distribution of \(p_0\) from a
single successful trial is \(f(p)=p\) for \(0 ≤ p ≤ 1\).  Similarly,
if we miss the shot, then the distribution is \(f(p)=(1-p)\) for
\(0≤p≤1\).  Since these probabilities are independent, we can multiply
them together and find that, for \(n\) shots, \(k\) successes, and
\((n-k)\) failures, we have \(f(p)=p^k (1-p)^{n-k}/c\) for some
normalizing constant \(c\).  It turns out, this is identical to the
beta distribution, with parameters \(α=k+1\) and \(β=n-k+1\).&lt;/p&gt;

&lt;p&gt;However, we need a point estimate of \(p_0\) to compute the expected
value of taking another shot.  We cannot simply use the ratio \(n/k\)
for two practical reasons: first, it is undefined when no shots have
been taken, and second, when the first shot has been taken, we have a
\(100\)% probability of one outcome and a \(0\)% probability of the
other.  If we want to assume a \(50\)% probability of making the shot
initially, an easy way to solve this problem is to use the ratio
\((k+1)/(n+2)\) instead of \(k/n\) to estimate the probability.
Interestingly, this quick and dirty solution is equivalent to finding
the mean of the beta distribution.  When no shots have been taken,
\(k=0\) and \(n=0\), so \(α=1\) and \(β=1\), which is equivalent to the
uniform distribution, hence our non-informative prior.&lt;/p&gt;

&lt;h3&gt;Code/Data:&lt;/h3&gt;

&lt;ul&gt;

    &lt;li&gt;&lt;a href=&quot;/res/soccer/find-best-strategy.py&quot;&gt;Analysis script&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;

</description>
        <pubDate>Wed, 08 Mar 2017 00:00:00 +0000</pubDate>
        <link>/2017/03/08/when-to-stop-and-when-to-keep-going.html</link>
        <guid isPermaLink="true">/2017/03/08/when-to-stop-and-when-to-keep-going.html</guid>
        
        <category>algorithm</category>
        
        <category>stats</category>
        
        <category>modeling</category>
        
        <category>puzzle</category>
        
        <category>game</category>
        
        
        <category>Puzzle</category>
        
      </item>
    
      <item>
        <title>Which hints are best in Towers?
</title>
        <description>&lt;p&gt;There is a wonderful collection of puzzles by Simon Tatham called the
&lt;a href=&quot;http://www.chiark.greenend.org.uk/~sgtatham/puzzles/&quot;&gt;Portable Puzzle Collection&lt;/a&gt;
which serves as a fun distraction.  The game “Towers” is a simple puzzle
where you must fill in a
&lt;a href=&quot;https://en.wikipedia.org/wiki/Latin_square&quot;&gt;Latin square&lt;/a&gt; with
numbers \(1 \ldots N\), only one of each per row/column, as if the
squares contained towers of this height.  The number of towers visible
from the edges of rows and columns are given as clues.  For example,&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/towers/example-board.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;An example starting board from the Towers game.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;Solved, the board would appear as,&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/towers/solved-example.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;The previous example solved.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;In more advanced levels, not all of the hints are given.
Additionally, in these levels, hints can also be given in the form of
the value of particular cells. For example, the initial conditions of
the puzzle may be,&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/towers/hard-level.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;A more difficult example board.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;With such different types of hints, it raises the question of whether
some hints are better than others.&lt;/p&gt;

&lt;h2 id=&quot;how-will-we-approach-the-problem&quot;&gt;How will we approach the problem?&lt;/h2&gt;

&lt;p&gt;We will use an
&lt;a href=&quot;https://en.wikipedia.org/wiki/Shannon_information&quot;&gt;information-theoretic&lt;/a&gt;
framework to understand how useful different hints are.  This allows
us to measure the amount of information that a particular hint gives
about the solution to a puzzle in bits, a nearly-identical unit to
that used by computers to measure file and memory size.&lt;/p&gt;

&lt;p&gt;Information theory is based on the idea that random variables
(quantities which can take on one of many values probabilistically)
are not always independent, so sometimes knowledge of the value of one
random variable can change the probabilities for a different random
variable.  For instance, one random variable may be a number 1-10, and
a second random variable may be whether that number is even or odd.  A
bit is an amount of information equal to the best possible yes or no
question, or (roughly speaking) information that can cut the number of
possible outcomes in half.  Knowing whether a number is even or odd
gives us one bit of information, since it specifies that the first
random variable can only be one of five numbers instead of one of ten.&lt;/p&gt;

&lt;p&gt;Here, we will define a few random variables.  Most importantly, we
will have the random variable describing the correct solution of the
board, which could be any possible board.  We will also have random
variables which represent hints.  There are two types of hints:
initial cell value hints (where one of the cells is already filled in)
and tower visibility hints (which define how many towers are visible
down a row or column).&lt;/p&gt;

&lt;p&gt;The number of potential Latin squares of size \(N\) grows very fast.
For a \(5×5\) square, there are 161,280 possibilities, and for a
\(10×10\), there are over \(10^{47}\).  Thus, for computational
simplicity, we analyze a \(4×4\) puzzle with a mere 576 possibilities.&lt;/p&gt;

&lt;h2 id=&quot;how-useful-are-initial-cell-value-hints&quot;&gt;How useful are “initial cell value” hints?&lt;/h2&gt;

&lt;p&gt;First, we measure the entropy, or the maximal information content that
a single cell will give.  For the first cell chosen, there is an equal
probability that any of the values (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3&lt;/code&gt;, or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;4&lt;/code&gt;) will be
found in that cell.  Since there are two options, this give us 2 bits
of information.&lt;/p&gt;

&lt;p&gt;What about the second initial cell value?  Interestingly, it depends
both on the location and on the value.  If the second clue is in the
same row or column as the first, it will give less information.  If it
is the same number as the first, it will also give less information.&lt;/p&gt;

&lt;p&gt;Counter-intuitively, in the 4×4 board, this means we gain &lt;em&gt;more&lt;/em&gt; than
2 bits of information from the second hint.  This is because, once we
reveal the first cell’s value, the probabilities of each of the other
cell’s possible values are not equal as they were before.  Since we
are not choosing from the same row or column of our first choice, is
more likely that this cell will be equal to the first cell’s value
than to any other value.  So therefore if we reveal a value which is
different, it will provide more information.&lt;/p&gt;

&lt;p&gt;Intuitively, for the 4×4 board, suppose we reveal the value of a cell
and it is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;4&lt;/code&gt;.  There cannot be another &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;4&lt;/code&gt; in the same column or row,
so if we are to choose a hint from a different column or row, we are
effectively choosing from a leaving a 3×3 grid.  There must be 3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;4&lt;/code&gt;
values in the 3×3 grid, so the probability of selecting it is 1/3.  We
have an even probability of selecting a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2&lt;/code&gt;, or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3&lt;/code&gt;, so each
other symbol has a probability of 2/9.  Being more surprising finds,
we gain 2.17 bits of information from each of these three.&lt;/p&gt;

&lt;p&gt;Consequently, selecting a cell in the same row or column, or one which
has the same value as the first, will give an additional 1.58 bits of
information.&lt;/p&gt;

&lt;h2 id=&quot;how-about-tower-visibility-hints&quot;&gt;How about “tower visibility” hints?&lt;/h2&gt;

&lt;p&gt;In a 4×4 puzzle, it is very easy to compute the information gained if
the hint is a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt; or a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;4&lt;/code&gt;.  A hint of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt; always gives the same
amount of information as a single square: it tells us that the cell on
the edge of the hint must be a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;4&lt;/code&gt;, and gives no information about the
rest of the squares.  If only one tower can be seen, the tallest tower
must come first.  Thus, it must give 2 bits of information.&lt;/p&gt;

&lt;p&gt;Additionally, we know that if the hint is equal to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;4&lt;/code&gt;, the only
possible combination for the row is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;4&lt;/code&gt;.  Thus, this
gives an amount of information equal to the entropy of a single row,
which turns out to be 4.58 bits.&lt;/p&gt;

&lt;p&gt;For a hint of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3&lt;/code&gt;, the information content is not as
immediately clear, but we can calculate them numerically.  For a hint
of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2&lt;/code&gt;, we have 1.13 bits, and for a hint of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3&lt;/code&gt;, we have 2 bits.&lt;/p&gt;

&lt;p&gt;Conveniently, due to the fact that the reduction of entropy in a row
must be equal to the reduction of entropy in the entire puzzle, we can
compute values for larger boards.  Below, we show the information
gained about the solution from each possible hint (indicated by the
color).  In general, it seems higher hints are usually better, but a
hint of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt; is generally better than one of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3&lt;/code&gt;.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/towers/information-by-board-size.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;For each board size, the information content of each
potential hint is plotted.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;In summary:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The more information given by a hint for a puzzle, the easier that
hint makes it to solve the puzzle.&lt;/li&gt;
  &lt;li&gt;Of the two types of hints, usually the hints about the tower
visibility are best.&lt;/li&gt;
  &lt;li&gt;On small boards (of size less than 5), hints about individual cells
are very useful.&lt;/li&gt;
  &lt;li&gt;The more towers visible from a row or column, the more information is
gained about the puzzle from that hint.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Of course, remember that all of the hints combined of any given puzzle
must be sufficient to completely solve the puzzle (assuming the puzzle
is solvable), so the information content provided by the hints must be
equal to the entropy of the puzzle of the given size.  When combined,
we saw in the “initial cell value” that hints may become more or less
effective, so these entropy values cannot be directly added to
determine which hints provide the most information.  Nevertheless,
this serves as a good starting point in determining which hints are
the most useful.&lt;/p&gt;

&lt;h2 id=&quot;more-information&quot;&gt;More information&lt;/h2&gt;

&lt;h3 id=&quot;theoretical-note&quot;&gt;Theoretical note&lt;/h3&gt;

&lt;p&gt;For initial cell hints, it is possible to compute the information
content analytically for any size board.  For a board of size \(N×N\)
with \(N\) symbols, we know that the information contained in the
first hint is \(-\log(1/N)\) bits.  Suppose this play uncovers token
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;X&lt;/code&gt;.  Using this first play, we construct a sub-board where the row
and column of the first hint are removed, leaving us with an
\((N-1)×(N-1)\) board.  If we choose a cell from this board, it has a
\(1/(N-1)\) probability of being &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;X&lt;/code&gt; and an equal chance of being
anything else, giving a \(\frac{N-2}{(N-1)^2}\) probability of each of
the other tokens.  Thus, information gained is
\(-\frac{N-2}{(N-1)^2}×\log\left(\frac{N-2}{(N-1)^2}\right)\) if the
value is different from the first, and
\(-1/(N-1)×\log\left(1/(N-1)\right)\) if they are the same; these
expressions are approximately equal for large \(N\).  Note how no
information is gained when the second square is revealed if \(N=2\).&lt;/p&gt;

&lt;p&gt;Similarly, when a single row is revealed (for example by knowing that
\(N\) towers are visible from the end of a row or column) we know that
the entropy must be reduced by \(-\sum_{i=1}^N \log(1/N)\).  This is
because the first element revealed in the row gives \(-\log(1/N)\)
bits, the second gives \(-\log(1/(N-1))\) bits, and so on.&lt;/p&gt;

&lt;h3 id=&quot;solving-a-puzzle-algorithmically&quot;&gt;Solving a puzzle algorithmically&lt;/h3&gt;

&lt;p&gt;Most of these puzzles are solvable without backtracking, i.e. the next
move can always be logically deduced from the state of the board
without the need for trial and error.  By incorporating the
information from each hint into the column and row states and then
integrating this information across rows and columns, it turned out to
be surprisingly simple to write a quick and dirty algorithm to solve
the puzzles.  This algorithm, while probably not of optimal
computational complexity, worked reasonably well.  Briefly,&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Represent the initial state of the board by a length-\(N\) list of
lists, where each of the \(N\) lists represents a row of the board,
and each sub-list contains all of the possible combinations of this
row (there are \(N!\) of them to start).  Similarly, define an
equivalent (yet redundant) data structure for the columns.&lt;/li&gt;
  &lt;li&gt;Enforce each condition on the start of the board by eliminating the
impossible combinations using the number of towers visible from
each row and column, and using the cells given at initialization.
Update the row and column lists accordingly.&lt;/li&gt;
  &lt;li&gt;Now, the possible moves for certain squares will be restricted by
the row and column limitations; for instance, if only 1 tower is
visible in a row or column, the tallest tower in the row or column
must be on the edge of the board.  Iterate through the cells,
restricting the potential rows by the limitations on the column and
vice versa.  For example, if we know the position of the tallest
tower in a particular &lt;em&gt;column&lt;/em&gt;, eliminate the corresponding &lt;em&gt;rows&lt;/em&gt;
which do not have the tallest tower in this position in the row.&lt;/li&gt;
  &lt;li&gt;After sufficient iterations of (3), there should only be one
possible ordering for each row (assuming it is solvable without
backtracking).  The puzzle is now solved.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is not a very efficient algorithm, but it is fast enough and
memory-efficient enough for all puzzles which might be fun for a human
to solve.  This algorithm also does not work with puzzles which
require backtracking, but could be easily modified to do
so.&lt;/p&gt;

&lt;h3&gt;Code/Data:&lt;/h3&gt;

&lt;ul&gt;

    &lt;li&gt;&lt;a href=&quot;/res/towers/compute_information.py&quot;&gt;Analysis script&lt;/a&gt;&lt;/li&gt;

    &lt;li&gt;&lt;a href=&quot;/res/towers/solve.py&quot;&gt;Script to solve a Towers puzzle&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;

</description>
        <pubDate>Sat, 28 Jan 2017 00:00:00 +0000</pubDate>
        <link>/2017/01/28/which-hints-are-best-in-towers.html</link>
        <guid isPermaLink="true">/2017/01/28/which-hints-are-best-in-towers.html</guid>
        
        <category>puzzle</category>
        
        <category>game</category>
        
        <category>towers</category>
        
        <category>algorithm</category>
        
        <category>information-theory</category>
        
        
        <category>Math</category>
        
      </item>
    
      <item>
        <title>When should you leave for the bus?
</title>
        <description>&lt;p&gt;Anyone who has taken the bus has at one time or another wondered,
“When should I plan to be at the bus stop?” or more importantly, “When
should I leave if I want to catch the bus?”  Many bus companies
suggest
&lt;a href=&quot;http://www.matatransit.com/ridersguide/how-to-ride/&quot;&gt;arriving&lt;/a&gt;
&lt;a href=&quot;http://www.riderta.com/howtoride&quot;&gt;a&lt;/a&gt;
&lt;a href=&quot;http://routes.valleymetro.org/&quot;&gt;few&lt;/a&gt;
&lt;a href=&quot;http://www.metrotransit.org/ride-the-bus&quot;&gt;minutes&lt;/a&gt;
&lt;a href=&quot;http://atltransit.org/guide/tips/&quot;&gt;early&lt;/a&gt;, but there seem to be no
good analyses on when to leave for the bus.  I decided to find out.&lt;/p&gt;

&lt;h2 id=&quot;finding-a-cost-function&quot;&gt;Finding a cost function&lt;/h2&gt;

&lt;p&gt;Suppose we have a bus route where a bus runs every \(I\) minutes, so if
you don’t catch your bus, you can always wait for the next bus.
However, since more than just your time is at stake for missing the
bus (e.g. missed meetings, stress, etc.), we assume there is a penalty
\(\delta\) for missing the bus in addition to the extra wait time.
\(\delta\) here is measured in minutes, i.e. how many minutes of your
time would you exchange to be guaranteed to avoid missing the bus.
\(\delta=0\) therefore means that you have no reason to prefer one bus
over another, and that you only care about minimizing your lifetime
bus wait time.&lt;/p&gt;

&lt;p&gt;Assuming we will not be late enough to need to catch the third bus, we
can model this with two terms, representing the cost to you (in
minutes) of catching each of the next two buses, weighted by the
probability that you will catch that bus:&lt;/p&gt;

\[C(t) = \left(E(T_B) - t\right) P\left(T_B &amp;gt; t + L_W\right) + \left(I + E(T_B) - t + \delta\right) P(T_B &amp;lt; t + L_W)\]

&lt;p&gt;where \(T_B\) is the random variable representing the time at which
the bus arrives, \(L_W\) is the random variable respresenting the
amount of time it takes to walk to the bus stop, and \(t\) is the time
you leave.  (\(E\) is expected value and \(P\) is the probability.)  We
wish to choose a time to leave the office \(t\) which minimizes the cost
function \(C\).&lt;/p&gt;

&lt;p&gt;If we assume that \(T_B\) and \(L_W\) are Gaussian, then it can shown that
the optimal time to leave (which minimizes the above function) is&lt;/p&gt;

\[t = -\mu_W - \sqrt{\left(\sigma_B^2 + \sigma_W^2\right)\left(2\ln\left(\frac{I+\delta}{\sqrt{\sigma_B^2+\sigma_W^2}}\right)-2\ln\left(\sqrt{2\pi}\right)\right)}\]

&lt;p&gt;where \(\sigma_B^2\) is the variance of the bus arrival time,
\(\sigma_W^2\) is the variance of your walk, and \(\mu_W\) is expected
duration of your walk.  In other words, you should plan to arrive at
the bus stop on average \(\sqrt{\left(\sigma_B^2 + \sigma_W^2\right)\left(2\ln\left(\left(I+\delta\right)/\sqrt{\sigma_B^2+\sigma_W^2}\right)-2\ln\left(\sqrt{2\pi}\right)\right)}\) minutes before your bus arrives.&lt;/p&gt;

&lt;p&gt;Note that one deliberate oddity of the model is that the cost function
does not just measure wait time, but also walking time.  I optimized
on this because, in the end, what matters is the total time you spend
getting on the bus.&lt;/p&gt;

&lt;h2 id=&quot;what-does-this-mean&quot;&gt;What does this mean?&lt;/h2&gt;

&lt;p&gt;The most important factor you should consider when choosing which bus
to take is the variability in the bus’ arrival time and the
variability in the time it takes you to walk to the bus.  The arrival
time scales approximately linearly with the standard deviation of the
variability.&lt;/p&gt;

&lt;p&gt;Additionally, it scales at approximately the square root of the log
the your value of time and of the frequency of the buses.  So even if
very high values of time and very infrequent buses do not
substantially change the time at which you should arrive.  For
approximation purposes, you might consider adding a constant in place
of this term, anywhere from 2-5 minutes depending on the frequency of
the bus.&lt;/p&gt;

&lt;h2 id=&quot;checking-the-assumption&quot;&gt;Checking the assumption&lt;/h2&gt;

&lt;p&gt;First, we need to collect some data to assess whether the bus time
arrival (\(T_B\)) is normally distributed.  I wrote scripts to scrape
data from Yale University’s Blue Line campus shuttle route.  Many bus
systems (including Yale’s) now have real-time predictions, so I used
many individual predictions by Yale’s real-time arrival prediction
system as the expected arrival time, simulating somebody checking this
to see when the next bus comes.&lt;/p&gt;

&lt;p&gt;For our purposes, the expected arrival time looks close enough to a
Gaussian distribution:&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/bus/isnormal.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;It actually looks like a Gaussian!&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;h2 id=&quot;so-what-time-should-i-leave&quot;&gt;So what time should I leave?&lt;/h2&gt;

&lt;p&gt;When estimating the \(\sigma_B^2\) parameter, we only examine bus
times which are 10 minutes away or later.  This is because you can’t
use a real-time bus system to plan ahead of time to catch something if
it is too near in the future, which defeats the purpose of the present
analysis.  The variance in arrival time for the Yale buses is
\(\sigma_B^2=5.7\).&lt;/p&gt;

&lt;p&gt;We use an inter-bus interval of \(I=15\) minutes.&lt;/p&gt;

&lt;p&gt;While the variability of the walk to the bus station \(\sigma_W^2\) is
unique for each person, I consider two cases: one case, where we
assume that arrival time variability is small (\(\sigma_W^2=0\))
compared to the bus’ variability, representing the case where the bus
stop is (for intance) located right outside one’s office building.  I
also consider the case where the time variability is comperable to the
variability for the bus (\(\sigma_W=5\)), representing the case where
one must walk a long distance to the bus stop.&lt;/p&gt;

&lt;p&gt;Finally, I consider the case where we strongly prioritize catching the
desired bus (\(\delta=60\) corresponding to, e.g., an important meeting)
and also the case where we seek to directly minimize the expected wait
time (\(\delta=0\) corresponding to, e.g., the commute home).&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/bus/variants.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Even though the
shape of the optimization function changes greatly, the optimal
arrival time changes very little.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;p&gt;We can also look at a spectrum of different cost tradeoffs for missing
the bus (values of \(\delta\)) and variance in the walk time (values
of \(\sigma_W^2 = var(W)\)).  Because they appear similarly in the
equations, we can also consider these values to be changes in the
interval of the bus arrival \(I\) and the variance of the bus’ arrival
time \(\sigma_B^2=var(B)\) respectively.&lt;/p&gt;

&lt;div&gt;


    &lt;figure&gt;
        &lt;center&gt;&lt;img src=&quot;/res/bus/howearly.png&quot; /&gt;&lt;/center&gt;
        &lt;figcaption class=&quot;imagecaption&quot;&gt;&lt;p&gt;Across all
reasonable values, the optimal time to plan to arrive is between 3.5
and 8 minutes early.&lt;/p&gt;
&lt;/figcaption&gt;
    &lt;/figure&gt;

&lt;/div&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;So to summarize:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;If it always takes you approximately the same amount of time to walk
to the bus stop, plan to be there 3-4 minutes early on your commute
home, or 5-6 minutes early if it’s the last bus before an important
meeting.&lt;/li&gt;
  &lt;li&gt;If you have a long walk to the bus stop which can vary in duration,
plan to arrive at the bus stop 4-5 minutes early if you take the bus
every day, or around 7-8 minutes early if you need to be somewhere
for a special event.&lt;/li&gt;
  &lt;li&gt;These estimations assume that you know how long it takes you on
average to walk to the bus stop.  As we saw previously, if you need
to be somewhere at a certain time, arriving a minute early is much
better than arriving a minute late.  If you don’t need to be
somewhere, just make your best guess.&lt;/li&gt;
  &lt;li&gt;The best way to reduce waiting time is to decrease variability.&lt;/li&gt;
  &lt;li&gt;These estimates also assume that the interval between buses is
sufficiently large.  If it is small, as in the case of a subway,
there are
&lt;a href=&quot;http://erikbern.com/2016/07/09/waiting-time-math.html&quot;&gt;different factors&lt;/a&gt;
that govern the time you spend waiting.&lt;/li&gt;
  &lt;li&gt;This analysis focuses on buses with an expected arrival time, not
with a scheduled arrival time.  When buses have schedules, they will
usually wait at the stop if they arrive early.  This situation would
require a different analysis than what was performed here.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Code/Data:&lt;/h3&gt;

&lt;ul&gt;

    &lt;li&gt;&lt;a href=&quot;/res/bus/2016-07-28-data.csv&quot;&gt;Data&lt;/a&gt;&lt;/li&gt;

    &lt;li&gt;&lt;a href=&quot;/res/bus/getyalebus.py&quot;&gt;Data collection script&lt;/a&gt;&lt;/li&gt;

    &lt;li&gt;&lt;a href=&quot;/res/bus/analyzebus.py&quot;&gt;Data analysis script&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;

</description>
        <pubDate>Mon, 01 Aug 2016 00:00:00 +0000</pubDate>
        <link>/2016/08/01/when-should-you-leave-for-the-bus.html</link>
        <guid isPermaLink="true">/2016/08/01/when-should-you-leave-for-the-bus.html</guid>
        
        <category>data</category>
        
        <category>bus</category>
        
        <category>stats</category>
        
        <category>modeling</category>
        
        
        <category>Data</category>
        
      </item>
    
  </channel>
</rss>
