<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Math, Cryptography, Quantum on kenji.blog</title><link>http://kenji.blog/en/categories/math-cryptography-quantum/</link><description>Recent content in Math, Cryptography, Quantum on kenji.blog</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>kenjinote</copyright><lastBuildDate>Tue, 15 Jul 2025 18:03:03 +0900</lastBuildDate><atom:link href="http://kenji.blog/en/categories/math-cryptography-quantum/index.xml" rel="self" type="application/rss+xml"/><item><title>Collatz Conjecture</title><link>http://kenji.blog/en/p/%E3%82%B3%E3%83%A9%E3%83%83%E3%83%84%E4%BA%88%E6%83%B3/</link><pubDate>Tue, 15 Jul 2025 18:03:03 +0900</pubDate><guid>http://kenji.blog/en/p/%E3%82%B3%E3%83%A9%E3%83%83%E3%83%84%E4%BA%88%E6%83%B3/</guid><description>&lt;img src="http://kenji.blog/p/%E3%82%B3%E3%83%A9%E3%83%83%E3%83%84%E4%BA%88%E6%83%B3/img.png" alt="Featured image of post Collatz Conjecture" />&lt;h1 id="is-it-true-that-any-number-eventually-becomes-1--playing-with-the-collatz-conjecture">Is it true that &amp;ldquo;any number eventually becomes 1&amp;rdquo;? ── Playing with the Collatz Conjecture
&lt;/h1>&lt;p>Hello! I&amp;rsquo;m kenji.&lt;/p>
&lt;p>Suddenly, but if you hear &amp;ldquo;a rule where any number eventually becomes 1&amp;rdquo;,
isn&amp;rsquo;t it a bit mysterious?&lt;/p>
&lt;blockquote>
&lt;p>For example, 19, or 87, or even 1000000.
If you tweak the numbers according to appropriate rules, for some reason it converges to &amp;ldquo;1&amp;rdquo; at the end.&lt;/p>
&lt;/blockquote>
&lt;p>Such a dream-like story is the &lt;strong>Collatz Conjecture&lt;/strong>.&lt;/p>
&lt;hr>
&lt;h2 id="what-is-the-collatz-conjecture-anyway">What is the Collatz Conjecture anyway?
&lt;/h2>&lt;p>First, let me introduce the rules.&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Start: Choose any &lt;strong>positive integer&lt;/strong>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Operation:&lt;/p>
&lt;ul>
&lt;li>If it is even → Halve it (n → n / 2)&lt;/li>
&lt;li>If it is odd → Triple it and add 1 (n → 3n + 1)&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;p>If you repeat this forever, the conjecture says that &lt;strong>any number will eventually reach 1&lt;/strong>.&lt;/p>
&lt;p>For example, starting from &lt;code>6&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">6 → 3 → 10 → 5 → 16 → 8 → 4 → 2 → 1
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>It properly became &amp;ldquo;1&amp;rdquo;. Welcome back!&lt;/p>
&lt;hr>
&lt;h2 id="lets-do-it-in-code-collatz-in-python">Let&amp;rsquo;s do it in code: Collatz in Python
&lt;/h2>&lt;p>Now, in times like this, it&amp;rsquo;s faster to try it in code!
Let&amp;rsquo;s output the &amp;ldquo;Collatz sequence&amp;rdquo; in Python.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="k">def&lt;/span> &lt;span class="nf">collatz&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">n&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">steps&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="n">n&lt;/span>&lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">while&lt;/span> &lt;span class="n">n&lt;/span> &lt;span class="o">!=&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="n">n&lt;/span> &lt;span class="o">%&lt;/span> &lt;span class="mi">2&lt;/span> &lt;span class="o">==&lt;/span> &lt;span class="mi">0&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">n&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">n&lt;/span> &lt;span class="o">//&lt;/span> &lt;span class="mi">2&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">else&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">n&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="mi">3&lt;/span> &lt;span class="o">*&lt;/span> &lt;span class="n">n&lt;/span> &lt;span class="o">+&lt;/span> &lt;span class="mi">1&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">steps&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">append&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">n&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">steps&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Example: Starting from 19&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">print&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">collatz&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">19&lt;/span>&lt;span class="p">))&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>When you execute it:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">[19, 58, 29, 88, 44, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>It splendidly reaches 1.
Even though it takes quite a detour, it firmly reaches the goal at the end!&lt;/p>
&lt;p>By the way, even if you start from 29, it reaches 1 in the same way.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="nb">print&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">collatz&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">29&lt;/span>&lt;span class="p">))&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>When you execute it:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">[27, 82, 41, 124, 62, 31, 94, 47, 142, 71, 214, 107, 322, 161, 484, 242,
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">121, 364, 182, 91, 274, 137, 412, 206, 103, 310, 155, 466, 233, 700, 350,
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">175, 526, 263, 790, 395, 1186, 593, 1780, 890, 445, 1336, 668, 334, 167,
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">502, 251, 754, 377, 1132, 566, 283, 850, 425, 1276, 638, 319, 958, 479,
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">1438, 719, 2158, 1079, 3238, 1619, 4858, 2429, 7288, 3644, 1822, 911,
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">2734, 1367, 4102, 2051, 6154, 3077, 9232, 4616, 2308, 1154, 577, 1732,
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">866, 433, 1300, 650, 325, 976, 488, 244, 122, 61, 184, 92, 46, 23, 70, 35,
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1]
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>Surprisingly, it takes 111 steps!&lt;/p>
&lt;p>Moreover, there are scenes where it balloons to over 9000 along the way.
It&amp;rsquo;s a pattern that takes a huge detour before reaching the goal.&lt;/p>
&lt;hr>
&lt;h2 id="so-whats-amazing-about-it-in-the-end">So, what&amp;rsquo;s amazing about it in the end?
&lt;/h2>&lt;p>What&amp;rsquo;s amazing about this conjecture is,&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>Even though it hasn&amp;rsquo;t been proven, it seems to become 1 no matter what number you use&lt;/strong>&lt;/p>
&lt;/blockquote>
&lt;p>That&amp;rsquo;s the point.&lt;/p>
&lt;p>Eh? Then, what about 1 trillion, or 10 quadrillion&amp;hellip;?&lt;/p>
&lt;p>If you thought that, you are sharp.
Actually, it has been verified up to about &amp;ldquo;2 to the 68th power&amp;rdquo; using computers,
and &lt;strong>all have reached 1&lt;/strong>. Unbelievable&amp;hellip;&lt;/p>
&lt;p>But, &lt;strong>it hasn&amp;rsquo;t been theoretically proven that &amp;ldquo;it always happens&amp;rdquo;&lt;/strong>.
This is what they call an &amp;ldquo;unsolved problem&amp;rdquo; in the world of mathematics.&lt;/p>
&lt;hr>
&lt;h2 id="who-is-mr-collatz">Who is Mr. Collatz?
&lt;/h2>&lt;p>So, reading this far, you might wonder &amp;ldquo;who is Collatz anyway?&amp;rdquo;.
Let me introduce him properly!&lt;/p>
&lt;ul>
&lt;li>Name: &lt;strong>Lothar Collatz&lt;/strong>&lt;/li>
&lt;li>Nationality: Germany&lt;/li>
&lt;li>Year of birth: 1910 - 1990&lt;/li>
&lt;li>Title: Mathematician (Active in the fields of functional analysis and number theory)&lt;/li>
&lt;/ul>
&lt;p>He proposed this conjecture in 1937,
and since then, for over 80 years, &lt;strong>no one has been able to prove or disprove it&lt;/strong>.&lt;/p>
&lt;p>By the way, this problem is so simple yet so deep that
even Paul Erdős (a super famous mathematician) is said to have said this:&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;Mathematics may not be ready for such problems.&amp;rdquo;&lt;/p>
&lt;/blockquote>
&lt;p>In other words, the theory that human mathematics hasn&amp;rsquo;t caught up with this mystery yet&amp;hellip;&lt;/p>
&lt;hr>
&lt;h2 id="no-complex-math-formulas-are-necessary">No &amp;ldquo;complex math formulas&amp;rdquo; are necessary
&lt;/h2>&lt;p>The good thing about the Collatz Conjecture is that &lt;strong>anyone can play with it&lt;/strong>.&lt;/p>
&lt;p>You can do it if you have paper and pen.
If you write code in Python, you can test it automatically.
And yet, &lt;strong>cutting-edge mathematicians are seriously challenging it&lt;/strong>.&lt;/p>
&lt;p>Doesn&amp;rsquo;t it make you excited?&lt;/p>
&lt;hr>
&lt;h2 id="bonus-code-to-test-it-all-at-once">Bonus: Code to test it all at once
&lt;/h2>&lt;p>I&amp;rsquo;ll also include code to test various numbers all at once.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="k">for&lt;/span> &lt;span class="n">n&lt;/span> &lt;span class="ow">in&lt;/span> &lt;span class="nb">range&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="mi">21&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">steps&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">collatz&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">n&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nb">print&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="sa">f&lt;/span>&lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="n">n&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s2">: &lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="n">steps&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s2"> (Steps: &lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="nb">len&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">steps&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s2">)&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>This outputs the Collatz sequences from &amp;ldquo;1 to 20&amp;rdquo; all at once.&lt;/p>
&lt;hr>
&lt;h2 id="conclusion-this-world-is-indeed-mysterious">Conclusion: This world is indeed mysterious
&lt;/h2>&lt;p>So, that&amp;rsquo;s the Collatz Conjecture.&lt;/p>
&lt;ul>
&lt;li>Even though it&amp;rsquo;s super simple&lt;/li>
&lt;li>No one can prove it&lt;/li>
&lt;li>It&amp;rsquo;s a huge problem in the math community&lt;/li>
&lt;/ul>
&lt;p>It&amp;rsquo;s an existence like a cluster of mysteries.&lt;/p>
&lt;p>Even programming beginners can try it, so please definitely play with it~!&lt;/p>
&lt;hr>
&lt;h2 id="recommended-links-for-interested-people">Recommended Links (For interested people)
&lt;/h2>&lt;ul>
&lt;li>&lt;a class="link" href="https://en.wikipedia.org/wiki/Collatz_conjecture" target="_blank" rel="noopener"
>Wikipedia: Collatz conjecture&lt;/a>&lt;/li>
&lt;li>&lt;a class="link" href="https://arxiv.org/abs/1909.03562" target="_blank" rel="noopener"
>Terence Tao Paper (English)&lt;/a>&lt;/li>
&lt;li>It&amp;rsquo;s also fun to try making a visualizer in Python! (I&amp;rsquo;ll make one if there&amp;rsquo;s a request)&lt;/li>
&lt;/ul>
&lt;hr>
&lt;p>If you want to know more about this kind of &amp;ldquo;mysterious math x programming&amp;rdquo; topics,
please feel free to request &amp;ldquo;tell me more&amp;rdquo;.
Eventually, I&amp;rsquo;ll introduce various things like the Riemann hypothesis and prime numbers!&lt;/p>
&lt;hr>
&lt;p>📮 The End!&lt;/p>
&lt;hr></description></item><item><title>What is the Birthday Paradox?</title><link>http://kenji.blog/en/p/%E3%83%90%E3%83%BC%E3%82%B9%E3%83%87%E3%82%A4%E3%83%91%E3%83%A9%E3%83%89%E3%83%83%E3%82%AF%E3%82%B9%E3%81%A8%E3%81%AF/</link><pubDate>Tue, 02 Apr 2024 01:20:50 +0900</pubDate><guid>http://kenji.blog/en/p/%E3%83%90%E3%83%BC%E3%82%B9%E3%83%87%E3%82%A4%E3%83%91%E3%83%A9%E3%83%89%E3%83%83%E3%82%AF%E3%82%B9%E3%81%A8%E3%81%AF/</guid><description>&lt;img src="http://kenji.blog/p/%E3%83%90%E3%83%BC%E3%82%B9%E3%83%87%E3%82%A4%E3%83%91%E3%83%A9%E3%83%89%E3%83%83%E3%82%AF%E3%82%B9%E3%81%A8%E3%81%AF/img.png" alt="Featured image of post What is the Birthday Paradox?" />&lt;h2 id="do-you-know-the-birthday-paradox">Do you know the Birthday Paradox?
&lt;/h2>&lt;p>Let me tell you a slightly mysterious story.
How many people do you think need to gather for the &amp;ldquo;probability of people having the same birthday&amp;rdquo; to become high?&lt;/p>
&lt;p>For example, a year has 365 days, so when you&amp;rsquo;re told &amp;ldquo;if 23 people gather, the probability of someone sharing a birthday is over 50%&amp;rdquo;&amp;hellip; it feels somewhat counterintuitive, right?&lt;/p>
&lt;p>But this is &lt;strong>actually over 50%.&lt;/strong>&lt;/p>
&lt;hr>
&lt;h2 id="why-does-this-happen">Why does this happen?
&lt;/h2>&lt;p>This phenomenon is called the &amp;ldquo;Birthday Paradox&amp;rdquo;.
Its name contains &amp;ldquo;paradox&amp;rdquo;, but there is a proper mathematical reason for it.&lt;/p>
&lt;p>When the number of people is &amp;ldquo;n&amp;rdquo;, the &lt;strong>probability that no one shares a birthday&lt;/strong> can be calculated with the following formula:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">P(No one shares) = 365/365 × 364/365 × 363/365 × ... × (365 - n + 1)/365
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>By subtracting that from 1, you get the &amp;ldquo;probability of sharing a birthday with someone&amp;rdquo;.&lt;/p>
&lt;hr>
&lt;h2 id="looking-at-the-results">Looking at the results&amp;hellip;
&lt;/h2>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Number of People&lt;/th>
&lt;th>Probability of people having the same birthday&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>10 people&lt;/td>
&lt;td>Approx. 11.7%&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>20 people&lt;/td>
&lt;td>Approx. 41.1%&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>23 people&lt;/td>
&lt;td>&lt;strong>Approx. 50.7% (Focus here!)&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>30 people&lt;/td>
&lt;td>Approx. 70.6%&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>70 people&lt;/td>
&lt;td>&lt;strong>A whopping approx. 99.9%!&lt;/strong>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>In other words, with just &lt;strong>23 people&lt;/strong>, there is a more than half chance that someone will share a birthday.
It seems like this could apply quite often in a school class or a workplace meeting, right?&lt;/p>
&lt;hr>
&lt;h2 id="conclusion-the-gap-between-intuition-and-mathematics-is-interesting">Conclusion: The gap between intuition and mathematics is interesting
&lt;/h2>&lt;p>The &amp;ldquo;Birthday Paradox&amp;rdquo; is an interesting example where our intuition and actual mathematical probabilities diverge.
Knowing this kind of story might make for lively small talk or a fun quiz!&lt;/p>
&lt;hr>
&lt;h2 id="reference-links">Reference Links
&lt;/h2>&lt;ul>
&lt;li>&lt;a class="link" href="https://en.wikipedia.org/wiki/Birthday_problem" target="_blank" rel="noopener"
>Birthday problem (Wikipedia)&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>[Complete Mathematical Guide] Why the Ultimate Classical 'GNFS' Loses to Quantum Algorithms: The Paradigm Shift in Prime Factorization</title><link>http://kenji.blog/en/p/gnfs-to-shors-algorithm-math-deepdive/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>http://kenji.blog/en/p/gnfs-to-shors-algorithm-math-deepdive/</guid><description>&lt;img src="http://kenji.blog/p/gnfs-to-shors-algorithm-math-deepdive/quantum_vs_gnfs_eyecatch_1788616101508.jpg" alt="Featured image of post [Complete Mathematical Guide] Why the Ultimate Classical 'GNFS' Loses to Quantum Algorithms: The Paradigm Shift in Prime Factorization" />&lt;p>Information security in the modern internet society is protected by public-key cryptography, such as RSA cryptography. The basis for the security of RSA relies on the fact that &lt;strong>&amp;ldquo;the prime factorization of huge composite numbers is computationally extremely difficult.&amp;rdquo;&lt;/strong>&lt;/p>
&lt;p>In this article, we will unravel the mathematical mechanism of the &lt;strong>&amp;ldquo;General Number Field Sieve&amp;rdquo;&lt;/strong> (GNFS), which is the most powerful prime factorization algorithm for classical computers. We will also dive deeply into why it is completely defeated by &lt;strong>&amp;ldquo;Shor&amp;rsquo;s Algorithm,&amp;rdquo;&lt;/strong> discovered by Peter Shor, exploring this paradigm shift thoroughly with mathematical formulas and conceptual diagrams.&lt;/p>
&lt;hr>
&lt;h2 id="1-the-approach-to-prime-factorization-in-classical-computing-evolution-from-fermats-factorization-method">1. The Approach to Prime Factorization in Classical Computing: Evolution from Fermat&amp;rsquo;s Factorization Method
&lt;/h2>&lt;p>The prime factorization problem is the problem of finding prime numbers $p$ and $q$ such that $N = p \times q$ for a given composite number $N$.&lt;/p>
&lt;p>The basic idea reduces to finding non-trivial $x$ and $y$ that satisfy the following congruence:&lt;/p>
$$ x^2 \equiv y^2 \pmod N $$
&lt;p>By rearranging this, we get:&lt;/p>
$$ x^2 - y^2 \equiv 0 \pmod N $$
$$ (x - y)(x + y) \equiv 0 \pmod N $$
&lt;p>Here, if $x \not\equiv \pm y \pmod N$, we can obtain a non-trivial factor of $N$ by calculating $\gcd(x-y, N)$ or $\gcd(x+y, N)$. This fact is the foundation of modern prime factorization algorithms like GNFS.&lt;/p>
&lt;hr>
&lt;h2 id="2-the-ultimate-classical-algorithm-the-depths-of-the-general-number-field-sieve-gnfs">2. The Ultimate Classical Algorithm: The Depths of the &amp;ldquo;General Number Field Sieve&amp;rdquo; (GNFS)
&lt;/h2>&lt;p>&lt;strong>&amp;ldquo;GNFS&amp;rdquo;&lt;/strong> is the fastest known prime factorization algorithm for classical computers today. Its time complexity requires sub-exponential time.&lt;/p>
&lt;h3 id="complexity-of-gnfs">Complexity of GNFS
&lt;/h3>&lt;p>Letting the number of digits (bits) of the number $N$ be $b = \log_2 N$, the computational complexity of GNFS is expressed as follows:&lt;/p>
$$ O\left( \exp \left( \left(\frac{64}{9} b\right)^{1/3} (\log b)^{2/3} \right) \right) $$
&lt;p>As can be seen from this formula, the computational complexity is not polynomial time, but &lt;strong>&amp;ldquo;sub-exponential time,&amp;rdquo;&lt;/strong> which is slightly slower than exponential time. Still, as the number of digits increases, the computation time grows astronomically.&lt;/p>
&lt;h3 id="mathematical-mechanism-of-gnfs">Mathematical Mechanism of GNFS
&lt;/h3>&lt;p>GNFS consists broadly of four steps:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Polynomial Selection&lt;/strong>&lt;/li>
&lt;li>&lt;strong>Sieving&lt;/strong>&lt;/li>
&lt;li>&lt;strong>Matrix Reduction&lt;/strong>&lt;/li>
&lt;li>&lt;strong>Square Root&lt;/strong>&lt;/li>
&lt;/ol>
&lt;h4 id="21-polynomial-selection-and-number-fields">2.1. Polynomial Selection and Number Fields
&lt;/h4>&lt;p>First, we select irreducible polynomials $f(x)$ and $g(x)$ with integer coefficients. These are set to have a common root $m$ modulo $N$. That is,&lt;/p>
$$ f(m) \equiv 0 \pmod N $$
$$ g(m) \equiv 0 \pmod N $$
&lt;p>Usually, $g(x)$ is chosen as a linear polynomial $g(x) = x - m$. If we let $\alpha$ be a root of $f(x)$, a &lt;strong>&amp;ldquo;Number Field&amp;rdquo;&lt;/strong> $\mathbb{Q}(\alpha)$ is constructed. We compare operations in the ring of $\mathbb{Q}(\alpha)$ and operations in the normal integer ring $\mathbb{Z}$ through the homomorphism $\phi: \alpha \mapsto m$.&lt;/p>
&lt;h4 id="22-sieving">2.2. Sieving
&lt;/h4>&lt;p>Next, we search for a massive number of coprime integer pairs $(a, b)$. The goal is to find pairs such that the following two values are both &lt;strong>&amp;ldquo;B-smooth&amp;rdquo;&lt;/strong> (composed only of relatively small prime factors):&lt;/p>
&lt;ol>
&lt;li>$a - bm$ (value over the integer ring)&lt;/li>
&lt;li>$b^d f(a/b)$ (corresponding to the norm $N(a - b\alpha)$ over the number field)&lt;/li>
&lt;/ol>
&lt;p>Here, a high-speed search method called a &lt;strong>&amp;ldquo;Sieve&amp;rdquo;&lt;/strong> is used. This efficiently extracts $(a, b)$ pairs that satisfy the conditions from a vast number of candidates.&lt;/p>
&lt;h4 id="23-linear-algebra-over-gf2-matrix-reduction">2.3. Linear Algebra over GF(2) (Matrix Reduction)
&lt;/h4>&lt;p>From the collected pairs $(a, b)$, we construct exponent vectors and find the left null space of a massive sparse matrix over $\mathbb{F}_2$ (the field with only elements 0 and 1).&lt;/p>
&lt;p>We find a vector $v$ as a solution so that the relations $ \prod (a_i - b_i m) $ and $ \prod (a_i - b_i \alpha) $ both become squares. This is nothing but solving a system of linear equations:&lt;/p>
$$ M \mathbf{x} \equiv \mathbf{0} \pmod 2 $$
&lt;p>Advanced numerical algorithms such as the Block Lanczos Algorithm and the Block Wiedemann Algorithm are utilized here.&lt;/p>
&lt;h4 id="24-square-root">2.4. Square Root
&lt;/h4>&lt;p>Finally, we take square roots in both the number field and the integer ring to derive the relation $x^2 \equiv y^2 \pmod N$. Then, we calculate $\gcd(x-y, N)$ to obtain the factor.&lt;/p>
&lt;hr>
&lt;h2 id="3-the-breakthrough-by-quantum-computing-shors-algorithm">3. The Breakthrough by Quantum Computing: &amp;ldquo;Shor&amp;rsquo;s Algorithm&amp;rdquo;
&lt;/h2>&lt;p>While GNFS requires sub-exponential time, &lt;strong>&amp;ldquo;Shor&amp;rsquo;s Algorithm,&amp;rdquo;&lt;/strong> published by Peter Shor in 1994, can solve this problem in &lt;strong>&amp;ldquo;polynomial time&amp;rdquo;&lt;/strong> by using a quantum computer.&lt;/p>
&lt;h3 id="complexity-of-shors-algorithm">Complexity of Shor&amp;rsquo;s Algorithm
&lt;/h3>&lt;p>When the number of qubits is $O(\log N)$, the time complexity is as follows:&lt;/p>
$$ O((\log N)^3) $$
&lt;p>This means it does not cause an exponential explosion with respect to the number of bits. This is an astonishing result: even for huge composite numbers where the complexity of &lt;strong>&amp;ldquo;classical computing&amp;rdquo;&lt;/strong> exceeds the lifespan of the universe, they can be cracked in hours to days with &lt;strong>&amp;ldquo;quantum computing.&amp;rdquo;&lt;/strong>&lt;/p>
&lt;h3 id="overview-of-shors-algorithm-reduction-to-the-period-finding-problem">Overview of Shor&amp;rsquo;s Algorithm: Reduction to the Period-Finding Problem
&lt;/h3>&lt;p>Shor&amp;rsquo;s algorithm cleverly reduces the prime factorization problem to a &lt;strong>&amp;ldquo;period-finding problem.&amp;rdquo;&lt;/strong>&lt;/p>
&lt;ol>
&lt;li>Choose a random integer $a$ coprime to $N$ ($1 &lt; a &lt; N$).&lt;/li>
&lt;li>Define the function $f(x) = a^x \bmod N$.&lt;/li>
&lt;li>Find the period $r$ of $f(x)$, i.e., the smallest positive integer $r$ such that $a^r \equiv 1 \pmod N$.&lt;/li>
&lt;li>If $r$ is even, check if $a^{r/2} \not\equiv -1 \pmod N$, and calculate $\gcd(a^{r/2} \pm 1, N)$ to obtain a prime factor.&lt;/li>
&lt;/ol>
&lt;p>&lt;strong>&amp;ldquo;Finding the period $r$&amp;rdquo;&lt;/strong> in step 3 is the bottleneck that requires exponential time on classical computers, but quantum computers solve this instantly using &lt;strong>&amp;ldquo;quantum superposition&amp;rdquo;&lt;/strong> and the &lt;strong>&amp;ldquo;Quantum Fourier Transform&amp;rdquo;&lt;/strong> (QFT).&lt;/p>
&lt;hr>
&lt;h2 id="4-quantum-fourier-transform-qft-and-period-extraction">4. Quantum Fourier Transform (QFT) and Period Extraction
&lt;/h2>&lt;p>Let&amp;rsquo;s look in detail with formulas at the manipulation of quantum states, which is the core of Shor&amp;rsquo;s algorithm.&lt;/p>
&lt;h3 id="41-generation-of-quantum-superposition">4.1. Generation of Quantum Superposition
&lt;/h3>&lt;p>First, we prepare two quantum registers. Register 1 holds a superposition state of inputs $x$, and Register 2 holds the computation result $f(x)$. We apply the Hadamard Transform to the initial state $|0\rangle |0\rangle$ to create a superposition of all possible $x$.&lt;/p>
$$ |\psi_1\rangle = \frac{1}{\sqrt{Q}} \sum_{x=0}^{Q-1} |x\rangle |0\rangle $$
&lt;p>
(Here $Q$ is a power of 2 satisfying $N^2 \le Q &lt; 2N^2$)&lt;/p>
&lt;p>Next, we use a quantum oracle $U_f$ to compute $f(x) = a^x \bmod N$ and store it in Register 2.&lt;/p>
$$ |\psi_2\rangle = U_f |\psi_1\rangle = \frac{1}{\sqrt{Q}} \sum_{x=0}^{Q-1} |x\rangle |a^x \bmod N\rangle $$
&lt;p>Let&amp;rsquo;s assume here that we measure Register 2 (in reality, the mathematical structure is the same even without measurement). If a value $y = a^{x_0} \bmod N$ is observed, the state of Register 1 collapses into a superposition of all $x$ such that $f(x) = y$. Letting the period be $r$, such $x$ are $x_0, x_0 + r, x_0 + 2r, \dots$&lt;/p>
$$ |\psi_3\rangle = \frac{1}{\sqrt{M}} \sum_{k=0}^{M-1} |x_0 + kr\rangle $$
&lt;p>
(Here $M \approx Q/r$ is the number of terms)&lt;/p>
&lt;p>This state inherently contains information about the period $r$, but direct measurement will only yield a random $x_0 + kr$, and the period $r$ remains unknown. This is where QFT comes in.&lt;/p>
&lt;h3 id="42-application-of-the-quantum-fourier-transform-qft">4.2. Application of the Quantum Fourier Transform (QFT)
&lt;/h3>&lt;p>QFT is an operation that performs a discrete Fourier transform on the amplitudes of quantum states. The action of QFT on state $|x\rangle$ is defined as follows:&lt;/p>
$$ \text{QFT} |x\rangle = \frac{1}{\sqrt{Q}} \sum_{y=0}^{Q-1} e^{2\pi i \frac{xy}{Q}} |y\rangle $$
&lt;p>When this is applied to $|\psi_3\rangle$, phase interference (quantum interference) occurs.&lt;/p>
$$ |\psi_4\rangle = \text{QFT} |\psi_3\rangle = \frac{1}{\sqrt{MQ}} \sum_{y=0}^{Q-1} \sum_{k=0}^{M-1} e^{2\pi i \frac{(x_0 + kr)y}{Q}} |y\rangle $$
&lt;p>Expanding the sum in this equation reveals the part:&lt;/p>
$$ \sum_{k=0}^{M-1} e^{2\pi i \frac{kry}{Q}} $$
&lt;p>This sum of a geometric series reinforces each other (Constructive Interference) only when $ry/Q$ is close to an integer, and cancels each other out (Destructive Interference) otherwise.&lt;/p>
&lt;p>Therefore, the state $|y\rangle$ measured with high probability will be an integer $y$ that satisfies the condition:&lt;/p>
$$ \frac{y}{Q} \approx \frac{c}{r} $$
&lt;p>(where $c$ is some integer).&lt;/p>
&lt;h3 id="43-identifying-the-period-via-continued-fraction-expansion">4.3. Identifying the Period via Continued Fraction Expansion
&lt;/h3>&lt;p>After obtaining $y$ through measurement, we perform a &lt;strong>&amp;ldquo;Continued Fraction Expansion&amp;rdquo;&lt;/strong> of $y/Q$ using a classical computer. This allows us to calculate the convergent fraction $c/r$ of $y/Q$, and extract candidates for the period $r$ from the denominator with high efficiency.&lt;/p>
&lt;hr>
&lt;h2 id="5-comparison-of-conceptual-models-and-the-paradigm-shift">5. Comparison of Conceptual Models and the Paradigm Shift
&lt;/h2>&lt;p>To intuitively understand the difference between GNFS and Shor&amp;rsquo;s algorithm, we present a conceptual diagram using Mermaid notation.&lt;/p>
&lt;h3 id="conceptual-diagram-of-shors-algorithm-via-quantum-circuit">Conceptual Diagram of Shor&amp;rsquo;s Algorithm via Quantum Circuit
&lt;/h3>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">graph TD
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> A[Initial State: 0...0] --&amp;gt; B[Superposition of all states via Hadamard Transform]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> B --&amp;gt; C[Modular exponentiation a^x mod N]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> C --&amp;gt;|Quantum Entanglement| D[Collapse to a state with periodicity]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> D --&amp;gt; E[Quantum Fourier Transform QFT]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> E --&amp;gt;|Probability amplification via interference| F[Measurement: Obtain y]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> F --&amp;gt; G[Classical processing: Continued Fraction Expansion]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> G --&amp;gt; H[Discovery of period r]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> H --&amp;gt; I[Calculate prime factors of N]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> style A fill:#f9f,stroke:#333,stroke-width:2px
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> style E fill:#bbf,stroke:#333,stroke-width:2px
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> style I fill:#bfb,stroke:#333,stroke-width:2px
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="the-essence-of-the-paradigm-shift">The Essence of the Paradigm Shift
&lt;/h3>&lt;p>GNFS takes the approach of &lt;strong>&amp;ldquo;searching for relations within a mathematical space (number field).&amp;rdquo;&lt;/strong> However, since the search space expands exponentially with the number of digits, it becomes virtually unsolvable for classical computer capabilities (even including parallelization) when the key length exceeds 2048 bits.&lt;/p>
&lt;p>On the other hand, Shor&amp;rsquo;s algorithm utilizes the &lt;strong>&amp;ldquo;wave nature of quantum interference.&amp;rdquo;&lt;/strong> It simultaneously evaluates all computation paths in a superposition state, uses QFT to cancel out (destructively interfere) unnecessary answers, and amplifies (constructively interferes) only the probability amplitude of the period that is the correct answer. Through this, instead of searching space, it realizes a completely different dimensional approach of &lt;strong>&amp;ldquo;making the correct answer itself surface.&amp;rdquo;&lt;/strong>&lt;/p>
&lt;h2 id="6-summary">6. Summary
&lt;/h2>&lt;p>In this article, we deeply compared the mathematical backgrounds and algorithmic structures of &lt;strong>&amp;ldquo;GNFS,&amp;rdquo;&lt;/strong> the pinnacle of classical limits, and &lt;strong>&amp;ldquo;Shor&amp;rsquo;s Algorithm,&amp;rdquo;&lt;/strong> which demonstrates the power of quantum computing.&lt;/p>
&lt;p>While GNFS drove computational complexity down to sub-exponential time by employing mathematical tricks such as polynomial selection and massive matrix calculations, Shor&amp;rsquo;s algorithm fused the fundamental principles of quantum mechanics—superposition and interference—with a mathematical tool (QFT), achieving a breakthrough to polynomial time in one stroke.&lt;/p>
&lt;p>Currently, Fault-Tolerant Quantum Computers (FTQC) capable of executing Shor&amp;rsquo;s algorithm at a practical scale (thousands of qubits) do not exist. However, the very existence of this mathematical and theoretical paradigm shift is the primary reason why the transition to Post-Quantum Cryptography (PQC) is urgently being accelerated worldwide today.&lt;/p></description></item></channel></rss>