python function to lookup-table-of-reflectors?

For scripts to aid with computation or simulation in cellular automata.
Post Reply
Johnicholas
Posts: 10
Joined: August 23rd, 2011, 4:28 pm

python function to lookup-table-of-reflectors?

Post by Johnicholas » August 29th, 2011, 8:14 am

If I understand correctly, both Paul Chapman's Minsky Register Machine and Calcyman's related Universal Computer-Constructor depend on lookup tables implemented by regular (in alignment but not in content) arrays of reflectors that express the microcode.

That is, inputs come in on one edge of the lookup table, and are bounced 90 degrees to the output on the other side of the table.

Does anyone currently have a Golly script that takes a python function and lays out reflectors to implement that function as a lookup table?

User avatar
calcyman
Posts: 2412
Joined: June 1st, 2009, 4:32 pm

Re: python function to lookup-table-of-reflectors?

Post by calcyman » August 29th, 2011, 1:51 pm

Does anyone currently have a Golly script that takes a python function and lays out reflectors to implement that function as a lookup table?
No. Paul uses some form of assembly language, and I use something that looks like this:

Code: Select all

# Pi calculation program

# This is designed to calculate the decimal digits of Pi, or 3.141592...

# State    Input   Next state    Actions
# ---------------------------------------

INITIAL;    Z;     I1;           READ T0
INITIAL;    NZ;    I1;           READ T0

I1;         Z;     I2;           SET T0, READ T2
I1;         NZ;    I2;           SET T0, READ T2
I2;         Z;     I3;           SET T2, NOP
I2;         NZ;    I3;           SET T2, NOP
I3;         Z;     I4;           INC R4, NOP
I3;         NZ;    I4;           INC R4, NOP

I4;         Z;     I5;           INC R0, NOP
I4;         NZ;    I5;           INC R0, NOP
I5;         Z;     I6;           INC R0, NOP
I5;         NZ;    I6;           INC R0, NOP
I6;         Z;     I7;           INC R0, NOP
I6;         NZ;    I7;           INC R0, NOP
I7;         Z;     I8;           INC R0, NOP
I7;         NZ;    I8;           INC R0, NOP
I8;         Z;     I9;           INC R0, NOP
I8;         NZ;    I9;           INC R0, NOP
I9;         Z;     I10;          INC R0, NOP
I9;         NZ;    I10;          INC R0, NOP
I10;        Z;     I11;          INC R0, NOP
I10;        NZ;    I11;          INC R0, NOP
I11;        Z;     A1;           INC R0, NOP
I11;        NZ;    A1;           INC R0, NOP



# Calculate next digit

A1;         Z;     A2;           INC R9, NOP
A1;         NZ;    A2;           INC R9, NOP
A2;         Z;     A3;           INC R9, NOP
A2;         NZ;    A3;           INC R9, NOP
A3;         Z;     A4;           INC R9, NOP
A3;         NZ;    A4;           INC R9, NOP
A4;         Z;     A5;           INC R9, NOP
A4;         NZ;    A5;           INC R9, NOP

A5;         Z;     A6;           TDEC R9
A5;         NZ;    A6;           TDEC R9
A6;         Z;     DISP;         NOP
A6;         NZ;    B1;           NOP



# Perform next iteration

B1;         Z;     B2;           INC R3, NOP
B1;         NZ;    B2;           INC R3, NOP
B2;         Z;     B3;           INC R4, NOP
B2;         NZ;    B3;           INC R4, NOP
B3;         Z;     B4;           INC R4, TDEC R0
B3;         NZ;    B4;           INC R4, TDEC R0



# Copy T0 to T3

B4;         Z;     B5;           TDEC R1
B4;         NZ;    B4;           INC R1, TDEC R0
B5;         Z;     B6;           TDEC R2
B5;         NZ;    B5;           INC R0, INC R2, TDEC R1

