<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Eli Bendersky's website - Math</title><link href="https://eli.thegreenplace.net/" rel="alternate"/><link href="https://eli.thegreenplace.net/feeds/math.atom.xml" rel="self"/><id>https://eli.thegreenplace.net/</id><updated>2026-10-18T01:28:10.973164-07:00</updated><entry><title>Notes on the complex roots of unity</title><link href="https://eli.thegreenplace.net/2026/notes-on-the-complex-roots-of-unity/" rel="alternate"/><published>2026-10-17T18:18:00-07:00</published><updated>2026-10-18T01:18:06.134012-07:00</updated><author><name>Eli Bendersky</name></author><id>tag:eli.thegreenplace.net,2026-10-17:/2026/notes-on-the-complex-roots-of-unity/</id><summary type="html">&lt;link rel="stylesheet" href="https://eli.thegreenplace.net/demos/rootsunity/rootsunity.css"&gt;&lt;p&gt;One of the most wonderful aspects of math is how deep we can get by
studying seemingly trivial questions. Consider the roots of unity, where
&amp;quot;unity&amp;quot; simply means the number 1.&lt;/p&gt;
&lt;div class="section" id="basics-roots-of-unity-for-real-numbers"&gt;
&lt;h2&gt;Basics: roots of unity for real numbers&lt;/h2&gt;
&lt;p&gt;Studying the roots of unity usually begins in middle school: what is …&lt;/p&gt;&lt;/div&gt;</summary><content type="html">&lt;link rel="stylesheet" href="https://eli.thegreenplace.net/demos/rootsunity/rootsunity.css"&gt;&lt;p&gt;One of the most wonderful aspects of math is how deep we can get by
studying seemingly trivial questions. Consider the roots of unity, where
&amp;quot;unity&amp;quot; simply means the number 1.&lt;/p&gt;
&lt;div class="section" id="basics-roots-of-unity-for-real-numbers"&gt;
&lt;h2&gt;Basics: roots of unity for real numbers&lt;/h2&gt;
&lt;p&gt;Studying the roots of unity usually begins in middle school: what is the
square root of 1? Equivalently, what are the solutions to this equation?&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/8363334cb309207f9e3589a8f3c0744d3e6d4f42.svg" style="height: 15px;" type="image/svg+xml"&gt;\[x^2=1\]&lt;/object&gt;
&lt;p&gt;Well, there are two answers: 1 and -1.&lt;/p&gt;
&lt;p&gt;Similarly, we can ask the question for higher roots; the third roots are
solutions to the equation:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/27d93743982aa6ccef3b9a7b2418b0c7a79e3d29.svg" style="height: 15px;" type="image/svg+xml"&gt;\[x^3=1\]&lt;/object&gt;
&lt;p&gt;And so on. When we’re only dealing with real numbers, that’s pretty much
the whole story. For odd-degree roots of 1, the only answer is 1; for
even-degree roots of 1, the answer is either 1 or -1.&lt;/p&gt;
&lt;p&gt;When we extend our domain to the complex numbers, things become much
more interesting.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="basics-roots-of-unity-for-complex-numbers"&gt;
&lt;h2&gt;Basics: roots of unity for complex numbers&lt;/h2&gt;
&lt;p&gt;By the &lt;a class="reference external" href="https://en.wikipedia.org/wiki/Root_of_unity"&gt;formal
definition&lt;/a&gt;, a root of
unity is any complex number that yields 1 when raised to a positive
integer power &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt;.&lt;/p&gt;
&lt;p&gt;Rather than looking at &lt;em&gt;all&lt;/em&gt; the possible roots of 1, it’s often more
useful to discuss the roots for a specific given &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt;: complex
numbers &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/395df8f7c51f007019cb30201c49e884b46b92fa.svg" style="height: 8px;" type="image/svg+xml"&gt;z&lt;/object&gt; such that &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/233d47313af3fd672046cb090353570bea80d230.svg" style="height: 12px;" type="image/svg+xml"&gt;z^n=1&lt;/object&gt;.&lt;/p&gt;
&lt;p&gt;For example, let’s consider &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/2091fb295870e9f79b6d8a10d0f6046b091e6fe5.svg" style="height: 12px;" type="image/svg+xml"&gt;n=2&lt;/object&gt;. We’ve already seen that the
roots are 1 and -1; these are complex numbers with a zero imaginary
part.&lt;/p&gt;
&lt;p&gt;How about &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/a2ca9af97a38440d0a4a221a8fd15cafa7284225.svg" style="height: 12px;" type="image/svg+xml"&gt;n=4&lt;/object&gt;? There are four roots: 1, -1, &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/042dc4512fa3d391c5170cf3aa61e6a638f84342.svg" style="height: 12px;" type="image/svg+xml"&gt;i&lt;/object&gt; and
&lt;object class="valign-m1 latex-math" data="https://eli.thegreenplace.net/images/math/91edc8362c7518c1b0e4a9a4a7bcb6c02d8e498b.svg" style="height: 13px;" type="image/svg+xml"&gt;-i&lt;/object&gt;. For &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/c22759b5221a77ba818faab4152fe1744f5b85f9.svg" style="height: 12px;" type="image/svg+xml"&gt;n=3&lt;/object&gt;, the three roots &lt;a class="footnote-reference" href="#footnote-1" id="footnote-reference-1"&gt;[1]&lt;/a&gt; are 1,
&lt;object class="valign-m6 latex-math" data="https://eli.thegreenplace.net/images/math/11d2d18e93d4619aa83566480f2c0178a74722c3.svg" style="height: 24px;" type="image/svg+xml"&gt;\frac{-1+i\sqrt{3}}{2}&lt;/object&gt; and &lt;object class="valign-m6 latex-math" data="https://eli.thegreenplace.net/images/math/85dd4eb543bbf24234f229cc28b840dd255d1f7b.svg" style="height: 24px;" type="image/svg+xml"&gt;\frac{-1-i\sqrt{3}}{2}&lt;/object&gt;. It’s
easy enough to check that these indeed give 1 when raised to the third
power, but how do we calculate them in the first place?&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="calculating-complex-roots-using-polar-coordinates"&gt;
&lt;h2&gt;Calculating complex roots using polar coordinates&lt;/h2&gt;
&lt;p&gt;A complex number with magnitude 1 can be represented in polar
coordinates  &lt;a class="footnote-reference" href="#footnote-2" id="footnote-reference-2"&gt;[2]&lt;/a&gt; as &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/e5c489bf8019e99e5ff665dfe1ae42692eacb0e2.svg" style="height: 15px;" type="image/svg+xml"&gt;z=e^{i\theta}&lt;/object&gt;. If we raise &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/395df8f7c51f007019cb30201c49e884b46b92fa.svg" style="height: 8px;" type="image/svg+xml"&gt;z&lt;/object&gt; to the
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt;-th power, we get:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/c0dd5345c3031363506dcf8aa301ac4ab67be6bf.svg" style="height: 16px;" type="image/svg+xml"&gt;\[z^n=e^{in\theta}\]&lt;/object&gt;
&lt;p&gt;The magnitude of &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/f59bb9d629aebd3b22a4279036c4ab6f1edbd152.svg" style="height: 12px;" type="image/svg+xml"&gt;z^n&lt;/object&gt; is still 1, which is essential if we want
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/395df8f7c51f007019cb30201c49e884b46b92fa.svg" style="height: 8px;" type="image/svg+xml"&gt;z&lt;/object&gt; to be a &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt;-th root of unity. Let’s equate &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/f59bb9d629aebd3b22a4279036c4ab6f1edbd152.svg" style="height: 12px;" type="image/svg+xml"&gt;z^n&lt;/object&gt;
to 1:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/2cedb131b766e28ed575b4c639af1b801ac90bfa.svg" style="height: 16px;" type="image/svg+xml"&gt;\[z^n=e^{in\theta}=1\]&lt;/object&gt;
&lt;p&gt;To find the solutions to this equation, we’ll first want to represent 1
itself in polar coordinates. Let’s use another variable for the angle:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/d5bde7acd6025458eb1d8a39c0c5967bc635a1e4.svg" style="height: 16px;" type="image/svg+xml"&gt;\[1=e^{i\phi}\]&lt;/object&gt;
&lt;p&gt;What is the value of &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/411e715f9ab9075b0a30b4117d209921f0bc2389.svg" style="height: 16px;" type="image/svg+xml"&gt;\phi&lt;/object&gt;? Thinking about the unit circle,
&lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/411e715f9ab9075b0a30b4117d209921f0bc2389.svg" style="height: 16px;" type="image/svg+xml"&gt;\phi&lt;/object&gt; is any integer multiple of &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/0833718ca4569f36e84dbdc7742eaec65e49b150.svg" style="height: 11px;" type="image/svg+xml"&gt;2\pi&lt;/object&gt; - which we’ll
express as &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/0624aa8f4e0fe6434ed03ae36d5a18233194de3e.svg" style="height: 12px;" type="image/svg+xml"&gt;2\pi k&lt;/object&gt; for &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/35c4afd45b33a5abbbdee3e90d30778062b80d2f.svg" style="height: 16px;" type="image/svg+xml"&gt;k=0,1,2...&lt;/object&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/176fbff982dfdfcbb1bb832092fcb086cace2ba5.svg" style="height: 16px;" type="image/svg+xml"&gt;\[1=e^{i2\pi k}\]&lt;/object&gt;
&lt;p&gt;Back to &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/f59bb9d629aebd3b22a4279036c4ab6f1edbd152.svg" style="height: 12px;" type="image/svg+xml"&gt;z^n&lt;/object&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/c2c4a94f53dd9ca418a1422f7c65ae71d7780507.svg" style="height: 16px;" type="image/svg+xml"&gt;\[z^n=e^{in\theta}=e^{i2\pi k}\]&lt;/object&gt;
&lt;p&gt;Or:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/51eed9b79786275bef5ab6410ae63e10af891837.svg" style="height: 37px;" type="image/svg+xml"&gt;\[n\theta=2\pi k\quad\Rightarrow\quad \theta=\frac{2\pi k}{n}\]&lt;/object&gt;
&lt;p&gt;So the &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt;-th roots of unity are &lt;a class="footnote-reference" href="#footnote-3" id="footnote-reference-3"&gt;[3]&lt;/a&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/ea482e5c67ccc3df2f6f7c2e703b64ad51fcfdd1.svg" style="height: 29px;" type="image/svg+xml"&gt;\[\boxed{z_k=e^{i2\pi k/n}, \qquad k=0,1,\dots,n-1}\]&lt;/object&gt;
&lt;/div&gt;
&lt;div class="section" id="some-basic-examples"&gt;
&lt;h2&gt;Some basic examples&lt;/h2&gt;
&lt;p&gt;Let’s begin with &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/2091fb295870e9f79b6d8a10d0f6046b091e6fe5.svg" style="height: 12px;" type="image/svg+xml"&gt;n=2&lt;/object&gt;. We have the following roots:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/4f49ddbc4e3bd330b3625fb44755cb06a9db19c5.svg" style="height: 48px;" type="image/svg+xml"&gt;\[\begin{aligned}
    z_0&amp;amp;=e^{i2\pi 0/2}=e^0=1\\
    z_1&amp;amp;=e^{i2\pi 1/2}=e^{i\pi}=\cos\pi+i\sin\pi=-1
\end{aligned}\]&lt;/object&gt;
&lt;p&gt;For &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/c22759b5221a77ba818faab4152fe1744f5b85f9.svg" style="height: 12px;" type="image/svg+xml"&gt;n=3&lt;/object&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/d9689d0c44ff53ebf37d3789f27a2bcafa99512f.svg" style="height: 115px;" type="image/svg+xml"&gt;\[\begin{aligned}
    z_0&amp;amp;=e^{i2\pi 0/3}=e^0=1\\
    z_1&amp;amp;=e^{i2\pi 1/3}=\cos\frac{2\pi}{3}+i\sin\frac{2\pi}{3}=-\frac{1}{2}+i\frac{\sqrt{3}}{2}\\
    z_2&amp;amp;=e^{i2\pi 2/3}=\cos\frac{4\pi}{3}+i\sin\frac{4\pi}{3}=-\frac{1}{2}-i\frac{\sqrt{3}}{2}
\end{aligned}\]&lt;/object&gt;
&lt;p&gt;As expected. It should be similarly simple to calculate the roots for
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/a2ca9af97a38440d0a4a221a8fd15cafa7284225.svg" style="height: 12px;" type="image/svg+xml"&gt;n=4&lt;/object&gt;; give it a try.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="roots-of-unity-and-rotations-on-the-unit-circle"&gt;
&lt;h2&gt;Roots of unity and rotations on the unit circle&lt;/h2&gt;
&lt;p&gt;What happens when we multiply some root of unity &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/ff098555ccf7ee8fec5b7b700285db4685fbae8e.svg" style="height: 10px;" type="image/svg+xml"&gt;z_k&lt;/object&gt; by itself?
Since the magnitude of the root is 1, multiplying by it is akin to a
&lt;em&gt;rotation&lt;/em&gt; along the unit circle by the root’s angle. For example,
consider &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/e454a1a44b86318c4927590ae2179eb450c5eb14.svg" style="height: 10px;" type="image/svg+xml"&gt;z_1&lt;/object&gt; from the 3rd roots of unity:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/edcce6a8a2cae27f290f81aa89244c331095bd22.svg" style="height: 20px;" type="image/svg+xml"&gt;\[z_1=e^{i2\pi1/3}\]&lt;/object&gt;
&lt;p&gt;Multiply &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/e454a1a44b86318c4927590ae2179eb450c5eb14.svg" style="height: 10px;" type="image/svg+xml"&gt;z_1&lt;/object&gt; by itself:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/0687e3e8cce4b4414ac8301f203f76ce08d8c411.svg" style="height: 21px;" type="image/svg+xml"&gt;\[z_1^2=e^{i2\pi1/3}\cdot e^{i2\pi1/3}=e^{i2\pi2/3}\]&lt;/object&gt;
&lt;p&gt;If the angle of &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/e454a1a44b86318c4927590ae2179eb450c5eb14.svg" style="height: 10px;" type="image/svg+xml"&gt;z_1&lt;/object&gt; is &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/7cc2f9aceb37cdf4cccd82972e376f791367641f.svg" style="height: 18px;" type="image/svg+xml"&gt;2\pi/3&lt;/object&gt;, the angle of
&lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/89924baa1435767fb3b7886247adacc1819750fd.svg" style="height: 19px;" type="image/svg+xml"&gt;z_1^2&lt;/object&gt; is &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/4279bea8cb80aad253df8a6495defb5055cc784f.svg" style="height: 18px;" type="image/svg+xml"&gt;4\pi/3&lt;/object&gt;. Let’s multiply by &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/e454a1a44b86318c4927590ae2179eb450c5eb14.svg" style="height: 10px;" type="image/svg+xml"&gt;z_1&lt;/object&gt; once
more:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/f559d69ac2245e1524e5793149f8da1150a5495c.svg" style="height: 21px;" type="image/svg+xml"&gt;\[z_1^3=e^{i2\pi2/3}\cdot e^{i2\pi1/3}=e^{i6\pi/3}=1\]&lt;/object&gt;
&lt;p&gt;The result is 1, as expected (after all, &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/e454a1a44b86318c4927590ae2179eb450c5eb14.svg" style="height: 10px;" type="image/svg+xml"&gt;z_1&lt;/object&gt; is a 3rd root of
unity).&lt;/p&gt;
&lt;p&gt;This visualization shows how roots of unity appear on the unit circle
and how raising them to powers rotates the roots until finally
&lt;object class="valign-m5 latex-math" data="https://eli.thegreenplace.net/images/math/638bca8891c842399d6782142078083c115b2334.svg" style="height: 17px;" type="image/svg+xml"&gt;z_k^n=1&lt;/object&gt;:&lt;/p&gt;
&lt;div class="rootsunity-wrap"&gt;
  &lt;section aria-label="Roots of unity"&gt;
    &lt;canvas id="rootsunity-roots" width="440" height="420" role="img"&gt;
      The nth roots of unity, equally spaced around the unit circle. Use the root selector below.
    &lt;/canvas&gt;
    &lt;div class="rootsunity-controls"&gt;
      &lt;label for="rootsunity-degree"&gt;Roots &lt;i&gt;n&lt;/i&gt; &lt;select id="rootsunity-degree" aria-label="Number of roots n"&gt;&lt;/select&gt;&lt;/label&gt;
      &lt;label for="rootsunity-root"&gt;Root &lt;i&gt;k&lt;/i&gt; &lt;select id="rootsunity-root" aria-label="Selected root k"&gt;&lt;/select&gt;&lt;/label&gt;
    &lt;/div&gt;
  &lt;/section&gt;
  &lt;section aria-label="Powers of the selected root"&gt;
    &lt;canvas id="rootsunity-powers" width="440" height="420" role="img"&gt;
      The powers of the selected root. Use the power slider below.
    &lt;/canvas&gt;
    &lt;div class="rootsunity-controls"&gt;
      &lt;label for="rootsunity-power"&gt;Power &lt;i&gt;m&lt;/i&gt;&lt;/label&gt;
      &lt;input id="rootsunity-power" type="range" min="1" max="6" value="1" step="1"&gt;
      &lt;output id="rootsunity-power-value" for="rootsunity-power"&gt;&lt;/output&gt;
    &lt;/div&gt;
  &lt;/section&gt;
&lt;/div&gt;&lt;p&gt;Select &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt; first; this shows the &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt;-th roots as blue dots
on the unit circle. Now you can click any of the roots, and see its
powers in the lower plot - drag the slidebar to see the rotations. If
you spend some time playing with this, you’ll notice that some roots -
for example &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/71f0e21bc266b9df576c4de576a5c1224f52f613.svg" style="height: 10px;" type="image/svg+xml"&gt;z_2&lt;/object&gt; when &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/fd917de64a52110443142df37dfb4c646c895ca0.svg" style="height: 12px;" type="image/svg+xml"&gt;n=6&lt;/object&gt; - go back to 1 when raised to a
smaller power than &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt;. We’ll revisit this outcome when we discuss
the group-theoretic aspects of roots of unity.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="geometry-roots-of-unity-and-regular-polygons"&gt;
&lt;h2&gt;Geometry: roots of unity and regular polygons&lt;/h2&gt;
&lt;p&gt;As we’ve seen, the roots of unity are evenly spaced along the unit
circle on the complex plane. If we connect the roots with straight lines
to their immediate neighbors, we’ll notice something interesting:&lt;/p&gt;
&lt;div class="rootsunity-wrap"&gt;
  &lt;section aria-label="Regular polygons from roots of unity"&gt;
    &lt;canvas id="rootsunity-polygon" width="440" height="420" role="img"&gt;
      Adjacent nth roots of unity joined to form a regular polygon on the unit circle.
    &lt;/canvas&gt;
    &lt;div class="rootsunity-controls"&gt;
      &lt;label for="rootsunity-polygon-degree"&gt;Roots &lt;i&gt;n&lt;/i&gt; &lt;select id="rootsunity-polygon-degree" aria-label="Number of roots n"&gt;&lt;/select&gt;&lt;/label&gt;
    &lt;/div&gt;
  &lt;/section&gt;
