CArule1d rule1(1,18); CArule1d rule2(1,204); CArule1d rule3; rule3=rule1*rule2; cout << Distance(rule1, rule3);
Another useful operator is
, which is used to compute a sum two rules. When
and
have the same radius, the ruletable of
is a bitwise mod 2 sum of ruletables of
and
. The following program, when executed, will print 72, which is the rule number of
the sum of rules 18 and 90.
CArule1d f(1,18); CArule1d g(1,90); CArule1d h; h=f+g; cout << h.GetNumber()<<endl;
Arrays of rules can be constructed using the default constructor. The following program will create an array A containing all elementary rules, and then test which of these rules commute with rule 43.
CArule1d r(1,43);
CArule1d *A;
A=new CArule1d[256];
int i;
for(i=0; i<256; i++)
{CArule1d s(1,i); A[i]=s;}
for(i=0; i<256; i++)
if (Distance(A[i]*r,r*A[i])==0)
cout << "Rule "<<i<< " commutes with rule 43"<<endl;