The Boolean I Ching

The Boolean I Ching

the script

The boolean I Ching displays selected hexagrams in pairs, and the hexagrams resulting from the application of the boolean operators AND, OR, XOR, XNOR, NOT, NAND, NOR, implication, and converse nonimplication.

Boolean algebra is informally applied to I Ching hexagrams during such operations as the transforming of moving lines, or the identification of the correct line in each position (explained some more below).  The basic operations are as follows:

 AND 0 1 0 0 0 1 0 1
 OR 0 1 0 0 1 1 1 1
 XOR 0 1 0 0 1 1 1 0
 XNOR 0 1 0 1 0 1 0 1
 NOT 0 1 1 0

The AND operator results in a value of 1 when both of the inputs are 1.  The OR operator results in a value of 1 when either of the inputs is 1.  The XOR (exclusive-or) operator results in a value of 1 when either, but not both, of the inputs is 1; or in other words, when the inputs are different.  The XNOR operator represents logical equality; it results in a value of 1 when both inputs are the same.  And the NOT operator simply reverses 0 to 1 and vice versa; it is the opposite of logical identity.

Beyond the identification of moving or correct lines, boolean operators can be used to combine individual hexagrams in different ways.  The lines of each hexagram are usually assigned values of 0 for yin and 1 for yang; each hexagram is thus represented as a six-digit binary number.  The operators are applied to the hexagrams via corresponding pairs of digits. I shall list the digits right to left (least to greatest, in binary notation) to represent lines from bottom to top (first to last).  So the combinations of hexagram 6 (111010) and 61 (110011) are as follows:

 111010 AND 110011 110010
 111010 OR 110011 111011
 111010 XOR 110011 001001
 111010 XNOR 110011 110110
 NOT 111010 000101

The XOR operator is how strings of digits are most often combined in fields such as cryptography.  However, the assignment of numeric values to yin and yang is a fairly recent invention.  Moreover, boolean values are actually logical, not numeric; they could just as well be “T” and “F,” or   and  .  (In the I Ching, they are yin and yang.)  The choice of yin=0 and yang=1 is ultimately arbitrary, and the results of the XOR operator differ depending on the choice; if yin=1 and yang=0, the results are reversed.  This is actually the equivalent of an easily-overlooked operator, XNOR or logical equality.  This operator is required if the system is to remain isomorphic with respect to the reversal of the values assigned to yin and yang.  And if you browse through the hexagram combinations and compare XOR with XNOR, you may see some interesting results.  (Try 6 and 7, for example.)  Concerning the other operators, reassigning the values of yin and yang exchanges the outcomes of AND and OR; “yang if either line is yang” is equivalent to “yin if both lines are yin.”  Formally:

a XOR b = NOT (a XNOR b)
a AND b = NOT ((NOT a) OR (NOT b))

This leads to a sixfold symmetry between the operations:

 a — NOT a a AND b — a OR b a XOR b — a XNOR b

A user-friendly way of looking at the results of applying the various operators is as follows:

• yang if the lines are different/changing  (a XOR b)
• yin if the lines are different/changing  (a XNOR b)
• yang if both lines are yang  (a AND b)
• yin if both lines are yin  (a OR b)
• line values reversed  (NOT a)

Note that XOR and XNOR hexagrams form triads; if a XOR b = c, then a XOR c = b, and b XOR c = a.

I have not very often seen the AND and OR operators applied to the I Ching.  They represent the yang, or yin, aspects that two hexagrams have in common.

A number of other boolean operators exist, such as NAND (yin if both lines are yang), NOR (yang if both lines are yin), implication (yin if changing yang), and converse nonimplication (yang if changing yin).  They can all be derived from the basic functions above.

 NAND 0 1 0 1 1 1 1 0
 NOR 0 1 0 1 0 1 0 0
 IF a THEN b 0 1 0 1 1 1 0 1
 NOT a BUT b 0 1 0 0 1 1 0 0

Boolean operators in practice

Changing a hexagram line is the equivalent of the hexagram XOR a 1 in the place of the changing line (which is actually two to the power of the number of the changing line, with the lines numbered 0 to 5).  To change the fouth line of hexagram 6, Sung/Conflict, one applies XOR with 001000:

 111010 XOR 001000 110010

The reversed (as opposed to inverted) hexagrams, or pang tong gua, are the hexagram pairs made by applying NOT to each other, rather than physically turning them upside-down.  What I call the anti-hexagram is similarly the NOT of the transformed hexagram; it is what the situation is “not” changing into, or what is being avoided.

When an I Ching reading includes moving lines, the base hexagram XOR the resulting hexagram consists of the outer pattern of change, and XNOR the inner pattern of change.  Another way of looking at it is that the patterns of change are representations of the moving lines; they are how you get from the base to the resulting hexagram.

Odd-numbered lines are considered correct when they are yang, and even-numbered lines similarly when they are yin.  The hexagram with all correct lines is thus 63 (010101), and the one with all incorrect lines is 64 (101010).  A hexagram’s correctness hexagram may be found by applying XNOR, equality, with hexagram 63, the all-correct hexagram; or by applying XOR with hexagram 64, the all-incorrect one.  Either way, in the result, correct lines are yang, and incorrect ones are yin.

