Dynamics of Langton's ant allowed to periodically go straight
DDynamics of Langton’s ant allowed to periodically gostraight
Pawe(cid:32)l Tokarz a, ∗ a Molecular Spectroscopy Laboratory, Faculty of Chemistry, University of Lodz, Tamka 12,91-403 Lodz, Poland
Abstract
A modified version of Langton’s ant is considered. The modified automaton isallowed to go straight N -th step instead of turning. The cell state, however,is changed as usually. Depending on the value of N the automaton exhibitsdifferent behaviors. Since the Cohen-Kung theorem is not applicable to thismodified rule set, in most cases oscillating patterns are observed. For severalvalues of N the automaton leads to a creation of a highway. More interestingly,a few of the automata were found to exhibit a long-term chaotic behavior,exceeding even 10 steps. The analysis of the dynamics of the system andemergent patterns is provided. Keywords: L angton’s ant, cellular automata, chaos
1. Introduction
Langton’s ant is one of the most recognizable cellular automata, introducedby Langton in 1986[1]. It consists of an infinite rectangular grid of cells whereeach is in one of two possible states – black or white. Additionally, an agentcalled ‘an an’ walks on that grid in cardinal directions (up, right, down or left).Upon entering a black cell the ant turns 90 ° clockwise and upon entering a whitecell – 90 ° counterclockwise. Then the ant switches the state of the cell and goesone step in a selected direction. Despite the set of rules is very simple the ∗ Corresponding author
Email address: [email protected] (Pawe(cid:32)l Tokarz)
Preprint submitted to Communications in Nonlinear Science and Numerical SimulationJuly 25, 2018 a r X i v : . [ n li n . C G ] J u l nt exhibits complex behavior. After initial symmetric and then pseudorandommovements, the ant starts to build a highway – an infinite patterned strip ina diagonal direction with periodicity τ h = 104 steps. Despite it has not beenrigorously proven whether the ant builds the highway regardless of the finiteinitial configuration, it has been shown that the trajectory of Langton’s ant isalways unbounded – the result known as Cohen-Kung theorem[2].The chaotic nature of the Langton’s ant behavior found several applica-tions, i.a. pseudo-random number generation[3] and image encryption[4]. Onthe other hand, since the automaton is Turing-complete, its ability to performcalculations was used for example to solve the Lights Out game[5].Several attempts have been made to generalize the algorithm. One of themost common modifications is an introduction of more than just two states. Thestate of a cell is incremented every time the ant visits the cell. Whether the antturns left or right after encountering the cell depends on a predefined rule stringwhich binds a particular state to a particular turn[6, 7]. Another modificationwas to introduce a special cell state – a grey one – at which the ant always goesstraight and do not change that state[8]. An interesting case of emergent tracksproduced by ant which movement is enforced by binary sequences was reportedas well[9].Herein, a new modification is presented. The set of rules is nearly identicalwith the original Langton’s formulation with the single exception that at every N th step the ant does not turn but goes straight through the entered cell (how-ever, the cell state is switched as usually). This simple modification appearsto completely change the behavior of the ant. Since the Cohen-Kong theoremno longer holds, the movement of the ant does not have to be unbounded. Infact, several oscillating patterns have been observed. It is clear that the originalLangston’s ant could be obtained from this generalization by setting an infinitevalue of N . For the sake of clarity the ant characterized by a given N valuewill be written as an N -ant, e.g. 6-ant. The aim of the article is to presenta general picture of the dynamics of the behavior of the N -ants to establish abase for a further comprehensive research ( e.g. on N -ant-based generators of2 igure 1: Left: Langton’s ant after 11 000 steps. Right: an example of proposed modifiedant (6-ant) after 10 steps. The grey color indicates the unvisited area. The ant do notdistinguish between black and grey. pseud-random numbers).
2. Calculations
In all cases the simulation was started with a completely blank grid, withthe ant oriented up. The simulations were generally run for no longer than 10 steps with two exceptions: 6-ant was investigated up to 10 steps and 50-antwas investigated for about 2 . · steps, at which point a cycle was found(see the Results section).The article concerns cases for N ≤ c = 1.2. Check the step counter. If N | c then go directly to the point 4.3. If the cell state is black – turn left; if it’s white – turn right.4. Switch the cell state.5. Move one cell forward. 3. Increment the counter by one and go back to the point 2.Simulations were done on PC with Intel i3 processor. Since the algorithm fora single ant is rather not parallelizable, different N -ants were simulated simul-taneously on different cores running other instances of the same program. Thesimulation itself was written in C and compiled with the GNU g++ compiler[10].Simulating 10 steps took several hours, simulating 10 steps took about 4-6 days. The density maps were generated by a script written in Processinglanguage[11] from data dumps generated by the C program. In all cases thesum of the visits of all cells on a dumped and read density map was checkedagainst the actual number of steps performed by the original C program con-firming the integrity of the map generation protocol.
3. Results
After running the simulations, it has been found that most of the tested antseventually produce either an oscillator (meaning that after a certain number ofsteps τ o , different for different N -ants, they come back to the initial blankconfiguration of the board and start the cycle again) of a highway (analogicallyto the original Langton’s ant). Several N -ants, however, did not produce eitherbehavior during the steps limit (10 ). In this paper they are referred to as long-term chaotic . Highways.
The original Langton’s ant (infinite N ) can be considered as a classof N -ants eventually building a highway. Starting from a blank configurationthe highway begins after s h = 9977 steps. The period of the highway is equal to τ h = 104. For N -ants with finite N the simplest highway is obviously producedby 1-ant, which never turns and immediately starts to draw a straight lane ofblack cells. 2-ant and 3-ant produce patterns similar to the original Langton’sant with the exception that 2-ant pattern is twice as wide and twice as high,while 3-ant pattern is just twice as high with unchanged width. Their periodsare τ h = 208 and τ h = 156 respectively.4 a) N = 1 (b) N = 2 (c) N = 3 (d) N = 4 (e) N = 5(f) N = 10 (g) N = 17 (h) N = 19 (i) N = 24 (j) N = 41Figure 2: All the highways found for N <
50. The red triangle represents the ant and itsdirection.
The 4-ant produces a very simple, three-cells wide highway with τ h = 8 thatstarts at fourth step and heads up. Interestingly, the 41-ant creates a rathersimple highway whose period takes only 2 N steps ( τ h = 82 = 2 N ), but ittakes as long as 280 085 922 steps of pseudorandom walk to enter it. Anotherimportant case is the 99-ant for which after the 100 365 745 steps the ant starts ahighway with period equal to N ( τ h = N = 99), which is the only such examplefound, excluding the trivial 1-ant). No highway was found for N ∈ < , > .Graphical representations of the highways are presented on the Figure 2 and thecorresponding numerical data are collected in the Table 1. Oscillators.
While, regardless of the starting pattern, the Langton’s ant neverproduces an oscillator, the evolution of most of the N -ants leads to oscillatingpatterns. This is true for at least 171 out of the first 200 N -ants. Since the N -ant automaton is obviously reversible it is trivial to notice that any oscillatingstructure must periodically come back to the initial configuration. Thus, tofind the periods τ o of the oscillators it was sufficient to run each simulationuntil all the cells have been turned black by the ant. This was done by simply5 s h τ h N s h τ h Table 1: Highways data. s h – step at which the ant starts to build the highway; τ h – highway’speriod. More data is provided in the supplementary material. tracking the number of the white cells. The period varies significantly – from τ o = 34 980 steps for N = 15 to even τ o = 2 471 414 288 401 steps in the case of N = 50. However, even the shortest oscillator period is significantly longer thanthe length of the chaotic walk of the Langton’s ant ( s h = 9 977). No connectionbetween N and τ o was found.The typical evolution of the oscillating pattern consists of eight phases. Thefirst phase is a seemingly chaotic movement, similar to that of the first 10 000steps of the Langton’s ant. At some point p the ant encounters a local configu-ration that guides the ant on the previously visited track but with the reverseddirection, starting the phase 2. Due to the reversibility of the automaton, theant erases all the white cells beside the fragment that guided it backwards,eventually at point p leaving board almost entirely black. The ant is now atthe initial position but heading a direction opposite to that it had at start.Moreover, since the ant has exactly followed backwards its own track and theautomaton was started with counter = 1 the next step after passing the initialposition will correspond to the counter = 0. Thus, the ant will start anotherphase with a straight move – differently from the first phase. The third phasethat has just begun is again chaotic as long as at some point p another localconfiguration will guide the ant backward on its own track – starting the fourthphase. The phase, somehow analogous to the second one, leads again to almost6 igure 3: Evolution of a typical oscillator – the 66-ant (see the text for explanations). Moreexample charts are provided in a supplementary material. complete erasure of the white cells beside the first (possibly modified) and thesecond local guiding configuration. The phase ends at point p = τ o with theant at initial position and heading the same direction as at the begining of thewhole evolution. The ant starts again to behave exactly as it was in the veryfirst phase, until it again reaches the first guiding configuration. The followingfour phases resemble the first four with the exception that this time the guidingconfigurations are not created but erased. Finally, the ant ends up on a blankarray and the whole cycle starts to repeat. Long-term chaotic.
During the initial systematic analysis the first fifty N -ants( N ∈ < , > ) were run for at most 10 steps. For this range of the N valuesand within the steps limit neither period nor highway was observed for 6-antand 50-ant. Thus, the steps limits for these two simulations were extended to10 steps. The 50-ant was found to form an oscillator with a period of τ o =2 471 414 288 401. Nevertheless, still neither period nor highway was observed for6-ant. Interestingly, for these 10 steps the 6-ant was found to reside almost7xclusively inside a small 200x200 area. This result is rather exceptional forsuch a simple modification of the Langton’s ant and suggests a possibility toexploit the automaton in further research on CA-based pesudo-random numbergenerators. It remains unknown why exactly this ant produces such an amountof chaos, since other ants with small N rather quickly oscillate or fall to ahighway. Beyond the N = 50 the ants were simulated up to 10 steps withoutexceptions. For this steps limit the long-term chaotic dynamics were observedfor sixteen ants ( N = 102, 109, 128, 133, 134, 143, 150, 153, 165, 170, 184, 186,188, 195, 197 and 198). Heat maps.
To investigate the structural properties of the N -ants dynamics theheat maps were generated by counting the number of times the ant visited aparticular cell. The data were transformed into a colored map with logarithmicscale. Blue color represents no visits, while red – the maximum number of visits(different for each ant). For oscillating ants the map was generated after a fullcycle, for ants forming the highways – after the ant left the 600x600 board andfor long-term oscillators – after 10 steps (10 in the case of 6-ant).Several types of maps have been observed. Some ants produced smooth,fuzzy maps, suggesting that their behavior is highly isotropic, without distin-guishable emergent structure. A good example is 128-ant. On the other handthere are ants (e.g. 6-ant) for which the heat maps show that the visit den-sity follows some gridded, rectangular pattern, resembling something between alabyrinth and a chessboard. Many other ants (like 50-ant) show cloudy struc-tures – the map is not smooth but no grid is visible either. Finally, relativelysmall number of ants (like 120-ant) draws a hilly heat map with clearly visibleregions with high density separated by valleys and saddles. For a given mapthe assignment to one of these classes might be arbitrary, since many of themexhibit mixed behaviors, however the existence of these different behaviors isclear.Interestingly, the heat maps clearly show, that all of the N -ants tend to visitthe same areas multiple times, even if no oscillator has been produced (yet). As8 a) N = 128 – smooth (b) N = 6 – gridded (c) N = 50 – cloudy (d) N = 120 hillyFigure 4: Types of observed maps: smooth ( N = 128), gridded ( N = 6), cloudy ( N = 50)and hilly ( N = 120). The light rectangle marks the 200x200 area centered on the startingposition. an example a ‘coast’ of the 186-ant density map is shown on a picture. Mostof the border of the visited area is green, meaning that the ant has visited theborder many times. Figure 5: Part of the north coast of the 186-ant, exhibiting typical, many times visited borderand a small, rarely visited region on the right (light blue cloud).
This green coast is adjacent to the unvisited area, meaning that there is nosmooth transition between the visited and unvisited regions. On the right sideof the coast there is a rarely observed example a the coast region with smallnumber of visits, drawn in light blue.The prevailing existence of a sharp border between the visited and unvisitedregions implies that N -ants often follow their previous paths which makes them9ompletely distinct from simple random walkers. This corresponds with the factthat many of them form oscillators (requiring walking backwards on own trace).On the other hand, any attempts to use N -ants as pseudo-random numbergenerators this might lead to security loopholes – even in non-oscillating regimethe N -ants behavior might exhibit some degree of periodicity.Despite the heat maps are useful for fast visual analysis they provide nonumerical values to show exactly how often an ant walks on the border of thevisited region. This might be, however, expressed as an average number ofvisits on the border, where the border is defined as all cells that have at leastone unvisited neighbor. The data shown in Table 2 clearly demonstrate that N -ants visit the border much more often than it would be expected for purerandom walk. For example after 10 steps the average number of visits at theborder cells for 6-ant exceeds 36 000 while the neighboring cells remain unvisited(Table 2). N c A V a L V c
20 635 48 461 352.00 967 36 557.167 6 032 124 2 922 2 064.38 307 40.258 1 038 238 912 4 685 221 609.16 378 9 340.889 1 620 252 1 542 1 050.75 193 47.8850 10
57 216 17 477 628.00 1 738 7 893.4877 176 792 1311 134.85 174 9.94
Table 2: Example data showing the ’walk on the border’ behavior. c – counter (number ofsteps), A – total visited area, L – coast line length, V a – average number of visits per cell, V c – average number of visits per border cells.
4. Conclusions
Allowing the Langton’s ant to periodically avoid turning at each N -th stepsignificantly changes the behavior of the automaton. Among the tested N -10nts ( N ∈ < , > ) at least 171 produce oscillating patterns with periods τ o varying from τ o = 34 980 ( N = 15) to τ o = 2 471 414 288 401 ( N = 50).Several other N -ants eventually fall into a highway mode (this is especiallytrue for small values of N , particularly for all cases of N < N -ants that generate neither oscillator nor highway foras long as 10 steps. Nevertheless, even these long-term chaotic ants do notsimply diffuse from the starting point but their movement remains confined in asmall area. An exceptionally interesting case is the 6-ant, since it is the simplestlong-term chaotic ant (the next one is 50-ant). It produces a pseudo-randomwalk for at least 10 steps while almost exclusively residing inside a 200x200area. Moreover, the map of the density of visits per cell for this ant exhibits ahighly structured pattern.A further research on exploiting the N -ants as a pseudo-random numbergenerators could led to beneficial results due to their simplicity and relativelylarge amount of chaos generated, when compared to the Langton’s ant. More-over, analysis of cases of high values of N might also provide interesting results,possibly especially for N values exceeding the length of the chaotic walk of theLangton’s ant (about 10 steps).
5. Acknowledgements
The members of the ’Dzetawka’ society, especially Micha(cid:32)l Zapa(cid:32)la, are kindlyacknowledged for fruitful discussions related to the topic. I would also like tothank to my wife, Paulina, for careful reading of the manuscript.
References [1] C. G. Langton, Studying artificial life with cellular automata, Phys. D 2 (1-3) (1986) 120–149.URL http://dl.acm.org/citation.cfm?id=25201.25210 [2] I. Stewart, The ultimate in anty-particles, Mathematical Recreations 271(1994) 104107. 11RL [3] S. M. Hosseini, H. Karimi, M. V. Jahan, Generating pseudo-randomnumbers by combining two systems with complex behaviors, Journalof Information Security and Applications 19 (2) (2014) 149 – 162. doi:https://doi.org/10.1016/j.jisa.2014.01.001 .URL [4] X. Wang, D. Xu, A novel image encryption scheme using chaos and lang-ton’s ant cellular automaton, Nonlinear Dynamics 79 (4) (2015) 2449–2456. doi:10.1007/s11071-014-1824-0 .URL https://doi.org/10.1007/s11071-014-1824-0 [5] C. Arangala, Langton’s turmite meets lights out, Complexity 21 (5) (2016)155–161. doi:10.1002/cplx.21643 .URL http://dx.doi.org/10.1002/cplx.21643 [6] J. Propp, Mathematical entertainments, The Mathematical Intelligencer16 (1) (1994) 37–44. doi:10.1007/BF03026614 .URL https://doi.org/10.1007/BF03026614 [7] D. Gale, J. Propp, S. Sutherland, S. Troubetzkoy, Mathematical enter-tainments, The Mathematical Intelligencer 17 (3) (1995) 48–56. doi:10.1007/BF03024370 .URL https://doi.org/10.1007/BF03024370 [8] D. Gale, Mathematical entertainments, The Mathematical Intelligencer15 (2) (1993) 54–58. doi:10.1007/BF03024194 .URL https://doi.org/10.1007/BF03024194 [9] M. Markus, M. Schmick, E. Goles, Tracks emerging by forcing langton’sant with binary sequences, Complexity 11 (3) (2006) 27–32. doi:10.1002/ plx.20111 .URL http://dx.doi.org/10.1002/cplx.20111 [10] R. M. e. a. Stallman, Using the gnu compiler collection.URL [11] B. Fry, C. Reas, Processing library for visual arts and design.URL