Lean 4 cubical-transport HoTT engine + Rust naga-IR FFI. The backend that powers topolei. Cells-spec implementation; the proof IS the implementation.
Find a file
Maximus Gorog 567d8722d5
Some checks are pending
Lean Action CI / build (push) Waiting to run
Refactor Phase 4: Rust ABI v6 → v7 (modal tag unification)
Mirrors the Lean-side modal unification (commits 6e4936d / cfabca3 /
2b7564e) at the native level.  ABI version constant
CUBICAL_TRANSPORT_ABI_VERSION = 7.

Tag unification (15 v6 modal tags → 5 v7 unified tags):
  · TY_MODAL = 9                          (was: TY_FLAT/SHARP/SHAPE = 9-11)
  · TERM_MODAL_INTRO = 17, TERM_MODAL_ELIM = 18
                                          (was: TERM_*_INTRO/ELIM = 17-22)
  · VAL_VMODAL_INTRO = 12                 (was: VAL_V*_INTRO = 12-14)
  · NEU_NMODAL_ELIM = 12                  (was: NEU_N*_ELIM = 12-14)
  · MODKIND_FLAT/SHARP/SHAPE = 0/1/2 (u32 — matches existing tag-
                                          namespace convention)

Tag-id design choice (TERM_MODAL_ELIM = 18, not 20):
  Lean compiler assigns constructor indices in declaration order;
  Syntax.lean declares modalIntro then modalElim consecutively, so
  the runtime tag is 18, not 20.  Using 20 would break FFI
  marshalling.  Same precedent as v4's sigma/path tag ordering.

Reserved freed slots (no v7 reassignment per directive — gaps
documented in tags.rs for future v8+ extensions):
  · CType: 10, 11
  · TERM:  19, 20, 21, 22
  · VAL:   13, 14
  · NEU:   13, 14

Layout tables in cubical_transport.h v7 entry:
  · TY_MODAL          [ℓ, k, A]
  · TERM_MODAL_INTRO  [k, a]
  · TERM_MODAL_ELIM   [k, f, m]
  · VAL_VMODAL_INTRO  [k, inner_value]
  · NEU_NMODAL_ELIM   [k, eliminator_value, stuck_scrutinee]

