Back to List

YiMatrix · Academy Journal

An Algorithm Hidden in the I Ching, Three Thousand Years Older Than the Turing Machine

"The number of the Great Expansion is fifty, and its use is forty nine." This line from the I Ching 's "Great Appendix" translates into code as an algorithm with initialization, lo

南荒May 30, 202619 min read
An Algorithm Hidden in the I Ching, Three Thousand Years Older Than the Turing Machine

"The number of the Great Expansion is fifty, and its use is forty-nine."

This sentence is written in the "Great Appendix" of the I Ching.

You may not understand it. That's fine. I'll translate it directly into code that today's programmers can read—first take fifty; leave one unused; divide the remaining forty-nine into two piles; draw one and hold it between fingers; count the remainder in groups of four; repeat this process eighteen times to derive a hexagram.

This is not philosophy.

This is an algorithm written long ago that can still run today.

Below, I measure it with three rulers: history of mathematics, history of computer science, and information encoding. After measuring, you'll find that the person who wrote these words did the same thing as those who later clarified what "computation" means.


I. Decompile It Sentence by Sentence

Let's break down the original text sentence by sentence. Each classical Chinese sentence is paired with a vernacular explanation and then mapped to a code concept.

"The number of the Great Expansion is fifty, and its use is forty-nine."

Fifty yarrow stalks (a type of grass stem, used as a computing tool in ancient times, analogous to beads on an abacus), first set one aside, and use the remaining forty-nine for the divination.

— This is initialization: define a starting value.

"Divide into two to represent the two primal forces."

Randomly split the forty-nine stalks into two piles.

— This splits the state into two, and the state of the entire process begins to change from here.

"Suspend one to represent the three powers."

Draw one stalk from one pile and place it between your fingers.

— A definite action of taking a number.

"Count off by fours to represent the four seasons."

Count each pile in groups of four.

— Perform a modulo operation with step size 4 to see the remainder.

"Place the odd remainder between the fingers to represent the intercalary month."

The leftover stalks after counting—one, two, three, or four—are also placed between the fingers to record.

— Store the remainder in a temporary variable.

"Thus, after two such operations, a line is formed."

One complete round is called a "change." Three changes produce one line (yao), and six lines form a hexagram.

— This is the loop and termination condition: loop eighteen times to accumulate six lines, then stop.

Putting these five sentences together, we get something like this. Even if you don't understand code, it's fine—the left column is the action, and the part after the hash is the corresponding classical sentence, line by line.

init   stalks = 50          # The number of the Great Expansion is fifty
use    stalks = 49          # Its use is forty-nine (leave one unused)
loop 18 times:              # Eighteen changes
    randomly split into two piles  # Divide into two to represent the two primal forces
    draw one and hold between fingers  # Suspend one to represent the three powers
    count remainder in groups of four  # Count off by fours to represent the four seasons
    store remainder          # Place the odd remainder between the fingers to represent the intercalary month
return hexagram formed by six lines  # Thus, after two such operations, a line is formed

See what this has.

It has initialization (fifty). It has state variables (the number of stalks in hand, changing each round). It has a loop (eighteen changes). It has a termination condition (stop when six lines form a hexagram).

Initialization, state variables, loops, termination conditions—these four things are the skeleton of any program.

That text has a complete skeleton.


II. This Is a Turing Machine

The first time I finished reading this, I paused and thought for a long time.

This is not a philosopher expressing a worldview. This is an exact, step-by-step process—given the same starting conditions, follow the same steps, each step has clear rules.

In 1936, British mathematician Alan Turing wrote a paper titled "On Computable Numbers."

In that paper, he first rigorously defined one thing: what kind of process can be executed step by step by a machine and finally yield a result—later called "computable." His standard was clean: a process must have an initial state, a set of transition rules, and a termination condition. If it satisfies these three, it is computable by a machine.

The abstract model he constructed for this was later called the Turing machine.

Every computer and smartphone you use today is essentially an engineering implementation of a Turing machine. What the CPU does, at the lowest level, is "read the current state, follow rules to jump to the next state, until halting."

Now look back at those fifty yarrow stalks.

Initial state—fifty, use forty-nine. Transition rules—divide, suspend, count by fours, place remainder. Termination condition—six lines form a hexagram.