&lt;/div&gt;&lt;p&gt;For different values of &lt;object class="valign-m2 latex-math" data="https://eli.thegreenplace.net/images/math/b31027a7d3ac1d87ed01a4ca9e6bc1a3ea6da64d.svg" style="height: 14px;" type="image/svg+xml"&gt;n\ge3&lt;/object&gt;, we get the &lt;a class="reference external" href="https://en.wikipedia.org/wiki/Regular_polygon"&gt;Regular
Polygons&lt;/a&gt;! It’s pretty
easy to prove this if we connect each root with a straight line to the
origin. The triangles we get are congruent, because the sides from the
origin to the roots are all of length 1, and the central angles are all
&lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/2ae20eff12708a7686de72a34c9d9753ea6021dd.svg" style="height: 18px;" type="image/svg+xml"&gt;2\pi /n&lt;/object&gt;. Therefore, both the sides of the polygons and their
angles are identical, which makes them regular.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="conjugates-of-roots-of-unity"&gt;
&lt;h2&gt;Conjugates of roots of unity&lt;/h2&gt;
&lt;p&gt;Suppose we have the root of unity:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/17b1c922c581c7418bb2492f31a33a7f6583375c.svg" style="height: 20px;" type="image/svg+xml"&gt;\[z_k=e^{i2\pi k/n}\]&lt;/object&gt;
&lt;p&gt;For some &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/13fbd79c3d390e5d6585a21e11ff5ec1970cff0c.svg" style="height: 12px;" type="image/svg+xml"&gt;k&lt;/object&gt; and &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt;. If we take the reciprocal of
&lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/ff098555ccf7ee8fec5b7b700285db4685fbae8e.svg" style="height: 10px;" type="image/svg+xml"&gt;z_k&lt;/object&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/87fa380c6bbbd66e98caf03714a27b6f4e2fa6bd.svg" style="height: 22px;" type="image/svg+xml"&gt;\[z_k^{-1}=e^{-i2\pi k/n}\]&lt;/object&gt;
&lt;p&gt;Then:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/7835bde1ec507eb137a919c14fba6f827d26cba5.svg" style="height: 22px;" type="image/svg+xml"&gt;\[(z_k^{-1})^n=e^{-in 2\pi k/n}=e^{-i2\pi k}=1\]&lt;/object&gt;
&lt;p&gt;So &lt;object class="valign-m5 latex-math" data="https://eli.thegreenplace.net/images/math/f380a3a6ce31c7a9d7ea90d3407560985f1925b1.svg" style="height: 21px;" type="image/svg+xml"&gt;z_k^{-1}&lt;/object&gt; is also an n-th root of unity. While the powers of
&lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/ff098555ccf7ee8fec5b7b700285db4685fbae8e.svg" style="height: 10px;" type="image/svg+xml"&gt;z_k&lt;/object&gt; are rotating counter-clockwise
on the unit circle until they land on 1 for the &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt;-th power,
the powers of &lt;object class="valign-m5 latex-math" data="https://eli.thegreenplace.net/images/math/f380a3a6ce31c7a9d7ea90d3407560985f1925b1.svg" style="height: 21px;" type="image/svg+xml"&gt;z_k^{-1}&lt;/object&gt; similarly rotate
&lt;em&gt;clockwise&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;&lt;object class="valign-m5 latex-math" data="https://eli.thegreenplace.net/images/math/f380a3a6ce31c7a9d7ea90d3407560985f1925b1.svg" style="height: 21px;" type="image/svg+xml"&gt;z_k^{-1}&lt;/object&gt; also happens to be the complex conjugate of
&lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/ff098555ccf7ee8fec5b7b700285db4685fbae8e.svg" style="height: 10px;" type="image/svg+xml"&gt;z_k&lt;/object&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/a23c986d7ecb8cd6172396205e557a2eadfa693b.svg" style="height: 21px;" type="image/svg+xml"&gt;\[z_k^{-1}=z_k^*\]&lt;/object&gt;
&lt;p&gt;So if we have:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/03d9dd24f65e4a24d5845fc97583178de083bb2c.svg" style="height: 20px;" type="image/svg+xml"&gt;\[z_k=e^{i2\pi k/n}, \qquad k=0,1,\dots,n-1\]&lt;/object&gt;
&lt;p&gt;As the &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt;-th roots of unity, then:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/4024b99d712d61bc80741fef823410a8274d4b6e.svg" style="height: 21px;" type="image/svg+xml"&gt;\[z_k^*=e^{-i2\pi k/n}, \qquad k=0,1,\dots,n-1\]&lt;/object&gt;
&lt;p&gt;Are also &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt;-th roots of unity. In fact, they are the same roots,
because for any given positive &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/13fbd79c3d390e5d6585a21e11ff5ec1970cff0c.svg" style="height: 12px;" type="image/svg+xml"&gt;k&lt;/object&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/38ee91a66813ad1c94b100d153b5f1b5471db5e2.svg" style="height: 135px;" type="image/svg+xml"&gt;\[\begin{aligned}
    z_k^*&amp;amp;=e^{-i2\pi k/n}\\
    &amp;amp;=1\cdot e^{-i2\pi k/n}\\
    &amp;amp;=e^{i2\pi}\cdot e^{-i2\pi k/n}\\
    &amp;amp;=e^{i2\pi n/n}\cdot e^{-i2\pi k/n}\\
    &amp;amp;=e^{i2\pi (n-k)/n}=z_{n-k}
\end{aligned}\]&lt;/object&gt;
&lt;p&gt;So enumerating the conjugate roots is the same as enumerating the roots
themselves in the opposite order.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="group-theory-the-cyclic-group-of-roots-of-unity"&gt;
&lt;h2&gt;Group theory: the cyclic group of roots of unity&lt;/h2&gt;
&lt;p&gt;Let’s look at the set of &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/ff098555ccf7ee8fec5b7b700285db4685fbae8e.svg" style="height: 10px;" type="image/svg+xml"&gt;z_k&lt;/object&gt; (roots of unity) for some
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/68715f4c8688f321158f590581a1b85b9d135511.svg" style="height: 32px;" type="image/svg+xml"&gt;\[\mu_n=\left\{z_k=e^{2\pi ik/n}:k=0,1,\dots,n-1\right\}\]&lt;/object&gt;
&lt;p&gt;This set - along with the multiplication operation - forms a &lt;em&gt;group&lt;/em&gt;.
Let’s prove that.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Closure:&lt;/strong&gt; Assume &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/a6609eca49b6c48a380ab6d1e4b3daf0a1738998.svg" style="height: 13px;" type="image/svg+xml"&gt;z,y\in\mu_n&lt;/object&gt; (so &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/233d47313af3fd672046cb090353570bea80d230.svg" style="height: 12px;" type="image/svg+xml"&gt;z^n=1&lt;/object&gt; and
&lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/40443a0bbab19712085bea791d8160cdc9af5882.svg" style="height: 15px;" type="image/svg+xml"&gt;y^n=1&lt;/object&gt;). Then:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/e596605ff5dde17a38f27e0c4e996f9843c4fd0e.svg" style="height: 18px;" type="image/svg+xml"&gt;\[(zy)^n=z^n y^n=1\]&lt;/object&gt;
&lt;p&gt;Therefore &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/7e8908dff37f92c4b190b13cd1b90d5e696296d4.svg" style="height: 13px;" type="image/svg+xml"&gt;zy\in\mu_n&lt;/object&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Identity:&lt;/strong&gt; The number &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/13e13a1debb55228edc4408b38c141bb53fa8ebb.svg" style="height: 15px;" type="image/svg+xml"&gt;1\in\mu_n&lt;/object&gt;, so it can serve as our
identity element for the group.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Associativity:&lt;/strong&gt; Taken directly from the associativity of the
multiplication operation on complex numbers.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Inverse:&lt;/strong&gt; We’ve just seen in the section on conjugates that
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/f952d2113cc5ef211c8a7a76dad3967568f0f880.svg" style="height: 15px;" type="image/svg+xml"&gt;z^{-1}&lt;/object&gt; is an &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt;-th root of unity when &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/395df8f7c51f007019cb30201c49e884b46b92fa.svg" style="height: 8px;" type="image/svg+xml"&gt;z&lt;/object&gt; is. So
the inverse exists and is part of the group.&lt;/p&gt;
&lt;p&gt;Because the operation we have is just complex multiplication, we can
trivially derive additional properties, like commutativity. Therefore,
the group &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/d220e0a0d3898265d8faf630c06c2a11f809e294.svg" style="height: 11px;" type="image/svg+xml"&gt;\mu_n&lt;/object&gt; is &lt;em&gt;Abelian&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Finally, we can show that the group is also &lt;em&gt;cyclic&lt;/em&gt; and discuss its
&lt;em&gt;generators&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;For slightly simpler notation, let’s denote &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/b83f781eef94665c0c0c8cf2f07fed9c17d2efa3.svg" style="height: 10px;" type="image/svg+xml"&gt;w=z_1&lt;/object&gt;. So the group
can be represented as:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/022cef06d5818c7bb8fd137aabb2a3d612d63536.svg" style="height: 22px;" type="image/svg+xml"&gt;\[\mu_n=\left\{1, w, w^2,\dots,w^{n-1}\right\}\]&lt;/object&gt;
&lt;p&gt;This makes it obvious that the group is cyclic - all its elements can be
expressed as integer powers of &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/aff024fe4ab0fece4091de044c58c9ae4233383a.svg" style="height: 8px;" type="image/svg+xml"&gt;w&lt;/object&gt;. And &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/aff024fe4ab0fece4091de044c58c9ae4233383a.svg" style="height: 8px;" type="image/svg+xml"&gt;w&lt;/object&gt; is a generator
for the group.&lt;/p&gt;
&lt;p&gt;But interestingly, &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/aff024fe4ab0fece4091de044c58c9ae4233383a.svg" style="height: 8px;" type="image/svg+xml"&gt;w&lt;/object&gt; is not the only generator for this group.
Any &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/4a44049c3a8f53936d8fcc36d815a42f1e142c30.svg" style="height: 15px;" type="image/svg+xml"&gt;w^k&lt;/object&gt; can be a generator, as long as &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/13fbd79c3d390e5d6585a21e11ff5ec1970cff0c.svg" style="height: 12px;" type="image/svg+xml"&gt;k&lt;/object&gt; and &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt;
are co-prime. For example, consider the group &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/1b97b3bbef9188f0b2b3fa65fe281543f777ef36.svg" style="height: 11px;" type="image/svg+xml"&gt;\mu_6&lt;/object&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/fc0be2f835f981ed8f20fa07b99b60d0792db10a.svg" style="height: 22px;" type="image/svg+xml"&gt;\[\mu_6=\left\{1, w, w^2,w^3,w^4,w^5\right\}\]&lt;/object&gt;
&lt;p&gt;Obviously, &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/aff024fe4ab0fece4091de044c58c9ae4233383a.svg" style="height: 8px;" type="image/svg+xml"&gt;w&lt;/object&gt; is a generator for this group. But &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/a4b6f6113d5e75c21bdb387b851a7265f997a9e7.svg" style="height: 15px;" type="image/svg+xml"&gt;w^2&lt;/object&gt;
isn’t! If we raise it to various powers we get:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/4cf480ee125e345551a71688da373bc384bcadb6.svg" style="height: 156px;" type="image/svg+xml"&gt;\[\begin{aligned}
    (w^2)^0&amp;amp;=1\\
    (w^2)^1&amp;amp;=w^2\\
    (w^2)^2&amp;amp;=w^4\\
    (w^2)^3&amp;amp;=w^6=1\\
    (w^2)^4&amp;amp;=w^8=w^2\\
    (w^2)^5&amp;amp;=w^{10}=w^4\\
\end{aligned}\]&lt;/object&gt;
&lt;p&gt;Since &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/4fa09a2f081fa4d539caf593f6ef1cdf8a0f0c3b.svg" style="height: 15px;" type="image/svg+xml"&gt;w^6=1&lt;/object&gt;, the powers of &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/a4b6f6113d5e75c21bdb387b851a7265f997a9e7.svg" style="height: 15px;" type="image/svg+xml"&gt;w^2&lt;/object&gt; repeat after just three
steps, so they only reach three out of six group elements.&lt;/p&gt;
&lt;p&gt;But if &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/13fbd79c3d390e5d6585a21e11ff5ec1970cff0c.svg" style="height: 12px;" type="image/svg+xml"&gt;k&lt;/object&gt; and &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt; are co-prime, &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/4a44049c3a8f53936d8fcc36d815a42f1e142c30.svg" style="height: 15px;" type="image/svg+xml"&gt;w^k&lt;/object&gt; is a generator;
in the case of &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/1b97b3bbef9188f0b2b3fa65fe281543f777ef36.svg" style="height: 11px;" type="image/svg+xml"&gt;\mu_6&lt;/object&gt;, we can easily verify that &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/aff024fe4ab0fece4091de044c58c9ae4233383a.svg" style="height: 8px;" type="image/svg+xml"&gt;w&lt;/object&gt; and
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/4111fef466982e1b6ffce01c01d4254db2a40c24.svg" style="height: 15px;" type="image/svg+xml"&gt;w^5&lt;/object&gt; are the only generators. The roots that are generators for
the group are also called the &lt;em&gt;primitive roots&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="sums-of-roots-of-unity"&gt;
&lt;h2&gt;Sums of roots of unity&lt;/h2&gt;
&lt;p&gt;Let’s take the &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt;-roots of unity (&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/719262cd45830248133d8a9183d18f9b43c1a7cb.svg" style="height: 12px;" type="image/svg+xml"&gt;n&amp;gt;1&lt;/object&gt;), denoted as above
with:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/82c3159e4ad11eea2305a1be4fd309eb96ca2ec0.svg" style="height: 23px;" type="image/svg+xml"&gt;\[\mu_n=\left\{1, w, w^2,\dots,w^{n-1}\right\}\qquad w=e^{2\pi i/n}\]&lt;/object&gt;
&lt;p&gt;What’s the sum of all these roots?&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/95e2fad1ca588ef53366342e0f1cb3a97473ebf5.svg" style="height: 52px;" type="image/svg+xml"&gt;\[S=1+w+w^2+\cdots+w^{n-1}=\sum_{i=0}^{n-1}w^i\]&lt;/object&gt;
&lt;p&gt;This is just the sum of a geometric series with the first term 1 and
common ratio &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/7cfc225017016ad50ea7ef500ad286270db16b1e.svg" style="height: 8px;" type="image/svg+xml"&gt;r=w&lt;/object&gt;. Therefore:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/c6f321c67a305509b4120d745ac7c71228f752ef.svg" style="height: 38px;" type="image/svg+xml"&gt;\[S=\frac{1-w^n}{1-w}=\frac{1-1}{1-w}=0\]&lt;/object&gt;
&lt;p&gt;If you look carefully at the visualization shown above - this makes
sense geometrically. All the roots of unity are evenly spread around the
unit circle, so viewing them as vectors, all components cancel out.&lt;/p&gt;
&lt;p&gt;How about the sum of roots raised to some integer power &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/13fbd79c3d390e5d6585a21e11ff5ec1970cff0c.svg" style="height: 12px;" type="image/svg+xml"&gt;k&lt;/object&gt;? Let’s
try this for &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/e5eb05bb23136deb5962f9004ae449e74f7e0547.svg" style="height: 12px;" type="image/svg+xml"&gt;k=2&lt;/object&gt; (assuming &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d9ec84c4dbd0cb3cb11ec81e619c6441e2f9c96a.svg" style="height: 12px;" type="image/svg+xml"&gt;n&amp;gt;2&lt;/object&gt;):&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/c0bc9ac12bb892a8ad276272ac6fcdb04b760bdf.svg" style="height: 20px;" type="image/svg+xml"&gt;\[S_2=1+w^2+w^4+\cdots+w^{2(n-1)}\]&lt;/object&gt;
&lt;p&gt;Using the same geometric series sum formula (with &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/19a7d4ca0575d265b7bb21665d1031ae82ac23a2.svg" style="height: 15px;" type="image/svg+xml"&gt;r=w^2&lt;/object&gt;), we
get:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/aef185ae02a5a3fa6fe87d24b5326af854df7aba.svg" style="height: 41px;" type="image/svg+xml"&gt;\[S_2=\frac{1-w^{2n}}{1-w^2}=\frac{1-(w^{n})^{2}}{1-w^2}=0\]&lt;/object&gt;
&lt;p&gt;In general, when &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/13fbd79c3d390e5d6585a21e11ff5ec1970cff0c.svg" style="height: 12px;" type="image/svg+xml"&gt;k&lt;/object&gt; is not divisible by &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt;, the sum is 0.
But when &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/13fbd79c3d390e5d6585a21e11ff5ec1970cff0c.svg" style="height: 12px;" type="image/svg+xml"&gt;k&lt;/object&gt; &lt;em&gt;is&lt;/em&gt; divisible by &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt;, each power becomes:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/d905642dd5d1ba288340912c53897c9720459cee.svg" style="height: 17px;" type="image/svg+xml"&gt;\[w^k=e^{2\pi ik/n}=1\]&lt;/object&gt;
&lt;p&gt;And &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt; of these sum to &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt;. In conclusion:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/80f6898f8f19db5ecfa87b096691cc8c37b5df5f.svg" style="height: 54px;" type="image/svg+xml"&gt;\[\sum_{i=0}^{n-1}w^{ki}=
\begin{cases}
    n &amp;amp; k \equiv 0 \pmod{n}\\
    0 &amp;amp; \text{otherwise} \\
\end{cases}\]&lt;/object&gt;
&lt;/div&gt;
&lt;div class="section" id="powers-of-roots-of-unity-as-an-orthogonal-basis"&gt;
&lt;h2&gt;Powers of roots of unity as an orthogonal basis&lt;/h2&gt;
&lt;p&gt;Let’s consider the powers of roots of unity as vectors. We’ll continue
using the notation:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/82c3159e4ad11eea2305a1be4fd309eb96ca2ec0.svg" style="height: 23px;" type="image/svg+xml"&gt;\[\mu_n=\left\{1, w, w^2,\dots,w^{n-1}\right\}\qquad w=e^{2\pi i/n}\]&lt;/object&gt;
&lt;p&gt;We’ll begin with the 0-th power vector - each of the roots raised to
power 0:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/7f1aabba7c282d24ac38976ea8d370e60c446e2e.svg" style="height: 18px;" type="image/svg+xml"&gt;\[v_0=\left[1, 1, 1,\dots,1\right]\]&lt;/object&gt;
&lt;p&gt;Then power 1 - just the roots themselves:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/e5098bb36b15bd6377e5ed73f7b5461ef76297c1.svg" style="height: 22px;" type="image/svg+xml"&gt;\[v_1=\left[1, w, w^2,\dots,w^{n-1}\right]\]&lt;/object&gt;
&lt;p&gt;Each root raised to power 2:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/152ac136c6c0f148beb07a88fb458f3a9ec7d243.svg" style="height: 32px;" type="image/svg+xml"&gt;\[v_2=\left[1, w^2, w^4,\dots,w^{2(n-1)}\right]\]&lt;/object&gt;
&lt;p&gt;And so on, until power &lt;object class="valign-m1 latex-math" data="https://eli.thegreenplace.net/images/math/81f998c5713fded10a77db292e4114ec87997543.svg" style="height: 12px;" type="image/svg+xml"&gt;n-1&lt;/object&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/b7809511f4d99148f3689178cd42a42aeb68c57b.svg" style="height: 32px;" type="image/svg+xml"&gt;\[v_{n-1}=\left[1, w^{n-1}, w^{2(n-1)},\dots,w^{(n-1)(n-1)}\right]\]&lt;/object&gt;
&lt;p&gt;To go full linear algebra mode, we’ll collect these vectors into an
&lt;object class="valign-m1 latex-math" data="https://eli.thegreenplace.net/images/math/940c9f17d1a1df149e433fd817009f4f3c5e8019.svg" style="height: 12px;" type="image/svg+xml"&gt;n\times n&lt;/object&gt; matrix:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/de36a955bb0b4d0f2834fc86d990431054481ecd.svg" style="height: 108px;" type="image/svg+xml"&gt;\[V=\begin{bmatrix}
    1 &amp;amp; 1 &amp;amp; 1 &amp;amp; \cdots &amp;amp; 1 \\
    1 &amp;amp; w &amp;amp; w^2 &amp;amp; \cdots &amp;amp; w^{n-1} \\
    1 &amp;amp; w^2 &amp;amp; w^4 &amp;amp; \cdots &amp;amp; w^{2(n-1)} \\
    \vdots &amp;amp; &amp;amp; &amp;amp; &amp;amp; \vdots \\
    1 &amp;amp; w^{n-1} &amp;amp; w^{2(n-1)} &amp;amp; \cdots &amp;amp; w^{(n-1)(n-1)} \\
