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.
License: MIT
ubuntu2004
import java.time.Duration;1import java.time.Instant;2import java.util.*;3import java.util.function.Function;45public class FDense {6private static int N = 2; // Size of the alphabet7private static HashMap<Integer, Integer> Rule= new HashMap<Integer, Integer>();89private static HashMap<Integer, Integer> createHashMap(char[] rule, int k) {10HashMap<Integer, Integer> hashMap = new HashMap<Integer, Integer>();11int n = (int) Math.pow(2, k); // Total number of input patterns1213// Iterate over all input patterns and store the output in the HashMap14for (int i = 0; i < n; i++) {15hashMap.put(i, Integer.parseInt(String.valueOf(rule[i]).trim()));16}1718return hashMap;19}2021private static List<String> generateWords(int length) {22List<String> words = new ArrayList<>();23generateWordsHelper("", length, words);24return words;25}2627private static void generateWordsHelper(String prefix, int length, List<String> words) {28if (prefix.length() == length) {29words.add(prefix);30} else {31for (int i = 0; i < N; i++) {32generateWordsHelper(prefix + i, length, words);33}34}35}3637public static List<String> applyRule(List<String> words, int span) {38List<String> newWords = new ArrayList<>();39int key;40for (String word : words) {41StringBuilder newWord = new StringBuilder();42for (int i = 0; i < word.length(); i++) {43String pattern = "";44if(i == word.length() - span + 1) {45pattern += word.charAt(i);46pattern += word.charAt(i+1);47pattern += word.charAt(i+2);48pattern += word.charAt(0);49} else if (i == word.length() - span + 2) {50pattern += word.charAt(i);51pattern += word.charAt(i+1);52pattern += word.charAt(0);53pattern += word.charAt(1);54} else if (i == word.length() - span + 3) {55pattern += word.charAt(i);56pattern += word.charAt(0);57pattern += word.charAt(1);58pattern += word.charAt(2);59} else {60pattern += word.charAt(i);61pattern += word.charAt(i+1);62pattern += word.charAt(i+2);63pattern += word.charAt(i+3);64}6566// apply the rule to the input pattern and append the result to the new word67key = Integer.parseInt(pattern, 2);68int output = Rule.get(key);69newWord.append(output);70}71newWords.add(newWord.toString());72}73return newWords;74}757677public static String applyRule(String word, int span) {78int key;79String newWord = "";80for (int i = 0; i < word.length(); i++) {81String pattern = "";82if (i == word.length() - span + 1) {83pattern += word.charAt(i);84pattern += word.charAt(i + 1);85pattern += word.charAt(i + 2);86pattern += word.charAt(0);87} else if (i == word.length() - span + 2) {88pattern += word.charAt(i);89pattern += word.charAt(i + 1);90pattern += word.charAt(0);91pattern += word.charAt(1);92} else if (i == word.length() - span + 3) {93pattern += word.charAt(i);94pattern += word.charAt(0);95pattern += word.charAt(1);96pattern += word.charAt(2);97} else {98pattern += word.charAt(i);99pattern += word.charAt(i + 1);100pattern += word.charAt(i + 2);101pattern += word.charAt(i + 3);102}103104// apply the rule to the input pattern and append the result to the new word105key = Integer.parseInt(pattern, 2);106newWord += Rule.get(key);107}108109return newWord;110}111112public static void main(String[] args) {113int k = 12;114int m = 10;115int span = 4;116117List<String> originalWords = new ArrayList<>();118List<String> wordsWithKperiod = new ArrayList<>();119List<String> allWords = new ArrayList<>();120121originalWords = generateWords(m);122123//System.out.println(originalWords);124125wordsWithKperiod = generateWords(k-m);126127for (int i = 0; i < originalWords.size(); i++) {128for (int j = 0; j < wordsWithKperiod.size(); j++) {129allWords.add(originalWords.get(i) + wordsWithKperiod.get(j));130}131}132133134/*135for (int i = 0; i < originalWords.size(); i++) {136for (int j = 0; j < wordsWithKperiod.size(); j++) {137String newWord = originalWords.get(i) + wordsWithKperiod.get(j);138newWord += newWord.substring(0, span); // add first k characters to end of string139allWords.add(newWord);140}141}142*/143144//testing145System.out.println(allWords);146147String tabularRule = "0000111101001011";148Rule = createHashMap(tabularRule.toCharArray(), span);149System.out.println(Rule);150151System.out.println(applyRule(allWords, span));152153154for(int z = 0; z < allWords.size(); z++) {155String newWord = applyRule(allWords.get(z), span);156while(!newWord.equals(allWords.get(z))) {157newWord = applyRule(newWord, span);158}159System.out.print("true ");160}161162163}164}165166