Fix the Dial queue: two ways it silently dropped states

First version scanned ahead for the next nonempty bucket but stopped one max
edge weight out, so a sparse frontier ended the search early and claimed
"nothing under the limit" while the queue still had work.  Scanning further is
also wrong: the ring reuses a slot every ring.size steps, so a far bucket sits
where a near one would be.  Plain Dial now: step one cost unit at a time.

The growth table in the README was measured with the broken version and was
wildly optimistic.  Real numbers from the fixed build, full adder with
adjacent cells: cost 58 -> 80M states, 66 -> 220M, 70 -> 280M, about 27 bytes
per state and 650k states/s, so cost 75 / 450M states / 12GB is roughly the
ceiling on this machine.

Validated solve_cost on the small problems where the answer is known by hand:
copy comes out at cost 17 (sacrifice 0 into {2}, then sacrifice 2 into {0,1}),
which is the two block program, and it replays ok.
This commit is contained in:
dsh committed 2026-11-06 09:10:00 +08:00
1 parent 98593b568c
commit 230cf92159
3 files changed
+31 -22

No files matched your search

+16 -11
View File
@@ -98,19 +98,24 @@ w(block) = 3 (biz + flb + rnz) + 2 × span(cell 地址) + Σ op # flb=1, set_1
桶队列(Dial),按代价递增弹出,第一次弹出目标态就是最短纸带。给一个 `max_cost` 上界就变成
分支限界,超出上界的状态不入队。
穷尽得到的数据(6 个 cell 紧邻,full_add):
full_add、6 个 cell 紧邻时,搜索推进到某个代价时已经攒下的状态数:
| max_cost | 状态数 | 用时 |
|---|---|---|
| 20 | 1,086 | 0.0 s |
| 40 | 128,528 | 0.1 s |
| 50 | 999,448 | 0.7 s |
| 60 | 7,671,626 | 12.8 s |
| 65 | 20,153,459 | 47.6 s |
| 代价 | 状态数 |
|---|---|
| 20 | 1,086 |
| 40 | 128,528 |
| 50 | 999,448 |
| 58 | 80,000,000 |
| 62 | 140,000,000 |
| 66 | 220,000,000 |
| 70 | 280,000,000 |
每加 5 点代价状态数约 ×2.6,每状态约 32 字节(8 字节 key + 2 距离 + 4 父 + 2 指令 + 哈希表)。
按这个斜率,`max_cost = 80` 约 3.5 亿状态 / 11 GB,`82` 约 6 亿 / 19 GB —— 后者超出机器
内存,所以默认跑 80。
每状态约 27 字节(8 key + 2 距离 + 4 父 + 2 指令 + 哈希表),到代价 70 约 7.5 GB,速度约
65 万状态/秒。所以这台机器上能跑到的上限大约就是「代价 75 左右 / 4.5 亿状态 / 12 GB」,
再往上就超出内存了 —— 这正是当初估的 13 GB 量级。
因为 Dijkstra 按代价递增弹出,**停在哪儿就证明了「比它更短的纸带不存在」**:跑到代价 d 就
停,等于给出「没有短于 d 字符的程序」这个下界。
注意:模型里的 `w` 不含「上一块的牺牲位跳到这一块」的那几步(`|s_i − s_{i−1}|`),因为那让
代价依赖历史、Dijkstra 就不能用了。发射器会把这部分加上再报真实长度,5 层程序是模型 82 /
+5 -10
View File
@@ -544,18 +544,13 @@ private:
int d = 0;
size_t pops_last = 0;
const int limit = opt.max_cost;
while (true) {
while (d <= limit) {
auto &bucket = ring[size_t(d) % ring.size()];
if (bucket.empty()) {
// Dijkstra pops in nondecreasing order, so when this bucket is dry the
// next state lives in the next nonempty one -- which can be further
// away than one edge weight.
int next = d + 1;
while (next <= limit && ring[size_t(next) % ring.size()].empty())
next++;
if (next > limit)
break; // nothing left under the limit
d = next;
// plain Dial: step one unit at a time. Scanning ahead is not safe --
// the ring reuses slots every ring.size() steps, so a far bucket can
// sit where a near one would be.
d++;
continue;
}
const uint32_t id = bucket.back();
+10 -1
View File
@@ -13,7 +13,16 @@ int main(int argc, char **argv) {
V v;
v.initialize_nicknames();
v.initialize_tp_paths();
auto raw = v.generate_truthtable([](V::cell inp) -> V::cell {
const int problem = argc > 4 ? std::atoi(argv[4]) : 0;
auto raw = v.generate_truthtable([problem](V::cell inp) -> V::cell {
if (problem == 1) { // copy: A -> bit0,bit1
unsigned a = inp & 1;
return V::cell((a << 1) | a);
}
if (problem == 2) { // clb_and: A&B -> bit2
unsigned a = inp & 1, b = (inp >> 1) & 1;
return V::cell(((a & b) << 2));
}
unsigned a = inp & 1, b = (inp >> 1) & 1, c = (inp >> 2) & 1;
unsigned s = a ^ b ^ c;
unsigned co = (a & b) | (a & c) | (b & c);