5D Library › Six-Dimensional Hypercube Walks, Hexagram Mutation Markov Chains and Modular Star-Palace Lattices · 中文

Chapter 2. Yarrow Stalks and Coins: the Exact Odds of the Two Methods

Two methods

Each of the six lines takes one of four values, 6, 7, 8 or 9: 6 is old yin and 9 old yang (moving lines), 7 young yang and 8 young yin (still lines). Tradition has two main ways of casting (Wilhelm 1967; Smith 2008).

The great-expansion yarrow method. Following the Appended Statements and Zhu Xi’s Divination Procedure: of fifty yarrow stalks one is set aside; the forty-nine are divided into two heaps, one stalk from the right heap is hung between the fingers, each heap is counted off by fours, and the remainder (1 to 4; 4 when it divides exactly) is set aside. The stalks removed in the first change (the hung one plus the two remainders) number 5 or 9, in the second and third 4 or 8. After three changes 36, 32, 28 or 24 stalks remain; divided by 4 they give 9, 8, 7 or 6.

The three-coin method. Three coins are thrown, a head counting 3 and a tail 2 (or the reverse); their sum is 6, 7, 8 or 9.

Calculation

The usual analysis of the yarrow method. Assume that each heap’s remainder modulo 4 is equally likely. In the first change the two heaps hold 48 stalks together, so the two remainders add to 4 or 8; adding to 8 needs both heaps divisible by 4, with probability 1/4, so 9 stalks are removed with probability 1/4 and 5 with probability 3/4. In the second and third changes the number of stalks is a multiple of 4 plus 3, the remainders add to 3 or 7, each with probability 1/2. Combining the three changes gives the probability of each line value.

Calculation

# Chapter 2. Yarrow stalks against three coins: the line probabilities.
# Yarrow (Zhu Xi's procedure): of 50 stalks one is set aside; the 49 are
# split in two, one stalk is hung between the fingers, each heap is
# counted off by fours and the remainder (1-4, a remainder of 0 counting
# as 4) is set aside. First change: 1 + remainders = 5 or 9; second and
# third changes: 4 or 8. What is left after three changes is 36, 32, 28
# or 24 stalks = 4 x (9, 8, 7, 6).
# The usual analysis assumes each heap's count mod 4 is equally likely.
# In the first change the two remainders must add to 4 or 8 (48 stalks);
# 8 needs both heaps divisible by 4: probability 1/4. In the later
# changes (39 or 43 stalks, = 3 mod 4) the sum is 3 or 7: 1/2 each.
# Three coins: heads = 3, tails = 2; the sum of three is 6, 7, 8 or 9.
from fractions import Fraction as F
from itertools import product

def yarrow():
    first = {5: F(3, 4), 9: F(1, 4)}
    later = {4: F(1, 2), 8: F(1, 2)}
    out = {}
    for a, b, c in product(first, later, later):
        v = (49 - a - b - c) // 4
        out[v] = out.get(v, 0) + first[a] * later[b] * later[c]
    return out

def coins():
    out = {}
    for faces in product((2, 3), repeat=3):
        out[sum(faces)] = out.get(sum(faces), 0) + F(1, 8)
    return out

if __name__ == "__main__":
    y, c = yarrow(), coins()
    names = {6: "old yin  (6, moving)", 7: "young yang (7)",
             8: "young yin (8)", 9: "old yang (9, moving)"}
    print("   line                    yarrow           coins")
    for v in (6, 7, 8, 9):
        print("   {:22s}  {:>5} = {:.4f}   {:>5} = {:.4f}".format(
            names[v], str(y[v]), float(y[v]), str(c[v]), float(c[v])))
    for label, d in (("yarrow", y), ("coins", c)):
        yang = d[7] + d[9]
        moving = d[6] + d[9]
        after = d[7] + d[6]                    # yang once moving lines flip
        print("   {:6s}: P(yang) = {}, P(moving) = {}, P(yang after change)"
              " = {}".format(label, yang, moving, after))
    print("   yarrow: old yang / old yin = {}".format(y[9] / y[6]))
    print("\nReading: both methods give yang and yin equally often and the")
    print("same chance (1/4) that a line moves. They differ in which lines")
    print("move: with coins old yang and old yin are equally likely; with")
    print("yarrow old yang is three times as likely, so a yang line moves")
    print("more often than a yin line and the changed hexagram leans yin.")
