ConwayLife.com - A community for Conway's Game of Life and related cellular automata
Home  •  LifeWiki  •  Forums  •  Download Golly

Does anyone have a script for canonising isotropic rules?

For scripts to aid with computation or simulation in cellular automata.

Does anyone have a script for canonising isotropic rules?

Postby calcyman » September 1st, 2017, 2:45 pm

In order to add isotropic rule support to apgluxe, I need a Python script which can:

(a) Convert any rule into canonical form;
(b) Produce the 512-bit transition table.

I understand this already must exist somewhere -- but where?
What do you do with ill crystallographers? Take them to the mono-clinic!
User avatar
calcyman
 
Posts: 1370
Joined: June 1st, 2009, 4:32 pm

Re: Does anyone have a script for canonising isotropic rules?

Postby A for awesome » September 1st, 2017, 5:20 pm

calcyman wrote:In order to add isotropic rule support to apgluxe, I need a Python script which can:

(a) Convert any rule into canonical form;
(b) Produce the 512-bit transition table.

I understand this already must exist somewhere -- but where?

I don't know if either one already exists, but here's a solution for (b) I wrote a few days ago to test something:
import re
#Binary encoding of each isotropic configuration
#Ordering is:
#8 1 2
#7 0 3
#6 5 4
#This could probably be changed by bit-shuffling if necessary.
transitions = {
    '0' : [0],
    '1c': [64, 4, 16, 1],
    '1e': [128, 2, 32, 8],
    '2a': [192, 6, 48, 129, 12, 96, 3, 24],
    '2c': [80, 20, 5, 65],
    '2e': [160, 10, 40, 130],
    '2i': [136, 34],
    '2k': [144, 18, 36, 132, 9, 33, 66, 72],
    '2n': [68, 17],
    '3a': [224, 14, 56, 131],
    '3c': [84, 21, 69, 81],
    '3e': [168, 42, 138, 162],
    '3i': [193, 7, 112, 28],
    '3j': [194, 134, 176, 161, 44, 104, 11, 26],
    '3k': [164, 74, 41, 146],
    '3n': [208, 22, 52, 133, 13, 97, 67, 88],
    '3q': [196, 70, 49, 145, 76, 100, 19, 25],
    '3r': [200, 38, 50, 137, 140, 98, 35, 152],
    '3y': [148, 82, 37, 73],
    '4a': [240, 30, 60, 135, 15, 225, 195, 120],
    '4c': [85],
    '4e': [170],
    '4i': [216, 54, 141, 99],
    '4j': [202, 166, 178, 169, 172, 106, 43, 154],
    '4k': [210, 150, 180, 165, 45, 105, 75, 90],
    '4n': [209, 23, 116, 197, 29, 113, 71, 92],
    '4q': [228, 78, 57, 147],
    '4r': [232, 46, 58, 139, 142, 226, 163, 184],
    '4t': [201, 39, 114, 156],
    '4w': [198, 177, 108, 27],
    '4y': [212, 86, 53, 149, 77, 101, 83, 89],
    '4z': [204, 102, 51, 153],
    '5a': [241, 31, 124, 199],
    '5c': [234, 174, 186, 171],
    '5e': [213, 87, 117, 93],
    '5i': [248, 62, 143, 227],
    '5j': [244, 94, 61, 151, 79, 229, 211, 121],
    '5k': [214, 181, 109, 91],
    '5n': [242, 158, 188, 167, 47, 233, 203, 122],
    '5q': [236, 110, 59, 155, 206, 230, 179, 185],
    '5r': [220, 118, 55, 157, 205, 103, 115, 217],
    '5y': [218, 182, 173, 107],
    '6a': [252, 126, 63, 159, 207, 231, 243, 249],
    '6c': [250, 190, 175, 235],
    '6e': [245, 95, 125, 215],
    '6i': [221, 119],
    '6k': [246, 222, 189, 183, 111, 237, 219, 123],
    '6n': [238, 187],
    '7c': [254, 191, 239, 251],
    '7e': [253, 127, 223, 247],
    '8' : [255]
}

transtable = [0]*512
rulestring = "B3/S2-i34q" #Or input this somehow

#Parse the rulestring:
b, s = rulestring.split("/") #Separate B and S transitions
b, s = b[1:], s[1:] #Remove the characters 'B' and 'S'
transgroup = re.compile(r"([0-8][a-zA-Z\-]*)") #Matches a group of isotropic transitions sharing the same outer-totalistic count
b, s = re.findall(transgroup, b), re.findall(transgroup, s) #Divide into transition groups

#Build first half of transition table
for i in b:
    # e.g. B3 or B2-an
    if len(i) == 1 or i[1] == "-":
        #Set all transitions with the given outer-totalistic count (possibly preemptively)
        for j in transitions:
            if j[0] == i[0]:
                for k in transitions[j]:
                    transtable[k] = 1
    # e.g. B2ce
    else:
        #Set all given transitions in group
        for j in i[1:]:
            for k in transitions[i[0]+j]:
                transtable[k] = 1
    # e.g. B2-an
    if len(i) > 1 and i[1] == "-":
        #Unset all given transitions in group
        for j in i[2:]:
            for k in transitions[i[0]+j]:
                transtable[k] = 0

#Build second half
for i in s:
    # e.g. B3 or B2-an
    if len(i) == 1 or i[1] == "-":
        #Set all transitions with the given outer-totalistic count (possibly preemptively)
        for j in transitions:
            if j[0] == i[0]:
                for k in transitions[j]:
                    transtable[k|256] = 1
    # e.g. B2ce
    else:
        #Set all given transitions in group
        for j in i[1:]:
            for k in transitions[i[0]+j]:
                transtable[k|256] = 1
    # e.g. B2-an
    if len(i) > 1 and i[1] == "-":
        #Unset all given transitions in group
        for j in i[2:]:
            for k in transitions[i[0]+j]:
                transtable[k|256] = 0

#Print transition table
print transtable

It's not fully tested, but it works for tlife at the very least (which was what I was using it for). Hopefully it's acceptable.
x₁=ηx
V ⃰_η=c²√(Λη)
K=(Λu²)/2
Pₐ=1−1/(∫^∞_t₀(p(t)ˡ⁽ᵗ⁾)dt)

$$x_1=\eta x$$
$$V^*_\eta=c^2\sqrt{\Lambda\eta}$$
$$K=\frac{\Lambda u^2}2$$
$$P_a=1-\frac1{\int^\infty_{t_0}p(t)^{l(t)}dt}$$

http://conwaylife.com/wiki/A_for_all

Aidan F. Pierce
User avatar
A for awesome
 
Posts: 1444
Joined: September 13th, 2014, 5:36 pm
Location: 0x-1

Re: Does anyone have a script for canonising isotropic rules?

Postby dvgrn » September 1st, 2017, 5:53 pm

calcyman wrote:(a) Convert any rule into canonical form;
...
I understand this already must exist somewhere -- but where?

Don't think I've seen this as a Python script anywhere (except "Golly Python", that is). But obviously there's canonicalization code built into Golly... and it even has helpful comments! I think you might even call this canonical canonicalization code for isotropic rules. A translation to Python may be slightly painful, but it doesn't look impossible at least.
dvgrn
Moderator
 
Posts: 4036
Joined: May 17th, 2009, 11:00 pm
Location: Madison, WI


Return to Scripts

Who is online

Users browsing this forum: No registered users and 2 guests