\end{bmatrix}\]&lt;/object&gt;
&lt;p&gt;Let’s calculate the inner product of two matrix rows. Recall that when
computing the inner product on vectors over &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/706e4005d6760527e1bd99f36d2e91c4f60ad91f.svg" style="height: 12px;" type="image/svg+xml"&gt;\mathbb{C}&lt;/object&gt;, we
conjugate the second element:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/fbd34c6fd92069885c1099bfa2974b6d1ba87587.svg" style="height: 235px;" type="image/svg+xml"&gt;\[\begin{aligned}
    \langle v_i,v_j\rangle&amp;amp;=\sum_{k=0}^{n-1}v_i[k]\cdot v_j[k]^*\\
    &amp;amp;=\sum_{k=0}^{n-1}w^{ik}\cdot (w^{jk})^*\\
    &amp;amp;=\sum_{k=0}^{n-1}w^{ik}\cdot w^{-jk}\\
    &amp;amp;=\sum_{k=0}^{n-1}w^{(i-j)k}\\
\end{aligned}\]&lt;/object&gt;
&lt;p&gt;But hold on, we’ve just calculated this exact sum in the previous
section. We get:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/200abbd5356ef26ed0bf1d40c0e4ebca134c9190.svg" style="height: 54px;" type="image/svg+xml"&gt;\[\langle v_i,v_j\rangle=\sum_{k=0}^{n-1}w^{(i-j)k}=
\begin{cases}
    n &amp;amp; (i-j) \equiv 0 \pmod{n}\\
    0 &amp;amp; \text{otherwise} \\
\end{cases}\]&lt;/object&gt;
&lt;p&gt;Since the vector indices &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/042dc4512fa3d391c5170cf3aa61e6a638f84342.svg" style="height: 12px;" type="image/svg+xml"&gt;i&lt;/object&gt; and &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/5c2dd944dde9e08881bef0894fe7b22a5c9c4b06.svg" style="height: 16px;" type="image/svg+xml"&gt;j&lt;/object&gt; only run over
&lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/3a1270fd6c92e5af5e3dcaab76bcf2f27f048995.svg" style="height: 18px;" type="image/svg+xml"&gt;[0..n-1]&lt;/object&gt;, this is equivalent to:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/dc5783b4ed63090679ee69cbd3564955b870b597.svg" style="height: 54px;" type="image/svg+xml"&gt;\[\langle v_i,v_j\rangle=\sum_{k=0}^{n-1}w^{(i-j)k}=
\begin{cases}
    n &amp;amp; i=j\\
    0 &amp;amp; \text{otherwise} \\
\end{cases}\]&lt;/object&gt;
&lt;p&gt;Which is to say: the vectors &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/f0cd317158e9b3b19134b2c5db4e0861fcd95222.svg" style="height: 11px;" type="image/svg+xml"&gt;v_i&lt;/object&gt; and &lt;object class="valign-m5 latex-math" data="https://eli.thegreenplace.net/images/math/e20982d9213ce7bd2a82b922940a525f0966b783.svg" style="height: 13px;" type="image/svg+xml"&gt;v_j&lt;/object&gt; are
mutually orthogonal when &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/eebecf421c4d33eeab4a0c4da6c20ed8d49e6c6c.svg" style="height: 17px;" type="image/svg+xml"&gt;i\neq j&lt;/object&gt;. Since we have a set of &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt; orthogonal vectors
in &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/3b050ca140974a380d383aa92bb4526fb2c62061.svg" style="height: 12px;" type="image/svg+xml"&gt;\mathbb{C}^n&lt;/object&gt;, these vectors form a &lt;em&gt;basis&lt;/em&gt; for
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/3b050ca140974a380d383aa92bb4526fb2c62061.svg" style="height: 12px;" type="image/svg+xml"&gt;\mathbb{C}^n&lt;/object&gt; - any vector in this space can be represented as a
linear combination of &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/f0cd317158e9b3b19134b2c5db4e0861fcd95222.svg" style="height: 11px;" type="image/svg+xml"&gt;v_i&lt;/object&gt;. This fact has far reaching
consequences in math and engineering, since it plays a critical part in
forming the DFT (Discrete Fourier Transform), and &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/c9ee5681d3c59f7541c27a38b67edf46259e187b.svg" style="height: 12px;" type="image/svg+xml"&gt;V&lt;/object&gt; is also
known as the &lt;em&gt;Fourier matrix&lt;/em&gt;. But this will be a topic for a separate
post.&lt;/p&gt;
&lt;p&gt;Another fun thing to notice before we’re finished here: the matrix
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/c9ee5681d3c59f7541c27a38b67edf46259e187b.svg" style="height: 12px;" type="image/svg+xml"&gt;V&lt;/object&gt; happens to be &lt;em&gt;symmetric&lt;/em&gt; (this is trivial to check by
observation). Therefore, its columns are also mutually orthogonal.&lt;/p&gt;
&lt;hr class="docutils" /&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-1" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-1"&gt;[1]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;In general - counting multiplicity - there are exactly &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt;
complex roots. This is because we’re essentially finding the
solutions to the polynomial &lt;object class="valign-m1 latex-math" data="https://eli.thegreenplace.net/images/math/4313a64c645e9272f64540a5ec5e9bd0b6f2ed6b.svg" style="height: 13px;" type="image/svg+xml"&gt;z^n-1=0&lt;/object&gt;, which has &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt;
complex solutions according to the Fundamental theorem of algebra.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-2" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-2"&gt;[2]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;For some notes on converting between the different representations of
complex numbers, see my post on &lt;a class="reference external" href="https://eli.thegreenplace.net/2024/notes-on-the-euler-formula/"&gt;the Euler
formula&lt;/a&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-3" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-3"&gt;[3]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;When &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/4e3e29e8e235c265a2c27015f6f62beaf2241ca6.svg" style="height: 12px;" type="image/svg+xml"&gt;k=n&lt;/object&gt;, &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/ac0c523a13d2fc48d74f2ee4fc9aa45b7cb8e0ec.svg" style="height: 12px;" type="image/svg+xml"&gt;\theta=2\pi&lt;/object&gt;, which is the same as
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/a1dffbe89f1ec5a919198de979fca459eb7fdf84.svg" style="height: 12px;" type="image/svg+xml"&gt;\theta=0&lt;/object&gt;. On a unit circle, the roots start repeating once
one full cycle is completed; therefore, there are only &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt;
unique roots with &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/5354732927c85ee27b18538cebf8d3a3386370d6.svg" style="height: 16px;" type="image/svg+xml"&gt;k=0,1,\dots,n-1&lt;/object&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;script src="https://eli.thegreenplace.net/demos/rootsunity/rootsunity.js"&gt;
&lt;/script&gt;&lt;/div&gt;
</content><category term="misc"/><category term="Math"/></entry><entry><title>Monte-Carlo simulations</title><link href="https://eli.thegreenplace.net/2026/monte-carlo-simulations/" rel="alternate"/><published>2026-10-07T19:34:00-07:00</published><updated>2026-10-08T02:35:03.997683-07:00</updated><author><name>Eli Bendersky</name></author><id>tag:eli.thegreenplace.net,2026-10-07:/2026/monte-carlo-simulations/</id><summary type="html">&lt;p&gt;Monte Carlo simulations (or &lt;em&gt;methods&lt;/em&gt;) is the technique of applying
randomness and the &lt;a class="reference external" href="https://en.wikipedia.org/wiki/Law_of_large_numbers"&gt;Law of large numbers&lt;/a&gt;
to the solution of various scientific and engineering problems. One of its
first documented uses was by Stanislaw Ulam and John von Neumann for nuclear
weapon simulations after WWII &lt;a class="footnote-reference" href="#footnote-1" id="footnote-reference-1"&gt;[1]&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In this post …&lt;/p&gt;</summary><content type="html">&lt;p&gt;Monte Carlo simulations (or &lt;em&gt;methods&lt;/em&gt;) is the technique of applying
randomness and the &lt;a class="reference external" href="https://en.wikipedia.org/wiki/Law_of_large_numbers"&gt;Law of large numbers&lt;/a&gt;
to the solution of various scientific and engineering problems. One of its
first documented uses was by Stanislaw Ulam and John von Neumann for nuclear
weapon simulations after WWII &lt;a class="footnote-reference" href="#footnote-1" id="footnote-reference-1"&gt;[1]&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In this post I want to provide examples of some simple uses of Monte Carlo
simulations. We'll start with the classical example of calculating the value
of &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/6ac47b6d7372b4087583cfd048d20f4c1571f5cf.svg" style="height: 7px;" type="image/svg+xml"&gt;\pi&lt;/object&gt; by throwing darts.&lt;/p&gt;
&lt;div class="section" id="estimating-pi"&gt;
&lt;h2&gt;Estimating pi&lt;/h2&gt;
&lt;p&gt;Suppose we take a square board and inscribe a quarter of a circle into it. We
then proceed to throw darts at the board and record whether each dart hits
inside or outside the quarter circle. Having thrown many such darts, we
calculate the ratio of the darts inside the circle to the total number thrown.&lt;/p&gt;
&lt;p&gt;Assuming our darts are distributed uniformly over the
square, by the Law of large numbers this ratio should approach the ratio of
areas of the quarter circle &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/053e24fad601a506b974712e00fd14bbb5ea3da0.svg" style="height: 15px;" type="image/svg+xml"&gt;A_{circ}&lt;/object&gt; to the full square &lt;object class="valign-m5 latex-math" data="https://eli.thegreenplace.net/images/math/c401d49241b6f39e05f069d7c7bade3cf32595e8.svg" style="height: 17px;" type="image/svg+xml"&gt;A_{square}&lt;/object&gt;.&lt;/p&gt;
&lt;p&gt;With a square side length of 1, we have:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/b14567bdf5801a6461d737775a3fecc53e5f2478.svg" style="height: 43px;" type="image/svg+xml"&gt;\[\frac{A_{circ}}{A_{square}}=\frac{\pi/4}{1}=\frac{\pi}{4}\]&lt;/object&gt;
&lt;p&gt;Therefore:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/2aa6dc077da492fa32af06b4e147895ad9c2fff3.svg" style="height: 37px;" type="image/svg+xml"&gt;\[\pi\approx 4\frac{\text{hits inside}}{\text{total throws}}\]&lt;/object&gt;
&lt;p&gt;Here's a visualization:&lt;/p&gt;
&lt;link rel="stylesheet" href="https://eli.thegreenplace.net/demos/pi-monte-carlo/pi-monte-carlo.css"&gt;

&lt;div class="pi-monte-carlo-wrap"&gt;
  &lt;canvas id="pi-monte-carlo-canvas" class="pi-monte-carlo-canvas" width="400" height="400" role="img"
          aria-label="Quarter circle of radius 1 inside a unit square."&gt;
    A quarter circle of radius 1 inside a unit square.
  &lt;/canvas&gt;

  &lt;div class="pi-monte-carlo-controls"&gt;
    &lt;div class="pi-monte-carlo-row"&gt;
      &lt;div class="pi-monte-carlo-slider"&gt;
        &lt;label class="pi-monte-carlo-label" for="pi-monte-carlo-samples"&gt;
          Samples &lt;output id="pi-monte-carlo-count" for="pi-monte-carlo-samples"&gt;200&lt;/output&gt;
        &lt;/label&gt;
        &lt;input id="pi-monte-carlo-samples" class="pi-monte-carlo-range" type="range" min="10" max="1000" step="1" value="200"&gt;
        &lt;div class="pi-monte-carlo-range-labels"&gt;&lt;span&gt;10&lt;/span&gt;&lt;span&gt;1000&lt;/span&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;button id="pi-monte-carlo-go" class="pi-monte-carlo-button" type="button"&gt;Run&lt;/button&gt;
    &lt;/div&gt;

    &lt;p class="pi-monte-carlo-result" role="status" aria-live="polite" aria-atomic="true"&gt;
      &lt;span class="pi-monte-carlo-symbol"&gt;π&lt;/span&gt; ≈ &lt;span id="pi-monte-carlo-estimate"&gt;—&lt;/span&gt;
    &lt;/p&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;script src="https://eli.thegreenplace.net/demos/pi-monte-carlo/pi-monte-carlo.js"&gt;
&lt;/script&gt;&lt;p&gt;Change the number of samples (dart throws) and click &amp;quot;Run&amp;quot; to regenerate. The
code is very simple - here's a slightly sanitized version:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;samples&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;inside&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;random&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;random&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;inCircle&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inCircle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;inside&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="nx"&gt;estimateValue&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;4&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;inside&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You'll notice that the estimate is relatively poor - even with 1000 samples - if
you click &amp;quot;Run&amp;quot; several times, some numbers will be way off mark. While this
method does estimate &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/6ac47b6d7372b4087583cfd048d20f4c1571f5cf.svg" style="height: 7px;" type="image/svg+xml"&gt;\pi&lt;/object&gt;, it's not a particularly &lt;em&gt;good&lt;/em&gt; estimate. I
find that running ~10 billion samples is necessary to estimate it to 4 digits
after the decimal with reasonable reliability.&lt;/p&gt;
&lt;p&gt;In general, for independent trials like these, the typical sampling error
decreases in proportion to &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/b916b26ab11bcac09c1d31a41bae27051ccb4477.svg" style="height: 20px;" type="image/svg+xml"&gt;1/\sqrt{N}&lt;/object&gt;, where N is the number of trials.
This means that halving the error requires four times as many samples.&lt;/p&gt;
&lt;p&gt;While the &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/6ac47b6d7372b4087583cfd048d20f4c1571f5cf.svg" style="height: 7px;" type="image/svg+xml"&gt;\pi&lt;/object&gt; estimation may seem whimsical, it's an example of an
important class of problems to which Monte Carlo simulation is applied:
numerical integration. Our simulation estimates the area
under the quarter-circle curve, which is a definite integral.&lt;/p&gt;
&lt;p&gt;Many integrals are very difficult to solve analytically, and much research has
been done in the area of numerical analysis to develop methods to calculate
integrals. Monte Carlo methods are
particularly useful for high-dimensional integrals, where other numerical
methods can become prohibitively expensive.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="combinatorial-simulation-the-game-of-set"&gt;
&lt;h2&gt;Combinatorial simulation - the game of SET&lt;/h2&gt;
&lt;p&gt;A common use of Monte Carlo methods is estimating complex combinatorial
calculations. These often don't have analytical solutions, and enumerating all
options is intractable due to the scale of the numbers involved. As an example,
let's consider &lt;a class="reference external" href="https://en.wikipedia.org/wiki/Set_(card_game)"&gt;the game of SET&lt;/a&gt;. Each SET card has four
attributes:&lt;/p&gt;
&lt;ol class="arabic simple"&gt;
&lt;li&gt;Number of shapes (1, 2 or 3)&lt;/li&gt;
&lt;li&gt;Color (Red, Green or Purple)&lt;/li&gt;
&lt;li&gt;Shape type (Oval, Diamond or Squiggle)&lt;/li&gt;
&lt;li&gt;Shading (Empty, Striped or Solid)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;And the goal is to find a &amp;quot;set&amp;quot; - three cards that are either all different or
all the same &lt;em&gt;for each attribute separately&lt;/em&gt;. As an example, here's
a hand with a single set; see if you can find it &lt;a class="footnote-reference" href="#footnote-2" id="footnote-reference-2"&gt;[2]&lt;/a&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/2026/one-set-hand.svg" style="width: 600px;" type="image/svg+xml"&gt;SET hand with a single set&lt;/object&gt;
&lt;p&gt;And the next hand doesn't have any sets:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/2026/no-set-hand.svg" style="width: 600px;" type="image/svg+xml"&gt;SET hand with no hands&lt;/object&gt;
&lt;p&gt;Here's a question: given a freshly shuffled SET deck, what are the odds that
the first 12 cards drawn will have no sets among them? This question is
difficult to answer without using a computer.&lt;/p&gt;
&lt;p&gt;It's easy to calculate the number of ways to deal a 12-card hand from
a deck of 81:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/098543364b030df5cdeb5293d65c28767d18356e.svg" style="height: 43px;" type="image/svg+xml"&gt;\[\binom{81}{12}=70,724,320,184,700\]&lt;/object&gt;
&lt;p&gt;But how many of these hands have no sets? Enumerating 70 trillion SET hands
and checking each one can take quite a while, and there is no straightforward
counting formula to answer this question. Some clever methods can be employed to
leverage symmetries and other mathematical properties of SET to cut down this
search space considerably. Donald Knuth himself worked on this problem and came
up with a neat program (&lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;setset-all&lt;/span&gt;&lt;/tt&gt; on &lt;a class="reference external" href="https://cs.stanford.edu/~knuth/programs.html"&gt;his programs page&lt;/a&gt;) that found 2,284,535,476,080
such hands. Therefore, the answer to our question is:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/16ae56c10f6d43c2cc1de509054039f6b320bc07.svg" style="height: 39px;" type="image/svg+xml"&gt;\[\frac{2,284,535,476,080}{70,724,320,184,700}\approx 0.0323\]&lt;/object&gt;
&lt;p&gt;There's a 3.23% chance that a randomly drawn hand of 12 cards from a full deck
of SET will have no set in it.&lt;/p&gt;
&lt;p&gt;Let's see how we can use a Monte Carlo simulation to answer this question
with relatively small effort, without deep knowledge of the mathematical
properties of SET that enable cutting down the search space Knuth-style.
We can use the following pseudo-code:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;C = 0
run N times:
  draw a random 12-card hand from a fresh deck
  count sets in the hand
  if no sets:
    C += 1

