202607301828

This commit is contained in:
starcells committed 2026-07-30 18:28:19 +08:00
1 parent 95f27efb43
commit a75704a4c0
3 files changed
+15 -18

No files matched your search

+4 -4
View File
@@ -4,6 +4,7 @@
#include <array>
#include <bit>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <ostream>
#include <set>
@@ -13,7 +14,7 @@
#include <unordered_set>
#include <utility>
#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<CELL_SIZE>;
using cell = size_t;
using cell = uint8_t;
using stat = std::array<r8veritas::cell, (1 << CELL_SIZE)>;
using stat_ref = const stat *;
using truthtable = std::pair<const r8veritas::stat *, const r8veritas::stat *>;
using truthtable = std::pair<r8veritas::stat_ref, r8veritas::stat_ref>;
using op = std::function<r8veritas::cell(r8veritas::cell)>;
using index = size_t;
using influence = size_t;
+8 -7
View File
@@ -9,11 +9,6 @@
#include <unordered_set>
#include <utility>
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<r8veritas::stat_ref, bool>
std::pair<r8veritas::stat_ref, bool> // 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 <last_stat,ins> in visited_stat
if (it != visited_stat.end()) { // found <last_stat,ins> 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]++;
}
}
+3 -7
View File
@@ -2,13 +2,9 @@
#include <iostream>
#include <ostream>
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);