cubical-transport-hott-lean4/Main.lean
Maximus Gorog c2e3ecb3e3
Some checks are pending
Lean Action CI / build (push) Waiting to run
Initial commit: topolei — cubical-transport HoTT in Lean 4 + Rust FFI
Implements the cells-spec vision: a computation space that preserves
auditability, correctness, interactivity. Phase 1 (Lean kernel +
naga-IR Rust backend) is closed; foundation hypothesis stack
(Selection H1+H2, Subobject H3, Trace H5, Obs.Ctx C2, Cubical.Trace)
landed.

Highlights:
- Cubical-HoTT syntax + value/eval/readback in Lean
- naga-IR pipeline (no GLSL string crosses FFI; 17/17 probes pass)
- Honesty audit: every non-transport (sealed cells, vertex shader,
  Y-flip, presentation conventions) is documented as such
- Polymorphic Trace α as free monoid; Cubical.Trace gives
  CTerm → Trace CTerm by structural fold (homomorphism = definition)
- Selection as Huet zipper; Subobject as Boolean algebra over WCell
- All theorems proven; the proof IS the implementation

See STATUS.md for the resume guide.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 20:40:45 -06:00

94 lines
4.6 KiB
Text

import Topolei
/-! Entry point for the topolei live transport renderer.
Each subcommand opens a window showing **one fixed fiber** of a
cubical 1-cell. No host-side time-driven animation — fibers are
selected at render time and stay put. Re-run with a different
subcommand to see a different fiber.
Default subcommand (`mid`) shows `plotT` at `pathParam = 0.5`:
`plotT.body = var "t"`, so every pixel evaluates to `0.5` — a
solid 50% grey panel. `at0` shows it at `0.0` (solid black),
`at1` at `1.0` (solid white). `endpoints` shows `at0 | at1`
side-by-side: solid black on the left, solid white on the right
— two genuinely-distinct fibers of the same 1-cell.
`gradient` shows `plotPx`, a constant 1-cell whose body is the
spatial coordinate `px`. Every fiber is the same: a black→white
horizontal gradient. Useful as a sanity check that fibers
coincide on a constant 1-cell (`EMLPath.const_endpoints`).
`transp` (and the older `plotExp` / `plotLn`) are kept reachable
but their bodies leave `[0, 1]` and so their greyscale renders
saturate to white / clamp to black at the display. The probe
test verifies they still match the spec — they're just
visually less informative without a normalized colorspace.
-/
def main (args : List String) : IO Unit := do
match args with
| "at0" :: _ =>
canvasRunPath plotT.toEMLPath 0.0 700 700
"topolei — plotT at pathParam = 0 (solid black, the at0 fiber of var t)"
| "at1" :: _ =>
canvasRunPath plotT.toEMLPath 1.0 700 700
"topolei — plotT at pathParam = 1 (solid white, the at1 fiber of var t)"
| "mid" :: _ | [] =>
canvasRunPath plotT.toEMLPath 0.5 700 700
"topolei — plotT at pathParam = 0.5 (solid 50% grey, the midpoint fiber)"
| "qtr" :: _ =>
canvasRunPath plotT.toEMLPath 0.25 700 700
"topolei — plotT at pathParam = 0.25 (solid 25% grey)"
| "tqr" :: _ =>
canvasRunPath plotT.toEMLPath 0.75 700 700
"topolei — plotT at pathParam = 0.75 (solid 75% grey)"
| "endpoints" :: _ =>
-- Side-by-side boundary fibers of the SAME 1-cell `plotT`.
-- Left panel: pathParam = 0 → solid black.
-- Right panel: pathParam = 1 → solid white.
-- Each panel has its own uniform buffer with its own
-- pathParam — the two fibers are genuinely distinct, and
-- no visualization adapter is aliasing them.
canvasRunPath2
plotT.toEMLPath 0.0
plotT.toEMLPath 1.0
1200 600
"topolei — plotT at0 | at1 (boundary fibers: solid black | solid white)"
| "gradient" :: _ =>
-- Constant 1-cell — body is `var "px"` so the image is fixed
-- regardless of pathParam. Two panels at different pathParams
-- should be pixel-identical (`EMLPath.const_endpoints`
-- realised on the GPU).
canvasRunPath2
plotPx.toEMLPath 0.0
plotPx.toEMLPath 1.0
1200 600
"topolei — plotPx (constant 1-cell): two panels at different pathParam coincide"
| "transp" :: _ =>
-- The original `plotTransp` 1-cell (body = exp(px) - t). Its
-- image leaves [0, 1] for these inputs, so most pixels saturate
-- to white at the display — but the spec and the probes still
-- agree on the underlying float values.
canvasRunPath2
plotTransp.toEMLPath 0.0
plotTransp.toEMLPath 1.0
1200 600
"topolei — plotTransp at0 | at1 (image leaves [0,1]; expect saturation)"
| _ =>
IO.println "topolei — usage:"
IO.println " topolei show plotT at pathParam = 0.5 (default; solid 50% grey)"
IO.println " topolei mid same as default"
IO.println " topolei at0 plotT at pathParam = 0 (solid black)"
IO.println " topolei at1 plotT at pathParam = 1 (solid white)"
IO.println " topolei qtr plotT at pathParam = 0.25"
IO.println " topolei tqr plotT at pathParam = 0.75"
IO.println " topolei endpoints plotT at0 | at1 (black | white side-by-side)"
IO.println " topolei gradient plotPx (constant 1-cell): same gradient on both panels"
IO.println " topolei transp plotTransp at0 | at1 (saturates; spec is honest)"
IO.println ""
IO.println "Each window renders ONE fiber of the cubical 1-cell, statically."
IO.println "There is no host-side time-to-parameter animation — that would"
IO.println "not be a transport. The `Float → RGB` step is identity"
IO.println "(greyscale), not a hue cycle, so fibers that genuinely differ"
IO.println "show distinct pixel output."