Estimated probability = C / N
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;After running 10 million simulated draws, I got an answer of 0.0323, which
matches the real answer very closely.&lt;/p&gt;
&lt;p&gt;The Monte Carlo approach lets us solve rather complicated problems in a very
simple way. Suppose we want to answer the same question for a hand of 15 cards;
this would blow up the search space considerably - there are about 100x more
ways to select 15-card hands than there are to select 12-card hands. But for
a Monte Carlo simulation, we adjust one small parameter and get a very reliable
&lt;a class="footnote-reference" href="#footnote-3" id="footnote-reference-3"&gt;[3]&lt;/a&gt; answer (about 0.00037, in case you were wondering).&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="retirement-projection"&gt;
&lt;h2&gt;Retirement projection&lt;/h2&gt;
&lt;p&gt;One domain where Monte Carlo simulations are ubiquitous is projections for
retirement portfolios. Suppose someone prepares to retire with a total sum
of 1 million dollars in their portfolio; they'd like to be able to draw
$30,000 a year from the portfolio for their living expenses. Would that work?&lt;/p&gt;
&lt;p&gt;There's a large number of factors to take into account when analyzing this
question, but for simplicity let's focus on just two: portfolio return and
inflation. We can run a naive estimate, assuming average values: suppose an
average yearly portfolio return of 4%, and average yearly inflation of 2% &lt;a class="footnote-reference" href="#footnote-4" id="footnote-reference-4"&gt;[4]&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Let's denote our portfolio return as &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/4873d0bc2415a46014ddaa386855afdafb8bb128.svg" style="height: 12px;" type="image/svg+xml"&gt;r=0.04&lt;/object&gt;, and inflation as
&lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/7d34e41484499ddb2865f5839fa9e077168e4eaf.svg" style="height: 15px;" type="image/svg+xml"&gt;q=0.02&lt;/object&gt;. Then the real return each year is:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/a0734fd502c94279f989107fe05d3e177acf0c46.svg" style="height: 39px;" type="image/svg+xml"&gt;\[r^{\mathrm{real}}=\frac{1+r}{1+q}-1\approx0.0196\]&lt;/object&gt;
&lt;p&gt;Starting with $1,000,000, at the end of the year we'll have $1,019,600
and then draw $30,000 for living expenses &lt;a class="footnote-reference" href="#footnote-5" id="footnote-reference-5"&gt;[5]&lt;/a&gt;, ending with $989,600. If we
continue this way, the money runs out after ~55 years, which means that a
person retiring at the age of 65 should be reasonably safe, right?&lt;/p&gt;
&lt;p&gt;But this is &lt;em&gt;very simplistic&lt;/em&gt;; assuming just average returns is risky, because
they do a poor job of representing reality, and many factors have uncertainty.
For example, the sequence of returns matters a lot; a bad year (-10%) followed
by a great year (+18%) would still count as &amp;quot;4% on average&amp;quot; but produces
significantly less money than two consecutive +4% years.
Inflation is also unpredictable, and sometimes
correlated with portfolio returns; there could be bad years of high inflation and
low / volatile returns that can wreak havoc on a portfolio.&lt;/p&gt;
&lt;p&gt;As we add factors (variance in yearly draws, mixed portfolios of stocks, bonds,
real estate, life expectancy, unexpected events, changing tax laws etc.),
relying on a single average estimate becomes increasingly more fraught. This
is why Monte Carlo simulations are very popular in this domain: by drawing
from reasonable distributions based on historical data, a Monte Carlo simulation
can easily run a million different scenarios and provide estimates: for example,
what are the odds of money running out before death.&lt;/p&gt;
&lt;p&gt;Here's a useful chart from a simulation I ran:&lt;/p&gt;
&lt;img alt="Monte Carlo simulation of retirement, showing percentiles and odds of funds running out" class="align-center" src="https://eli.thegreenplace.net/images/2026/retirement-monte-carlo.png" /&gt;
&lt;p&gt;In the top chart:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;The dashed line shows the constant assumptions mentioned before: what happens
when yearly return is always 4% and inflation is always 2%.&lt;/li&gt;
&lt;li&gt;The shaded blue areas demonstrate the outcomes of 1,000,000 simulations where
inflation and return numbers are drawn from reasonable normal distributions
based on historical data. We see that in 25% of the cases, all money ran out
by roughly 22 years.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In the bottom chart:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;It's even easier to see how long the funds last; if we're interested in
knowing, say, what are the odds that this plan will have enough money for
30 years - the chart shows it's about 60% (since in 40% of the simulations
the funds were depleted at this point).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Looking a this simulation, under the current assumptions the plan sounds much
riskier than the average assumption makes it appear. Assuming that a 65-y.o.
person would plan for
25 years of retirement until death, the ~30% odds of not having sufficient funds
for this duration of time are sobering. Perhaps a change in plans is needed
(such as a more frugal lifestyle or securing additional funds in some way).&lt;/p&gt;
&lt;p&gt;Retirement projection is only one of may ways in which Monte Carlo simulations
are used for financial and economical applications; given the high uncertainty
of these domains, it's very difficult to plan using analytical calculations.
Company sales projections, growth projections, stock offering prices and much
more uses Monte Carlo simulations to arrive at estimates with reasonable error
bars.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="code"&gt;
&lt;h2&gt;Code&lt;/h2&gt;
&lt;p&gt;All the code for the explorations in this post is &lt;a class="reference external" href="https://github.com/eliben/code-for-blog/tree/main/2026/monte-carlo"&gt;available on GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;hr class="docutils" /&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-1" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-1"&gt;[1]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;While these techniques were conceptually understood much earlier, it's
not surprising that their first real applications coincided with the
development of the first digital computers. As we'll see later in the
post, Monte Carlo simulations benefit from running large numbers of
trials to get reasonable accuracy.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-2" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-2"&gt;[2]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;The answer is: three empty red diamonds, three solid purple ovals, three
striped green squiggles. Note that for each of the 4 SET attributes,
these three cards are either all the same or all different.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-3" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-3"&gt;[3]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;For the same number of trials, this estimate has greater relative
uncertainty than the 12-card estimate, because we encounter far fewer
hands without a set.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-4" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-4"&gt;[4]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;For the examples in this post, we'll be using &lt;em&gt;real dollars&lt;/em&gt;, or today's
value of the money. We'll assume that the $30,000 yearly draw doesn't
change and will instead apply inflation to the portfolio itself.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-5" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-5"&gt;[5]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;More sophisticated simulations would let us control these parameters;
for example, are the expense funds drawn at the beginning or end of each
year, or distributed on a monthly basis?&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
</content><category term="misc"/><category term="Math"/><category term="Science"/><category term="Rust"/><category term="Python"/></entry><entry><title>Notes on discrete-time Fourier series and transform</title><link href="https://eli.thegreenplace.net/2026/notes-on-discrete-time-fourier-series-and-transform/" rel="alternate"/><published>2026-09-19T09:39:00-07:00</published><updated>2026-10-18T01:28:10.973164-07:00</updated><author><name>Eli Bendersky</name></author><id>tag:eli.thegreenplace.net,2026-09-19:/2026/notes-on-discrete-time-fourier-series-and-transform/</id><summary type="html">&lt;link rel="stylesheet" href="https://eli.thegreenplace.net/demos/discrete-fourier/discrete-fourier.css"&gt;&lt;p&gt;The following are my notes on discrete-time Fourier series (DTFS), as
well as the discrete-time Fourier transform (DTFT). These topics serve
as an important theoretical underpinning to the digital processing of
signals by computers using the DFT (which will be covered in a future
post).&lt;/p&gt;
&lt;p&gt;For discrete-time signals, we use …&lt;/p&gt;</summary><content type="html">&lt;link rel="stylesheet" href="https://eli.thegreenplace.net/demos/discrete-fourier/discrete-fourier.css"&gt;&lt;p&gt;The following are my notes on discrete-time Fourier series (DTFS), as
well as the discrete-time Fourier transform (DTFT). These topics serve
as an important theoretical underpinning to the digital processing of
signals by computers using the DFT (which will be covered in a future
post).&lt;/p&gt;
&lt;p&gt;For discrete-time signals, we use the square bracket notation to
denote samples: &lt;object class="valign-m5 latex-math" data="https://eli.thegreenplace.net/images/math/97897883b2ac574b045db012a128c024c5a05498.svg" style="height: 18px;" type="image/svg+xml"&gt;x[n]&lt;/object&gt; is the n-th sample of signal
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/11f6ad8ec52a2984abaafd7c3b516503785c2072.svg" style="height: 8px;" type="image/svg+xml"&gt;x&lt;/object&gt;.&lt;/p&gt;
&lt;p&gt;We’ll say that a discrete-time (just &lt;em&gt;discrete&lt;/em&gt; from this point on, for
brevity) signal is periodic with period &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/b51a60734da64be0e618bacbea2865a8a7dcd669.svg" style="height: 12px;" type="image/svg+xml"&gt;N&lt;/object&gt; if:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/72444fe45e23358b5515c447242702d052cf8b29.svg" style="height: 18px;" type="image/svg+xml"&gt;\[x[n]=x[n+N]\qquad\forall{n}\]&lt;/object&gt;
&lt;p&gt;When talking about &lt;a class="reference external" href="https://eli.thegreenplace.net/2026/notes-on-fourier-series/"&gt;continuous-time Fourier
series&lt;/a&gt;,
we started with real trigonometric functions and later moved to complex
exponentials. Here, we’ll just go ahead and start directly with
(discrete) complex exponentials - converting between the two
representations isn’t difficult and can be done as needed (Appendix C in
this post demonstrates it).&lt;/p&gt;
&lt;p&gt;We’ll be dealing with the following family of signals &lt;a class="footnote-reference" href="#footnote-1" id="footnote-reference-1"&gt;[1]&lt;/a&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/893482d035c092058c8fe74a07d0d2007b2610f0.svg" style="height: 21px;" type="image/svg+xml"&gt;\[\phi_k[n]=e^{ikw_0n}=e^{ik(2\pi/N)n}\qquad \forall k\in\mathbb{Z}\]&lt;/object&gt;
&lt;p&gt;These are discrete complex exponentials that are periodic with period N.
&lt;object class="valign-m6 latex-math" data="https://eli.thegreenplace.net/images/math/aff8cebf2b8fefea8ffbcb72636173fa560cb3c4.svg" style="height: 21px;" type="image/svg+xml"&gt;w_0=\frac{2\pi}{N}&lt;/object&gt; is the &lt;em&gt;angular frequency&lt;/em&gt;. As discussed in
Appendix A, there are only N such distinct signals, since:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/63dc5525074209448db49c6df6e21ad55681bd06.svg" style="height: 18px;" type="image/svg+xml"&gt;\[\phi_k[n]=\phi_{k+N}[n]\qquad\forall{k}\]&lt;/object&gt;
&lt;div class="section" id="coefficients-of-discrete-time-fourier-series"&gt;
&lt;h2&gt;Coefficients of discrete-time Fourier series&lt;/h2&gt;
&lt;p&gt;We’ll want to consider the representation of an arbitrary N-periodic
&lt;object class="valign-m5 latex-math" data="https://eli.thegreenplace.net/images/math/97897883b2ac574b045db012a128c024c5a05498.svg" style="height: 18px;" type="image/svg+xml"&gt;x[n]&lt;/object&gt; by a linear combination of &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/1da2937ccce1ec5bb97b6acf3aa4c16b0600ac0a.svg" style="height: 18px;" type="image/svg+xml"&gt;\phi_k[n]&lt;/object&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/bc26c473be832c359f7b4113522934be90ee741f.svg" style="height: 44px;" type="image/svg+xml"&gt;\[x[n]=\sum_{k=\langle N\rangle}a_k\phi_k[n]\]&lt;/object&gt;
&lt;p&gt;The notation &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/7b3c13344886d907a02d04d04620598839f6b01f.svg" style="height: 18px;" type="image/svg+xml"&gt;k=\langle N\rangle&lt;/object&gt; means &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/13fbd79c3d390e5d6585a21e11ff5ec1970cff0c.svg" style="height: 12px;" type="image/svg+xml"&gt;k&lt;/object&gt; runs over any
sequence of &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/b51a60734da64be0e618bacbea2865a8a7dcd669.svg" style="height: 12px;" type="image/svg+xml"&gt;N&lt;/object&gt; consecutive integers. Since there are only
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/b51a60734da64be0e618bacbea2865a8a7dcd669.svg" style="height: 12px;" type="image/svg+xml"&gt;N&lt;/object&gt; distinct signals &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/ce4de0873a5958646dce9993ddaba5d4511d8b2d.svg" style="height: 16px;" type="image/svg+xml"&gt;\phi_k&lt;/object&gt;, the order of summation
doesn’t matter - as long as all of them are used. So it could go from 0
to &lt;object class="valign-m1 latex-math" data="https://eli.thegreenplace.net/images/math/4f927fbfe4d5898f228630ce76e5284ed202f837.svg" style="height: 14px;" type="image/svg+xml"&gt;N-1&lt;/object&gt;, or from 1 to &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/b51a60734da64be0e618bacbea2865a8a7dcd669.svg" style="height: 12px;" type="image/svg+xml"&gt;N&lt;/object&gt;, or from 2 to &lt;object class="valign-m1 latex-math" data="https://eli.thegreenplace.net/images/math/4bbff46d5e4a2066e44932399c1db699e807cf39.svg" style="height: 14px;" type="image/svg+xml"&gt;N+1&lt;/object&gt;, and so
on. All of these orders will enumerate all distinct &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/ce4de0873a5958646dce9993ddaba5d4511d8b2d.svg" style="height: 16px;" type="image/svg+xml"&gt;\phi_k&lt;/object&gt;.&lt;/p&gt;
&lt;p&gt;Going back to our linear combination:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/60c500ee298bcca4f6a719dff3b72b2ecb114fda.svg" style="height: 44px;" type="image/svg+xml"&gt;\[x[n]=\sum_{k=\langle N\rangle}a_k\phi_k[n]=\sum_{k=\langle N\rangle}a_ke^{ikw_0n}\]&lt;/object&gt;
&lt;p&gt;This is the discrete-time Fourier series (DTFS) representation of
&lt;object class="valign-m5 latex-math" data="https://eli.thegreenplace.net/images/math/97897883b2ac574b045db012a128c024c5a05498.svg" style="height: 18px;" type="image/svg+xml"&gt;x[n]&lt;/object&gt; and the coefficients &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/b93e6f239fad8d0444d74634490a6e0e067b8954.svg" style="height: 11px;" type="image/svg+xml"&gt;a_k&lt;/object&gt; are the Fourier series
coefficients. Note that there are no convergence issues as in the
continuous case, because we’re dealing with a finite sum.&lt;/p&gt;
&lt;p&gt;To find the coefficients &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/b93e6f239fad8d0444d74634490a6e0e067b8954.svg" style="height: 11px;" type="image/svg+xml"&gt;a_k&lt;/object&gt;, we’ll proceed in a way that’s
somewhat similar to the continuous case. Multiply both sides of the
equation above by &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/4bd537f689b1c8840838d523803661568c9fafda.svg" style="height: 16px;" type="image/svg+xml"&gt;e^{-ir(2\pi/N)n}&lt;/object&gt; and sum over &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/b51a60734da64be0e618bacbea2865a8a7dcd669.svg" style="height: 12px;" type="image/svg+xml"&gt;N&lt;/object&gt; terms:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/3ffeb7c8c33c990b9f29376bd6f897597e3d06b4.svg" style="height: 44px;" type="image/svg+xml"&gt;\[\sum_{n=\langle N\rangle}x[n]e^{-ir(2\pi/N)n}=
\sum_{n=\langle N\rangle}\sum_{k=\langle N\rangle}a_ke^{i(k-r)(2\pi/N)n}\]&lt;/object&gt;
&lt;p&gt;Interchanging the order of summation on the right-hand side:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/9804b43fc55e5f192b10cb39e6eb9a084be50542.svg" style="height: 44px;" type="image/svg+xml"&gt;\[\sum_{n=\langle N\rangle}x[n]e^{-ir(2\pi/N)n}=
\sum_{k=\langle N\rangle}a_k\sum_{n=\langle N\rangle}e^{i(k-r)(2\pi/N)n}\]&lt;/object&gt;
&lt;p&gt;By Appendix B, the inner sum on the right-hand side is equal to
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/b51a60734da64be0e618bacbea2865a8a7dcd669.svg" style="height: 12px;" type="image/svg+xml"&gt;N&lt;/object&gt; when &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/0fcd76904fe07394bb05ec64895cdeb8f8515a9d.svg" style="height: 18px;" type="image/svg+xml"&gt;N\mid r-k&lt;/object&gt; and to 0 otherwise. Without loss of
generality - since we iterate over &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/b51a60734da64be0e618bacbea2865a8a7dcd669.svg" style="height: 12px;" type="image/svg+xml"&gt;N&lt;/object&gt; consecutive values - let’s
just assume this happens in our sum when &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/6bfa11b94d344c093694a5e5c0c226bd7bb67deb.svg" style="height: 12px;" type="image/svg+xml"&gt;r=k&lt;/object&gt; (and therefore
&lt;object class="valign-m1 latex-math" data="https://eli.thegreenplace.net/images/math/7bfafe6ba7d6a147468ce3ae51ef134705ea6190.svg" style="height: 14px;" type="image/svg+xml"&gt;r-k=0&lt;/object&gt;, which is an integer multiple of &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/b51a60734da64be0e618bacbea2865a8a7dcd669.svg" style="height: 12px;" type="image/svg+xml"&gt;N&lt;/object&gt;).&lt;/p&gt;
&lt;p&gt;So our equation becomes:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/aeca1db09dfaab4c07ac592863fdf8918e7e205a.svg" style="height: 44px;" type="image/svg+xml"&gt;\[\sum_{n=\langle N\rangle}x[n]e^{-ir(2\pi/N)n}=a_r N\]&lt;/object&gt;
&lt;p&gt;Or:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/725df9008f33e0060b10f1f261198885af42c03f.svg" style="height: 49px;" type="image/svg+xml"&gt;\[a_r=\frac{1}{N}\sum_{n=\langle N\rangle}x[n]e^{-ir(2\pi/N)n}\]&lt;/object&gt;
&lt;p&gt;To conclude, the Fourier decomposition of a periodic discrete signal
&lt;object class="valign-m5 latex-math" data="https://eli.thegreenplace.net/images/math/97897883b2ac574b045db012a128c024c5a05498.svg" style="height: 18px;" type="image/svg+xml"&gt;x[n]&lt;/object&gt; into periodic complex exponentials is:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/945f40a89aa021441ed20fcfa8b08f4fa7fb1ad5.svg" style="height: 138px;" type="image/svg+xml"&gt;\[\boxed{
\begin{aligned}
    x[n]&amp;amp;=\sum_{k=\langle N\rangle}a_k e^{ik(2\pi/N)n}\\
    \vspace{2pt}\\
    a_k&amp;amp;=\frac{1}{N}\sum_{n=\langle N\rangle}x[n]e^{-ik(2\pi/N)n}
\end{aligned}
}\]&lt;/object&gt;
&lt;/div&gt;
&lt;div class="section" id="example-revisiting-the-triangular-function"&gt;
&lt;h2&gt;Example: revisiting the triangular function&lt;/h2&gt;
&lt;p&gt;Let’s revisit the triangular function &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/75a7147566fd4ba98fe5d85fe008fab6d58d3968.svg" style="height: 17px;" type="image/svg+xml"&gt;t(x)&lt;/object&gt; from &lt;a class="reference external" href="https://eli.thegreenplace.net/2026/notes-on-fourier-series"&gt;the post on
Fourier
series&lt;/a&gt;.
Here, we’ll be using the following &lt;em&gt;sampled&lt;/em&gt; version:&lt;/p&gt;
&lt;div class="fourier-plot-wrap"&gt;
  &lt;canvas id="sampled-triangle" class="fourier-plot-canvas" width="760" height="510"&gt;
  Your browser does not support the HTML5 canvas tag.
  &lt;/canvas&gt;
&lt;/div&gt;&lt;p&gt;The sampling is done with 12 samples per period of 4. The spacing
between two samples is &lt;object class="valign-m6 latex-math" data="https://eli.thegreenplace.net/images/math/13b32fa8a41892c1a019dab0362e6d9d405155a2.svg" style="height: 21px;" type="image/svg+xml"&gt;\Delta x=\frac{1}{3}&lt;/object&gt;. Another way to
express it:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/8d255b5d4fbff6cfe08740d3fac99376d86cb10f.svg" style="height: 18px;" type="image/svg+xml"&gt;\[t_d[n]=t(n/3)\]&lt;/object&gt;
&lt;p&gt;Substituting this into the definition of &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/75a7147566fd4ba98fe5d85fe008fab6d58d3968.svg" style="height: 17px;" type="image/svg+xml"&gt;t(x)&lt;/object&gt;, we get:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/cb846a2c9318006c0154c8027430ff79e8dfa895.svg" style="height: 54px;" type="image/svg+xml"&gt;\[t_d[n]=
\begin{cases}
    \frac{n}{3}     &amp;amp;  0 \leq n \leq 3 \\
    2-\frac{n}{3}   &amp;amp;  3 &amp;lt; n \leq 6  \\
\end{cases}\]&lt;/object&gt;
&lt;p&gt;We then do an odd extension &lt;a class="footnote-reference" href="#footnote-2" id="footnote-reference-2"&gt;[2]&lt;/a&gt; to the range &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/bc0e87f5ff28e46cb89d0658c909161ece916b88.svg" style="height: 18px;" type="image/svg+xml"&gt;n=[6..12)&lt;/object&gt;, and
repeat it with period &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/29fc4a36d13899104899f4ab4d5c8ce2a63aba4d.svg" style="height: 12px;" type="image/svg+xml"&gt;N=12&lt;/object&gt;.&lt;/p&gt;
&lt;p&gt;Using considerations similar to the &lt;a class="reference external" href="https://eli.thegreenplace.net/2026/notes-on-fourier-series/"&gt;continuous time
case&lt;/a&gt;,
because our function is odd we just need a sine series here:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/8785494695502450d002402ca913063457868572.svg" style="height: 52px;" type="image/svg+xml"&gt;\[t_d[n]=\sum_{k=1}^{5}b_k sin\frac{k\pi n}{6}\]&lt;/object&gt;
&lt;p&gt;The five terms correspond to the five pairs of nonzero-frequency
indices; see Appendix C.&lt;/p&gt;
&lt;p&gt;And the coefficients are:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/f7d0d38c795dd2579f2f787a52e0c929362146bb.svg" style="height: 51px;" type="image/svg+xml"&gt;\[b_k=\frac{1}{6}\sum_{n=0}^{11}t_d[n]sin\frac{k\pi n}{6}\\\]&lt;/object&gt;
&lt;p&gt;We can run this sum over half the period, because the terms at &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt;
and &lt;object class="valign-m1 latex-math" data="https://eli.thegreenplace.net/images/math/a57fdf4a737281653331838e54c1f649f3aef0ab.svg" style="height: 13px;" type="image/svg+xml"&gt;12-n&lt;/object&gt; are equal (both &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/b2c6547bf744e9cad27f25ea4a538006b5e10df1.svg" style="height: 18px;" type="image/svg+xml"&gt;t_d[n]&lt;/object&gt; and the sine change
signs). Also, the terms at &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/bfbd617aa9bc9d5a8b0b006de9d1d45d8e688c8d.svg" style="height: 11px;" type="image/svg+xml"&gt;n=0&lt;/object&gt; and &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/fd917de64a52110443142df37dfb4c646c895ca0.svg" style="height: 12px;" type="image/svg+xml"&gt;n=6&lt;/object&gt; vanish because
&lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/e3c78f2af1b33eec6a99870e066384434b712b41.svg" style="height: 18px;" type="image/svg+xml"&gt;t_d[0]=t_d[6]=0&lt;/object&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/3cdf6806c737e14fb49307ffef19344a949cc809.svg" style="height: 51px;" type="image/svg+xml"&gt;\[b_k=\frac{1}{3}\sum_{n=1}^{5}t_d[n]sin\frac{k\pi n}{6}\\\]&lt;/object&gt;
&lt;p&gt;Looking at the values of &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/6c703960ebb50c648ed2886b17158571a96dd773.svg" style="height: 14px;" type="image/svg+xml"&gt;t_d&lt;/object&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/0cfe030d1da24fd3e0c7306c19bd6e3f5ba9437b.svg" style="height: 45px;" type="image/svg+xml"&gt;\[b_1=\frac{1}{3}\left(\frac{1}{3}sin\frac{\pi}{6}+\frac{2}{3}sin\frac{2\pi}{6}+sin\frac{3\pi}{6}+\frac{2}{3}sin\frac{4\pi}{6}+\frac{1}{3}sin\frac{\pi}{6}\right)=\frac{4+2\sqrt{3}}{9}\]&lt;/object&gt;
&lt;p&gt;We can similarly calculate all &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/3b3f66f8c1dafc487acd2b86ecf65def380b2314.svg" style="height: 15px;" type="image/svg+xml"&gt;b_k&lt;/object&gt; until &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/146fe9d1591e99d78c5be44a6b0f0afc608b0735.svg" style="height: 12px;" type="image/svg+xml"&gt;k=5&lt;/object&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/025a84bb16cfb0037bc990691f9c498eafc231a9.svg" style="height: 180px;" type="image/svg+xml"&gt;\[\begin{aligned}
    b_1&amp;amp;=\frac{4+2\sqrt{3}}{9}\\
    b_2&amp;amp;=0\\
    b_3&amp;amp;=-\frac{1}{9}\\
    b_4&amp;amp;=0\\
    b_5&amp;amp;=\frac{4-2\sqrt{3}}{9}\\