B6;         Z;     B11;          DEC T3
B6;         NZ;    B7;           READ T3
B7;         Z;     B8;           READ T0
B7;         NZ;    B8;           READ T0
B8;         Z;     B9;           RESET T3, RESET T0, INC T3
B8;         NZ;    B9;           SET T3, SET T0, INC T3
B9;         Z;     B10;          INC T0
B9;         NZ;    B10;          INC T0
B10;        Z;     B6;           TDEC R2
B10;        NZ;    B6;           TDEC R2
B11;        Z;     B12;          DEC T0
B11;        NZ;    B11;          DEC T3
B12;        Z;     C4;           TDEC R0
B12;        NZ;    B12;          DEC T0



# Add T0 to T3

C4;         Z;     C5;           TDEC R1
C4;         NZ;    C4;           INC R1, TDEC R0
C5;         Z;     C6;           TDEC R2
C5;         NZ;    C5;           INC R0, INC R2, TDEC R1
C6;         Z;     C12;          DEC T0
C6;         NZ;    C7;           READ T0
C7;         Z;     C8;           RESET T0, READ T3
C7;         NZ;    C8;           SET T0, ADD A1, READ T3
C8;         Z;     C9;           ADD B0
C8;         NZ;    C9;           ADD B1
C9;         Z;     C10;          RESET T3, INC T3
C9;         NZ;    C10;          SET T3, INC T3
C10;        Z;     C11;          INC T0
C10;        NZ;    C11;          INC T0
C11;        Z;     C6;           TDEC R2
C11;        NZ;    C6;           TDEC R2
C12;        Z;     C13;          DEC T3
C12;        NZ;    C12;          DEC T0
C13;        Z;     D4;           TDEC R0
C13;        NZ;    C13;          DEC T3



# Add T1 to T3, clearing T1 in the process

D4;         Z;     D5;           TDEC R1
D4;         NZ;    D4;           INC R1, TDEC R0
D5;         Z;     D6;           TDEC R2
D5;         NZ;    D5;           INC R0, INC R2, TDEC R1
D6;         Z;     D12;          DEC T1
D6;         NZ;    D7;           READ T1
D7;         Z;     D8;           RESET T1, READ T3
D7;         NZ;    D8;           RESET T1, ADD A1, READ T3
D8;         Z;     D9;           ADD B0
D8;         NZ;    D9;           ADD B1
D9;         Z;     D10;          RESET T3, INC T3
D9;         NZ;    D10;          SET T3, INC T3
D10;        Z;     D11;          INC T1
D10;        NZ;    D11;          INC T1
D11;        Z;     D6;           TDEC R2
D11;        NZ;    D6;           TDEC R2
D12;        Z;     D13;          DEC T3
D12;        NZ;    D12;          DEC T1
D13;        Z;     E1;           NOP
D13;        NZ;    D13;          DEC T3



# Multiply T3 by R4 and store in T1

E1;         Z;     E2;           TDEC R4
E1;         NZ;    E2;           TDEC R4
E2;         Z;     E3;           TDEC R1
E2;         NZ;    E2;           INC R1, TDEC R4
E3;         Z;     E4;           TDEC R5
E3;         NZ;    E3;           INC R4, INC R5, TDEC R1
E4;         Z;     F1;           NOP
E4;         NZ;    E5;           TDEC R0
E5;         Z;     E6;           TDEC R1
E5;         NZ;    E5;           INC R1, TDEC R0
E6;         Z;     E7;           TDEC R2
E6;         NZ;    E6;           INC R0, INC R2, TDEC R1
E7;         Z;     E13;          DEC T3
E7;         NZ;    E8;           READ T3
E8;         Z;     E9;           RESET T3, READ T1
E8;         NZ;    E9;           SET T3, ADD A1, READ T1
E9;         Z;     E10;          ADD B0
E9;         NZ;    E10;          ADD B1
E10;        Z;     E11;          RESET T1, INC T1
E10;        NZ;    E11;          SET T1, INC T1
E11;        Z;     E12;          INC T3
E11;        NZ;    E12;          INC T3
E12;        Z;     E7;           TDEC R2
E12;        NZ;    E7;           TDEC R2
E13;        Z;     E14;          DEC T1
E13;        NZ;    E13;          DEC T3
E14;        Z;     E4;           TDEC R5
E14;        NZ;    E14;          DEC T1



