MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ truth_table()

MAYAFLUX_API bool MayaFlux::Kinesis::Discrete::truth_table ( std::span< const bool >  history,
std::span< const double >  coefs 
)
noexcept

Any boolean function of the last bits, as a table.

coefs: [arity, outputs...]. Reads the arity newest bits, missing ones as zero, and returns the output at that pattern. A table is a universal gate, so this covers AND, XOR, majority and every other combinational rule, and with a rule number over three bits it is an elementary automaton run through time.

Definition at line 45 of file Boolean.cpp.

46{
47 if (coefs.empty())
48 return false;
49
50 const size_t arity = index_of(coefs.front());
51 if (arity > MAX_TABLE_ARITY || coefs.size() < 1 + (size_t { 1 } << arity))
52 return false;
53
54 size_t pattern = 0;
55 for (size_t i = 0; i < arity && i < history.size(); ++i) {
56 if (history[i])
57 pattern |= size_t { 1 } << i;
58 }
59 return coefs[1 + pattern] > 0.5;
60}