\end{aligned}\]&lt;/object&gt;
&lt;p&gt;The resulting Fourier series is therefore:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/360fb6d0e15c3f648f39813083cd487a7ebc118c.svg" style="height: 40px;" type="image/svg+xml"&gt;\[t_d[n]=\frac{4+2\sqrt{3}}{9}sin\frac{\pi n}{6}-\frac{1}{9}sin\frac{\pi n}{2}+\frac{4-2\sqrt{3}}{9}sin\frac{5\pi n}{6}\]&lt;/object&gt;
&lt;p&gt;You can use the following interactive plot to explore this approximation
to the discrete triangle function &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/b2c6547bf744e9cad27f25ea4a538006b5e10df1.svg" style="height: 18px;" type="image/svg+xml"&gt;t_d[n]&lt;/object&gt;:&lt;/p&gt;
&lt;div class="fourier-plot-wrap"&gt;
&lt;canvas id="sampled-triangle-fourier" class="fourier-plot-canvas" width="760" height="510" role="img"&gt;
Your browser does not support the HTML5 canvas tag.
&lt;/canvas&gt;
&lt;div class="fourier-plot-controls"&gt;
  &lt;label class="fourier-plot-label" for="terms"&gt;Terms in the Fourier series
    &lt;select id="terms" class="fourier-plot-input"&gt;
      &lt;option value="1"&gt;1&lt;/option&gt;
      &lt;option value="2"&gt;2&lt;/option&gt;
      &lt;option value="3"&gt;3&lt;/option&gt;
    &lt;/select&gt;
  &lt;/label&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;The dropdown box selects how many of the terms in the series shown above
to plot. The orange crosses show where the series’ values at the integer
indices are, and the orange line is interpolated to better visualize the
sine waves being added. Note that when all the coefficients are used,
the DTFS &lt;em&gt;exactly&lt;/em&gt; reconstructs the input signal.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="discrete-time-fourier-transform-dtft"&gt;
&lt;h2&gt;Discrete-time Fourier Transform (DTFT)&lt;/h2&gt;
&lt;p&gt;In the post on &lt;a class="reference external" href="https://eli.thegreenplace.net/2026/notes-on-the-fourier-transform/"&gt;the Fourier
Transform&lt;/a&gt;
we’ve seen how non-periodic signals can be represented in the frequency
domain by taking the Fourier series and calculating them at the limit
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/7024b94c8e1c4e174500651fed6f4034b91338e2.svg" style="height: 12px;" type="image/svg+xml"&gt;L\rightarrow\infty&lt;/object&gt;. Here, we’ll do something similar for
discrete signals.&lt;/p&gt;
&lt;p&gt;Suppose we have a non-periodic discrete signal &lt;object class="valign-m5 latex-math" data="https://eli.thegreenplace.net/images/math/97897883b2ac574b045db012a128c024c5a05498.svg" style="height: 18px;" type="image/svg+xml"&gt;x[n]&lt;/object&gt; of finite
duration (it’s zero outside a finite range of indices). Here’s a sample
plot:&lt;/p&gt;
&lt;div class="fourier-plot-wrap"&gt;
  &lt;canvas id="sampled-triangle-single-cycle" class="fourier-plot-canvas" width="760" height="660" role="img"&gt;
  Your browser does not support the HTML5 canvas tag.
  &lt;/canvas&gt;
&lt;/div&gt;&lt;p&gt;The bottom half is &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/c6df076ab603be3c2cbc4b1d6d092e640b77e29b.svg" style="height: 18px;" type="image/svg+xml"&gt;x_N[n]&lt;/object&gt; - a periodic signal, one period
(&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/b51a60734da64be0e618bacbea2865a8a7dcd669.svg" style="height: 12px;" type="image/svg+xml"&gt;N&lt;/object&gt;) of which is equal to &lt;object class="valign-m5 latex-math" data="https://eli.thegreenplace.net/images/math/97897883b2ac574b045db012a128c024c5a05498.svg" style="height: 18px;" type="image/svg+xml"&gt;x[n]&lt;/object&gt;. We choose &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/c63ae6dd4fc9f9dda66970e827d13f7c73fe841c.svg" style="height: 12px;" type="image/svg+xml"&gt;M&lt;/object&gt; large
enough that &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/4f69300aeca511bb7959f0d5aff5e33ed79f99b9.svg" style="height: 18px;" type="image/svg+xml"&gt;x[n]=0&lt;/object&gt; outside &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/506ae4d92172f3c5ce809ecedd25641313a8b1be.svg" style="height: 18px;" type="image/svg+xml"&gt;[-M,M]&lt;/object&gt; and set
&lt;object class="valign-m1 latex-math" data="https://eli.thegreenplace.net/images/math/7648c8206c068d4af6259b746a017a4db66b1ad3.svg" style="height: 14px;" type="image/svg+xml"&gt;N=2M+1&lt;/object&gt;.&lt;/p&gt;
&lt;p&gt;Since &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/e3c3a8503e4f75a769e8bfe1a0aacda6768f9fdc.svg" style="height: 10px;" type="image/svg+xml"&gt;x_N&lt;/object&gt; is periodic, we can represent it with DTFS &lt;a class="footnote-reference" href="#footnote-3" id="footnote-reference-3"&gt;[3]&lt;/a&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/7655e9e51d27c95ec2f109c7991133a220d036b6.svg" style="height: 116px;" type="image/svg+xml"&gt;\[\begin{aligned}
    x_N[n]&amp;amp;=\sum_{k=-M}^{M}a_k e^{ik(2\pi/N)n}\\
    a_k&amp;amp;=\frac{1}{N}\sum_{n=-M}^{M}x[n]e^{-ik(2\pi/N)n}
\end{aligned}\]&lt;/object&gt;
&lt;p&gt;We’ll use the notation of angular frequency:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/5863471c15fd749d07460da1cd5555373a479bee.svg" style="height: 36px;" type="image/svg+xml"&gt;\[\Delta w=\frac{2\pi}{N}\qquad w_k=k\Delta w\]&lt;/object&gt;
&lt;p&gt;Then:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/d60f037fdf97691796d26081748cfc9075bae414.svg" style="height: 116px;" type="image/svg+xml"&gt;\[\begin{aligned}
    x_N[n]&amp;amp;=\sum_{k=-M}^{M}a_k e^{i w_k n}\\
    a_k&amp;amp;=\frac{1}{N}\sum_{n=-M}^{M}x[n]e^{-i w_k n}
