Creating Wolfram’s ‘Rule 30’ in Excel with Lambda
Background
Stephen Wolfram’s cellular automaton Rule 30 starts from a scalar – 1 – and with each new iteration checking the bits of the previous iteration, forms a complex pattern resembling certain patterns found in nature.
How can something that simple produce something that complex? It’s been nearly 40 years since I first saw rule 30—but it still amazes me. Long ago it became my personal all-time favorite science discovery, and over the years it’s changed my whole worldview and led me to all sorts of science, technology, philosophy and more.
The Rule Set
p – cell Left of bit being check (If no cell left of the bit checked, default to 0)
q – the bit checked
r – the cell Right of the bit checked (If no cell right of bit checked, default to 0)
The calculation performed on each bit:
XOR(p,OR(q,r))
The formula
I feel no shame in using MAKEARRAY within REDUCE to accomplish this task! The rule set is simple, but the obstacle with Excel is the nature of XOR/OR returning a scalar. I find it easy to ‘check the bits’ by utilizing MAKEARRAY. I toyed with other methods that quickly became contorted and calculated very slowly. I even considered deploying MAKEARRAY recursively (w/o REDUCE) but thought better of it.
Wolfram30
=Lambda(n,LET(
width, n * 2 – 1,
counter, SEQUENCE(n),
iterate, LAMBDA(previous, i,
LET(
pad_with_zero, EXPAND(0, , n – i, 0),
iteration, IF(i = 1, HSTACK(pad_with_zero, i, pad_with_zero), TAKE(previous, -1)),
bitcheck, LAMBDA(row, col,
LET(
start, n + 1 – i,
bits, i * 2 – 1,
end, start + bits,
left, IF(col = 1, 0, INDEX(iteration, , col – 1)),
center, INDEX(iteration, , col),
right, IF(col = width, 0, INDEX(iteration, , col + 1)),
IF(AND(col >= start, col <= end), N(XOR(left, OR(center, right))), 0)
)
),
bit_array, MAKEARRAY(1, width, bitcheck),
next, IF(i = 1, iteration, bit_array),
VSTACK(previous, next)
)
),
DROP(REDUCE(0, counter, iterate), 1)
))
I welcome all formula solutions (PQ, too, if you can pull that off). Please no VBA or AI contributions.
BackgroundStephen Wolfram’s cellular automaton Rule 30 starts from a scalar – 1 – and with each new iteration checking the bits of the previous iteration, forms a complex pattern resembling certain patterns found in nature. How can something that simple produce something that complex? It’s been nearly 40 years since I first saw rule 30—but it still amazes me. Long ago it became my personal all-time favorite science discovery, and over the years it’s changed my whole worldview and led me to all sorts of science, technology, philosophy and more.-Stephen WolframThe Rule Setp – cell Left of bit being check (If no cell left of the bit checked, default to 0)q – the bit checkedr – the cell Right of the bit checked (If no cell right of bit checked, default to 0) The calculation performed on each bit: XOR(p,OR(q,r)) The formulaI feel no shame in using MAKEARRAY within REDUCE to accomplish this task! The rule set is simple, but the obstacle with Excel is the nature of XOR/OR returning a scalar. I find it easy to ‘check the bits’ by utilizing MAKEARRAY. I toyed with other methods that quickly became contorted and calculated very slowly. I even considered deploying MAKEARRAY recursively (w/o REDUCE) but thought better of it.Wolfram30
=Lambda(n,LET(
width, n * 2 – 1,
counter, SEQUENCE(n),
iterate, LAMBDA(previous, i,
LET(
pad_with_zero, EXPAND(0, , n – i, 0),
iteration, IF(i = 1, HSTACK(pad_with_zero, i, pad_with_zero), TAKE(previous, -1)),
bitcheck, LAMBDA(row, col,
LET(
start, n + 1 – i,
bits, i * 2 – 1,
end, start + bits,
left, IF(col = 1, 0, INDEX(iteration, , col – 1)),
center, INDEX(iteration, , col),
right, IF(col = width, 0, INDEX(iteration, , col + 1)),
IF(AND(col >= start, col <= end), N(XOR(left, OR(center, right))), 0)
)
),
bit_array, MAKEARRAY(1, width, bitcheck),
next, IF(i = 1, iteration, bit_array),
VSTACK(previous, next)
)
),
DROP(REDUCE(0, counter, iterate), 1)
)) I welcome all formula solutions (PQ, too, if you can pull that off). Please no VBA or AI contributions. Read More