Applied Mathematics and Computation 258 (2015) 404–409
Contents lists available at ScienceDirect
Applied Mathematics and Computation journal homepage: www.elsevier.com/locate/amc
Analytic function of local rules of Elementary Cellular Automata Yuhong Ruan a,⇑, Anwei Li a, Jing Huang b a b
Department of Science, Taiyuan Institute of Technology, Taiyuan 030008, China Department of Mechanical Engineering, Taiyuan Institute of Technology, Taiyuan 030008, China
a r t i c l e
i n f o
Keywords: Elementary Cellular Automata Local rules Analytic function
a b s t r a c t Tabulation method is usually adopted to describe the mapping relation of the analytic function of the local rules of Cellular Automaton. Although tabulation method is quite suitable to describe the mapping relation among discrete variables, there are numerous if-else sentences for the state decision of independent variables in computer programming. In this paper, we define an analytic function of the local rules of an Elementary Cellular Automaton by constructing the recognition function of the states of the cell and the neighbors. Therefore, a huge number of calculations by if-else sentences are transferred to the function calculation due to the adoption of the function of the local rules during the evolution of the ECA. Finally, the simulation results show that the programming structure is optimized and the programming efficiency is enhanced. In addition, the proposed method can also be extended to other 2-state cellular automata. Ó 2015 Elsevier Inc. All rights reserved.
1. Introduction Cellular Automata (CA), composed of a cell, a cell space, neighbors and local rules for evolution, is a mathematical model with discrete variables in terms of time, space, and state. Initially, Cellular Automata was firstly proposed by Stanislaw M. Ulam and John Von Neunann in the 1950s, and then Martin Gardner introduced one ‘‘Game of Life’’ invented by John Conway in paper [1–3], triggering a huge tide for the study on Cellular Automata among scholars. In the 1980s, Stephen Wolfram proposed an Elementary Cellular Automata (ECA) with the state of 2 and the radius of 1. The ECA is one basic type of CA with simple structure. However, the different local rules in the ECA show quite complex behavior dynamics, and the evolution under the local rules presents the phenomena of complex dynamic interaction and self-duplication. In 2002, Stephoen Wolfram studied CA deeply and creatively named the CA as a novel scientific filed [4]. Currently, there have been wide applications of CA in different areas, including sociology, biology, ecology, information science, computer science, mathematics, physics, chemistry, geography, environment, military, infectious diseases and so on [5–11]. The local rule for a CA is generally defined as a state-transition table. During the evolution of the CA by computer programming, it is necessary for the programming to firstly decide the states of the cell and the neighbors at current moment by ‘if-else’ sentences, and then the evolution state of the cell at next moment is obtained according to the state-transition table. However, it is a huge waste in resource allocation and quite slow in computing speed to design the complex programming structure and to adopt a large number of ‘if-else’ programming sentences. In this paper, we define a function of the local rule for an Elementary Cellular Automaton by constructing a recognition function of the states of the cell and the neighbors. Therefore, a huge number of calculations by ‘if-else’ sentences are transferred to the function calculation due to the ⇑ Corresponding author. E-mail address:
[email protected] (Y. Ruan). http://dx.doi.org/10.1016/j.amc.2015.02.022 0096-3003/Ó 2015 Elsevier Inc. All rights reserved.
405
Y. Ruan et al. / Applied Mathematics and Computation 258 (2015) 404–409 Table 1 The state transition table for the local rules of S. Wolfram No. 76 cellular automata. Ntx ¼ stx1 ; stx ; stxþ1 stþ1 x
¼
f ðN tx Þ
(1, 1, 1)
(1, 1, 0)
(1, 0, 1)
(1, 0, 0)
(0, 1, 1)
(0, 1, 0)
(0, 0, 1)
(0, 0, 0)
0
1
0
0
1
1
0
0
adoption of the analytic function of the local rule during the evolution of the ECA. As a result, the programming structure is optimized and the programming efficiency is enhanced. 2. Elementary Cellular Automata (ECA) A standard cellular automata (CA) is represented as a quadruple by mathematical marks, as shown in (1),
A ¼ ðLd ; S; N; f Þ:
ð1Þ
A represents one CA system, and L is the cell space with an integer d to represent the dimensions of the cell space inside of the CA. Besides, S ¼ fs1 ; s2 ; . . . ; sk g is a finite and discrete set of cell state s1 ; s2 ; . . . ; sk , and N ¼ fs1 ; s2 ; . . . ; sn g indicates a combination between a cell and all the other neighboring cells, which means N ¼ fs1 ; s2 ; . . . ; sn g is a space vector including n different cell states where n is the total number of the cell and the neighboring cells with the integers si (i = 1,2, ,n). In addition, f n
zfflfflfflfflfflfflfflfflfflfflffl}|fflfflfflfflfflfflfflfflfflfflffl{ presents a local mapping relation or a local rule to map S S S ¼ Sn to S. The Elementary Cellular Automata (ECA) proposed by S. Wolfram is a one-dimensional cellular automata, and the corresponding cell state is 2, and the radius is 1 and 3. In general, S ¼ f0; 1g is the set of cell states, and the cell state at moment t is noted as stx . Furthermore, the states of defined neighbors with r ¼ 1 are marked as stx1 and stxþ1 respectively, and the combination Ntx
¼ f ð1; 1; 1Þ
of
states
ð1; 1; 0Þ
between ð1; 0; 1Þ
the
ð1; 0; 0Þ
cell
and
ð0; 1; 1Þ
the
ð0; 1; 0Þ
neighbors ð0; 0; 1Þ
is
represented
by
Ntx ¼ ðstx1 ; stx ; stxþ1 Þ,
ð0; 0; 0Þ g; as shown in Fig. 1. Although an
3
ECA looks quite simple, there are 22 ¼ 256 local rules for the ECA, and the Wolfram code (0255) is adopted to identify each local rule of the ECA [1,2]. A cell state stþ1 at the moment of t þ 1 is the function of the state combination Ntx ¼ ðstx1 ; stx ; stxþ1 Þ between the cell and the x neighbors at the moment of t, which is represented as stþ1 ¼ f ðNtx Þ. Thus, this function is named as local rule or local mapping x relation, which is usually described in terms of state transition table, such as the local rules of S. Wolfram No.76 cellular automata in Table 1. 3. The construction of analytic function of the local rule of Elementary Cellular Automata (ECA) 3.1. State recognition of neighbors The combinations of the states of the neighbors are finite regardless the state stx of the cell is either 0 or 1. In other words, 2 fð1; 1Þ; ð1; 0Þ; ð0; 1Þ; ð0; 0Þg as either stx ¼ 0 or stx ¼ 1. Therefore, in order to recognize and uniquely identify the m11 m12 states of the cell’s neighbors, we construct a recognition function y ¼ gðstx1 ; stxþ1 ; MÞ, where M ¼ , and the funcm21 m22 tion is used to observe the states of the cell’s neighbors: ðstx1 ; stxþ1 Þ
y ¼ gðstx1 ; stxþ1 ; MÞ ¼ ð stx1
1 stx1 Þ
m11
m12
m21
m22
1
stxþ1 - stxþ1
!
8 m11 > > > < m12 ¼ > m21 > > : m22
as ðstx1 ; stxþ1 Þ ¼ ð1; 1Þ as as
ðstx1 ; stxþ1 Þ ¼ ð1; 0Þ ðstx1 ; stxþ1 Þ ¼ ð0; 1Þ
as
ðstx1 ; stxþ1 Þ ¼ ð0; 0Þ
For instance, as ðstx1 ; stxþ1 Þ ¼ 1; 0, there is y ¼ gðxtx1 ; xtxþ1 ; MÞ ¼ m12 .
Fig. 1. The state combination Ntx of an ECA and the neighbors at the moment t.
ð2Þ
406
Y. Ruan et al. / Applied Mathematics and Computation 258 (2015) 404–409
Table 2 The mapping relation between Ntx and Mð1Þ , Mð2Þ ). Ntx ¼ ðstx1 ; stx ; stxþ1 Þ
(1, 1, 1)
(1, 1, 0)
(1, 0, 1)
(1, 0, 0)
(0, 1, 1)
(0, 1, 0)
(0, 0, 1)
(0, 0, 0)
Ntþ1 x
ð1Þ m11
ð1Þ m21
ð1Þ m21
ð1Þ m22
ð2Þ m12
ð2Þ m12
ð2Þ m21
m22
¼
f ðstx ; g 1 ; g 2
ð2Þ
Fig. 2. Von Neumann neighbors.
The calculation results of the function y ¼ gðxtx1 ; xtxþ1 ; MÞ shows that each state of the cell’s neighbors ðstx1 ; stxþ1 Þ can be recognized exactly by the recognition function y ¼ gðstx1 ; stxþ1 ; MÞ and the state of the cell’s neighbors can also be exactly represented by each element mij ði; j ¼ 1; 2Þ in the recognition matrix M. 3.2. The state recognition of the cell and the neighbors Based on the constructing method of the function y ¼ gðstx1 ; stxþ1 ; MÞ, we can also construct a function z ¼ f ðstx ; g 1 ; g 2 Þ for recognizing the states of the cells and the neighbors Ntx ¼ ðstx1 ; stx ; stxþ1 Þ in an ECA. In the construction of the function, there is
g 1 ¼ stx1 ; stxþ1 ; Mð1Þ ;
ð1Þ
Mð1Þ ¼
ð1Þ
m11
m12
ð1Þ
m22
m21
!
g 2 ¼ stx1 ; stxþ1 ;
;
ð1Þ
Mð2Þ ;
Mð2Þ ¼
m11
ð2Þ
m12
ð2Þ
m22
m21
ð2Þ ð2Þ
!
;
and
z ¼ f ðstx ; g 1 ; g 2 Þ ¼ stx g 1 stx1 ; stxþ1 ; Mð1Þ þ 1 - stx g 2 ðstx1 ; stxþ1 ; Mð2Þ Þ ¼ stx ð stx1
þ 1 - stx ð stx1
ð2Þ
m11
1 - stx- 1 Þ
ð2Þ m21
1 - stx- 1 Þ
8 ð1Þ > > > m11 > > ð1Þ > > m12 > > > > ð1Þ > > m21 > > > ! ! > ð2Þ < mð1Þ stxþ1 m12 22 ¼ t ð2Þ > mð2Þ 1 - sxþ1 > m22 > 11 > > > ð2Þ > m > 12 > > > > ð2Þ > m21 > > > > : mð2Þ 22
m11
ð1Þ
m12
ð1Þ
m22
m21
ð1Þ ð1Þ
!
stxþ1
!
1 - stxþ1
as
ðstx1 ; stx ; stxþ1 Þ ¼ ð1; 1; 1Þ
as
ðstx1 ; stx ; stxþ1 Þ ¼ ð1; 1; 0Þ
as
ðstx1 ; stx ; stxþ1 Þ ¼ ð0; 1; 1Þ
as
ðstx1 ; stx ; stxþ1 Þ ¼ ð0; 1; 0Þ
as
ðstx1 ; stx ; stxþ1 Þ ¼ ð1; 0; 1Þ
as
ðstx1 ; stx ; stxþ1 Þ ¼ ð1; 0; 0Þ
ðstx1 ; stx ; stxþ1 Þ ¼ ð0; 0; 1Þ t as sx1 ; stx ; stxþ1 ¼ ð0; 0; 0Þ as
ð3Þ For instance,
N tx ðstx1 ; stx ; stxþ1 Þ
ð1Þ
¼ 1; 0; 1, there is M
z¼
f ðstx ; g 1 ; g 2
¼
ð2Þ m11 .
3.3. The function of local rules in an Elementary Cellular Automata The mapping relation between Ntx ¼ stx1 ; stx ; stxþ1 (the states of the cell and the neighbors) and Mð1Þ , Mð2Þ can be estabt lished by constructing the function z ¼ f ðsx ; g 1 ; g 2 . According to the state-transition table of local rules, the elements in of Ntx ¼ ðstx1 ; stx ; stxþ1 Þ at the moment of t þ 1, as shown in Table 2. Therefore, there is an Mð1Þ and Mð2Þ are the states stþ1 x analytic function of the local rules for the evolution of the ECA as follows. As a result, we have that:
407
Y. Ruan et al. / Applied Mathematics and Computation 258 (2015) 404–409 Table 3 The table of mapping relation between Ntx;yÞ ¼ ðstx1;yÞ ; stðx;yþ1Þ ; stðx;yÞ ; stðxþ1;yÞ ; stðx;y1Þ Þ and ðkÞ m ij i; j ¼ 1; 2; 3; 4 k ¼ 1; 2: ðk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1
!
1 - stxþ1
ð4Þ
1 - stxþ1
4. The analytic function of local rules of 2-State cellular automata There are numerous of 2-state cellular automata with other forms of neighbors. In this paper, we take the two dimensional cellular automata with Von Neumann neighbors as shown in Fig. 2 as an example to briefly introduce the construction of the analytic function of the local rules. For each 2-state cellular automata S ¼ f0; 1g with Von Neumann neighbors, the state combination between the cells and the neighbors at the moment t is noted as Ntx;yÞ ¼ ðstx1;yÞ ; stðx;yþ1Þ ; stðx;yÞ ; stðxþ1;yÞ ; stðx;y1Þ Þ, and based on the definition (4) the analytic function of the local rules can be defined as
tþ1 Nðx;yÞ ¼ f stðx;yÞ ; g 1 ; g 2 ¼ ð stðx;yÞ g 1 ðstx1;yÞ ; stðx;yþ1Þ ; stðxþ1;yÞ ; stðx;y1Þ ; Mð1Þ Þ þ ð1 - stðx;yÞ Þg 2 ðstx1;yÞ ; stðx;yþ1Þ ; stðxþ1;yÞ ; stðx;y1Þ ; Mð2Þ ð5Þ and
408
Y. Ruan et al. / Applied Mathematics and Computation 258 (2015) 404–409
Fig. 3. Source code for the evolution of the Elementary Cellular Automata with periodic boundary conditions.
Fig. 4. The 200 evolutions of various cases in Matlab (The dot represents that the state of the cell is 1, while the blank represents that the state of the cell is 0). (a) Case 1; (b) Case 2; (c) Case 3; (d) Case 4.
Table 4 Calculation cases. Ntx Ntþ1 x Case Case Case Case
¼ 1 2 3 4
f ðstx Þ; g 1 ; g 2
(1, 1, 1)
(1, 1, 0)
(1, 0, 1)
(1, 0, 0)
(0, 1, 1)
(0, 1, 0)
(0, 0, 1)
(0, 0, 0)
ð1Þ m11
ð1Þ m12
ð1Þ m21
ð1Þ m22
ð1Þ m211
ð1Þ m12
ð1Þ m21
0 0 0 0
1 0 0 0
0 1 0 1
0 0 0 0
1 0 0 0
1 1 1 0
0 1 1 0
m22 0 0 0 1
ð1Þ
409
Y. Ruan et al. / Applied Mathematics and Computation 258 (2015) 404–409
g k ðstx1;yÞ ; stðx;yþ1Þ ; stðxþ1;yÞ ; stðx;y1Þ ; MðkÞ
ðk¼1;2Þ
1T 0 t sðx;yþ1Þ 0 ! T C B stðx1;yÞ 0 C B 1 - stðx;yþ1Þ C B ¼ 0 stðx;yþ1Þ C 1 - stðx1;yÞ B A @ 0 1 - stðx;yþ1Þ 10 0 ðkÞ 1 ðkÞ ðkÞ ðkÞ stðxþ1;yÞ 0 m11 m12 m13 m14 C B ðkÞ ! C B ðkÞ ðkÞ ðkÞ Bm 1 stðxþ1;yÞ 0 stðx;y1Þ C m22 m23 m24 C CB B C B : B 21 C t B mðkÞ mðkÞ mðkÞ mðkÞ CB 0 stðxþ1;yÞ C A 1 - sðx;y1Þ @ 31 32 33 34 A@ ðkÞ ðkÞ ðkÞ ðkÞ 0 1 stðxþ1;yÞ m41 m42 m43 m44 ð6Þ
Besides, the mapping relation between Nð x; yÞt ¼ ðsð x 1; yÞt ; stðx;yþ1Þ ; stðx;yÞ ; stðxþ1;yÞ ; stðx;y1Þ Þ and m
ðkÞ
ij
i; j ¼ 1; 2; 3; 4
k ¼ 1; 2
can be found in Table 3. 5. Results In this simulation, several Elementary Cellular Automata with same initial states and periodic boundary conditions are evolved for 200 times respectively by adopting the function Ntþ1 ¼ f ðstx ; g 1 ; g 2 Þ in Matlab software. The source code is shown x in Fig. 3, and the simulating results are illustrated in Fig. 4 (four cases are in Table 4). The figures we obtained in Fig. 4 are similar with the results based on if-else sentences. However, the speed of this calculation shown in Fig. 3 is faster than if-else sentences. In other words, our methods are useful in ECA. 6. Conclusions and discussion In this paper, the analytic function Ntþ1 ¼ f ðstx ; g 1 ; g 2 Þ of the local rules in Elementary Cellular Automata is established by x constructing the recognition function of the states of the cells and the neighbors. Based on the proposed method, the analytic function of the local rules in other 2-state cellular automata is also studied and constructed. The simulation results show that the programming structure is optimized and the programming efficiency is enhanced by the proposed method. It should be noted that our method can be applied in many fields of research including ecosystems, epidemic systems and so on [12–14]. Taking disease transmission as an example, the state of the cells can be denoted as susceptible, exposed or infectious populations, and the rules obey transmission process. In that case, we may obtain the spatial patterns, transmission velocity and final sizes of infectious diseases which in turn guide policy decisions [15–18]. References [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18]
S. Wolfram, Statistical mechanics of cellular automata, Rev. Mod. Phys. 55 (1983) 601–644. S. Wolfram (A New Kind of Science), Wolfram Media, Inc., 2002. G. Martin, Mathematical games, Sci. Am. 223 (1970) 120–123. S. Wolfram (Cellular Automata and Complexity), Perseus Books Group, 2002. W.M. van Ballegooijen, M.C. Boerlijst, Emergent trade-offs and selection for outbreak frequency in spatial epidemics, Proc. Natl. Acad. Sci. USA 101 (2004) 18246–18250. M. Su et al, Spatiotemporal dynamics of the epidemic transmission in a predator-prey system, Bull. Math. Biol. 70 (2008) 2195–2210. G.-Q. Sun et al, Influence of infection rate and migration on extinction of disease in spatial epidemics, J. Theor. Biol. 264 (2010) 95–103. S. Lion, M. van Baalen, Self-structuring in spatial evolutionary ecology, Ecol. Lett. 11 (2008) 277–285. G.-Q. Sun, Z. Jin, L. Li, Emergent turing pattern in epidemic spreading using cellular automaton, Int. J. Mod. Phys. B 25 (2011) 4605–4613. R. Durrett, S.A. Levin, The importance of being discrete (and spatial), Theor. Popul. Biol. 46 (1994) 363–394. R. Durrett, S.A. Levin, Stochastic spatial models-a user guide to ecological applications, Philos. Trans. R. Soc. Lond. B 343 (1994) 329–350. G.-Q. Sun et al, Phase transition in spatial epidemics using cellular automata with noise, Ecol. Res. 26 (2011) 333–340. G.-Q. Sun et al, Spatial patterns of a predator-prey model with cross diffusion, Nonlinear Dyn. 69 (2012) 1631–1638. G.-Q. Sun, J. Zhang, L.-P. Song, Z. Jin, B.-L. Li, Pattern formation of a spatial predator-prey system, Appl. Math. Comput. 218 (2012) 11151–11162. L. Li, G.-Q. Sun, Z. Jin, Emergence of power-law in spatial epidemics using cellular automation, Int. J. Mod. Phy. C 21 (2010) 983–989. S.N. Dorogovtsev, A.V. Goltsev, J.F.F. Mendes, Critical phenomena in complex networks, Rev. Mod. Phys. 80 (2008) 1275–1335. L.B.L. Santos et al, Periodic forcing in a three-level cellular automata model for a vector-transmitted disease, Phys. Rev. E 80 (2009) 016102. M.D.F. Shirley, S.P. Rushton, The impacts of network topology on disease spread, Ecol. Complex 2 (2005) 287–299.