Skip to content

Commit 5ebd078

Browse files
HBit::harmony substrate-routed (D3 partial)
Replace the Euclidean `1/(1+|alpha-beta|)` harmony formula in value::HBit::harmony with substrate-routed `1/(1+attractor_distance(|alpha-beta|))`. Harmony now measures coherence with the phi-pi-fibonacci attractor lattice — peaks at 1.0 when the band-diff lands on a Fibonacci attractor (0, 1, 2, 3, 5, 8, 13, 21, ..., 63245986). Decays with distance from the nearest. Also delete the duplicate harmony formula in hbit::HBitProcessor — it now delegates to value::HBit::harmony so both call sites share one substrate-routed implementation. Test coverage refreshed: HBitProcessor::harmony(5, 10) is no longer asserted < 1.0 (diff 5 is on an attractor, so harmony = 1.0 is correct under the new formula). New asserts pin off-attractor pairs (harmony(4, 10) where diff 6 lands between attractors) and far-off pairs (harmony(0, 1000) where diff 1000 lands distance 13 from nearest attractor 987). NOTE: this is D3-PARTIAL. The remaining work — wiring @hbit pragma into a real codegen path (SL HBit architecture targets AVX-512 SIMD intrinsics) — is a multi-session project tracked separately. This commit is the substrate-alignment foundation that the codegen path will build on top of. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 3d4f9b0 commit 5ebd078

2 files changed

Lines changed: 38 additions & 10 deletions

File tree

omnimcode-core/src/hbit.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ impl HBitProcessor {
3737
self.track_harmony(harmony);
3838
}
3939

40-
/// Calculate harmony between two bands (from value.rs HBit)
41-
/// Delegates to existing implementation to avoid duplication
40+
/// Calculate harmony between two bands.
41+
/// Delegates to the canonical substrate-routed formula in value.rs
42+
/// (D3 substrate-fill — was a Euclidean duplicate here, now both
43+
/// sites share the same attractor-distance computation).
4244
pub fn harmony(alpha: i64, beta: i64) -> f64 {
43-
let diff = (alpha - beta).abs() as f64;
44-
1.0 / (1.0 + diff)
45+
crate::value::HBit::harmony(alpha, beta)
4546
}
4647

4748
/// Calculate tension (complementary to harmony)
@@ -217,10 +218,24 @@ mod tests {
217218
use super::*;
218219

219220
#[test]
220-
fn test_hbit_harmony() {
221-
assert_eq!(HBitProcessor::harmony(5, 5), 1.0); // Perfect harmony
222-
assert!(HBitProcessor::harmony(5, 10) < 1.0); // Some discord
223-
assert!(HBitProcessor::harmony(5, 10) > 0.0); // Still positive
221+
fn test_hbit_harmony_substrate_routed() {
222+
// Equal bands → diff 0 → on attractor 0 → perfect harmony.
223+
assert_eq!(HBitProcessor::harmony(5, 5), 1.0);
224+
// Diff lands ON a Fibonacci attractor → perfect harmony (this
225+
// is the architecturally significant change vs the old
226+
// Euclidean formula, where any nonzero diff dropped harmony).
227+
// 10 - 5 = 5; 5 is an attractor; substrate-routed harmony = 1.0.
228+
assert_eq!(HBitProcessor::harmony(5, 10), 1.0);
229+
// Diff lands BETWEEN attractors → harmony < 1.0.
230+
// 10 - 4 = 6; nearest attractor is 5 (dist 1) or 8 (dist 2);
231+
// either way the distance is non-zero so harmony < 1.0.
232+
let h = HBitProcessor::harmony(4, 10);
233+
assert!(h < 1.0);
234+
assert!(h > 0.0);
235+
// Large off-attractor gap → very low harmony.
236+
// 1000 - 0 = 1000; nearest attractor 987 (dist 13).
237+
let h_far = HBitProcessor::harmony(0, 1000);
238+
assert!(h_far < 0.1);
224239
}
225240

226241
#[test]

omnimcode-core/src/value.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,22 @@ impl HBit {
108108
}
109109
}
110110

111+
/// Harmony — substrate-routed measure of how aligned α and β are
112+
/// with OMC's φ-π-fibonacci attractor lattice. Equals
113+
/// `1 / (1 + attractor_distance(|α - β|))`.
114+
///
115+
/// Peak (1.0) when |α - β| is exactly on a Fibonacci attractor
116+
/// (0, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …, up to 63,245,986).
117+
/// Decays with distance from the nearest attractor.
118+
///
119+
/// Pre-substrate-fill this was Euclidean `1 / (1 + |α - β|)`. The
120+
/// substrate routing makes harmony a *coherence with the
121+
/// attractor grid*, not a coincidence-coincidence signal — see
122+
/// SUBSTRATE_CHANGES.md (D3 substrate-routing of HBit harmony).
111123
pub fn harmony(alpha: i64, beta: i64) -> f64 {
112-
let diff = (alpha - beta).abs() as f64;
113-
1.0 / (1.0 + diff)
124+
let diff = (alpha - beta).abs();
125+
let (_, attractor_dist) = crate::phi_pi_fib::nearest_attractor_with_dist(diff);
126+
1.0 / (1.0 + attractor_dist as f64)
114127
}
115128
}
116129

0 commit comments

Comments
 (0)