<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>Dimitri Lozeve's Blog</title>
        <link>https://lozeve.com</link>
        <description><![CDATA[Recent posts]]></description>
        <atom:link href="https://lozeve.com/rss.xml" rel="self"
                   type="application/rss+xml" />
        <lastBuildDate>Tue, 10 Nov 2026 00:00:00 UT</lastBuildDate>
        <item>
    <title>Topology from the Kuratowski closure</title>
    <link>https://lozeve.com/posts/kuratowski-closure-topology.html</link>
    <content:encoded><![CDATA[<section>
  <p>The notion of open set has a classical set-theoretic definition, by
its properties under unions and intersections. But there is another
way to define <em>open</em> and <em>closed</em>, via an <em>operator</em>. This definition
is equivalent to the usual one, and I find that it matches our
intuition nicely, both for topological spaces and continuity.</p>
<div class="sidenote-wrapper">
<input type="checkbox" id="sn-0" class="margin-toggle" />
<div class="marginnote">
<p><img src="https://lozeve.com/images/kuratowski/Kazimierz_Kuratowski.jpg" alt="Photograph of Kazimierz Kuratowski in 1959" width="200" /></p>
<p>Kazimierz Kuratowski in 1959 (from <a href="https://en.wikipedia.org/wiki/Kazimierz_Kuratowski">Wikipedia</a>)</p>
</div>
</div>
<p>This alternative definition is due to <a href="https://en.wikipedia.org/wiki/Kazimierz_Kuratowski">Kazimierz Kuratowski</a> (1896–1980),
a Polish mathematician <label for="sn-0" class="margin-toggle">⊕</label> who worked mainly on set
theory, topology, and graph theory.</p>
<div id="toc"><h2>Table of Contents</h2><ul>
<li><a href="#the-classical-definition-of-open-sets-and-topology" id="toc-the-classical-definition-of-open-sets-and-topology">The classical definition of open sets and topology</a></li>
<li><a href="#another-way-to-define-closure-the-kuratowski-closure-operator" id="toc-another-way-to-define-closure-the-kuratowski-closure-operator">Another way to define closure: the Kuratowski closure operator</a></li>
<li><a href="#equivalence-of-definitions" id="toc-equivalence-of-definitions">Equivalence of definitions</a>
<ul>
<li><a href="#from-topology-to-kuratowski-closure" id="toc-from-topology-to-kuratowski-closure">From topology to Kuratowski closure</a></li>
<li><a href="#from-kuratowski-closure-to-topology" id="toc-from-kuratowski-closure-to-topology">From Kuratowski closure to topology</a></li>
</ul></li>
<li><a href="#idempotence" id="toc-idempotence">Idempotence</a></li>
<li><a href="#continuity" id="toc-continuity">Continuity</a></li>
<li><a href="#conclusion" id="toc-conclusion">Conclusion</a></li>
</ul></div>
<h2 id="the-classical-definition-of-open-sets-and-topology">The classical definition of open sets and topology</h2>
<p>Let <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>X</mi><annotation encoding="application/x-tex">X</annotation></semantics></math> be a set and <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="script">𝒫</mi><mo stretchy="false" form="prefix">(</mo><mi>X</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">\mathcal{P}(X)</annotation></semantics></math> its power set (the set of all subsets
of <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>X</mi><annotation encoding="application/x-tex">X</annotation></semantics></math>).</p>
<div id="def-topology" class="definition">
<p><span class="env-label">Definition 1.</span> A subset <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="script">𝒰</mi><mo>⊆</mo><mi mathvariant="script">𝒫</mi><mo stretchy="false" form="prefix">(</mo><mi>X</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">\mathcal{U} \subseteq \mathcal{P}(X)</annotation></semantics></math> is a <em>topology</em> on <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>X</mi><annotation encoding="application/x-tex">X</annotation></semantics></math>,
and its elements are called <em>open sets</em>, if the following hold:</p>
<dl>
<dt><em>(i)</em></dt>
<dd>
The empty set <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>∅</mi><annotation encoding="application/x-tex">\emptyset</annotation></semantics></math> and the set <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>X</mi><annotation encoding="application/x-tex">X</annotation></semantics></math> are open,
</dd>
<dt><em>(ii)</em></dt>
<dd>
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi mathvariant="script">𝒰</mi><annotation encoding="application/x-tex">\mathcal{U}</annotation></semantics></math> is closed under arbitrary unions: for any
collection <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false" form="prefix">(</mo><msub><mi>U</mi><mi>i</mi></msub><msub><mo stretchy="false" form="postfix">)</mo><mrow><mi>i</mi><mo>∈</mo><mi>I</mi></mrow></msub></mrow><annotation encoding="application/x-tex">(U_i)_{i\in I}</annotation></semantics></math> of open sets, <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mo>⋃</mo><mrow><mi>i</mi><mo>∈</mo><mi>I</mi></mrow></msub><msub><mi>U</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">\bigcup_{i\in I} U_i</annotation></semantics></math> is
open,
</dd>
<dt><em>(iii)</em></dt>
<dd>
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi mathvariant="script">𝒰</mi><annotation encoding="application/x-tex">\mathcal{U}</annotation></semantics></math> is closed under finite intersections: for
any <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>U</mi><mn>1</mn></msub><mo>,</mo><mi>…</mi><mo>,</mo><msub><mi>U</mi><mi>n</mi></msub></mrow><annotation encoding="application/x-tex">U_1, \dots, U_n</annotation></semantics></math> open, <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msubsup><mo>⋂</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>n</mi></msubsup><msub><mi>U</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">\bigcap_{i=1}^n U_i</annotation></semantics></math> is open.
</dd>
</dl>
<p>The pair <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false" form="prefix">(</mo><mi>X</mi><mo>,</mo><mi mathvariant="script">𝒰</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">(X, \mathcal{U})</annotation></semantics></math> is called a <em>topological space</em>. A set is
<em>closed</em> if its complement is open.</p>
</div>
<p>This definition makes sense if you already have an intuition for what
an open set is, but at first it can seem a little arbitrary: why are
we allowed arbitrary unions but only <em>finite</em> intersections? And can’t
we define what an open set <em>is</em> instead of giving properties of the
set of open sets?</p>
<h2 id="another-way-to-define-closure-the-kuratowski-closure-operator">Another way to define closure: the Kuratowski closure operator</h2>
<div class="sidenote-wrapper">
<input type="checkbox" id="sn-1" class="margin-toggle" />
<div class="marginnote">
<p><img src="https://lozeve.com/images/kuratowski/kuratowski_axioms.png" alt="The closure axioms in Kuratowski's original article (in French)" width="400" /></p>
<p>The closure axioms in Kuratowski’s <a href="https://matwbn.icm.edu.pl/ksiazki/fm/fm3/fm3121.pdf">original article</a> (in French)]</p>
</div>
</div>
<p><label for="sn-1" class="margin-toggle">⊕</label></p>
<div id="def-closure" class="definition">
<p><span class="env-label">Definition 2.</span> A <em>Kuratowski closure operator</em> is a function <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo>:</mo><mi mathvariant="script">𝒫</mi><mo stretchy="false" form="prefix">(</mo><mi>X</mi><mo stretchy="false" form="postfix">)</mo><mo>→</mo><mi mathvariant="script">𝒫</mi><mo stretchy="false" form="prefix">(</mo><mi>X</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">c : \mathcal{P}(X) \to
\mathcal{P}(X)</annotation></semantics></math> such that:</p>
<dl>
<dt><em>(a)</em></dt>
<dd>
It preserves the empty set: <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>∅</mi><mo stretchy="false" form="postfix">)</mo><mo>=</mo><mi>∅</mi></mrow><annotation encoding="application/x-tex">c(\emptyset) = \emptyset</annotation></semantics></math>,
</dd>
<dt><em>(b)</em></dt>
<dd>
It is <em>extensive</em>: for all <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mo>⊆</mo><mi>X</mi></mrow><annotation encoding="application/x-tex">A \subseteq X</annotation></semantics></math>, <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mo>⊆</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">A \subseteq c(A)</annotation></semantics></math>,
</dd>
<dt><em>(c)</em></dt>
<dd>
It is <em>idempotent</em>: for all <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mo>⊆</mo><mi>X</mi></mrow><annotation encoding="application/x-tex">A \subseteq X</annotation></semantics></math>, <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo>=</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">c(A) = c(c(A))</annotation></semantics></math>,
</dd>
<dt><em>(d)</em></dt>
<dd>
It preserves unions: for all <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mo>,</mo><mi>B</mi><mo>⊆</mo><mi>X</mi></mrow><annotation encoding="application/x-tex">A, B \subseteq X</annotation></semantics></math>, <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo>∪</mo><mi>B</mi><mo stretchy="false" form="postfix">)</mo><mo>=</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo>∪</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>B</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">c(A \cup B) = c(A) \cup c(B)</annotation></semantics></math>.
</dd>
</dl>
<p>These are called the <a href="https://en.wikipedia.org/wiki/Kuratowski_closure_axioms">Kuratowski closure axioms</a>.</p>
</div>
<p>Informally, <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">c(A)</annotation></semantics></math> is the set of points that are “close” to <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>A</mi><annotation encoding="application/x-tex">A</annotation></semantics></math>. From
such an operator, we can say that a set <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>A</mi><annotation encoding="application/x-tex">A</annotation></semantics></math> is <em>closed</em> if it is left
unchanged by <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>c</mi><annotation encoding="application/x-tex">c</annotation></semantics></math>, i.e. if <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo>=</mo><mi>A</mi></mrow><annotation encoding="application/x-tex">c(A) = A</annotation></semantics></math>, and <em>open</em> if its complement is
closed.</p>
<p>An immediate property of this operator is that it is monotone with
respect to inclusion in <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>X</mi><annotation encoding="application/x-tex">X</annotation></semantics></math>, which is consistent with the intuition
behind “closeness”:</p>
<div id="prop-monotone" class="proposition">
<p><span class="env-label">Proposition 1.</span> A Kuratowski closure operator <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>c</mi><annotation encoding="application/x-tex">c</annotation></semantics></math> is monotone with respect to
inclusion: for any <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mo>,</mo><mi>B</mi><mo>⊆</mo><mi>X</mi></mrow><annotation encoding="application/x-tex">A, B \subseteq X</annotation></semantics></math>, if <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mo>⊆</mo><mi>B</mi></mrow><annotation encoding="application/x-tex">A \subseteq B</annotation></semantics></math>, then <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo>⊆</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>B</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">c(A)
\subseteq c(B)</annotation></semantics></math>.</p>
</div>
<div class="proof">
<p><span class="env-label">Proof.</span> Let <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mo>,</mo><mi>B</mi><mo>⊆</mo><mi>X</mi></mrow><annotation encoding="application/x-tex">A, B \subseteq X</annotation></semantics></math> such that <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mo>⊆</mo><mi>B</mi></mrow><annotation encoding="application/x-tex">A \subseteq B</annotation></semantics></math>. We have:</p>
<p><math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mtable><mtr><mtd columnalign="right" style="text-align: right; padding-right: 0"><mi>A</mi><mo>∪</mo><mi>B</mi></mtd><mtd columnalign="left" style="text-align: left; padding-left: 0"><mo>=</mo><mi>B</mi></mtd></mtr><mtr><mtd columnalign="right" style="text-align: right; padding-right: 0"><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo>∪</mo><mi>B</mi><mo stretchy="false" form="postfix">)</mo></mtd><mtd columnalign="left" style="text-align: left; padding-left: 0"><mo>=</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>B</mi><mo stretchy="false" form="postfix">)</mo></mtd></mtr></mtable><annotation encoding="application/x-tex">\begin{align*}
A \cup B &amp;= B \\
c(A \cup B) &amp;= c(B)
\end{align*}</annotation></semantics></math></p>
<p>From property <em>(d)</em> of <a href="#def-closure">Definition 2</a>:</p>
<p><math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo>∪</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>B</mi><mo stretchy="false" form="postfix">)</mo><mo>=</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>B</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex"> c(A) \cup c(B) = c(B)  </annotation></semantics></math></p>
<p>and therefore <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo>⊆</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>B</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">c(A) \subseteq c(B)</annotation></semantics></math>.</p>
</div>
<h2 id="equivalence-of-definitions">Equivalence of definitions</h2>
<h3 id="from-topology-to-kuratowski-closure">From topology to Kuratowski closure</h3>
<p>If we have a topology for which properties <em>(i)-(iii)</em> of <a href="#def-topology">Definition 1</a> hold, we can define an operator <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>c</mi><annotation encoding="application/x-tex">c</annotation></semantics></math> as:</p>
<p><math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo>=</mo><mo>⋂</mo><mrow><mo stretchy="true" form="prefix">{</mo><mi>F</mi><mo>:</mo><mspace width="0.278em"></mspace><mi>A</mi><mo>⊆</mo><mi>F</mi><mo>,</mo><mspace width="0.278em"></mspace><mi>F</mi><mrow><mspace width="0.333em"></mspace><mtext mathvariant="normal"> closed</mtext></mrow><mo stretchy="true" form="postfix">}</mo></mrow><mi>.</mi></mrow><annotation encoding="application/x-tex"> c(A) = \bigcap \left\{ F:\; A \subseteq F, \; F \text{ closed} \right\}. </annotation></semantics></math></p>
<p>From the definition, it is easy to see that for all <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mo>⊆</mo><mi>X</mi></mrow><annotation encoding="application/x-tex">A \subseteq X</annotation></semantics></math>,
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">c(A)</annotation></semantics></math> is closed. Indeed, by <a href="https://en.wikipedia.org/wiki/De_Morgan%27s_laws">de Morgan’s laws</a>, <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>X</mi><mo>\</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">X \setminus c(A)</annotation></semantics></math> is
a union of open sets, and therefore is open.</p>
<div id="prop-closure" class="proposition">
<p><span class="env-label">Proposition 2.</span> <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>c</mi><annotation encoding="application/x-tex">c</annotation></semantics></math> is a Kuratowski closure operator.</p>
</div>
<div class="proof">
<p><span class="env-label">Proof.</span> Let us prove all the properties in <a href="#def-closure">Definition 2</a>.</p>
<p><math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>∅</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">c(\emptyset)</annotation></semantics></math> is the intersection of all closed sets that contain the
empty set; since the empty set itself is closed, <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>∅</mi><mo stretchy="false" form="postfix">)</mo><mo>=</mo><mi>∅</mi></mrow><annotation encoding="application/x-tex">c(\emptyset) =
\emptyset</annotation></semantics></math>, proving <em>(a)</em>.</p>
<p>For <em>(b)</em>, let <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mo>⊆</mo><mi>X</mi></mrow><annotation encoding="application/x-tex">A \subseteq X</annotation></semantics></math>. <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">c(A)</annotation></semantics></math> is the intersection of sets that
are supersets of <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>A</mi><annotation encoding="application/x-tex">A</annotation></semantics></math>, so <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mo>⊆</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">A \subseteq c(A)</annotation></semantics></math>.</p>
<p>For <em>(c)</em>:
<math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo stretchy="false" form="postfix">)</mo><mo>=</mo><mo>⋂</mo><mrow><mo stretchy="true" form="prefix">{</mo><mi>F</mi><mo>:</mo><mspace width="0.278em"></mspace><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo>⊆</mo><mi>F</mi><mo>,</mo><mspace width="0.278em"></mspace><mi>F</mi><mrow><mspace width="0.333em"></mspace><mtext mathvariant="normal"> closed</mtext></mrow><mo stretchy="true" form="postfix">}</mo></mrow></mrow><annotation encoding="application/x-tex"> c(c(A)) = \bigcap \left\{ F:\; c(A) \subseteq F, \; F \text{ closed} \right\} </annotation></semantics></math></p>
<p>But <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">c(A)</annotation></semantics></math> itself is closed, so the intersection is <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">c(A)</annotation></semantics></math> itself and <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo stretchy="false" form="postfix">)</mo><mo>=</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">c(c(A)) = c(A)</annotation></semantics></math>.</p>
<p>Let us now turn to <em>(d)</em>, proving the equality by proving inclusion in both directions.</p>
<p><math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo>∪</mo><mi>B</mi><mo stretchy="false" form="postfix">)</mo><mo>=</mo><mo>⋂</mo><mrow><mo stretchy="true" form="prefix">{</mo><mi>F</mi><mo>:</mo><mspace width="0.278em"></mspace><mi>A</mi><mo>∪</mo><mi>B</mi><mo>⊆</mo><mi>F</mi><mo>,</mo><mspace width="0.278em"></mspace><mi>F</mi><mrow><mspace width="0.333em"></mspace><mtext mathvariant="normal"> closed</mtext></mrow><mo stretchy="true" form="postfix">}</mo></mrow></mrow><annotation encoding="application/x-tex"> c(A \cup B) = \bigcap \left\{ F:\; A \cup B \subseteq F, \; F \text{ closed} \right\} </annotation></semantics></math></p>
<p>If <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>F</mi><annotation encoding="application/x-tex">F</annotation></semantics></math> is closed and contains <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mo>∪</mo><mi>B</mi></mrow><annotation encoding="application/x-tex">A \cup B</annotation></semantics></math>, it contains <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>A</mi><annotation encoding="application/x-tex">A</annotation></semantics></math> and <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>B</mi><annotation encoding="application/x-tex">B</annotation></semantics></math> as well, so <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo>⊆</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo>∪</mo><mi>B</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">c(A) \subseteq c(A \cup B)</annotation></semantics></math> and <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>B</mi><mo stretchy="false" form="postfix">)</mo><mo>⊆</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo>∪</mo><mi>B</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">c(B) \subseteq c(A \cup B)</annotation></semantics></math>, and</p>
<p><math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo>∪</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>B</mi><mo stretchy="false" form="postfix">)</mo><mo>⊆</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo>∪</mo><mi>B</mi><mo stretchy="false" form="postfix">)</mo><mi>.</mi></mrow><annotation encoding="application/x-tex"> c(A) \cup c(B) \subseteq c(A \cup B). </annotation></semantics></math></p>
<p>Conversely, since <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mo>⊆</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">A \subseteq c(A)</annotation></semantics></math> and <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>B</mi><mo>⊆</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>B</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">B \subseteq c(B)</annotation></semantics></math>, we have</p>
<p><math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mo>∪</mo><mi>B</mi><mo>⊆</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo>∪</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>B</mi><mo stretchy="false" form="postfix">)</mo><mi>.</mi></mrow><annotation encoding="application/x-tex"> A \cup B \subseteq c(A) \cup c(B). </annotation></semantics></math></p>
<p>Both <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">c(A)</annotation></semantics></math> and <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>B</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">c(B)</annotation></semantics></math> are closed, so by <em>(iii)</em> with de Morgan’s laws, <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo>∪</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>B</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">c(A) \cup c(B)</annotation></semantics></math> is closed as well.
Hence <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo>∪</mo><mi>B</mi><mo stretchy="false" form="postfix">)</mo><mo>⊆</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo>∪</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>B</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">c(A \cup B) \subseteq c(A) \cup c(B)</annotation></semantics></math>, completing the equality.</p>
</div>
<h3 id="from-kuratowski-closure-to-topology">From Kuratowski closure to topology</h3>
<div id="prop-topology" class="proposition">
<p><span class="env-label">Proposition 3.</span> If <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo>:</mo><mi mathvariant="script">𝒫</mi><mo stretchy="false" form="prefix">(</mo><mi>X</mi><mo stretchy="false" form="postfix">)</mo><mo>→</mo><mi mathvariant="script">𝒫</mi><mo stretchy="false" form="prefix">(</mo><mi>X</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">c: \mathcal{P}(X) \to \mathcal{P}(X)</annotation></semantics></math> is a Kuratowski closure
operator, it induces a topology on <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>X</mi><annotation encoding="application/x-tex">X</annotation></semantics></math>.</p>
</div>
<div class="proof">
<p><span class="env-label">Proof.</span> For <em>(i)</em>, we can see that <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>∅</mi><mo stretchy="false" form="postfix">)</mo><mo>=</mo><mi>∅</mi></mrow><annotation encoding="application/x-tex">c(\emptyset) = \emptyset</annotation></semantics></math> by <em>(a)</em>, and by
<em>(b)</em>, <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>X</mi><mo>⊆</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>X</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">X \subseteq c(X)</annotation></semantics></math> so <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>X</mi><mo stretchy="false" form="postfix">)</mo><mo>=</mo><mi>X</mi></mrow><annotation encoding="application/x-tex">c(X) = X</annotation></semantics></math>. Therefore both <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>∅</mi><annotation encoding="application/x-tex">\emptyset</annotation></semantics></math> and
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>X</mi><annotation encoding="application/x-tex">X</annotation></semantics></math> are closed and both are open.</p>
<p>For <em>(ii)</em>, let <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false" form="prefix">(</mo><msub><mi>F</mi><mi>i</mi></msub><msub><mo stretchy="false" form="postfix">)</mo><mrow><mi>i</mi><mo>∈</mo><mi>I</mi></mrow></msub></mrow><annotation encoding="application/x-tex">(F_i)_{i\in I}</annotation></semantics></math> be a collection of closed sets,
i.e. for all <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>i</mi><mo>∈</mo><mi>I</mi></mrow><annotation encoding="application/x-tex">i \in I</annotation></semantics></math>, <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><msub><mi>F</mi><mi>i</mi></msub><mo stretchy="false" form="postfix">)</mo><mo>=</mo><msub><mi>F</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">c(F_i) = F_i</annotation></semantics></math>.
Then
<math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo>∀</mo><mi>j</mi><mo>∈</mo><mi>I</mi><mo>,</mo><munder><mo>⋂</mo><mrow><mi>i</mi><mo>∈</mo><mi>I</mi></mrow></munder><msub><mi>F</mi><mi>i</mi></msub><mo>⊆</mo><msub><mi>F</mi><mi>j</mi></msub><mo>,</mo></mrow><annotation encoding="application/x-tex"> \forall j \in I, \bigcap_{i\in I} F_i \subseteq F_j, </annotation></semantics></math></p>
<p>and by <a href="#prop-monotone">Proposition 1</a>,
<math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo>∀</mo><mi>j</mi><mo>∈</mo><mi>I</mi><mo>,</mo><mi>c</mi><mrow><mo stretchy="true" form="prefix">(</mo><munder><mo>⋂</mo><mrow><mi>i</mi><mo>∈</mo><mi>I</mi></mrow></munder><msub><mi>F</mi><mi>i</mi></msub><mo stretchy="true" form="postfix">)</mo></mrow><mo>⊆</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><msub><mi>F</mi><mi>j</mi></msub><mo stretchy="false" form="postfix">)</mo><mi>.</mi></mrow><annotation encoding="application/x-tex"> \forall j \in I, c\left( \bigcap_{i\in I} F_i \right) \subseteq c(F_j). </annotation></semantics></math></p>
<p>Hence
<math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mrow><mo stretchy="true" form="prefix">(</mo><munder><mo>⋂</mo><mrow><mi>i</mi><mo>∈</mo><mi>I</mi></mrow></munder><msub><mi>F</mi><mi>i</mi></msub><mo stretchy="true" form="postfix">)</mo></mrow><mo>⊆</mo><munder><mo>⋂</mo><mrow><mi>i</mi><mo>∈</mo><mi>I</mi></mrow></munder><mi>c</mi><mo stretchy="false" form="prefix">(</mo><msub><mi>F</mi><mi>i</mi></msub><mo stretchy="false" form="postfix">)</mo><mo>=</mo><munder><mo>⋂</mo><mrow><mi>i</mi><mo>∈</mo><mi>I</mi></mrow></munder><msub><mi>F</mi><mi>i</mi></msub><mi>.</mi></mrow><annotation encoding="application/x-tex"> c\left( \bigcap_{i\in I} F_i \right) \subseteq \bigcap_{i\in I} c(F_i) = \bigcap_{i\in I} F_i. </annotation></semantics></math></p>
<p>By <em>(b)</em>,
<math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><munder><mo>⋂</mo><mrow><mi>i</mi><mo>∈</mo><mi>I</mi></mrow></munder><msub><mi>F</mi><mi>i</mi></msub><mo>⊆</mo><mi>c</mi><mrow><mo stretchy="true" form="prefix">(</mo><munder><mo>⋂</mo><mrow><mi>i</mi><mo>∈</mo><mi>I</mi></mrow></munder><msub><mi>F</mi><mi>i</mi></msub><mo stretchy="true" form="postfix">)</mo></mrow><mo>,</mo></mrow><annotation encoding="application/x-tex"> \bigcap_{i\in I} F_i \subseteq c\left( \bigcap_{i\in I} F_i \right), </annotation></semantics></math></p>
<p>so <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mo>⋂</mo><mrow><mi>i</mi><mo>∈</mo><mi>I</mi></mrow></msub><msub><mi>F</mi><mi>i</mi></msub><mo>=</mo><mi>c</mi><mrow><mo stretchy="true" form="prefix">(</mo><msub><mo>⋂</mo><mrow><mi>i</mi><mo>∈</mo><mi>I</mi></mrow></msub><msub><mi>F</mi><mi>i</mi></msub><mo stretchy="true" form="postfix">)</mo></mrow></mrow><annotation encoding="application/x-tex">\bigcap_{i\in I} F_i = c\left( \bigcap_{i\in I} F_i \right)</annotation></semantics></math> and the intersection of all <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false" form="prefix">(</mo><msub><mi>F</mi><mi>i</mi></msub><msub><mo stretchy="false" form="postfix">)</mo><mrow><mi>i</mi><mo>∈</mo><mi>I</mi></mrow></msub></mrow><annotation encoding="application/x-tex">(F_i)_{i\in I}</annotation></semantics></math> is closed.
Therefore an arbitrary intersection of closed sets is closed, and by de Morgan, an arbitrary union of open sets is open.</p>
<p>Now we turn to <em>(iii)</em> of <a href="#def-topology">Definition 1</a>. Let <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mo>,</mo><mi>B</mi><mo>⊆</mo><mi>X</mi></mrow><annotation encoding="application/x-tex">A, B \subseteq X</annotation></semantics></math> be
closed. By <em>(d)</em>,</p>
<p><math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mtable><mtr><mtd columnalign="right" style="text-align: right; padding-right: 0"><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo>∪</mo><mi>B</mi><mo stretchy="false" form="postfix">)</mo></mtd><mtd columnalign="left" style="text-align: left; padding-left: 0"><mo>=</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo>∪</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>B</mi><mo stretchy="false" form="postfix">)</mo></mtd></mtr><mtr><mtd columnalign="right" style="text-align: right; padding-right: 0"></mtd><mtd columnalign="left" style="text-align: left; padding-left: 0"><mo>=</mo><mi>A</mi><mo>∪</mo><mi>B</mi><mi>.</mi></mtd></mtr></mtable><annotation encoding="application/x-tex">\begin{align*}
c(A \cup B) &amp;= c(A) \cup c(B) \\
  &amp;= A \cup B.
