WOLFRAM’S RULE 60 AND “EXTENDED” ADDITIVITY Stuart Smith stu@cs.uml.edu INTRODUCTION In A New Kind of Science[1] Wolfram showed that his elementary one-dimensional cellular automaton exhibits a property called “additivity” when operating according to one of a small subset of the 256 possible rules that govern the operation of the automaton. Of interest here is Rule 60. With Rule 60, the automaton generates the next row of the Sierpinski triangle on each successive step when the initial contains a single 1 surrounded by zeroes.1 If the initial row contains more than one 1, additivity guarantees that the result—no matter how complex it may appear visually—is simply the element-wise sum (modulo-2)2 of right-shifted instances of the Sierpinski pattern. This paper shows that the additive property of the Sierpinski pattern extends into two dimensions and that any square boolean matrix can be represented as the element-wise sum of instances of the Sierpinski pattern that have been shifted or rotated3 right and/or down. The determination of which instances must be summed to obtain a given boolean matrix is performed by a simple analysis function. An equally simple synthesis function can reconstruct the original matrix from the results of the analysis function THE ELEMENTARY CELLULAR AUTOMATON The elementary cellular automaton is a small program that takes three inputs: a rule, which is the 8-bit binary expansion of an integer in the range 0-255. The rule specifies how the next state of each cell is to be computed from the current state of the cell and the current states of its left and right neighbors. a boolean vector that specifies the initial conditions with which the automaton is to start a computation the number of steps to be executed. The output of each step becomes the input to the next. The following notations have been used to characterize cellular automata: i : the position of an individual cell in the one-dimensional array of cells t : the time step qi (t ) : the output state of the ith cell at the tth time step qi (t 1) : the output of the ith cell at the (t+1)th time step 1 Wolfram places the single 1 in the middle of the initial vector, which allows the automaton to produce patterns that grow to the left as well as to the right. Rule 60 grows only to the right. 2 The additive operation can also be element-wise exclusive-or. 3 The rotations are toroidal, i.e., they wrap around bottom to top and right to left. Shifts are end-off with zero fill. Neither rotations nor shifts cause loss of information in that the initial conditions can be exactly recovered from the automaton’s output. The next-state transition for Rule 60 of Wolfram’s elementary cellular automaton is: qi (t 1) qi1 (t ) qi (t ) Under Rule 60, the next state of each cell is the modulo-2 sum or exclusive-or of its current state and the current state of its left-hand neighbor. Wolfram allows the output to wrap around both from the rightmost cell into the leftmost, and from the leftmost into the rightmost. The output of Rule 60 grows only to the right. THE SIERPINSKI MATRIX The computations described here employ a matrix representation of the Sierpinski triangle4. Fig. 1 is a 4×4 example of the pattern: 1 1 1 1 0 1 0 1 0 0 1 1 0 0 0 1 Figure 1 In this paper boolean matrices are represented as pictures composed entirely of black and white squares. By convention, a black square corresponds to 1, a white square to 0. Fig. 2, for example, is the 16×16 image produced by sixteen steps of Rule 60 starting from the initial conditions 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0. Figure 2 ADDITIVITY Rule 60 is one of eight rules that possess the additive property. For any initial conditions, the patterns produced by Rule 60 are always simple superpositions of some number of shifted5 copies of the basic Sierpinski pattern (e.g., fig. 2) obtained by starting with a single black square. The number of positions to shift each copy is the index of the corresponding 1 in the vector of initial conditions. Thus, for example, if the initial conditions are the vector 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0, the result for Rule 60 There are several ways to generate the Sierpinski matrix. (see, e.g., APPENDIX I). When the copies are rotated, the matrices effectively lie on a torus. In this paper we also touch on the effect of shifting the copies. See In Search of the “World Formula”[2] for a discussion of rotation vs. shifting in this context. 4 5 will be the sum of the un-shifted original and a copy shifted six positions to the right, as shown in fig. 3: Figure 3 Because summing is accomplished with modulo-2 addition, whenever an odd number of 1’s overlap the result is 0. As can be seen in fig. 3, the two Sierpinski patterns are visible for the first few steps, but as the un-shifted pattern begins to spread out to the right it starts interacting with the shifted copy. As a result the individual patterns become more difficult to discern. mathworld.wolfram.com/Rule60.html provides an animated demonstration of additivity with Rule 60. The analysis function described in the next section can take the boolean matrix representation of the output of the elementary cellular automaton with Rule 60 given any initial conditions and return the vector of initial conditions. In addition, as will be shown next, this same function can analyze any boolean matrix and show which instances of the Sierpinski pattern must be summed to reconstruct the original matrix. Thus the additivity exhibited by the elementary cellular automaton with Rule 60 can be regarded as a special case of a more general additive property possessed by the Sierpinski pattern. ANALYZING AND SYNTHESIZING BOOLEAN MATRICES As was stated in the INTRODUCTION, every square boolean matrix can be analyzed as the element-wise sum of appropriately rotated instances of the Sierpinski pattern. Fig. 4 shows the set of rotated matrices out which any 4×4 boolean matrix can be constructed. The basic pattern is the upper left square in the fig. 4. In any row each matrix is rotated one position further to the right than its left neighbor. Each row is rotated one position further down than the row above it. Since the boundary conditions are cyclic, one more rotation either right or down will simply reproduce the first column or first row. In the analysis of a 4×4 matrix, each black square selects the matrix in the corresponding position in fig. 4. Thus, for example, if an analysis has black squares at (1,1) and (4,4), this indicates that the original matrix can be reconstructed by adding the matrices in the upper left and lower right corners of fig. 4. The analysis of an n×n matrix implicitly uses an n×n table of rotated Sierpinski matrices like fig.4, but actually constructing such a table is not necessary, or even feasible since the table consumes memory proportional to 𝑛4 . Figure 4 The Matlab analyze function below constructs its matrix result by exclusive-or’ing an instance of the 2×2 matrix in fig. 5 into the result matrix (initially all 0’s) at every 2×2 region where the input matrix has a 1. 1 0 1 1 Figure 5 The upper left corner of the 2×2 matrix goes into the location containing 1 in the input matrix. Whenever this procedure causes the insertion of a 1 into a location already containing a 1, the result is 0. Insertions that would go beyond the rightmost column or below the bottom row wrap around. function y = analyze( x ) [ r , c ] = size( x ) ; y = zeros( r , c ) ; gg = y ; gg( 1 , 1 ) = 1 ; gg( 2 , 1 ) = 1 ; gg( 2 , 2 ) = 1 ; for i = 1 : r for j = 1 : c if x( i , j ) y = xor( y , gg ) ; end gg = circshift( gg' , 1 )' ; end gg = circshift( gg , 1 ) ; end end The Matlab synthesize function below reconstructs an n×n matrix from the analysis provided by the analyze function. This is accomplished by adding an appropriately rotated n×n instance of the Sierpinski pattern into the result matrix (initially all 0’s) whenever the input matrix has a 1. Whenever this procedure causes the insertion of a 1 into a location already containing a 1, the result is 0. Insertions that would go beyond the rightmost column or below the bottom row wrap around. function y = synthesize( x ) [ r , c ] = size( x ) ; y = zeros( r , c ) ; gg = G( r ) ; for i = 1 : r for j = 1 : c if x( i , j ) y = xor( y , gg ) ; end gg = circshift( gg' , 1 )' ; end gg = circshift( gg , 1 ) ; end end function y = G( n ) y = zeros( n , n ) ; y( 1 , : ) = ones( 1 , n ) ; for i = 2:n y( i , : ) = mod( cumsum( y( i - 1 , end y = flipud( y ) ; end : ) ) , 2 ) ; EXAMPLES Fig. 6 was generated from the same vector of initial conditions as fig. 3. Like fig. 3, it consists of two superposed instances of the Sierpinski pattern; however, it looks slightly different because the pattern which begins near the middle of the top row has been rotated rather than shifted, causing wraparound. As a result, some squares that were black in fig. 3 have changed to white, and some white squares have changed to black. Figure 6 Fig. 7 is the analysis of fig. 6 and, as can be seen, the top row of fig. 7 represents exactly the same vector used by Wolfram’s cellular automaton to generate fig. 3, i.e., 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0. Figure 7 Because the analysis function is intended to analyze arbitrary boolean matrices, it always returns a matrix result. Fig. 8 is an image consisting of six instances of the basic Sierpinski pattern at six different scales and aligned along the main diagonal. Figure 8 Fig. 9 is the analysis of fig. 8. As can be seen, the analysis is two-dimensional. Each square identifies a rotated instance of the Sierpinski pattern necessary to recreate the original image. In this case the six instances specified by the black squares must be summed to produce fig. 8. One new instance begins in row 0, 1, 2, 4, 8, and 16. Figure 9 Fig. 10 is another picture created by the superposition of rotated instances of the Sierpinski pattern. Figure 10 Fig. 11 is the analysis of fig. 10. The black squares indicate that a new instance of the Sierpinski pattern begins in row 0, 1, 2, 4, 8, 16, and 32. Figure 11 Fig. 12 was produced by the superposition of many randomly rotated instances of the Sierpinski pattern. The visual texture of fig. 12 is typical of Wolfram’s “Type 3” behavior, which is observed in many natural and artificial processes. Figure 12 Fig. 13 is the analysis of fig. 12. There is no obvious pattern, as would be expected from the random construction of fig. 12. But again, each square identifies a specific rotated instance of the Sierpinski pattern necessary to recreate the original picture. Figure 13 A WOLFRAMIZED VARIATION If the rotations (i.e., circshift’s) in the analyze and synthesize functions are replaced with right- and down-shifts, the behavior of these functions becomes analogous to the operation of multiple elementary cellular automata running concurrently. Each row of the result of analyze would represent the initial conditions of a new automaton starting up at the time step corresponding to that row, and the output of synthesize would represent the combined output of the automata. For example, fig. 9 would represent automata starting at time steps 0, 1, 2, 4, 8, and 16. As fig. 14 shows, the combined output of all six automata would not be the same as that shown in fig. 8 because the Wolframized version of synthesize uses shifts rather than rotations. The Matlab code for the Wolframized functions can be found in APPENDIX II. Figure 14 DISCUSSION This paper grew out of my earliest attempts to understand and apply the work of French biochemist and crystallographer Gérard Langlet (1940-1996). Despite early promise, this work never caught on beyond the relatively small community of APL implementers, developers, and programmers, of which I was a member. In Langlet’s 1992 paper [3] I saw what appeared to be a very simple and efficient way to analyze digital signals and images. As it turned out, his transforms yielded little of practical value in those domains, and Langlet himself was unable to establish the connection he desired between his transforms and the FFT. However, as part of my own investigations of his transforms I did discover a few interesting things, such as the extended additivity discussed in this paper. More might be done in this area. Although Rule 102 is just the mirror image of Rule 60, Rules 90 and 150 might yield interesting results if investigated from the standpoint of extended additivity. Wolfram has a website [4] that provides demonstrations of additivity and useful information about the additive rules. REFERENCES [1] Stephen Wolfram. A New Kind of Science. Champaign, IL: Wolfram Media (2002) [2] Stuart Smith. In Search of the “World Formula”. http://www.cs.uml.edu/~stu [3] Gérard Langlet. Towards the Ultimate APL-TOE. ACM SIGAPL Quote Quad, 23:1, July 1992. [4] http://mathworld.wolfram.com/AdditiveCellularAutomaton.html APPENDIX I Because Wolfram first identified the additivity property in connection with his elementary cellular automaton with Rule 60, this paper has focused on that method for generating the basic Sierpinski pattern; however, this pattern can be generated in several other ways. Among these are the following: Binary-to-Gray Code Conversion Generate the Sierpinski matrix one row at a time, making each successive row the binaryto-gray code conversion of the preceding row. The first row contains 1 in the first position and zeroes in the remaining positions. For a length-n initial vector perform n-1 conversion steps. Pascal's Triangle modulo 2 Generate n rows of Pascal's Triangle modulo-2 and pad the rows on the right with zeroes so that they are all of length n. Kronecker product/block replacement Begin with the following 2×2 matrix, which will be called G: 1 0 1 1 To obtain the next higher order G, compute the Kronecker product G2 n G Gn where n is the order of the matrix to be enlarged to the next higher order. Each time the product is computed, the length of the side is doubled and the number of cells is quadrupled. The block replacement method is similar. Beginning with the 2×2 G matrix, replace each cell containing a 1 with a copy of G, and replace each cell containing a 0 with a 2×2 all-zeroes matrix. As with the Kronecker product method, this method doubles the length of the side and quadruples the number of cells each time it is applied. For example, if we compute either G G or one round of block replacement, the result will be: 1 1 1 1 0 1 0 1 0 0 1 1 0 0 0 1 APPENDIX II function y = analyze( x [ r , c ] = size( x ) y = zeros( r , c ) ; m = y ; m( 1 , 1 ) = 1 ; m( 2 , 1 ) = 1 ; m( 2 , 2 ) = 1 ; gg = m ; for i = 1 : r for j = 1 : c if x( i , j ) y = xor( y , gg end gg = shiftr( gg ) end m = shiftd( m ) ; gg = m ; end end ) ; ) ; ; function y = synthesize( x ) [ r , c ] = size( x ) ; y = zeros( r , c ) ; m = G( r ) ; gg = m; for i = 1 : r for j = 1 : c if x( i , j ) y = xor( y , gg ) ; end gg = shiftr( gg ) ; end m = shiftd( m ) ; gg = m ; end end function y = shiftr( x ) [ r , c ] = size( x ) ; y = horzcat( zeros( r , 1 ) , x ) ; y = y( 1:r , 1:c) ; end function y = shiftd( x ) [ r , c ] = size( x ) ; y = horzcat( zeros( c , 1 ) , x' )' ; y = y( 1:r , 1:c) ; end