Some checks failed
Lean Action CI / build (push) Has been cancelled
Two structural changes landed together as one coherent body of work.
## 1. Engine is name-clean from higher-order projects
The engine no longer carries "topolei" in its own naming surface.
Higher-order projects depend on the engine, not vice versa, so the
engine should be self-named.
topolei-cubical (Cargo) → cubical-transport
libtopolei_cubical.a → libcubical_transport.a
topolei_cubical.h → cubical_transport.h
TOPOLEI_FFI_ABI_VERSION → CUBICAL_TRANSPORT_ABI_VERSION
topolei_cubical_* (14 FFI fns) → cubical_transport_*
topolei_shim_* (9 shim fns) → cubical_transport_shim_*
Inter-repo references describing topolei as a downstream consumer
(README, KERNEL_BOUNDARY.md, INDUCTIVE_TYPES.md, etc.) are preserved
as legitimate dependency-direction descriptions.
## 2. Universe-stratified, dependently-typed CType
CType : ULevel → Type (genuinely indexed inductive)
with dependent pi/sigma carrying a binder name, a lift constructor
for cumulativity, and parameter lists of Σ-packaged types.
Per CCHM rules:
· univ ℓ : CType (ℓ.succ)
· pi/sigma : CType (max ℓ_A ℓ_B), with named binder
· path A : at A's level
· glue T A : T and A at same level
· ind : at user-chosen level (heterogeneous-level params)
· interval : CType .zero
· lift : CType (ℓ.succ), data-preserving
Every existing engine module cascades through {ℓ : ULevel} implicits
on functions/theorems, pi/sigma binder updates, and Σ-packaged params
lists. CTerm stays un-indexed (universe lives on CType).
## 3. Substrate machinery for the cascade
Universe.lean — ULevel inductive + max algebra (assoc, comm, etc.),
all theorems proven structurally.
Syntax.lean — adds SkeletalCType enum + CType.skeleton level-erasure
projection + per-constructor skeleton_* simp lemmas +
CType.ind_skeleton_ne_pi disjointness lemma. Used to
discharge cross-level HEq cases in TransportLaws/CompLaws
without invoking K.
## 4. Rust ABI v3 → v4
Lean 4 keeps implicit {ℓ : ULevel} parameters at runtime as constructor
fields, in declaration order interleaved with explicit args (verified
via probeLayout instrumentation). Layout for level-bearing constructors
documented in cubical_transport.h §"v4 layout tables".
CType.pi : 5 fields — [ℓ_d, ℓ_c, var, A, B]
CType.path : 4 fields — [ℓ, A, a, b]
CType.glue : 9 fields — [ℓ, φ, T, f, fInv, sec, ret, coh, A]
CType.ind : 3 fields — [ℓ, S, params]
CType.lift : 2 fields — [ℓ, A]
CTerm.transp : 5 fields — [i, ℓ, A, φ, t] (i precedes ℓ)
CVal.vCompFun : 9 fields — [ℓ_d, ℓ_c, env, i, dom, cod, φ, u, t]
... etc
All Rust marshalling (value.rs, eval.rs, transport.rs, composition.rs,
glue.rs, beta.rs, dim_absent.rs, readback.rs, subst.rs, ffi.rs, tags.rs)
updated to match.
## Discipline
· Zero sorry in CubicalTransport/.
· Zero noncomputable instances; zero Classical.propDecidable shortcuts.
· No CType.level projection (the level lives in the inductive's index).
· No parallel CTypeU type.
· No stub substrate types (def Ω := CType.univ etc.).
· Tests restored to full coverage (EvalTest 623 lines, FFITest 351
lines with classifier-runtime tests intact).
## Verification
cd cubical-transport-hott-lean4
lake build # 48 jobs OK
./.lake/build/bin/cubical-test
# ── 49/49 passed ──
# ── 46/46 properties passed ──
# PASS: all smoke + property tests
cd ../topolei
lake build # 90 jobs OK
./.lake/build/bin/probe-test
# ── 7/7 probes passed ──
# PASS: GPU output matches Lean ShaderSemantic
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
96 lines
5 KiB
Text
96 lines
5 KiB
Text
/-
|
||
CubicalTransport.CompLaws
|
||
========================
|
||
Residual step-level axiom for composition: subject reduction (C4).
|
||
|
||
C1 (`comp_full`) and C2 (`comp_empty`), formerly stated here as
|
||
step-level axioms, are now NbE theorems in `Cubical/Readback.lean`
|
||
(`readback_comp_full` / `readback_comp_empty`). The Rust backend's
|
||
discharge obligations for composition reduce to: the eval-level
|
||
axioms in `Eval.lean`, the readback-level axioms in `Readback.lean`,
|
||
and the C4 residual below.
|
||
|
||
Note on CCHM C3 (`transp = comp_{[φ↦t₀]} t₀`):
|
||
CCHM expresses transport as a specialised composition. That
|
||
specialisation is only *typed* when the system body coincides with
|
||
the base (u = t₀) and the compatibility `t₀[i:=0] = t₀` holds —
|
||
i.e. `L.binder` is absent from `t₀`. Stating it would duplicate
|
||
the constant-line transport identity (`readback_transp_const_id`).
|
||
The real CCHM reduction (`transp = hcomp + fill`) lives at the
|
||
eval level; see `vCompFun` / `vApp_vCompFun` in `Eval.lean`.
|
||
|
||
Why C4 stays step-level: same reason as T3 — needs a typing-
|
||
preservation lemma on `eval`/`readback` (Stream B #2a).
|
||
-/
|
||
|
||
import CubicalTransport.System
|
||
import CubicalTransport.TransportLaws
|
||
import CubicalTransport.ValueTyping
|
||
|
||
-- ── Subject reduction for composition ────────────────────────────────────────
|
||
|
||
/-- **C4 (composition subject reduction)** — stepping a well-typed
|
||
composition preserves the output type.
|
||
|
||
**Now a theorem, not an axiom.** Stage 2.3 consolidation: follows
|
||
from `HasType.comp` and `CTerm.step_preserves_type` (ValueTyping.lean).
|
||
Parallel to `transp_step_preserves` (T3).
|
||
|
||
The `HasType.comp` constructor requires a compatibility side-condition
|
||
on the system body (`u[i:=0] = t₀` wherever `φ ∩ (i=0)` is inhabited).
|
||
Callers that cannot produce this side-condition should fall through
|
||
to a per-callsite argument rather than using this theorem. -/
|
||
theorem comp_step_preserves {ℓ : ULevel}
|
||
(Γ : Ctx) (L : DimLine ℓ) (φ : FaceFormula)
|
||
(u t₀ : CTerm)
|
||
(ht : HasType Γ t₀ L.at0)
|
||
(hu : HasType Γ u L.at1)
|
||
(hc : ∀ env : DimVar → Bool,
|
||
φ.eval env = true → env L.binder = false →
|
||
CTerm.substDimBool L.binder false u = t₀) :
|
||
HasType Γ (CTerm.step (.comp L.binder L.body φ u t₀)) L.at1 :=
|
||
CTerm.step_preserves_type Γ _ _ (HasType.comp L ht hu hc)
|
||
|
||
-- ── Composition over schema-defined inductive types (REL1) ──────────────────
|
||
-- Composition over `.ind S params` flows through `eval_comp_stuck`
|
||
-- (`.ind ≠ .pi`). Derived theorems below make the case explicit.
|
||
-- REL1.1 / REL2: pointwise distribution through ctor args.
|
||
|
||
/-- Composition over a non-trivial `.ind` line reduces to a stuck
|
||
`ncomp` neutral. Derived from `eval_comp_stuck`. -/
|
||
theorem eval_comp_ind {ℓ : ULevel} (env : CEnv) (i : DimVar)
|
||
(S : CTypeSchema) (params : List (Σ ℓ' : ULevel, CType ℓ'))
|
||
(φ : FaceFormula) (u t : CTerm)
|
||
(hφ₁ : φ ≠ .top) (hφ₂ : φ ≠ .bot)
|
||
(hA : CType.dimAbsent i (CType.ind (ℓ := ℓ) S params) = false) :
|
||
eval env (.comp i (CType.ind (ℓ := ℓ) S params) φ u t) =
|
||
.vneu (.ncomp i (CType.ind (ℓ := ℓ) S params) φ (eval env u) (eval env t)) :=
|
||
eval_comp_stuck env i (CType.ind (ℓ := ℓ) S params) φ u t hφ₁ hφ₂ hA
|
||
(CType.ind_skeleton_ne_pi S params)
|
||
|
||
/-- Composition over a constant `.ind` line reduces to homogeneous
|
||
composition. Derived from `eval_comp_const`. -/
|
||
theorem eval_comp_ind_const {ℓ : ULevel} (env : CEnv) (i : DimVar)
|
||
(S : CTypeSchema) (params : List (Σ ℓ' : ULevel, CType ℓ'))
|
||
(φ : FaceFormula) (u t : CTerm)
|
||
(hφ₁ : φ ≠ .top) (hφ₂ : φ ≠ .bot)
|
||
(hA : CType.dimAbsent i (CType.ind (ℓ := ℓ) S params) = true) :
|
||
eval env (.comp i (CType.ind (ℓ := ℓ) S params) φ u t) =
|
||
vHCompValue (CType.ind (ℓ := ℓ) S params) φ (eval env (.plam i u)) (eval env t) :=
|
||
eval_comp_const env i (CType.ind (ℓ := ℓ) S params) φ u t hφ₁ hφ₂ hA
|
||
|
||
/-- Composition over `.ind` at `φ = .top`: the system covers everything,
|
||
so the result is the tube body at `i := 1`. Direct corollary of C1. -/
|
||
theorem eval_comp_ind_top {ℓ : ULevel} (env : CEnv) (i : DimVar)
|
||
(S : CTypeSchema) (params : List (Σ ℓ' : ULevel, CType ℓ')) (u t : CTerm) :
|
||
eval env (.comp i (CType.ind (ℓ := ℓ) S params) .top u t) =
|
||
eval env (u.substDim i .one) :=
|
||
eval_comp_top env i (CType.ind (ℓ := ℓ) S params) u t
|
||
|
||
/-- Composition over `.ind` at `φ = .bot`: the system contributes nothing,
|
||
so the result is transport of the base. Direct corollary of C2. -/
|
||
theorem eval_comp_ind_bot {ℓ : ULevel} (env : CEnv) (i : DimVar)
|
||
(S : CTypeSchema) (params : List (Σ ℓ' : ULevel, CType ℓ')) (u t : CTerm) :
|
||
eval env (.comp i (CType.ind (ℓ := ℓ) S params) .bot u t) =
|
||
eval env (.transp i (CType.ind (ℓ := ℓ) S params) .bot t) :=
|
||
eval_comp_bot env i (CType.ind (ℓ := ℓ) S params) u t
|