#    line                    yarrow           coins
#    old yin  (6, moving)     1/16 = 0.0625     1/8 = 0.1250
#    young yang (7)           5/16 = 0.3125     3/8 = 0.3750
#    young yin (8)            7/16 = 0.4375     3/8 = 0.3750
#    old yang (9, moving)     3/16 = 0.1875     1/8 = 0.1250
#    yarrow: P(yang) = 1/2, P(moving) = 1/4, P(yang after change) = 3/8
#    coins : P(yang) = 1/2, P(moving) = 1/4, P(yang after change) = 1/2
#    yarrow: old yang / old yin = 3
#
# Reading: both methods give yang and yin equally often and the
# same chance (1/4) that a line moves. They differ in which lines
# move: with coins old yang and old yin are equally likely; with
# yarrow old yang is three times as likely, so a yang line moves
# more often than a yin line and the changed hexagram leans yin.

The two methods agree exactly in three respects: a line is yang with probability 1/2, and a line moves with probability 1/4. They differ in which kind of line moves. With coins old yin and old yang take 1/8 each, perfectly symmetric; with yarrow old yang is 3/16 = 0.1875 and old yin 1/16 = 0.0625, exactly three times. A consequence seldom mentioned follows: with yarrow a yang line changes more readily than a yin line, so the changed hexagram leans yin — a line of the changed hexagram is yang with probability only 3/8, while with coins it remains 1/2.

Probability of each of the four line values: yarrow (plum) and three coins (blue).

“Three times” depends on how the stalks are split

“Equally likely remainders” is an assumption. Hands split the stalks, and the fourth program recomputes the three changes exactly under three ways of splitting: the split position spread evenly over every possible place; each stalk falling left independently with probability 1/2 (binomial); a split close to half (normal weights centred on half with a standard deviation of 3 stalks).

Calculation

# Chapter 2. The yarrow odds without the "equally likely remainder" step.
# p03 assumed that a heap's count is equally likely to be 1, 2, 3 or 0
# mod 4. Real hands split the stalks in a particular way. Here the split
# of n stalks into a left heap L and a right heap n - L (L >= 1, right
# heap >= 2 so that one stalk can be hung from it) follows one of three
# models, and the four line values are computed exactly by running all
# three changes:
#   uniform    every L from 1 to n - 2 equally likely
#   binomial   each stalk falls left or right with probability 1/2
#   near-even  L close to n / 2: weights exp(-(L - n/2)^2 / (2 x 3^2))
import math

def rem(x):
    return x % 4 or 4

def weights(n, model):
    out = {}
    for left in range(1, n - 1):
        if model == "uniform":
            w = 1.0
        elif model == "binomial":
            w = math.comb(n, left)
        else:
            w = math.exp(-(left - n / 2) ** 2 / 18)
        out[left] = w
    z = sum(out.values())
    return {k: v / z for k, v in out.items()}

def change(n, model):
    dist = {}
    for left, w in weights(n, model).items():
        removed = 1 + rem(left) + rem(n - left - 1)
        dist[n - removed] = dist.get(n - removed, 0.0) + w
    return dist

