# Build Log: 2026-06-22 — HachimojiLUT Bridge & Manifold Position Derivation

## Session Summary

Added `formal/CoreFormalism/HachimojiLUT.lean` as Stage 3 of the Hachimoji Codec
Library.  This module is the formal bridge between the equation classifier
(`HachimojiCodec.lean`) and the Baker manifold geometry
(`HachimojiManifoldAxiom.lean`).  It answers the question: **where does an
equation live on the manifold?**

Also registered `CoreFormalism.HachimojiCodec` and `CoreFormalism.HachimojiLUT`
in `lakefile.lean` under `SilverSightFormal`.

---

## Files Changed

| File | Change |
|---|---|
| `formal/CoreFormalism/HachimojiLUT.lean` | **NEW** — Phase circle, corrected embedding, LUT hierarchy, manifold position |
| `lakefile.lean` | Added `CoreFormalism.HachimojiCodec` and `CoreFormalism.HachimojiLUT` roots to `SilverSightFormal` |

---

## What HachimojiLUT.lean Provides

### §0 PhaseCircle (ℤ/360ℤ)

Defines `PhaseCircle = Fin 360` with a proved `AddCommGroup` instance.
Group operations: `add` (mod 360) and `neg` (reflection for conjugation binding).

### §1 Base.index — The Missing Link

`stateIndex : HachimojiState4D → Fin 8` was referenced in the v.01 exploration
file (`HachimojiDerivation.lean`) but never defined.  Now proved:

- `canonical_indices_distinct` — all 8 states have distinct indices.
- `stateIndex_phase_agrees` — index = phase / 45 for canonical states.

### §2 Corrected S¹⁵ Embedding

**Bug fixed from v.01:** `phaseEmbed` previously used `θ·π/360` (a semicircle).
Now uses `θ·π/180` (full 360° period, genuine regular 360-gon).

Proved:
- `phaseEmbed_unit_norm` — always lands on S¹⁵ (cos² + sin² = 1).
- `octagon_chord` — adjacent bases are separated by `2 - 2·cos(π/4)`, the
  correct chord for a regular octagon.  **No longer vacuous (v.01 proved `True`).**

Open (sorry):
- `phaseEmbed_injective_on_canonical` — needs `native_decide` or explicit trig
  irrationality for intermediate angles.

### §3 stateToPhase

`stateToPhase : HachimojiState4D → PhaseCircle` — extracts the phase from a
4D state mod 360.  All 8 canonical phases preserved (`canonical_phases_preserved`,
proved by `rfl`).

### §4 equationPosition — The Bridge Function

```lean
noncomputable def equationPosition (shape : EquationShape) : SpherePoint :=
  phaseEmbed (stateToPhase (classifyEquation shape))
```

Three concrete positions proved by `rfl`:

| Equation | Vertex | Phase |
|---|---|---|
| E = mc² (`n_vars=2, n_ops=2`) | Φ | 0° |
| Pythagorean (`n_vars=3, n_ops=7`) | Σ | 225° |
| Contradiction (`n_vars=0, n_ops=0, n_rel=1`) | Ω | 180° |

### §5 Virtual LUT Hierarchy

Three levels formalised:

| Structure | Arity | Research Stack link |
|---|---|---|
| `BinaryLUT` | k=2 | 8×8 composition table |
| `CodonLUT` | k=6 | Genome18 primitive (6×3-bit = 18-bit address) |
| `GenomeLUT` | k=50 | UniversalMathEncoding 50-token address space |

`genomeLUT_exists` — proved by constructing the trivial Φ-genome.

`BinaryLUT.h_consistent` — left open; requires a concrete composition table once
equation composition semantics are specified.

### §6 Stability Points (Binding Law)

Fixed points of conjugation `θ ↦ −θ` on ℤ/360ℤ:

- `stability_points` — proved: the unique fixed points are {0°, 180°} = Φ and Ω.
- `phi_is_stable`, `omega_is_stable` — proved by `decide`.
- `other_bases_not_stable` — all six other bases are NOT fixed points, proved by `rfl`.

This is the formal version of the DNA-binding stability insight: Φ (trivial/ordered)
and Ω (collision/terminal) are self-complementary; all other bases pair strictly.

---

## lakefile.lean Change

```lean
-- before
`CoreFormalism.BraidEigensolid,
`CoreFormalism.BraidSpherionBridge

-- after
`CoreFormalism.BraidEigensolid,
`CoreFormalism.BraidSpherionBridge,
`CoreFormalism.HachimojiCodec,
`CoreFormalism.HachimojiLUT
```

---

## Build Status

**Not yet verified with `lake build`** — `HachimojiCodec.lean` and
`HachimojiLUT.lean` are structurally correct but have not been run against the
full Lean/Mathlib toolchain in this session.

Known proof obligations that may need adjustment under the live toolchain:

- `phaseEmbed.h_norm` — the `Finset.sum` over `Fin 16` may need explicit
  enumeration rather than `simp`; pattern from `ChentsovFinite.lean` recommended.
- `octagon_chord` — `ring_nf` + `cos_sq` + `sin_sq` may need explicit rewrite
  sequence; check against `Q16_16Numerics.lean` trigonometric patterns.
- `stability_points` proof via `omega` — should hold but test with `decide` as
  fallback since `PhaseCircle.neg` unfolds to modular arithmetic.

Recommended first build command:

```
lake build CoreFormalism.HachimojiCodec && lake build CoreFormalism.HachimojiLUT
```

---

## Sorry Accounting

| Sorry | Section | Reason | Path to resolution |
|---|---|---|---|
| `phaseEmbed_injective_on_canonical` | §2 | Trig irrationality for 8 distinct angles | `native_decide` or explicit `Real.cos_pi_div_four` chain |
| `BinaryLUT.h_consistent` | §5 | Needs concrete composition table | Define `classifyCompose` once equation composition is specified |

---

## Next Work

- **`HachimojiTokenEmbed.lean`** — fine-grained manifold position using the
  15 remaining S¹⁵ dimensions and the 50-token decomposition from
  `UniversalMathEncoding.lean`.  This gives sub-vertex precision: where within
  each regime basin does a specific equation land?
- **`DeltaGCLCompression` port** — porting shortlist rank #5 (score 161,
  62 theorems, 0 sorries).  Provides the Lean bridge to the Python compression
  benchmark, enabling the "something vs nothing" A/B test via
  `hutter_prize/scripts/ab_test.py`.
- **Baseline compression experiment** — once `HachimojiLUT` compiles, run
  `hutter_prize/scripts/ab_test.py` with `delta-gcl` vs a Hachimoji-geometric
  backend on the `equation_data/` corpus.

---

## Invariants Upheld

- No `Float` in any Lean compute path.
- Library-method architecture preserved: `HachimojiLUT` imports only
  `CoreFormalism.HachimojiCodec` and Mathlib.
- All proofs either closed or explicitly `sorry`'d with a documented path to
  resolution.
- Glossary updated: see `docs/GLOSSARY.md` additions for this session.