Cascade across:
  · tags.rs — 15 deletions + 5 unified consts + 3 ModalityKind +
    reservation block
  · value.rs — CVal::VModalIntro(ModalityKind, _) and
    CNeu::NModalElim(ModalityKind, _, _) variants
  · eval.rs — 9-arm modal dispatch → 3-arm; β-rule fires only on
    matching kinds (k == k') with marker neutral on mismatch
  · subst.rs — 9 modal substDim arms → 3 unified
  · readback.rs — 6 modal readback arms → 2
  · dim_absent.rs — 9 dim-absent modal arms → 3

Files NOT touched (verified): transport.rs, composition.rs,
glue.rs, beta.rs, ffi.rs.  Wildcard catchalls handle modal types as
stuck neutrals (same as v6).

Refcount discipline for the new k field documented at every
mk_vmodal_intro / mk_nmodal_elim / mk_ty_modal call site.

Verification:
  · cargo build --release: clean
  · cargo test --release: 0 passed, 0 failed (no in-crate tests)
  · lake build: 48 jobs PASS
  · lake build CubicalTransport: 43 jobs PASS
  · lake exe cubical-test: 49/49 + 46/46 = 95/95 PASS
  · 0 new unsafe / unimplemented! / todo! / panic! catchalls

Net: -58 lines across 7 files (-397 deletions, +339 insertions).
Source-code reduction concentrated in cascade modules; tags.rs and
header grew due to reservation documentation and v7 layout tables.

Honest gap: existing test suite doesn't exercise modal terms via
FFI (modal Lean-side use sits behind sorry'd Phase 3 axioms).  The
95/95 confirms no regression of existing paths but doesn't directly
validate v7 modal marshalling.  An FFI smoke test exercising modal
terms is queued for when modal cohesion sorries discharge.

Layer 0 + elegance refactor pass COMPLETE.  All four phases landed:
Phase 1 (derive_reflect_reify macro), Phase 2 (Lean modal
unification), Phase 3 (Modal.lean rewrite + topolei consumer
cascade), Phase 4 (Rust ABI v7).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 02:25:10 -06:00
.forgejo/workflows Add proprietary LICENSE; move CI to .forgejo/workflows/, run cubical-test 2026-04-27 23:04:16 -06:00
CubicalTransport Refactor Phase 3a: Modal.lean rewrite — forModalityKind unification 2026-05-06 02:13:16 -06:00
docs REL2 universe stratification + topolei naming cleanup + Rust ABI v4 2026-05-04 00:21:14 -06:00
native/cubical Refactor Phase 4: Rust ABI v6 → v7 (modal tag unification) 2026-05-06 02:25:10 -06:00
.gitignore Initial commit: topolei — cubical-transport HoTT in Lean 4 + Rust FFI 2026-04-27 20:40:45 -06:00
build.sh Split: engine = cubical-transport HoTT only 2026-04-27 21:35:01 -06:00
CubicalBench.lean REL2 universe stratification + topolei naming cleanup + Rust ABI v4 2026-05-04 00:21:14 -06:00
CubicalTest.lean Split: engine = cubical-transport HoTT only 2026-04-27 21:35:01 -06:00
CubicalTransport.lean Modal cascade Phase 3: Modal.lean module proper — Layer 0 complete 2026-05-05 23:28:01 -06:00
lake-manifest.json Drop Infoductor dependency; cubical-transport is now pure cubical engine 2026-05-01 07:52:59 -06:00
lakefile.toml REL2 universe stratification + topolei naming cleanup + Rust ABI v4 2026-05-04 00:21:14 -06:00
lean-toolchain Initial commit: topolei — cubical-transport HoTT in Lean 4 + Rust FFI 2026-04-27 20:40:45 -06:00
LICENSE Add proprietary LICENSE; move CI to .forgejo/workflows/, run cubical-test 2026-04-27 23:04:16 -06:00
NOTICE Add NOTICE: AI tooling acknowledgement; proprietary rights stand on human-directed whole 2026-04-27 23:10:32 -06:00
README.md REL2 universe stratification + topolei naming cleanup + Rust ABI v4 2026-05-04 00:21:14 -06:00

cubical-transport-hott-lean4

A Lean 4 implementation of cubical-transport homotopy type theory (CCHM-flavor), with a fast Rust kernel exposed through C ABI.

The Lean side defines the syntax, semantics, and soundness theorems. The Rust side discharges the per-step β-rules of the evaluator. Lean axioms are routed through @[implemented_by] to Rust functions that return Lean objects in the same shape Lean would have produced; the soundness layer (CubicalTransport/Soundness.lean) certifies the backend at the boundary, so the kernel speed of the Rust code preserves the Lean-level proofs.

What's here

  • CubicalTransport/ — 22 Lean modules for syntax, substitution, dimensional structure, faces, typing, evaluation (eval / value / readback), transport, Glue, composition, and the soundness theorems.
  • native/cubical/ — Rust kernel (#![no_std], dual-target native staticlib + cdylib, wasm32 cdylib).
  • CubicalTest.lean, CubicalBench.lean — engine smoke + property tests (62/62 passing) and microbenchmarks.

Consuming the engine (with permission)

This Software is proprietary. See LICENSE — no use is granted by virtue of the repository being public. The instructions below are for the copyright holder and any party with prior written consent from mgorog@gmail.com.

Add as a Lake dependency from another Lean 4 project:

[[require]]
name = "cubicalTransport"
path = "../cubical-transport-hott-lean4"   # or git = "..."

Then import CubicalTransport.Syntax, import CubicalTransport.Eval, etc. Link against native/cubical/target/release/libcubical_transport.a in your own moreLinkArgs so the FFI symbols resolve.

Build

(cd native/cubical && cargo build --release)
lake build
./.lake/build/bin/cubical-test    # 62/62 tests pass

Reference

  • docs/FFI_DESIGN.md — C ABI contract between Lean and the Rust kernel.
  • docs/FFI_COMPLETENESS.md — per-function axiom audit.
  • docs/KERNEL_BOUNDARY.md — what this delivers in unmodified Lean 4 vs. what would need upstream Lean kernel work.
  • docs/NUMERICAL.md — numerical implementation principles.
  • docs/PHASE1_HISTORY.md — original transport/composition formalisation plan (archived; Phase 1 closed; preserved as methodology template for future phases).
  • docs/ZIGZAG_PORT.md — step-by-step Lean port plan for the n-category combinatorial engine (Phase 2+ higher-cell backend). Lands here in the engine. Read the cascade caveat at the top before editing: changes in the ported zigzag layer cascade to the sibling topolei repo.
  • native/cubical/README.md — Rust crate build + dev guide.
  • native/cubical/WASM.md — wasm32 ABI integration contract.

Used by

  • max/topolei — the cells-spec workspace interface, built on this engine. See its docs/cells-spec.md and docs/STATUS.md for the application-side picture.