# Move T0 to T3

F1;         Z;     F2;           TDEC R0
F1;         NZ;    F2;           TDEC R0
F2;         Z;     F3;           TDEC R1
F2;         NZ;    F2;           INC R1, TDEC R0
F3;         Z;     F4;           TDEC R2
F3;         NZ;    F3;           INC R0, INC R2, TDEC R1
F4;         Z;     F9;           DEC T3
F4;         NZ;    F5;           READ T3
F5;         Z;     F6;           READ T0
F5;         NZ;    F6;           READ T0
F6;         Z;     F7;           RESET T3, RESET T0, INC T3
F6;         NZ;    F7;           SET T3, RESET T0, INC T3
F7;         Z;     F8;           INC T0
F7;         NZ;    F8;           INC T0
F8;         Z;     F4;           TDEC R2
F8;         NZ;    F4;           TDEC R2
F9;         Z;     F10;          DEC T0
F9;         NZ;    F9;           DEC T3
F10;        Z;     G1;           NOP
F10;        NZ;    F10;          DEC T0



# Multiply T3 by R3 and store in T0

G1;         Z;     G2;           TDEC R3
G1;         NZ;    G2;           TDEC R3
G2;         Z;     G3;           TDEC R1
G2;         NZ;    G2;           INC R1, TDEC R3
G3;         Z;     G4;           TDEC R5
G3;         NZ;    G3;           INC R3, INC R5, TDEC R1
G4;         Z;     H1;           NOP
G4;         NZ;    G5;           TDEC R0
G5;         Z;     G6;           TDEC R1
G5;         NZ;    G5;           INC R1, TDEC R0
G6;         Z;     G7;           TDEC R2
G6;         NZ;    G6;           INC R0, INC R2, TDEC R1
G7;         Z;     G13;          DEC T3
G7;         NZ;    G8;           READ T3
G8;         Z;     G9;           RESET T3, READ T0
G8;         NZ;    G9;           SET T3, ADD A1, READ T0
G9;         Z;     G10;          ADD B0
G9;         NZ;    G10;          ADD B1
G10;        Z;     G11;          RESET T0, INC T0
G10;        NZ;    G11;          SET T0, INC T0
G11;        Z;     G12;          INC T3
G11;        NZ;    G12;          INC T3
G12;        Z;     G7;           TDEC R2
G12;        NZ;    G7;           TDEC R2
G13;        Z;     G14;          DEC T0
G13;        NZ;    G13;          DEC T3
G14;        Z;     G4;           TDEC R5
G14;        NZ;    G14;          DEC T0



# Move T2 to T3

H1;         Z;     H2;           TDEC R0
H1;         NZ;    H2;           TDEC R0
H2;         Z;     H3;           TDEC R1
H2;         NZ;    H2;           INC R1, TDEC R0
H3;         Z;     H4;           TDEC R2
H3;         NZ;    H3;           INC R0, INC R2, TDEC R1
H4;         Z;     H9;           DEC T3
H4;         NZ;    H5;           READ T3
H5;         Z;     H6;           READ T2
H5;         NZ;    H6;           READ T2
H6;         Z;     H7;           RESET T3, RESET T2, INC T3
H6;         NZ;    H7;           SET T3, RESET T2, INC T3
H7;         Z;     H8;           INC T2
H7;         NZ;    H8;           INC T2
H8;         Z;     H4;           TDEC R2
H8;         NZ;    H4;           TDEC R2
H9;         Z;     H10;          DEC T2
H9;         NZ;    H9;           DEC T3
H10;        Z;     J1;           NOP
H10;        NZ;    H10;          DEC T2



