Git Product home page Git Product logo

catemplates's Introduction

CATemplates

CATemplates is a Mathematica package that enables the use of Cellular Automaton (CA) templates, as first described in Representing Families of Cellular Automata Rules.

A Cellular Automaton template allows one to represent potentially huge CA sets through a lightweight data structure, and defer their enumeration to a moment when the rules are really needed.

The CATemplates package provides ways to create user-defined raw templates, along with built-in generator functions able to create templates for rule sets that share a given static property. It also includes operations capable of manipulating templates and enumerating the sets they represent.

Usage

(* Import the CATemplates package after installation *)
In[0] = <<CATemplates`;

(* Generate a template for all elementary colorblind CAs *)
In[1] = tColorblind = ColorBlindTemplate[2, 1.0];

(* Expand tColorblind to get all 16 rule tables of the colorblind elementary CAs (in k-ary form)*)
In[2] = ExpandTemplate[tColorblind]
Out[2] = {{1,1,1,1,0,0,0,0},{0,1,1,1,0,0,0,1},{1,0,1,1,0,0,1,0},{0,0,1,1,0,0,1,1},{1,1,0,1,0,1,0,0},{0,1,0,1,0,1,0,1},{1,0,0,1,0,1,1,0},{0,0,0,1,0,1,1,1},{1,1,1,0,1,0,0,0},{0,1,1,0,1,0,0,1},{1,0,1,0,1,0,1,0},{0,0,1,0,1,0,1,1},{1,1,0,0,1,1,0,0},{0,1,0,0,1,1,0,1},{1,0,0,0,1,1,1,0},{0,0,0,0,1,1,1,1}}

(* Generate a template for all elementary totalistic rules *)
In[3] = tTotalistic = TotalisticTemplate[2, 1.0];

(* Expand tTotalistic to get all of the 16 totalistic elementary CAs*)
In[4] = ExpandTemplate[tTotalistic]
Out[4] = {{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,1},{0,0,0,1,0,1,1,0},{0,0,0,1,0,1,1,1},{0,1,1,0,1,0,0,0},{0,1,1,0,1,0,0,1},{0,1,1,1,1,1,1,0},{0,1,1,1,1,1,1,1},{1,0,0,0,0,0,0,0},{1,0,0,0,0,0,0,1},{1,0,0,1,0,1,1,0},{1,0,0,1,0,1,1,1},{1,1,1,0,1,0,0,0},{1,1,1,0,1,0,0,1},{1,1,1,1,1,1,1,0},{1,1,1,1,1,1,1,1}}

(* Intersect both templates *)
In[5] = tTotalisticAndColorblind = TemplateIntersection[tColorblind, tTotalistic];

(* Expanding the intersection template renders only the elementary rules which are both totalistic and colorblind *)
In[6] = ExpandTemplate[tTotalisticAndColorblind]
Out[6] = {{1,1,1,0,1,0,0,0},{0,1,1,0,1,0,0,1},{1,0,0,1,0,1,1,0},{0,0,0,1,0,1,1,1}}

(* Here is where things get fun!
   We can generate templates for bigger (potentially huge) spaces.
   Let's try to increase r a little: *)
In[7] = $RecursionLimit = Infinity; tr5 = With[{k=2, r=5.0}, TemplateIntersection[ColorBlindTemplate[k, r], TotalisticTemplate[k, r]]];

(* Note we just found templates representatives of all binary radius 5.0 colorblind rules,
   did the same for totalistic rules and intersected the sets.
   All of this executed in 4.52314 seconds on my notebook. 
   Remember there are 2^2^11 = 3.23 10^616 binary, radius 5.0 CAs. 
   Given the new template, all we have to do is a new Expansion to find out how many rules are both totalistic and coloblind in this huge space. *)
In[8] = Length[ExpandTemplate[tr5]]
Out[8]= 64 (* Only 64 of the 2^2048 rules are both colorblind and totalistic. *)

Installation

Open Mathematica, and evaluate the following code:

$UserBaseDirectory

On a terminal, cd to $UserBaseDirectory/Applications, and clone this repository:

git clone [email protected]:mverardo/CATemplates.git

Restart Mathematica, and run:

<< CATemplates`

The package should be loaded.

If you don't want to clone the repository directly inside $UserBaseDirectory, you can clone it to another place and add a SymLink to $UserBaseDirectory/Applications.

#Running unit tests

Run the script:

$ ./test

It checks for every .m file in the "/Tests" directory, and runs it as a mathematica script.

catemplates's People

Contributors

mverardo avatar ppbo avatar zorandir avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

zorandir csrjr

catemplates's Issues

Bug when handling asymmetric radii

Below, two cases to make the bug evident, both for k=3. Possibly, the bug occurs only for k>2, but this should be checked.


In[6]:= Intersection[
ExpandTemplate[With[{k = 3, r = 0.5}, ColorBlindTemplate[k, r]]],
ExpandTemplate[With[{k = 3, r = 0.5}, TotalisticTemplate[k, r]]]]

