wolframscience.com

A New Kind of Science: The NKS Forum : Powered by vBulletin version 2.3.0 A New Kind of Science: The NKS Forum > Pure NKS > Difference between the code and the rule
  Last Thread   Next Thread
Author
Thread Post New Thread    Post A Reply
M.Abdeldjalil


Registered: Nov 2008
Posts: 39

Difference between the code and the rule

Hello,

For 2-D CA, is the code has the same sense of rule?
For example, the code 454 is the same rule 454. If it's, i can't obtain it's schema, i obtained this schema with the rule 454(111000110).

M.Abdeldjalil has attached this image:

Report this post to a moderator | IP: Logged

Old Post 03-03-2009 08:49 PM
M.Abdeldjalil is offline Click Here to See the Profile for M.Abdeldjalil Visit M.Abdeldjalil's homepage! Edit/Delete Message Reply w/Quote
M.Abdeldjalil


Registered: Nov 2008
Posts: 39

the same rule 454 in more steps

M.Abdeldjalil has attached this image:

Report this post to a moderator | IP: Logged

Old Post 03-03-2009 10:12 PM
M.Abdeldjalil is offline Click Here to See the Profile for M.Abdeldjalil Visit M.Abdeldjalil's homepage! Edit/Delete Message Reply w/Quote
Jason Cawley
Wolfram Science Group
Phoenix, AZ USA

Registered: Aug 2003
Posts: 712

They are outer totalistic rules, but sure code and rule refer to the same thing.

There are 10 cases in the rule table, you only give 9. (454 has a leading 0 case).

Rule 454 means with the input sides -

Tuples[{{4, 3, 2, 1, 0}, {1, 0}}]

and the output sides -

IntegerDigits[454, 2, 10]

The full mapping is then -

Rule @@@ Transpose[{Tuples[{{4, 3, 2, 1, 0}, {1, 0}}]
   IntegerDigits[454, 2, 10]}]


which evaluates to this rule list -

{{4, 1} -> 0, {4, 0} -> 1, 
{3, 1} -> 1, {3, 0} -> 1, 
{2, 1} ->  0, {2, 0} -> 0, 
{1, 1} -> 0, {1, 0} -> 1, 
{0, 1} -> 1, {0, 0} -> 0}


The built in function version of this rule can be run as e.g. -

data1 = CellularAutomaton[{454, {2, {{0, 2, 0}, {2, 1, 2}, {0, 2, 0}}}, {1,  1}}, {{{1}}, 0}, 20];

ArrayPlot[Last[data1]]

To use the rule table above, instead, you must construct the outer totals in a function e.g.

myCARule[neighborhood_] := 
 With[{rulelist =  
    Rule @@@ 
     Transpose[{Tuples[{{4, 3, 2, 1, 0}, {1, 0}}]
       IntegerDigits[454, 2, 10]}]}, 
  {neighborhood[[1, 2]] + neighborhood[[2, 1]] + 
     neighborhood[[2, 3]] + neighborhood[[3, 2]]
    neighborhood[[2, 2]]} /. rulelist
  ]

then you'd evaluate that in the functional form of the CA function as -