# Multiply T3 by R4 and store in T2

J1;         Z;     J2;           TDEC R4
J1;         NZ;    J2;           TDEC R4
J2;         Z;     J3;           TDEC R1
J2;         NZ;    J2;           INC R1, TDEC R4
J3;         Z;     J4;           TDEC R5
J3;         NZ;    J3;           INC R4, INC R5, TDEC R1
J4;         Z;     K1;           NOP
J4;         NZ;    J5;           TDEC R0
J5;         Z;     J6;           TDEC R1
J5;         NZ;    J5;           INC R1, TDEC R0
J6;         Z;     J7;           TDEC R2
J6;         NZ;    J6;           INC R0, INC R2, TDEC R1
J7;         Z;     J13;          DEC T3
J7;         NZ;    J8;           READ T3
J8;         Z;     J9;           RESET T3, READ T2
J8;         NZ;    J9;           SET T3, ADD A1, READ T2
J9;         Z;     J10;          ADD B0
J9;         NZ;    J10;          ADD B1
J10;        Z;     J11;          RESET T2, INC T2
J10;        NZ;    J11;          SET T2, INC T2
J11;        Z;     J12;          INC T3
J11;        NZ;    J12;          INC T3
J12;        Z;     J7;           TDEC R2
J12;        NZ;    J7;           TDEC R2
J13;        Z;     J14;          DEC T2
J13;        NZ;    J13;          DEC T3
J14;        Z;     J4;           TDEC R5
J14;        NZ;    J14;          DEC T2



# Increase precision

K1;         Z;     K2;           TDEC R3
K1;         NZ;    K2;           TDEC R3
K2;         Z;     K3;           TDEC R1
K2;         NZ;    K2;           INC R1, TDEC R3
K3;         Z;     A5;           NOP
K3;         NZ;    K3;           INC R0, INC R3, TDEC R1



# Display next digit

DISP;       Z;     L1;           TDEC R7
DISP;       NZ;    L1;           TDEC R7
L1;         Z;     L2;           TDEC R1
L1;         NZ;    L1;           INC R1, TDEC R7
L2;         Z;     N1;           NOP
L2;         NZ;    L2;           INC R7, INC R8, TDEC R1


# Copy T0 to T3

N1;         Z;     N2;           TDEC R0
N1;         NZ;    N2;           TDEC R0
N2;         Z;     N3;           TDEC R1
N2;         NZ;    N2;           INC R1, TDEC R0
N3;         Z;     N4;           TDEC R2
N3;         NZ;    N3;           INC R0, INC R2, TDEC R1
N4;         Z;     N9;           DEC T3
N4;         NZ;    N5;           READ T3
N5;         Z;     N6;           READ T0
N5;         NZ;    N6;           READ T0
N6;         Z;     N7;           RESET T3, RESET T0, INC T3
N6;         NZ;    N7;           SET T3, SET T0, INC T3
N7;         Z;     N8;           INC T0
N7;         NZ;    N8;           INC T0
N8;         Z;     N4;           TDEC R2
N8;         NZ;    N4;           TDEC R2
N9;         Z;     N10;          DEC T0
N9;         NZ;    N9;           DEC T3
N10;        Z;     P1;           NOP
N10;        NZ;    N10;          DEC T0

# Add T1 to T3