\end{align*}</annotation></semantics></math></p>
<p>So <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mo>∪</mo><mi>B</mi></mrow><annotation encoding="application/x-tex">A \cup B</annotation></semantics></math> is closed, and any finite union of closed sets is closed, which completes the proof.</p>
</div>
<h2 id="idempotence">Idempotence</h2>
<p>Looking at the proof of <a href="#prop-topology">Proposition 3</a>, we notice that we never used
property <em>(c)</em> of the Kuratowski closure, the one related to
idempotence. This is because we don’t actually need it to prove the
equivalence between the Kuratowski closure axioms and the topology
axioms!</p>
<p>It is usually present in the list because it matches our intuition
nicely about “closeness”. Without the idempotence axiom, the operator
is called a <a href="https://en.wikipedia.org/wiki/Preclosure_operator">preclosure operator</a> or Čech closure operator.</p>
<p>So if we start from the open sets definition of a topology
(<a href="#def-topology">Definition 1</a>), the natural closure operator associated with it will
be idempotent.</p>
<p>On the other hand, we can take a preclosure operator (<a href="#def-closure">Definition 2</a>
without <em>(c)</em> idempotence) and define a valid topology (such a space
where the closure operator is not assumed idempotent is called a
<a href="https://en.wikipedia.org/wiki/Pretopological_space">pretopological space</a>). Of course we can now take this topology and
define a new closure operator which will be idempotent!</p>
<h2 id="continuity">Continuity</h2>
<p>Topological spaces are the natural context in which to define
continuity. So it is natural to ask: how does the definition translate
in terms of closure operators?</p>
<p>As a reminder, a function is said to be continuous if the preimage of
any open set is open:</p>
<div id="def-continuity" class="definition">
<p><span class="env-label">Definition 3.</span> Let <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>X</mi><annotation encoding="application/x-tex">X</annotation></semantics></math> and <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>Y</mi><annotation encoding="application/x-tex">Y</annotation></semantics></math> be topological spaces. A function <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>f</mi><mo>:</mo><mi>X</mi><mo>→</mo><mi>Y</mi></mrow><annotation encoding="application/x-tex">f: X \to Y</annotation></semantics></math> is
<em>continuous</em> if for every open set <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>U</mi><annotation encoding="application/x-tex">U</annotation></semantics></math> in <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>Y</mi><annotation encoding="application/x-tex">Y</annotation></semantics></math>, <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>f</mi><mrow><mi>−</mi><mn>1</mn></mrow></msup><mo stretchy="false" form="prefix">(</mo><mi>U</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">f^{-1}(U)</annotation></semantics></math> is open in
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>X</mi><annotation encoding="application/x-tex">X</annotation></semantics></math>.</p>
</div>
<p>We can now express continuity in terms of closure operators: a
continuous function maps points <em>close</em> to <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>A</mi><annotation encoding="application/x-tex">A</annotation></semantics></math> to points close to
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>f</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">f(A)</annotation></semantics></math>.</p>
<div id="prop-continuity" class="proposition">
<p><span class="env-label">Proposition 4.</span> Let <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>X</mi><annotation encoding="application/x-tex">X</annotation></semantics></math> and <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>Y</mi><annotation encoding="application/x-tex">Y</annotation></semantics></math> be topological spaces, with associated closure
operators <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>c</mi><mi>X</mi></msub><annotation encoding="application/x-tex">c_X</annotation></semantics></math> and <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>c</mi><mi>Y</mi></msub><annotation encoding="application/x-tex">c_Y</annotation></semantics></math>.</p>
<p>A function <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>f</mi><mo>:</mo><mi>X</mi><mo>→</mo><mi>Y</mi></mrow><annotation encoding="application/x-tex">f: X \to Y</annotation></semantics></math> is continuous if, and only if, for all <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mo>⊆</mo><mi>X</mi></mrow><annotation encoding="application/x-tex">A
\subseteq X</annotation></semantics></math>,</p>
<p><math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>f</mi><mo stretchy="false" form="prefix">(</mo><msub><mi>c</mi><mi>X</mi></msub><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo stretchy="false" form="postfix">)</mo><mo>⊆</mo><msub><mi>c</mi><mi>Y</mi></msub><mo stretchy="false" form="prefix">(</mo><mi>f</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo stretchy="false" form="postfix">)</mo><mi>.</mi></mrow><annotation encoding="application/x-tex"> f(c_X(A)) \subseteq c_Y(f(A)). </annotation></semantics></math></p>
</div>
<div class="proof">
<p><span class="env-label">Proof.</span> To simplify the notation, we will denote both <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>c</mi><mi>X</mi></msub><annotation encoding="application/x-tex">c_X</annotation></semantics></math> and <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>c</mi><mi>Y</mi></msub><annotation encoding="application/x-tex">c_Y</annotation></semantics></math> as <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>c</mi><annotation encoding="application/x-tex">c</annotation></semantics></math>.</p>
<p>Assume that <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>f</mi><annotation encoding="application/x-tex">f</annotation></semantics></math> is continuous.</p>
<p><math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>f</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo stretchy="false" form="postfix">)</mo><mo>=</mo><mo>⋂</mo><mrow><mo stretchy="true" form="prefix">{</mo><mi>F</mi><mo>:</mo><mspace width="0.278em"></mspace><mi>f</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo>⊆</mo><mi>F</mi><mo>,</mo><mspace width="0.278em"></mspace><mi>F</mi><mrow><mspace width="0.333em"></mspace><mtext mathvariant="normal"> closed</mtext></mrow><mo stretchy="true" form="postfix">}</mo></mrow></mrow><annotation encoding="application/x-tex"> c(f(A)) = \bigcap \left\{ F:\; f(A) \subseteq F, \; F \text{ closed} \right\} </annotation></semantics></math></p>
<p>Since <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>f</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo>⊆</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>f</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">f(A) \subseteq c(f(A))</annotation></semantics></math>, <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mo>⊆</mo><msup><mi>f</mi><mrow><mi>−</mi><mn>1</mn></mrow></msup><mo stretchy="false" form="prefix">(</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>f</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo stretchy="false" form="postfix">)</mo><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">A \subseteq f^{-1}(c(f(A)))</annotation></semantics></math>.
Moreover, since <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>f</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">c(f(A))</annotation></semantics></math> is closed and <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>f</mi><annotation encoding="application/x-tex">f</annotation></semantics></math> is continuous, <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>f</mi><mrow><mi>−</mi><mn>1</mn></mrow></msup><mo stretchy="false" form="prefix">(</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>f</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo stretchy="false" form="postfix">)</mo><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">f^{-1}(c(f(A)))</annotation></semantics></math> is closed. So</p>
<p><math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo>⊆</mo><msup><mi>f</mi><mrow><mi>−</mi><mn>1</mn></mrow></msup><mo stretchy="false" form="prefix">(</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>f</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo stretchy="false" form="postfix">)</mo><mo stretchy="false" form="postfix">)</mo><mo>,</mo></mrow><annotation encoding="application/x-tex"> c(A) \subseteq f^{-1}(c(f(A))), </annotation></semantics></math></p>
<p>and by applying <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>f</mi><annotation encoding="application/x-tex">f</annotation></semantics></math> on both sides,</p>
<p><math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>f</mi><mo stretchy="false" form="prefix">(</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo stretchy="false" form="postfix">)</mo><mo>⊆</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>f</mi><mo stretchy="false" form="prefix">(</mo><mi>A</mi><mo stretchy="false" form="postfix">)</mo><mo stretchy="false" form="postfix">)</mo><mi>.</mi></mrow><annotation encoding="application/x-tex"> f(c(A)) \subseteq c(f(A)). </annotation></semantics></math></p>
<p>Now we show the converse implication. Recall that <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>f</mi><annotation encoding="application/x-tex">f</annotation></semantics></math> is continuous if
and only if the preimage of every closed set is closed. Let <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>F</mi><mo>⊆</mo><mi>Y</mi></mrow><annotation encoding="application/x-tex">F
\subseteq Y</annotation></semantics></math> closed. We have</p>
<p><math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>f</mi><mo stretchy="false" form="prefix">(</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><msup><mi>f</mi><mrow><mi>−</mi><mn>1</mn></mrow></msup><mo stretchy="false" form="prefix">(</mo><mi>F</mi><mo stretchy="false" form="postfix">)</mo><mo stretchy="false" form="postfix">)</mo><mo stretchy="false" form="postfix">)</mo><mo>⊆</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>f</mi><mo stretchy="false" form="prefix">(</mo><msup><mi>f</mi><mrow><mi>−</mi><mn>1</mn></mrow></msup><mo stretchy="false" form="prefix">(</mo><mi>F</mi><mo stretchy="false" form="postfix">)</mo><mo stretchy="false" form="postfix">)</mo><mo stretchy="false" form="postfix">)</mo><mo>⊆</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><mi>F</mi><mo stretchy="false" form="postfix">)</mo><mo>=</mo><mi>F</mi><mi>.</mi></mrow><annotation encoding="application/x-tex"> f(c(f^{-1}(F))) \subseteq c(f(f^{-1}(F))) \subseteq c(F) = F. </annotation></semantics></math></p>
<p>Since every element of <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><msup><mi>f</mi><mrow><mi>−</mi><mn>1</mn></mrow></msup><mo stretchy="false" form="prefix">(</mo><mi>F</mi><mo stretchy="false" form="postfix">)</mo><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">c(f^{-1}(F))</annotation></semantics></math> has its image by <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>f</mi><annotation encoding="application/x-tex">f</annotation></semantics></math> in <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>F</mi><annotation encoding="application/x-tex">F</annotation></semantics></math>, it
belongs to <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>f</mi><mrow><mi>−</mi><mn>1</mn></mrow></msup><mo stretchy="false" form="prefix">(</mo><mi>F</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">f^{-1}(F)</annotation></semantics></math>, so</p>
<p><math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mo stretchy="false" form="prefix">(</mo><msup><mi>f</mi><mrow><mi>−</mi><mn>1</mn></mrow></msup><mo stretchy="false" form="prefix">(</mo><mi>F</mi><mo stretchy="false" form="postfix">)</mo><mo stretchy="false" form="postfix">)</mo><mo>⊆</mo><msup><mi>f</mi><mrow><mi>−</mi><mn>1</mn></mrow></msup><mo stretchy="false" form="prefix">(</mo><mi>F</mi><mo stretchy="false" form="postfix">)</mo><mo>,</mo></mrow><annotation encoding="application/x-tex"> c(f^{-1}(F)) \subseteq f^{-1}(F), </annotation></semantics></math></p>
<p>and by <em>(b)</em>, <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>f</mi><mrow><mi>−</mi><mn>1</mn></mrow></msup><mo stretchy="false" form="prefix">(</mo><mi>F</mi><mo stretchy="false" form="postfix">)</mo><mo>⊆</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><msup><mi>f</mi><mrow><mi>−</mi><mn>1</mn></mrow></msup><mo stretchy="false" form="prefix">(</mo><mi>F</mi><mo stretchy="false" form="postfix">)</mo><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">f^{-1}(F) \subseteq c(f^{-1}(F))</annotation></semantics></math>, so</p>
<p><math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>f</mi><mrow><mi>−</mi><mn>1</mn></mrow></msup><mo stretchy="false" form="prefix">(</mo><mi>F</mi><mo stretchy="false" form="postfix">)</mo><mo>=</mo><mi>c</mi><mo stretchy="false" form="prefix">(</mo><msup><mi>f</mi><mrow><mi>−</mi><mn>1</mn></mrow></msup><mo stretchy="false" form="prefix">(</mo><mi>F</mi><mo stretchy="false" form="postfix">)</mo><mo stretchy="false" form="postfix">)</mo><mo>,</mo></mrow><annotation encoding="application/x-tex"> f^{-1}(F) = c(f^{-1}(F)), </annotation></semantics></math></p>
<p>and <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>f</mi><mrow><mi>−</mi><mn>1</mn></mrow></msup><mo stretchy="false" form="prefix">(</mo><mi>F</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">f^{-1}(F)</annotation></semantics></math> is closed. Therefore <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>f</mi><annotation encoding="application/x-tex">f</annotation></semantics></math> is continuous.</p>
</div>
<h2 id="conclusion">Conclusion</h2>
<p>What I find most interesting about this alternative formalization of a
topology is that it is easy to see which axioms are essential and
which are not: we have seen that idempotence is not actually needed to
recover a topology from the closure axioms.</p>
<p>We have also seen that axiom <em>(d)</em> (preservation of unions) implies
monotonicity (<a href="#prop-monotone">Proposition 1</a>). If we replace axiom <em>(d)</em> with
monotonicity itself, we end up with a <a href="https://en.wikipedia.org/wiki/Closure_operator">closure operator</a>, whose
instances include convex hulls, linear spans, and algebraic
closures. Among all closure operators, topologies are identified by
the preservation of unions.</p>
</section>
]]></content:encoded>
    <pubDate>Tue, 10 Nov 2026 00:00:00 UT</pubDate>
    <guid>https://lozeve.com/posts/kuratowski-closure-topology.html</guid>
    <dc:creator>Dimitri Lozeve</dc:creator>
