Commit fe776fb
committed
Substrate refactor: route compute_resonance and friends through phi_pi_fib
The foundational harmonic ops now use the canonical FIBONACCI table
and phi_pi_fib's Fibonacci-step search instead of duplicated local
arrays + linear scans. New surface in phi_pi_fib.rs:
nearest_attractor_with_dist(value: i64) -> (i64, i64)
The canonical "snap to nearest attractor" primitive.
Sign-preserving, tie-break to lower (matches old linear-scan
semantics). Returns (nearest, |value - nearest|).
fold_to_nearest_attractor(value: i64) -> i64
Discards the distance.
is_on_fibonacci_attractor(value: i64) -> bool
True iff distance is 0.
Four foundational call sites refactored:
value.rs::HInt::compute_resonance — was 16-element linear scan
value.rs::is_fibonacci — was 20-element .contains()
interpreter.rs::fold_to_fibonacci_const — was 15-element linear scan
interpreter.rs::is_on_fibonacci_attractor — was 15-element .any()
These were 4 of the 17+ duplicate Fibonacci tables across the
codebase. The remaining ~13 (inline `fibs:` arrays in interpreter.rs
builtin bodies, vm.rs hot path, bytecode_opt.rs) are mechanical
replacements and will follow in a separate commit so the diff stays
reviewable.
Semantic changes:
- For |value| <= 610: byte-identical to the old behavior. All 92
conformance tests pass.
- For |value| > 610: STRICTLY MORE ACCURATE. The old 16-element
table saturated at 610 (giving res(1000) = 0.610). The canonical
40-element table extends to 63,245,986, so res(1000) = 0.987
(nearest attractor is 987, distance 13). Nothing in the test
suite or examples depended on the saturation.
Substrate-coherence implication:
Every HInt::new() in OMC now routes its nearest-attractor lookup
through the phi_pi_fib Fibonacci-step search. Per experiment 9,
that's 90% step-coherent (step sizes are F(k) by construction)
versus the old linear scan's degenerate 100% (every step F_1 = 1,
no information used). The foundational op now describes itself
in the substrate's native vocabulary.
Counter side effect:
phi_pi_fib_stats() now reflects TOTAL substrate work across the
whole program (every HInt construction bumps the counter), not
just explicit phi_pi_fib_search calls. That's a more honest
measurement of substrate load but changes the interpretation of
prior experiments' compare-per-search numbers — exp 7's "gate
work" went from 24 compares to 857 because the counter now
includes the background HInt construction work the gate triggers.
Flagged for a follow-up that either splits the counter or
snapshots it more carefully in experiments.
148/148 tests pass. Both engines audit byte-identical on both
exp 7 (2712 bytes) and exp 9 (3117 bytes).1 parent ac2f15a commit fe776fb
3 files changed
Lines changed: 85 additions & 37 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5070 | 5070 | | |
5071 | 5071 | | |
5072 | 5072 | | |
5073 | | - | |
5074 | | - | |
5075 | | - | |
5076 | | - | |
5077 | | - | |
5078 | | - | |
5079 | | - | |
5080 | | - | |
5081 | | - | |
5082 | | - | |
5083 | | - | |
5084 | | - | |
| 5073 | + | |
| 5074 | + | |
| 5075 | + | |
5085 | 5076 | | |
5086 | 5077 | | |
5087 | 5078 | | |
5088 | | - | |
5089 | | - | |
5090 | | - | |
5091 | | - | |
5092 | | - | |
| 5079 | + | |
| 5080 | + | |
| 5081 | + | |
5093 | 5082 | | |
5094 | | - | |
5095 | | - | |
5096 | | - | |
| 5083 | + | |
5097 | 5084 | | |
5098 | 5085 | | |
5099 | 5086 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
317 | 376 | | |
318 | 377 | | |
319 | 378 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
32 | 42 | | |
33 | | - | |
| 43 | + | |
34 | 44 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
439 | 439 | | |
440 | 440 | | |
441 | 441 | | |
442 | | - | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
443 | 448 | | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
| 449 | + | |
448 | 450 | | |
449 | 451 | | |
450 | 452 | | |
| |||
0 commit comments