\end{aligned}\]&lt;/object&gt;
&lt;p&gt;Now the critical part; since &lt;object class="valign-m5 latex-math" data="https://eli.thegreenplace.net/images/math/97897883b2ac574b045db012a128c024c5a05498.svg" style="height: 18px;" type="image/svg+xml"&gt;x[n]&lt;/object&gt; is zero outside
&lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/506ae4d92172f3c5ce809ecedd25641313a8b1be.svg" style="height: 18px;" type="image/svg+xml"&gt;[-M,M]&lt;/object&gt;, extending the summation to all integers does not change
its value:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/651bf87714366d89832fc83ad2f37727771e1ed6.svg" style="height: 50px;" type="image/svg+xml"&gt;\[a_k=\frac{1}{N}\sum_{n=-\infty}^{\infty}x[n]e^{-i w_k n}\]&lt;/object&gt;
&lt;p&gt;We’ll define the following &lt;em&gt;continuous&lt;/em&gt; function with variable
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/aff024fe4ab0fece4091de044c58c9ae4233383a.svg" style="height: 8px;" type="image/svg+xml"&gt;w&lt;/object&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/12e943c782c2b7d52bc4af24f03889a7a390c800.svg" style="height: 50px;" type="image/svg+xml"&gt;\[X(w)=\sum_{n=-\infty}^{\infty}x[n]e^{-i w n}\]&lt;/object&gt;
&lt;p&gt;Then at points &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/3d49dd4dad59a3db42b484b5bd2c815d00f63747.svg" style="height: 10px;" type="image/svg+xml"&gt;w_k&lt;/object&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/2410280553643c2394bb40d31177935f81116b78.svg" style="height: 36px;" type="image/svg+xml"&gt;\[a_k=\frac{1}{N}X(w_k)\]&lt;/object&gt;
&lt;p&gt;The function &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/634ff97b7c8940e499bad1f419482d41f5985e75.svg" style="height: 18px;" type="image/svg+xml"&gt;X(w)&lt;/object&gt; is the discrete-time Fourier transform (DTFT)
of &lt;object class="valign-m5 latex-math" data="https://eli.thegreenplace.net/images/math/97897883b2ac574b045db012a128c024c5a05498.svg" style="height: 18px;" type="image/svg+xml"&gt;x[n]&lt;/object&gt;. The inverse DTFT process reconstructs &lt;object class="valign-m5 latex-math" data="https://eli.thegreenplace.net/images/math/97897883b2ac574b045db012a128c024c5a05498.svg" style="height: 18px;" type="image/svg+xml"&gt;x[n]&lt;/object&gt; from
&lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/634ff97b7c8940e499bad1f419482d41f5985e75.svg" style="height: 18px;" type="image/svg+xml"&gt;X(w)&lt;/object&gt;, by substituting &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/b93e6f239fad8d0444d74634490a6e0e067b8954.svg" style="height: 11px;" type="image/svg+xml"&gt;a_k&lt;/object&gt; back into the DTFS:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/3862d71c50490b1f847db8a0d6d73d3edbf1ef59.svg" style="height: 54px;" type="image/svg+xml"&gt;\[x_N[n]=\sum_{k=-M}^{M}\frac{1}{N}X(w_k) e^{i w_k n}\]&lt;/object&gt;
&lt;p&gt;By our definition of &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/485c352e1532df3fe1ad52c8ac1ec6cdcefae85f.svg" style="height: 12px;" type="image/svg+xml"&gt;\Delta w&lt;/object&gt;, we have:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/03df7807d548c507c064153f90c03c9a563c0805.svg" style="height: 37px;" type="image/svg+xml"&gt;\[\frac{1}{N}=\frac{\Delta w}{2\pi}\]&lt;/object&gt;
&lt;p&gt;Therefore:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/4a8494e729e71cda8a0a755ccda0efc956b18e23.svg" style="height: 54px;" type="image/svg+xml"&gt;\[x_N[n]=\frac{1}{2\pi}\sum_{k=-M}^{M}X(w_k) e^{i w_k n}\Delta w\]&lt;/object&gt;
&lt;p&gt;Just like in the continuous case, we recognize the sum as a &lt;em&gt;Riemann
sum&lt;/em&gt;. Let &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/e25aba83bff23dbc0999183f7c3336fbbd597321.svg" style="height: 12px;" type="image/svg+xml"&gt;M\rightarrow\infty&lt;/object&gt;. The spacing &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/485c352e1532df3fe1ad52c8ac1ec6cdcefae85f.svg" style="height: 12px;" type="image/svg+xml"&gt;\Delta w&lt;/object&gt; tends
to zero, and we can rewrite the sum as an integral:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/4439fc58730a31e2dd28d6ebda63260268060e11.svg" style="height: 43px;" type="image/svg+xml"&gt;\[x[n]=\lim_{M\rightarrow\infty}x_N[n]=\frac{1}{2\pi}\int_{-\pi}^{\pi}X(w)e^{iwn}dw\]&lt;/object&gt;
&lt;p&gt;To conclude, the DTFT and inverse DTFT pair are:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/30a15dc5e03b381e24ac86dd31144dcbbe0d7687.svg" style="height: 137px;" type="image/svg+xml"&gt;\[\boxed{
    \begin{aligned}
        X(w)&amp;amp;=\sum_{n=-\infty}^{\infty}x[n]e^{-i w n}\\
        \vspace{2pt}\\
        x[n]&amp;amp;=\frac{1}{2\pi}\int_{-\pi}^{\pi}X(w)e^{iwn}dw
    \end{aligned}
}\]&lt;/object&gt;
&lt;p&gt;&lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/634ff97b7c8940e499bad1f419482d41f5985e75.svg" style="height: 18px;" type="image/svg+xml"&gt;X(w)&lt;/object&gt; is a continuous, periodic function with period
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/0833718ca4569f36e84dbdc7742eaec65e49b150.svg" style="height: 11px;" type="image/svg+xml"&gt;2\pi&lt;/object&gt;, because:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/c03a305933e7f52bce45ca16a618ebf03bf0e70c.svg" style="height: 167px;" type="image/svg+xml"&gt;\[\begin{aligned}
    X(w+2\pi)&amp;amp;=\sum_{n=-\infty}^{\infty}x[n]e^{-i (w+2\pi) n}\\
    &amp;amp;=\sum_{n=-\infty}^{\infty}x[n]e^{-i w n}e^{-i 2\pi n}\\
    &amp;amp;=\sum_{n=-\infty}^{\infty}x[n]e^{-i w n}=X(w)\\
\end{aligned}\]&lt;/object&gt;
&lt;p&gt;Therefore, it’s enough to run the integral on any interval of length
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/0833718ca4569f36e84dbdc7742eaec65e49b150.svg" style="height: 11px;" type="image/svg+xml"&gt;2\pi&lt;/object&gt;.&lt;/p&gt;
&lt;p&gt;The DTFS and DTFT are closely related. Starting with a finite-duration
signal &lt;object class="valign-m5 latex-math" data="https://eli.thegreenplace.net/images/math/97897883b2ac574b045db012a128c024c5a05498.svg" style="height: 18px;" type="image/svg+xml"&gt;x[n]&lt;/object&gt;, we form a periodic signal by repeating a block of
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/b51a60734da64be0e618bacbea2865a8a7dcd669.svg" style="height: 12px;" type="image/svg+xml"&gt;N&lt;/object&gt; samples containing it. Its DTFS coefficients are equally
spaced, scaled samples of the DTFT:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/b992961b96d8a9a9826ee6a62f6b4adf636f54b2.svg" style="height: 43px;" type="image/svg+xml"&gt;\[a_k=\frac{1}{N}X\left(\frac{2\pi k}{N}\right)\]&lt;/object&gt;
&lt;p&gt;The relation is similar to the one between Fourier series and the
Fourier transform in the continuous case.&lt;/p&gt;
&lt;p&gt;The DTFT also has useful properties similar to the continuous Fourier
transform: linearity, time shifting, the convolution theorem etc, but we
won’t spend time on them here.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="appendix-a-discrete-time-complex-exponentials"&gt;
&lt;h2&gt;Appendix A: Discrete-time complex exponentials&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Note&lt;/em&gt;: for this and the next appendix, see the later post on the
&lt;a class="reference external" href="https://eli.thegreenplace.net/2026/notes-on-the-complex-roots-of-unity/"&gt;complex roots of unity&lt;/a&gt; for additional background.&lt;/p&gt;
&lt;p&gt;Discrete-time complex exponentials have the form &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/7fd6adcf6eb2206420843202395b5e7971111935.svg" style="height: 15px;" type="image/svg+xml"&gt;e^{iw_0n}&lt;/object&gt; where
&lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/6950ac388dc5e1d03924e0c4e7875931b7774abf.svg" style="height: 10px;" type="image/svg+xml"&gt;w_0&lt;/object&gt; is the &lt;em&gt;angular frequency&lt;/em&gt;. The discrete nature of these
functions leads to some interesting outcomes; for example, consider the
exponential with angular frequency &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/11d5a9c41c6b478b606c650d1677cd48ff4381f7.svg" style="height: 14px;" type="image/svg+xml"&gt;w_0+2\pi&lt;/object&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/0e8282dc16ccb8d86eb4bcc5537f678aac1825d2.svg" style="height: 17px;" type="image/svg+xml"&gt;\[e^{i(w_0+2\pi)n}=e^{iw_0n}e^{i2\pi n}=e^{iw_0n}\]&lt;/object&gt;
&lt;p&gt;Therefore, the exponential at &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/11d5a9c41c6b478b606c650d1677cd48ff4381f7.svg" style="height: 14px;" type="image/svg+xml"&gt;w_0+2\pi&lt;/object&gt; is &lt;em&gt;exactly the same&lt;/em&gt; as
the exponential at &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/6950ac388dc5e1d03924e0c4e7875931b7774abf.svg" style="height: 10px;" type="image/svg+xml"&gt;w_0&lt;/object&gt;. In considering discrete complex
exponentials, we need only choose &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/6950ac388dc5e1d03924e0c4e7875931b7774abf.svg" style="height: 10px;" type="image/svg+xml"&gt;w_0&lt;/object&gt; from a range of length
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/0833718ca4569f36e84dbdc7742eaec65e49b150.svg" style="height: 11px;" type="image/svg+xml"&gt;2\pi&lt;/object&gt;.&lt;/p&gt;
&lt;p&gt;Another interesting aspect of these functions concerns their
periodicity. In order for &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/7fd6adcf6eb2206420843202395b5e7971111935.svg" style="height: 15px;" type="image/svg+xml"&gt;e^{iw_0n}&lt;/object&gt; to be periodic with some
positive integer period &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/b51a60734da64be0e618bacbea2865a8a7dcd669.svg" style="height: 12px;" type="image/svg+xml"&gt;N&lt;/object&gt;, the following must hold:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/68f3400d73ba76397c3a61bc1adb9e1fdfadd26a.svg" style="height: 17px;" type="image/svg+xml"&gt;\[e^{iw_0(n+N)}=e^{iw_0n}\]&lt;/object&gt;
&lt;p&gt;In other words:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/1b3ebb4ad3d3eec0bf3cd4b699ee3c366cca4e18.svg" style="height: 16px;" type="image/svg+xml"&gt;\[e^{iw_0N}=1\]&lt;/object&gt;
&lt;p&gt;So &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/d08b73152a14ec2be0f693981bc9c49cf2d539c8.svg" style="height: 15px;" type="image/svg+xml"&gt;w_0N&lt;/object&gt; itself must be an integral multiple of &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/0833718ca4569f36e84dbdc7742eaec65e49b150.svg" style="height: 11px;" type="image/svg+xml"&gt;2\pi&lt;/object&gt;. For
some integer &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/13fbd79c3d390e5d6585a21e11ff5ec1970cff0c.svg" style="height: 12px;" type="image/svg+xml"&gt;k&lt;/object&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/a9ac703fbfa53f089a336b9a0c160d74a3e27183.svg" style="height: 37px;" type="image/svg+xml"&gt;\[w_0N=k\cdot(2\pi)\Longrightarrow w_0=\frac{k2\pi}{N}\]&lt;/object&gt;
&lt;p&gt;For a fixed positive integer &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/b51a60734da64be0e618bacbea2865a8a7dcd669.svg" style="height: 12px;" type="image/svg+xml"&gt;N&lt;/object&gt;, let’s consider all complex
exponentials for which &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/b51a60734da64be0e618bacbea2865a8a7dcd669.svg" style="height: 12px;" type="image/svg+xml"&gt;N&lt;/object&gt; is a period:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/fa894357b1a5788b91ab60893cdeb9067bc65b87.svg" style="height: 21px;" type="image/svg+xml"&gt;\[\phi_k[n]=e^{ik(2\pi/N)n}\qquad \forall k\in\mathbb{Z}\]&lt;/object&gt;
&lt;p&gt;But earlier we’ve said that all complex exponentials with angular
frequencies &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/0833718ca4569f36e84dbdc7742eaec65e49b150.svg" style="height: 11px;" type="image/svg+xml"&gt;2\pi&lt;/object&gt; apart are identical. This means that the set
above consists of only &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/b51a60734da64be0e618bacbea2865a8a7dcd669.svg" style="height: 12px;" type="image/svg+xml"&gt;N&lt;/object&gt; distinct exponentials. We can choose
any starting &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/13fbd79c3d390e5d6585a21e11ff5ec1970cff0c.svg" style="height: 12px;" type="image/svg+xml"&gt;k&lt;/object&gt; and get distinct signals with &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/13fbd79c3d390e5d6585a21e11ff5ec1970cff0c.svg" style="height: 12px;" type="image/svg+xml"&gt;k&lt;/object&gt;,
&lt;object class="valign-m1 latex-math" data="https://eli.thegreenplace.net/images/math/8d2d1975719162e2210a96c3bd5bebfdf42caa9b.svg" style="height: 14px;" type="image/svg+xml"&gt;k+1&lt;/object&gt;, &lt;object class="valign-m1 latex-math" data="https://eli.thegreenplace.net/images/math/f61af7574246ba464c7161afc0cddb3dc1b11267.svg" style="height: 14px;" type="image/svg+xml"&gt;k+2&lt;/object&gt; and so on until &lt;object class="valign-m1 latex-math" data="https://eli.thegreenplace.net/images/math/cef9dc4c07e239fd0ddcc7676f56668ca0151099.svg" style="height: 14px;" type="image/svg+xml"&gt;k+N-1&lt;/object&gt;. After that, they
begin repeating: &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/1e420e19bf305c8715608dbf062a60159dfbdc2a.svg" style="height: 18px;" type="image/svg+xml"&gt;\phi_N[n]=\phi_0[n]&lt;/object&gt; and so on.&lt;/p&gt;
&lt;p&gt;All of this is very different from the continuous case, where &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/8efd86fb78a56a5145ed7739dcb00c78581c5375.svg" style="height: 11px;" type="image/svg+xml"&gt;t&lt;/object&gt;
is a real number. The signals &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/28d243e6888f4bc4a0fc32b9f7af2a2ffa7f8c89.svg" style="height: 15px;" type="image/svg+xml"&gt;e^{iw_0t}&lt;/object&gt; and
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/9075753c0861695d1e91cec2d6932e06acd4bda6.svg" style="height: 16px;" type="image/svg+xml"&gt;e^{i(w_0+2\pi)t}&lt;/object&gt; agree only at integer values of &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/8efd86fb78a56a5145ed7739dcb00c78581c5375.svg" style="height: 11px;" type="image/svg+xml"&gt;t&lt;/object&gt;, so
they are distinct functions of &lt;object class="valign-m1 latex-math" data="https://eli.thegreenplace.net/images/math/9eae9191c02b6e7957862fc2401767c5f8b69547.svg" style="height: 13px;" type="image/svg+xml"&gt;t\in\mathbb{R}&lt;/object&gt;. Consequently, for
a fixed positive period &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/c2c53d66948214258a26ca9ca845d7ac0c17f8e7.svg" style="height: 12px;" type="image/svg+xml"&gt;T&lt;/object&gt;, the continuous-time exponentials
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/041cda9e66d700c462a028de0f417be881e8e073.svg" style="height: 16px;" type="image/svg+xml"&gt;e^{ik(2\pi/T)t}&lt;/object&gt; are distinct for every integer &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/13fbd79c3d390e5d6585a21e11ff5ec1970cff0c.svg" style="height: 12px;" type="image/svg+xml"&gt;k&lt;/object&gt;, giving
infinitely many distinct signals.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="appendix-b-sum-of-consecutive-complex-exponentials"&gt;
&lt;h2&gt;Appendix B: Sum of consecutive complex exponentials&lt;/h2&gt;
&lt;p&gt;Let’s consider the following discrete function, defined by a sum:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/33a6c380ddeed86ef34e7e6583ca60f6d0bb642f.svg" style="height: 52px;" type="image/svg+xml"&gt;\[A[k]=\sum_{n=0}^{N-1}e^{i(2\pi/N)kn}\]&lt;/object&gt;
&lt;p&gt;We’ll want to consider two cases:&lt;/p&gt;
&lt;p&gt;(1) When &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/13fbd79c3d390e5d6585a21e11ff5ec1970cff0c.svg" style="height: 12px;" type="image/svg+xml"&gt;k&lt;/object&gt; is an integer multiple of &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/b51a60734da64be0e618bacbea2865a8a7dcd669.svg" style="height: 12px;" type="image/svg+xml"&gt;N&lt;/object&gt;: &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/e1f10f9c84c6289cd8a4279a240c098df07b22fa.svg" style="height: 12px;" type="image/svg+xml"&gt;k=rN&lt;/object&gt; for
some integer &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/4dc7c9ec434ed06502767136789763ec11d2c4b7.svg" style="height: 8px;" type="image/svg+xml"&gt;r&lt;/object&gt; (for example &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/02f5d048ae1528ddfe91661c25c64469d096dd42.svg" style="height: 12px;" type="image/svg+xml"&gt;k=0&lt;/object&gt;, &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/84b1f89229e29e995deb4370c612a9f76e24a2f7.svg" style="height: 12px;" type="image/svg+xml"&gt;k=N&lt;/object&gt;,
&lt;object class="valign-m1 latex-math" data="https://eli.thegreenplace.net/images/math/fec2b67cd1bb34d1d2338637374b8c4c86b0162b.svg" style="height: 14px;" type="image/svg+xml"&gt;k=-2N&lt;/object&gt; etc.)&lt;/p&gt;
&lt;p&gt;In this case, the sum becomes:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/914ae21c02d6c49cdbc4eafd92329769c87fee81.svg" style="height: 52px;" type="image/svg+xml"&gt;\[A[k]=\sum_{n=0}^{N-1}e^{i(2\pi/N)rNn}=\sum_{n=0}^{N-1}e^{i2\pi rn}\]&lt;/object&gt;
&lt;p&gt;Since both &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/4dc7c9ec434ed06502767136789763ec11d2c4b7.svg" style="height: 8px;" type="image/svg+xml"&gt;r&lt;/object&gt; and &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt; are integers, the exponent is an
integer multiple of &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d2a8e570b43fb5570c95c42925813186ac2ea038.svg" style="height: 12px;" type="image/svg+xml"&gt;2\pi i&lt;/object&gt;, so:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/118bd1b6b3654c8e6847db1fe680270692bc2108.svg" style="height: 52px;" type="image/svg+xml"&gt;\[A[k]=\sum_{n=0}^{N-1}1=N\]&lt;/object&gt;
&lt;p&gt;(2) When &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/13fbd79c3d390e5d6585a21e11ff5ec1970cff0c.svg" style="height: 12px;" type="image/svg+xml"&gt;k&lt;/object&gt; is not an integer multiple of &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/b51a60734da64be0e618bacbea2865a8a7dcd669.svg" style="height: 12px;" type="image/svg+xml"&gt;N&lt;/object&gt;, let’s do a
variable change &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/b723abdc2defc33a8cb6711523ebb1e84e78761d.svg" style="height: 15px;" type="image/svg+xml"&gt;p=n+1&lt;/object&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/b7d825bbc662795d58217b17d9620f862fce599d.svg" style="height: 54px;" type="image/svg+xml"&gt;\[A[k]=\sum_{p=1}^{N}e^{i(2\pi/N)k(p-1)}\]&lt;/object&gt;
&lt;p&gt;We can now use the finite sum formula for a geometric progression with
the common ratio &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/f4dab53801ba436b1f7b4648aaeb33ba8e4415bc.svg" style="height: 16px;" type="image/svg+xml"&gt;r=e^{i(2\pi/N)k}&lt;/object&gt;; the sum is:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/c391f9689c3c8d921b2f4ef726abe50d147365b2.svg" style="height: 41px;" type="image/svg+xml"&gt;\[S_N=\frac{1-r^N}{1-r}\]&lt;/object&gt;
&lt;p&gt;Note that &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/a492f6aa77feab0fbe5517ba5401340ff9e1ada1.svg" style="height: 16px;" type="image/svg+xml"&gt;r\neq 1&lt;/object&gt; because &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/13fbd79c3d390e5d6585a21e11ff5ec1970cff0c.svg" style="height: 12px;" type="image/svg+xml"&gt;k&lt;/object&gt; is not an integer multiple
of &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/b51a60734da64be0e618bacbea2865a8a7dcd669.svg" style="height: 12px;" type="image/svg+xml"&gt;N&lt;/object&gt;. However:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/92a7e0eade5ae2829fcb79d29b3b0562b02722a9.svg" style="height: 17px;" type="image/svg+xml"&gt;\[r^N=e^{i(2\pi/N)kN}=1\]&lt;/object&gt;
&lt;p&gt;Therefore:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/4dd7c42cdb7a4290b25a4c25fd5851d13130efb0.svg" style="height: 18px;" type="image/svg+xml"&gt;\[A[k]=S_N=0\]&lt;/object&gt;
&lt;p&gt;While these calculations demonstrate the sums from &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/bfbd617aa9bc9d5a8b0b006de9d1d45d8e688c8d.svg" style="height: 11px;" type="image/svg+xml"&gt;n=0&lt;/object&gt; to
&lt;object class="valign-m1 latex-math" data="https://eli.thegreenplace.net/images/math/4f927fbfe4d5898f228630ce76e5284ed202f837.svg" style="height: 14px;" type="image/svg+xml"&gt;N-1&lt;/object&gt;, they work exactly the same for any &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/b51a60734da64be0e618bacbea2865a8a7dcd669.svg" style="height: 12px;" type="image/svg+xml"&gt;N&lt;/object&gt; consecutive
indices, because the summand is periodic in &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt; with period
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/b51a60734da64be0e618bacbea2865a8a7dcd669.svg" style="height: 12px;" type="image/svg+xml"&gt;N&lt;/object&gt;. Therefore:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/ee92f8136729a20230b6d99f86f4347956f5e929.svg" style="height: 57px;" type="image/svg+xml"&gt;\[A[k]=\sum_{n=\langle N\rangle}e^{i(2\pi/N)kn}=
\begin{cases}
    N      &amp;amp; N\mid k\\
    0      &amp;amp; \text{otherwise}
\end{cases}\]&lt;/object&gt;
&lt;/div&gt;
&lt;div class="section" id="appendix-c-sine-series-decomposition-of-t-d-n"&gt;
&lt;h2&gt;Appendix C: Sine series decomposition of &lt;object class="valign-m6 latex-math heading-math" data="https://eli.thegreenplace.net/images/math/b2c6547bf744e9cad27f25ea4a538006b5e10df1.svg" style="height: 27px;" type="image/svg+xml"&gt;t_d[n]&lt;/object&gt;&lt;/h2&gt;
&lt;p&gt;Using the formula for DTFS developed earlier in the post:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/dea847f17d73cf72834a3bf138cf296585600e8f.svg" style="height: 112px;" type="image/svg+xml"&gt;\[\begin{aligned}
    a_k&amp;amp;=\frac{1}{12}\sum_{n=0}^{11}t_d[n]e^{-ik(\pi/6)n}\\
    &amp;amp;=\frac{1}{12}\sum_{n=0}^{11}t_d[n]cos\frac{k\pi n}{6}-i\frac{1}{12}\sum_{n=0}^{11}t_d[n]sin\frac{k\pi n}{6}\\
\end{aligned}\]&lt;/object&gt;
&lt;p&gt;Recall that &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/b2c6547bf744e9cad27f25ea4a538006b5e10df1.svg" style="height: 18px;" type="image/svg+xml"&gt;t_d[n]&lt;/object&gt; is odd over the full range &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/6aaa4029be956bb3225f684513bacd9d2fa721d9.svg" style="height: 18px;" type="image/svg+xml"&gt;n=[0..12)&lt;/object&gt;.
Specifically, since the cosine is an even function, we have for any
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/6b0d31c0d563223024da45691584643ac78c96e8.svg" style="height: 7px;" type="image/svg+xml"&gt;m&lt;/object&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/78c15be789336fccf8caf504bf0a468c65a4ba10.svg" style="height: 63px;" type="image/svg+xml"&gt;\[\begin{aligned}
    t_d[12-m]&amp;amp;=-t_d[m]\\
    cos\frac{k\pi(12-m)}{6}&amp;amp;=cos(2\pi k -\frac{k\pi m}{6})=cos\frac{k\pi m}{6}\\
\end{aligned}\]&lt;/object&gt;
&lt;p&gt;Therefore the cosine terms cancel out throughout the period; term 1 is
the same as negative term 11, etc.&lt;/p&gt;
&lt;p&gt;We’re left with the sines:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/04810fca94f796c09eb1a479d4c33728084e1ce7.svg" style="height: 51px;" type="image/svg+xml"&gt;\[a_k=-i\frac{1}{12}\sum_{n=0}^{11}t_d[n]sin\frac{k\pi n}{6}\]&lt;/object&gt;
&lt;p&gt;All coefficients are purely imaginary. For convenience, let’s write:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/bc8a0c8832f7e8c57b624805bf57a3ab7442b335.svg" style="height: 95px;" type="image/svg+xml"&gt;\[\begin{aligned}
    b_k&amp;amp;=\frac{1}{6}\sum_{n=0}^{11}t_d[n]sin\frac{k\pi n}{6}\\
    a_k&amp;amp;=\frac{-i b_k}{2}\\
\end{aligned}\]&lt;/object&gt;
&lt;p&gt;Let’s turn back to the Fourier reconstruction formula:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/a81d1b157290e1b6fe8f180e4d35ebccacad75a0.svg" style="height: 44px;" type="image/svg+xml"&gt;\[t_d[n]=\sum_{k=\langle N\rangle}a_k e^{ik(2\pi/N)n}\]&lt;/object&gt;
&lt;p&gt;And pair up exponentials at &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/13fbd79c3d390e5d6585a21e11ff5ec1970cff0c.svg" style="height: 12px;" type="image/svg+xml"&gt;k&lt;/object&gt; with ones at &lt;object class="valign-m1 latex-math" data="https://eli.thegreenplace.net/images/math/ca298a83efb32922e18a77b4656ece9aafc49f60.svg" style="height: 14px;" type="image/svg+xml"&gt;12-k&lt;/object&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/d3dad0787d1f52bc208ac361a75067b2e68b3d76.svg" style="height: 17px;" type="image/svg+xml"&gt;\[e^{i(12-k)\pi n/6}=e^{i2\pi n}e^{-ikn\pi/6}=e^{-ikn\pi/6}\]&lt;/object&gt;
&lt;p&gt;Also, since &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/b2c6547bf744e9cad27f25ea4a538006b5e10df1.svg" style="height: 18px;" type="image/svg+xml"&gt;t_d[n]&lt;/object&gt; are real, the conjugate of &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/b93e6f239fad8d0444d74634490a6e0e067b8954.svg" style="height: 11px;" type="image/svg+xml"&gt;a_k&lt;/object&gt; is:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/097c9b2f3444ca43f9fba1aaff3df757b70e25bd.svg" style="height: 37px;" type="image/svg+xml"&gt;\[a_{12-k}=a_k^*=\frac{ib_k}{2}\]&lt;/object&gt;
&lt;p&gt;So adding the paired exponentials with their coefficients and using
Euler’s formula:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/f2cbd4e85e6772e49d149f5412bc92e8cb990318.svg" style="height: 125px;" type="image/svg+xml"&gt;\[\begin{aligned}
    a_ke^{i k\pi n/6}+a_{12-k}e^{-i k\pi n/6}&amp;amp;=-\frac{ib_k}{2}e^{i k\pi n/6}+\frac{ib_k}{2}e^{-i k\pi n/6}\\
    &amp;amp;=b_k\frac{e^{i k\pi n/6}-e^{-i k\pi n/6}}{2i}\\
    &amp;amp;=b_k sin\frac{k\pi n}{6}