Out[6]= {{2, 0, 1, 0, 1, 2, 1, 2, 0}}

ExpandTemplate[
With[{k = 3, r = 0.5},
TemplateIntersection[
ColorBlindTemplate[k, r],
TotalisticTemplate[k, r]]]] // Length

Out[5]= 0


In[10]:= Intersection[
ExpandTemplate[With[{k = 3, r = 1.5}, ColorBlindTemplate[k, r]]],
ExpandTemplate[With[{k = 3, r = 1.5}, TotalisticTemplate[k, r]]]]

Out[10]= {{2, 1, 0, 1, 0, 2, 0, 2, 1, 1, 0, 2, 0, 2, 1, 2, 1, 0, 0, 2,
1, 2, 1, 0, 1, 0, 2, 1, 0, 2, 0, 2, 1, 2, 1, 0, 0, 2, 1, 2, 1, 0,
1, 0, 2, 2, 1, 0, 1, 0, 2, 0, 2, 1, 0, 2, 1, 2, 1, 0, 1, 0, 2, 2, 1,
0, 1, 0, 2, 0, 2, 1, 1, 0, 2, 0, 2, 1, 2, 1, 0}}

In[11]:= ExpandTemplate[
With[{k = 3, r = 1.5},
TemplateIntersection[ColorBlindTemplate[k, r],
TotalisticTemplate[k, r]]]] // Length

Out[11]= 0

RuleTemplateVars returns the symbols in lex order

To reproduce:

In > RuleTemplateVars[BaseTemplate[2, 2]]����
Out> {x0, x1, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x2, x20, x21, x22, x23, x24, x25, x26, x27, x28, x29, x3, x30, x31, x4, x5, x6, x7, x8, x9}�����

Implement a template ADT

Should look like this:

Template
{
template : {x8,x7,x6}
ExpansionFunction : Partial[ExpandTemplate[k,r]]
k : 2
r : 1
N : 3
}

Create a version of TemplateIntersection that works with templates generated with Mod[].

this version of the TemplateIntersection function should use the modulus -> k option, and translate the C[i] constants into template variables.

Currently, the problem with this approach is that the C[i] constants can't be called x_i, as this would create a semantic conflict between these variables and the ones from templates generated without mod.

It's still not clear if all new intersections should be named with different variables, or if the C[i] should get a new name with a new template (possibly resulting from intersections).

$RecursionLimit set to Infinity should be default in the package.

The example in the READ.ME,

With[{k = 2, r = 5.0},
TemplateIntersection[ColorBlindTemplate[k, r], TotalisticTemplate[k, r]]];

doesn't work, unless $RecursionLimit set to a big value. As a matter of uniformity, maybe it should be set to Infinity as default. By the way, until this is done, READ.ME should be altered with an example that would work.

RestrictedTemplateIntersection[t1,t1] results in {} instead of t1

In := t1 = BuildTemplate[3, 1.0, {2, x1 \[Element] {0, 2}, 0}, RestrictedExpansion];
In := t2 = BuildTemplate[3, 1.0, {2, x1, 0}, RestrictedExpansion];
In := TemplateIntersection[t1, t2] 
Out = <|"k" -> 3, "r" -> 1., "rawList" -> {}, "expansionFunction" -> RestrictedExpansion|>

Out should be

<|"k" -> 3, "r" -> 1., "rawList" -> {2, x1 \[Element] {0, 2}, 0}, "expansionFunction" -> RestrictedExpansion|>

ModularTemplateIntersection produces wrong results on equivalent templates

The following templates are equivalent when expanded mod 3:

In >> t1 = {2 + x1, x0};
In >> t2 = {x1, x0};

Problem is that their intersection is empty:

In >> ModularTemplateIntersection[t1, t2, 3]
Out >> {}

Changing one of the template's variables to yi corrects this problem, tough:

In >> ty2 = Symbol[StringReplace[SymbolName[#], "x" -> "y"]] & /@ t2;

In >> ModularTemplateIntersection[t1, ty2, 3]
Out >> {2 + x1, x0}

Maybe ModularTemplateIntersection should translate one of it's arguments to ys?

ColorBlindTemplate[4] produces error.

Probably because it uses ImprisonmentExpressions internally for k>4, and ModularTemplateIntersection is not prepared to treat these kinds of expressions.

When mixing modular and non-modular templates, ModularTemplateIntersection depends on the order of it's arguments

Given the templates:
t1 = ColorBlindTemplate[3, 2];
t2 = TotalisticTemplate[3, 2];

If ModularTemplateIntersection is used as follows:
In >> ModularTemplateIntersection[t2, t1, 3]

Out >> {2, 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0}

The output is a valid k-ary rule table.
If the order of the arguments are reversed, the output is:

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

Wich, clearly, is not a valid rule table.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.