<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Math Space on Xiang Huang | 黄湘</title>
    <link>https://xianghuang.org/math/</link>
    <description>Recent content in Math Space on Xiang Huang | 黄湘</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <atom:link href="https://xianghuang.org/math/" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>The Entropy of Three Outcomes, in 3D</title>
      <link>https://xianghuang.org/math/ternary-entropy/</link>
      <pubDate>Thu, 24 Sep 2026 00:00:00 +0000</pubDate>
      <author>Xiang Huang</author>
      <guid>https://xianghuang.org/math/ternary-entropy/</guid>
      <description>
        <![CDATA[
        <p><em>A coin has one free parameter, so its entropy is a curve. A three-sided die has two, so its entropy is a surface. Here is that surface, and you can turn it around.</em></p>
<p>For a distribution $(p_1, p_2, p_3)$ with $p_1 + p_2 + p_3 = 1$, the Shannon entropy is
$$
H(p_1, p_2, p_3) = -\sum_{i=1}^{3} p_i \log_2 p_i .
$$
The domain is the probability simplex, a triangle, and the graph of $H$ over it is a dome. Drag to rotate it, scroll or pinch to zoom, and hover or tap to read off a distribution.</p>
<iframe id="ternary-entropy" src="/demos/ternary-entropy/?embed" title="Interactive 3D plot of ternary Shannon entropy over the probability simplex" style="display:block;width:100%;height:1000px;border:0;" loading="lazy"></iframe>
<script>
window.addEventListener("message", function (e) {
  if (e.origin === location.origin && e.data && e.data.type === "ternary-entropy-height") {
    document.getElementById("ternary-entropy").style.height = e.data.height + "px";
  }
});
</script>
<p><a href="/demos/ternary-entropy/">Open the full-page version</a>.</p>
<h2 id="laying-the-simplex-flat">Laying the simplex flat</h2>
<p>Write $(x, y, z)$ for $(p_1, p_2, p_3)$. The quickest way to plot is to eliminate $z$ and draw $H(x, y, 1 - x - y)$ over the triangle $x, y \ge 0$, $x + y \le 1$ in the $xy$-plane. But that triangle is not the simplex. It is the simplex&rsquo;s shadow on the $xy$-plane, a right isosceles triangle, so the picture comes out lopsided. The three outcomes play identical roles in $H$, yet they no longer look alike.</p>
<p>The fix is to put coordinates on the plane $x + y + z = 1$ itself. Call the corners $A = (0, 0, 1)$, $B = (1, 0, 0)$ and $C = (0, 1, 0)$. Take $B$ as the new origin, the edge $BC$ as the $u$-axis, and the line in plane $ABC$ through $B$ perpendicular to $BC$ as the $v$-axis. Given a point $P = (u, v)$ in the plane, we want its original coordinates $(x, y, z)$. Everything follows from one angle, the angle between plane $ABC$ and the $xy$-plane. Figure 1 walks through the construction step by step. Rotate it to see it from any side.</p>
<iframe id="simplex-coords" src="/demos/simplex-coordinates/?embed" title="Rotatable 3D construction of the (u, v) coordinates on the plane x + y + z = 1" style="display:block;width:100%;height:760px;border:0;" loading="lazy"></iframe>
<script>
window.addEventListener("message", function (e) {
  if (e.origin === location.origin && e.data && e.data.type === "simplex-coords-height") {
    document.getElementById("simplex-coords").style.height = e.data.height + "px";
  }
});
</script>
<p class="fig-caption" style="font-size:0.9em;color:#555;">Figure 1. The plane $x + y + z = 1$ (blue) and its shadow on the $xy$-plane (beige). Use the buttons to step through the construction and the sliders to move $P$. Segments with the same color play the same role in the two similar triangles. <a href="/demos/simplex-coordinates/">Open it full-page.</a></p>
<p><strong>Step 1: the angle between the planes.</strong> Let $M$ be the midpoint of $BC$. In the equilateral triangle $ABC$ the median $AM$ is perpendicular to $BC$, and in the right isosceles triangle $OBC$ so is $OM$. So $\theta = \angle AMO$ is the angle between the two planes. It sits in the right triangle $AOM$, with
$$
AO = 1, \qquad OM = \frac{\sqrt{2}}{2}, \qquad AM = \frac{\sqrt{6}}{2}.
$$</p>
<p><strong>Step 2: lift $P$.</strong> Let $F$ be the foot of the perpendicular from $P$ to $BC$, so $PF = v$ and $BF = u$. Let $Q$ be the shadow of $P$ on the $xy$-plane, so $PQ = z$. Write $w = QF$ for the length of the shadow of $PF$. The line $BC$ is perpendicular to both $PF$ and the vertical $PQ$, so it is perpendicular to the whole plane $PQF$. In particular $QF \perp BC$, so the angle at $F$ is again $\theta$, and triangle $PQF$ is similar to triangle $AOM$:
$$
z = v \cdot \frac{AO}{AM} = \frac{2v}{\sqrt{6}}, \qquad w = v \cdot \frac{OM}{AM} = \frac{v}{\sqrt{3}}.
$$</p>
<p><strong>Step 3: the shadow.</strong> Now work in the $xy$-plane, where triangle $OBC$ has $45^\circ$ angles at $B$ and $C$. Let $G$ be the point on $BC$ with the same $x$-coordinate as $Q$. Walk along $BC$ from $B$ to $C$:</p>
<ul>
<li>$BF = u$;</li>
<li>$FG = w$, since $QFG$ is an isosceles right triangle;</li>
<li>$GC = \sqrt{2}\,x$, since $G = (x, 1 - x)$ is at distance $x$ from the $y$-axis.</li>
</ul>
<p>The three pieces make up $BC = \sqrt{2}$, so
$$
u + w + \sqrt{2}\,x = \sqrt{2} \quad\Longrightarrow\quad x = \frac{\sqrt{2} - u - v/\sqrt{3}}{\sqrt{2}}.
$$</p>
<p><strong>Step 4: $y$.</strong> $Q$ is at distance $w$ from the line $x + y = 1$, so $x + y = 1 - \sqrt{2}\,w$. That gives
$$
y = 1 - x - \frac{\sqrt{2}\,v}{\sqrt{3}}.
$$
As a check, $z = 2v/\sqrt{6} = \sqrt{2}\,w$, so $x + y + z = 1$.</p>
<p>Altogether,
$$
x = \frac{\sqrt{2} - u - v/\sqrt{3}}{\sqrt{2}}, \qquad
y = 1 - x - \frac{\sqrt{2}\,v}{\sqrt{3}}, \qquad
z = \frac{2v}{\sqrt{6}}.
$$
The triangle itself is $v \ge 0$ together with
$$
v \le \sqrt{3}\,u \quad \text{for } 0 \le u \le \tfrac{\sqrt{2}}{2}, \qquad
v \le \sqrt{6} - \sqrt{3}\,u \quad \text{for } \tfrac{\sqrt{2}}{2} \le u \le \sqrt{2}.
$$
These two conditions are the sides $BA$ and $CA$. These are exactly the formulas and the <code>RegionFunction</code> in my original Mathematica notebook. The map $(u, v) \mapsto (x, y, z)$ is an isometry, since it sends one equilateral triangle of side $\sqrt{2}$ onto another. So the plot shows the simplex at its true shape.</p>
<h3 id="another-way-to-see-it">Another way to see it</h3>
<p>There is also a shortcut that never leaves the plane. Each of $x$, $y$, $z$ is an affine function on the triangle. It is $1$ at its own corner and $0$ along the opposite side, since that whole side lies in the plane where the coordinate vanishes. An affine function that vanishes along a line is proportional to the distance from that line. So each coordinate is the distance from $P$ to the opposite side divided by the altitude $h = \sqrt{6}/2$:
$$
x = \frac{d_B}{h}, \qquad y = \frac{d_C}{h}, \qquad z = \frac{d_A}{h}.
$$
As a bonus, $x + y + z = 1$ becomes $d_A + d_B + d_C = h$. This is Viviani&rsquo;s theorem: from any point inside an equilateral triangle, the distances to the three sides add up to the altitude.</p>
<figure class="simplex-fig">
<svg id="flat-fig" viewBox="0 0 380 350" role="img" aria-label="The simplex laid flat in the u-v plane. Drag the point P to see its distances to the three sides.">
<g class="axis">
<line x1="50" y1="300" x2="360" y2="300" marker-end="url(#fig2-arrow)"/>
<line x1="50" y1="300" x2="50" y2="30" marker-end="url(#fig2-arrow)"/>
</g>
<text x="362" y="318" class="it">u</text>
<text x="36" y="36" class="it">v</text>
<polygon id="ff-tri" points="50,300 318.7,300 184.4,67.3" class="face drag"/>
<line x1="318.7" y1="300" x2="184.4" y2="67.3" class="side s1"/>
<line x1="50" y1="300" x2="184.4" y2="67.3" class="side s2"/>
<line x1="50" y1="300" x2="318.7" y2="300" class="side s3"/>
<line x1="184.4" y1="67.3" x2="184.4" y2="300" class="alt"/>
<text x="188" y="200" class="small">h = √6 / 2</text>
<text x="264" y="176" class="c1 small">√3 u + v = √6</text>
<text x="104" y="176" text-anchor="end" class="c2 small">v = √3 u</text>
<text x="184.4" y="318" text-anchor="middle" class="c3 small">v = 0</text>
<text x="44" y="318" text-anchor="end" class="c1">B</text>
<text x="324" y="318" class="c2">C</text>
<text x="184.4" y="58" text-anchor="middle" class="c3">A</text>
<line id="ff-d1" class="dist s1"/><line id="ff-d2" class="dist s2"/><line id="ff-d3" class="dist s3"/>
<text id="ff-l1" class="c1 it" text-anchor="middle">d<tspan dy="4" font-size="11">B</tspan></text>
<text id="ff-l2" class="c2 it" text-anchor="middle">d<tspan dy="4" font-size="11">C</tspan></text>
<text id="ff-l3" class="c3 it" text-anchor="middle">d<tspan dy="4" font-size="11">A</tspan></text>
<circle id="ff-hit" r="16" class="hit drag"/>
<circle id="ff-p" r="5" class="pt drag"/>
<text id="ff-pl" class="it" pointer-events="none">P</text>
<defs><marker id="fig2-arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="#333"/></marker></defs>
</svg>
<table class="ff-read">
<thead><tr><th>corner</th><th>distance to opposite side</th><th>coordinate</th></tr></thead>
<tbody>
<tr class="c1"><td>B</td><td id="ff-v1"></td><td id="ff-q1"></td></tr>
<tr class="c2"><td>C</td><td id="ff-v2"></td><td id="ff-q2"></td></tr>
<tr class="c3"><td>A</td><td id="ff-v3"></td><td id="ff-q3"></td></tr>
<tr class="sum"><td>sum</td><td id="ff-vs"></td><td id="ff-qs"></td></tr>
</tbody>
</table>
<figcaption>Figure 2. The same triangle, laid flat with $B$ at the origin. Drag $P$ or tap anywhere in the triangle. Each side has the color of the corner opposite it. The three distances always add up to $h$, so $x + y + z = 1$. Current point: <span id="ff-uv"></span>.</figcaption>
</figure>
<style>
.simplex-fig { margin: 1.5em auto; max-width: 460px; }
.simplex-fig svg { display: block; width: 100%; height: auto; overflow: visible; }
.simplex-fig text { font-family: inherit; font-size: 14px; fill: #222; }
.simplex-fig text.it, .simplex-fig .lbl-p { font-style: italic; }
.simplex-fig text.small { font-size: 12px; fill: #555; }
.simplex-fig .axis line { stroke: #777; stroke-width: 1; }
.simplex-fig .axis line.hidden { stroke-dasharray: 3 3; stroke: #aaa; }
.simplex-fig .face { fill: #e8eef4; fill-opacity: 0.85; stroke: #334; stroke-width: 1.3; stroke-linejoin: round; }
.simplex-fig .uv line { stroke: #333; stroke-width: 1.3; }
.simplex-fig .pt { fill: #111; }
.simplex-fig .hit { fill: transparent; }
.simplex-fig .drag { cursor: grab; touch-action: none; }
.simplex-fig .side { stroke-width: 2.5; stroke-linecap: round; }
.simplex-fig .dist { stroke-width: 2; stroke-dasharray: 5 3; }
.simplex-fig .alt { stroke: #888; stroke-width: 1; stroke-dasharray: 2 3; }
.simplex-fig .s1 { stroke: #1f6fb2; } .simplex-fig .c1, .simplex-fig text.c1 { color: #1f6fb2; fill: #1f6fb2; }
.simplex-fig .s2 { stroke: #c96a12; } .simplex-fig .c2, .simplex-fig text.c2 { color: #b35d0e; fill: #b35d0e; }
.simplex-fig .s3 { stroke: #a3336d; } .simplex-fig .c3, .simplex-fig text.c3 { color: #a3336d; fill: #a3336d; }
.simplex-fig figcaption { font-size: 0.9em; color: #555; margin-top: 0.6em; }
.ff-read { margin: 0.8em auto 0; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.ff-read th, .ff-read td { padding: 2px 12px; text-align: right; }
.ff-read th { font-weight: normal; color: #555; font-size: 0.9em; border-bottom: 1px solid #ccc; }
.ff-read td:first-child { text-align: left; }
.ff-read tr.sum td { border-top: 1px solid #ccc; color: #222; }
</style>
<script>
(function () {
  var svg = document.getElementById("flat-fig");
  if (!svg) return;
  var S = 190, AX = 50, AY = 300;
  var r3 = Math.sqrt(3), r6 = Math.sqrt(6), h = r6 / 2;
  var V = [[0, 0], [Math.SQRT2, 0], [1 / Math.SQRT2, r6 / 2]];
  // side opposite corner i: 1 -> BC, 2 -> AC, 3 -> AB
  var SIDE = [[V[1], V[2]], [V[0], V[2]], [V[0], V[1]]];
  function scr(q) { return [AX + S * q[0], AY - S * q[1]]; }
  function probs(u, v) { return [(r6 - r3 * u - v) / r6, (r3 * u - v) / r6, 2 * v / r6]; }
  function fromProbs(p) { var v = p[2] * r6 / 2; return [(p[1] * r6 + v) / r3, v]; }
  function foot(P, A, B) {
    var dx = B[0] - A[0], dy = B[1] - A[1];
    var t = ((P[0] - A[0]) * dx + (P[1] - A[1]) * dy) / (dx * dx + dy * dy);
    return [A[0] + t * dx, A[1] + t * dy];
  }
  function $(id) { return document.getElementById(id); }
  function set(el, a) { for (var k in a) el.setAttribute(k, a[k]); }
  var cur = fromProbs([0.5, 0.3, 0.2]);
  function draw() {
    var u = cur[0], v = cur[1], p = probs(u, v), Ps = scr(cur), dsum = 0;
    set($("ff-p"), { cx: Ps[0], cy: Ps[1] });
    set($("ff-hit"), { cx: Ps[0], cy: Ps[1] });
    set($("ff-pl"), { x: Ps[0] + 8, y: Ps[1] - 8 });
    for (var i = 0; i < 3; i++) {
      var F = foot(cur, SIDE[i][0], SIDE[i][1]), Fs = scr(F);
      var d = Math.hypot(F[0] - u, F[1] - v);
      dsum += d;
      set($("ff-d" + (i + 1)), { x1: Ps[0], y1: Ps[1], x2: Fs[0], y2: Fs[1] });
      var mx = (Ps[0] + Fs[0]) / 2, my = (Ps[1] + Fs[1]) / 2;
      var nx = -(Fs[1] - Ps[1]), ny = Fs[0] - Ps[0], nl = Math.hypot(nx, ny) || 1;
      set($("ff-l" + (i + 1)), { x: mx + 15 * nx / nl, y: my + 15 * ny / nl + 4 });
      $("ff-l" + (i + 1)).style.visibility = d * S < 18 ? "hidden" : "visible";
      $("ff-v" + (i + 1)).textContent = "d" + "BCA"[i] + " = " + d.toFixed(3);
      $("ff-q" + (i + 1)).textContent = "xyz"[i] + " = d" + "BCA"[i] + "/h = " + p[i].toFixed(3);
    }
    $("ff-vs").textContent = dsum.toFixed(3) + " = h";
    $("ff-qs").textContent = (p[0] + p[1] + p[2]).toFixed(3);
    $("ff-uv").textContent = "(u, v) = (" + u.toFixed(3) + ", " + v.toFixed(3) + ")";
  }
  function moveTo(evt) {
    var pt = svg.createSVGPoint(); pt.x = evt.clientX; pt.y = evt.clientY;
    var q = pt.matrixTransform(svg.getScreenCTM().inverse());
    var p = probs((q.x - AX) / S, (AY - q.y) / S).map(function (x) { return Math.max(0, x); });
    var s = p[0] + p[1] + p[2];
    cur = fromProbs(p.map(function (x) { return x / s; }));
    draw();
  }
  var dragging = false;
  svg.addEventListener("pointerdown", function (e) {
    if (!e.target.classList.contains("drag")) return;
    dragging = true; svg.setPointerCapture(e.pointerId); moveTo(e); e.preventDefault();
  });
  svg.addEventListener("pointermove", function (e) { if (dragging) moveTo(e); });
  svg.addEventListener("pointerup", function () { dragging = false; });
  svg.addEventListener("pointercancel", function () { dragging = false; });
  draw();
})();
</script>
<p>In Figure 2 the three sides lie on the lines $v = 0$ (side $BC$), $v = \sqrt{3}\,u$ (side $BA$) and $\sqrt{3}\,u + v = \sqrt{6}$ (side $CA$). The point-to-line distance formula gives
$$
d_A = v, \qquad d_C = \frac{\sqrt{3}\,u - v}{2}, \qquad d_B = \frac{\sqrt{6} - \sqrt{3}\,u - v}{2},
$$
and dividing by $h$,
$$
x = \frac{\sqrt{6} - \sqrt{3}\,u - v}{\sqrt{6}}, \qquad
y = \frac{\sqrt{3}\,u - v}{\sqrt{6}}, \qquad
z = \frac{2v}{\sqrt{6}}.
$$
This is the same map as before, written symmetrically. The interactive plot at the top uses the same idea in the forward direction. It places the corners $V_1, V_2, V_3$ of an equilateral triangle and sends $(p_1, p_2, p_3) \mapsto p_1 V_1 + p_2 V_2 + p_3 V_3$.</p>
<h2 id="what-to-look-for">What to look for</h2>
<p><strong>The corners are at zero.</strong> A distribution with all its mass on one outcome has no uncertainty.</p>
<p><strong>The edges are the binary entropy curve.</strong> On the edge $p_3 = 0$ we are back to a coin, and
$$
H(p, 1-p, 0) = h(p) = -p\log_2 p - (1-p)\log_2(1-p).
$$
The orange curves in the plot are three copies of $h$. Each peaks at 1 bit at the midpoint of its edge.</p>
<p><strong>The top is at $\log_2 3$.</strong> By Jensen&rsquo;s inequality applied to the concave function $\log_2$,
$$
H = \sum_i p_i \log_2 \frac{1}{p_i} \le \log_2 \sum_i p_i \cdot \frac{1}{p_i} = \log_2 3 \approx 1.585,
$$
with equality exactly at the uniform distribution $(\tfrac13, \tfrac13, \tfrac13)$.</p>
<p><strong>The contours are convex.</strong> $H$ is concave, so each super-level set $\{H \ge c\}$ is convex. The contour lines are nested convex curves around the peak. The heavy contour at $H = 1$ is a nice one: it touches the boundary at exactly the three edge midpoints, because 1 bit is the most any single edge can reach.</p>
<p><strong>The walls are vertical.</strong> Start on the edge $p_3 = 0$ and move a small amount $t$ inward, taking $t/2$ from each of $p_1$ and $p_2$. The first-order change in $H$ is
$$
t\left(\tfrac12\log_2 p_1 + \tfrac12\log_2 p_2 - \log_2 t\right) + O(t),
$$
and the $-t\log_2 t$ term dominates. The slope $\log_2(1/t)$ blows up as $t \to 0$. Adding even a tiny chance of a third outcome raises the uncertainty very fast. In the side view the surface meets the boundary with a vertical tangent.</p>
<h2 id="a-printed-copy">A printed copy</h2>
<p>The surface also exists as a physical object. I 3D-printed it, and it stands on its three corners, the pure distributions where $H = 0$.</p>
<figure class="print-fig">
<img src="/demos/ternary-entropy/photos/printed-front.jpg" alt="3D print of the entropy surface seen from the side: a white dome standing on three thin legs" width="750" height="1000" loading="lazy">
<img src="/demos/ternary-entropy/photos/printed-corner.jpg" alt="The same print seen from one corner, showing the three legs and the rounded top at the uniform distribution" width="750" height="1000" loading="lazy">
<figcaption>The printed surface, seen from the middle of an edge (left) and from a corner (right).</figcaption>
</figure>
<style>
.print-fig { margin: 1.5em 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.print-fig img { width: 100%; height: auto; display: block; border-radius: 3px; }
.print-fig figcaption { grid-column: 1 / -1; font-size: 0.9em; color: #555; }
</style>
<p>The needle-sharp legs are the vertical walls from above. Along an edge, near a corner, the height is $h(p) \approx p \log_2 (1/p)$, whose slope blows up as $p \to 0$. So each edge curve comes down to the table vertically, and the three legs taper to points.</p>
<p><strong>Print your own.</strong> Download <a href="/demos/ternary-entropy/entropy-surface.stl"><code>entropy-surface.stl</code></a> (binary STL, 4.9 MB). It is generated directly from the formula, so the heights are exact everywhere, including along all three edges. It is a closed shell in millimetres: 100 mm along each edge of the base, 112 mm tall, with a 1.2 mm wall that tapers to a point at the three tips. Scale it freely in your slicer. The <a href="https://github.com/xiangyazi24/3D-Entropy-Function-Plot/tree/main/stl">generator script</a> can make other sizes and wall thicknesses.</p>
<h2 id="why-redraw-it">Why redraw it</h2>
<p>I first drew this in Mathematica with <code>ParametricPlot3D</code> over a rectangle in $(u,v)$, cut down to the triangle with <code>RegionFunction</code>. The picture was never quite right. Clipping a square grid leaves a ragged edge, the vertical walls come out faceted, and a rainbow color map hides where the surface is actually high.</p>
<p>The version above uses a triangular grid laid out in the $p_i$ themselves, so the boundary is exact. Color, contours and lighting are computed per pixel from the formula and its exact gradient, so the steep walls stay smooth. Color runs from dark (certain) to light (uncertain). The faint grid marks $p_i = 0.1, 0.2, \ldots$, and the floor repeats the contours as a flat ternary diagram.</p>
<p>The code is on <a href="https://github.com/xiangyazi24/3D-Entropy-Function-Plot">GitHub</a>.</p>
        
        ]]>
      </description>
    </item>
    
    
    
    <item>
      <title>The Sequence That Describes Itself: Golomb, Golden Ratios, and an ODE That Won&#39;t Be Tamed</title>
      <link>https://xianghuang.org/math/golomb-sequence/</link>
      <pubDate>Sun, 29 Mar 2026 00:00:00 +0000</pubDate>
      <author>Xiang Huang</author>
      <guid>https://xianghuang.org/math/golomb-sequence/</guid>
      <description>
        <![CDATA[
        <p><em>Some objects in mathematics contain themselves. The Cantor set is made of smaller Cantor sets. The Mandelbrot set has little Mandelbrot sets nested inside it. And then there is the Golomb sequence — a sequence that, in a very precise sense, is its own description.</em></p>
<h2 id="a-sequence-that-encodes-itself">A Sequence That Encodes Itself</h2>
<p>Here is a list: 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, &hellip;</p>
<p>Look at it for a moment. There is one 1, two 2s, two 3s, three 4s, three 5s, four 6s, four 7s, four 8s, four 9s, and so on. The count of how many times the number $n$ appears in the sequence is itself the $n$-th term of the sequence.</p>
<p>That is not a coincidence. That is the definition.</p>
<div class="definition">
<p><strong>Definition (Golomb Sequence).</strong> The <em>Golomb sequence</em> $a(1), a(2), a(3), \ldots$ is the unique nondecreasing sequence of positive integers such that for every $n \geq 1$, the value $n$ appears exactly $a(n)$ times in the sequence, with $a(1) = 1$.</p>
</div>
<p>The first few values:</p>
<table>
  <thead>
      <tr>
          <th style="text-align: center">$n$</th>
          <th style="text-align: center">1</th>
          <th style="text-align: center">2</th>
          <th style="text-align: center">3</th>
          <th style="text-align: center">4</th>
          <th style="text-align: center">5</th>
          <th style="text-align: center">6</th>
          <th style="text-align: center">7</th>
          <th style="text-align: center">8</th>
          <th style="text-align: center">9</th>
          <th style="text-align: center">10</th>
          <th style="text-align: center">11</th>
          <th style="text-align: center">12</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td style="text-align: center">$a(n)$</td>
          <td style="text-align: center">1</td>
          <td style="text-align: center">2</td>
          <td style="text-align: center">2</td>
          <td style="text-align: center">3</td>
          <td style="text-align: center">3</td>
          <td style="text-align: center">4</td>
          <td style="text-align: center">4</td>
          <td style="text-align: center">4</td>
          <td style="text-align: center">5</td>
          <td style="text-align: center">5</td>
          <td style="text-align: center">5</td>
          <td style="text-align: center">6</td>
      </tr>
  </tbody>
</table>
<p>Why does such a sequence exist? And why is it unique? The answer is structural. Any nondecreasing sequence satisfying the self-describing property must grow slowly enough that the number of appearances of $n$ (which is $a(n)$) never &ldquo;outruns&rdquo; $n$ itself. The sequence grows roughly like $n^{0.618}$, which is sublinear — slow enough to be self-consistent. If you tried to build a self-describing sequence that grew faster, it would eventually require more copies of $n$ than there are positions available; slower, and it would run out of terms to use. The Golomb sequence is the unique fixed point of this constraint.</p>
<p>There is also a beautiful way to think about the structure: the sequence is its own <em>run-length encoding</em>. A &ldquo;run&rdquo; is a maximal block of equal values. The run of 4s has length $a(4) = 3$. The run of 6s has length $a(6) = 4$. In general, the run of $n$s has length $a(n)$. And since the runs are blocks of increasing integers, the sequence of run lengths is exactly the sequence itself. It encodes itself.</p>
<h2 id="the-recurrence-and-an-independent-derivation">The Recurrence, and an Independent Derivation</h2>
<p>The self-describing property is beautiful, but it is not directly a formula. How do you actually <em>compute</em> $a(n+1)$ from earlier values? The key result is <strong>Mallows&rsquo;s recurrence</strong>:</p>
<div class="theorem">
<p><strong>Theorem (Mallows&rsquo;s Recurrence).</strong> The Golomb sequence satisfies</p>
<div>$$a(1) = 1, \qquad a(n+1) = 1 + a\!\left(n + 1 - a(a(n))\right) \quad \text{for } n \geq 1.$$</div>
</div>
<p>This formula looks intimidating at first — it has $a$ applied three levels deep. But the logic is elegant once you see it.</p>
<p>The key structural fact is that <strong>consecutive run lengths differ by at most 1</strong>. Here is why: the run of $n$s has length $a(n)$, and the run of $(n+1)$s has length $a(n+1)$. Since $a$ is nondecreasing and increases by at most 1 at each step, consecutive values of $a$ on consecutive integers can differ by at most 1.</p>
<p>Now, consider position $n$ and position $n+1$ in the sequence. There are two cases.</p>
<p><strong>Case 1:</strong> $a(n+1) = a(n)$. Positions $n$ and $n+1$ are in the same run. The value $a(n)$ appears exactly $a(a(n))$ times — that is the run length. So the run started $a(a(n))$ positions earlier. Subtracting $a(a(n))$ from $n+1$ lands us exactly at the start of the <em>previous</em> run. And the value there is $a(n) - 1 = a(n+1) - 1$, so adding 1 gives $a(n+1)$.</p>
<p><strong>Case 2:</strong> $a(n+1) = a(n) + 1$. Position $n$ is the last element of its run, and $n+1$ is the first element of the next. The run ending at position $n$ has length $a(a(n))$, so $n - a(a(n)) + 1$ is the start of that run. Then $n + 1 - a(a(n))$ is in the run <em>before</em> that — the value there is $a(n+1) - 1$, and adding 1 recovers $a(n+1)$.</p>
<p>In both cases: step back by the current run length, land in the previous run, add 1. That is the recurrence.</p>
<p>It&rsquo;s satisfying to independently derive this formula — working through the same case analysis from scratch, with a proof organized around these two cases. The argument is natural once you internalize the run structure; and there is something pleasing about reconstructing classical mathematics by following the logic wherever it leads rather than looking up the answer.</p>
<p>Let us verify with small values. Using $a(a(1)) = a(1) = 1$:</p>
<ul>
<li>$a(2) = 1 + a(2 - 1) = 1 + a(1) = 2.$ ✓</li>
<li>$a(3) = 1 + a(3 - a(a(2))) = 1 + a(3 - 2) = 1 + a(1) = 2.$ ✓</li>
<li>$a(4) = 1 + a(4 - a(a(3))) = 1 + a(4 - 2) = 1 + a(2) = 3.$ ✓</li>
<li>$a(5) = 1 + a(5 - a(a(4))) = 1 + a(5 - 3) = 1 + a(2) = 3.$ ✓</li>
</ul>
<p>The recurrence works. But it is a deeply <em>unusual</em> recurrence — computing $a(n+1)$ requires knowing $a$ at a position that depends on the sequence itself. It is self-referential all the way down.</p>
<h2 id="the-continuous-analogue-an-ode-appears">The Continuous Analogue: An ODE Appears</h2>
<p>Sequences are discrete, but analysis is continuous. Can we understand the long-run behavior of $a(n)$ by finding a smooth function that approximates it?</p>
<p>Let $f: [1, \infty) \to [1, \infty)$ be a smooth, increasing function approximating $a$. What equation should it satisfy?</p>
<p>Here is the key: the self-describing property says the value $n$ forms a run of length $a(n) \approx f(n)$. At position $m$ where $f(m) \approx n$, the value $n$ persists for about $f(n) \approx f(f(m))$ steps before increasing by 1. So the <em>rate of change</em> of $f$ at position $m$ is approximately 1 divided by the run length:</p>
<div>$$f'(m) \approx \frac{1}{f(f(m))}.$$</div>
<p>Taking the limit, the natural continuous analogue of the Golomb sequence satisfies the <strong>functional-differential equation</strong>:</p>
<div class="theorem">
<p><strong>The Golomb ODE.</strong></p>
<div>$$f'(t) = \frac{1}{f(f(t))}$$</div>
</div>
<div class="remark">
<p>This equation is genuinely exotic. It is not an ODE in the usual sense — the right-hand side depends on $f$ evaluated at $f(t)$, which is a <em>different</em> point from $t$. This makes it a functional-differential equation (more specifically, an equation with state-dependent functional composition). Such equations were studied by McKiernan in 1957, and later systematically in the context of the Golomb sequence by Pétermann and Rémy (1998, 1999).</p>
</div>
<p>The ODE has a natural interpretation: when $f(t)$ is large, $f(f(t))$ is much larger, so $f&rsquo;(t)$ is very small. The sequence grows, but it slows down as it grows. This is qualitatively right — $a(n)$ is much less than $n$ for large $n$.</p>
<h2 id="the-golden-ratio-emerges">The Golden Ratio Emerges</h2>
<p>Here is where the analysis gets beautiful. Let us ask a simple question: does the ODE admit power-law solutions?</p>
<p>This is a standard technique for equations with scaling symmetry — try $f(t) = A t^\alpha$ and see what constraints arise. No prior knowledge of the answer is needed; we just substitute and see what happens.</p>
<p><strong>Left side:</strong> $f&rsquo;(t) = A \alpha , t^{\alpha - 1}.$</p>
<p><strong>Right side:</strong> First, $f(t) = A t^\alpha$, so $f(f(t)) = f(A t^\alpha) = A (A t^\alpha)^\alpha = A^{1+\alpha} t^{\alpha^2}.$ Then:</p>
<div>$$\frac{1}{f(f(t))} = \frac{1}{A^{1+\alpha} t^{\alpha^2}}.$$</div>
<p>Setting left equal to right:</p>
<div>$$A \alpha \, t^{\alpha - 1} = \frac{1}{A^{1+\alpha} \, t^{\alpha^2}}.$$</div>
<p>For this to hold for <em>all</em> $t &gt; 0$, the powers of $t$ on both sides must match:</p>
<div>$$\alpha - 1 = -\alpha^2 \qquad \implies \qquad \alpha^2 + \alpha - 1 = 0.$$</div>
<p>Stop. Look at that equation. The positive root is:</p>
<div>$$\alpha = \frac{-1 + \sqrt{5}}{2} = \varphi - 1 \approx 0.618$$</div>
<p>where $\varphi = \frac{1+\sqrt{5}}{2}$ is the golden ratio. The negative root, $\alpha = -\varphi$, gives a decreasing function and is ruled out since $a(n)$ is increasing.</p>
<p>This is the golden ratio appearing not from any deliberate construction, but from a balance of forces — the derivative (exponent $\alpha - 1$) versus the self-composition (exponent $\alpha^2$) in the ODE. The equation $\alpha^2 + \alpha = 1$ is nothing other than the characteristic property of the golden ratio: $\varphi^2 = \varphi + 1$.</p>
<p><strong>The coefficient $A$.</strong> Once we know $\alpha = \varphi - 1$, the coefficient condition $A^{2+\alpha} \alpha = 1$ gives, after simplification using golden ratio identities ($\varphi^2 = \varphi + 1$, $1/\varphi = \varphi - 1$):</p>
<div>$$A = \varphi^{2 - \varphi} \approx 1.2018.$$</div>
<div class="theorem">
<p><strong>Theorem (Marcus–Fine; Vardi 1992).</strong> The Golomb sequence satisfies:</p>
<div>$$a(n) = \varphi^{2-\varphi} \, n^{\varphi - 1} + O\!\left(\frac{n^{\varphi-1}}{\log n}\right)$$</div>
where $\varphi = \frac{1+\sqrt{5}}{2}$ is the golden ratio.
</div>
<div class="remark">
<p>In Fibonacci sequences, $\varphi$ appears as the growth rate of a <em>linear</em> recurrence. This recurrence takes the form of adding the previous two terms.</p>
<p>Specifically, the sequence is given by the rule where the $n$-th term equals the sum of the previous two terms. The characteristic equation is $x^2 = x + 1$.</p>
<p>Here, $\varphi$ appears through a fundamentally different mechanism: the <em>nonlinear self-reference</em> of functional composition in the ODE. Same number, completely different reason.</p>
</div>
<h2 id="the-fixed-point-is-varphi-itself">The Fixed Point Is $\varphi$ Itself</h2>
<p>There is yet another way $\varphi$ appears, which I find even more striking.</p>
<p>Ask: at what point $p$ does the scaling solution satisfy the condition that its value equals its argument?</p>
<p>For the scaling solution $f(t) = \varphi^{2-\varphi} t^{\varphi - 1}$, we are looking for a <em>fixed point</em>.</p>
<p>Setting $\varphi^{2-\varphi} p^{\varphi-1} = p$, we get $p^{2-\varphi} = \varphi^{2-\varphi}$, and so:</p>
<div>$$p = \varphi.$$</div>
<p>The golden ratio is the fixed point of the scaling solution. At $t = \varphi$, the solution passes through the line $y = x$.</p>
<p>Why does this matter? At a fixed point, the self-referential structure of the ODE collapses completely:</p>
<div>$$f(f(\varphi)) = f(\varphi) = \varphi.$$</div>
<p>So the ODE at the fixed point simply reads $f&rsquo;(\varphi) = 1/\varphi$. And indeed, we can check: $f_0&rsquo;(\varphi) = (\varphi - 1) \cdot \varphi^{(2-\varphi) + (\varphi - 2)} = (\varphi - 1) \cdot \varphi^0 = \varphi - 1 = 1/\varphi.$ ✓</p>
<p>The self-reference of the sequence, the power-law growth, and the fixed point — all converge on the same number. $\varphi$ is not incidental here; it is the organizing principle of the entire structure.</p>
<h2 id="why-the-ode-cannot-be-a-polynomial-ode">Why the ODE Cannot Be a Polynomial ODE</h2>
<p>At this point I want to dig into something that connects the Golomb story to a broader question in dynamical systems: <em>can the Golomb ODE be rewritten as a polynomial ODE?</em></p>
<p>In a polynomial ODE $\mathbf{x}&rsquo;(t) = \mathbf{p}(\mathbf{x}(t))$, the right-hand side is a polynomial in the current state $\mathbf{x}(t)$ — everything evaluated at the <em>same</em> time $t$. The Golomb ODE has a fundamentally different structure: the right-hand side $1/f(f(t))$ evaluates $f$ at the point $f(t)$, which is <em>not</em> $t$ (unless we happen to be at a fixed point). This is nonlocal in time.</p>
<p>The answer is: <strong>no</strong>, the Golomb ODE cannot be reduced to any polynomial ODE in finitely many variables. Two approaches show why — and each illuminates the obstruction from a different angle.</p>
<h3 id="approach-1-the-iterated-composition-hierarchy">Approach 1: The Iterated Composition Hierarchy</h3>
<p>Since the ODE says $f&rsquo;(t) = 1/f(f(t))$, define $u(t) = f&rsquo;(t)$. The ODE gives us:</p>
<div>$$f(f(t)) = \frac{1}{u(t)}.$$</div>
<p>Now try to differentiate to get an ODE for $u$. Let $g(t) = f^{\circ n}(t)$ denote the $n$-fold composition.</p>
<p>We have the zeroth composition as simply $t$.</p>
<p>The first composition is $f(t)$.</p>
<p>The second composition is $1/u(t)$.</p>
<p>Differentiating the identity $f(f(t)) = 1/u$:</p>
<div>$$f'(f(t)) \cdot f'(t) = -\frac{u'}{u^2}.$$</div>
<p>Now $f&rsquo;(s) = 1/f(f(s))$ for any $s$. At $s = f(t)$, this gives $f&rsquo;(f(t)) = 1/f(f(f(t))) = 1/g_3(t)$. So:</p>
<div>
<div>$$\frac{u}{g_3} = -\frac{u'}{u^2} \qquad \implies \qquad g_3 = -\frac{u^3}{u'}.$$</div>
</div>
<p>More generally, one can show a recurrence on the iterated compositions. From the chain rule and the ODE applied at each level, the next composition is formed from the previous two:</p>
<div>
<div>$$g_{n+2}(t) = \frac{g_n'(t)}{g_{n+1}'(t)}.$$</div>
</div>
<p>This generates each new composition from the previous two, but at the cost of requiring one additional derivative of $u$. Explicitly:</p>
<ul>
<li>
<p>The second composition is $1/u$ (requires $u$).</p>
</li>
<li>
<p>The third composition is $-u^3/u&rsquo;$ (requires $u, u&rsquo;$).</p>
</li>
<li>
<p>The fourth composition involves $u, u&rsquo;, u&rsquo;&rsquo;$.</p>
</li>
<li>
<p>And so on.</p>
</li>
</ul>
<p>The system is genuinely <em>infinite-dimensional</em>: each composition $g_n$ needs derivatives of $u$ up to order $n-2$, and there is no level at which the hierarchy closes.</p>
<p>One might hope that differentiating the original ODE $f&rsquo; = 1/f(f(t))$ gives a <em>new</em> constraint. But it does not. After differentiating both sides and substituting, we get $f&rsquo;&rsquo; = u&rsquo;$ — which is just $(f&rsquo;)&rsquo; = u&rsquo;$, a pure tautology. Differentiating once captures no new information. The system cannot be reduced.</p>
<div class="remark">
<p>The recurrence above has a faint continued-fraction flavor.</p>
<p>Given that $\varphi$ has the simplest possible continued fraction $[1; 1, 1, 1, \ldots]$, the resonance may be more than coincidental — but tracing this thread rigorously is a different project.</p>
</div>
<h3 id="approach-2-taylor-expansion-at-the-fixed-point">Approach 2: Taylor Expansion at the Fixed Point</h3>
<p>The second approach is more local. At the fixed point $p = \varphi$, the nonlocality of $f(f(t))$ disappears. So let us expand $f$ as a Taylor series around $\varphi$:</p>
<div>
<div>$$f(t) = \varphi + c_1(t - \varphi) + c_2(t - \varphi)^2 + c_3(t - \varphi)^3 + \cdots$$</div>
</div>
<p>We already know the first coefficient is $f&rsquo;(\varphi) = 1/\varphi$.</p>
<p>To find the second coefficient, substitute into the ODE and match terms. With $s = t - \varphi$:</p>
<div>
<div>
<div>$$f(f(t)) = \varphi + c_1^2 s + (c_1 c_2 + c_2 c_1^2) s^2 + O(s^3)$$</div>
</div>
</div>
<p>and</p>
<div>
<div>$$\frac{1}{f(f(t))} = \frac{1}{\varphi} - \frac{c_1^2}{\varphi^2} s + O(s^2).$$</div>
</div>
<p>Matching the coefficient of $s$ with the derivative $f&rsquo;(t)$:</p>
<div>
<div>$$2c_2 = -\frac{c_1^2}{\varphi^2} = -\frac{1}{\varphi^4} \qquad \implies \qquad c_2 = -\frac{1}{2\varphi^4}.$$</div>
</div>
<p>Higher coefficients are recursively computable by the same method.</p>
<p>This is a <em>formal power series solution</em> at the fixed point.</p>
<p>But notice what this gives us: a local power series, recursively defined, with each coefficient depending on all previous ones. It does not give a polynomial ODE — there is no finite system of polynomial equations that $f$ satisfies globally. The Taylor series describes the solution near $\varphi$; the ODE itself remains irreducibly nonlocal.</p>
<div class="remark">
<p>Pétermann and Rémy (1999) proved rigorously that the scaling solution is analytic at its fixed point, confirming that the Taylor expansion converges in a neighborhood of $\varphi$. But the global equation remains non-polynomial.</p>
</div>
<p><strong>The conclusion:</strong> the Golomb ODE is not in the class of polynomial dynamical systems. It is closer to a <em>delay differential equation</em> — except the delay is $f(t)$, which is itself solution-dependent, making it more exotic still. Every attempted reduction produces an infinite hierarchy that refuses to close.</p>
<h2 id="why-analytic-combinatorics-doesn-t-apply">Why Analytic Combinatorics Doesn&rsquo;t Apply</h2>
<p>Given how effective Flajolet and Sedgewick&rsquo;s <em>Analytic Combinatorics</em> framework is for sequences defined by combinatorial recursions, a natural question is: can we attack the Golomb sequence with generating functions?</p>
<p>The short answer is no — for reasons that are themselves illuminating.</p>
<p>The symbolic method requires a <em>combinatorial class</em>: a set of objects with a size function, where objects of size $n$ are built from objects of smaller size in a recursive, decomposable way. The Golomb sequence does not count objects in this sense. It is self-referential: $a(n)$ simultaneously <em>is</em> the multiplicity of $n$ <em>and</em> is determined by the structure of the whole sequence. There is no known decomposition in the Flajolet–Sedgewick sense.</p>
<p>Even if we ignore that and look at the ordinary generating function $F(x) = \sum_{n \geq 1} a(n) x^n$, we run into a wall. The function satisfies the identity:</p>
<div>$$F(x) = \sum_{k \geq 1} x^{a(k)}.$$</div>
<p>This is not a standard functional equation — the values $a(k)$ appear as <em>exponents</em>, not coefficients. And any equation encoding the self-referential recurrence would involve something like $F(F(x))$, a composition of generating functions that is far outside the algebraic/D-finite framework that the symbolic method handles.</p>
<p>The correct analytic framework for the Golomb sequence is the functional-differential equation — not generating functions. The sequence lives in a part of mathematics where the tools of combinatorics and the tools of analysis diverge: it is essentially a dynamical object, not a counting object.</p>
<h2 id="the-connection-to-crn-theory">The Connection to CRN Theory</h2>
<p>In my research on Chemical Reaction Networks (CRNs), systems of chemical reactions — like $A + B \to C$ — give rise to <em>polynomial ODEs</em> via the law of mass-action kinetics. If species $A$ and $B$ combine at rate $k$, the concentration dynamics are governed by $\dot{a} = -k \cdot [A][B]$, a polynomial in the concentrations. The entire class of mass-action systems produces <em>only</em> polynomial ODEs.</p>
<p>This is a rich and powerful class. Polynomial ODEs can compute real-valued functions, simulate arbitrary dynamical systems (under appropriate conditions), and implement analog computation. My work connects CRN computation to analog computing theory, Turing completeness, and even questions in algorithmic randomness.</p>
<p>But the Golomb ODE, $f&rsquo;(t) = 1/f(f(t))$, is demonstrably <em>not</em> in this class. It involves functional composition — evaluating $f$ at $f(t)$ — which polynomial ODEs cannot express. No matter how many auxiliary variables you introduce, the system refuses to close into a finite polynomial system.</p>
<p>This is a genuine boundary. The Golomb sequence comes from a beautifully simple self-describing property, its continuous analogue is a natural ODE, and yet the ODE sits just outside the reach of mass-action CRNs. It is a concrete example of how &ldquo;natural&rdquo; does not always mean &ldquo;polynomial.&rdquo;</p>
<p>There is something philosophically satisfying about this. The Golomb sequence describes itself — it is the fixed point of a self-referential constraint. The Golomb ODE similarly resists being captured — every attempt to pin it down in finite algebraic terms generates an infinite regress. The self-reference runs all the way through.</p>
<h2 id="summary-a-map-of-the-territory">Summary: A Map of the Territory</h2>
<p>Let me collect the main points:</p>
<ul>
<li>The Golomb sequence is the unique nondecreasing sequence where $n$ appears exactly $a(n)$ times — it is its own run-length encoding.</li>
<li>Mallows&rsquo;s recurrence $a(n+1) = 1 + a(n+1 - a(a(n)))$ follows from a case analysis on run transitions. It is self-referential but computable.</li>
<li>The continuous analogue satisfies $f&rsquo;(t) = 1/f(f(t))$, a functional-differential equation.</li>
<li>Substituting the power-law ansatz $f(t) = A t^\alpha$ forces $\alpha^2 + \alpha - 1 = 0$, whose positive root is $\varphi - 1$. The golden ratio emerges from balancing derivative versus self-composition.</li>
<li>The scaling solution has fixed point $p = \varphi$. At this point, the nonlocal ODE becomes local.</li>
<li>The ODE cannot be reduced to a polynomial ODE: the iterated composition hierarchy is infinite-dimensional, the tautology test confirms no finite closure exists, and the Taylor expansion at $\varphi$ is local but not polynomial.</li>
<li>The symbolic method from analytic combinatorics does not apply: the sequence has no natural combinatorial class and its generating function satisfies non-standard functional equations.</li>
<li>The Golomb ODE sits outside the class of polynomial ODEs arising from CRN theory, providing a concrete example of a natural, well-motivated ODE that mass-action kinetics cannot generate.</li>
</ul>
<p>The sequence began as a puzzle — something that describes itself. It ends (at least for now) as a gateway to questions about self-reference in dynamical systems, the limits of polynomial computation, and the unexpected ubiquity of $\varphi$ as an organizing principle.</p>
<hr>
<p><em>References: Golomb (1966), McKiernan (1957), Vardi (1992), Pétermann (1995, 1996), Pétermann–Rémy (1998), Pétermann–Rémy–Vardi (1999, 2001), Flajolet–Sedgewick (2009).</em><div>
8143781437</p>
</div><div>
81437
81437
</div><div>
8143781437
</div>
        
        ]]>
      </description>
    </item>
    
    
    
    <item>
      <title>Fliping $\frac{1}{1-x}$</title>
      <link>https://xianghuang.org/math/flip/</link>
      <pubDate>Sun, 26 Mar 2023 00:00:00 +0000</pubDate>
      <author>Xiang Huang</author>
      <guid>https://xianghuang.org/math/flip/</guid>
      <description>
        <![CDATA[
        <p>I teach Discrete Math every semester. Each time I really want to go deep into generating function, but I can&rsquo;t. So I often tell my students the only generating function they really need to know is this very boring one for $a_n=1$ for  all $n$ $$\frac{1}{1-x}=1+x + x^2 +x^3+\cdots.$$ Today let&rsquo;s have fun playing with it, by, well, just flipping it.</p>
<h2 id="odd-compositions-and-even-compositions">Odd Compositions and Even Compositions</h2>
<p>After flipping $\frac{1}{1-x}$, you will get, obviously,
$$
\frac{1}{\frac{1}{1-x}} =1-x.
$$
Well that is easy and straightforward. How about the other way to write $\frac{1}{1-x}$? We have</p>
<p>\begin{align}
1-x=\frac{1}{\frac{1}{1-x}}&amp;= \frac{1}{1+x+ x^2+ x^3\cdots}\\
&amp;= \frac{1}{1- (-x -x^2 - x^3 -\cdots)}\\
&amp;= 1+ (-x -x^2 - x^3 -\cdots) + (-x -x^2 - x^3 -\cdots)^2 +(-x -x^2 - x^3 -\cdots)^3\cdots
\end{align}</p>
<p>We collect all the similar terms and observe what we get, e.g., $x^5=x^{2 + 3}= x^{3+2}$, the factors are extract from $(-x- x^2 - x^3-\cdots)^2$, where the exponent &ldquo;2&rdquo; means we &ldquo;split&rdquo; our number &ldquo;5&rdquo; into two parts. Note that the order matters $5=2+3=3+2$ are view as two different ways of splitting. This notion of splitting a number into parts is called <a href="https://en.wikipedia.org/wiki/Composition_(combinatorics)">composition</a>.
Further more, we call a composition even (odd) if the composition has even (odd) parts, respectively.</p>
<p><strong>Observation</strong>:</p>
<ul>
<li>Every even composition contributes &ldquo;+1&rdquo; to the coefficient.</li>
<li>Every odd composition contributes &ldquo;-1&rdquo; to the coefficient.</li>
<li>All the coefficient for $x^n$, where $n&gt;2$, vanishes.</li>
</ul>
<p>So the equation
\begin{align}
1-x= 1+ (-x -x^2 - x^3 -\cdots) + (-x -x^2 - x^3 -\cdots)^2 +(-x -x^2 - x^3 -\cdots)^3\cdots
\end{align}
actually says for any $n&gt;2$, there are equal number of even compositions and odd compositions.</p>
<h2 id="another-proof">Another Proof</h2>
<p>We can also proof the above fact by the standard &ldquo;<a href="https://en.wikipedia.org/wiki/Stars_and_bars_(combinatorics)">stars and bars</a>&rdquo; trick. To decompose a number $n$ into $k$ parts, we place $k-1$ bar into the $n-1$ gaps of $n$ stars. Also note that
\begin{equation*}
\sum_{k\ \text{odd}} \binom{n}{k} = \sum_{k\ \text{even}} \binom{n}{k}
\end{equation*}
For $n&gt;=1$.So for $n-1&gt;=1$, i.e., $n&gt;=2$, we have the number of even composition equals to odd composition. The proof of the equation above is yet another question I like to ask my students. You can either prove it <a href="https://math.stackexchange.com/questions/483457/the-number-of-odd-size-subsets-is-equal-to-the-number-of-even-size-subsets">by binomial theorem</a> or by constructing a bijection between the even subsets and odd subsets of $[n]$. I prefer the latter often, especially when I talk about combinatorial proofs.</p>
<h2 id="further-reading">Further Reading</h2>
<p>Composition is not to be confused with partition (order does not matter), which is a more interesting subject. The even partition and the odd partition has a more <a href="https://math.stackexchange.com/questions/92191/identity-involving-partitions-of-even-and-odd-parts">complicated relation</a>. Partition is a fascinating subject in combinations and number theory. I will read/write more about it, just for fun.</p>

        
        ]]>
      </description>
    </item>
    
    
    
    <item>
      <title>Testing Math</title>
      <link>https://xianghuang.org/math/math-test-obs/</link>
      <pubDate>Tue, 14 Mar 2023 00:00:00 +0000</pubDate>
      
      <guid>https://xianghuang.org/math/math-test-obs/</guid>
      <description>
        <![CDATA[
        <p>This page is for testing all kinds of setups I had for math blogging. I now have everything I need to write math in Markdown/HTML!</p>
<h2 id="basic-math-mode">Basic Math Mode</h2>
<p>I am writing my big theorem here with the following wonderful equation</p>
<p>\(\int_a^b f(x) = F(b)-F(a)\)</p>
<p>\begin{equation*}
e^{\pi i} + 1 = 0
\end{equation*}</p>
<p>\begin{equation}
E = mc^2 \label{eq:zhineng} \tag{1}
\end{equation}</p>
<p>\begin{equation}
\int_a^b f(x) = F(b) - F(a)
\end{equation}</p>
<p>It is powerful enough that I can do referencing <sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup>.
I can then write very complicated math (\ref{eq:zhineng}).</p>
<p>Testing mathbb: $\mathbb{1}$</p>
<p>$$
\begin{bmatrix}
a &amp; b \\
c &amp; d \\
e &amp; f \\
\end{bmatrix}
$$</p>
<div class="has-mathjax">


  \begin{bmatrix}
    a & b \\
    c & d \\
    e & f \\
  \end{bmatrix}


</div>

<div class="has-mathjax">

\[
    \begin{bmatrix}
    a & b \\
    c & d \\
    e & f \\
  \end{bmatrix}
\]

</div>

<p>\begin{bmatrix}
a &amp; b \\
c &amp; d \\
e &amp; f \\
\end{bmatrix}</p>
<span class="has-mathjax">
$
    \begin{bmatrix}
    a & b \\
    c & d \\
    e & f \\
  \end{bmatrix}
$
</span>

<div class="has-mathjax">

\[a \ne 0\]

</div>

<h2 id="mathjax-macro">Mathjax Macro</h2>
<p>The following formulas use some macroes. I aslo test cross references and equation tag/numbering.
\[
\f\relax{x} = \int_{-\infty}^\infty
\f\hat\xi,e^{2 \pi i \xi x} \tag{fancy}\label{eq:fancy}
,d\xi
\]</p>
<p>\(x &lt; y\)
\(\frac{x}{y}\)
\begin{align}
a &amp;=b \\
&amp;=c \notag<br>
\end{align}</p>
<p>\begin{align} A &amp; = B \\ &amp; = C \end{align}</p>
<p>\begin{braced} \frac{x}{y} \end{braced}</p>
<p>\begin{ABC}{Z} xyz \end{ABC}</p>
<p><strong>Crossreference:</strong> Here I add a pointer to fancy \eqref{eq:fancy}.</p>
<h2 id="css-theorem-style-and-automatic-theorem-counter">CSS Theorem Style and Automatic Theorem Counter</h2>
<p>I don&rsquo;t really know any CSS or HTML very well. But luckily I manage to make things work! I use different counters for theorems and for definitions.</p>
<div class="theorem mathjax" text='New theorem'>
hahahahhahahahsdf alsjdfljasfdljla asdfjlajsdf
</div> 
<div class="theorem" text='Prime numbers'>
All prime number are odd except 2.
</div>
<div class="proof mathjax">
There are no natural numbers. Xiang is editing this place.
is a natural number greater than 2.   There are no natural numbers $\mathbf{N} = (1, 2, 3, \ldots)$ $x$, $y$, and $z$ such that $x^n + y^n = z^n$, in which $n$ is a natural number greater than 2.
</div>
<div class="definition", text="Big Idea">
Here we define lasdkljflkj asdfljlj.
</div>
<div class="lemma">
Here we proof this very useful lemma.
</div>
<div class="lemma", text='another lemma'>
Here we proof another very useful lemma.
</div>
<div class="obs", text="Big Observation">
Here we proof this very useful observation with x new def.
</div>
<div class="obs mathjax", text="Big Observation2">
  Here we proof this very $$\int_a^b f(x)= F(b) - F(a)$$ observation with x new def.
</div>
<div class="theorem mathjax">
  There are no natural numbers $\mathbf{N} = (1, 2, 3, \ldots)$ $x$, $y$, and $z$ such that $x^n + y^n = z^n$, in which $n$ is a natural number greater than 2. A dollar sign \$.
</div>
<div class="definition mathjax", text="Big Idea">
Here we define lasdkljflkj asdfljlj.
</div>
<div class="proof mathjax">
kjhkasdhf lklasjdflj ljljasd fljl alsdjfl $$\int_a^b f(x)= F(b) - F(a).$$
</div> 
<div class="theorem mathjax" text='Fermat Last Theorem'>
ljasldfj llkjasdf
<p>alsfjdla jsdflljasdfl jals</p>
</div> 
<div class="obs mathjax" >
lajsdlfj
ljalsdfj 
</div> 
<div class="obs mathjax" text='Another Observation'>
lajslfj ljasdlfj l aljsdflj jljasdlf 
</div>  
<p>\begin{align}
A &amp;= B \\
&amp;= C
\end{align}</p>
<p>\begin{gather}
A = B \\
C = D
\end{gather}</p>
<p>$safjljsf$</p>
<p>$$
\int_a^b f(x) = F(b)- F(a)
$$</p>
<div class="lemma mathjax">
adsllljlajsf
lajsdflj
</div> 
<div class="lemma mathjax" text='haha'>
ljal sjfdlajsd flj <strong>ljalsfjd </strong>
</div> 
<div class="theorem mathjax" text='Big Theorem' number="5.5">
My big, important theorem:
$$
  \int f(x) = F(x) + c.
$$
</div> 
<div class="definition mathjax" text='Big Theorem' number="5.5">
My big, important theorem:
$$
  \int f(x) = F(x) + c.
$$
</div> 
<div class="obs mathjax" text='Big Theorem' number="5.5">
My big, important theorem:
$$
  \int f(x) = F(x) + c.
$$
and
$$
  \int_a^b f(x)= F(b) - F(a).
$$
</div> 
<div class="theorem-no-number mathjax" text='Main Theorem'>
    My Main Theorem today without automatic numbering.
</div> 
<p>By doing all the things above. I think I now have a very good webpage template to write math.</p>
<div class="highlight myclass"><div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;display:grid;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;display:grid;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="background-color:#3c3d38"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span></span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="background-color:#3c3d38"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span></span><span style="background-color:#3c3d38"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span></span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;display:grid;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#66d9ef">public</span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Graph</span> {
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex; background-color:#3c3d38"><span>    <span style="color:#66d9ef">private</span> Set<span style="color:#f92672">&lt;</span>Node<span style="color:#f92672">&gt;</span> nodes <span style="color:#f92672">=</span> <span style="color:#66d9ef">new</span> HashSet<span style="color:#f92672">&lt;&gt;</span>();
</span></span><span style="display:flex;"><span>    
</span></span><span style="display:flex; background-color:#3c3d38"><span>    <span style="color:#66d9ef">public</span> <span style="color:#66d9ef">void</span> <span style="color:#a6e22e">addNode</span>(Node nodeA) {
</span></span><span style="display:flex; background-color:#3c3d38"><span>        nodes.<span style="color:#a6e22e">add</span>(nodeA);
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">// getters and setters </span>
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></td></tr></table>
</div>
</div><h2 id="checklists">Checklists</h2>
<p>[ ] a task list item
[ ] list syntax required
[ ] incomplete
[x] completed
[ ] asfdsaf
[ ] asdfsa</p>
<ul>
<li><input disabled="" type="checkbox"> jalsdfj jl</li>
<li><input disabled="" type="checkbox"> aslfjlja</li>
<li><input disabled="" type="checkbox"> asfdlkjaljsdf</li>
<li><input disabled="" type="checkbox"> asdlfjalsjdf</li>
<li><input disabled="" type="checkbox"> alsdfjlajs f</li>
</ul>
<h2 id="tables">Tables</h2>
<p>Sublime Text&rsquo;s Table Editor extension makes editing table very smooth for me.</p>
<table>
  <thead>
      <tr>
          <th>people</th>
          <th>money</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>dlkjsdjf</td>
          <td>ljasjdfljaslfd</td>
      </tr>
      <tr>
          <td>asdfjlajs</td>
          <td>sldkfjalsjf</td>
      </tr>
  </tbody>
</table>
<p>Better table:</p>





<p>| askfdhkajhfd |   colum head   | sadfhkajshdf |    asdfasdfasfdas    |</p>
<table class="table table-striped table-bordered">
  <thead>
      <tr>
          <th>Column 1</th>
          <th></th>
          <th>Column 2</th>
          <th>Column 3</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>fasfdasdf</td>
          <td>asdfjsaflk</td>
          <td>safdasfd</td>
          <td>sfasfdasfd</td>
      </tr>
      <tr>
          <td>asdffsadasdf</td>
          <td>asdfasdf</td>
          <td>sadfasdf</td>
          <td>asdfasd</td>
      </tr>
      <tr>
          <td>asdfasdf</td>
          <td>sadfasd</td>
          <td>asdfasdf</td>
          <td>sadfsadf</td>
      </tr>
      <tr>
          <td>asdfajsldkfj</td>
          <td>asldfjlkj</td>
          <td>alksjdflkaj</td>
          <td>asdfljaslkdfj</td>
      </tr>
      <tr>
          <td>asdfasdfklj</td>
          <td>asjdflkja</td>
          <td>asdfklajsdfl</td>
          <td>aksldfjkaljsdf</td>
      </tr>
      <tr>
          <td>asdfjalksjdf</td>
          <td>asdlfkjalksjdf</td>
          <td>asdfjlasjdf</td>
          <td>sadfljasfkdlasdfasdf</td>
      </tr>
      <tr>
          <td>dsfasfd</td>
          <td>safdasdf</td>
          <td>asdfas</td>
          <td>sadfasdfffasfda</td>
      </tr>
  </tbody>
</table>


<p>| askfdhkajhfd |   colum head   | sadfhkajshdf |    asdfasdfasfdas    |</p>
<table>
  <thead>
      <tr>
          <th>Column 1</th>
          <th></th>
          <th>Column 2</th>
          <th>Column 3</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>fasfdasdf</td>
          <td>asdfjsaflk</td>
          <td>safdasfd</td>
          <td>sfasfdasfd</td>
      </tr>
      <tr>
          <td>asdffsadasdf</td>
          <td>asdfasdf</td>
          <td>sadfasdf</td>
          <td>asdfasd</td>
      </tr>
      <tr>
          <td>asdfasdf</td>
          <td>sadfasd</td>
          <td>asdfasdf</td>
          <td>sadfsadf</td>
      </tr>
      <tr>
          <td>asdfajsldkfj</td>
          <td>asldfjlkj</td>
          <td>alksjdflkaj</td>
          <td>asdfljaslkdfj</td>
      </tr>
      <tr>
          <td>asdfasdfklj</td>
          <td>asjdflkja</td>
          <td>asdfklajsdfl</td>
          <td>aksldfjkaljsdf</td>
      </tr>
      <tr>
          <td>asdfjalksjdf</td>
          <td>asdlfkjalksjdf</td>
          <td>asdfjlasjdf</td>
          <td>sadfljasfkdlasdfasdf</td>
      </tr>
      <tr>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
      </tr>
  </tbody>
</table>
<table>
  <thead>
      <tr>
          <th>sadfkl</th>
          <th>Column 2asdfjalkjs</th>
          <th>adfkalsjdf</th>
          <th>asdjfkha</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Cell 1-1sdkjfhaksjdh</td>
          <td>Cell 1-2asdkjfhkahsdf</td>
          <td>asdfkjhaksjdfh</td>
          <td>kahsdfkha</td>
      </tr>
      <tr>
          <td>Cell 2-1asdkjfhkaj</td>
          <td>Cell 2-2aksjdfhkajshdf</td>
          <td>aksdfhskjdh</td>
          <td>asdfasfasdf</td>
      </tr>
      <tr>
          <td>asfjlkj</td>
          <td>asljdflj</td>
          <td>alsjdflj</td>
          <td>lkjaslfjd</td>
      </tr>
      <tr>
          <td>asdfas</td>
          <td>asdf</td>
          <td>asdf</td>
          <td>asdfsfd</td>
      </tr>
  </tbody>
</table>
<p>add the newest version.
Not Updated on the website?</p>
<h2 id="test-video">Test Video</h2>
<p>Here I plugin a video.</p>
<div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;">
      <iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen" loading="eager" referrerpolicy="strict-origin-when-cross-origin" src="https://www.youtube.com/embed/spUNpyF58BY?autoplay=0&amp;controls=1&amp;end=0&amp;loop=0&amp;mute=0&amp;start=0" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" title="YouTube video"></iframe>
    </div>

<div class="footnotes" role="doc-endnotes">
<hr>
<ol>
<li id="fn:1">
<p>Some footnote here.&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
</ol>
</div>

        
        ]]>
      </description>
    </item>
    
    
  </channel>
</rss>