P1;         Z;     P2;           TDEC R0
P1;         NZ;    P2;           TDEC R0
P2;         Z;     P3;           TDEC R1
P2;         NZ;    P2;           INC R1, TDEC R0
P3;         Z;     P4;           TDEC R2
P3;         NZ;    P3;           INC R0, INC R2, TDEC R1
P4;         Z;     P10;          DEC T1
P4;         NZ;    P5;           READ T1
P5;         Z;     P6;           RESET T1, READ T3
P5;         NZ;    P6;           SET T1, ADD A1, READ T3
P6;         Z;     P7;           ADD B0
P6;         NZ;    P7;           ADD B1
P7;         Z;     P8;           RESET T3, INC T3
P7;         NZ;    P8;           SET T3, INC T3
P8;         Z;     P9;           INC T1
P8;         NZ;    P9;           INC T1
P9;         Z;     P4;           TDEC R2
P9;         NZ;    P4;           TDEC R2
P10;        Z;     P11;          DEC T3
P10;        NZ;    P10;          DEC T1
P11;        Z;     L3;           TDEC R6
P11;        NZ;    P11;          DEC T3

L3;         Z;     M1;           NOP
L3;         NZ;    L3;           TDEC R6



# Compare T2 with T3

M1;         Z;     M2;           TDEC R0
M1;         NZ;    M2;           TDEC R0
M2;         Z;     M3;           TDEC R1
M2;         NZ;    M2;           INC R1, TDEC R0
M3;         Z;     M4;           TDEC R2
M3;         NZ;    M3;           INC R0, INC R2, TDEC R1
M4;         Z;     M7;           READ T3
M4;         NZ;    M5;           INC T3
M5;         Z;     M6;           INC T2
M5;         NZ;    M6;           INC T2
M6;         Z;     M4;           TDEC R2
M6;         NZ;    M4;           TDEC R2
M7;         Z;     M8;           RESET T3, READ T2
M7;         NZ;    M11;          SET T3, READ T2
M8;         Z;     M9;           RESET T2, DEC T2
M8;         NZ;    M12;          SET T2, DEC T3
M9;         Z;     M10;          DEC T3
M9;         NZ;    M10;          DEC T3
M10;        Z;     M16;          DEC T2
M10;        NZ;    M7;           READ T3
M11;        Z;     M15;          RESET T2, DEC T3
M11;        NZ;    M9;           SET T2, DEC T2
M12;        Z;     M13;          DEC T2
M12;        NZ;    M12;          DEC T3
M13;        Z;     EVL;          TDEC R8
M13;        NZ;    M13;          DEC T2
M15;        Z;     M16;          DEC T2
M15;        NZ;    M15;          DEC T3
M16;        Z;     Q1;           NOP
M16;        NZ;    M16;          DEC T2



# Subtract T2 from T3

Q1;         Z;     Q2;           TDEC R0
Q1;         NZ;    Q2;           TDEC R0
Q2;         Z;     Q3;           TDEC R1
Q2;         NZ;    Q2;           INC R1, TDEC R0
Q3;         Z;     Q4;           TDEC R2
Q3;         NZ;    Q3;           INC R0, INC R2, TDEC R1
Q4;         Z;     Q10;          DEC T3
Q4;         NZ;    Q5;           READ T3
Q5;         Z;     Q6;           READ T2
Q5;         NZ;    Q6;           SUB A1, READ T2
Q6;         Z;     Q7;           RESET T2, SUB B0
Q6;         NZ;    Q7;           SET T2, SUB B1
Q7;         Z;     Q8;           RESET T3, INC T3
Q7;         NZ;    Q8;           SET T3, INC T3
Q8;         Z;     Q9;           INC T2
Q8;         NZ;    Q9;           INC T2
Q9;         Z;     Q4;           TDEC R2
Q9;         NZ;    Q4;           TDEC R2
Q10;        Z;     Q11;          DEC T2
Q10;        NZ;    Q10;          DEC T3
Q11;        Z;     M1;           INC R6, NOP
Q11;        NZ;    Q11;          DEC T2



# Decide whether the extracted digit is the intended one

EVL;        Z;     U1;           NOP
EVL;        NZ;    S1;           NOP



# If not, then multiply T3 by 10