Another type of bitwise operator, the shift operators, shifts the bits of a binary number to the left or right.  These operators are used in mathematical operations and cryptography.  In an ordinary linear shift, bits on the extreme left or right are discarded, and zeroes are added to the other end to fill the empty spaces.  So,

 LEFT SHIFT 1 111010 110100

A circular shift, or bitwise rotation, is more relevant to I Ching hexagrams.  In a circular shift, the discarded bits at the extreme left or right are used to fill in the gap on the other end.  When applied to a hexagram, a circular shift of three bits constitutes a reversal of the trigrams.  Six one-bit shifts rotate the hexagram around and back to the original.  The waxing and waning seasonal cycle of hexagrams consists of a subset of six lines from a circular shift of the hexagram pair Ch’ien/The Creative and K’un/The Receptive (see The Case for Little-Endian).

 LEFT ROTATE 1 111010 110101

The script

Select hexagrams below, and the indicated operation will be applied.

Note—the dropdown boxes used to sometimes freeze up in Firefox.  It was a bug; I don’t think it happens in recent Firefox versions.

 Hexagram a:  1.  Ch’ien / The Creative 2.  K’un / The Receptive yang if changing (a XOR b) yin if changing (a XNOR b) yang if both yang (a AND b) yin if both yin (a OR b) values reversed (NOT a) Hexagram b:  1.  Ch’ien / The Creative 2 . K’un / The Receptive yin if both yang (a NAND b) yang if both yin (a NOR b) yin if changing yang (IF a THEN b) yang if changing yin (NOT a BUT b) rotate a up one line | continue Resulting hexagram: 1. 2. 3. THE JUDGMENT THE JUDGMENT THE JUDGMENT THE LINES THE LINES THE LINES

Please see Andreas Schöter’s articles for a more formal treatment of the subject.

See also Yin-Yang Code:  A Introduction To I-Ching by Ning Lu, Ph.D., and,

On Leibniz and the I-Ching by Sherwin Doroudi.

Chris Lofting discusses some of the above operators, albeit in his own context.

Base 2 or base 4?

Some, especially those who seek parallels between the I Ching and the genetic code, treat hexagram lines as a base 4 system, and use digrams to represent them:

 moving yin 6 yang 7 yin 8 moving yang 9

However, I believe that it is best to consider the lines as a binary, or base 2, system, with an additional bit used to represent whether a line is changing or not.  If the first (rightmost) bit determines the line, and the second determines whether the line is moving, then we have:

 moving yin 10 yang 01 yin 00 moving yang 11

The transformed line is found by applying XOR to the two bits.  Moving yin thus become yang, and yang stays yang, because their bits are different; and yin stays yin, and moving yang become yin, because their bits are the same.  (Digrams could be used to represent this as well, but in this case they are not very intuitive.)

The bits may be more logically represented as one six-digit number representing the base hexagram, and another representing the moving lines; this second hexagram is the outer pattern of change.  The equation below would represent the transformation between the two hexagrams at the top of the page:

 001010 XOR 010010 011000

Geek stuff

Javascript includes several logical operators that apply to ordinary numeric values, and may be familiar to those who have used it:  AND, a && b; OR, a || b; equality, a == b; inequality, a != b; and NOT, !a.  But a more powerful set of operators, called “bitwise operators,” apply their operations to the individual bits (zeroes and ones) of the operands.  This allows I Ching hexagrams to be treated as six-bit binary integers, and compared bit-by-bit.  The operators used here are:

AND:  a & b
OR:  a | b
XOR:  a ^ b
LEFT SHIFT:  a << b

The bitwise NOT operator, ~a, like the other bitwise operators, always treats its operands as signed 32-bit integers, and so is not useful for merely reversing the bits of a six-bit integer.  The way to apply NOT to individual bits is to apply XOR with a value of 1; a XOR 1 is always the reverse of a.  So, in practice,

NOT:  a ^ 111111

There is no javascript operator for bitwise equality, XNOR.  But, thanks to the equivalence relationship above, it may be rendered as the NOT of XOR:

XNOR:  (a ^ b) ^ 111111

Bitwise equality is sometimes called EQV, and Visual Basic 6 included it as an operator (but it is no longer present in VB.NET).  I have called it XNOR, partly because this seems to be an established name in fields other than computer languages, and partly because it recalls its derived nature as NOT XOR.

NAND and NOR are similarly derived from NOT AND and NOT OR:

NAND:  (a & b) ^ 111111
NOR:  (a | b) ^ 111111

Implication and converse nonimplication are derived as (NOT a) OR b, and (NOT a) AND b:

IF a THEN b:  (a ^ 111111) | b
NOT a BUT b:  (a ^ 111111) & b

Bitwise rotation is a little more complicated.  The linear left shift operator moves all six bits of a hexagram number to the left, which is the equivalent of multiplying it by two.  So we need to move that seventh bit to the first position.  The bit is identified by the operation a AND 100000, and converted to 0 or 1 by dividing it by 32.  We apply the shift operation, a LEFT SHIFT 1, and then remove the seventh bit by applying AND 111111 to the result.  Finally, this result OR the leftmost digit identified above gives us the final result:

a LEFT ROTATE 1:  a = ((a << 1) & 111111) | ((a & 100000) / 32)