</item>
<item>
    <title>The recursive matrix formula for the Hilbert curve</title>
    <link>https://lozeve.com/posts/hilbert-curve-matrix.html</link>
    <content:encoded><![CDATA[<section>
  <p>The <a href="https://en.wikipedia.org/wiki/Hilbert_curve">Hilbert curve</a> <span class="sidenote-wrapper"><label for="sn-0" class="margin-toggle">⊕</label><input type="checkbox" id="sn-0" class="margin-toggle" /><span class="marginnote"><br />
<br />
<img src="https://lozeve.com/images/Hilbert_plasma_aligned.gif" alt="Animation of the first 7 iterations of the Hilbert curve." /><br />
<br />
</span></span> is probably the most famous
example of a <a href="https://en.wikipedia.org/wiki/Space-filling_curve">space-filling curve</a>: a 1-dimensional curve which can
reach every point in a 2-dimensional region.</p>
<p>The Hilbert curve is useful for mapping algorithms, because it
provides a nice mapping between 1D and 2D, preserving locality: places
that are close in 2D space will also be close in the 1D coordinates
along the Hilbert curve. A nice illustration of this can be found <a href="https://datascienceconfidential.github.io//r/graphics/2026/10/26/space-filling-curves.html">in this blog post</a>, where they map all battles in Great Britain to display
a simple 2D chart with the date on the <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>y</mi><annotation encoding="application/x-tex">y</annotation></semantics></math>-axis and the location on
the <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>x</mi><annotation encoding="application/x-tex">x</annotation></semantics></math>-axis.</p>
<p>I knew about the recursive construction of the Hilbert curve, and the
way to construct it via the <a href="https://lozeve.com/posts/lsystems.html">L-system formulation</a>, but the blog post
also mentions a way to represent the curve as a single matrix,
containing numbers from 0 to <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>n</mi><mn>2</mn></msup><mo>−</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">n^2-1</annotation></semantics></math> along the path of the curve.</p>
<p><math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="true" form="prefix">[</mo><mtable><mtr><mtd columnalign="center" style="text-align: center"><mn>0</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>3</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>4</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>5</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>58</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>59</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>60</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>63</mn></mtd></mtr><mtr><mtd columnalign="center" style="text-align: center"><mn>1</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>2</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>7</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>6</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>57</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>56</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>61</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>62</mn></mtd></mtr><mtr><mtd columnalign="center" style="text-align: center"><mn>14</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>13</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>8</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>9</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>54</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>55</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>50</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>49</mn></mtd></mtr><mtr><mtd columnalign="center" style="text-align: center"><mn>15</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>12</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>11</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>10</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>53</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>52</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>51</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>48</mn></mtd></mtr><mtr><mtd columnalign="center" style="text-align: center"><mn>16</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>17</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>30</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>31</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>32</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>33</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>46</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>47</mn></mtd></mtr><mtr><mtd columnalign="center" style="text-align: center"><mn>19</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>18</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>29</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>28</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>35</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>34</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>45</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>44</mn></mtd></mtr><mtr><mtd columnalign="center" style="text-align: center"><mn>20</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>23</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>24</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>27</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>36</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>39</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>40</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>43</mn></mtd></mtr><mtr><mtd columnalign="center" style="text-align: center"><mn>21</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>22</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>25</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>26</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>37</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>38</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>41</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>42</mn></mtd></mtr><mtr><mtd columnalign="center" style="text-align: center"></mtd></mtr></mtable><mo stretchy="true" form="postfix">]</mo></mrow><annotation encoding="application/x-tex">
\begin{bmatrix}
   0 &amp;  3 &amp;  4 &amp;  5 &amp; 58 &amp; 59 &amp; 60 &amp; 63 \\
   1 &amp;  2 &amp;  7 &amp;  6 &amp; 57 &amp; 56 &amp; 61 &amp; 62 \\
  14 &amp; 13 &amp;  8 &amp;  9 &amp; 54 &amp; 55 &amp; 50 &amp; 49 \\
  15 &amp; 12 &amp; 11 &amp; 10 &amp; 53 &amp; 52 &amp; 51 &amp; 48 \\
  16 &amp; 17 &amp; 30 &amp; 31 &amp; 32 &amp; 33 &amp; 46 &amp; 47 \\
  19 &amp; 18 &amp; 29 &amp; 28 &amp; 35 &amp; 34 &amp; 45 &amp; 44 \\
  20 &amp; 23 &amp; 24 &amp; 27 &amp; 36 &amp; 39 &amp; 40 &amp; 43 \\
  21 &amp; 22 &amp; 25 &amp; 26 &amp; 37 &amp; 38 &amp; 41 &amp; 42 \\
\end{bmatrix}
</annotation></semantics></math></p>
<p>How can we build this matrix? The Wikipedia page did not explain this
and I couldn’t find an explicit construction anywhere, so I tried to
derive it directly.</p>
<p>You start with the base case <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>2</mn><mo>×</mo><mn>2</mn></mrow><annotation encoding="application/x-tex">2\times2</annotation></semantics></math> matrix:</p>
<p><math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>H</mi><mn>1</mn></msub><mo>=</mo><mrow><mo stretchy="true" form="prefix">[</mo><mtable><mtr><mtd columnalign="center" style="text-align: center"><mn>0</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>3</mn></mtd></mtr><mtr><mtd columnalign="center" style="text-align: center"><mn>1</mn></mtd><mtd columnalign="center" style="text-align: center"><mn>2</mn></mtd></mtr></mtable><mo stretchy="true" form="postfix">]</mo></mrow><mo>,</mo></mrow><annotation encoding="application/x-tex">
H_1=\begin{bmatrix}0&amp;3\\1&amp;2\end{bmatrix},
</annotation></semantics></math></p>
<p>and from the <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>k</mi><mo>×</mo><mi>k</mi></mrow><annotation encoding="application/x-tex"> k\times k </annotation></semantics></math> matrix you can build the next one as
follows:</p>
<p><math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>H</mi><mrow><mi>k</mi><mo>+</mo><mn>1</mn></mrow></msub><mo>=</mo><mrow><mo stretchy="true" form="prefix">[</mo><mtable><mtr><mtd columnalign="center" style="text-align: center"><msubsup><mi>H</mi><mi>k</mi><mi>⊤</mi></msubsup></mtd><mtd columnalign="center" style="text-align: center"><mi>R</mi><mo stretchy="false" form="prefix">(</mo><msubsup><mi>H</mi><mi>k</mi><mi>⊤</mi></msubsup><mo stretchy="false" form="postfix">)</mo><mo>+</mo><mn>3</mn><mo>⋅</mo><msup><mn>4</mn><mi>k</mi></msup></mtd></mtr><mtr><mtd columnalign="center" style="text-align: center"><msub><mi>H</mi><mi>k</mi></msub><mo>+</mo><msup><mn>4</mn><mi>k</mi></msup></mtd><mtd columnalign="center" style="text-align: center"><msub><mi>H</mi><mi>k</mi></msub><mo>+</mo><mn>2</mn><mo>⋅</mo><msup><mn>4</mn><mi>k</mi></msup></mtd></mtr></mtable><mo stretchy="true" form="postfix">]</mo></mrow></mrow><annotation encoding="application/x-tex">
H_{k+1}=\begin{bmatrix}
H_k^{\top} &amp; R(H_k^{\top})+3\cdot 4^k\\[4pt]
H_k+4^k &amp; H_k+2\cdot 4^k
\end{bmatrix}
</annotation></semantics></math></p>
<p>where <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>R</mi><mo stretchy="false" form="prefix">(</mo><mi>M</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">R(M)</annotation></semantics></math> is the matrix <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>M</mi><annotation encoding="application/x-tex">M</annotation></semantics></math> rotated by 180°.</p>
<p>Intuitively, every matrix <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>H</mi><mi>k</mi></msub><annotation encoding="application/x-tex">H_k</annotation></semantics></math> starts at the top-left corner, and
ends at the top-right corner. For <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>H</mi><mrow><mi>k</mi><mo>+</mo><mn>1</mn></mrow></msub><annotation encoding="application/x-tex">H_{k+1}</annotation></semantics></math>, we follow the general
structure of the Hilbert curve (as seen in <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>H</mi><mn>1</mn></msub><annotation encoding="application/x-tex">H_1</annotation></semantics></math>):</p>
<ol type="1">
<li>The top-left quadrant needs to start at the top left, but to end at
the bottom left. A good candidate is therefore <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msubsup><mi>H</mi><mi>k</mi><mi>⊤</mi></msubsup><annotation encoding="application/x-tex">H_k^\top</annotation></semantics></math>.</li>
<li>The bottom-left quadrant needs to start at the top-left and end at
the top-right. This is just <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>H</mi><mi>k</mi></msub><annotation encoding="application/x-tex">H_k</annotation></semantics></math>.</li>
<li>The bottom-right quadrant is the same: <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>H</mi><mi>k</mi></msub><annotation encoding="application/x-tex">H_k</annotation></semantics></math> again.</li>
<li>The top-right quadrant needs to start at the bottom right, and end
at the top right. For this we need to transpose <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>H</mi><mi>k</mi></msub><annotation encoding="application/x-tex">H_k</annotation></semantics></math> and then
rotate it 180°.</li>
</ol>
<div class="sidenote-wrapper">
<input type="checkbox" id="sn-1" class="margin-toggle" />
<div class="marginnote">
<p>Or in <a href="https://mlochbaum.github.io/BQN/try.html#code=SGlsYmVydFJlY+KGkHsKICBvZmbihpDDl8uc4omg8J2VqQogIHRs4oaQ4o2J8J2VqQogIHRy4oaQKOKMveKMvuKliuKNifCdlakpKzPDl29mZgogIGJs4oaQ8J2VqStvZmYKICBicuKGkPCdlakrMsOXb2ZmCiAgKHRs4oi+y5h0ciniiL4oYmziiL7LmGJyKQp9CgpoMeKGkFtbMCwzXSxbMSwyXV0KSGlsYmVydOKGkHtIaWxiZXJ0UmVj4o2fKPCdlaktMSloMX0KCkhpbGJlcnQgMw==">BQN</a>:</p>
<pre class="bqn"><code>HilbertRec←{
  off←×˜≠𝕩
  tl←⍉𝕩
  tr←(⌽⌾⥊⍉𝕩)+3×off
  bl←𝕩+off
  br←𝕩+2×off
  (tl∾˘tr)∾(bl∾˘br)
}

h1←[[0,3],[1,2]]
Hilbert←{HilbertRec⍟(𝕩-1)h1}

Hilbert 3
</code></pre>
</div>
</div>
<p>All of this can be implemented in a few lines of Python with Numpy:<label for="sn-1" class="margin-toggle">⊕</label></p>
<div class="sourceCode" id="cb2"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> numpy <span class="im">as</span> np</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> hilbert(n):</span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a>    H <span class="op">=</span> np.array([[<span class="dv">0</span>, <span class="dv">3</span>], [<span class="dv">1</span>, <span class="dv">2</span>]])</span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a>    <span class="cf">for</span> k <span class="kw">in</span> <span class="bu">range</span>(<span class="dv">1</span>, n):</span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a>        off <span class="op">=</span> <span class="dv">4</span><span class="op">**</span>k</span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a>        TL <span class="op">=</span> H.T</span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a>        TR <span class="op">=</span> np.rot90(H.T, <span class="dv">2</span>) <span class="op">+</span> <span class="dv">3</span> <span class="op">*</span> off</span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a>        BL <span class="op">=</span> H <span class="op">+</span> off</span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a>        BR <span class="op">=</span> H <span class="op">+</span> <span class="dv">2</span> <span class="op">*</span> off</span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a>        H <span class="op">=</span> np.block([[TL, TR], [BL, BR]])</span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a>    <span class="cf">return</span> H</span></code></pre></div>
<p>I think for most use cases there are better ways than generating the
full matrix (there are explicit formulas to convert <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false" form="prefix">(</mo><mi>x</mi><mo>,</mo><mi>y</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">(x,y)</annotation></semantics></math>
coordinates to the index <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>d</mi><annotation encoding="application/x-tex">d</annotation></semantics></math> on the curve and vice-versa), but I
found this construction interesting as it clearly mirrors the visual
construction of the Hilbert curve.</p>
</section>
]]></content:encoded>
    <pubDate>Wed, 04 Nov 2026 00:00:00 UT</pubDate>
    <guid>https://lozeve.com/posts/hilbert-curve-matrix.html</guid>
    <dc:creator>Dimitri Lozeve</dc:creator>
</item>
<item>
    <title>Two Types of Bureaucracy: Enabling and Coercive</title>
    <link>https://lozeve.com/posts/types-of-bureaucracy-enabling-and-coercive.html</link>
    <content:encoded><![CDATA[<section>
  <p>This post is a summary of a paper by
<span class="citation" data-cites="adler1996_two_types_bureauc">Adler and Borys (1996)</span>. It argues that despite the bad
reputation of “bureaucracy” in organizations, a set of formal
procedures can be beneficial. Using a comparison with technology, they
define two types of formalization, <em>coercive</em> and <em>enabling</em>, each
with their characteristics, and analyze the factors that encourage one
or the other form.</p>
<div id="toc"><h2>Table of Contents</h2><ul>
<li><a href="#bureaucracy-and-workflow-formalization" id="toc-bureaucracy-and-workflow-formalization">Bureaucracy and workflow formalization</a></li>
<li><a href="#standard-views-of-formalization" id="toc-standard-views-of-formalization">Standard views of formalization</a>
<ul>
<li><a href="#negative" id="toc-negative">Negative</a></li>
<li><a href="#positive" id="toc-positive">Positive</a></li>
</ul></li>
<li><a href="#enabling-and-coercive-bureaucracy" id="toc-enabling-and-coercive-bureaucracy">Enabling and coercive bureaucracy</a>
<ul>
<li><a href="#an-analogy-with-technology" id="toc-an-analogy-with-technology">An analogy with technology</a></li>
<li><a href="#features-of-enabling-and-coercive-formalization" id="toc-features-of-enabling-and-coercive-formalization">Features of enabling and coercive formalization</a></li>
</ul></li>
<li><a href="#implementation-of-enabling-bureaucracy" id="toc-implementation-of-enabling-bureaucracy">Implementation of enabling bureaucracy</a>
<ul>
<li><a href="#typology-of-organizations" id="toc-typology-of-organizations">Typology of organizations</a></li>
<li><a href="#factors-influencing-the-emergence-of-a-coercive-or-an-enabling-bureaucracy" id="toc-factors-influencing-the-emergence-of-a-coercive-or-an-enabling-bureaucracy">Factors influencing the emergence of a coercive or an enabling bureaucracy</a></li>
</ul></li>
<li><a href="#references" id="toc-references">References</a></li>
</ul></div>
<h2 id="bureaucracy-and-workflow-formalization">Bureaucracy and workflow formalization</h2>
<p>This paper <span class="citation" data-cites="adler1996_two_types_bureauc">(Adler and Borys 1996)</span> provides an analysis of
bureaucracy and formal procedures and processes in organizations. They
distinguish two kinds of bureaucracies: one is <em>enabling</em>, helping
people master tasks, clarifies responsibilities, and provide guidance,
the other is <em>coercive</em>, enforcing each employee’s compliance and
stifling creativity and motivation.</p>
<p>The focus is on “workflow formalization” (i.e. processes), which they
define as “written values, procedures, and instructions”.</p>
<p>Contrary to the common negative view of bureaucracy, they claim that
what is important is not the <em>degree</em> of formalization (i.e. more
formalization is not necessarily bad), but its type (how are your
values and procedures designed? what kind of bureaucracy do you
have?).</p>
<h2 id="standard-views-of-formalization">Standard views of formalization</h2>
<h3 id="negative">Negative</h3>
<p>The basic (negative) intuition about bureaucracy and formalization is
that they lead to a kind of alienation of the worker, restricting his
individual autonomy. In this view, work is fundamentally bad, a
disutility. This is the (neo-)Marxist view of work.</p>
<p>In the human resource management literature, the only possible
alternative to coercive formalization is the absence of any
formalization. In their view, formalization can only lead to less
commitment, more dissatisfaction, and less creativity.<span class="sidenote-wrapper"><label for="sn-0" class="margin-toggle sidenote-number"></label><input type="checkbox" id="sn-0" class="margin-toggle" /><span class="sidenote">Incidentally, I think that this view is still widely
shared, decades after this paper. A lot of startup founders truly
believe that any kind of procedure or value formalization will lead to
decrease in creativity and overall job satisfaction. Conveniently,
they often forget about the part where work is fundamentally a
disutility, instead praising extreme work hours…<br />
<br />
</span></span></p>
<h3 id="positive">Positive</h3>
<p>Work can be fulfilling. Being part of an organization can be felt as
an increase in cooperation, rather than a loss in autonomy.</p>
<p>In general, whenever there is an overlap between the employee’s and
the organization’s interest, formalization is welcome, as it can
improve efficiency.</p>
<p>Formalization can also clarify responsibilities, and hereby reduce
role conflicts and ambiguity. All of this leads to less alienation, as
people know what they are supposed to do and why.</p>
<p>Finally, there is evidence of a positive correlation between
formalization and innovation (both in the product and in
processes). Fundamentally, well-designed procedures help in capturing
lessons from previous experiences and help coordination between
members of an organization.</p>
<h2 id="enabling-and-coercive-bureaucracy">Enabling and coercive bureaucracy</h2>
<p>Clearly, there has to be something else that we have not taken into
account. Bureaucracy and formalization cannot be entirely good or
bad. In real life, people are noted to resent “bad” formalization,
while “good” rules are welcome. What makes a rule “better” than
another?</p>
<p>A first hint comes from attempts to find patterns of bureaucracy:</p>
<ul>
<li><em>representative bureaucracy</em>: rules serve the interests of both
managers and workers,</li>
<li><em>punishment-centered bureaucracy</em>: rules serve to assert right of
managers to sanction workers,</li>
<li><em>mock bureaucracy</em>: rules are ignored by both parties.</li>
</ul>
<p>But these categories are not easy to delineate in practice. What we
need is to find the relevant properties of the rules themselves, not
the intent behind them (which will always be difficult to assess).</p>
<h3 id="an-analogy-with-technology">An analogy with technology</h3>
<p>Technology provides a useful comparison. First, a definition of
technology:</p>
<blockquote>
<p>Technology is know-how that has been objectified and thus rendered
relatively independent of the skill of specific actors.</p>
</blockquote>
<p>Examples of such objectifications:</p>
<ul>
<li>equipment and software,</li>
<li>organization procedures and structures.</li>
</ul>
<p>There is a debate on the impact of technology, and in particular
automation. Some view it as fundamentally deskilling and alienating,
degrading work. Others view technology as enabling and upgrading work,
augmenting capabilities.</p>
<p>In the specific case of equipment, the important thing is how it was
designed. Was it intended as a means to deskill workers,
“fool-proofing” it, in a way that shows that the designers did not
trust the workers? In this case, the objective was probably to reduce
reliance on highly-skilled workers. Alternatively, it may have been
designed to enhance workers’ abilities, and increase their skills. The
user can either be thought of as a source of problems to be eliminated
or as a source of intelligence to be supported and enhanced.</p>
<p>Similarly to technology, formal procedures can’t make work processes
fool-proof, and they should not be designed to do so. Instead, they
should aim at enabling employees to be more effective in their
work. In particular, formalization can help employees deal more
effectively with unexpected contingencies (which always happen), and
can codify and diffuse best practices. These unexpected scenarios will
always happen: instead of forcing workers’ behavior in the “happy
path”, leaving them stuck during the unexpected, try to leverage their
skills and motivations to deal with them.</p>
<p>Coercive formalization will try to force commitment, compliance,
through a reluctant effort. Enabling formalization will try to
leverage employees’ commitment in order to help them deal with their
job more effectively, by providing necessary organizational
experience.</p>
<h3 id="features-of-enabling-and-coercive-formalization">Features of enabling and coercive formalization</h3>
<p><span class="sidenote-wrapper"><label for="sn-1" class="margin-toggle">⊕</label><input type="checkbox" id="sn-1" class="margin-toggle" /><span class="marginnote">All of these characteristics of enabling formalization
closely resembles the structure of <a href="https://lozeve.com/posts/high-reliability-organizations.html">High reliability organizations</a>.<br />
<br />
</span></span></p>
<h4 id="repair">Repair</h4>
<p>In the coercive logic, procedures are used to check that employees
operate in compliance, not to help them identify or solve
problems. Deviation from the procedure is always seen as
wrong. Procedures are seen as a top-down contract.</p>
<p>The enabling logic facilitates response to real-world
contingencies. Workers perform their own analysis of the process. They
have the opportunity to challenge it and suggest improvements.</p>
<h4 id="internal-transparency">Internal transparency</h4>
<p>Deskilling equipment has no incentive for a transparent design. Users
are not supposed to see or understand the inner workings. By contrast,
when equipment is designed with a usability focus, users are expected
to face unforeseen situations and deal with them. Therefore, they need
access and understanding to the inner workings.</p>
<p>Enabling procedures similarly explain the rationale behind the rules,
and provide users with feedback on their performance.</p>
<h4 id="global-transparency">Global transparency</h4>
<p>Global transparency is the understanding of the overall organizational
structure or system. In the coercive logic, global transparency is
asymmetrical: only managers ought to see everything, and workers
should only see what they are meant to see. Global transparency is
seen as a risk and a liability.</p>
<p>In the enabling approach, employees have access to the broader
organizational structure. The goal is to help them interact creatively
with their environments, proactively identifying and solving
problems. This encourages suggestions from all actors, even if the
payoffs are very small.</p>
<h4 id="flexibility">Flexibility</h4>
<p>Coercive procedures are very rigid, and explicitly prohibits any
deviation. Only the supervisor can authorize a deviation.</p>
<p>Enabling procedures recognize that deviations are risks, but also that
they are learning opportunities to increase the worker’s skills and
the organization’s experience with abnormal situations.</p>
<h2 id="implementation-of-enabling-bureaucracy">Implementation of enabling bureaucracy</h2>
<p>Employee participation in the design of formal procedures can improve
morale and performance.</p>
<h3 id="typology-of-organizations">Typology of organizations</h3>
<p>Organization types can be decomposed along two dimensions: type and
degree of formalization. As it turns out, the degree of formalization
is relatively unimportant, ensuring that formalization is <em>enabling</em>
is what really matters.</p>
<table>
<caption>A Typology of organizations</caption>
<tbody>
<tr>
<td></td>
<td>Enabling formalization</td>
<td>Coercive formalization</td>
</tr>
<tr>
<td>Low formalization</td>
<td>Organic</td>
<td>Autocratic</td>
</tr>
<tr>
<td>High formalization</td>
<td>Enabling bureaucracy</td>
<td>Mechanistic</td>
</tr>
</tbody>
</table>
<p>This typology is particularly important for innovative,
knowledge-intensive organizations, where work often involve a mix of
routine and non-routine tasks. Difficulties might arise if one tries
to impose a mechanistic, highly formalized management structure for
the routine parts, while keeping the non-routine parts in a organic
management style enabling creativity.</p>
<p>In fact, there is no such dichotomy. Both types of tasks can be
managed in an enabling way. With enabling formal procedures, employees
can switch easily between routine and non-routine tasks, while keeping
their motivation and creativity at all stages.</p>
<h3 id="factors-influencing-the-emergence-of-a-coercive-or-an-enabling-bureaucracy">Factors influencing the emergence of a coercive or an enabling bureaucracy</h3>
<p>Factors encouraging the coercive logic:</p>
<ul>
<li><em>Asymmetries of power in the organization</em>: Managers can deflect
responsibility downwards more easily than subordinates can deflect
it upwards. Asymmetry can be counterbalanced with specific
institutions (e.g. unions) but only in a limited way.</li>
<li><em>Absence of reality checks</em> (e.g. competition, demanding customers):
With no such balances, internal conflicts take precedence over
common goals.</li>
</ul>
<p>Factors encouraging the enabling logic:</p>
<ul>
<li>The enabling logic has more <em>legitimacy</em> in the broader culture.</li>
<li>Procedures designed with subordinates tend to focus more on
<em>autonomy</em> and <em>consensus</em>, and thus be more enabling.</li>
<li>More intense <em>competitive pressure</em> leads to a need to find more
opportunities to improve performance. It this becomes necessary to
involve employees in the procedures. Coercive rules, by prohibiting
employees to think by themselves and innovate, thus pay a
significant opportunity cost.</li>
<li><em>Automation</em> also help enabling forms of bureaucracy. Operators get
more non-routine tasks, issues are generally less predictable and
more damaging (because most common issues are handled by the
automated system), and more learning is necessary.</li>
</ul>
<h2 class="unnumbered" id="references">References</h2>
<div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0" role="list">
<div id="ref-adler1996_two_types_bureauc" class="csl-entry" role="listitem">
Adler, Paul S., and Bryan Borys. 1996. <span>“Two Types of Bureaucracy: Enabling and Coercive.”</span> <em>Administrative Science Quarterly</em> 41 (1): 61–89. <a href="https://doi.org/10.2307/2393986">https://doi.org/10.2307/2393986</a>.
</div>
</div>
</section>
]]></content:encoded>
    <pubDate>Wed, 27 May 2026 00:00:00 UT</pubDate>
    <guid>https://lozeve.com/posts/types-of-bureaucracy-enabling-and-coercive.html</guid>
    <dc:creator>Dimitri Lozeve</dc:creator>
</item>
<item>
    <title>Johnson's Rule: scheduling items in two machines</title>
    <link>https://lozeve.com/posts/johnsons-rule.html</link>
    <content:encoded><![CDATA[<section>
  <p>You manage a restaurant that delivers food directly to customers. Each
customer comes with an order, that you need to cook and then
deliver. Depending on the order and the delivery address, each of
these two steps will take various durations. You need to complete all
orders and you want to finish your evenings as early as possible. If
all orders arrive at the same time, in what order should you complete
them to finish as early as possible?<span class="sidenote-wrapper"><label for="sn-0" class="margin-toggle">⊕</label><input type="checkbox" id="sn-0" class="margin-toggle" /><span class="marginnote">For the sake of the
example, we ignore all kinds of real-world complexities: yes the food
might become cold, no the driver cannot take several items with him,
and people apparently all order at the same time and don’t really care
when their food arrives.<br />
<br />
</span></span></p>
<p>This is a simple scheduling problem where each item needs to go
through two machines A and B in order. Each item will spend a
different amount of time in A and in B, and each machine can only
process a single item at a time.</p>
<p>Good news for your restaurant: there is a simple method to find the
optimal schedule!</p>
<h2 id="johnsons-rule">Johnson’s Rule</h2>
<p>The procedure is very simple:</p>
<ol type="1">
<li><p>Build a table of all items with the durations in machine A and in
machine B:</p>
<table>
<thead>
<tr>
<th>Item</th>
<th>Machine A</th>
<th>Machine B</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td><math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>A</mi><mn>1</mn></msub><annotation encoding="application/x-tex">A_1</annotation></semantics></math></td>
<td><math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>B</mi><mn>1</mn></msub><annotation encoding="application/x-tex">B_1</annotation></semantics></math></td>
</tr>
<tr>
<td>2</td>
<td><math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>A</mi><mn>2</mn></msub><annotation encoding="application/x-tex">A_2</annotation></semantics></math></td>
<td><math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>B</mi><mn>2</mn></msub><annotation encoding="application/x-tex">B_2</annotation></semantics></math></td>
</tr>
<tr>
<td>⋮</td>
<td>⋮</td>
<td>⋮</td>
</tr>
<tr>
<td><math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>n</mi><annotation encoding="application/x-tex">n</annotation></semantics></math></td>
<td><math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>A</mi><mi>n</mi></msub><annotation encoding="application/x-tex">A_n</annotation></semantics></math></td>
<td><math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>B</mi><mi>n</mi></msub><annotation encoding="application/x-tex">B_n</annotation></semantics></math></td>
</tr>
</tbody>
</table></li>
<li><p>Find the item with the shortest duration, either in A or in B.</p></li>
<li><p>If the shortest duration is for the first machine (A), place the
corresponding item <em>first</em>.</p></li>
<li><p>If the shortest duration is for the second machine (B), place the
corresponding item <em>last</em>.</p></li>
<li><p>Remove this item from the list.</p></li>
<li><p>Repeat, building the final item order from the ends toward the
middle.</p></li>
</ol>
<p>Here is an example of the algorithm applied to items with random
durations. We can see that the shortest A durations are near the
beginning, and the shortest B durations near the end.</p>
<figure class="fullwidth">
<img src="https://lozeve.com/images/johnsons_rule/gantt.svg" alt="Gantt chart of items scheduled on machine A and machine B by Johnson's rule">
<figcaption>Gantt chart of a project with random item durations.</figcaption>
</figure>

<p>This surprisingly simple algorithm was first described by
<a href="https://en.wikipedia.org/wiki/Selmer_M._Johnson">Selmer M. Johnson</a> at the RAND Corporation, who worked on all sorts of
<a href="https://lozeve.com/posts/planning-and-scheduling.html">scheduling methods</a>.</p>
<p>The full paper <span class="citation" data-cites="johnson1954_optim">(Johnson 1954)</span> can be found <a href="https://www.rand.org/content/dam/rand/pubs/papers/2008/P402.pdf">here on RAND’s website</a>.<span class="sidenote-wrapper"><label for="sn-1" class="margin-toggle">⊕</label><input type="checkbox" id="sn-1" class="margin-toggle" /><span class="marginnote">I just love these 10-page papers written on a simple
typewriter!<br />
<br />
</span></span></p>
<h2 id="the-intuition-behind-the-algorithm">The intuition behind the algorithm</h2>
<p>Why does it work? Let’s go back to our restaurant example. Our
“machine” A is the kitchen, and it will never be idle. For each item,
cooking is the first step, so whatever order we choose, as soon as an
order is cooked we can start the next one without any delay.</p>
<p>This is not the case for delivery, our “machine” B. After completing a
delivery, we might have to wait for the next item to be cooked and
ready, so the delivery driver might sit idle for some time. Depending
on the order we choose for the items, the delivery driver might waste
a lot of time waiting around for the kitchen to finish.<span class="sidenote-wrapper"><label for="sn-2" class="margin-toggle">⊕</label><input type="checkbox" id="sn-2" class="margin-toggle" /><span class="marginnote">This
is probably why big delivery firms pay their drivers by the delivery
and not for their time…<br />
<br />
</span></span></p>
<p>To finish as early as possible, we need to minimize the idle time of
machine B. To avoid wasting time, we want to keep it as busy as
possible, as early as possible. This is why the algorithm schedules
first the items with short durations on machine A, so that machine B
can start quickly. The next item will then likely be completed on
machine A before the step on machine B finishes, reducing idle
time. Similarly, items with short durations on machine B are scheduled
toward the end, because it makes little sense to complete them early
only to have machine B sit idle while the prerequisites on machine A
finish.</p>
<h2 id="proof-of-optimality">Proof of optimality</h2>
<p>I won’t reproduce the full proof here, you can find it explained very
clearly <a href="https://www.rand.org/content/dam/rand/pubs/papers/2008/P402.pdf">in the original paper</a>. It is very short and you will benefit
from the glorious mathematical typesetting of the 1950s:</p>
<p><img src="https://lozeve.com/images/johnsons_rule/inactive_periods.png" alt="Typewritten formula for the sum of inactive periods of machine B" /></p>
<p>The proof starts by computing the exact formula for the sum of
inactive periods of machine B (the sum of the <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>X</mi><mi>i</mi></msub><annotation encoding="application/x-tex">X_i</annotation></semantics></math> above). Different
item orders will lead to different values for this sum, and we can
show that an order is optimal if it follows the following rule:</p>
<blockquote>
<p>Item <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>j</mi><annotation encoding="application/x-tex">j</annotation></semantics></math> precedes item <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>j</mi><mo>+</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">j+1</annotation></semantics></math> if <span class="sidenote-wrapper"><label for="sn-3" class="margin-toggle">⊕</label><input type="checkbox" id="sn-3" class="margin-toggle" /><span class="marginnote">In the original: <img src="https://lozeve.com/images/johnsons_rule/rule.png" alt="Typewritten inequality min(A_j, B_j+1) less than min(A_j+1, B_j)"><br />
<br />
</span></span>
<math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mrow><mi mathvariant="normal">min</mi><mo>⁡</mo></mrow><mrow><mo stretchy="true" form="prefix">(</mo><msub><mi>A</mi><mi>j</mi></msub><mo>,</mo><msub><mi>B</mi><mrow><mi>j</mi><mo>+</mo><mn>1</mn></mrow></msub><mo stretchy="true" form="postfix">)</mo></mrow><mo>&lt;</mo><mrow><mi mathvariant="normal">min</mi><mo>⁡</mo></mrow><mrow><mo stretchy="true" form="prefix">(</mo><msub><mi>A</mi><mrow><mi>j</mi><mo>+</mo><mn>1</mn></mrow></msub><mo>,</mo><msub><mi>B</mi><mi>j</mi></msub><mo stretchy="true" form="postfix">)</mo></mrow><mi>.</mi></mrow><annotation encoding="application/x-tex">
    \min\left(A_j, B_{j+1}\right) &lt; \min\left(A_{j+1}, B_j\right).
</annotation></semantics></math></p>
</blockquote>
<p>It can be easily proved that this rule is transitive, therefore
establishing a total order on the possible schedules, and implying the
existence of a minimal schedule (unique up to items with identical
durations).</p>
<h2 id="a-small-implementation">A small implementation</h2>
<p>Here is a minimal implementation of the algorithm as described above:</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> johnsons_rule(items: <span class="bu">list</span>[<span class="bu">tuple</span>[<span class="bu">int</span>, <span class="bu">int</span>]]) <span class="op">-&gt;</span> <span class="bu">list</span>[<span class="bu">int</span>]:</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a>    <span class="co"># Sort items by the duration for either machine</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a>    sorted_indices <span class="op">=</span> <span class="bu">sorted</span>(</span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a>        <span class="bu">range</span>(<span class="bu">len</span>(items)), key<span class="op">=</span><span class="kw">lambda</span> i: <span class="bu">min</span>(items[i])</span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a>    )</span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a>    front: <span class="bu">list</span>[<span class="bu">int</span>] <span class="op">=</span> []  <span class="co"># Items placed at the front</span></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a>    back: <span class="bu">list</span>[<span class="bu">int</span>] <span class="op">=</span> []  <span class="co"># Items placed at the back</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a>    <span class="cf">for</span> i <span class="kw">in</span> sorted_indices:</span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a>        tA, tB <span class="op">=</span> items[i]</span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a>        <span class="cf">if</span> tA <span class="op">&lt;=</span> tB:</span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a>            front.append(i)</span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a>        <span class="cf">else</span>:</span>
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true" tabindex="-1"></a>            back.append(i)</span>
<span id="cb1-14"><a href="#cb1-14" aria-hidden="true" tabindex="-1"></a>    back.reverse()</span>
<span id="cb1-15"><a href="#cb1-15" aria-hidden="true" tabindex="-1"></a>    <span class="cf">return</span> front <span class="op">+</span> back</span></code></pre></div>
<p>However in Python we can also sort the list of items using a
comparison function. Using the comparison function from the proof
above directly, we get:</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> functools</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> johnsons_rule_direct(items: <span class="bu">list</span>[<span class="bu">tuple</span>[<span class="bu">int</span>, <span class="bu">int</span>]]) <span class="op">-&gt;</span> <span class="bu">list</span>[<span class="bu">int</span>]:</span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a>    <span class="cf">return</span> <span class="bu">sorted</span>(</span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a>        <span class="bu">range</span>(<span class="bu">len</span>(items)),</span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a>        key<span class="op">=</span>functools.cmp_to_key(</span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a>            <span class="kw">lambda</span> i, j: (</span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a>                <span class="bu">min</span>(items[i][<span class="dv">0</span>], items[j][<span class="dv">1</span>])</span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a>                <span class="op">-</span> <span class="bu">min</span>(items[j][<span class="dv">0</span>], items[i][<span class="dv">1</span>])</span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a>            )</span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a>        ),</span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a>    )</span></code></pre></div>
<p>We can now compute the schedule:</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> dataclasses <span class="im">import</span> dataclass</span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> collections.abc <span class="im">import</span> Generator</span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a><span class="at">@dataclass</span></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a><span class="kw">class</span> ItemSchedule:</span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a>    item_id: <span class="bu">int</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a>    machineA: <span class="bu">tuple</span>[<span class="bu">int</span>, <span class="bu">int</span>]</span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a>    machineB: <span class="bu">tuple</span>[<span class="bu">int</span>, <span class="bu">int</span>]</span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> compute_schedule(</span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true" tabindex="-1"></a>    items: <span class="bu">list</span>[<span class="bu">tuple</span>[<span class="bu">int</span>, <span class="bu">int</span>]], order: <span class="bu">list</span>[<span class="bu">int</span>]</span>
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true" tabindex="-1"></a>) <span class="op">-&gt;</span> Generator[ItemSchedule]:</span>
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true" tabindex="-1"></a>    endA <span class="op">=</span> <span class="dv">0</span></span>
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true" tabindex="-1"></a>    endB <span class="op">=</span> <span class="dv">0</span></span>
<span id="cb3-16"><a href="#cb3-16" aria-hidden="true" tabindex="-1"></a>    <span class="cf">for</span> i <span class="kw">in</span> order:</span>
<span id="cb3-17"><a href="#cb3-17" aria-hidden="true" tabindex="-1"></a>        tA, tB <span class="op">=</span> items[i]</span>
<span id="cb3-18"><a href="#cb3-18" aria-hidden="true" tabindex="-1"></a>        startA <span class="op">=</span> endA</span>
<span id="cb3-19"><a href="#cb3-19" aria-hidden="true" tabindex="-1"></a>        endA <span class="op">=</span> startA <span class="op">+</span> tA</span>
<span id="cb3-20"><a href="#cb3-20" aria-hidden="true" tabindex="-1"></a>        startB <span class="op">=</span> <span class="bu">max</span>(endA, endB)</span>
<span id="cb3-21"><a href="#cb3-21" aria-hidden="true" tabindex="-1"></a>        endB <span class="op">=</span> startB <span class="op">+</span> tB</span>
<span id="cb3-22"><a href="#cb3-22" aria-hidden="true" tabindex="-1"></a>        <span class="cf">yield</span> ItemSchedule(</span>
<span id="cb3-23"><a href="#cb3-23" aria-hidden="true" tabindex="-1"></a>            item_id<span class="op">=</span>i,</span>
<span id="cb3-24"><a href="#cb3-24" aria-hidden="true" tabindex="-1"></a>            machineA<span class="op">=</span>(startA, endA),</span>
<span id="cb3-25"><a href="#cb3-25" aria-hidden="true" tabindex="-1"></a>            machineB<span class="op">=</span>(startB, endB),</span>
<span id="cb3-26"><a href="#cb3-26" aria-hidden="true" tabindex="-1"></a>        )</span></code></pre></div>
<p><img src="https://lozeve.com/images/johnsons_rule/example.png" alt="Worked example from Johnson's paper with a 5-item duration table and optimal sequence" /></p>
<p>On the example from the paper, we get:</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode txt"><code class="sourceCode default"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>Optimal order: [4, 0, 3, 2, 1]</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a>Sorted items: [(2, 3), (4, 5), (6, 30), (30, 4), (4, 1)]</span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a>Schedule:</span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a>  Item 4: machine A (0, 2), machine B (2, 5)</span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a>  Item 0: machine A (2, 6), machine B (6, 11)</span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a>  Item 3: machine A (6, 12), machine B (12, 42)</span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a>  Item 2: machine A (12, 42), machine B (42, 46)</span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a>  Item 1: machine A (42, 46), machine B (46, 47)</span></code></pre></div>
<p>As a bonus, the implementation in <a href="https://mlochbaum.github.io/BQN/">BQN</a>:</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode txt"><code class="sourceCode default"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a>items←⟨4‿5,4‿1,30‿4,6‿30,2‿3⟩</span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a># Naive version</span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a>JohnsonsRuleNaive←{((0⊸⊑𝕨)⌊1⊸⊑𝕩)&lt;(0⊸⊑𝕩)⌊1⊸⊑𝕨}</span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a># Array-oriented version</span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a>JohnsonsRule←{&lt;´⌊´˘⍉𝕨≍⌽𝕩}</span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a># Sort the items according to the rule</span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a>(⍒JohnsonsRule⌜˜)⊸⊏items</span></code></pre></div>
<p>Which returns</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode txt"><code class="sourceCode default"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>⟨ ⟨ 2 3 ⟩ ⟨ 4 5 ⟩ ⟨ 6 30 ⟩ ⟨ 30 4 ⟩ ⟨ 4 1 ⟩ ⟩</span></code></pre></div>
<p>as expected.</p>
<h2 class="unnumbered" id="references">References</h2>
<div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0" role="list">
<div id="ref-johnson1954_optim" class="csl-entry" role="listitem">
Johnson, S. M. 1954. <span>“Optimal Two- and Three-Stage Production Schedules with Setup Times Included.”</span> <em>Naval Research Logistics Quarterly</em> 1 (1): 61–68. <a href="https://doi.org/10.1002/nav.3800010110">https://doi.org/10.1002/nav.3800010110</a>.
</div>
</div>
</section>
]]></content:encoded>
    <pubDate>Tue, 19 May 2026 00:00:00 UT</pubDate>
    <guid>https://lozeve.com/posts/johnsons-rule.html</guid>
    <dc:creator>Dimitri Lozeve</dc:creator>
</item>
<item>
    <title>Overengineering Dice Rolling</title>
    <link>https://lozeve.com/posts/diceroll.html</link>
    <content:encoded><![CDATA[<section>
  <p>We have a weekly D&amp;D game with a few of my colleagues. We play at
lunchtime. A few weeks ago, something terrible happened: our DM forgot
his dice.</p>
<p><img src="https://lozeve.com/images/diceroll/slack_screenshot_1.png" alt="Slack message where the DM says they forgot all their D&D gear, 0 dice and 0 screen">
<span class="sidenote-wrapper"><label for="sn-0" class="margin-toggle">⊕</label><input type="checkbox" id="sn-0" class="margin-toggle" /><span class="marginnote">Translation from the French: “I didn’t realize, but I didn’t
bring any of my D&amp;D stuff at all. I have 0 dice, 0 screen”<br />
<br />
</span></span></p>
<p>There are already thousands of websites and mobile apps for rolling
dice in role-playing games, but that would be boring. What if I made
one myself? <span class="sidenote-wrapper"><label for="sn-1" class="margin-toggle">⊕</label><input type="checkbox" id="sn-1" class="margin-toggle" /><span class="marginnote">Another tragic event happened in game: my character
died during combat. And this particular warlock believes in a higher
power, and the coming of the Great Old One in an apocalypse that will
consume the world. The warlock’s interpretation of his death is that
fate is rigged, and the dice are probably wrong.<br />
<br />
</span></span></p>
<p>The initial idea was very simple. Character sheets and player
handbooks use “dice expressions” like <code class="verbatim">6d4 + 4</code>. This means “roll six
four-sided dice, add the values, and add 4”. This gives you the damage
you deal to a monster while hitting it with your amazing sword or
badass magical spell. So we could simply type a dice expression, and
the tool would simulate the dice rolls, compute the sum, and give you
the result. Quick and easy.</p>
<p>Dear reader: it ended up doing way more than that. Way too much.</p>
<h2 id="the-first-version">The first version</h2>
<p>Famously, all problems can be solved with regular expressions. So my
first version was basically this regex:
<code>(?&lt;sign&gt;[+-]?)(?:(?&lt;count&gt;\d*)[dD](?&lt;sides&gt;\d+)|(?&lt;num&gt;\d+))</code>, along
with some code that went through each capture group and called
<code>random_range(1..6)</code> if it encountered <code class="verbatim">d6</code>.</p>
<p>Then it’s just a matter of reading the command-line arguments, parsing
them with the regex, and printing the result. I did it in Rust because
I was already familiar with it, and I could quickly whip up a small
command-line utility like this. And it gave me a single binary that I
could share with the team.</p>
<p><img src="https://lozeve.com/images/diceroll/slack_screenshot_2.png" alt="Slack message sharing the diceroll binary with usage examples and reactions" /></p>
<p>Great.</p>
<p>But not enough.</p>
<h2 id="the-rabbit-hole">The rabbit hole</h2>
<p>Even a cursory glance at the player’s handbook will let you know that
dice expressions can become <em>much</em> more complex than that. And my tool
would not be a <em>serious</em> tool if it didn’t support everything, right?
So I rewrote the parser to use a proper parser combinator library
(<a href="https://crates.io/crates/nom">nom</a>) instead of a regex, and I happily started to implement necessary
and not-so-necessary features:</p>
<ul>
<li>adding and subtracting dice expressions: <code class="verbatim">4d10 - 2d3 + 4</code>,</li>
<li>parenthesized groups and multipliers: <code class="verbatim">d20 + (2d6+3)*2 + 5</code>,</li>
<li>keep/drop highest/lowest rolls: <code class="verbatim">2d20kh1</code> rolls a <code class="verbatim">d20</code> with
advantage, <code class="verbatim">4d6dl2</code> drops the two lowest values,</li>
<li>re-rolls: <code class="verbatim">6d10r</code> re-rolls 1s until the die stops showing 1,</li>
<li>exploding dice, minimum and maximum results, count matching, and so
on. All of these modifiers can obviously be combined!</li>
</ul>
<p>But what about the user experience? Surely our dear users<span class="sidenote-wrapper"><label for="sn-2" class="margin-toggle">⊕</label><input type="checkbox" id="sn-2" class="margin-toggle" /><span class="marginnote">At
this stage, “users” means “myself”.<br />
<br />
</span></span> will grow tired of the simple CLI
interface? So I added a REPL, and JSON output for programmatic use,
and a web server because why not? Someone might want to use it through
an HTTP API!</p>
<p>At that point it also stopped being just a dice rolling utility. I’m
quite happy with the <code class="verbatim">stats</code> command, which rolls the dice expression
many times and computes statistics, which is useful to see what you
can expect from a given combination. What is the standard deviation of
the damage dealt by your weapon? What chance do you have of hitting
that goblin with your spell?</p>
<h2 id="the-website">The website</h2>
<p>At this point I was actively looking for opportunities to overengineer
this even more. What useless feature could I possibly add?</p>
<p>Well, I had a nice command-line tool in Rust. Being a serious person
working on a serious project, I had a clean architecture, with a
library and binary that called it. So where could I use that library?
Rust can compile to WebAssembly, why not try that? I could call the
library from a small website and roll <em>blazing fast</em> dice in WASM
directly in the browser!</p>
<p>I found a cheap domain name, and shortly after, the result was
accessible on <a href="https://diceroll.run/">diceroll.run</a>.</p>
<p><img src="https://lozeve.com/images/diceroll/diceroll-run.png" alt="The diceroll.run website showing a REPL of dice expressions with results and dice buttons" /></p>
<p>With the website, I could experiment with a lot of stuff that I wanted
to explore:</p>
<ul>
<li>the WASM module itself of course, how to build it and use it from JS
in the browser,</li>
<li>generating a random seed at the start of the session for
reproducibility,</li>
<li>saving all the state (random seed and input history) in the URL
query parameters, for easily sharing a session with other people!</li>
</ul>
<h2 id="coding-agents-and-learning-opportunities">Coding agents and learning opportunities</h2>
<p>Among these vast amounts of overengineering and unnecessary features,
there was at least a nice outcome: I learned a lot.</p>
<p>As mentioned earlier, the initial version was basically a single
script generated with an AI agent. After that, as I became more
invested in the features, I continued iterating with AI. But this was
mostly for fun and a learning opportunity: I was under no pressure to
actually deliver any of those features! So I didn’t “vibe code”, I
used the agent to iterate on the code, reviewing it line-by-line as I
would have done if I had written it myself.</p>
<p>This allowed me to iterate rapidly on the features and on the code
structure. Rust was really helpful as well. I decided on the data
structures and the libraries, and from there the LLM could generate
very good code within the constraints of the data models and the
compiler’s checks.</p>
<p>The parser in particular is code that can quickly become a little bit
boring, even with a parser combinator library. Here the LLM could
generate a battery of unit tests, and I could very easily check that
it covered the most important cases, both expected successes and
expected failures. Without AI assistance I don’t think I ever would
have had the patience to write these tests for a side project! It’s in
this sense that I believe AI agents can lead us to write much better
code, especially for one-off, unimportant side projects like this.</p>
<p>The only part that was fully AI-generated with (almost) no supervision
is the website. The HTML, CSS, and the bit of JS wrapping the WASM
module was fully “vibe coded” in the sense that I didn’t read the code
in detail, I just looked at the output, tried it, and iterated from
there. Given that most of the logic is in the Rust library, I didn’t
want to spend too much time changing CSS by hand…</p>
<p>With or without AI, small projects like these are a great learning
opportunity. I could experiment with new (to me) libraries for parser
combinators, minimal HTTP servers, CLI argument parsing, etc. The AI
agent is also a great source of learning, studying the code of simple
examples!</p>
<h2 id="use-it-if-you-want">Use it (if you want)</h2>
<p>The code is <a href="https://github.com/dlozeve/diceroll">on GitHub</a> (you can download a pre-built binary in the
releases), and the website is on <a href="https://diceroll.run/">diceroll.run</a>! As you can imagine, I
would be <em>very</em> happy to hear about your ideas for new features and
improvements 😛</p>
</section>
]]></content:encoded>
    <pubDate>Wed, 13 May 2026 00:00:00 UT</pubDate>
    <guid>https://lozeve.com/posts/diceroll.html</guid>
    <dc:creator>Dimitri Lozeve</dc:creator>
</item>
<item>
    <title>Why I built Leibniz: in defense of Gantt charts and project scheduling</title>
    <link>https://lozeve.com/posts/leibniz-product-vision.html</link>
    <content:encoded><![CDATA[<section>
  <p>In the past few months, I have been working on a new project:
<a href="https://getleibniz.com">Leibniz</a>. I designed it to improve the way we plan projects. Like most
side projects, it started because of my own dissatisfaction with the
existing tools and processes during my work. Here, I want to explain
the story, the frustrations I encountered, and the vision I
have.<span class="sidenote-wrapper"><label for="sn-0" class="margin-toggle">⊕</label><input type="checkbox" id="sn-0" class="margin-toggle" /><span class="marginnote">This is the origin story and the product
vision. I hope to have more to say about the technical details and the
juicy algorithms later!<br />
<br />
</span></span></p>
<h2 id="project-management-the-old-school-way">Project management, the old-school way</h2>
<p>In my previous job, I was in charge of project management. The company
was very old-school in its approach, and although quite small, copied
most of its processes from large industrial companies like Thales and
Safran.</p>
<p>This meant that most projects were managed in the following
manner:</p>
<ul>
<li>a project manager designed the entire project from scratch, dividing
the project into many <em>tasks</em>,</li>
<li>she mapped the <em>dependencies</em> between each task,</li>
<li>she assigned a <em>resource</em> (usually a job title, like “backend
developer” or “research engineer”) to each task,</li>
<li>she set a <em>duration</em> for each task<span class="sidenote-wrapper"><label for="sn-1" class="margin-toggle sidenote-number"></label><input type="checkbox" id="sn-1" class="margin-toggle" /><span class="sidenote">This only covers the initial part of project
planning. But the main difficulty actually arises during project
execution: adapting activities, dependencies, and schedule to
external, unforeseen events.<br />
<br />
</span></span>.</li>
</ul>
<p>After that, the project manager set up a meeting with the company’s
top management to present the plan. It got challenged, often in very
minute details, including time estimates. The goal of the project
manager at this point was to obtain top management’s approval for
running the project, and above all to negotiate the deadline (she
wanted to set it as late as possible, because she would be held
accountable if she missed it), and the resources made available to her
(i.e. people).</p>
<p>And then the dance started: there was a big meeting with all the other
project managers (each with their own projects and requirements), and
they would all haggle over the “resources” (once again, actual people,
fellow colleagues working right next to them). This often degenerated
into apothecary-style counting: a typical sentence in these meetings
was “ok, you can have Bob on week 3 of April, but then I will need 0.5
Alice on week 4 to compensate”. Not only were these arrangements
nearly meaningless (how can a developer work for 2.5 days on a given
project then switch to another?), but the vocabulary encouraged
project managers to think of people as “resources”, machines that
could be subdivided, reallocated, and moved as easily as equipment can
be repurposed.</p>
<p>But that was not the worst part. The worst part was the tooling we had
to use.</p>
<p>I managed small projects, mainly software. Think a few months, at most
a year, and a small team of between 5 and 10 people. Something that
most startups handle very easily. We could have done it with an agile
team iterating rapidly, but to fit the process, I had to build a full
project plan, including the list of tasks with all the metadata, a
Gantt chart, and so on. It could have been done very easily. But the
company used <a href="https://en.wikipedia.org/wiki/Microsoft_Project">Microsoft Project</a>.</p>
<p>Microsoft Project has… a few issues. The software was basically
built in the 90s and never touched since. The developers had clearly
never spoken to an actual user in their entire lives. If it was made
for anyone, it was for project managers on extremely large projects
(perhaps for designing and building an entire airplane).<span class="sidenote-wrapper"><label for="sn-2" class="margin-toggle">⊕</label><input type="checkbox" id="sn-2" class="margin-toggle" /><span class="marginnote">I should note that this is a personal impression based
on very superficial use. We are talking about a very large piece of
software in which Microsoft has probably invested <em>decades</em> of work. I
am sure many people have mastered it and find it invaluable. But it
was not what I wanted for my simple use cases. And it certainly didn’t
spark joy.<br />
<br />
</span></span>
There were thousands of features I would never need, and the basic
ones were very hard to use.</p>
<ul>
<li>The entire interface is built like an Excel spreadsheet. Each
activity on its own line, with ID, name, duration, resources, and
dependencies. A project is inherently a graph, and project planning
(at least for me) is an inherently visual activity. Yet the only
place where you can actually edit the project is a very dense table.</li>
<li>Dependencies are represented in the most obscure way possible: each
activity has a “dependencies” column where you fill the IDs of the
activities on which it depends. Good luck figuring out what it means
when you see that your activities depend on 127, 134, and 34. It
basically feels like you are looking at the underlying database
schema, not at something built for actual users.</li>
<li>It is very hard to collaborate on projects. Even though the essence
of a project is to organize an entire team, you cannot share it
easily other people. If one person has it opened, you have to wait
until they close it before being able to open it yourself. And the
interface is so dense and unclear that only people who are used to
work with it know what to look for, so it’s useless to show to
individual developers for instance.</li>
<li>The scheduling algorithm feels limited: you have hundreds of options
to configure different dependency types, but it many cases the
program just gives up and settles for highlighting conflicts between
activities (generally resource conflicts). Then you have to fix them
manually, moving tasks and hardcoding their start date, defeating
the entire purpose of a scheduling software.</li>
</ul>
<h2 id="project-scheduling-is-a-good-abstraction">Project scheduling is a good abstraction</h2>
<p>None of this was great, both in terms of process and tooling. It’s
easy to conclude that we should throw out the whole thing and do
something else entirely (agile, scrum, whatever you want to call
it). But underneath the unpleasantness, I still thought that the
underlying <em>model</em> was interesting. The problem is not the Gantt
chart; the problem is sticking rigidly to it. The problem is not
decomposing the project into small tasks and assigning them to people;
it’s treating people as consumable, impersonal resources. The model
was still useful for helping me structure my thoughts on large and
ambitious projects, and to <em>communicate</em> the tradeoffs and decisions
to other people (both the members of my team and my managers).</p>
<p>And to be honest, the maths nerd in me was also quickly fascinated by
the underlying algorithms for project scheduling<span class="sidenote-wrapper"><label for="sn-3" class="margin-toggle sidenote-number"></label><input type="checkbox" id="sn-3" class="margin-toggle" /><span class="sidenote">The mathematical
model of a project, as used in most algorithms, is very clean and
elegant, with very few concepts. This convinced me that there exists a
good UX that will help people manipulate it easily.<br />
<br />
</span></span>.</p>
<p>So I went looking for a way to leverage that model while challenging
both the tooling and the process. As a small-scale manager, there
wasn’t much I could do about the process directly, but I could propose
better tooling and use that as a means to challenge the process
itself.</p>
<h2 id="looking-for-alternative-tooling">Looking for alternative tooling</h2>
<p>Given the 1990s look and feel of Microsoft Project, I naturally
assumed there would be something better that I could propose to my
boss. I had already managed to convince him to let me migrate my team
to Linear, while the rest of the company was still on Jira. Where was
the Linear to Microsoft Project’s Jira?</p>
<p>It turns out it didn’t really exist. Most competitors were either as
bad as Microsoft Project (with fewer features), or were focused on
some other area I didn’t need (mostly CRMs, ERPs, and things like
that), with project scheduling bolted on the side<span class="sidenote-wrapper"><label for="sn-4" class="margin-toggle sidenote-number"></label><input type="checkbox" id="sn-4" class="margin-toggle" /><span class="sidenote">Of course I
can’t pretend I looked at <a href="https://en.wikipedia.org/wiki/Comparison_of_project_management_software">each and every one of them</a>…<br />
<br />
</span></span>.</p>
<p>Looking into it, the reason everyone gave was that project scheduling
was a “hard problem” requiring dedicated research teams and
state-of-the-art algorithms. This piqued my curiosity, and without
much ambition, just out of curiosity, I looked into the literature on
project scheduling. I quickly learned that simple algorithms (like the
<a href="https://en.wikipedia.org/wiki/Critical_path_method">critical path method</a>) cover the most basic use cases very simply. But
the theory was much richer than I expected: there are hundreds of
variants of the scheduling problem, and there’s a very active research
community with close ties to the industry. (I wrote about it a bit in
a <a href="https://lozeve.com/posts/planning-and-scheduling.html">previous post</a>.) I eventually bought a book on project scheduling
with time windows and resource constraints, had a very basic
implementation running within a few days in my spare time.</p>
<h2 id="the-algorithm-is-not-the-product">The algorithm is not the product</h2>
<p>As is often the case, the algorithm is not the difficult part. The
difficult part is the product. What did I want from this software? As
my own first user, my needs were clear:</p>
<ul>
<li>An intuitive user experience. This is table stakes: nobody wants to
spend months mastering a project scheduling tool.</li>
<li>Easy visualization and manipulation of dependencies. Dependencies
are the key part of the model. Everything, from the resource
allocations to the final schedule, hinges on them.</li>
<li>A collaborative experience from the start. If you can’t share it
with anyone, the project plan loses 90% of its use.</li>
<li>A state-of-the-art scheduling algorithm, that never forces you to
adjust manually.</li>
<li>A fast, responsive experience. When I change something, I want the
changes to be reflected immediately in the schedule.</li>
</ul>
<p>Above all, I wanted it to be useful to everyone: not only to people
working with traditional project management processes, but also to
people who work in more agile, flexible environments. And from small
projects of a few tasks to enormous undertakings involving thousands.</p>
<h2 id="going-forward">Going forward</h2>
<p>Over the past months, I have built a tool that answers most of my
needs. I am my own first user (and apart from a few colleagues, the
only one). Despite no longer working at the same company, and
following vastly different processes, I still use it every day.</p>
<p>Project scheduling algorithms are so general that they can be applied
to many different contexts. In the next few posts I will probably talk
more about some design choices and some technical decisions I
made. For spoilers, the key features are <a href="https://getleibniz.com/">on the website</a>! And maybe I
will also explain the name…</p>
</section>
]]></content:encoded>
    <pubDate>Sun, 03 May 2026 00:00:00 UT</pubDate>
    <guid>https://lozeve.com/posts/leibniz-product-vision.html</guid>
    <dc:creator>Dimitri Lozeve</dc:creator>
</item>
<item>
    <title>A Mastodon bot for interesting integer sequences</title>
    <link>https://lozeve.com/posts/oeis-bot.html</link>
    <content:encoded><![CDATA[<section>
  <p>A few days ago I stumbled into the <a href="https://oeis.org/">OEIS</a> again via their <a href="https://oeis.org/OEIS_pics.html">pictures page</a>. Looking at some of the pages there gave me an idea for a new,
small project, so I gave it a shot.</p>
<h2 id="what-is-the-oeis">What is the OEIS?</h2>
<p>The Online Encyclopedia of Integer Sequences, or “OEIS” for short, is
a collaborative project whose objective is to collect all sequences of
integers into a comprehensive repository. It is useful to all
mathematicians (professional or amateur!) who stumble into a sequence
and wish to identify it: they can type a few terms into the search
bar, and the OEIS will return all sequences that match.</p>
<p>The OEIS was started by Neil J. A. Sloane, after publishing a few
books collecting many important sequences. Many people had interesting
sequences they wanted to contribute, and sent letters to Sloane with
suggestions. The collection began to be so large that Sloane started
an online version, which became the OEIS<span class="sidenote-wrapper"><label for="sn-0" class="margin-toggle sidenote-number"></label><input type="checkbox" id="sn-0" class="margin-toggle" /><span class="sidenote">The full history can be
found <a href="https://oeisf.org/#HISTORY">here</a>.<br />
<br />
</span></span>.</p>
<p>Each sequence in the database has a unique identifier like <a href="https://oeis.org/A000108">A000108</a>. An
entry includes a description, the known terms of the sequence, and a
lot of additional data: explicit formulas when they exist, comments
and bibliographical references, programs to compute the sequence, and
other related sequences in the database. The <a href="https://oeis.org/demo1.html">demo</a> is a good place to
start for how to use the database.</p>
<p>Like most people, I have no real need of the OEIS on a day-to-day
basis. However I still find it fascinating. Many sequences are
well-known: the prime numbers (<a href="https://oeis.org/A000040">A000040</a>), the Fibonacci numbers
(<a href="https://oeis.org/A000045">A000045</a>), etc. Others I have encountered elsewhere in popular
mathematics, like the Busy Beaver problem (<a href="https://oeis.org/A060843">A060843</a>), whose 5th term
has been <a href="https://www.quantamagazine.org/amateur-mathematicians-find-fifth-busy-beaver-turing-machine-20240702/">computed recently</a>. And others I have discovered directly on
the OEIS, like the “peaceable coexisting armies of queens” (<a href="https://oeis.org/A250000">A250000</a>,
look at the ASCII chess boards in the examples!).</p>
<p>What I like about these sequences is that they are often at the
intersection of many domains in mathematics. Some of these sequences
have very deep connections to many areas, and let you discover new
interesting concepts and ideas. Moreover the relationships between
sequences is often interesting as well, and let you continue the
exploration.</p>
<h2 id="the-idea">The idea</h2>
<p>The only problem is that the OEIS is more a search engine, and
therefore most sequences are not very discoverable. Contributors and
editors add keywords to the sequences, some are <a href="https://oeis.org/search?q=keyword%3Anice&amp;language=english&amp;go=Search">nice</a>, some have a nice
<a href="https://oeis.org/search?q=keyword%3Alook&amp;language=english&amp;go=Search">graph</a> (click on “graph” under the sequence itself!), and the wiki
lists some <a href="https://oeis.org/wiki/Index_to_OEIS:_Section_Cor#core">important sequences</a>. But other than this it is not easy to
discover interesting sequences randomly.</p>
<p>So I got the idea of implementing a bot that would share a random
sequence regularly, so I could read the full OEIS page if the
description seemed interesting. Since I am mostly on <a href="https://mathstodon.xyz/@dlzv">Mastodon</a>, I
wanted to implement this as a Mastodon bot so that others could follow
it if they want.</p>
<h2 id="the-implementation">The implementation</h2>
<p>The general idea is as follows:</p>
<ol type="1">
<li>Pick a random sequence ID out of the nearly 400,000 sequences
currently in the database.</li>
<li>Retrieve the metadata for this sequence (its name, the first few
terms, keywords and comments).</li>
<li>Format this as a Mastodon post and post it.</li>
</ol>
<p>It is a very simple process (basically a GET request to the OEIS
followed by a POST request to a Mastodon instance). Mastodon servers
have a public API that is very easy to use and very well documented: I
only needed the <a href="https://docs.joinmastodon.org/methods/statuses/#create">statuses</a> endpoint. It requires a token that can be
generated easily from the account settings, by creating an application
with the <code class="verbatim">write:statuses</code> scope.</p>
<p>The OEIS API has a <a href="https://oeis.org/wiki/JSON_Format">JSON output format</a>. I wanted to parse this
correctly. Looking at the <a href="https://oeis.org/eishelp2.html">documentation</a> of the format, I realized that
many sequences should be excluded because they are duplicates,
unimportant, or too obscure<span class="sidenote-wrapper"><label for="sn-1" class="margin-toggle sidenote-number"></label><input type="checkbox" id="sn-1" class="margin-toggle" /><span class="sidenote">Specifically, I excluded sequences
tagged with <code class="verbatim">dead</code>, <code class="verbatim">dumb</code>, <code class="verbatim">dupe</code>, <code class="verbatim">less</code>, <code class="verbatim">obsc</code>, <code class="verbatim">probation</code>, or
<code class="verbatim">uned</code>.<br />
<br />
</span></span>. So I added a step in the process above to make sure that the
sequence picked at random was sufficiently interesting. Given the
number of available sequences, there should be more than enough
interesting ones!</p>
<p>I implemented it in Rust<span class="sidenote-wrapper"><label for="sn-2" class="margin-toggle sidenote-number"></label><input type="checkbox" id="sn-2" class="margin-toggle" /><span class="sidenote">Mostly because I am comfortable with it,
it has a very good ecosystem, and it can be deployed as a single
binary.<br />
<br />
</span></span>. Claude Code was fairly helpful to build all this, especially
for the serde types to deserialize the OEIS internal format. All in
all, I had a fully functional program in under an hour, for something
that would have taken me at least a few hours if I had done everything
“manually” (and which would not have been particularly interesting or
fun to do). I am reasonably happy with the overall quality of the
code, that you can find <a href="https://github.com/dlozeve/oeis_bot">on GitHub</a>.</p>
<p>The final program is deployed on my VPS, I just copied the executable
and set up a <a href="https://github.com/dlozeve/oeis_bot/blob/main/oeis-bot.timer">systemd timer</a> to call it every 4 hours. The token for
Mastodon is given as an environment variable in the <a href="https://github.com/dlozeve/oeis_bot/blob/main/oeis-bot.service">service file</a>.</p>
<h2 id="the-result">The result</h2>
<p>I created an account on <a href="https://mathstodon.xyz/">Mathstodon</a>, the instance I use for my <a href="https://mathstodon.xyz/@dlzv">personal account</a>. As this is my first bot, I wasn’t sure about the process, but
the administrators of the instance were happy to allow the bot as long
as it is clearly identified as such and does not spam too much. I also
made it clear that the bot is not operated officially by the
OEIS. Should they decide to join Mastodon, I would be happy to cede
them the account if they wish.</p>
<p>If you want to follow it, the account is <a href="https://mathstodon.xyz/@OEISbot">@OEISbot</a>!</p>
<blockquote lang="en" cite="https://mathstodon.xyz/@OEISbot/116069813960351345" data-source="fediverse">
  <p>OEIS sequence A177263<br />Triangle read by rows: T(n,k) is the number of permutations of {1,2,...,n} having k as the last entry in the first block (1&lt;=k&lt;=n).</p><p>1, 0, 2, 1, 1, 4, 4, 5, 5, 10, 18, 22, 23, 23, 34, 96, 114, 118, 119, 119, 154, 600, 696, 714, 718, 719, 719, 874, 4320, 4920, 5016, 5034, 5038, 5039, 5039, 5914, 35280, 39600, 40200, 40296, 40314, 40318, 40319, 40319, 46234, 322560, 357840, 362160, 362760, 362856, 362874, 362878, 362879, 362879, 409114</p><p><a href="https://oeis.org/A177263" target="_blank" rel="nofollow noopener" translate="no"><span class="invisible">https://</span><span class>oeis.org/A177263</span><span class="invisible"></span></a></p>
  <footer>
     — OEIS bot (@OEISbot) <a href="https://mathstodon.xyz/@OEISbot/116069813960351345"><time datetime="2026-02-14T16:00:07.743Z">2/14/2026, 5:00:07 PM</time></a>
  </footer>
</blockquote>

<blockquote lang="en" cite="https://mathstodon.xyz/@OEISbot/116067926081324392" data-source="fediverse">
  <p>OEIS sequence A071904<br />Odd composite numbers.</p><p>9, 15, 21, 25, 27, 33, 35, 39, 45, 49, 51, 55, 57, 63, 65, 69, 75, 77, 81, 85, 87, 91, 93, 95, 99, 105, 111, 115, 117, 119, 121, 123, 125, 129, 133, 135, 141, 143, 145, 147, 153, 155, 159, 161, 165, 169, 171, 175, 177, 183, 185, 187, 189, 195, 201, 203, 205</p><p><a href="https://oeis.org/A71904" target="_blank" rel="nofollow noopener" translate="no"><span class="invisible">https://</span><span class>oeis.org/A71904</span><span class="invisible"></span></a></p>
  <footer>
     — OEIS bot (@OEISbot) <a href="https://mathstodon.xyz/@OEISbot/116067926081324392"><time datetime="2026-02-14T08:00:00.996Z">2/14/2026, 9:00:00 AM</time></a>
  </footer>
</blockquote>

<p>For now only a few sequences have been posted, but I’m excited to see
what interesting sequences come up!</p>
</section>
]]></content:encoded>
    <pubDate>Sat, 14 Feb 2026 00:00:00 UT</pubDate>
    <guid>https://lozeve.com/posts/oeis-bot.html</guid>
    <dc:creator>Dimitri Lozeve</dc:creator>
</item>
<item>
    <title>The Bulgarian Solitaire</title>
    <link>https://lozeve.com/posts/bulgarian-solitaire.html</link>
    <content:encoded><![CDATA[<section>
  <p>Imagine you are the director of a unit in a large company. You have 5
teams, with various numbers of people in each team. An important new
project has come up, and you would like to set up a new team to tackle
it. The problem is: you don’t have any budget to hire new people!</p>
<p>What can you do? Well, you could take one person from each existing
team, and build a new team with these 5 people.</p>
<p>It works well for a while, but of course soon enough, a new project
comes up, and you still don’t have any additional budget! It worked
the first time, so you reshuffle the teams once more in the same
way. One of the existing team had only one person left, so they go to
the newly created team and their existing team just disappears.</p>
<p>Now the CEO is getting concerned with your unconventional management
practices. She summons you to her office and asks you: What would
happen if you do this repeatedly for every new project? How many teams
will you end up with, with how many people in each one of them?</p>
<h2 id="the-bulgarian-solitaire">The Bulgarian Solitaire</h2>
<p>Instead of this (admittedly far-fetched) management scenario, you can
do the same process with playing cards. You have <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>n</mi><annotation encoding="application/x-tex">n</annotation></semantics></math> cards divided
arbitrarily into several piles. At each step, you remove one card from
each pile and collect them in a new pile next to the existing ones. If
you repeat this operation, how many piles of cards will you get? With
how many cards in each of them? This problem is called the <em>Bulgarian
Solitaire</em>. It is described in <a href="https://arxiv.org/abs/1503.00885">this paper</a><span class="sidenote-wrapper"><label for="sn-0" class="margin-toggle sidenote-number"></label><input type="checkbox" id="sn-0" class="margin-toggle" /><span class="sidenote">Which also describes the
history of the problem, including why it is called “Bulgarian”.<br />
<br />
</span></span>.</p>
<p>With <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>n</mi><annotation encoding="application/x-tex">n</annotation></semantics></math> cards, the Bulgarian Solitaire is an example of a discrete
dynamical system on partitions of <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>n</mi><annotation encoding="application/x-tex">n</annotation></semantics></math>. A <em>partition</em> is an unordered
sequence of numbers that sum to <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>n</mi><annotation encoding="application/x-tex">n</annotation></semantics></math>. For instance, <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false" form="prefix">(</mo><mn>4</mn><mo>,</mo><mn>3</mn><mo>,</mo><mn>2</mn><mo>,</mo><mn>1</mn><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">(4,3,2,1)</annotation></semantics></math> and
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false" form="prefix">(</mo><mn>8</mn><mo>,</mo><mn>3</mn><mo>,</mo><mn>2</mn><mo>,</mo><mn>2</mn><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">(8,3,2,2)</annotation></semantics></math> are partitions of 15. At each step, the Bulgarian
Solitaire will transform a partition like <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false" form="prefix">(</mo><mn>8</mn><mo>,</mo><mn>3</mn><mo>,</mo><mn>2</mn><mo>,</mo><mn>2</mn><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">(8,3,2,2)</annotation></semantics></math> into a new one,
in this case <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false" form="prefix">(</mo><mn>7</mn><mo>,</mo><mn>2</mn><mo>,</mo><mn>1</mn><mo>,</mo><mn>1</mn><mo>,</mo><mn>4</mn><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">(7,2,1,1,4)</annotation></semantics></math> (the new pile is at the end, but we don’t
care about the order so we can also write it as <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false" form="prefix">(</mo><mn>7</mn><mo>,</mo><mn>4</mn><mo>,</mo><mn>2</mn><mo>,</mo><mn>1</mn><mo>,</mo><mn>1</mn><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">(7,4,2,1,1)</annotation></semantics></math>).</p>
<p>What we are trying to understand is in fact a standard question in
dynamical systems: where is the system going? Are there stable states,
cycles? What are they?</p>
<h2 id="visualizing-the-bulgarian-solitaire-process">Visualizing the Bulgarian Solitaire process</h2>
<p>As a first example, let’s take <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi><mo>=</mo><mn>10</mn></mrow><annotation encoding="application/x-tex">n=10</annotation></semantics></math> cards, in piles of 4, 3, and 3
cards. We take one card from the top of each pile (in orange), and we
make a new pile of size 3:</p>
<p><img src="https://lozeve.com/images/bulgarian-solitaire/cards.svg" alt="Ten cards in piles of 4, 3, and 3, with the top card of each pile in orange forming a new pile" width="300" /></p>
<p>Visualizing cards like this is not very practical, but as it turns
out, mathematicians have already devised a nice way to visualize
partitions: <a href="https://en.wikipedia.org/wiki/Young_tableau#Diagrams">Young diagrams</a>. They represent a partition as rows of
boxes. For example, the partition <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false" form="prefix">(</mo><mn>6</mn><mo>,</mo><mn>5</mn><mo>,</mo><mn>3</mn><mo>,</mo><mn>1</mn><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">(6,5,3,1)</annotation></semantics></math> of the number 15 can be
visualized as:</p>
<p><picture><source srcset="https://lozeve.com/images/bulgarian-solitaire/young-dark.png" media="(prefers-color-scheme: dark)"><img src="https://lozeve.com/images/bulgarian-solitaire/young.png" alt="Young diagram of the partition 6, 5, 3, 1 as left-aligned rows of boxes"></picture></p>
<p>In our cases, we can rotate the Young diagram by 90° so that it looks
more like piles of cards:</p>
<p><picture><source srcset="https://lozeve.com/images/bulgarian-solitaire/young_rotated-dark.png" media="(prefers-color-scheme: dark)"><img src="https://lozeve.com/images/bulgarian-solitaire/young_rotated.png" alt="Young diagram rotated 90 degrees so rows of boxes stand as vertical piles of cards"></picture></p>
<p>A step in the Bulgarian Solitaire will look like this:</p>
<p><picture><source srcset="https://lozeve.com/images/bulgarian-solitaire/step-dark.png" media="(prefers-color-scheme: dark)"><img src="https://lozeve.com/images/bulgarian-solitaire/step.png" alt="One Bulgarian Solitaire step on a Young diagram, top box of each pile in orange forming a new pile"></picture></p>
<p>We take one card from each pile (highlighted in orange in the diagram
above), and create a new pile from them. Then we reorder the piles so
that they are sorted by decreasing size.</p>
<h2 id="convergence-of-the-bulgarian-solitaire">Convergence of the Bulgarian Solitaire</h2>
<p>Now, if you try the Bulgarian Solitaire with 15 cards, for every
possible starting position, you will end up with 4 piles of size 1, 2,
3, and 4. It turns out that this pattern can be observed consistently:</p>
<div class="theorem">
<p><span class="env-label">Theorem 1.</span> When the number of cards <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi><mo>=</mo><mi>k</mi><mo stretchy="false" form="prefix">(</mo><mi>k</mi><mo>+</mo><mn>1</mn><mo stretchy="false" form="postfix">)</mo><mi>/</mi><mn>2</mn></mrow><annotation encoding="application/x-tex">n = k(k+1)/2</annotation></semantics></math> is triangular<span class="sidenote-wrapper"><label for="sn-1" class="margin-toggle sidenote-number"></label><input type="checkbox" id="sn-1" class="margin-toggle" /><span class="sidenote"><a href="https://en.wikipedia.org/wiki/Triangular_number">Triangular numbers</a> are the sums of consecutive
integers: 1, 1+2, 1+2+3, etc. They get their names from the fact that
they can be arranged in a triangle. (OEIS: <a href="https://oeis.org/A000217">A000217</a>) (Image from
<a href="https://commons.wikimedia.org/wiki/File:First_six_triangular_numbers.svg">Wikimedia</a>, CC-BY-SA.)<br />
<br />
<picture><source srcset="https://lozeve.com/images/bulgarian-solitaire/First_six_triangular_numbers-dark.svg" media="(prefers-color-scheme: dark)"><img src="https://lozeve.com/images/bulgarian-solitaire/First_six_triangular_numbers.svg" alt="Dots arranged in triangles showing the first six triangular numbers 1, 3, 6, 10, 15, 21"></picture><br />
<br />
</span></span>,
the Bulgarian Solitaire will converge to piles of size 1, 2, …, <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>k</mi><annotation encoding="application/x-tex">k</annotation></semantics></math>.</p>
</div>
<p>How can we prove this?</p>
<p>There is a nice trick: we rotate (again!) our Young diagram by 45°:</p>
<p><picture><source srcset="https://lozeve.com/images/bulgarian-solitaire/young_rotated_45-dark.png" media="(prefers-color-scheme: dark)"><img src="https://lozeve.com/images/bulgarian-solitaire/young_rotated_45.png" alt="Young diagram rotated 45 degrees so boxes stack in diagonal layers"></picture></p>
<p>When we do a step in the Bulgarian Solitaire, we move around the boxes:</p>
<p><picture><source srcset="https://lozeve.com/images/bulgarian-solitaire/young_fall-dark.png" media="(prefers-color-scheme: dark)"><img src="https://lozeve.com/images/bulgarian-solitaire/young_fall.png" alt="Bulgarian Solitaire step on a 45-degree Young diagram, a grey box falling into an empty space below"></picture></p>
<p>Sometimes we can see that a box (in grey here) is above an empty
space, and therefore it falls down. This corresponds to cases when
there is a need to reorder the piles so that they remain in order of
decreasing size.</p>
<p>We can see that at each step, the total potential energy of the boxes
either stays the same (when all boxes are still resting on other boxes
or on the edges) or decreases (when a box is above an empty space and
falls down). And the lowest possible potential energy is reached when
the configuration is fully triangular, when boxes are spread evenly
across all piles!</p>
<p>So now we just need to prove that all configurations will end up at
this minimum of potential energy, i.e. that there is no local minimum
that prevents the system from reaching this global minimum.</p>
<p>Imagine we are <em>not</em> at this triangular position. Since the total
number of boxes is triangular, there is necessarily one layer with an
empty space for a box, and one layer above with an additional box. At
each step, the boxes will “rotate”, and the empty space and the
additional box will move one space to the right. If the layer with the
empty space is of size <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>k</mi><annotation encoding="application/x-tex">k</annotation></semantics></math>, the layer above it will be of size <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>k</mi><mo>+</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">k+1</annotation></semantics></math>,
and these numbers are relatively prime. After a certain number of
steps, the additional box will be directly above the empty space and
will fall down.</p>
<p>So no configuration that is not fully triangular is stable: after a
certain number of steps, the potential energy will decrease. The
detailed proof can be found in section 2 of <a href="https://arxiv.org/abs/1503.00885">the paper</a>.</p>
<h2 id="simulating-the-bulgarian-solitaire">Simulating the Bulgarian Solitaire</h2>
<p>Let’s simulate the process (in Python) to visualize the
convergence. The script will generate all partitions of a given
integer <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>n</mi><annotation encoding="application/x-tex">n</annotation></semantics></math>, and generate the transition graph of the Bulgarian
Solitaire. If a step of the Bulgarian Solitaire transforms partition
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>p</mi><mn>1</mn></msub><annotation encoding="application/x-tex">p_1</annotation></semantics></math> into partition <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>p</mi><mn>2</mn></msub><annotation encoding="application/x-tex">p_2</annotation></semantics></math>, we will draw an edge between <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>p</mi><mn>1</mn></msub><annotation encoding="application/x-tex">p_1</annotation></semantics></math> and
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msub><mi>p</mi><mn>2</mn></msub><annotation encoding="application/x-tex">p_2</annotation></semantics></math>.</p>
<p>We’ll start by defining helpful type aliases: a partition is a tuple
of ints, and the graph we will generate is a dictionary from
partitions to partitions.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="bu">type</span> Partition <span class="op">=</span> <span class="bu">tuple</span>[<span class="bu">int</span>, ...]</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="bu">type</span> Graph <span class="op">=</span> <span class="bu">dict</span>[Partition, Partition]</span></code></pre></div>
<p>Next, we need a function that enumerates all possible partitions of a
given integer <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>n</mi><annotation encoding="application/x-tex">n</annotation></semantics></math>. It is built recursively: for all possible prefixes
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>0</mn><mo>&lt;</mo><mi>k</mi><mo>≤</mo><mi>n</mi></mrow><annotation encoding="application/x-tex">0 &lt; k \leq n</annotation></semantics></math>, the partitions we are looking for consist of <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>k</mi><annotation encoding="application/x-tex">k</annotation></semantics></math>
followed by all partitions of <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi><mo>−</mo><mi>k</mi></mrow><annotation encoding="application/x-tex">n-k</annotation></semantics></math>.</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> collections.abc <span class="im">import</span> Generator</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> integer_partition(n: <span class="bu">int</span>) <span class="op">-&gt;</span> Generator[Partition]:</span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a>    <span class="cf">if</span> n <span class="op">&lt;=</span> <span class="dv">0</span>:</span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a>        <span class="cf">return</span></span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a>    <span class="kw">def</span> find_partitions_recursive(target: <span class="bu">int</span>, current_partition: <span class="bu">list</span>[<span class="bu">int</span>]):</span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a>        <span class="cf">if</span> target <span class="op">==</span> <span class="dv">0</span>:</span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a>            <span class="cf">yield</span> current_partition</span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a>            <span class="cf">return</span></span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a>        max_val <span class="op">=</span> current_partition[<span class="op">-</span><span class="dv">1</span>] <span class="cf">if</span> current_partition <span class="cf">else</span> target</span>
<span id="cb2-13"><a href="#cb2-13" aria-hidden="true" tabindex="-1"></a>        <span class="cf">for</span> i <span class="kw">in</span> <span class="bu">range</span>(<span class="bu">min</span>(target, max_val), <span class="dv">0</span>, <span class="op">-</span><span class="dv">1</span>):</span>
<span id="cb2-14"><a href="#cb2-14" aria-hidden="true" tabindex="-1"></a>            current_partition.append(i)</span>
<span id="cb2-15"><a href="#cb2-15" aria-hidden="true" tabindex="-1"></a>            <span class="cf">yield</span> <span class="cf">from</span> find_partitions_recursive(target <span class="op">-</span> i, current_partition)</span>
<span id="cb2-16"><a href="#cb2-16" aria-hidden="true" tabindex="-1"></a>            <span class="co"># Backtrack</span></span>
<span id="cb2-17"><a href="#cb2-17" aria-hidden="true" tabindex="-1"></a>            current_partition.pop()</span>
<span id="cb2-18"><a href="#cb2-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-19"><a href="#cb2-19" aria-hidden="true" tabindex="-1"></a>    <span class="cf">yield</span> <span class="cf">from</span> <span class="bu">map</span>(<span class="bu">tuple</span>, find_partitions_recursive(n, []))</span></code></pre></div>
<p>The <code>step</code> function is the Bulgarian Solitaire itself:</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> step(partition: Partition) <span class="op">-&gt;</span> Partition:</span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a>    <span class="bu">next</span> <span class="op">=</span> [<span class="bu">len</span>(partition)] <span class="op">+</span> [k <span class="op">-</span> <span class="dv">1</span> <span class="cf">for</span> k <span class="kw">in</span> partition <span class="cf">if</span> k <span class="op">&gt;</span> <span class="dv">1</span>]</span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a>    <span class="cf">return</span> <span class="bu">tuple</span>(<span class="bu">sorted</span>(<span class="bu">next</span>, reverse<span class="op">=</span><span class="va">True</span>))</span></code></pre></div>
<p>We can now compute the transition graph:</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> compute_graph(n: <span class="bu">int</span>) <span class="op">-&gt;</span> Graph:</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a>    <span class="cf">return</span> {partition: step(partition) <span class="cf">for</span> partition <span class="kw">in</span> integer_partition(n)}</span></code></pre></div>
<p>Now for display, we generate some <a href="https://graphviz.org/">Graphviz</a> code. The colors are
adapted for viewing directly in the terminal.</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> print_graphviz(graph: Graph) <span class="op">-&gt;</span> <span class="va">None</span>:</span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a>    <span class="bu">print</span>(<span class="st">&quot;&quot;&quot;digraph {</span></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a><span class="st">    bgcolor=&quot;transparent&quot;;</span></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a><span class="st">    node [shape=&quot;rect&quot;, fontcolor=&quot;white&quot;, color=&quot;white&quot;];</span></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a><span class="st">    edge [fontcolor=&quot;white&quot;, color=&quot;white&quot;];</span></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a><span class="st">    &quot;&quot;&quot;</span>)</span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a>    <span class="cf">for</span> k, v <span class="kw">in</span> graph.items():</span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a>        <span class="bu">print</span>(<span class="ss">f'    &quot;</span><span class="sc">{</span>k<span class="sc">}</span><span class="ss">&quot; -&gt; &quot;</span><span class="sc">{</span>v<span class="sc">}</span><span class="ss">&quot;;'</span>)</span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a>    <span class="bu">print</span>(<span class="st">&quot;}&quot;</span>)</span></code></pre></div>
<p>To finish, let’s add a command-line interface:</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> argparse</span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> main():</span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a>    parser <span class="op">=</span> argparse.ArgumentParser()</span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a>    parser.add_argument(<span class="st">&quot;n&quot;</span>, <span class="bu">type</span><span class="op">=</span><span class="bu">int</span>)</span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a>    args <span class="op">=</span> parser.parse_args()</span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true" tabindex="-1"></a>    graph <span class="op">=</span> compute_graph(args.n)</span>
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true" tabindex="-1"></a>    print_graphviz(graph)</span>
<span id="cb6-10"><a href="#cb6-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-11"><a href="#cb6-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-12"><a href="#cb6-12" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> <span class="va">__name__</span> <span class="op">==</span> <span class="st">&quot;__main__&quot;</span>:</span>
<span id="cb6-13"><a href="#cb6-13" aria-hidden="true" tabindex="-1"></a>    main()</span></code></pre></div>
<p>The script can then be called directly:</p>
<div class="sourceCode" id="cb7" data-org-language="sh"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Save the graphviz file</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a><span class="ex">python</span> bulgarian_solitaire.py 10 <span class="op">&gt;</span> graph10.dot</span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Generate a PNG graph</span></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a><span class="ex">python</span> bulgarian_solitaire.py 10 <span class="kw">|</span> <span class="ex">dot</span> <span class="at">-Tpng</span> <span class="op">&gt;</span> graph_10.png</span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a><span class="co"># Display the image directly in the terminal (if it supports image display)</span></span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a><span class="ex">python</span> bulgarian_solitaire.py 12 <span class="kw">|</span> <span class="ex">dot</span> <span class="at">-Tpng</span> <span class="kw">|</span> <span class="ex">viu</span> <span class="at">-</span></span></code></pre></div>
<p>Here is the output for <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi><mo>=</mo><mn>6</mn></mrow><annotation encoding="application/x-tex">n=6</annotation></semantics></math>:</p>
<p><img src="https://lozeve.com/images/bulgarian-solitaire/graph_6.svg" style="background-color: #151515;" alt="Transition graph of the Bulgarian Solitaire on partitions of 6, all converging to 3, 2, 1" /></p>
<p>And for <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi><mo>=</mo><mn>10</mn></mrow><annotation encoding="application/x-tex">n=10</annotation></semantics></math>:</p>
<p><img src="https://lozeve.com/images/bulgarian-solitaire/graph_10.svg" style="background-color: #151515;" alt="Transition graph of the Bulgarian Solitaire on partitions of 10, all converging to 4, 3, 2, 1" /></p>
<p>As we can see, all partitions indeed converge to the triangular
configurations <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false" form="prefix">(</mo><mn>3</mn><mo>,</mo><mn>2</mn><mo>,</mo><mn>1</mn><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">(3,2,1)</annotation></semantics></math> and <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false" form="prefix">(</mo><mn>4</mn><mo>,</mo><mn>3</mn><mo>,</mo><mn>2</mn><mo>,</mo><mn>1</mn><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">(4,3,2,1)</annotation></semantics></math>.</p>
<p>Now what happens when the number <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>n</mi><annotation encoding="application/x-tex">n</annotation></semantics></math> is not triangular?</p>
<p>For <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi><mo>=</mo><mn>7</mn></mrow><annotation encoding="application/x-tex">n=7</annotation></semantics></math>:</p>
<p><img src="https://lozeve.com/images/bulgarian-solitaire/graph_7.svg" style="background-color: #151515;" alt="Transition graph of the Bulgarian Solitaire on partitions of 7, converging to a four-state cycle" /></p>
<p>The dynamical system converges to a cycle between <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false" form="prefix">(</mo><mn>4</mn><mo>,</mo><mn>2</mn><mo>,</mo><mn>1</mn><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">(4,2,1)</annotation></semantics></math>,
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false" form="prefix">(</mo><mn>3</mn><mo>,</mo><mn>3</mn><mo>,</mo><mn>1</mn><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">(3,3,1)</annotation></semantics></math>, <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false" form="prefix">(</mo><mn>3</mn><mo>,</mo><mn>2</mn><mo>,</mo><mn>2</mn><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">(3,2,2)</annotation></semantics></math>, and <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false" form="prefix">(</mo><mn>3</mn><mo>,</mo><mn>2</mn><mo>,</mo><mn>1</mn><mo>,</mo><mn>1</mn><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">(3,2,1,1)</annotation></semantics></math>. When we look at this cycle, we
realize that it is the triangular configuration <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false" form="prefix">(</mo><mn>3</mn><mo>,</mo><mn>2</mn><mo>,</mo><mn>1</mn><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">(3,2,1)</annotation></semantics></math>, plus an
additional box cycling above.</p>
<p>For <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi><mo>=</mo><mn>8</mn></mrow><annotation encoding="application/x-tex">n=8</annotation></semantics></math>:</p>
<p><img src="https://lozeve.com/images/bulgarian-solitaire/graph_8.svg" style="background-color: #151515;" alt="Transition graph of the Bulgarian Solitaire on partitions of 8, with two connected components" /></p>
<p>Here we get two connected components in the graph. And here again, we
get the triangular partition but with two additional boxes cycling
above.</p>
<p>This property can be proved (Theorem 2 in the paper), and the number
of connected components can be computed exactly for all <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>n</mi><annotation encoding="application/x-tex">n</annotation></semantics></math>.</p>
<h2 id="conclusion">Conclusion</h2>
<p>The Bulgarian Solitaire is a nice example of a discrete dynamical
system. The proof is particularly interesting because it relies on
visualization and physical intuition about the “potential energy” of
the system, which translates directly into the formal proof.</p>
<p><a href="https://arxiv.org/abs/1503.00885">The paper</a> also mentions generalizations. I am interested in particular
in the <em>stochastic</em> Bulgarian Solitaire. Instead of taking one card
from each pile at each step, we take one card from each pile
independently with probability <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>0</mn><mo>&lt;</mo><mi>p</mi><mo>&lt;</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">0&lt;p&lt;1</annotation></semantics></math>. The dynamical system becomes a
Markov chain, and it would be interesting to study (even
experimentally) its convergence properties.</p>
<h2 id="bonus-bqn-implementation-of-the-simulator">Bonus: <a href="https://mlochbaum.github.io/BQN/">BQN</a> implementation of the simulator</h2>
<p>First, the <code>Step</code> function computes one step of the Bulgarian
Solitaire. It removes 1 from each pile (<code>¯1⊸+</code>), removes the piles
that became empty (<code>0⊸≠</code>), adds a pile of the original size (<code>≠∾</code>), and
sorts the piles for consistency (<code>∨</code>).</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode txt"><code class="sourceCode default"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>Step←∨≠∾(0⊸≠⊸/¯1⊸+)</span></code></pre></div>
<p>The <code>Partitions</code> function generates all partitions of a given
integer. Conveniently, this was already available in <a href="https://mlochbaum.github.io/bqncrate/?q=integer%20partitions">BQNcrate</a>!</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode txt"><code class="sourceCode default"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a>Partitions←{∾⊢´∾⟜(&lt;-⟜↕∘≠{𝕨∾¨∾(-𝕨⌊≠𝕩)↑𝕩}¨⊢)⍟𝕩⋈⋈⋈↕0}</span></code></pre></div>
<p>We can now compute the graph, by first computing all partitions of the
input, then building the edges by calling <code>Step</code> on each partition.</p>
<div class="sourceCode" id="cb10"><pre class="sourceCode txt"><code class="sourceCode default"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>ComputeGraph←{&gt;(⊢⋈Step)¨Partitions𝕩}</span></code></pre></div>
<p>We now generate and print the graphviz code:</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode txt"><code class="sourceCode default"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a>EdgeToGraphviz←{∾⟜(&quot;&quot;&quot;;&quot;∾@+10)5↓∾&quot;&quot;&quot; -&gt; &quot;&quot;&quot;⊸∾¨•Fmt¨𝕩}</span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a>graphvizheader←&quot;bgcolor=&quot;&quot;transparent&quot;&quot;;</span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a>node [shape=&quot;&quot;rect&quot;&quot;,fontcolor=&quot;&quot;white&quot;&quot;,color=&quot;&quot;white&quot;&quot;];</span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a>edge [fontcolor=&quot;&quot;white&quot;&quot;,color=&quot;&quot;white&quot;&quot;];&quot;</span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a>ToGraphviz←{&quot;digraph {&quot;∾graphvizheader∾(∾EdgeToGraphviz¨&lt;˘𝕩)∾&quot;}&quot;}</span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true" tabindex="-1"></a>n←•ParseFloat⊑•args</span>
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true" tabindex="-1"></a>•Out ToGraphviz ComputeGraph n</span></code></pre></div>
<p>Similarly to the Python version, we can run the script with:</p>
<div class="sourceCode" id="cb12" data-org-language="sh"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="ex">bqn</span> bulgarian_solitaire.bqn 6 <span class="kw">|</span> <span class="ex">dot</span> <span class="at">-Tpng</span> <span class="op">&gt;</span> graph_6.png</span></code></pre></div>
</section>
]]></content:encoded>
    <pubDate>Sun, 08 Feb 2026 00:00:00 UT</pubDate>
    <guid>https://lozeve.com/posts/bulgarian-solitaire.html</guid>
    <dc:creator>Dimitri Lozeve</dc:creator>
</item>
<item>
    <title>Language models are injective and hence invertible</title>
    <link>https://lozeve.com/posts/language-models-are-injective.html</link>
    <content:encoded><![CDATA[<section>
  <p>This is the title of a recent preprint
<span class="citation" data-cites="nikolaou2025_languag_model">(Nikolaou et al. 2025)</span><span class="sidenote-wrapper"><label for="sn-0" class="margin-toggle sidenote-number"></label><input type="checkbox" id="sn-0" class="margin-toggle" /><span class="sidenote">Quick link: <a href="https://arxiv.org/abs/2510.15511">ArXiv:2510.15511</a>.<br />
<br />
</span></span>, that has some
interesting insights on the mathematical properties of Transformers
when viewed as functions.</p>
<p>The immediate reaction is “this is nonsense”, and the title may be
viewed as either misleading or deliberately provocative in order to
gather interest. Indeed, most functions inside neural
networks<span class="sidenote-wrapper"><label for="sn-1" class="margin-toggle">⊕</label><input type="checkbox" id="sn-1" class="margin-toggle" /><span class="marginnote"><img src="https://lozeve.com/images/language-models-are-injective/swiglu.png" alt="Plot of the SwiGLU activation function, a non-injective curve"> The
SwiGLU activation function. It is clearly not injective.<br />
<br />
</span></span> and particularly Transformers are not
injective. One thinks immediately of activation functions,
normalization layers, and so on, counter-examples abound. So how can
an entire language model be injective?</p>
<p>At a higher level, injectivity seems like an even taller order. From
the user’s point of view, plenty of input prompts will lead to the
same answers (one can think of all prompts ending with “answer with
yes or no”)<span class="sidenote-wrapper"><label for="sn-2" class="margin-toggle sidenote-number"></label><input type="checkbox" id="sn-2" class="margin-toggle" /><span class="sidenote">Indeed, the public discourse around this paper was
dismal, with thousands of users on X/Twitter posting ChatGPT
screenshots “disproving” injectivity…<br />
<br />
</span></span>.</p>
<p>So, let’s actually go through the paper to understand the claim more
precisely!</p>
<h2 id="language-models-as-functions">Language models as functions</h2>
<p>There are many different ways of viewing language models as
mathematical functions. In the first intuition above, we considered
models as functions from vectors to vectors, or from text to
text. This is what makes the result seem counter-intuitive at first.</p>
<p>I think one of the main contribution of the paper is to slightly
change the context: they see language models as functions from a
<em>prompt</em> (i.e. a finite sequence of discrete tokens) to <em>activations</em>
on the output layers (vectors).<span class="sidenote-wrapper"><label for="sn-3" class="margin-toggle">⊕</label><input type="checkbox" id="sn-3" class="margin-toggle" /><span class="marginnote"><img src="https://lozeve.com/images/language-models-are-injective/map.png" alt="Diagram of an LLM mapping prompt space to latent space, invertible by SipIt"> The
function we are studying: from prompt space (sequence of tokens) to
latent space (vector of activations).<br />
<br />
</span></span></p>
<p>Formally, we have a finite vocabulary <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi mathvariant="script">𝒱</mi><annotation encoding="application/x-tex">\mathcal{V}</annotation></semantics></math>, and context
length <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>K</mi><annotation encoding="application/x-tex">K</annotation></semantics></math>. From a sequence of tokens <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mo>∈</mo><msup><mi mathvariant="script">𝒱</mi><mrow><mo>≤</mo><mi>K</mi></mrow></msup></mrow><annotation encoding="application/x-tex">s \in \mathcal{V}^{\leq K}</annotation></semantics></math> and
parameters <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi mathvariant="bold-italic">𝜽</mi><annotation encoding="application/x-tex">\mathbf{\theta}</annotation></semantics></math>, the language model gives us <em>last-token
representations</em> <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="bold-italic">𝒓</mi><mo stretchy="false" form="prefix">(</mo><mi>s</mi><mo>,</mo><mi mathvariant="bold-italic">𝜽</mi><mo stretchy="false" form="postfix">)</mo><mo>∈</mo><msup><mi mathvariant="double-struck">ℝ</mi><mi>d</mi></msup></mrow><annotation encoding="application/x-tex">\mathbf{r}(s, \mathbf{\theta}) \in \mathbb{R}^d</annotation></semantics></math>.</p>
<p>The central claim of the paper is that <em>this</em> function is injective.</p>
<h2 id="why-is-injectivity-important">Why is injectivity important?</h2>
<p>Since the various components of the language models are not themselves
injective, people tend to assume that there is some “forgetting” and
privacy is built into all language models. Since the input prompt is
transformed into an intermediate representation that goes through many
transformations, information is lost and the input prompt cannot be
reconstructed exactly. This intuition is wrong.</p>
<p>This has practical consequences for systems that store intermediate
activations (e.g. embeddings), in the assumption that this is somehow
more secure, or more respectful of their users privacy, than storing
the user inputs directly. In practice, all the information is in the
activations, and the paper provides both a formal proof and a
practical reconstruction method.</p>
<h2 id="structure-of-the-paper">Structure of the paper</h2>
<p>The paper has two main parts.</p>
<ul>
<li>The <em>theoretical</em> part defines a Transformer-based language model
mathematically as a function from sequences of tokens to real-valued
vectors. In this context, they prove that language models based on
common blocks (feed-forward layers, embedding layers, self-attention
blocks, common activations, etc) are almost surely injective after
random initialization of the parameters, and that this property is
preserved during training.</li>
<li>The <em>practical</em> part builds on these insights and builds a fairly
straightforward algorithm to reconstruct user inputs from the
activations of any intermediate layer, including the output
layer. They show 100% reconstruction accuracy on widely-used
language models.</li>
</ul>
<h2 id="the-theoretical-argument">The theoretical argument</h2>
<h3 id="a-primer-on-analytic-functions">A primer on analytic functions</h3>
<p>To prove the main results, the paper uses the notion of
<em>analyticity</em><span class="sidenote-wrapper"><label for="sn-4" class="margin-toggle sidenote-number"></label><input type="checkbox" id="sn-4" class="margin-toggle" /><span class="sidenote">See Appendix A of the paper for the full
background on analytic functions.<br />
<br />
</span></span>. Analytic functions are highly
regular, actually even “smoother” than infinitely differentiable
functions. It is this “smoothness” that will have important
consequences for proving injectivity.</p>
<p>Intuitively, analytic functions are “locally polynomial”:</p>
<div class="definition">
<p><span class="env-label">Definition 1.</span> Let <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="script">𝒰</mi><mo>⊆</mo><msup><mi mathvariant="double-struck">ℝ</mi><mi>m</mi></msup></mrow><annotation encoding="application/x-tex">\mathcal{U} \subseteq \mathbb{R}^m</annotation></semantics></math> be open.
A function <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>f</mi><mo>:</mo><mi mathvariant="script">𝒰</mi><mo>→</mo><mi mathvariant="double-struck">ℝ</mi></mrow><annotation encoding="application/x-tex">f : \mathcal{U} \to \mathbb{R}</annotation></semantics></math> is <em>real-analytic</em> on <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi mathvariant="script">𝒰</mi><annotation encoding="application/x-tex">\mathcal{U}</annotation></semantics></math> if,
for every <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="bold-italic">𝒚</mi><mo>∈</mo><mi mathvariant="script">𝒰</mi></mrow><annotation encoding="application/x-tex">\mathbf{y} \in \mathcal{U}</annotation></semantics></math>, there exists coefficients
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false" form="prefix">{</mo><msub><mi>c</mi><mi mathvariant="bold-italic">𝜶</mi></msub><mo>∈</mo><mi mathvariant="double-struck">ℝ</mi><msub><mo stretchy="false" form="postfix">}</mo><mrow><mi>α</mi><mo>∈</mo><msup><mi mathvariant="double-struck">ℕ</mi><mi>m</mi></msup></mrow></msub></mrow><annotation encoding="application/x-tex">\{c_\mathbf{\alpha} \in \mathbb{R}\}_{\alpha \in \mathbb{N}^m}</annotation></semantics></math>
and <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi><mo>&gt;</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">r&gt;0</annotation></semantics></math> such that</p>
<p><math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>f</mi><mo stretchy="false" form="prefix">(</mo><mi mathvariant="bold-italic">𝒙</mi><mo stretchy="false" form="postfix">)</mo><mo>=</mo><munder><mo>∑</mo><mrow><mi mathvariant="bold-italic">𝜶</mi><mo>∈</mo><msup><mi mathvariant="double-struck">ℕ</mi><mi>m</mi></msup></mrow></munder><msub><mi>c</mi><mi mathvariant="bold-italic">𝜶</mi></msub><mo stretchy="false" form="prefix">(</mo><mi mathvariant="bold-italic">𝒙</mi><mo>−</mo><mi mathvariant="bold-italic">𝒚</mi><msup><mo stretchy="false" form="postfix">)</mo><mi mathvariant="bold-italic">𝜶</mi></msup></mrow><annotation encoding="application/x-tex">
f(\mathbf{x}) = \sum_{\mathbf{\alpha} \in \mathbb{N}^m} c_\mathbf{\alpha} (\mathbf{x} - \mathbf{y})^\mathbf{\alpha}
</annotation></semantics></math></p>
<p>for all <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="bold-italic">𝒙</mi><mo>∈</mo><mi mathvariant="script">𝒰</mi></mrow><annotation encoding="application/x-tex">\mathbf{x} \in \mathcal{U}</annotation></semantics></math> with <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mrow><mo stretchy="true" form="prefix">‖</mo><mi mathvariant="bold-italic">𝒙</mi><mo>−</mo><mi mathvariant="bold-italic">𝒚</mi><mo stretchy="true" form="postfix">‖</mo></mrow><mn>2</mn></msub><mo>&lt;</mo><mi>r</mi></mrow><annotation encoding="application/x-tex">\lVert \mathbf{x} - \mathbf{y} \rVert_2 &lt; r</annotation></semantics></math>.</p>
<p>The set of analytic functions on <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi mathvariant="script">𝒰</mi><annotation encoding="application/x-tex">\mathcal{U}</annotation></semantics></math> is denoted by <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>C</mi><mi>ω</mi></msup><mo stretchy="false" form="prefix">(</mo><mi mathvariant="script">𝒰</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">C^\omega(\mathcal{U})</annotation></semantics></math>.</p>
</div>
<p>Intuitively, not only the function is infinitely differentiable, and
therefore can be locally approximated by its Taylor series, but
actually the coefficients are zero after some point, so the function
is locally a polynomial. This gives enormous regularity guarantees,
and analytic functions are among the most well-behaved.</p>
<p>A vector-valued function is analytic if all its components are
analytic, and we can similarly extend the definition to matrix-valued
functions. This is very important for our discussions since the
component blocks of Transformers are often matrix-valued,
e.g. attention layers.</p>
<p>Importantly, the set of analytic functions is closed under common
operations: addition, product, quotient, and composition. This means
that we only have to prove the analyticity of common building blocks
of Transformers, and through addition and composition the analyticity
of the overall function will be immediately proven.</p>
<p>Moreover, analytic functions have a key property relating to their
zero sets:</p>
<div class="proposition">
<p><span class="env-label">Proposition 1.</span> Let <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="script">𝒰</mi><mo>⊆</mo><msup><mi mathvariant="double-struck">ℝ</mi><mi>m</mi></msup></mrow><annotation encoding="application/x-tex">\mathcal{U} \subseteq \mathbb{R}^m</annotation></semantics></math> be connected and open,
and let <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>f</mi><mo>∈</mo><msup><mi>C</mi><mi>ω</mi></msup><mo stretchy="false" form="prefix">(</mo><mi mathvariant="script">𝒰</mi><mo>;</mo><msup><mi mathvariant="double-struck">ℝ</mi><mi>n</mi></msup><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">f \in C^\omega(\mathcal{U}; \mathbb{R}^n)</annotation></semantics></math>.
If <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>f</mi><mo>≢</mo><msub><mn mathvariant="bold">𝟎</mn><mi>n</mi></msub></mrow><annotation encoding="application/x-tex">f \not\equiv \mathbf{0}_n</annotation></semantics></math>, then its zero set</p>
<p><math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>Z</mi><mo stretchy="false" form="prefix">(</mo><mi>f</mi><mo stretchy="false" form="postfix">)</mo><mo>:=</mo><msup><mi>f</mi><mrow><mi>−</mi><mn>1</mn></mrow></msup><mo stretchy="false" form="prefix">(</mo><mo stretchy="false" form="prefix">{</mo><msub><mn mathvariant="bold">𝟎</mn><mi>n</mi></msub><mo stretchy="false" form="postfix">}</mo><mo stretchy="false" form="postfix">)</mo><mo>=</mo><mo stretchy="false" form="prefix">{</mo><mi mathvariant="bold-italic">𝒙</mi><mo>∈</mo><mi mathvariant="script">𝒰</mi><mo>:</mo><mi>f</mi><mo stretchy="false" form="prefix">(</mo><mi mathvariant="bold-italic">𝒙</mi><mo stretchy="false" form="postfix">)</mo><mo>=</mo><msub><mn mathvariant="bold">𝟎</mn><mi>n</mi></msub><mo stretchy="false" form="postfix">}</mo></mrow><annotation encoding="application/x-tex">
Z(f) := f^{-1}(\{\mathbf{0}_n\}) = \{\mathbf{x} \in \mathcal{U} : f(\mathbf{x}) = \mathbf{0}_n\}
</annotation></semantics></math></p>
<p>has Lebesgue measure zero in <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msup><mi mathvariant="double-struck">ℝ</mi><mi>m</mi></msup><annotation encoding="application/x-tex">\mathbb{R}^m</annotation></semantics></math>.</p>
</div>
<div class="proof">
<p><span class="env-label">Proof.</span> The proof can be found in <span class="citation" data-cites="mityagin2020_zero_set">Mityagin (2020)</span><span class="sidenote-wrapper"><label for="sn-5" class="margin-toggle sidenote-number"></label><input type="checkbox" id="sn-5" class="margin-toggle" /><span class="sidenote">The paper actually cites the (identical) <a href="https://arxiv.org/abs/1512.07276">preprint version</a>.<br />
<br />
</span></span>.</p>
</div>
<p>The gist is simply this: if <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>f</mi><annotation encoding="application/x-tex">f</annotation></semantics></math> is not zero everywhere, then it is
zero almost nowhere. If there is an entire continuous region where <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>f</mi><annotation encoding="application/x-tex">f</annotation></semantics></math>
is zero, it means that <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>f</mi><annotation encoding="application/x-tex">f</annotation></semantics></math> is zero everywhere! This is a very strong
property of analytic functions: fundamentally, they are so regular
that if they are zero on any significant portion of their domain,
their smoothness imposes that they become zero everywhere.</p>
<p>This proposition is key to the paper as it will be used to prove
injectivity. We can now go on to the actual results of the paper.</p>
<h3 id="language-models-are-analytic">Language models are analytic</h3>
<p>A language model is a composition of many building blocks. Transformer
blocks are themselves composed of self-attention layers and MLPs,
which are themselves compositions of stacking operations,
normalizations, softmax, exponentials, and polynomials. By going
bottom-up, we can start from basic blocks (polynomial functions, the
exponential function), show that they are analytic, and since analytic
functions are closed under composition, show that the entire language
model is analytic.</p>
<p>The proofs that these building blocks are analytics are detailed in
Appendix A of the paper. The full language model is defined
mathematically as a composition of these building blocks in
Appendix B, with Proposition B.3 putting everything together and
proving that Transformers are analytic.</p>
<h3 id="injectivity-at-initialization">Injectivity at initialization</h3>
<p>Let us draw a set of parameters <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi mathvariant="bold-italic">𝜽</mi><annotation encoding="application/x-tex">\mathbf{\theta}</annotation></semantics></math> at random, from a
distribution with a density. For any two prompts <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mo>,</mo><msup><mi>s</mi><mo>′</mo></msup><mo>∈</mo><msup><mi mathvariant="script">𝒱</mi><mrow><mo>≤</mo><mi>K</mi></mrow></msup></mrow><annotation encoding="application/x-tex">s, s' \in
\mathcal{V}^{\leq K}</annotation></semantics></math>, the probability that the output activations
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="bold-italic">𝒓</mi><mo stretchy="false" form="prefix">(</mo><mi>s</mi><mo>,</mo><mi mathvariant="bold-italic">𝜽</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">\mathbf{r}(s, \mathbf{\theta})</annotation></semantics></math> and <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="bold-italic">𝒓</mi><mo stretchy="false" form="prefix">(</mo><msup><mi>s</mi><mo>′</mo></msup><mo>,</mo><mi mathvariant="bold-italic">𝜽</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">\mathbf{r}(s', \mathbf{\theta})</annotation></semantics></math>
are equal is zero.</p>
<p>This is because the function <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="bold-italic">𝜽</mi><mo>↦</mo><mi mathvariant="bold-italic">𝒓</mi><mo stretchy="false" form="prefix">(</mo><mi>s</mi><mo>,</mo><mi mathvariant="bold-italic">𝜽</mi><mo stretchy="false" form="postfix">)</mo><mo>−</mo><mi mathvariant="bold-italic">𝒓</mi><mo stretchy="false" form="prefix">(</mo><msup><mi>s</mi><mo>′</mo></msup><mo>,</mo><mi mathvariant="bold-italic">𝜽</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">\mathbf{\theta} \mapsto \mathbf{r}(s,
\mathbf{\theta}) - \mathbf{r}(s', \mathbf{\theta})</annotation></semantics></math> is a sum of
analytic functions, and is therefore analytic. By the key proposition
above, its zero set has measure zero. So by drawing random parameters
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi mathvariant="bold-italic">𝜽</mi><annotation encoding="application/x-tex">\mathbf{\theta}</annotation></semantics></math>, you have almost surely <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="bold-italic">𝒓</mi><mo stretchy="false" form="prefix">(</mo><mi>s</mi><mo>,</mo><mi mathvariant="bold-italic">𝜽</mi><mo stretchy="false" form="postfix">)</mo><mo>≠</mo><mi mathvariant="bold-italic">𝒓</mi><mo stretchy="false" form="prefix">(</mo><msup><mi>s</mi><mo>′</mo></msup><mo>,</mo><mi mathvariant="bold-italic">𝜽</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">\mathbf{r}(s,
\mathbf{\theta}) \neq \mathbf{r}(s', \mathbf{\theta})</annotation></semantics></math>.</p>
<p>We have just proven that if <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mo>≠</mo><msup><mi>s</mi><mo>′</mo></msup></mrow><annotation encoding="application/x-tex">s \neq s'</annotation></semantics></math>, then, with probability 1 over
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi mathvariant="bold-italic">𝜽</mi><annotation encoding="application/x-tex">\mathbf{\theta}</annotation></semantics></math>, we have that <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="bold-italic">𝒓</mi><mo stretchy="false" form="prefix">(</mo><mi>s</mi><mo>,</mo><mi mathvariant="bold-italic">𝜽</mi><mo stretchy="false" form="postfix">)</mo><mo>≠</mo><mi mathvariant="bold-italic">𝒓</mi><mo stretchy="false" form="prefix">(</mo><msup><mi>s</mi><mo>′</mo></msup><mo>,</mo><mi mathvariant="bold-italic">𝜽</mi><mo stretchy="false" form="postfix">)</mo></mrow><annotation encoding="application/x-tex">\mathbf{r}(s, \mathbf{\theta}) \neq
\mathbf{r}(s', \mathbf{\theta})</annotation></semantics></math> i.e., <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi mathvariant="bold-italic">𝒓</mi><annotation encoding="application/x-tex">\mathbf{r}</annotation></semantics></math> is injective!</p>
<h3 id="injectivity-is-preserved-during-training">Injectivity is preserved during training</h3>
<p>However, we only draw <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi mathvariant="bold-italic">𝜽</mi><annotation encoding="application/x-tex">\mathbf{\theta}</annotation></semantics></math> at random during
initialization. What if during training, as <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi mathvariant="bold-italic">𝜽</mi><annotation encoding="application/x-tex">\mathbf{\theta}</annotation></semantics></math> changes,
the language model loses its injectivity?</p>
<p>It turns out that gradient descent itself is also analytic (and so are
its variants, stochastic gradient descent, minibatch GD, etc). It is
therefore once again very smooth, and can only stretch and bend the
parameter space, but not collapse regions of positive volume into
single points. So as the parameters change during training, the points
that are apart stay apart and do not collapse onto each
other<span class="sidenote-wrapper"><label for="sn-6" class="margin-toggle sidenote-number"></label><input type="checkbox" id="sn-6" class="margin-toggle" /><span class="sidenote">The argument is made formally in the paper using
topological properties of the Jacobian of the gradient descent
function. I won’t go into the details here, see Section 2 of the paper
for an overview, and Appendix C for the full proof.<br />
<br />
</span></span>.</p>
<p>The injectivity property established at initialization is therefore
preserved at each step of the training. This concludes the main result
of the paper: a fully-trained language model based on Transformers is
injective. Two different input prompts will always lead to two
different output activations in the final layer (and in any
intermediate layer for that matter).</p>
<h3 id="remarks">Remarks</h3>
<p>The paper bases all the proofs on a definition of a “standard”
language model based on Transformers. However, there are architecture
choices that can break the fundamental hypotheses. In particular, some
activation functions like ReLU are not analytic (indeed, it is not
even differentiable), and things like quantization also break the
analytic property of the entire model. In these cases, the model will
not be injective.</p>
<p>However, all modern language model architectures use smooth
activations<span class="sidenote-wrapper"><label for="sn-7" class="margin-toggle sidenote-number"></label><input type="checkbox" id="sn-7" class="margin-toggle" /><span class="sidenote">See <a href="https://jcarlosroldan.com/post/348/">this great article</a> on SwiGLU and family for an
overview of activation functions used in LLMs.<br />
<br />
</span></span>, and quantization is not the norm
everywhere. As we will see in the next section, the theoretical result
hold very well in practice for LLMs that are widely used today.</p>
<h2 id="practical-application">Practical application</h2>
<p>Proving a theorem might not be enough, as there are plenty of things
that are ignored in the mathematical formulation (e.g. floating-point
precision). Moreover, real-world LLMs are very complex systems with
thousands of building blocks. For instance, activation functions are
part of a very active research domain and change frequently, so there
is no guarantee that all activation functions found in the wild follow
the requirements of the theorem.</p>
<p>The first practical test is to check for collisions: two input prompts
that lead to the same activation vector. If we can exhibit two
sequences of tokens like this, we will have broken the injectivity.</p>
<p>For large vocabularies, the input space is too big to be checked
exhaustively, so they can’t check everything. Instead they start with
a dataset of real-world prompts and find the ones that are the closest
in the output. They append all the possible sequences of tokens to
these prompts. Therefore the test is “exhaustive” starting from
“prefix” prompts that were already very close.</p>
<p>What they find is that all input pairs are very far from a collision
threshold of <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><msup><mn>10</mn><mrow><mi>−</mi><mn>6</mn></mrow></msup><annotation encoding="application/x-tex">10^{-6}</annotation></semantics></math> (probably chosen to account for floating-point
error). As this check is not truly exhaustive and the thresholds have
been fixed somewhat arbitrarily, it’s not very significant, but it
acts as a nice “sanity check” for the theory.</p>
<p><img src="https://lozeve.com/images/language-models-are-injective/collisions.png" alt="Swarm and box plots of L2 distances across models and layers, all above the collision threshold">
<span class="sidenote-wrapper"><label for="sn-8" class="margin-toggle">⊕</label><input type="checkbox" id="sn-8" class="margin-toggle" /><span class="marginnote">Distance between final layer and intermediate layer outputs
for the “exhaustive” check on input prompts. All are significantly
above the collision threshold as defined in the paper.<br />
<br />
</span></span></p>
<p>The second practical experiments is to exploit the injectivity result
to build an algorithm to invert a language model. Starting from the
last-layer activations, they build a simple gradient-guided search
that reconstruct the input sequence of tokens. The results are
impressive: they get 100% token-level accuracy on all prompts, and in
a remarkably quick process. The following results are for the GPT-2
Small model:</p>
<table>
<thead>
<tr>
<th>Method</th>
<th>Mean Time (s)</th>
<th>Accuracy</th>
</tr>
</thead>
<tbody>
<tr>
<td>HardPrompts</td>
<td>6132.59 ± 104.61</td>
<td>0.00</td>
</tr>
<tr>
<td>BruteForce</td>
<td>3889.61 ± 691.17</td>
<td><strong>1.00</strong></td>
</tr>
<tr>
<td>SipIt</td>
<td><strong>28.01 ± 35.87</strong></td>
<td><strong>1.00</strong></td>
</tr>
</tbody>
</table>
<h2 id="conclusion-rebuilding-our-intuition">Conclusion: rebuilding our intuition</h2>
<h3 id="expressivity-and-regularization">Expressivity and regularization</h3>
<p>Transformers (and neural networks in general) are very useful because
they generalize very well. The class of learned functions needs to be
very large to be as expressive as possible, but still constrained to
avoid overfitting. The regularization built into our language models
can be understood as properties of the functions they
represent. Analytic functions are a class of very smooth, very regular
functions, that have a lot of nice property, so it is no accident that
they are very good targets of a machine learning algorithm.</p>
<h3 id="curse-of-dimensionality">Curse of dimensionality</h3>
<p>The main result of the paper does not seem so unintuitive if its
hypotheses are laid out clearly. What we have is a function with
inputs on a <em>discrete space</em> (finite sequences on a finite
vocabulary), and outputs in <em>continuous, high-dimension</em> vector
space. Since the output space is so much larger, it would actually be
very surprising that a non-pathological function makes several inputs
“collapse” into a single high-dimension vector!</p>
<p>Moreover, there is an instance of the <em>curse of dimensionality</em>: if
you draw two vectors with random directions in a high-dimension space,
they will very probably be orthogonal
<span class="citation" data-cites="vershynin2018_high_dimen_probab">(Vershynin 2018, sec. 3.3.3)</span>. High dimensions
tend to “push everything to the edges” and so collisions become
increasingly unlikely. So another way to see this result is that it is
unintuitive only because probability on high-dimension vector spaces
is in itself quite unintuitive!</p>
<h2 class="unnumbered" id="references">References</h2>
<div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0" role="list">
<div id="ref-mityagin2020_zero_set" class="csl-entry" role="listitem">
Mityagin, Boris S. 2020. <span>“The Zero Set of a Real Analytic Function.”</span> <em>Mathematical Notes</em> 107 (3–4): 529–30. <a href="https://doi.org/10.1134/s0001434620030189">https://doi.org/10.1134/s0001434620030189</a>.
</div>
<div id="ref-nikolaou2025_languag_model" class="csl-entry" role="listitem">
Nikolaou, Giorgos, Tommaso Mencattini, Donato Crisostomi, Andrea Santilli, Yannis Panagakis, and Emanuele Rodolà. 2025. <span>“Language Models Are Injective and Hence Invertible.”</span> <a href="https://arxiv.org/abs/2510.15511">https://arxiv.org/abs/2510.15511</a>.
</div>
<div id="ref-vershynin2018_high_dimen_probab" class="csl-entry" role="listitem">
Vershynin, Roman. 2018. <em>High-Dimensional Probability: An Introduction with Applications in Data Science</em>. Cambridge Series in Statistical and Probabilistic Mathematics 47. <span>Cambridge</span>: <span>Cambridge University Press</span>. <a href="https://www.math.uci.edu/~rvershyn/papers/HDP-book/HDP-book.html">https://www.math.uci.edu/~rvershyn/papers/HDP-book/HDP-book.html</a>.
</div>
</div>
</section>
]]></content:encoded>
    <pubDate>Tue, 25 Nov 2025 00:00:00 UT</pubDate>
    <guid>https://lozeve.com/posts/language-models-are-injective.html</guid>
    <dc:creator>Dimitri Lozeve</dc:creator>
</item>
<item>
    <title>Reading notes: Kolmogorov-Arnold Networks</title>
    <link>https://lozeve.com/posts/kolmogorov-arnold-networks.html</link>
    <content:encoded><![CDATA[<section>
  <p>This paper <span class="citation" data-cites="liu2024_kan">(Liu et al. 2024)</span> proposes an alternative to multi-layer
perceptrons (MLPs) in machine learning.</p>
<p>The basic idea is that MLPs have parameters on the nodes of the
computation graph (the weights and biases on each cell), and that KANs
have the parameters on the edges. Each edge has a learnable activation
function parameterized as a spline.</p>
<p>The network is learned at two levels, which allows for “adjusting
locally”:</p>
<ul>
<li>the overall shape of the computation graph and its connexions
(external degrees of freedom, to learn the compositional structure),</li>
<li>the parameters of each activation function (internal degrees of
freedom).</li>
</ul>
<p>It is based on the <a href="https://en.wikipedia.org/wiki/Kolmogorov%E2%80%93Arnold_representation_theorem">Kolmogorov-Arnold representation theorem</a>, which
says that any continuous multivariate function can be represented as a
sum of continuous univariate functions. We recover the distinction
between the compositional structure of the sum and the structure of
each internal univariate function.</p>
<p>The theorem can be interpreted as two layers, and the paper then
generalizes it to multiple layer of arbitrary width. In the theorem,
the univariate functions are arbitrary and can be complex (even
fractal), so the hope is that allowing for arbitrary depth and width
will allow to only use splines. They derive an approximation theorem:
when replacing the arbitrary continuous functions of the
Kolmogorov-Arnold representation with splines, we can bound the error
independently of the dimension. (However there is a constant which
depends on the function and its representation, and therefore on the
dimension…) Theoretical scaling laws in the number of parameters are
much better than for MLPs, and moreover, experiments show that KANs
are much closer to their theoretical bounds than MLPs.</p>
<p>KANs have interesting properties:</p>
<ul>
<li>The splines are interpolated on grid points which can be iteratively
refined. The fact that there is a notion of “fine-grainedness” is
very interesting, it allows to add parameters without having to
retrain everything.</li>
<li>Larger is not always better: the quality of the reconstruction
depends on finding the optimal shape of the network, which should
match the structure of the function we want to approximate. Finding
this optimal shape is found via sparsification, pruning, and
regularization (non-trivial).</li>
<li>We can have a “human in the loop” during training, guiding pruning,
and “symbolifying” some activations (i.e. by recognizing that an
activation function is actually a cos function, replace it
directly). This symbolic discovery can be guided by a symbolic
system recognizing some functions. It’s therefore a mix of symbolic
regression and numerical regression.</li>
</ul>
<p>They test mostly with scientific applications in mind: reconstructing
equations from physics and pure maths. Conceptually, it has a lot of
overlap with Neural Differential Equations
<span class="citation" data-cites="chenNeuralOrdinaryDifferential2018 ruthotto2024_differ_equat">(Chen et al. 2018; Ruthotto 2024)</span>
and “scientific ML” in general.</p>
<p>There is an interesting discussion at the end about KANs as the model
of choice for the “language of science”. The idea is that LLMs are
important because they are useful for natural language, and KANs
could fill the same role for the language of functions. The
interpretability and adaptability (being able to be manipulated and
guided during training by a domain expert) is thus a core feature that
traditional deep learning models lack.</p>
<p>There are still challenges, mostly it’s unclear how it performs on
other types of data and other modalities, but it is very
encouraging. There is also a computational challenges, they are
obviously much slower to train, but there has been almost no
engineering work on them to optimize this, so it’s expected. The fact
that the operations are not easily batchable (compared to matrix
multiplication) is however worrying for scalability to large networks.</p>
<h2 class="unnumbered" id="references">References</h2>
<div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0" role="list">
<div id="ref-chenNeuralOrdinaryDifferential2018" class="csl-entry" role="listitem">
Chen, Ricky T. Q., Yulia Rubanova, Jesse Bettencourt, and David Duvenaud. 2018. <span>“Neural <span>Ordinary Differential Equations</span>,”</span> June. <a href="http://arxiv.org/abs/1806.07366">http://arxiv.org/abs/1806.07366</a>.
</div>
<div id="ref-liu2024_kan" class="csl-entry" role="listitem">
Liu, Ziming, Yixuan Wang, Sachin Vaidya, Fabian Ruehle, James Halverson, Marin Soljačić, Thomas Y. Hou, and Max Tegmark. 2024. <span>“<span>KAN</span>: <span>Kolmogorov</span>-<span>Arnold</span> <span>Networks</span>.”</span> arXiv. <a href="https://doi.org/10.48550/arXiv.2404.19756">https://doi.org/10.48550/arXiv.2404.19756</a>.
</div>
<div id="ref-ruthotto2024_differ_equat" class="csl-entry" role="listitem">
Ruthotto, Lars. 2024. <span>“Differential <span>Equations</span> for <span>Continuous</span>-<span>Time</span> <span>Deep</span> <span>Learning</span>.”</span> <em>Notices of the American Mathematical Society</em> 71 (05). <a href="https://doi.org/10.1090/noti2930">https://doi.org/10.1090/noti2930</a>.
</div>
</div>
</section>
]]></content:encoded>
    <pubDate>Sat, 08 Jun 2024 00:00:00 UT</pubDate>
    <guid>https://lozeve.com/posts/kolmogorov-arnold-networks.html</guid>
    <dc:creator>Dimitri Lozeve</dc:creator>
</item>

    </channel>
</rss>