def line_values(model):
    states = {49: 1.0}
    for _ in range(3):
        nxt = {}
        for n, p in states.items():
            for m, q in change(n, model).items():
                nxt[m] = nxt.get(m, 0.0) + p * q
        states = nxt
    return {n // 4: p for n, p in states.items()}

if __name__ == "__main__":
    print("   split        old yin 6  young yang 7  young yin 8"
          "  old yang 9  9 / 6")
    print("   ideal (p03)    0.0625       0.3125       0.4375"
          "      0.1875    3.000")
    for model in ("uniform", "binomial", "near-even"):
        v = line_values(model)
        print("   {:10s}     {:6.4f}       {:6.4f}       {:6.4f}"
              "      {:6.4f}    {:5.3f}".format(
                  model, v[6], v[7], v[8], v[9], v[9] / v[6]))
    print("\nReading: when the hand splits the stalks roughly evenly")
    print("(binomial or near-even) the ideal fractions hold to four decimal")
    print("places and old yang is three times as likely as old yin. A split")
    print("spread evenly over every possible position - not how hands")
    print("divide a bundle - shifts the odds and raises the ratio to about")
    print("4. The 3:1 bias comes from the counting rule, given a natural")
    print("split.")
#    split        old yin 6  young yang 7  young yin 8  old yang 9  9 / 6
#    ideal (p03)    0.0625       0.3125       0.4375      0.1875    3.000
#    uniform        0.0517       0.2887       0.4484      0.2112    4.082
#    binomial       0.0625       0.3125       0.4375      0.1875    3.000
#    near-even      0.0625       0.3125       0.4375      0.1875    3.000
#
# Reading: when the hand splits the stalks roughly evenly
# (binomial or near-even) the ideal fractions hold to four decimal
# places and old yang is three times as likely as old yin. A split
# spread evenly over every possible position - not how hands
# divide a bundle - shifts the odds and raises the ratio to about
# 4. The 3:1 bias comes from the counting rule, given a natural
# split.

With a binomial or near-even split, the four probabilities agree with the ideal values to four decimal places, and the ratio of old yang to old yin is 3.000. If the split position is spread evenly over every place, old yin falls to 0.0517 and old yang rises to 0.2112, a ratio of 4.082. An even spread is not how a hand divides a bundle of stalks, so “three times” holds under natural splitting; but it comes from the counting rule together with the way of splitting, not as a constant independent of it.

What the methods share, and how far apart they are

Calculation

# Chapter 2. What the two methods share and how far apart they are.
# Number of moving lines in a six-line cast: each line moves with
# probability 1/4 under both methods (p03), independently, so the count
# is Binomial(6, 1/4) for both. The methods differ only in WHICH lines
# move. Their distance is measured by the Kullback-Leibler divergence of
# the line values (6, 7, 8, 9), and by how many casts, on average, a
# likelihood-ratio comparison needs before the evidence reaches 100 : 1
# for the method actually used.
import math
from fractions import Fraction as F

Y = {6: F(1, 16), 7: F(5, 16), 8: F(7, 16), 9: F(3, 16)}
C = {6: F(1, 8), 7: F(3, 8), 8: F(3, 8), 9: F(1, 8)}

def kl(p, q):
    return sum(float(p[v]) * math.log(float(p[v]) / float(q[v]))
               for v in p)

if __name__ == "__main__":
    print("   moving lines   probability (both methods)")
    for k in range(7):
        pk = math.comb(6, k) * F(1, 4) ** k * F(3, 4) ** (6 - k)
        print("        {}         {:>9} = {:.4f}".format(k, str(pk),
                                                       float(pk)))
    print("   at least one moving line: {:.4f}".format(
        1 - float(F(3, 4) ** 6)))
    for a, b, p, q in (("yarrow", "coins", Y, C), ("coins", "yarrow", C, Y)):
        d = kl(p, q)
        casts = math.log(100) / (6 * d)
        print("   KL({} || {}) = {:.4f} nats per line; about {:.1f}"
              " casts".format(a, b, d, casts))
    print("\nReading: the number of moving lines - and with it the reading")
    print("rule of Chapter 4 - has the same distribution under both")
    print("methods. The line values differ by about 0.04 nats per line, so")
    print("telling from the casts alone which method produced them takes")
    print("some 17 six-line casts on average.")
#    moving lines   probability (both methods)
#         0          729/4096 = 0.1780
#         1          729/2048 = 0.3560
#         2         1215/4096 = 0.2966
#         3          135/1024 = 0.1318
#         4          135/4096 = 0.0330
#         5            9/2048 = 0.0044
#         6            1/4096 = 0.0002
#    at least one moving line: 0.8220
#    KL(yarrow || coins) = 0.0432 nats per line; about 17.8 casts
#    KL(coins || yarrow) = 0.0465 nats per line; about 16.5 casts
#
# Reading: the number of moving lines - and with it the reading
# rule of Chapter 4 - has the same distribution under both
# methods. The line values differ by about 0.04 nats per line, so
# telling from the casts alone which method produced them takes
# some 17 six-line casts on average.

Under both methods the number of moving lines follows the binomial distribution Bin(6,1/4)\mathrm{Bin}(6, 1/4): no moving line with probability 0.1780, one with 0.3560, all six only 0.0002; at least one with 0.8220. The reading rules of Chapter 4 are classified by the number of moving lines, so each rule is used with the same probability under both methods.

The Kullback-Leibler divergence between the two methods’ line-value distributions is about 0.0432 nats per line. In other words, judging from a record of casts alone which method produced it takes on average about 17.8 six-line casts before the evidence reaches 100 to 1.

Summary

The yarrow and three-coin methods agree exactly in the shares of yin and yang and of moving and still lines; they differ only in which kind of line moves: with coins old yin and old yang are 1/8 each, with yarrow old yang (3/16) is three times old yin (1/16), so the changed hexagram leans yin (3/8 of its lines yang). “Three times” holds to four decimal places under a binomial or near-even split and becomes 4.082 under an evenly spread split. The distribution of moving lines is the same under both methods, and telling them apart from a record takes about 18 casts on average.

References

Smith, Richard J. 2008. Fathoming the Cosmos and Ordering the World: The Yijing (i Ching, or Classic of Changes) and Its Evolution in China. University of Virginia Press.
Wilhelm, Richard. 1967. The i Ching or Book of Changes. 3rd ed. Translated by Cary F. Baynes. Princeton University Press.

Fan, Y. (2026). Six-Dimensional Hypercube Walks, Hexagram Mutation Markov Chains and Modular Star-Palace Lattices: Boolean Cube Spectral Gaps, Yarrow-versus-Coin Probability Biases and Twelve-Palace Dihedral Projections [六维超立方体游走、卦变马尔可夫链与模运算星宫晶格] (Version 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.24090176 · Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).