Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
Adam P. Goucher
slmake
Commits
4ed63f14
Commit
4ed63f14
authored
Oct 27, 2018
by
Adam P. Goucher
Browse files
Merge
parents
f992d53a
a73f8d89
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
79 additions
and
99 deletions
+79
-99
isotropic_metafier.py
isotropic_metafier.py
+77
-12
isotropic_metafier.sh
isotropic_metafier.sh
+0
-62
lifelib
lifelib
+1
-1
metacell/xorkron.cpp
metacell/xorkron.cpp
+0
-24
update-lifelib.sh
update-lifelib.sh
+1
-0
No files found.
mktable
.py
→
isotropic_metafier
.py
View file @
4ed63f14
#!/usr/bin/python
# Function to convert rulestring to transition table:
try
:
from
lifelib.genera.isotropic
import
str2tab
except
ImportError
:
...
...
@@ -10,8 +8,14 @@ except ImportError:
os
.
system
(
"bash update-lifelib.sh"
)
from
lifelib.genera.isotropic
import
str2tab
import
lifelib
def
rule2tuples
(
rulestring
):
'''
Convert an isotropic rulestring to a list of transitions.
This uses the function str2tab from the isotropic code in
lifelib.
'''
rulestring
=
rulestring
.
replace
(
'B'
,
'b'
).
replace
(
'/S'
,
's'
)
tt
=
str2tab
(
rulestring
)
...
...
@@ -46,6 +50,9 @@ def rule2tuples(rulestring):
def
tuples2vn
(
tuples
,
filename
):
'''
Function to optionally save a set of transitions as a Golly ruletable.
'''
from
os.path
import
splitext
,
basename
...
...
@@ -65,8 +72,12 @@ def tuples2vn(tuples, filename):
def
tuples2tape
(
tuples
):
'''
Convert a set of transitions into the tape header for the metacell.
The output is a list of spacings between successive gliders.
'''
print
(
[
0
]
+
([
90
]
*
41
)
)
tape
=
[
0
]
+
([
90
]
*
41
)
# Amount of time to wait between finishing the 42-glider salute and
# beginning the first entry of the transition table:
...
...
@@ -93,22 +104,76 @@ def tuples2tape(tuples):
for
_
in
range
(
j
-
1
):
l
+=
[
90
]
debt
-=
90
print
(
l
)
tape
+=
l
debt
+=
1024
print
([
debt
+
10000
])
tape
+=
[
debt
+
10000
]
return
tape
def
main
(
input_file
,
output_file
,
output_table
=
None
):
# The final result will be in b3s23:
sess
=
lifelib
.
load_rules
(
'b3s23'
)
lt
=
sess
.
lifetree
()
# Load the target pattern into lifelib and obtain the isotropic rule:
pattern_to_metafy
=
lt
.
load
(
input_file
)
original_rule
=
pattern_to_metafy
.
getrule
()
# Cast to b3s23:
pattern_to_metafy
=
lt
.
pattern
(
""
,
"b3s23"
)
+
pattern_to_metafy
# Convert the transition table into a tape header for the metacell:
rtuples
=
rule2tuples
(
original_rule
)
tape
=
tuples2tape
(
rtuples
)
# Optionally save a Golly-compatible ruletable:
if
output_table
is
not
None
:
tuples2vn
(
rtuples
,
output_table
)
# Load an empty metacell with a glider pointing into its input:
empty_cell
=
lt
.
load
(
"metacell/emptycell.mc"
)
# Convert the tape header from a sequence of numbers into an actual
# stream of gliders heading into the metacell:
cell_without_glider
=
empty_cell
&
empty_cell
[
8
]
glider
=
empty_cell
-
cell_without_glider
cell_with_tape
=
cell_without_glider
+
glider
.
stream
(
tape
)
# Run in HashLife to pipe the tape header into the metacell:
gensleft
=
430531840
while
(
gensleft
>
16777216
):
cell_with_tape
=
cell_with_tape
[
16777216
]
gensleft
-=
16777216
print
(
'%d generations remaining...'
%
gensleft
)
cell_with_tape
=
cell_with_tape
[
gensleft
]
# Load the metacell with full tape and default header:
print
(
'Loading patterns...'
)
default_cell
=
lt
.
load
(
"metacell/tableonly_default.mc"
)
default_cell_full
=
lt
.
load
(
"metacell/complete_default.mc"
)
# Use a 3-way XOR to obtain a metacell with full tape and the
# correct header for the desired rule:
print
(
'Applying patch...'
)
onecell
=
(
cell_with_tape
^
default_cell
)
^
default_cell_full
onecell
=
onecell
.
centre
()
# Multiplication is overloaded to mean Kronecker product:
metafied_pattern
=
pattern_to_metafy
*
onecell
# Save the metafied pattern:
metafied_pattern
.
write_file
(
output_file
)
print
(
'...saved output in %s'
%
output_file
)
if
__name__
==
'__main__'
:
from
sys
import
argv
if
(
len
(
argv
)
!=
3
):
raise
TypeError
(
"Usage: python isotropic_metafier.py infile.rle outfile.mc [outfile.rule]"
)
if
(
len
(
argv
)
<
2
):
raise
TypeError
(
"Usage: python mktable.py RULESTRING [output.rule]"
)
rtuples
=
rule2tuples
(
argv
[
1
])
tuples2tape
(
rtuples
)
main
(
*
(
argv
[
1
:]))
if
(
len
(
argv
)
>=
3
):
tuples2vn
(
rtuples
,
argv
[
2
])
isotropic_metafier.sh
deleted
100755 → 0
View file @
f992d53a
#!/bin/bash
if
[
"$#"
-ne
2
]
;
then
echo
"Usage: ./isotropic_metafier.sh INPUT_PATTERN OUTPUT_PATTERN"
echo
"The input file can be either .rle or .mc"
echo
"The output file is guaranteed to be .mc"
exit
1
fi
INPUT_FILE
=
$(
readlink
-f
"
$1
"
)
OUTPUT_FILE
=
$(
readlink
-f
"
$2
"
)
cd
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
rm
-r
temp |
true
mkdir
-p
temp
grep
'^x'
"
$INPUT_FILE
"
>
temp/ruledata.txt
grep
'^#R'
"
$INPUT_FILE
"
>>
temp/ruledata.txt
RULESTRING
=
$(
head
-n
1 temp/ruledata.txt |
tr
' '
'\n'
|
tr
'='
'\n'
|
tail
-n
1
)
# Abort if anything goes wrong.
set
-e
echo
"rule : '
$RULESTRING
'"
python mktable.py
"
$RULESTRING
"
>
temp/ruletable.txt
echo
"Table successfully created."
if
[
-f
"lifelib/dd0e0p"
]
;
then
echo
"dd0e0p exists"
else
bash update-lifelib.sh
cd
lifelib
echo
"Compiling dd0e0p..."
g++
-O3
-march
=
native
-std
=
c++11
-Wall
-Wextra
dd0e0p.cpp
-o
dd0e0p
cd
-
fi
echo
"Imaging ruletable into empty metacell..."
lifelib/dd0e0p
if
=
temp/ruletable.txt
tf
=
metacell/emptycell.mc
of
=
temp/tableonly_new.mc
absolute
=
430531840
bs
=
16777216 final
echo
"...completed."
if
[
-f
"metacell/xorkron"
]
;
then
echo
"xorkron exists"
else
echo
"Compiling xorkron..."
cd
metacell
g++
-O3
-march
=
native
-std
=
c++11
-Wall
-Wextra
xorkron.cpp
-o
xorkron
cd
-
fi
echo
"Constructing metapattern..."
metacell/xorkron
"temp/tableonly_new.mc"
"metacell/tableonly_default.mc"
"metacell/complete_default.mc"
"
$INPUT_FILE
"
"
$OUTPUT_FILE
"
rm
-r
temp
echo
"...constructed."
lifelib
@
f44177c5
Compare
b9f47959
...
f44177c5
Subproject commit
b9f479598a3de2d358ca8ef40071a55ec1f0a7b1
Subproject commit
f44177c5ef1ecebfc830921e31102d92f1dbab60
metacell/xorkron.cpp
deleted
100644 → 0
View file @
f992d53a
#include "../lifelib/pattern2.h"
int
main
(
int
argc
,
char
*
argv
[])
{
apg
::
lifetree
<
uint32_t
,
4
>
lt
(
1500
);
apg
::
pattern
part1
(
&
lt
,
std
::
string
(
argv
[
1
]));
apg
::
pattern
part2
(
&
lt
,
std
::
string
(
argv
[
2
]));
apg
::
pattern
part3
(
&
lt
,
std
::
string
(
argv
[
3
]));
apg
::
pattern
patch
=
part1
^
part2
;
apg
::
pattern
onecell
=
patch
^
part3
;
apg
::
pattern
nocell
(
&
lt
,
""
,
"b3s23"
);
onecell
=
onecell
.
centre
();
apg
::
pattern
origpattern
(
&
lt
,
std
::
string
(
argv
[
4
]));
apg
::
pattern
metapattern
=
origpattern
.
tensor
(
onecell
,
nocell
);
std
::
ofstream
out
(
argv
[
5
]);
metapattern
.
write_macrocell
(
out
);
return
0
;
}
update-lifelib.sh
View file @
4ed63f14
...
...
@@ -4,6 +4,7 @@ then
if
[
-d
"lifelib/avxlife"
]
then
printf
"Ensuring lifelib is up-to-date...
\n
"
printf
"import lifelib
\n
lifelib.reset_tree()
\n
"
| python
else
printf
"
\0
33[33;1mDownloading lifelib...
\0
33[0m
\n
"
fi
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment