Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

A (one dimensional) cellular automaton is a function1 F : Σ → Σ with the property that there is a K > 0 such that F (x)i depends only on the 2K + 1 coordinates xi−K , xi−K+1, . . . , xi−1, xi, xi+1, . . . , xi+K . A periodic point of σ is any x such that σ^p (x) = x for some p ∈ N, and a periodic point of F is any x such that F^q (x) = x for some q ∈ N. Given a cellular automaton F, a point x ∈ Σ is jointly periodic if there are p, q ∈ N such that σ^p (x) = F^q (x) = x, that is, it is a periodic point under both functions.

This project aims to explore the nature of one-dimensional Cellular Automata, in the hope of finding the structure of cellular automata through its periodic points.

2034 views
License: MIT
ubuntu2004
1
/*
2
* Copyright (C) 2004 Bryant Lee
3
*
4
* This file is part of FPeriod.
5
*
6
* FPeriod is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
10
*
11
* FPeriod is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with FPeriod; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
*/
20
21
/**
22
* Represents a composition of poly functions
23
*
24
* Written by: Bryant Lee
25
* Date: 11/22/04
26
**/
27
28
#include <vector>
29
#include <string>
30
#include <map> //uses a map in printDefinitions()
31
32
#include <fstream> //used in printDefinitions()
33
34
#include <math.h> //for ceil
35
36
#include "Comp.h"
37
#include "StringOps.h"
38
39
extern int UINTSIZE;
40
41
Comp::Comp(int iShiftSize) {
42
shiftSize = iShiftSize;
43
}
44
45
Comp::~Comp() {
46
clearFuncStore();
47
}
48
49
string Comp::returnName() {
50
string compStr;
51
int i;
52
53
for(i = compNames.size() - 1; i >= 0; i--) {
54
//elements are already trimmed (see setComposition())
55
compStr.append(compNames[i]);
56
if(i != 0)
57
compStr.append("#");
58
}
59
60
return compStr;
61
}
62
63
//printDefinitions
64
void Comp::printDefinitions(ofstream & fout) {
65
int i;
66
map <string, bool> seen; //track functions used twice (so we define only once)
67
map<string, Func *>::iterator frt;
68
69
for(i = compNames.size() - 1; i >= 0; i--) {
70
if(seen.find(compNames[i]) == seen.end()) {
71
seen.insert(pair<string,bool>(compNames[i], true));
72
frt = funcStore.find(compNames[i]);
73
if(frt->second->isOpt())
74
fout << "OPT ";
75
fout << compNames[i] << " = ";
76
frt->second->print(fout);
77
}
78
}
79
}
80
81
void Comp::print() {
82
//dead function
83
84
/*
85
unsigned int size = composition.size(), i;
86
87
for(i = 0; i < size; i++) {
88
cout << "Comp func " << i << ": ";
89
composition[i]->print();
90
}
91
92
cout << "\n";
93
*/
94
}
95
96
bool Comp::setComposition(const string & inStr) {
97
int i;
98
vector <string> cArr;
99
100
split(inStr, '#', cArr);
101
102
//run through string backwards to create composition
103
composition.clear();
104
compNames.clear();
105
106
for(i = cArr.size() - 1; i >= 0; i--) {
107
trim(cArr[i]); //permanently trims
108
map<string, Func *>::iterator cfunc = funcStore.find(cArr[i]);
109
110
if(cfunc == funcStore.end())
111
return false;
112
else {
113
composition.push_back(cfunc->second);
114
compNames.push_back(cArr[i]);
115
}
116
}
117
118
return true;
119
}
120
121
void Comp::addFunc(const string & inStr, string name, bool opt) {
122
trim(name);
123
124
funcStore.insert(pair<string, Func *>(name,
125
new Func(inStr, shiftSize, opt)));
126
}
127
128
void Comp::image(byte *word, int wordLength, byte *output) {
129
int size = composition.size(), i;
130
byte temp[wordLength];
131
132
copyWord(temp, word, wordLength);
133
134
for(i = 0; i < size; i++) {
135
if(i % 2 == 0) {
136
composition[i]->image(temp, wordLength, output);
137
}
138
else { // i is odd
139
composition[i]->image(output, wordLength, temp);
140
}
141
}
142
143
if(size % 2 == 0)
144
copyWord(output, temp, wordLength);
145
}
146
147
/*
148
* NOTE: the 4th parameter, blocks, could be derived from wordLength, but
149
* it requires a division. It is cheaper to pass it.
150
*/
151
void Comp::image(unsigned int *word, int wordLength, unsigned int *output,
152
unsigned int blocks) {
153
int size = composition.size(), i;
154
unsigned int temp[blocks];
155
156
copyUIntArray(temp, word, blocks);
157
158
for(i = 0; i < size; i++) {
159
if(i % 2 == 0) {
160
composition[i]->image(temp, wordLength, output, blocks);
161
}
162
else { // i is odd
163
composition[i]->image(output, wordLength, temp, blocks);
164
}
165
}
166
167
if(size % 2 == 0)
168
copyUIntArray(output, temp, blocks);
169
}
170
171
void Comp::clearFuncStore() {
172
map<string, Func *>::iterator it;
173
174
for(it = funcStore.begin(); it != funcStore.end(); it++) {
175
delete(it->second);
176
}
177
}
178
179
180
181
182
183
184
185
186
187
188
189
190