feat(crystal): sandwich layout + bipolar cells + harvest docs#209
Conversation
…orum sentinel Addresses all 3 Codex comments on PR #208: P1 — Binary16K → VSA10K is now LOSSLESS. Each of the 256 u64 words maps to a contiguous 39-dim slice [start..stop] (VSA convention). 64 bits pack into 39 dims: 25 dims carry 2 bits each (4-level encoding: -1.0 / -0.33 / 0.33 / 1.0), 14 dims carry 1 bit each. Total: 25×2 + 14×1 = 64 bits, no aliasing. Verified by lossless roundtrip test with 0xDEAD_BEEF_CAFE_BABE pattern across all 256 words. P2 — i8 division now uses 128.0 (not 127.0) + clamp to [-1, 1]. -128/128 = -1.0 exactly, no overshoot. P2 — Quorum sentinel at dim 3130: >0 means quorum present, ≤0 means None. Roundtrip test verifies quorum: None survives. Additionally: - VSA algebra ops: vsa_bind (element-wise multiply, self-inverse for ±1 keys), vsa_bundle (superposition), vsa_superpose (weighted), vsa_cosine (similarity). - binary16k_from_vsa10k() inverse function added. - 9 fingerprint-specific tests (was 3), 112 total contract tests. https://claude.ai/code/session_01SbYsmmbPf9YQuYbHZN52Zh
…::hpc::vsa
Aligns the crystal module with existing infrastructure:
Sandwich layout in the 10K-D form (VSA convention: content centered
with role-binding space on each side):
[ 0..3437] lead context — role-A superposition / pre-bind
[3437..6562] 3,125 cells — bipolar, negatives cancel on bundling
[6562..6567] quorum (5D)
[ 6567] quorum sentinel
[6568..10000] tail context — role-B superposition / post-bind
Cells are now BIPOLAR: u8 0..=255 → f32 [-1, 1] via /127.5 - 1.0.
Negative cancellation works for 5^5 too — opposing cells at the same
sandwich dim cancel when two crystals bundle, reinforcing the consensus.
Roundtrip test verifies both directions.
References existing modules (no duplication):
- ndarray::hpc::vsa for the canonical binary-VSA algebra (bind,
unbind, bundle, permute, similarity, hamming, sequence, clean).
- ladybug-rs, ada-consciousness, bighorn for crystal/quantum
implementations. Contract module is the shared type surface only.
Removed ad-hoc bit_chain_stride() — ndarray::hpc::vsa::vsa_permute
is the canonical bit-chain permutation primitive.
Kept:
- sandwich_lead() / sandwich_cells() / sandwich_tail() layout accessors.
- vsa_bind / vsa_bundle / vsa_superpose / vsa_cosine as the f32
continuous-valued variant (complement to ndarray's binary VsaVector).
All 9 fingerprint tests + 112 total contract tests pass.
https://claude.ai/code/session_01SbYsmmbPf9YQuYbHZN52Zh
…rints
Three knowledge docs + one contract doc-string update, following the
2026-04-19 cross-repo survey via pygithub on ladybug-rs,
ada-consciousness, and bighorn.
crystal-quantum-blueprints.md
Maps the two complementary blueprints:
- Crystal mode: grammar as a bundled Markov chain of SPO sentences,
discrete, bipolar cells, negative canceling, sandwich layout.
- Quantum mode: holographic memory as embedding residual accumulation,
phase-tagged (128-bit), signed interference, cos(Δφ)=1-2h/128.
Same 10K substrate, two operating modes. Both already implemented in
ladybug-rs/src/extensions/hologram/ (quantum_5d/7d/crystal.rs).
cross-repo-harvest-2026-04-19.md
14 epiphanies mined from the sibling repos, each with upstream source
and lance-graph hook. Highlights: Born rule (1-2h/N)^2 = |<psi|phi>|^2,
phase tag 16-byte classical/quantum threshold, interference as truth
engine (100% on causal direction, memory immune system), Grammar
Triangle == ContextCrystal(window=1), NSM primes map to SPO+Qualia+
Temporal axes, FP_WORDS=160 SIMD-clean, Mexican-hat time kernel,
Int4State 4-bit facets, Glyph5B 256^5 archetypes, Crystal4K 41:1
compression, teleportation F=1.000000, 144-verb taxonomy, Three
Mountains triangulation.
endgame-holographic-agi.md
North-star doc: holographic memory AGI on the lance-graph stack.
5-layer architecture (L1 ndarray -> L2 codec -> L3 lance-graph spine
-> L4 ladybug-rs agent -> L5 ada-consciousness). 12-step holographic
memory loop with time budgets. P0/P1/P2/P3 follow-up priorities.
Session policy (re-use first, contract-add second, operators down-
stream). One-sentence north star.
crystal/mod.rs
Doc update: alignment note between Crystal hierarchy and the existing
cognitive_shader Φ/Ψ/B/Γ DTO flow. ShaderBus::cycle_fingerprint
[u64; 256] == Container == CrystalFingerprint::Binary16K (same 2 KB
backing). CycleCrystal is the persistence view of ShaderCrystal.
Zero-copy goes through cognitive_shader::ColumnWindow.
112 contract tests still passing.
https://claude.ai/code/session_01SbYsmmbPf9YQuYbHZN52Zh
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 65804528dc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let val = match (b0, b1) { | ||
| (0, 0) => -1.0f32, | ||
| (1, 0) => -0.33, | ||
| (0, 1) => 0.33, | ||
| _ => 1.0, |
There was a problem hiding this comment.
Preserve Hamming ranking in Binary16K 2-bit packing
The 2-bit scalar mapping here (00→-1, 10→-0.33, 01→0.33, 11→1) gives different magnitudes to different bit patterns, so cosine similarity on the projected vectors is not monotonic with original Hamming distance. That breaks the stated “similarity-preserving” behavior for Binary16K: a farther fingerprint can score higher than a nearer one after projection, which can mis-rank nearest-neighbor retrieval when this path is used. If Hamming ordering must be preserved, this needs an equal-weight encoding (for example, per-bit dimensions or an orthogonal 4-state code) instead of amplitude-coding two bits into one scalar.
Useful? React with 👍 / 👎.
| weights: &[f32], | ||
| ) -> Box<[f32; 10_000]> { | ||
| let mut out = Box::new([0.0f32; 10_000]); | ||
| for (v, &w) in vectors.iter().zip(weights.iter()) { |
There was a problem hiding this comment.
Enforce equal lengths in weighted superposition
vsa_superpose uses zip over vectors and weights, so mismatched inputs are silently truncated. In scenarios where callers provide more vectors than weights (or vice versa), part of the intended signal is dropped without any error, yielding incorrect fingerprint composition that is difficult to detect downstream. This should validate matching lengths and fail fast instead of silently discarding data.
Useful? React with 👍 / 👎.
Per user: negative-canceling bipolar with 5^5 (3125 states) and 7^7
(823,543 states) structure. Key fix from prior negative result:
GLOBAL (population-wide) scale instead of per-row max-abs.
Zipper5LevelDescriptor:
- Values ∈ {-2, -1, 0, +1, +2}
- 5 samples = 5^5 states, packs to ~2 B
- 25 samples = 5 × 5^5, packs to ~10 B
- bundle() saturates at ±2; negative values cancel (VSA semantics)
- compute_global_scale() returns median |coef| across population
Zipper7LevelDescriptor:
- Values ∈ {-3, -2, -1, 0, +1, +2, +3}
- 7 samples = 7^7 states, packs to ~3 B
- 49 samples = 7 × 7^7, packs to ~18 B
- bundle() saturates at ±3
Thresholds at half-integer multiples of global_scale:
5-level: {-1.5, -0.5, +0.5, +1.5} × scale
7-level: {-2.5, -1.5, -0.5, +0.5, +1.5, +2.5} × scale
This unifies the Structured5x5 ethos from PR #209 with the φ-stride
zipper sampling. Negative cancellation on bundling means noise cancels,
signal accumulates — useful for VSA query superposition (not directly
measured by the pair-cosine bench, but a property the descriptor holds).
4 new lab-gated CodecCandidates:
Zipper-5^5(2B) — 5 samples, 5-level
Zipper-5^5×5(10B) — 25 samples, 5-level
Zipper-7^7(3B) — 7 samples, 7-level
Zipper-7^7×7(18B) — 49 samples, 7-level
https://claude.ai/code/session_01SbYsmmbPf9YQuYbHZN52Zh
Summary
Follow-up to PR #208 with (a) Codex review fixes, (b) a sandwich-layout refactor aligning
CrystalFingerprint::Structured5x5with VSA bipolar semantics, and (c) three knowledge docs capturing session epiphanies and the endgame.Codex fixes (commit
4b06bb5)-128 → -1.0(was-1.008).quorum: Noneround-trips correctly via a sentinel dim (was collapsing toSome(0,0,0,0,0)).Sandwich layout + bipolar cells (commit
58c11ba)Structured5x5 cells now sit in the middle of the 10K vector with role-binding space on each side (VSA convention):
Cells encode bipolar:
u8 0..=255 → f32 [-1, 1]viav/127.5 - 1.0. Opposing cells at the same sandwich dim cancel when two crystals bundle — VSA negative-canceling now applies to structured cells too. Referencesndarray::hpc::vsa::vsa_permuteas the canonical bit-chain permutation primitive instead of duplicating it.Exposes layout accessors:
sandwich_lead() / sandwich_cells() / sandwich_tail().Knowledge docs (commit
6580452)Three docs capturing the 2026-04-19 cross-repo survey (pygithub against ladybug-rs / ada-consciousness / bighorn):
crystal-quantum-blueprints.md— the two complementary modes. Crystal = bundled Markov chain of SPO sentences (discrete, structural). Quantum = holographic memory via embedding residual accumulation with 128-bit phase tags (continuous, superposition). Both already implemented inladybug-rs/src/extensions/hologram/.cross-repo-harvest-2026-04-19.md— 14 epiphanies (H1–H14) mined from the siblings. Highlights: Born rule(1−2h/N)² = |⟨ψ|φ⟩|², 16-byte phase-tag classical/quantum threshold, interference as truth engine (100% causal direction, memory immune system), Grammar Triangle ≡ ContextCrystal(window=1), NSM → SPO axis map, FP_WORDS=160 for SIMD-clean layout, Mexican-hat time kernel, Int4State, Glyph5B (256⁵), Crystal4K 41:1 compression, teleportation F=1.000000, 144-verb taxonomy, Three Mountains triangulation.endgame-holographic-agi.md— north-star integration of the 5-layer stack (ndarray → codec → lance-graph spine → ladybug-rs agent → ada-consciousness). 12-step holographic memory loop with time budgets, P0/P1/P2/P3 follow-up priorities, and one-sentence north star.Alignment note added to
crystal/mod.rscross-referencing the existingcognitive_shader.rsDTO flow —ShaderBus::cycle_fingerprint [u64; 256] == Container == CrystalFingerprint::Binary16K(same 2 KB backing).Test plan
cargo test -p lance-graph-contract --lib— 112 passing (was 106 pre-harvest, +6 new structured/binary roundtrip + passthrough tests)quorum: Noneround-trip preserved via sentinel-128 → -1.0via /128.0 + clampRelated
https://claude.ai/code/session_01SbYsmmbPf9YQuYbHZN52Zh