Not a single element is missing.

The Great Expansion is an algorithm that can run on yarrow stalks and human hands—and its executor is the earliest Turing machine.

The timeline makes it even more interesting.

In 1936, Turing used an entire paper to rigorously define what kind of process is computable.

But the ancient author who wrote the "Great Appendix" had no word for "algorithm," no such concept, and no abstract mathematical language to describe what they were doing.

Turing used a paper to clarify what an algorithm is. The ancients didn't clarify it—they just ran it directly.


III. From Taiji to 64 Hexagrams: A Perfect Binary Tree

The I Ching also hides another structure, even more direct and instantly recognizable.

Chapter 11 of the "Great Appendix" says:

"In the I Ching, there is Taiji, which generates the two primal forces. The two primal forces generate the four images. The four images generate the eight trigrams."

Translated into today's terms—

Taiji is one. Two primal forces are two. Four images are four. Eight trigrams are eight.

One becomes two, two becomes four, four becomes eight, each layer multiplies by two. The eight trigrams are then paired with each other, eight times eight, yielding sixty-four hexagrams.

Write out this sequence:

1 → 2 → 4 → 8 → 16 → 32 → 64.

That is 2 to the power of 0, up to 2 to the power of 6. The sixth power corresponds to the six lines of a hexagram.

This is a strict binary tree. Each node splits into two branches—yin or yang, 0 or 1, no third possibility.

All the names you've heard in computer science—binary search, binary heap, Huffman coding—are distant relatives of this tree. When you unlock your phone with facial recognition today, behind it is 0 and 1 splitting layer by layer.

One, two, four, eight, sixteen, thirty-two, sixty-four—this is not just counting; it's a tree growing.

From Taiji to 64 hexagrams: a perfect binary tree

Now back to that "fifty." It wasn't an arbitrary number; there's arithmetic behind it.

Chapter 9 of the "Great Appendix" says that the numbers of heaven (odd: 1, 3, 5, 7, 9) sum to 25, and the numbers of earth (even: 2, 4, 6, 8, 10) sum to 30, totaling 55.

But the divination uses 50—55 minus 5.

I must honestly admit: why subtract exactly 5? The ancients' reason was to treat the five elements as a base layer, left outside the system and not participating in the calculation. This step is a convention, not strictly derived from the number 55.

And from 50 to 49—subtracting one more—this step is clean: the subtracted "one" is the unmoving "Taiji," which as the starting point itself is not included in the calculation.

55, 50, 49—these numbers are not independent; at least the latter half is interlocking. It's an arithmetic problem, not some mystery.


IV. But the I Ching Is Not the Origin of Algorithms

At this point, I must pause and address something easily misunderstood in excitement.

The I Ching is not the origin of today's computer science.

Leibniz, who is often said to have invented binary from the eight trigrams—he independently wrote a binary manuscript in 1679, before he had ever seen any Chinese trigram diagram. He did not learn binary from the trigrams.

It was only in 1703 that he saw the Fuxi sixty-four hexagram diagram and realized that ancient Chinese had written this system long ago. The order is exactly reversed.

Similarly, Turing did not conceive the Turing machine by reading the "Great Appendix." He followed the Western line of mathematical logic at Cambridge and arrived at the question of "what is computable" on his own.

(Regarding that "long ago"—the word-by-word decompilation of the "Great Appendix" was actually written later, mostly between the Warring States period and the early Han dynasty; but it records a divination method that was already in use earlier.)

Two different civilizations, separated by thousands of years, never seeing each other, independently arrived at the same underlying structure.

This is a hundred times more震撼 than saying "the I Ching is the origin."

It's not that one copied the other. It's that whenever humans seriously observe nature and abstract patterns, they will eventually stumble upon the same underlying structure.

A computable world does not distinguish between East and West, ancient or modern. It is there, waiting for different people to approach from different directions and encounter it.


The ancients had no keyboards, no CPUs, no word for "algorithm."

With fifty stalks, they wrote a runnable computation into a book that has never been interrupted for thousands of years—first counting the world, then encoding states, then deducing step by step, and finally restoring it to the phenomena before their eyes.

Today we call this an algorithm. They just looked at the world carefully.


Continue reading

Recommended

Back to List