61#ifndef TPL_CA_BLOCK_RULE_H
62#define TPL_CA_BLOCK_RULE_H
81template <
typename State>
89template <
typename R,
typename State>
91 {
r(b) } -> std::convertible_to<Block_2x2<State>>;
94namespace ca_block_rule_detail {
98template <
typename State>
99[[nodiscard]]
inline constexpr State
invert(
const State &s)
noexcept
101 if constexpr (std::is_same_v<State, bool>)
103 else if constexpr (std::is_integral_v<State>)
104 return s == State{0} ? State{1} : State{0};
106 return s == State{} ? State{1} : State{};
110template <
typename State>
114 for (
const auto &v : b)
150 template <
typename State>
153 using namespace ca_block_rule_detail;
154 if (popcount(in) == 2)
158 out[0] = invert(in[3]);
159 out[1] = invert(in[2]);
160 out[2] = invert(in[1]);
161 out[3] = invert(in[0]);
194 template <
typename State>
197 using namespace ca_block_rule_detail;
198 const std::size_t n = popcount(in);
214 = (in[0] != State{})
and (in[3] != State{})
and (in[1] == State{})
and (in[2] == State{});
216 = (in[1] != State{})
and (in[2] != State{})
and (in[0] == State{})
and (in[3] == State{});
217 if (main_diag or anti_diag)
263 template <
typename State>
266 using namespace ca_block_rule_detail;
267 const std::size_t n = popcount(in);
269 if (n == 1 or n == 3)
282 = (in[0] != State{})
and (in[1] != State{})
and (in[2] == State{})
and (in[3] == State{});
283 const bool bottom_row
284 = (in[2] != State{})
and (in[3] != State{})
and (in[0] == State{})
and (in[1] == State{});
285 if (top_row or bottom_row)
297 = (in[0] != State{})
and (in[2] != State{})
and (in[1] == State{})
and (in[3] == State{});
299 = (in[1] != State{})
and (in[3] != State{})
and (in[0] == State{})
and (in[2] == State{});
300 if (left_col or right_col)
312 = (in[0] != State{})
and (in[3] != State{})
and (in[1] == State{})
and (in[2] == State{});
314 = (in[1] != State{})
and (in[2] != State{})
and (in[0] == State{})
and (in[3] == State{});
315 if (main_diag or anti_diag)
346template <
typename Cell_Rule>
364 template <
typename State>
368 for (std::size_t i = 0; i < 4; ++i)
size_t size_t int32_t * out
Fredkin–Toffoli Billiard Ball Machine block rule.
constexpr Block_2x2< State > operator()(const Block_2x2< State > &in) const noexcept
Apply the BBM block rule.
Adapt a regular cell rule (with empty neighborhood) to a block rule.
constexpr Block_2x2< State > operator()(const Block_2x2< State > &in) const
Apply the wrapped rule to every cell of the 2×2 block.
constexpr Cell_Rule_As_Block_Rule(Cell_Rule cr)
Wrap cr as a block rule.
Critters reversible CA block rule.
constexpr Block_2x2< State > operator()(const Block_2x2< State > &in) const noexcept
Apply the Critters block rule.
Toffoli–Margolus (TM) lattice-gas block rule.
constexpr Block_2x2< State > operator()(const Block_2x2< State > &in) const noexcept
Apply the TM lattice-gas block rule.
A rule that maps a 2×2 block to a 2×2 block.
constexpr std::size_t popcount(const Block_2x2< State > &b) noexcept
Population count of a 2×2 block: number of non-zero cells.
constexpr State invert(const State &s) noexcept
Toggle a cell value between its zero and a non-zero counterpart.
@ R
Recovered (and immune).
std::array< State, 4 > Block_2x2
Fixed-size 2×2 block of cell values used by Margolus rules.
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.