MultipleB3S23

For general discussion about Conway's Game of Life.
Post Reply
User avatar
EvinZL
Posts: 854
Joined: November 8th, 2018, 4:15 pm
Location: A tungsten pool travelling towards the sun
Contact:

MultipleB3S23

Post by EvinZL » February 3rd, 2024, 10:17 pm

Today I just decided to look back on the problem of generating ruletrees for MultipleB3S23 and it is literally easier than I thought.

Given rules A and B we define the Cartesian product to be the rule consisting of two non-interacting universes of A*B. Let R and S be reduced ruletrees for A and B respectively. Then it's easy to get a ruletree for A*B where the nodes at a given depth are redered pairs of (R node, S node) of that depth. Call this the Cartesian product R*S. If R and S are reduced then R*S is also reduced.

The number of nodes at each depth in the Life ruletree are 3, 4, 5, 5, 5, 4, 3, 2, 1. So the total number of nodes in the ruletree for Life^n is 3*5^n+2*4^n+2*3^n+2^n+1. Unsurprisingly, this exactly reproduces the known values of 32, 130, 566 for small values. For the next value of Life^4 we should have exactly 2566 nodes. At Life^8 we will have 1,316,326 nodes.

Here is a C++ program to generate the rule trees:

Code: Select all

#if 0
sourcename="$0"
exename="$(readlink -f "${sourcename%.*}")"
g++ -std=c++2a -march=native -O3 "$sourcename" -o "$exename"
"$exename" "$@"; status=$?
exit $status
#endif

/*
Copyright (c) 2023 EvinZL

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#include <vector>
#include <cmath>
#include <iterator>
#include <cstdlib>
#include <iostream>
#include <fstream>

using namespace std;

const int ruletree[] = {
    0, 1, 1, 1, 0, 0,
    2, 0, 0, 1, 1, 2, 2, 2,
    3, 0, 0, 1, 1, 2, 2, 3, 3, 3,
    0, 1, 1, 2, 2, 3, 3, 4, 4, 4,
    0, 1, 1, 2, 2, 3, 3, 4, 4, 4,
    0, 1, 1, 2, 2, 3, 3, 4,
    0, 1, 1, 2, 2, 3,
    0, 1, 1, 2,
    0, 1
};

class TupleIt {
    int length;
    int bound;
    public: 
    TupleIt(int l, int b) {
        length = l;
        bound = b;
    }
    int index(vector<int> v) {
        int idx = 0;
        for (auto i : v) {
            idx *= bound;
            idx += i;
        }
        return idx;
    }
    class iterator : public std::iterator<input_iterator_tag, vector<int>> {
        int length;
        int bound;
        public:
        vector<int> current;
        iterator(TupleIt* t) {
            length = t->length;
            bound = t->bound;
            current.assign(length, 0);
        }
        iterator& operator++() {
            current[length - 1]++;
            for (int i = length - 1; current[i] == bound && i > 0; i--) {
                current[i] = 0;
                current[i - 1]++;
            }
            return *this;
        }
        bool operator==(iterator other) { return current == other.current; }
        bool operator!=(iterator other) { return current != other.current; }
        reference operator*() { return current; }
    };
    iterator begin() { return iterator(this); }
    iterator end() { iterator it = iterator(this); it.current[0] = bound; return it; }
};

void do_level(TupleIt it, int n, int level, int lower_size, int offset, int lookup[], vector<vector<int>>& output) {
    for (auto i : it) {
        vector<int>& node = output.emplace_back(1 + pow(2, n), offset);
        node[0] = level;
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < pow(2, n); k++) {
                node[1 + k] += pow(lower_size, n - 1 - j) * lookup[2 * i[j] + (k >> (n - 1 - j) & 1)];
            }
        }
    }
}

void maketree(int n, vector<vector<int>>& output) {
    int nodes = 3 * pow(5, n) + 2 * pow(4, n) + 2 * pow(3, n) + pow(2, n) + 1;
    int states = pow(2, n);
    output.reserve(nodes);
    TupleIt it2(n, 2);
    TupleIt it3(n, 3);
    TupleIt it4(n, 4);
    TupleIt it5(n, 5);
    do_level(it3, n, 1, 2, 0, (int*)ruletree, output);
    do_level(it4, n, 2, 3, 0, (int*)ruletree + 6, output);
    do_level(it5, n, 3, 4, pow(3, n), (int*)ruletree + 14, output);
    do_level(it5, n, 4, 5, pow(3, n) + pow(4, n), (int*)ruletree + 24, output);
    do_level(it5, n, 5, 5, pow(3, n) + pow(4, n) + pow(5, n), (int*)ruletree + 34, output);
    do_level(it4, n, 6, 5, pow(3, n) + pow(4, n) + 2 * pow(5, n), (int*)ruletree + 44, output);
    do_level(it3, n, 7, 4, pow(3, n) + pow(4, n) + 3 * pow(5, n), (int*)ruletree + 52, output);
    do_level(it2, n, 8, 3, pow(3, n) + 2 * pow(4, n) + 3 * pow(5, n), (int*)ruletree + 58, output);
    do_level(TupleIt(n, 1), n, 9, 2, 2 * pow(3, n) + 2 * pow(4, n) + 3 * pow(5, n), (int*)ruletree + 62, output);
}

int main(int argc, char* argv[]) {
    if (argc < 2) {
        cout << "Usage: ./multipleb3s23 num-layers outfile" << endl;
        return 0;
    }
    int power = strtol(argv[1], nullptr, 10);
    ofstream outfile(argv[2]);
    vector<vector<int>> tree;
    maketree(power, tree);
    outfile << "@TREE" << "\n";
    outfile << "num_states=" << pow(2, power) << "\n";
    outfile << "num_neighbors=8" << "\n";
    outfile << "num_nodes=" << tree.size() << "\n";
    for (auto i : tree) {
        for (int j = 0; j < i.size() - 1; j++) {
            outfile << i[j] << " ";
        }
        outfile << i[i.size() - 1] << "\n";
    }
    outfile.flush();
}
On my computer, quadruple takes 10 milliseconds, sextuple takes 671ms, and septuple takes 7 seconds. Octuple is taking quite a bit longer. I've uploaded QuadrupleB3S23 to LifeWiki, if anybody cares.

Code: Select all

x = 64, y = 64, rule = QuadrupleB3S23
!
#C [[ RANDOMIZE ]]
EDIT: I'm surprisingly impatient. OctupleB3S23 finishes in 1 and a half minutes.

User avatar
PHPBB12345
Posts: 1096
Joined: August 5th, 2015, 11:55 pm
Contact:

Re: MultipleB3S23

Post by PHPBB12345 » February 3rd, 2024, 10:57 pm

What is the difference between QuadrupleB3S23 and QuadB3S23?

Post Reply