\end{aligned}\]&lt;/object&gt;
&lt;p&gt;Therefore:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/51f6856ecd4c6d1c0a997e355ed137c78e2ea77c.svg" style="height: 52px;" type="image/svg+xml"&gt;\[t_d[n]=\sum_{k=0}^{11}a_k e^{ik(2\pi/N)n}=\sum_{k=1}^{5}b_k sin\frac{k\pi n}{6}\]&lt;/object&gt;
&lt;p&gt;We don’t include the terms at &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/02f5d048ae1528ddfe91661c25c64469d096dd42.svg" style="height: 12px;" type="image/svg+xml"&gt;k=0&lt;/object&gt; and &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/a1c10e3a8984ac438298ab152c4168f266ede25f.svg" style="height: 12px;" type="image/svg+xml"&gt;k=6&lt;/object&gt;, because
&lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/84797f94c404864332fcfec975213ee61d2442a4.svg" style="height: 14px;" type="image/svg+xml"&gt;a_0=a_6=0&lt;/object&gt; (sine of an integral multiple of &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/6ac47b6d7372b4087583cfd048d20f4c1571f5cf.svg" style="height: 7px;" type="image/svg+xml"&gt;\pi&lt;/object&gt;).&lt;/p&gt;
&lt;hr class="docutils" /&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-1" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-1"&gt;[1]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;There are a lot of symbols used in this equation. &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt; is the
&amp;quot;time&amp;quot; index of the signal &lt;object class="valign-m5 latex-math" data="https://eli.thegreenplace.net/images/math/97897883b2ac574b045db012a128c024c5a05498.svg" style="height: 18px;" type="image/svg+xml"&gt;x[n]&lt;/object&gt; - its domain; &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/13fbd79c3d390e5d6585a21e11ff5ec1970cff0c.svg" style="height: 12px;" type="image/svg+xml"&gt;k&lt;/object&gt;
enumerates the k-th function &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/ce4de0873a5958646dce9993ddaba5d4511d8b2d.svg" style="height: 16px;" type="image/svg+xml"&gt;\phi_k&lt;/object&gt; from a family of
functions - each &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/1da2937ccce1ec5bb97b6acf3aa4c16b0600ac0a.svg" style="height: 18px;" type="image/svg+xml"&gt;\phi_k[n]&lt;/object&gt; is a function of &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt;;
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/b51a60734da64be0e618bacbea2865a8a7dcd669.svg" style="height: 12px;" type="image/svg+xml"&gt;N&lt;/object&gt; is the period; &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/042dc4512fa3d391c5170cf3aa61e6a638f84342.svg" style="height: 12px;" type="image/svg+xml"&gt;i&lt;/object&gt; is the imaginary unit.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-2" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-2"&gt;[2]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;The odd extension may be slightly confusing because we don’t use
negative indices. But indices are arbitrary! In our case, within a
single period index &lt;object class="valign-m1 latex-math" data="https://eli.thegreenplace.net/images/math/d868a680affb6ad2c7e2392566b6adc4e3201dea.svg" style="height: 12px;" type="image/svg+xml"&gt;-n&lt;/object&gt; is equivalent to &lt;object class="valign-m1 latex-math" data="https://eli.thegreenplace.net/images/math/a57fdf4a737281653331838e54c1f649f3aef0ab.svg" style="height: 13px;" type="image/svg+xml"&gt;12-n&lt;/object&gt;; if we
consider one period around the halfway point of &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/fd917de64a52110443142df37dfb4c646c895ca0.svg" style="height: 12px;" type="image/svg+xml"&gt;n=6&lt;/object&gt;, it’s
easy to see that the function is indeed odd.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-3" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-3"&gt;[3]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;Note that we use &lt;object class="valign-m5 latex-math" data="https://eli.thegreenplace.net/images/math/97897883b2ac574b045db012a128c024c5a05498.svg" style="height: 18px;" type="image/svg+xml"&gt;x[n]&lt;/object&gt;, not &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/c6df076ab603be3c2cbc4b1d6d092e640b77e29b.svg" style="height: 18px;" type="image/svg+xml"&gt;x_N[n]&lt;/object&gt; in the summation
for &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/b93e6f239fad8d0444d74634490a6e0e067b8954.svg" style="height: 11px;" type="image/svg+xml"&gt;a_k&lt;/object&gt;. This is because within the chosen range they are
equal.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;script src="https://eli.thegreenplace.net/demos/discrete-fourier/sampled-triangle.js"&gt;
&lt;/script&gt;&lt;/div&gt;
</content><category term="misc"/><category term="Math"/></entry><entry><title>How big are factorials?</title><link href="https://eli.thegreenplace.net/2026/how-big-are-factorials/" rel="alternate"/><published>2026-08-27T18:52:00-07:00</published><updated>2026-08-28T01:53:48.001094-07:00</updated><author><name>Eli Bendersky</name></author><id>tag:eli.thegreenplace.net,2026-08-27:/2026/how-big-are-factorials/</id><summary type="html">&lt;p&gt;The other day, I found myself wondering how big 52! (52 factorial) is,
and that led me to ponder how these could be estimated without a
calculator or a computer.&lt;/p&gt;
&lt;p&gt;It turns out there’s some fairly interesting math behind being able to
estimate the size (number of digits) of …&lt;/p&gt;</summary><content type="html">&lt;p&gt;The other day, I found myself wondering how big 52! (52 factorial) is,
and that led me to ponder how these could be estimated without a
calculator or a computer.&lt;/p&gt;
&lt;p&gt;It turns out there’s some fairly interesting math behind being able to
estimate the size (number of digits) of a factorial reasonably
accurately. This post will start by stating how to do the estimate, and
if you’re curious you can read on for the math background.&lt;/p&gt;
&lt;p&gt;Without further ado, the approximation is:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/59eb2eb0cd6a017bee697978a2e97c9fa116f30d.svg" style="height: 33px;" type="image/svg+xml"&gt;\[\text{number of digits in n!}\approx n\log_{10}\left(\frac{n}{e}\right)+2\]&lt;/object&gt;
&lt;p&gt;As an example, let’s use my original question, by estimating this for
52!&lt;/p&gt;
&lt;p&gt;Well, 52 divided by &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/58e6b3a414a1e090dfc6029add0f3555ccba127f.svg" style="height: 8px;" type="image/svg+xml"&gt;e&lt;/object&gt; is... 20-ish? And &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/f1a691980a18c579b07a80f022dc267c48844592.svg" style="height: 18px;" type="image/svg+xml"&gt;\log_{10}(20)&lt;/object&gt; is
about 1.3  &lt;a class="footnote-reference" href="#footnote-1" id="footnote-reference-1"&gt;[1]&lt;/a&gt;; therefore our estimate comes out to:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/7b5a7e609d29ba3070ef9622c6a5bad2023b6b36.svg" style="height: 16px;" type="image/svg+xml"&gt;\[\text{number of digits in 52!}\approx 52\cdot 1.3 +2 \approx69\]&lt;/object&gt;
&lt;p&gt;The real answer is 68, so this is very close! In estimates like this -
when you’re dealing with enormous numbers - being off by a couple of
digits usually isn't a big deal.&lt;/p&gt;
&lt;div class="section" id="the-gamma-function"&gt;
&lt;h2&gt;The Gamma function&lt;/h2&gt;
&lt;p&gt;The Gamma function for real &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/98b4f7b1f9e3613bfd676d3fdee9cd7b3b3f2a93.svg" style="height: 11px;" type="image/svg+xml"&gt;n&amp;gt;0&lt;/object&gt; is defined &lt;a class="footnote-reference" href="#footnote-2" id="footnote-reference-2"&gt;[2]&lt;/a&gt; as:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/109727d947cc4aa18f946c15ae28ad66104bdcff.svg" style="height: 42px;" type="image/svg+xml"&gt;\[\Gamma(n)=\int_{0}^{\infty}x^{n-1}e^{-x}dx\]&lt;/object&gt;
&lt;p&gt;This integral does not have an analytic expression in the general case,
but it does have a very useful property that we can take advantage of.
Let’s see what &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/fc32a9ecba56860559f27badf2a708fc2c5deae7.svg" style="height: 18px;" type="image/svg+xml"&gt;\Gamma(n+1)&lt;/object&gt; is:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/9bd592d202d8111d6fdc0fbf839704b50599049b.svg" style="height: 42px;" type="image/svg+xml"&gt;\[\Gamma(n+1)=\int_{0}^{\infty}x^{n}e^{-x}dx\]&lt;/object&gt;
&lt;p&gt;And now use integration by parts with:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/3eb21496d2fb403b6f7872823924ea30a490feb1.svg" style="height: 16px;" type="image/svg+xml"&gt;\[u=x^n\qquad v=-e^{-x}\]&lt;/object&gt;
&lt;p&gt;Then:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/d62e697071b3ea7710fddb098a262b0bae1ce71b.svg" style="height: 15px;" type="image/svg+xml"&gt;\[du=nx^{n-1} dx\qquad dv=e^{-x}dx\]&lt;/object&gt;
&lt;p&gt;So:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/a0f606dbd3fe6e9f81c4ab06d4b189a7e8be1103.svg" style="height: 135px;" type="image/svg+xml"&gt;\[\begin{aligned}
    \Gamma(n+1)&amp;amp;=\int_{0}^{\infty}x^{n}e^{-x}dx\\
    &amp;amp;=\left. -x^n e^{-x}\right|_{0}^{\infty}-\int_{0}^{\infty}-e^{-x}n x^{n-1}dx\\
    &amp;amp;=n\int_{0}^{\infty}x^{n-1}e^{-x}dx
\end{aligned}\]&lt;/object&gt;
&lt;p&gt;But notice that the last integral is just &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/35d22607fb899deb63a04c62af61ff2431c5f262.svg" style="height: 18px;" type="image/svg+xml"&gt;\Gamma(n)&lt;/object&gt;; therefore,
we’ve shown that:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/f7e3f3ba2cb5182564d9c347deb416e94c8b29e6.svg" style="height: 18px;" type="image/svg+xml"&gt;\[\Gamma(n+1)=n\Gamma(n)\]&lt;/object&gt;
&lt;p&gt;Let’s also calculate &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/ebf542bc1a916f216c6b0131c026b14353ce754d.svg" style="height: 18px;" type="image/svg+xml"&gt;\Gamma(1)&lt;/object&gt; - it’s a special case that has an
analytical solution:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/7acf9430cec2f479b2445cceeade7498c5acf5a9.svg" style="height: 42px;" type="image/svg+xml"&gt;\[\Gamma(1)=\int_{0}^{\infty}e^{-x}dx=\left. -e^{-x}\right|_{0}^{\infty}=1\]&lt;/object&gt;
&lt;p&gt;This helps establish an induction argument:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/ebd16ac09b430122ee665edf67086a1dec039367.svg" style="height: 119px;" type="image/svg+xml"&gt;\[\begin{aligned}
    \Gamma(2)=1\cdot\Gamma(1)&amp;amp;=1!\\
    \Gamma(3)=2\cdot\Gamma(2)&amp;amp;=2!\\
    \Gamma(4)=3\cdot\Gamma(3)&amp;amp;=3!\\
    \dots\\
    \Gamma(n+1)=n\cdot\Gamma(n)&amp;amp;=n!
\end{aligned}\]&lt;/object&gt;
&lt;p&gt;In other words - the Gamma function is an interpolation of the factorial
over all positive reals. Here’s a plot of the Gamma function over a
small range; note that the y axis is log-scale because of the function’s
fast growth:&lt;/p&gt;
&lt;img alt="Gamma function plot" class="align-center" src="https://eli.thegreenplace.net/images/2026/gamma-cont.png" /&gt;
&lt;/div&gt;
&lt;div class="section" id="stirlings-approximation"&gt;
&lt;h2&gt;Stirling’s approximation&lt;/h2&gt;
&lt;p&gt;You may have encountered Stirling’s approximation before:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/bc7c47f7d5a66ca699c62c087c1c457644818aca.svg" style="height: 34px;" type="image/svg+xml"&gt;\[n!\approx\sqrt{2\pi n}\cdot\left(\frac{n}{e} \right)^n\]&lt;/object&gt;
&lt;p&gt;It’s a great approximation that works reasonably well even for small
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt;. This section is a brief overview of how Stirling’s formula is
derived from the Gamma function.&lt;/p&gt;
&lt;p&gt;Taking:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/d94b8035ec807c0ed49ad2b4b8ecbf81caf29e2e.svg" style="height: 42px;" type="image/svg+xml"&gt;\[n!=\Gamma(n+1)=\int_{0}^{\infty}x^n e^{-x}dx\]&lt;/object&gt;
&lt;p&gt;We’ll start by massaging the integrand a bit:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/c7d142255dc0de29e9878332a1cf1e9de3867c73.svg" style="height: 42px;" type="image/svg+xml"&gt;\[n!=\int_{0}^{\infty}x^n e^{-x}dx=\int_{0}^{\infty}e^{n \ln x} e^{-x}dx\]&lt;/object&gt;
&lt;p&gt;And making a change of variables &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/c159eefe7e6d315a418f73bf57fd0f9cbcf0b3dc.svg" style="height: 11px;" type="image/svg+xml"&gt;x=ny&lt;/object&gt;, which means that
&lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/5b2052842a93a4eb71ea0a3e0d136d255aaed48e.svg" style="height: 16px;" type="image/svg+xml"&gt;dx=ndy&lt;/object&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/b57b880d72a08685fff66b6371841a1106941f2b.svg" style="height: 88px;" type="image/svg+xml"&gt;\[\begin{aligned}
    n!&amp;amp;=\int_{0}^{\infty}ne^{n\ln(ny) - ny}dy=n\int_{0}^{\infty}e^{n(\ln n+\ln y-y)}dy\\
    &amp;amp;=ne^{n\ln n}\int_{0}^{\infty}e^{n(\ln y-y)}dy
\end{aligned}\]&lt;/object&gt;
&lt;p&gt;These steps make the integral amenable to applying &lt;a class="reference external" href="https://en.wikipedia.org/wiki/Laplace's_method"&gt;Laplace’s
method&lt;/a&gt;, which allows
us to approximate definite integrals of the form:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/3616ce703d0d134c344d8c901ba41c86c6d4ca38.svg" style="height: 45px;" type="image/svg+xml"&gt;\[\int_{a}^{b}e^{nf(x)}dx\]&lt;/object&gt;
&lt;p&gt;Where &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/3e03f4706048fbc6c5a252a85d066adf107fcc1f.svg" style="height: 18px;" type="image/svg+xml"&gt;f(x)&lt;/object&gt; is a twice-differentiable function and &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt; some
large number. By Laplace’s method, such integrals can be approximated
by:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/52bebd1bf39c848a8674b04dc7b5f9ee9725df27.svg" style="height: 54px;" type="image/svg+xml"&gt;\[\int_{a}^{b}e^{nf(x)}dx\approx\sqrt{\frac{2\pi}{n|f&amp;#x27;&amp;#x27;(x_0)|}}e^{n f(x_0)}\]&lt;/object&gt;
&lt;p&gt;Where &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/efbda784ad565c1c5201fdc948a570d0426bc6e6.svg" style="height: 10px;" type="image/svg+xml"&gt;x_0&lt;/object&gt; is the global maximum of &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/3e03f4706048fbc6c5a252a85d066adf107fcc1f.svg" style="height: 18px;" type="image/svg+xml"&gt;f(x)&lt;/object&gt;.&lt;/p&gt;
&lt;p&gt;Let’s see how to apply this method &lt;a class="footnote-reference" href="#footnote-3" id="footnote-reference-3"&gt;[3]&lt;/a&gt; to the latest equation we have
for &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/be86ded6f79cc18b8f5e9d7fcfc9a8c31712f5af.svg" style="height: 12px;" type="image/svg+xml"&gt;n!&lt;/object&gt; (renaming the dummy integration variable back to
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/11f6ad8ec52a2984abaafd7c3b516503785c2072.svg" style="height: 8px;" type="image/svg+xml"&gt;x&lt;/object&gt;):&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/253c3d3ab913e33071b5e82314a1020cd055f773.svg" style="height: 42px;" type="image/svg+xml"&gt;\[n!=ne^{n\ln n}\int_{0}^{\infty}e^{n(\ln x-x)}dx\]&lt;/object&gt;
&lt;p&gt;In our case, &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/04dc92cac4abb82f45427170ea9a147571d70700.svg" style="height: 18px;" type="image/svg+xml"&gt;f(x)=\ln x - x&lt;/object&gt;. It’s easy to show that this
function is twice differentiable and has a global maximum at
&lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/0c1d7f319728a07a57d000f2379b5215e4130147.svg" style="height: 14px;" type="image/svg+xml"&gt;x_0=1&lt;/object&gt;. Moreover:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/9032a58f00f68bf627a00dab927d939f9d38b851.svg" style="height: 43px;" type="image/svg+xml"&gt;\[\begin{aligned}
    f(x_0)&amp;amp;=-1\\
    f&amp;#x27;&amp;#x27;(x_0)&amp;amp;=-1\\
\end{aligned}\]&lt;/object&gt;
&lt;p&gt;Substituting these into the proper places in Laplace’s approximation, we
get:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/2137237280a6068d803f0a0489ab8d5c2ff7174d.svg" style="height: 111px;" type="image/svg+xml"&gt;\[\begin{aligned}
    n! &amp;amp;\approx ne^{n\ln n}\sqrt{\frac{2\pi}{n}}e^{-n}\\
    &amp;amp;\approx \sqrt{2\pi n}\cdot e^{n(\ln n - 1)}\\
    &amp;amp;\approx \sqrt{2\pi n}\cdot \left(\frac{n}{e}\right)^n\quad\blacksquare
\end{aligned}\]&lt;/object&gt;
&lt;/div&gt;
&lt;div class="section" id="number-of-digits-from-stirlings-approximation"&gt;
&lt;h2&gt;Number of digits from Stirling’s approximation&lt;/h2&gt;
&lt;p&gt;We can calculate the number of digits in &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/be86ded6f79cc18b8f5e9d7fcfc9a8c31712f5af.svg" style="height: 12px;" type="image/svg+xml"&gt;n!&lt;/object&gt; by taking the
base-10 logarithm of Stirling’s formula:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/97423a10d2cd9a401a6126b4cbd3171bb38cee61.svg" style="height: 111px;" type="image/svg+xml"&gt;\[\begin{aligned}
\text{number of digits in n!}&amp;amp;\approx \log_{10} \left(\sqrt{2\pi n}\cdot
 \left(\frac{n}{e}\right)^n\right)\\
