# Is it possible to extract the rules of cellular automata as Mathematica code?

I would like to run cellular automata in the vertical direction if row index is greater than column index and in the horizontal direction if row index is less than column index, in a square array starting in the upper left corner for some initial value. For this to succeed the cells referred to in the rule must be either on the same row or column or on the two previous row or column. Perhaps not really clearly explained but it is access to the rule description that I would like to have.

Example of the type of cross directional table I would like to plot, here in Excel for some cellular automata rule:

The cell formula I used was:

=IF(OR(AVERAGE(B3;C3;D3)=0;AVERAGE(B3;C3;D3)=4/3;AVERAGE(B3;C3;D3)=5/3; AVERAGE (C2;C3;C4)=0;AVERAGE(C2;C3;C4)=4/3;AVERAGE(C2;C3;C4)=5/3);0;IF(OR(AVERAGE(B3;C3;D3) =1/3;AVERAGE(B3;C3;D3)=3/3;AVERAGE(B3;C3;D3)=6/3; AVERAGE(C2;C3;C4)=1/3;AVERAGE (C2;C3;C4)=3/3;AVERAGE(C2;C3;C4)=6/3);1;2))

which was entered in cell C3 and had the initial matrix:

$\left( \begin{array}{cc} 0 & 0 \\ 0 & 1 \end{array} \right)$

Is there a way to extract or list the rules for cellular automata, in order to write new programs with them to produce images like the one above?

Edit: What I am looking for is the source code for cellular automata, with the source code written in Mathematica language.

Edit: The program I would like to see work looks like this:

(*program start*)
Clear[n, k, A, nn];
nn = 70
a = {1, 0, 0, 0, 0, 0, 1, 1};
t[n_, k_] :=
t[n, k] =
If[Or[n == 1, k == 1], 0,
If[And[n == 2, k == 2] , 1,
If[Or[And[t[n - 1, k - 2] == 1, t[n - 1, k - 1] == 1,
t[n - 1, k] == 1],
And[t[n - 2, k - 1] == 1, t[n - 1, k - 1] == 1,
t[n, k - 1] == 1]], a[[1]],
If[Or[And[t[n - 1, k - 2] == 1, t[n - 1, k - 1] == 1,
t[n - 1, k] == 0],
And[t[n - 2, k - 1] == 1, t[n - 1, k - 1] == 1,
t[n, k - 1] == 0]], a[[2]],
If[Or[And[t[n - 1, k - 2] == 1, t[n - 1, k - 1] == 0;
t[n - 1, k] == 1],
And[t[n - 2, k - 1] == 1, t[n - 1, k - 1] == 0,
t[n, k - 1] == 1]], a[[3]],
If[Or[And[t[n - 1, k - 2] == 1, t[n - 1, k - 1] == 0,
t[n - 1, k] == 0],
And[t[n - 2, k - 1] == 1, t[n - 1, k - 1] == 0,
t[n, k - 1] == 0]], a[[4]],
If[Or[And[t[n - 1, k - 2] == 0, t[n - 1, k - 1] == 1,
t[n - 1, k] == 1],
And[t[n - 2, k - 1] == 0, t[n - 1, k - 1] == 1,
t[n, k - 1] == 1]], a[[5]],
If[Or[And[t[n - 1, k - 2] == 0, t[n - 1, k - 1] == 1,
t[n - 1, k] == 0],
And[t[n - 2, k - 1] == 0, t[n - 1, k - 1] == 1,
t[n, k - 1] == 0]], a[[6]],
If[Or[And[t[n - 1, k - 2] == 0, t[n - 1, k - 1] == 0,
t[n - 1, k] == 1],
And[t[n - 2, k - 1] == 0, t[n - 1, k - 1] == 0,
t[n, k - 1] == 1]], a[[7]],
If[Or[And[t[n - 1, k - 2] == 0, t[n - 1, k - 1] == 0,
t[n - 1, k] == 0],
And[t[n - 2, k - 1] == 0, t[n - 1, k - 1] == 0,
t[n, k - 1] == 0]], a[[8]], 0]]]]]]]]]];
MatrixForm[Table[Table[t[n, k], {k, 1, nn}], {n, 1, nn}]]
(*program end*)


The vector "a" is the rule vector for the cellular automata.

Here are some example outputs from Excel 2007:

http://mobiusfunction.wordpress.com/?attachment_id=1079

http://i.stack.imgur.com/xUnzM.png

When I try to run the program I get "recursion limit exceeded" and "iteration limit exceeded" errors. Then I tried to change these session parameters but this gave a program with no output. What to do?

-
I realized this is pretty trivial after all. One can write an elementary cellular automata by varying the input vector to the same set of logical rules. The input vector to the program being the output vector of the cellular automata rules. – Mats Granvik Jan 6 '13 at 11:02
– ssch Jan 6 '13 at 11:15
I realize now that in my Excel formula I don't have any IF statements about row index or column index. The image is produced by the given cell formula however. – Mats Granvik Jan 6 '13 at 11:46
What if row index = column index? – Sjoerd C. de Vries Jan 6 '13 at 17:53
I don't know. But now I noticed I have an if statement missing for the case n>2 and k>2 in the Mathematica code. – Mats Granvik Jan 6 '13 at 19:18