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(i + 3);87pattern += word.charAt(i + 4);88pattern += word.charAt(0);89} else if (i == word.length() - span + 2) {90pattern += word.charAt(i);91pattern += word.charAt(i + 1);92pattern += word.charAt(i + 2);93pattern += word.charAt(i + 3);94pattern += word.charAt(0);95pattern += word.charAt(1);96} else if (i == word.length() - span + 3) {97pattern += word.charAt(i);98pattern += word.charAt(i + 1);99pattern += word.charAt(i + 2);100pattern += word.charAt(0);101pattern += word.charAt(1);102pattern += word.charAt(2);103} else if (i == word.length() - span + 4) {104pattern += word.charAt(i);105pattern += word.charAt(i + 1);106pattern += word.charAt(0);107pattern += word.charAt(1);108pattern += word.charAt(2);109pattern += word.charAt(3);110} else if (i == word.length() -span + 5) {111pattern += word.charAt(i);112pattern += word.charAt(0);113pattern += word.charAt(1);114pattern += word.charAt(2);115pattern += word.charAt(3);116pattern += word.charAt(4);117} else {118pattern += word.charAt(i);119pattern += word.charAt(i + 1);120pattern += word.charAt(i + 2);121pattern += word.charAt(i + 3);122pattern += word.charAt(i + 4);123pattern += word.charAt(i + 5);124}125126// apply the rule to the input pattern and append the result to the new word127key = Integer.parseInt(pattern, 2);128newWord += Rule.get(key);129}130131return newWord;132}133134public static void main(String[] args) {135int k = 15;136int m = 10;137int span = 6;138139List<String> originalWords = new ArrayList<>();140List<String> wordsWithKperiod = new ArrayList<>();141List<String> allWords = new ArrayList<>();142143originalWords = generateWords(m);144145//System.out.println(originalWords);146147wordsWithKperiod = generateWords(k-m);148149for (int i = 0; i < originalWords.size(); i++) {150for (int j = 0; j < wordsWithKperiod.size(); j++) {151allWords.add(originalWords.get(i) + wordsWithKperiod.get(j));152}153}154155156/*157for (int i = 0; i < originalWords.size(); i++) {158for (int j = 0; j < wordsWithKperiod.size(); j++) {159String newWord = originalWords.get(i) + wordsWithKperiod.get(j);160newWord += newWord.substring(0, span); // add first k characters to end of string161allWords.add(newWord);162}163}164*/165166//testing167System.out.println(allWords);168169String tabularRule = "1010101001010101010101010101010101010101101010101010101010101010";170Rule = createHashMap(tabularRule.toCharArray(), span);171System.out.println(Rule);172173174int mdense = 0;175176for(int z = 0; z < allWords.size(); z++) {177String newWord = applyRule(allWords.get(z), span);178while(!newWord.equals(allWords.get(z))) {179newWord = applyRule(newWord, span);180}181mdense += 1;182}183184System.out.println(mdense);185186}187}188189