&amp;amp;\approx \log_{10}\left(\sqrt{2\pi n}\right)+ \log_{10}\left(\frac{n}{e}\right)^n\\
&amp;amp;\approx \log_{10}\left(\sqrt{2\pi n}\right)+ n\cdot \log_{10}\left(\frac{n}{e}\right)
\end{aligned}\]&lt;/object&gt;
&lt;p&gt;Note that the first term is not multiplied by &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt; itself;
therefore, as &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt; grows, it will become less and less noticeable.
That said, it still adds a couple of digits - so you should take it into
account if you want a more accurate approximation &lt;a class="footnote-reference" href="#footnote-4" id="footnote-reference-4"&gt;[4]&lt;/a&gt;&lt;/p&gt;
&lt;hr class="docutils" /&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-1" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-1"&gt;[1]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;Mental tricks for calculating &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/e94a447fe28f08ae87dc57434036ab7f4bb1a125.svg" style="height: 17px;" type="image/svg+xml"&gt;\log_{10}&lt;/object&gt; is a different topic,
but it really helps to remember that &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/ea98121d7d3c34ec2b12ca3e79aa25d5a4b986f7.svg" style="height: 17px;" type="image/svg+xml"&gt;\log_{10}2=0.3&lt;/object&gt;,
&lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/35ef3eaf3f31f1f685a336494a1005e9e1af0922.svg" style="height: 17px;" type="image/svg+xml"&gt;\log_{10}3=0.5&lt;/object&gt;, and from here using the various logarithm
laws to estimate multiples.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-2" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-2"&gt;[2]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;As a matter of fact, the Gamma function is defined for complex
numbers, but for our purpose talking about the reals is sufficient.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-3" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-3"&gt;[3]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;As much as I’d like to dive into &lt;em&gt;why&lt;/em&gt; this approximation works, the
rabbit hole in this post is already deep enough!&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-4" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-4"&gt;[4]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;It adds up to 2 extra digits as long as &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/d1854cae891ec7b29161ccaf79a24b00c274bdaa.svg" style="height: 8px;" type="image/svg+xml"&gt;n&lt;/object&gt; is less than 1600
or so, and may add more than 2 after that, though no more than 3
until n is 160000. It’s not clear why anyone would like to estimate
the number of digits of 1600! (about 4450, in case you were
wondering), let alone 160000!&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
</content><category term="misc"/><category term="Math"/></entry><entry><title>Relative velocity and closing speed</title><link href="https://eli.thegreenplace.net/2026/relative-velocity-and-closing-speed/" rel="alternate"/><published>2026-08-03T20:01:00-07:00</published><updated>2026-08-04T03:01:09.277721-07:00</updated><author><name>Eli Bendersky</name></author><id>tag:eli.thegreenplace.net,2026-08-03:/2026/relative-velocity-and-closing-speed/</id><summary type="html">&lt;p&gt;In Physics simulations or game engines it’s sometimes useful to
determine the speed with which two objects are approaching each other.
This post will discuss the concept of &lt;em&gt;closing speed&lt;/em&gt;, which is the
&lt;em&gt;normal component&lt;/em&gt; of the &lt;em&gt;relative velocity&lt;/em&gt; of two objects.&lt;/p&gt;
&lt;div class="section" id="relative-velocity-and-its-components"&gt;
&lt;h2&gt;Relative velocity and its components&lt;/h2&gt;
&lt;p&gt;Suppose we …&lt;/p&gt;&lt;/div&gt;</summary><content type="html">&lt;p&gt;In Physics simulations or game engines it’s sometimes useful to
determine the speed with which two objects are approaching each other.
This post will discuss the concept of &lt;em&gt;closing speed&lt;/em&gt;, which is the
&lt;em&gt;normal component&lt;/em&gt; of the &lt;em&gt;relative velocity&lt;/em&gt; of two objects.&lt;/p&gt;
&lt;div class="section" id="relative-velocity-and-its-components"&gt;
&lt;h2&gt;Relative velocity and its components&lt;/h2&gt;
&lt;p&gt;Suppose we have objects A and B &lt;a class="footnote-reference" href="#footnote-1" id="footnote-reference-1"&gt;[1]&lt;/a&gt; with velocity vectors
&lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/94a17f930633898bbe6d1ef2a6c263573aa3842a.svg" style="height: 20px;" type="image/svg+xml"&gt;\vec{V_A}&lt;/object&gt; and &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/c4f87fb6f28657fbd625b4bfbc514b0574e80108.svg" style="height: 20px;" type="image/svg+xml"&gt;\vec{V_B}&lt;/object&gt;. The &lt;em&gt;relative velocity&lt;/em&gt; of B
w.r.t. A is:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/27625ffaa87e60a1f991ed3aa390d5b284868118.svg" style="height: 24px;" type="image/svg+xml"&gt;\[\vec{V}_{B|A}=\vec{V}_B-\vec{V}_A\]&lt;/object&gt;
&lt;p&gt;Put differently, it’s the velocity of B in A’s frame of reference.&lt;/p&gt;
&lt;p&gt;This relative velocity is a vector, and we can split it into orthogonal
components. Obviously, the nature of such a split depends on the basis
we want to use. We could look at the vector’s x an y components (we’ll
be using &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/2b688757b3d0949451e1fa97e71ac5f5f284a5e4.svg" style="height: 15px;" type="image/svg+xml"&gt;\mathbb{R}^2&lt;/object&gt; - two dimensional space, but everything
here applies to 3D as well), but for this post we’re interested in
something slightly different:&lt;/p&gt;
&lt;img alt="Normal and tangential components of the relative velocity." class="align-center" src="https://eli.thegreenplace.net/images/2026/normal-and-tangential.png" /&gt;
&lt;p&gt;We draw a line connecting the two objects. The component of
&lt;object class="valign-m6 latex-math" data="https://eli.thegreenplace.net/images/math/8ccc4a9163c92ed1e8e723b64a9d7056ada65491.svg" style="height: 24px;" type="image/svg+xml"&gt;\vec{V}_{B|A}&lt;/object&gt; in the direction of this line is called the
&lt;em&gt;normal component&lt;/em&gt; of relative velocity, while the component
perpendicular to this direction is called the &lt;em&gt;tangential component&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="computing-the-normal-component"&gt;
&lt;h2&gt;Computing the normal component&lt;/h2&gt;
&lt;p&gt;How do we find the component of a vector in the direction of a specific
line? By using a &lt;a class="reference external" href="https://eli.thegreenplace.net/2024/projections-and-projection-matrices/"&gt;vector
projection!&lt;/a&gt;.
We’ll represent the line by a vector, and find the projection of
&lt;object class="valign-m6 latex-math" data="https://eli.thegreenplace.net/images/math/8ccc4a9163c92ed1e8e723b64a9d7056ada65491.svg" style="height: 24px;" type="image/svg+xml"&gt;\vec{V}_{B|A}&lt;/object&gt; onto this vector.&lt;/p&gt;
&lt;p&gt;The positions of A and B can also be seen as vectors: &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/0cbd4a39e2dc15c143419b61cfab3d08c89dd946.svg" style="height: 20px;" type="image/svg+xml"&gt;\vec{P}_A&lt;/object&gt;
and &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/8be98601c153883b6091b8ba841746479c876b9c.svg" style="height: 20px;" type="image/svg+xml"&gt;\vec{P}_B&lt;/object&gt;. The line connecting them can then be expressed as
the vector &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/702505a802f90f2627da0f341f6f28af8a4a2aca.svg" style="height: 20px;" type="image/svg+xml"&gt;\vec{P}_B-\vec{P}_A&lt;/object&gt;:&lt;/p&gt;
&lt;img alt="The relative-position vector is the difference of the two position vectors." class="align-center" src="https://eli.thegreenplace.net/images/2026/the-relative-position.png" /&gt;
&lt;p&gt;All we need from this position difference vector is its direction, not
its magnitude, however &lt;a class="footnote-reference" href="#footnote-2" id="footnote-reference-2"&gt;[2]&lt;/a&gt;. So we’ll use the &lt;em&gt;unit vector&lt;/em&gt; of
&lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/702505a802f90f2627da0f341f6f28af8a4a2aca.svg" style="height: 20px;" type="image/svg+xml"&gt;\vec{P}_B-\vec{P}_A&lt;/object&gt;, denoted as:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/4037effd91b348b652473f482fc242b7dc83ea57.svg" style="height: 49px;" type="image/svg+xml"&gt;\[\widehat{P}=\frac{\vec{P}_B-\vec{P}_A}{|\vec{P}_B-\vec{P}_A|}\]&lt;/object&gt;
&lt;p&gt;Finally, to find the projection of &lt;object class="valign-m6 latex-math" data="https://eli.thegreenplace.net/images/math/8ccc4a9163c92ed1e8e723b64a9d7056ada65491.svg" style="height: 24px;" type="image/svg+xml"&gt;\vec{V}_{B|A}&lt;/object&gt; onto
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/ae76f98aa161c8e6255ff6aac4741c7745715b54.svg" style="height: 17px;" type="image/svg+xml"&gt;\widehat{P}&lt;/object&gt;, we compute &lt;a class="footnote-reference" href="#footnote-3" id="footnote-reference-3"&gt;[3]&lt;/a&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/bfa87afcdbc16f27582886265e68c81a888a5719.svg" style="height: 24px;" type="image/svg+xml"&gt;\[S_c=\vec{V}_{B|A}\cdot\widehat{P}=(\vec{V}_B-\vec{V}_A)\cdot\widehat{P}\]&lt;/object&gt;
&lt;p&gt;Where the multiplication operator between the vectors is the &lt;em&gt;dot
product&lt;/em&gt;. Note that the result of the dot product is a scalar;
therefore, the quantity &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/b423d57e7c978d9b6f9e3d76c3e02f52cf5a1a17.svg" style="height: 15px;" type="image/svg+xml"&gt;S_c&lt;/object&gt; is called the &lt;em&gt;closing speed&lt;/em&gt; - it
expresses the rate at which the relative distance of the two objects is
changing. If it’s positive, the objects are drifting farther apart; if
it’s negative, the objects are getting closer together. Therefore the
term &amp;quot;closing speed&amp;quot; may be slightly confusing; alternatively, this has
been called a &amp;quot;signed separation speed&amp;quot;, or &amp;quot;normal relative speed&amp;quot; &lt;a class="footnote-reference" href="#footnote-4" id="footnote-reference-4"&gt;[4]&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The signs in these calculations can be tricky to get right, so we have
to be very careful. Let’s see a few examples that will help us make
these computations more concrete.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="examples"&gt;
&lt;h2&gt;Examples&lt;/h2&gt;
&lt;p&gt;To build up some intuition and get some practice with the equations,
we’ll review the following examples:&lt;/p&gt;
&lt;img alt="Four relative-motion examples." class="align-center" src="https://eli.thegreenplace.net/images/2026/four-relative-motion.png" /&gt;
&lt;p&gt;&lt;strong&gt;Example I&lt;/strong&gt;: We’ll start by computing the relative position unit
vector &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/ae76f98aa161c8e6255ff6aac4741c7745715b54.svg" style="height: 17px;" type="image/svg+xml"&gt;\widehat{P}&lt;/object&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/f28d4a7d06cafd403cd826c0a670975b172ff67a.svg" style="height: 49px;" type="image/svg+xml"&gt;\[\widehat{P}=\frac{\vec{P}_B-\vec{P}_A}{|\vec{P}_B-\vec{P}_A|}=\frac{\langle 4,0\rangle}{|\langle 4,0 \rangle|}=\langle1,0\rangle\]&lt;/object&gt;
&lt;p&gt;Then, the closing speed is:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/f3b2874b8233cd8c1751ed5ff2fdfbae1d96c711.svg" style="height: 22px;" type="image/svg+xml"&gt;\[S_c=(\vec{V}_B-\vec{V}_A)\cdot\widehat{P}=\langle -3,0\rangle\cdot\langle1,0\rangle=-3\]&lt;/object&gt;
&lt;p&gt;Based on our convention, the negative sign of &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/b423d57e7c978d9b6f9e3d76c3e02f52cf5a1a17.svg" style="height: 15px;" type="image/svg+xml"&gt;S_c&lt;/object&gt; means that the
objects are approaching each other. Due to the simple nature of the
example, this result is easy to verify, as it can be immediately guessed
just by looking at the diagram.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example II&lt;/strong&gt;: Here &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/ae76f98aa161c8e6255ff6aac4741c7745715b54.svg" style="height: 17px;" type="image/svg+xml"&gt;\widehat{P}&lt;/object&gt; is the same as in the previous
example. The closing speed is:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/f66ddd84100e0b1eaafe03b3afed57dc50a82965.svg" style="height: 22px;" type="image/svg+xml"&gt;\[S_c=(\vec{V}_B-\vec{V}_A)\cdot\widehat{P}=\langle 3,0\rangle\cdot\langle1,0\rangle=3\]&lt;/object&gt;
&lt;p&gt;Same magnitude, but different sign from before, because the objects are
moving farther apart.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example III&lt;/strong&gt; This example is to demonstrate that we get consistent
results even if B is to the left of A. Here the relative position unit
vector is:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/e7796cd9ca52dc9cf7de0692372020ef2303bbb8.svg" style="height: 49px;" type="image/svg+xml"&gt;\[\widehat{P}=\frac{\vec{P}_B-\vec{P}_A}{|\vec{P}_B-\vec{P}_A|}=\frac{\langle -2,0\rangle}{|\langle -2,0 \rangle|}=\langle-1,0\rangle\]&lt;/object&gt;
&lt;p&gt;And the closing speed:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/67c72205da69531f03dd92be8d75a04c775e5342.svg" style="height: 22px;" type="image/svg+xml"&gt;\[S_c=(\vec{V}_B-\vec{V}_A)\cdot\widehat{P}=\langle 3,0\rangle\cdot\langle -1,0\rangle=-3\]&lt;/object&gt;
&lt;p&gt;Which is the same as in example I, as expected. The direction of
&lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/ae76f98aa161c8e6255ff6aac4741c7745715b54.svg" style="height: 17px;" type="image/svg+xml"&gt;\widehat{P}&lt;/object&gt; flipped, but so did the direction of the relative
velocity vector, so the result has the same sign.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example IV&lt;/strong&gt;: Finally, an example showing more arbitrary positions and
velocities.&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/aa10ecf2964b6bfc8fc7613fe86515408c2fa555.svg" style="height: 49px;" type="image/svg+xml"&gt;\[\widehat{P}=\frac{\vec{P}_B-\vec{P}_A}{|\vec{P}_B-\vec{P}_A|}=\frac{\langle 3,4\rangle}{|\langle 3,4 \rangle|}=\langle0.6,0.8\rangle\]&lt;/object&gt;
&lt;p&gt;Then:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/a03119506d85247140be836d2e7c898ba991e46e.svg" style="height: 22px;" type="image/svg+xml"&gt;\[S_c=(\vec{V}_B-\vec{V}_A)\cdot\widehat{P}=\langle -3,-6\rangle\cdot\langle 0.6,0.8\rangle=-6.6\]&lt;/object&gt;
&lt;p&gt;This example is a good opportunity to demonstrate something important
about &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/b423d57e7c978d9b6f9e3d76c3e02f52cf5a1a17.svg" style="height: 15px;" type="image/svg+xml"&gt;S_c&lt;/object&gt;: it’s time-dependent, because positions change with
time. Here, -6.6 is the closing speed at the exact moment when A’s and
B’s positions and velocities are as stated in the example. In the next
time step, the position of A will be &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/2bc27b863835e60fdba1357f797159dc72d77045.svg" style="height: 18px;" type="image/svg+xml"&gt;\langle2,5\rangle&lt;/object&gt; and the
position of B will be &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/2450a84c29d863591b7db00ceada4f084bfb99ea.svg" style="height: 18px;" type="image/svg+xml"&gt;\langle2,3\rangle&lt;/object&gt;, while their velocities
remain the same. The &lt;object class="valign-m3 latex-math" data="https://eli.thegreenplace.net/images/math/b423d57e7c978d9b6f9e3d76c3e02f52cf5a1a17.svg" style="height: 15px;" type="image/svg+xml"&gt;S_c&lt;/object&gt; then will be quite different. This is a
good segue to the next topic - which is a more physical view of closing
speed.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="closing-speed-as-a-function-of-time"&gt;
&lt;h2&gt;Closing speed as a function of time&lt;/h2&gt;
&lt;p&gt;The computation shown so far represents a static view of the world;
perhaps the right word to use is &lt;em&gt;instantaneous&lt;/em&gt;. Given the positions
and velocities at a given moment, what is the closing speed between the
objects &lt;em&gt;at that exact moment&lt;/em&gt;?&lt;/p&gt;
&lt;p&gt;But there’s no reason to not generalize this using a more standard
physical interpretation of velocity.&lt;/p&gt;
&lt;p&gt;First, let’s state the position vectors of A and B as a function of
time: &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/4eb67887f180834938958d847a67ce8c4e833101.svg" style="height: 22px;" type="image/svg+xml"&gt;\vec{P}_A(t)&lt;/object&gt; and &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/3b69a9ddd6f52dba77380fd33edf1ce5adb8e57d.svg" style="height: 22px;" type="image/svg+xml"&gt;\vec{P}_B(t)&lt;/object&gt;. The relative
position vector between the objects is also a function of time:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/70dfcf594bc9407384d7c009f9a608eb3fef4e73.svg" style="height: 22px;" type="image/svg+xml"&gt;\[\vec{R}(t)=\vec{P}_B(t)-\vec{P}_A(t)\]&lt;/object&gt;
&lt;p&gt;Now we’ll define the scalar distance as the magnitude of this vector:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/7cdc889c6f871266456a41fba1c39755e176be60.svg" style="height: 22px;" type="image/svg+xml"&gt;\[r(t)=|\vec{R}(t)|=|\vec{P}_B(t)-\vec{P}_A(t)|\]&lt;/object&gt;
&lt;p&gt;We’re interested in &lt;object class="valign-m6 latex-math" data="https://eli.thegreenplace.net/images/math/2e486b6ff05146a7eec038ad6e7e0fc8528811c3.svg" style="height: 24px;" type="image/svg+xml"&gt;\frac{dr(t)}{dt}&lt;/object&gt; - the change in this
distance over time. Let’s start by breaking &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/9f99e0576aed540806bce0791e5746726e6e413e.svg" style="height: 18px;" type="image/svg+xml"&gt;R(t)&lt;/object&gt; down to its
constituents:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/f3fe85228247cba64b2cf42ab620ca2ad021f58e.svg" style="height: 51px;" type="image/svg+xml"&gt;\[\begin{aligned}
    \vec{R}(t)&amp;amp;=\langle x(t),y(t)\rangle \\
    r(t)&amp;amp;=\sqrt{x(t)^2+y(t)^2}
\end{aligned}\]&lt;/object&gt;
&lt;p&gt;By the chain rule &lt;a class="footnote-reference" href="#footnote-5" id="footnote-reference-5"&gt;[5]&lt;/a&gt;:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/6306fb3b34832bfa2973b4f5f2ce022e50e61bfc.svg" style="height: 100px;" type="image/svg+xml"&gt;\[\begin{aligned}
    \frac{dr(t)}{dt}&amp;amp;=\frac{\frac{d}{dt}(x(t)^2+y(t)^2)}{2\sqrt{x(t)^2+y(t)^2}}\\
    &amp;amp;=\frac{2x(t)x&amp;#x27;(t)+2y(t)y&amp;#x27;(t)}{2\sqrt{x(t)^2+y(t)^2}}
    =\frac{x(t)x&amp;#x27;(t)+y(t)y&amp;#x27;(t)}{\sqrt{x(t)^2+y(t)^2}}
\end{aligned}\]&lt;/object&gt;
&lt;p&gt;Switching back to the vector representation: since
&lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/07a18a0fb49fd212904167765ad6d84a0c82e087.svg" style="height: 22px;" type="image/svg+xml"&gt;\vec{R}(t)=\langle x(t),y(t)\rangle&lt;/object&gt;, the numerator of the
fraction above is then a dot product between &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/7c50f292ef65e21556b433d72d5c11b6e9f87ecf.svg" style="height: 22px;" type="image/svg+xml"&gt;\vec{R}(t)&lt;/object&gt; and
&lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/4dfa75b6830d41bca1c17cdb195e628f68ed338b.svg" style="height: 22px;" type="image/svg+xml"&gt;\vec{R}&amp;#x27;(t)&lt;/object&gt;, we can write this as:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/a42dd678ac96ed753c3c3526680198572a2fe257.svg" style="height: 49px;" type="image/svg+xml"&gt;\[\frac{dr(t)}{dt}=\frac{\vec{R}(t)\cdot\vec{R}&amp;#x27;(t)}{|\vec{R}(t)|}=\hat{R}(t)\cdot\vec{R}&amp;#x27;(t)\]&lt;/object&gt;
&lt;p&gt;But &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/54361db0be49009bd9ab092a77a7a00ddf8a1639.svg" style="height: 21px;" type="image/svg+xml"&gt;\hat{R}(t)&lt;/object&gt; is precisely &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/1787f35be0deea91d648e299fd551f3dcb3e44b5.svg" style="height: 17px;" type="image/svg+xml"&gt;\hat{P}&lt;/object&gt; from the earlier
section, as a function of time. Moreover:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/a98048e9ed9db3cf9b4799aa6f6146b7dd2cb992.svg" style="height: 22px;" type="image/svg+xml"&gt;\[\vec{R}&amp;#x27;(t)=\vec{P}&amp;#x27;_B(t)-\vec{P}&amp;#x27;_A(t)=\vec{V}_B(t)-\vec{V}_A(t)\]&lt;/object&gt;
&lt;p&gt;Because velocity is the time derivative of position. Therefore, we end
up with the same equation, just as a function of time:&lt;/p&gt;
&lt;object class="align-center" data="https://eli.thegreenplace.net/images/math/e3e0da99f86f0ff329cba714e12223664276b75c.svg" style="height: 38px;" type="image/svg+xml"&gt;\[\frac{dr(t)}{dt}=\hat{P}(t)\cdot(\vec{V}_B(t)-\vec{V}_A(t))\]&lt;/object&gt;
&lt;p&gt;This formulation is more precise because it makes it very obvious that
all the quantities we’re dealing with are time dependent.&lt;/p&gt;
&lt;hr class="docutils" /&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-1" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-1"&gt;[1]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;Throughout this post, we assume our objects are sufficiently far
apart that they can be treated as &lt;em&gt;points&lt;/em&gt; (or &lt;em&gt;particles&lt;/em&gt;) without
any shape, area or volume.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-2" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-2"&gt;[2]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;The velocity components should be the same regardless of how far
apart the two objects are.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-3" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-3"&gt;[3]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;In the standard projection formula we’d also divide by the magnitude
of &lt;object class="valign-0 latex-math" data="https://eli.thegreenplace.net/images/math/ae76f98aa161c8e6255ff6aac4741c7745715b54.svg" style="height: 17px;" type="image/svg+xml"&gt;\widehat{P}&lt;/object&gt;, but in our case it’s a unit vector anyway.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-4" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-4"&gt;[4]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;In some online sources you may see the closing speed described as
closing velocity because it has a direction. IMHO this is the wrong
framing. Scalars can be signed! The closing speed is certainly a
scalar, not a vector.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-5" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-5"&gt;[5]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;The notation &lt;object class="valign-m4 latex-math" data="https://eli.thegreenplace.net/images/math/8cef7d030134448b059cf3ccf9ef9edc29b769c0.svg" style="height: 18px;" type="image/svg+xml"&gt;x&amp;#x27;(t)&lt;/object&gt; means &lt;object class="valign-m6 latex-math" data="https://eli.thegreenplace.net/images/math/153450414b2add185e4ad0b5fe515c2835446bfe.svg" style="height: 24px;" type="image/svg+xml"&gt;\frac{dx(t)}{dt}&lt;/object&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
</content><category term="misc"/><category term="Math"/></entry></feed>