diff --git a/include/r8veritas.hh b/include/r8veritas.hh index 1f7f297..3c96cd1 100644 --- a/include/r8veritas.hh +++ b/include/r8veritas.hh @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -13,7 +14,7 @@ #include #include -#define CELL_SIZE 3 +#define CELL_SIZE 5 #define CELL_SIZE_BITWIDTH std::bit_width(unsigned(CELL_SIZE)) #define INS_SIZE (CELL_SIZE + 1) @@ -22,11 +23,10 @@ // mask,bytecode and sacrifice namespace r8veritas { -// using cell = std::bitset; -using cell = size_t; +using cell = uint8_t; using stat = std::array; using stat_ref = const stat *; -using truthtable = std::pair; +using truthtable = std::pair; using op = std::function; using index = size_t; using influence = size_t; diff --git a/src/r8veritas.cc b/src/r8veritas.cc index 297570d..60fbeda 100644 --- a/src/r8veritas.cc +++ b/src/r8veritas.cc @@ -9,11 +9,6 @@ #include #include - - - - - void initialize_nicknames() { for (r8veritas::index i = 0; i < CELL_SIZE; i++) { nicknames[i] = "%" + std::to_string(i + 1); @@ -54,12 +49,12 @@ r8veritas::truthtable generate_truthtable(const r8veritas::op &operation) { save_stat(std::move(out)))); } -std::pair +std::pair // true -> the stat has been visited. operate_ins(const r8veritas::stat_ref &last_stat, const r8veritas::ins &ins) { auto key = std::pair(last_stat, r8veritas::ins_bytecode(ins)); r8veritas::stat next_stat = *last_stat; auto it = visited_stat.find(key); - if (it != visited_stat.end()) { // foud in visited_stat + if (it != visited_stat.end()) { // found in visited_stat return {it->second, true}; } int opcode = ins.bc & 1; @@ -96,6 +91,11 @@ std::ostream &operator<<(std::ostream &os, const r8veritas::ins &s) { bool just_sacrifice = ((s.bc == 0b0) || (s.bc == 0b1)); std::reverse(&str[0], &str[CELL_SIZE]); + /* e.g. + CELL_SIZE = 4 + (0b)00101 -> 01001 + ^ ^str[CELL_SIZE] + */ if (!just_sacrifice) { for (r8veritas::index i = 0; i < str.length() - 1; i++) { if (str[i] == '1') { @@ -168,6 +168,7 @@ compress_stat_space(const r8veritas::truthtable &raw_truthtable) { for (r8veritas::index j = 0; j < (1 << CELL_SIZE); j++) { if ((*(raw_truthtable.second))[j] != (*(raw_truthtable.second))[j ^ (1 << i)]) { + // when [j] can influence the ans influences[i]++; } } diff --git a/tests/r8_test.cc b/tests/r8_test.cc index 7224dd1..e9a7d01 100644 --- a/tests/r8_test.cc +++ b/tests/r8_test.cc @@ -2,13 +2,9 @@ #include #include -r8veritas::cell func_and(r8veritas::cell inp) { - return ((((inp >> 0) & (inp >> 1)) & r8veritas::cell(0b1)) << 2) | - (inp & 0b11); // inp[0]->arg1, inp[1]->arg2, inp[2]->ans -} - r8veritas::cell func_copy(r8veritas::cell inp) { - return (((inp & 1) << 1) | (inp & 1)); // inp[0] -> from,inp[1]->to + bool A = inp & 0b1; + return (A << 1) | A; } r8veritas::cell func_full_add_Co(r8veritas::cell inp) { @@ -41,7 +37,7 @@ int main() { initialize_nicknames(); initialize_tp_paths(); r8veritas::debug_output = true; - auto tab1 = generate_truthtable(func_half_add); + auto tab1 = generate_truthtable(func_full_add_Co); auto new_tab1 = compress_stat_space(tab1); if (bfs(new_tab1)) { r8veritas::path p = track_path(tab1);