ArrayPlot[Last[#]] &@
 CellularAutomaton[{myCARule[#] &, {}, {1, 1}}, {{{1}}, 0}, 20]


Output checks. That is the scheme being used.

Report this post to a moderator | IP: Logged

Old Post 03-03-2009 10:17 PM
Jason Cawley is offline Click Here to See the Profile for Jason Cawley Click here to Send Jason Cawley a Private Message Edit/Delete Message Reply w/Quote
Jason Cawley
Wolfram Science Group
Phoenix, AZ USA

Registered: Aug 2003
Posts: 712

Sorry I have no idea what you are doing to get those evolutions, really. You associated the 454 code with a 9 digit binary number, rather than a 10 digit one - perhaps you meant the leading 0 to be understood implicitly. Your evolutions cannot be outer totalistic because they lack its characteristic symmetries. But a 2D 2 color range 1 CA without such symmetries has a lot more than 10 binary digits in its rule, because there are many more than 10 cases it is rule table. 32 with in the 5 neighbor case.

Report this post to a moderator | IP: Logged

Old Post 03-03-2009 10:28 PM
Jason Cawley is offline Click Here to See the Profile for Jason Cawley Click here to Send Jason Cawley a Private Message Edit/Delete Message Reply w/Quote
M.Abdeldjalil


Registered: Nov 2008
Posts: 39

Please can you tell some Doc about this language :
myCARule[neighborhood_] :=
With[{rulelist =
Rule @@@
Transpose[{Tuples[{{4, 3, 2, 1, 0}, {1, 0}}],
IntegerDigits[454, 2, 10]}]},
{neighborhood[[1, 2]] + neighborhood[[2, 1]] +
neighborhood[[2, 3]] + neighborhood[[3, 2]],
neighborhood[[2, 2]]} /. rulelist
]

I develop with java,so i haven't any idea about this language.

Report this post to a moderator | IP: Logged

Old Post 03-04-2009 09:18 AM
M.Abdeldjalil is offline Click Here to See the Profile for M.Abdeldjalil Visit M.Abdeldjalil's homepage! Edit/Delete Message Reply w/Quote
Jason Cawley
Wolfram Science Group
Phoenix, AZ USA

Registered: Aug 2003
Posts: 712

It is Mathematica code, if that wasn't clear.

myCARule is a (new, arbitrary) function name for the function I was writing. It is being told to take a single argument and call it "neighborhood". It will in fact be passed the local neighborhood for each updating cell, in the form of a 3x3 array of site values. That is its input.

The := means "SetDelayed", and is the usual way of specifying a function in Mathematica.

The With function simply sets a local variable that is treated as a constant for the remainder of the function. You could just as easily have that set outside, or passed in as an additional variable, or use a Module and make the assignment on a previous line within it.

The Rule@@@Transpose construction is just a way of pairing up the left hand side "rule cases" with the right hand side "new site values". The Tuples and IntegerDigits functions make those. That entire assignment boils down to making the rulelist -

{{4, 1} -> 0, {4, 0} -> 1, 
{3, 1} -> 1, {3, 0} -> 1, 
{2, 1} ->  0, {2, 0} -> 0, 
{1, 1} -> 0, {1, 0} -> 1, 
{0, 1} -> 1, {0, 0} -> 0}


So it can be replaced by that list explicitly or anything else that passes that information to the function.

The main body of the myCARule function just says, take these various parts of the neighborhood you were passed, add up four of them and put those in the first position, and put the central one in the second position. This is making an ordered pair of the form {outertotal, centercellvalue}. Then apply the rulelist above to that ordered pair.

The "/." (slash-dot) syntax stands for ReplaceAll, and applies the list of replacement rules (stored in rulelist) to the ordered pair.

The ordered pair making, itself, is using a function called Part, which simply picks off the specified pieces of any array or other nested expression. Thus neighborhood[[1,2]] means the second column on the first row of the 3x3 neighborhood. Four such specific positions are added together to form the outer total, that is the first element of the ordered pair. The second element is simple the center cell value, neighborhood[[2,2]].

When this function is used within CellularAutomaton, what is happening is CellularAutomaton is forming little neighborhood arrays around each site (effectively like Partition) and passing them to myCARule. myCARule takes each 3x3 array it gets and turns it into the correct new site value for the center cell. CellularAutomaton uses the new array of those new site values for its next step.

You can obviously reproduce this division of labor in java or C etc, though it is most natural in Mathematica, since it is using various built in functions to do much of the work. Here, CellularAutomaton for the control loop and local neighborhood making and full array updating, and things like ReplaceAll to quickly apply a list of replacement rules to an individual ordered pair. Also functions like Tuples and IntegerDigits to rapidly make the right list of replacement rules for any given rule number.

I hope this helps.

Report this post to a moderator | IP: Logged

Old Post 03-04-2009 01:33 PM
Jason Cawley is offline Click Here to See the Profile for Jason Cawley Click here to Send Jason Cawley a Private Message Edit/Delete Message Reply w/Quote
Post New Thread    Post A Reply
  Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread


 

wolframscience.com  |  wolfram atlas  |  NKS online  |  web resources  |  contact us

Forum Sponsored by Wolfram Research

© 2004-13 Wolfram Research, Inc. | Powered by vBulletin 2.3.0 © 2000-2002 Jelsoft Enterprises, Ltd. | Disclaimer | Archives