S1;         Z;     S2;           TDEC R0
S1;         NZ;    S2;           TDEC R0
S2;         Z;     S3;           TDEC R1
S2;         NZ;    S2;           INC R1, TDEC R0
S3;         Z;     S4;           TDEC R2
S3;         NZ;    S3;           INC R0, INC R2, TDEC R1
S4;         Z;     S8;           DEC T3
S4;         NZ;    S5;           READ T3
S5;         Z;     S6;           MUL 0
S5;         NZ;    S6;           MUL 1
S6;         Z;     S7;           RESET T3, INC T3
S6;         NZ;    S7;           SET T3, INC T3
S7;         Z;     S4;           TDEC R2
S7;         NZ;    S4;           TDEC R2
S8;         Z;     L3;           TDEC R6
S8;         NZ;    S8;           DEC T3



# Output R6

U1;         Z;     U2;           TDEC R6
U1;         NZ;    U2;           TDEC R6
U2;         Z;     U11;          OUTPUT 0, NOP
U2;         NZ;    U3;           TDEC R6
U3;         Z;     U11;          OUTPUT 1, NOP
U3;         NZ;    U4;           TDEC R6
U4;         Z;     U11;          OUTPUT 2, NOP
U4;         NZ;    U5;           TDEC R6
U5;         Z;     U11;          OUTPUT 3, NOP
U5;         NZ;    U6;           TDEC R6
U6;         Z;     U11;          OUTPUT 4, NOP
U6;         NZ;    U7;           TDEC R6
U7;         Z;     U11;          OUTPUT 5, NOP
U7;         NZ;    U8;           TDEC R6
U8;         Z;     U11;          OUTPUT 6, NOP
U8;         NZ;    U9;           TDEC R6
U9;         Z;     U11;          OUTPUT 7, NOP
U9;         NZ;    U10;          TDEC R6
U10;        Z;     U11;          OUTPUT 8, NOP
U10;        NZ;    U11;          OUTPUT 9, NOP

U11;        Z;     U12;          TDEC R7
U11;        NZ;    U12;          TDEC R7
U12;        Z;     U13;          OUTPUT ., NOP
U12;        NZ;    U13;          INC R7, NOP
U13;        Z;     A1;           INC R7, NOP
U13;        NZ;    A1;           INC R7, NOP
What do you do with ill crystallographers? Take them to the mono-clinic!

Johnicholas
Posts: 10
Joined: August 23rd, 2011, 4:28 pm

Re: python function to lookup-table-of-reflectors?

Post by Johnicholas » August 29th, 2011, 8:21 pm

That's very interesting!

I tried to write something to show what I was looking for; nothing so sophisticated as an assembler.
It is not useable without source tweaking, and I may have gotten the reflector wrong; I'm an idiot at Life.

Code: Select all

# Based on bricklayer.py from PLife (http://plife.sourceforge.net/).

from glife import *
from glife.base import *

rule ()  # Life

reflector= pattern("11$18b2o$18b2o4$17b3o$17b3o$16bo3bo$15bo5bo$16bo3bo$17b3o9$15b2o$16bo$13b3o$13bo!")

xsize = 100
ysize = 100
xspacing = 40
yspacing = 40

def f(i):
	# some meaningless function that should be implemented
	# by the lookup table.
	if i < 10:
		return 2 * i
	else:
		return 3 * i

def test(i, j):
	return f(j) == i

all = pattern()
for i in range(xsize):
	for j in range(ysize):
		if test(i, j):
			all = all + reflector(i*xspacing + j*yspacing, i*xspacing - j*yspacing);

all.display("lookup")

User avatar
calcyman
Posts: 2412
Joined: June 1st, 2009, 4:32 pm

Re: python function to lookup-table-of-reflectors?

Post by calcyman » August 30th, 2011, 6:17 am

Oh, sorry, I thought you meant a Python --> Life compiler... :D
What do you do with ill crystallographers? Take them to the mono-clinic!

Post Reply