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
from functools import wraps
2
3
def print_star_dashes(rule):
4
mapping = {0: '-', 1: '*'}
5
6
@wraps(rule)
7
def print_rule(state):
8
print(''.join( [mapping[s] for s in state] ))
9
return rule(state)
10
return print_rule
11
12
@print_star_dashes
13
def repeat_rule(state):
14
return state
15
16
@print_star_dashes
17
def simple_rule(state):
18
new_state = []
19
for index, cell in enumerate(state):
20
if index == 0:
21
new_state.append(1 if state[1] == 1 else 0)
22
elif index == len(state) - 1:
23
new_state.append(1 if state[-1] == 1 else 0)
24
else:
25
new_state.append(0 if state[index - 1] == state[index + 1] else 1)
26
27
return new_state
28
29
@print_star_dashes
30
def rule_30(state):
31
state = list(map(int, state))
32
new_state = []
33
for index, cell in enumerate(state):
34
if index == 0:
35
new_state.append(0 ^ (state[index] | state[index + 1]))
36
elif index == len(state) - 1:
37
new_state.append(state[index - 1] ^ (state[index] | 0))
38
else:
39
new_state.append( state[index - 1] ^ (state[index] | state[index + 1] ))
40
41
42
return new_state
43
44
@print_star_dashes
45
def rule_110(state):
46
state = list(map(int, state))
47
new_state = []
48
# elemntary cellular automata
49
# 110 in binary
50
# rule = [(110/pow(2,i)) % 2 for i in range(8)]
51
#rule = [0, 1, 1, 1, 0, 1, 1, 0]
52
rule = list(map(int, list(str(bin(110))[2:].zfill(8))))
53
for index, cell in enumerate(state):
54
if index == 0:
55
new_state.append(rule[2 * state[index] + state[index + 1]])
56
elif index == len(state) - 1:
57
new_state.append( rule[4 * state[index - 1] + 2 * state[index]] )
58
else:
59
new_state.append( rule[4 * state[index - 1] + 2 * state[index] + state[index + 1]] )
60
61
62
return new_state
63
64
# TODO numpy
65
def apply_elementary_rule(rule_num):
66
67
@print_star_dashes
68
def apply_rule(state):
69
state = list(map(int, state))
70
new_state = []
71
# TODO comment
72
rule = list(reversed(list(map(int, list(str(bin(rule_num))[2:].zfill(8))))))
73
for index, cell in enumerate(state):
74
if index == 0:
75
new_state.append(rule[2 * state[index] + state[index + 1]])
76
elif index == len(state) - 1:
77
new_state.append( rule[4 * state[index - 1] + 2 * state[index]] )
78
else:
79
new_state.append( rule[4 * state[index - 1] + 2 * state[index] + state[index + 1]] )
80
81
82
return new_state
83
84
return apply_rule
85
86