Cellular/Automata/Wolfram version 1.0 ===================================== ABSTRACT Dr. Steven Wolfram describes in his book, A New Kind of Science, ISBN:1-57955-008-8 his path-breaking experiment where he comprehensively explored a mathematical function which can be described (by me see the reference for a detailed explanation) as follows: Given an 1d array of numbers A: [0,0,0,0,0,0,0,1,0,0,0,0,0,0,0] Call this generation 1 (i.e. t). Generation 2 (i.e. t+1) will be created by applying a rule to each number of the form A(i)(t+1) = rules(A(i-1)(t),A(i)(t),A(i+1)(t)), where A(i)(t) is the current value at position i for generation t in the array, and A(i)(t+1) is the next generations value of A(i). For an array limited to 0 and 1 as possible values in each position the complete rules function can be described as follows: Given array rule_input: [111,110,101,100,011,010,001,000] This is all the possible values that can be given as inputs to the rule function for an 0,1 array of numbers. The return for the rule function can be defined as follows: [111,110,101,100,011,010,001,000] | | | | | | | | 0 1 1 0 1 1 1 0 This number 01101110 can be treated as a decimal number expressed as 110, as the result of the following standard binary to decimal formula. 0x128+1x64+1x32+0x16+1x8+1x4+1x2+0x1 = 110. This number 110 can be used to define the entire rules function that is needed to determine the next generation. Since all the possbile rules can be described from a eight digit binary number they run from 0 to 255 decimal, each number describes a different rules function and every possible rules function for an array limited to 0 and 1 and whose input is three values drawn from that array. The three values are chosen in the formula descibed above. The choice of i-1, the left adjacent cell, and, i+1, the right adjacent cell, as the number of left and right ajacent cells to consider for the next generation can be defined as radius R. The number of values each cell can take can be described as K (in drawing the number of colors). The examples short description is therefore (rule 110, K=2,R=1). This module allows you to explore every one dimensional cellular automata for any valid rule for a given K and R. The array wraps by default. The result of rule 110 with K=2 [0,1] R=1 for 80 generations in an array of K values width 80 where the values wrap: 00000000000000000000000000000000000000010000000000000000000000000000000000000000 00000000000000000000000000000000000000110000000000000000000000000000000000000000 00000000000000000000000000000000000001110000000000000000000000000000000000000000 00000000000000000000000000000000000011010000000000000000000000000000000000000000 00000000000000000000000000000000000111110000000000000000000000000000000000000000 00000000000000000000000000000000001100010000000000000000000000000000000000000000 00000000000000000000000000000000011100110000000000000000000000000000000000000000 00000000000000000000000000000000110101110000000000000000000000000000000000000000 00000000000000000000000000000001111111010000000000000000000000000000000000000000 00000000000000000000000000000011000001110000000000000000000000000000000000000000 00000000000000000000000000000111000011010000000000000000000000000000000000000000 00000000000000000000000000001101000111110000000000000000000000000000000000000000 00000000000000000000000000011111001100010000000000000000000000000000000000000000 00000000000000000000000000110001011100110000000000000000000000000000000000000000 00000000000000000000000001110011110101110000000000000000000000000000000000000000 00000000000000000000000011010110011111010000000000000000000000000000000000000000 00000000000000000000000111111110110001110000000000000000000000000000000000000000 00000000000000000000001100000011110011010000000000000000000000000000000000000000 00000000000000000000011100000110010111110000000000000000000000000000000000000000 00000000000000000000110100001110111100010000000000000000000000000000000000000000 00000000000000000001111100011011100100110000000000000000000000000000000000000000 00000000000000000011000100111110101101110000000000000000000000000000000000000000 00000000000000000111001101100011111111010000000000000000000000000000000000000000 00000000000000001101011111100110000001110000000000000000000000000000000000000000 00000000000000011111110000101110000011010000000000000000000000000000000000000000 00000000000000110000010001111010000111110000000000000000000000000000000000000000 00000000000001110000110011001110001100010000000000000000000000000000000000000000 00000000000011010001110111011010011100110000000000000000000000000000000000000000 00000000000111110011011101111110110101110000000000000000000000000000000000000000 00000000001100010111110111000011111111010000000000000000000000000000000000000000 00000000011100111100011101000110000001110000000000000000000000000000000000000000 00000000110101100100110111001110000011010000000000000000000000000000000000000000 00000001111111101101111101011010000111110000000000000000000000000000000000000000 00000011000000111111000111111110001100010000000000000000000000000000000000000000 00000111000001100001001100000010011100110000000000000000000000000000000000000000 00001101000011100011011100000110110101110000000000000000000000000000000000000000 00011111000110100111110100001111111111010000000000000000000000000000000000000000 00110001001111101100011100011000000001110000000000000000000000000000000000000000 01110011011000111100110100111000000011010000000000000000000000000000000000000000 11010111111001100101111101101000000111110000000000000000000000000000000000000000 11111100001011101111000111111000001100010000000000000000000000000000000000000001 00000100011110111001001100001000011100110000000000000000000000000000000000000011 00001100110011101011011100011000110101110000000000000000000000000000000000000111 00011101110110111111110100111001111111010000000000000000000000000000000000001101 00110111011111100000011101101011000001110000000000000000000000000000000000011111 01111101110000100000110111111111000011010000000000000000000000000000000000110001 11000111010001100001111100000001000111110000000000000000000000000000000001110011 01001101110011100011000100000011001100010000000000000000000000000000000011010110 11011111010110100111001100000111011100110000000000000000000000000000000111111110 11110001111111101101011100001101110101110000000000000000000000000000001100000011 00010011000000111111110100011111011111010000000000000000000000000000011100000110 00110111000001100000011100110001110001110000000000000000000000000000110100001110 01111101000011100000110101110011010011010000000000000000000000000001111100011010 11000111000110100001111111010111110111110000000000000000000000000011000100111110 11001101001111100011000001111100011100010000000000000000000000000111001101100011 01011111011000100111000011000100110100110000000000000000000000001101011111100110 11110001111001101101000111001101111101110000000000000000000000011111110000101110 10010011001011111111001101011111000111010000000000000000000000110000010001111011 10110111011110000001011111110001001101110000000000000000000001110000110011001110 11111101110010000011110000010011011111010000000000000000000011010001110111011011 00000111010110000110010000110111110001110000000000000000000111110011011101111110 00001101111110001110110001111100010011010000000000000000001100010111110111000010 00011111000010011011110011000100110111110000000000000000011100111100011101000110 00110001000110111110010111001101111100010000000000000000110101100100110111001110 01110011001111100010111101011111000100110000000000000001111111101101111101011010 11010111011000100111100111110001001101110000000000000011000000111111000111111110 11111101111001101100101100010011011111010000000000000111000001100001001100000011 00000111001011111101111100110111110001110000000000001101000011100011011100000110 00001101011110000111000101111100010011010000000000011111000110100111110100001110 00011111110010001101001111000100110111110000000000110001001111101100011100011010 00110000010110011111011001001101111100010000000001110011011000111100110100111110 01110000111110110001111011011111000100110000000011010111111001100101111101100010 11010001100011110011001111110001001101110000000111111100001011101111000111100110 11110011100110010111011000010011011111010000001100000100011110111001001100101111 00010110101110111101111000110111110001110000011100001100110011101011011101111000 00111111111011100111001001111100010011010000110100011101110110111111110111001000 01100000001110101101011011000100110111110001111100110111011111100000011101011000 11100000011011111111111111001101111100010011000101111101110000100000110111111000 10100000111110000000000001011111000100110111001111000111010001100001111100001001 11100001100010000000000011110001001101111101011001001101110011100011000100011011 00100011100110000000000110010011011111000111111011011111010110100111001100111110 01100110101110000000001110110111110001001100001111110001111111101101011101100010 This program has the following hash as its default values: {rule=>110,radius=>1,width=>80,num_of_gens=>100,random=>"",colors=>[white,black],draw_file=>'wolfram.png'} This hash can be overidden in the constructor. For example: use Cellular::Automata::Wolfram; my $caw = new Cellular::Automata::Wolfram( rule=>255,colors=>[red,blue]); Any of the defaults can be overwitten. The defaults are defined as follows: rule=The number which defines the rules for this automata. radius=The number of left and right adjacent cells to be passed to the rule function. width=The width of the inital array. num_of_gens=How many generations this automata will run. random=If a perl false value ("",0), then start with a single cell e.g. 0001000, if a true valve then a random startup e.g. 1101010 colors=An anonymous hash containing color names from the module Graphics::ColorNames, this is used for drawing and to set the number of states K of the cellular automata. draw_file=The file that will contain the png drawing which represents the cellular automata. use Cellular::Automata::Wolfram; my $caw = new Cellular::Automata::Wolfram(); my $rule = $caw->rule(); print "$rule\n"; # prints 110, the default. $rule = 90; $caw->rule($rule); # sets rule to 90 $caw->generate(); # generates the result with the new rule. $caw->draw(); # Writes out to the wolfram.png # the image of the new automata. INSTALLATION To install this module type the following: perl Makefile.PL make make test make install THE LATEST VERSION IS 1.00 DEPENDENCIES This module requires these other modules and libraries: Lincoln Stein's GD.pm, version 2.05 http://search.cpan.org/author/LDS/GD-2.05/ Ken Williams' Math::BaseCalc, version 1.011 http://search.cpan.org/author/KWILLIAMS/Math-Base-Calc-1.011/ Robert Rothenberg's Graphics::ColorNames, version 0.31 http://search.cpan.org/author/RRWO/Graphics-Color-Names-0.31/ Martyn J. Pearce's Class::MethodMaker, version 1.08 http://search.cpan.org/author/FLUFFY/Class-Method-Maker-1.08/ COPYRIGHT AND LICENCE Copyright (c) 2002, James M. Freeman II, All Rights Reserved. This module is free sofware. It may be used, redistributed and/or modified under the same terms as Perl itself. ACKNOWLEDGEMENTS: I would like to thank Dr. Steven Wolfram for his groundbreaking Cellular Automata work without which this module could not be possible. I would also like to thank members of Boston Perl Mongers (http://boston.pm.org) for their commentary and suggestions when I presented the beta version of this module to them at the September 2002 meeting. UPDATES: The current version of Cellular::Automata::Wolfram can be found in CPAN. AUTHOR: James M. Freeman II jmfreeman@attbi.com,racecarradar@yahoo.com