<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[HUI Philosophy]]></title><description><![CDATA[HUI Philosophy]]></description><link>https://hui-philosophy.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Dec 2026 20:32:41 GMT</lastBuildDate><atom:link href="https://hui-philosophy.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Building a 49-Stalk Yarrow Probability Simulator & 64-Hexagram Archival SVG API on Cloudflare Workers + D1]]></title><description><![CDATA[Most people who know a bit about the I Ching (Zhouyi) think tossing three coins and dividing 49 yarrow stalks are interchangeable ways to generate a 6-bit…]]></description><link>https://hui-philosophy.hashnode.dev/building-a-49-stalk-yarrow-probability-simulator-64-hexagram-archival-svg-api-on-cloudflare-workers-d1</link><guid isPermaLink="true">https://hui-philosophy.hashnode.dev/building-a-49-stalk-yarrow-probability-simulator-64-hexagram-archival-svg-api-on-cloudflare-workers-d1</guid><category><![CDATA[cloudflare]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Math]]></category><category><![CDATA[SVG]]></category><dc:creator><![CDATA[Nancy B Molaser]]></dc:creator><pubDate>Wed, 02 Dec 2026 02:14:08 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6b0f79eca670d7ad8bbe9c4a/d5bcef10-464f-4e49-82ad-ee9b1c77e360.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Most people who know a bit about the <em>I Ching</em> (<em>Zhouyi</em>) think tossing three coins and dividing 49 yarrow stalks are interchangeable ways to generate a 6-bit hexagram.</p>
<p>Mathematically, they aren't even close.</p>
<p>While both methods produce an identical <strong>25% overall probability of a moving line</strong>, three coins follow a symmetric <code>1:3:3:1</code> binomial distribution, whereas the classical 49-stalk <em>Da Yan</em> (大衍筮法) algorithm produces an asymmetric <code>1:5:7:3</code> distribution—making Old Yang (<code>9</code>) <strong>three times more likely</strong> than Old Yin (<code>6</code>).</p>
<p>I wanted a clean, zero-signup place to inspect the modulo-4 math empirically and embed crisp Song-dynasty archival hexagram SVGs without bundling heavy icon packs. So I built <strong>HUI Philosophy</strong> (<a href="https://yijingning.com/en">yijingning.com</a>) on <strong>Cloudflare Workers + D1</strong>, and extracted the core math and SVG utilities into a zero-dependency MIT library (<a href="https://github.com/ningyanhui/iching-yarrow-svg-kit"><code>iching-yarrow-svg-kit</code></a>).</p>
<hr />
<h2>1. Why 49 Stalks Break Symmetry (<code>1:5:7:3</code> vs <code>1:3:3:1</code>)</h2>
<p>In the three-coin method, each toss sums three fair coins (Yin = 2, Yang = 3):</p>
<table>
<thead>
<tr>
<th align="left">Line Value</th>
<th align="left">Archetype</th>
<th align="center">Three Coins</th>
<th align="center">49-Stalk Yarrow</th>
</tr>
</thead>
<tbody><tr>
<td align="left"><strong>6</strong></td>
<td align="left">Old Yin (moving → Yang)</td>
<td align="center"><code>2/16</code> (12.50%)</td>
<td align="center"><code>1/16</code> <strong>(6.25%)</strong></td>
</tr>
<tr>
<td align="left"><strong>7</strong></td>
<td align="left">Young Yang (static)</td>
<td align="center"><code>6/16</code> (37.50%)</td>
<td align="center"><code>5/16</code> <strong>(31.25%)</strong></td>
</tr>
<tr>
<td align="left"><strong>8</strong></td>
<td align="left">Young Yin (static)</td>
<td align="center"><code>6/16</code> (37.50%)</td>
<td align="center"><code>7/16</code> <strong>(43.75%)</strong></td>
</tr>
<tr>
<td align="left"><strong>9</strong></td>
<td align="left">Old Yang (moving → Yin)</td>
<td align="center"><code>2/16</code> (12.50%)</td>
<td align="center"><code>3/16</code> <strong>(18.75%)</strong></td>
</tr>
</tbody></table>
<p>Why does the asymmetry happen?</p>
<ol>
<li><strong>Step 1 starts with 49 stalks</strong>, sets <code>1</code> aside (leaving <strong>48</strong>, which is divisible by 4), splits into two heaps, counts each heap modulo 4 (treating <code>0</code> as <code>4</code>), and sums the remainders plus the set-aside stalk:<ul>
<li>Remainder pairs summing to <code>5</code> (<code>(1,3), (2,2), (3,1)</code>) occur <strong>3/4</strong> of the time.</li>
<li>Only <code>(4,4)</code> sums to <code>9</code>, occurring <strong>1/4</strong> of the time.</li>
</ul>
</li>
<li><strong>Steps 2 and 3 start with 44 or 40 stalks</strong>, set <code>1</code> aside (leaving <code>43</code> or <code>39</code>, which are <code>3 mod 4</code>), so the remainder sum is <code>4</code> <strong>with probability 1/2</strong> and <code>8</code> <strong>with probability 1/2</strong>.</li>
</ol>
<p>Multiplying the three independent steps gives:</p>
<ul>
<li><code>P(9) = 3/4 × 1/2 × 1/2 = 3/16</code> (18.75%)</li>
<li><code>P(6) = 1/4 × 1/2 × 1/2 = 1/16</code> (6.25%)</li>
<li>Total Yang (<code>9 + 7</code>) = <code>3/16 + 5/16 = 50%</code>; Total Yin (<code>6 + 8</code>) = <code>1/16 + 7/16 = 50%</code>.</li>
</ul>
<p>You can run 10,000 live Monte Carlo trials side by side in the browser here:</p>
<ul>
<li><strong>Interactive Simulator</strong>: <a href="https://yijingning.com/tools/yarrow-simulator">https://yijingning.com/tools/yarrow-simulator</a></li>
<li><strong>Full Step-by-Step Math Proof</strong>: <a href="https://yijingning.com/guides/yarrow-stalk-probability">https://yijingning.com/guides/yarrow-stalk-probability</a></li>
</ul>
<hr />
<h2>2. Leibniz, Binary Arithmetic, and the 64-State Lattice</h2>
<p>In 1701–1703, Jesuit missionary Joachim Bouvet sent Gottfried Wilhelm Leibniz the 11th-century Shao Yong <em>Fu Xi 64-Hexagram</em> diagram. Mapping broken Yin lines to <code>0</code> and solid Yang lines to <code>1</code> maps all 64 hexagrams bijectively onto the 6-bit integers <code>0</code> (<code>000000</code> Kun #2) through <code>63</code> (<code>111111</code> Qian #1).</p>
<p>I wrote up the historical correspondence and exact bit mapping in our open guide:</p>
<ul>
<li><strong>Leibniz, Binary Arithmetic &amp; the Fu Xi Sequence</strong>: <a href="https://yijingning.com/guides/leibniz-binary-fu-xi-hexagrams">https://yijingning.com/guides/leibniz-binary-fu-xi-hexagrams</a></li>
</ul>
<hr />
<h2>3. A Zero-Dependency 64-Hexagram Archival SVG API</h2>
<p>For blogs, Notion pages, or study notes, every hexagram is also served directly as a lightweight, cacheable SVG endpoint on Cloudflare Workers:</p>
<pre><code class="language-html">&lt;!-- Hexagram #28 (Da Guo / Great Exceeding), Xuan-paper theme, Line 3 highlighted --&gt;
&lt;img
  src="https://yijingning.com/api/svg/hexagram/28.svg?theme=paper&amp;moving=3"
  alt="Hexagram 28 Da Guo"
  width="116"
/&gt;
</code></pre>
<p>Or dark theme (<code>?theme=dark</code>):</p>
<pre><code class="language-html">&lt;img
  src="https://yijingning.com/api/svg/hexagram/1.svg?theme=dark"
  alt="Hexagram 1 Qian"
  width="116"
/&gt;
</code></pre>
<p>And if you want to embed the math or SVG generator locally in Node/Browser with zero dependencies:</p>
<ul>
<li><strong>GitHub (MIT)</strong>: <a href="https://github.com/ningyanhui/iching-yarrow-svg-kit">https://github.com/ningyanhui/iching-yarrow-svg-kit</a></li>
<li><strong>Interactive SVG Widget</strong>: <a href="https://yijingning.com/tools/hexagram-svg-widget">https://yijingning.com/tools/hexagram-svg-widget</a></li>
</ul>
<hr />
<h2>Architecture Notes (Cloudflare Workers + D1)</h2>
<img src="https://cdn.hashnode.com/uploads/covers/6b0f79eca670d7ad8bbe9c4a/e1121be3-d445-4a91-bf11-cd7e281152a7.jpg" alt="" style="display:block;margin:0 auto" />

<p>Everything runs inside a single Cloudflare Worker (<code>hui-bagua-oracle</code>) backed by Cloudflare D1:</p>
<ul>
<li><strong>192 SSR Encyclopedia Pages</strong> (<code>/hexagrams/*</code>, <code>/zh-tw/gua/*</code>, <code>/zh/gua/*</code>) with trilingual classical Tuan/Daxiang commentaries and <code>Article</code> / <code>FAQPage</code> / <code>BreadcrumbList</code> JSON-LD.</li>
<li><strong>Machine-Readable AI Indexes</strong>: <code>/llms.txt</code> and <code>/llms-full.txt</code> exposing all 64 hexagrams and exact probability tables cleanly for LLM retrieval.</li>
</ul>
<p>Feedback on the simulator UX, SVG parameters, or open-source kit is very welcome!</p>
]]></content:encoded></item></channel></rss>