|
| 1 | +# PhiSpiral256 Leaf Planetarium Integration Plan — ndarray |
| 2 | + |
| 3 | +## Goal |
| 4 | + |
| 5 | +Define the ndarray-side primitive for **PhiSpiral256**, a leaf-location codec that complements PolarQuant and CAM_PQ. |
| 6 | + |
| 7 | +This plan keeps the terms separate: |
| 8 | + |
| 9 | +```text |
| 10 | +PolarQuant |
| 11 | + magnitude / similarity / distance-like compression |
| 12 | +
|
| 13 | +CAM_PQ |
| 14 | + meaning / semantic basin compression |
| 15 | +
|
| 16 | +BGZ17 |
| 17 | + golden-ratio offset/stride recoverable sampling skeleton |
| 18 | +
|
| 19 | +PhiSpiral256 |
| 20 | + orthogonal local residual location encoded as golden-spiral address |
| 21 | +
|
| 22 | +Fisher-z cosine |
| 23 | + optional statistical angular scorer / confidence gate after candidate ranking |
| 24 | +``` |
| 25 | + |
| 26 | +PhiSpiral256 is not HHTL. It is a **planetarium lane** that can sit beside HHTL, CAM_PQ, PolarQuant, and BGZ17 in struct-of-arrays pipelines. |
| 27 | + |
| 28 | +## Core thesis |
| 29 | + |
| 30 | +```text |
| 31 | +The leaf should not carry the full difference. |
| 32 | +The leaf should carry where the unexplained difference lives. |
| 33 | +``` |
| 34 | + |
| 35 | +PhiSpiral256 compresses orthogonal residual location into one byte: |
| 36 | + |
| 37 | +```text |
| 38 | +continuous orthogonal local residual direction |
| 39 | + -> |
| 40 | +golden-spiral address 0..255 |
| 41 | +``` |
| 42 | + |
| 43 | +Then the packed atom can combine: |
| 44 | + |
| 45 | +```text |
| 46 | +8 bits phi_spiral_id |
| 47 | +4 bits magnitude band |
| 48 | +2 bits BGZ offset family |
| 49 | +2 bits BGZ stride family |
| 50 | +``` |
| 51 | + |
| 52 | +This yields: |
| 53 | + |
| 54 | +```text |
| 55 | +256 spiral locations |
| 56 | +× 16 magnitudes |
| 57 | +× 4 offset families |
| 58 | +× 4 stride families |
| 59 | += 65,536 recoverable local residual states |
| 60 | +``` |
| 61 | + |
| 62 | +## Relationship to BGZ17 |
| 63 | + |
| 64 | +BGZ17 is the recoverable sampling skeleton, not the same thing as PhiSpiral256. |
| 65 | + |
| 66 | +BGZ17 supplies: |
| 67 | + |
| 68 | +```text |
| 69 | +golden-ratio offset/stride sampling |
| 70 | +16k -> Base17 compression |
| 71 | +recoverable sparse sampling schedule |
| 72 | +SIMD-friendly Base17 kernels |
| 73 | +``` |
| 74 | + |
| 75 | +PhiSpiral256 supplies: |
| 76 | + |
| 77 | +```text |
| 78 | +local orthogonal location address |
| 79 | +spiral neighbor structure |
| 80 | +location-lane table lookup |
| 81 | +``` |
| 82 | + |
| 83 | +Together: |
| 84 | + |
| 85 | +```text |
| 86 | +BGZ17 tells how to sample/recover. |
| 87 | +PhiSpiral256 tells where the unexplained residual lives. |
| 88 | +``` |
| 89 | + |
| 90 | +## Relationship to Palette256 |
| 91 | + |
| 92 | +Do not mix the terms. |
| 93 | + |
| 94 | +```text |
| 95 | +Palette256 |
| 96 | + candidate ranking / codebook indexing layer |
| 97 | +
|
| 98 | +PhiSpiral256 |
| 99 | + golden-spiral address space for local residual location |
| 100 | +
|
| 101 | +Fisher-z cosine |
| 102 | + statistical scorer/gate after candidate ranking |
| 103 | +``` |
| 104 | + |
| 105 | +PhiSpiral256 may reuse the existing 256-entry palette/distance-table mechanics, but its semantics are a location address, not a generic palette prototype. |
| 106 | + |
| 107 | +## Coordinate flow |
| 108 | + |
| 109 | +```text |
| 110 | +source residual |
| 111 | + -> |
| 112 | +remove CAM_PQ / meaning-explained component |
| 113 | + -> |
| 114 | +orthogonal residual |
| 115 | + -> |
| 116 | +BGZ17 offset/stride sampling family |
| 117 | + -> |
| 118 | +local planetarium coordinate |
| 119 | + -> |
| 120 | +PhiSpiral256 address |
| 121 | + -> |
| 122 | +packed leaf atom |
| 123 | +``` |
| 124 | + |
| 125 | +If a Poincare/Mobius chart is used: |
| 126 | + |
| 127 | +```text |
| 128 | +parent anchor |
| 129 | + -> |
| 130 | +Mobius recenter |
| 131 | + -> |
| 132 | +local tangent/orthogonal residual |
| 133 | + -> |
| 134 | +PhiSpiral256 address |
| 135 | +``` |
| 136 | + |
| 137 | +Implementation must keep the chart optional. The first test can use Euclidean local tangent coordinates. |
| 138 | + |
| 139 | +## PhiSpiral256 construction |
| 140 | + |
| 141 | +Use golden/Weyl angular sequence: |
| 142 | + |
| 143 | +```text |
| 144 | +theta_k = 2π * frac(k / φ) |
| 145 | +``` |
| 146 | + |
| 147 | +Use radius depending on the chart: |
| 148 | + |
| 149 | +```text |
| 150 | +Euclidean local chart: |
| 151 | + r_k = sqrt((k + 0.5) / 256) |
| 152 | +
|
| 153 | +Poincare chart: |
| 154 | + rho_k = arcosh(1 + u_k * (cosh(rho_max) - 1)) |
| 155 | + r_k = tanh(rho_k / 2) |
| 156 | + u_k = (k + 0.5) / 256 |
| 157 | +``` |
| 158 | + |
| 159 | +Store centers as compact fixed-point directions: |
| 160 | + |
| 161 | +```rust |
| 162 | +pub struct PhiSpiralCenterQ15 { |
| 163 | + pub x_q15: i16, |
| 164 | + pub y_q15: i16, |
| 165 | + pub radius_q15: u16, |
| 166 | +} |
| 167 | + |
| 168 | +pub struct PhiSpiral256 { |
| 169 | + pub centers: [PhiSpiralCenterQ15; 256], |
| 170 | + pub neighbors: [[u8; K]; 256], |
| 171 | + pub distance: [u16; 256 * 256], |
| 172 | +} |
| 173 | +``` |
| 174 | + |
| 175 | +`K` should start as 8 or 16. |
| 176 | + |
| 177 | +## Packed atom |
| 178 | + |
| 179 | +```rust |
| 180 | +#[repr(transparent)] |
| 181 | +pub struct PhiSpiralLeafAtom16(pub u16); |
| 182 | + |
| 183 | +impl PhiSpiralLeafAtom16 { |
| 184 | + pub fn new(spiral_id: u8, mag4: u8, offset2: u8, stride2: u8) -> Self; |
| 185 | + pub fn spiral_id(self) -> u8; |
| 186 | + pub fn mag4(self) -> u8; |
| 187 | + pub fn offset2(self) -> u8; |
| 188 | + pub fn stride2(self) -> u8; |
| 189 | +} |
| 190 | +``` |
| 191 | + |
| 192 | +Bit layout: |
| 193 | + |
| 194 | +```text |
| 195 | +bits 0..=7 phi_spiral_id |
| 196 | +bits 8..=11 mag4 |
| 197 | +bits 12..=13 offset family |
| 198 | +bits 14..=15 stride family |
| 199 | +``` |
| 200 | + |
| 201 | +## SoA layout |
| 202 | + |
| 203 | +The primitive should be SoA-native: |
| 204 | + |
| 205 | +```rust |
| 206 | +pub struct LeafPlanetariumSoA { |
| 207 | + pub leaf_id: Vec<u64>, |
| 208 | + pub atom_start: Vec<u32>, |
| 209 | + pub atom_len: Vec<u8>, |
| 210 | + |
| 211 | + pub atom16: Vec<PhiSpiralLeafAtom16>, |
| 212 | + pub confidence_q: Vec<u8>, |
| 213 | + |
| 214 | + // sibling lanes, not owned semantically by PhiSpiral256 |
| 215 | + pub cam_pq_id: Vec<u16>, |
| 216 | + pub polarquant_id: Vec<u8>, |
| 217 | + pub replay_ref: Vec<u64>, |
| 218 | +} |
| 219 | +``` |
| 220 | + |
| 221 | +Multiple atoms per leaf are allowed: |
| 222 | + |
| 223 | +```text |
| 224 | +K=1 ultra-fast single local residual address |
| 225 | +K=2 branching / ambiguous residual |
| 226 | +K=4 rich leaf constellation |
| 227 | +K=8 debug or high-certification mode |
| 228 | +``` |
| 229 | + |
| 230 | +## Candidate ranking and scoring |
| 231 | + |
| 232 | +PhiSpiral256 can provide a cheap nearest/neighbor candidate list: |
| 233 | + |
| 234 | +```text |
| 235 | +local residual vector |
| 236 | + -> |
| 237 | +nearest spiral_id |
| 238 | + -> |
| 239 | +neighbor ids from spiral_neighbors[spiral_id] |
| 240 | +``` |
| 241 | + |
| 242 | +Fisher-z cosine is a separate optional scoring pass: |
| 243 | + |
| 244 | +```text |
| 245 | +candidate spiral centers |
| 246 | + -> |
| 247 | +cosine(local_direction, center_direction) |
| 248 | + -> |
| 249 | +Fisher-z transform |
| 250 | + -> |
| 251 | +margin/confidence gate |
| 252 | +``` |
| 253 | + |
| 254 | +Keep this naming strict: |
| 255 | + |
| 256 | +```text |
| 257 | +PhiSpiral256 addresses. |
| 258 | +Palette/ranking narrows. |
| 259 | +Fisher-z judges. |
| 260 | +``` |
| 261 | + |
| 262 | +## Calibration targets |
| 263 | + |
| 264 | +Calibrate against these baselines: |
| 265 | + |
| 266 | +```text |
| 267 | +A. Mag4 only |
| 268 | + 16 magnitude bands, no local location |
| 269 | +
|
| 270 | +B. BGZ17 L1 / weighted L1 |
| 271 | + existing Base17 distance behavior |
| 272 | +
|
| 273 | +C. BGZ17 sign agreement |
| 274 | + existing direction-ish sign kernel baseline |
| 275 | +
|
| 276 | +D. PolarQuant only |
| 277 | + magnitude/similarity compression without local residual place |
| 278 | +
|
| 279 | +E. PhiSpiral256 Euclidean |
| 280 | + local orthogonal direction encoded as spiral address |
| 281 | +
|
| 282 | +F. PhiSpiral256 Poincare/Mobius |
| 283 | + parent-local chart before spiral address |
| 284 | +
|
| 285 | +G. PhiSpiral256 + Fisher-z gate |
| 286 | + same as E/F, but with statistical angular confidence |
| 287 | +
|
| 288 | +H. Hybrid packet |
| 289 | + CAM_PQ meaning + PolarQuant magnitude + PhiSpiral256 location + BGZ17 recovery schedule |
| 290 | +``` |
| 291 | + |
| 292 | +## Metrics |
| 293 | + |
| 294 | +```text |
| 295 | +location recall@1 |
| 296 | +location recall@k |
| 297 | +next-basin recall@1 if used by caller |
| 298 | +candidate fanout reduction |
| 299 | +leaf replay reduction |
| 300 | +atom count per leaf |
| 301 | +bytes per leaf |
| 302 | +palette / spiral occupancy entropy |
| 303 | +Gini coefficient of spiral bin use |
| 304 | +boundary / high-curvature failure rate |
| 305 | +orthogonal residual reconstruction error |
| 306 | +Fisher-z margin distribution |
| 307 | +wrong-high-confidence rate |
| 308 | +ns per encode |
| 309 | +ns per route / candidate lookup |
| 310 | +L1 cache footprint |
| 311 | +``` |
| 312 | + |
| 313 | +## Distortion checks |
| 314 | + |
| 315 | +The spiral must be tested for projection artifacts: |
| 316 | + |
| 317 | +```text |
| 318 | +center over-resolution |
| 319 | +boundary under-resolution |
| 320 | +kissen distortion |
| 321 | +trapez distortion |
| 322 | +cluster collapse |
| 323 | +neighbor discontinuity |
| 324 | +``` |
| 325 | + |
| 326 | +Required diagnostics: |
| 327 | + |
| 328 | +```text |
| 329 | +spiral occupancy histogram |
| 330 | +spiral neighbor graph visualization |
| 331 | +distance matrix heatmap |
| 332 | +radial-bin occupancy |
| 333 | +angular-bin occupancy |
| 334 | +Möbius-equivariance error if Poincare mode is enabled |
| 335 | +``` |
| 336 | + |
| 337 | +## Golden tests |
| 338 | + |
| 339 | +```text |
| 340 | +pack/unpack atom16 roundtrip |
| 341 | +spiral center generation deterministic |
| 342 | +neighbor table symmetric-enough sanity check |
| 343 | +self-distance zero |
| 344 | +distance matrix symmetry |
| 345 | +nearest center deterministic |
| 346 | +multi-atom packet roundtrip |
| 347 | +SoA slicing preserves atom order |
| 348 | +``` |
| 349 | + |
| 350 | +## Benchmarks |
| 351 | + |
| 352 | +```text |
| 353 | +encode_phi_spiral_1k |
| 354 | +encode_phi_spiral_100k |
| 355 | +nearest_phi_spiral_scalar |
| 356 | +nearest_phi_spiral_simd_optional |
| 357 | +neighbor_lookup_1m |
| 358 | +atom16_pack_unpack_1m |
| 359 | +soa_scan_atom16_1m |
| 360 | +fisher_gate_top8_1m |
| 361 | +``` |
| 362 | + |
| 363 | +## Acceptance criteria |
| 364 | + |
| 365 | +- PhiSpiral256 is documented and implemented as location lane, not meaning lane and not magnitude lane. |
| 366 | +- Atom16 pack/unpack is deterministic and zero-allocation. |
| 367 | +- 256 centers and distance table are deterministic for the same mode/config. |
| 368 | +- Existing BGZ17 and palette terminology remains unmixed. |
| 369 | +- PhiSpiral256 beats Mag4-only on orthogonal location recall. |
| 370 | +- Hybrid packet reduces leaf replay / exact recovery workload in at least one synthetic fixture. |
| 371 | +- Fisher-z, if used, improves wrong-high-confidence rate without being required for the hot path. |
| 372 | + |
| 373 | +## First fixture |
| 374 | + |
| 375 | +Synthetic local residual field: |
| 376 | + |
| 377 | +```text |
| 378 | +parent anchor at origin |
| 379 | +16 known orthogonal directions |
| 380 | +random magnitudes |
| 381 | +controlled noise |
| 382 | +masked/missing locations |
| 383 | +known target spiral sector |
| 384 | +``` |
| 385 | + |
| 386 | +Then add: |
| 387 | + |
| 388 | +```text |
| 389 | +BGZ17-derived residual vectors |
| 390 | +CAM_PQ meaning axis removal |
| 391 | +Poincare/Mobius recentering |
| 392 | +multi-atom leaves |
| 393 | +``` |
| 394 | + |
| 395 | +## Wall sentence |
| 396 | + |
| 397 | +```text |
| 398 | +PhiSpiral256 is the leaf planetarium: a one-byte golden-spiral place for the orthogonal difference that meaning and magnitude did not explain. |
| 399 | +``` |
0 commit comments