cubical-transport-hott-lean4/CubicalTransport/Value.lean
Maximus Gorog b9ca1d8875
Some checks are pending
Lean Action CI / build (push) Waiting to run
Modal cascade Phase 1: Syntax + Lean engine cascade
Per THEORY.md §3.1: cubical-native modal type formers as the engine
support layer for the cohesive modality triple (ʃ ⊣ ♭ ⊣ ♯).

CType (3 level-preserving formers):
  · CType.flat / .sharp / .shape : {ℓ} → CType ℓ → CType ℓ

CTerm (6 — three intros + three elims, modelled on .glueIn / .unglue):
  · CTerm.flatIntro / .sharpIntro / .shapeIntro  : CTerm → CTerm
  · CTerm.flatElim  / .sharpElim  / .shapeElim   : CTerm → CTerm → CTerm

Cascade: Syntax (constructors + SkeletalCType + skeleton + substDim);
DecEq (beq arms); Subst (substDim / substDimExpr + 6 rfl theorems);
DimLine (cascade through 8 dim-absent / dim-substitution lemma families);
Value (3 vIntro CVal + 3 nElim CNeu); Eval (β-reduction axioms +
stuck-neutral propagation, "marker neutral" idiom from vFst/vSnd
preserved); Readback (3 vIntro + 3 nElim arms with axioms); Typing
(6 HasType cases — bare recursion-principle shape; modal cohesion
dependent-motive form deferred to Phase 3); Reflect (3 reflectCType + 6
reflectCTerm + 3 reifyCType with level-coherence discharge + 6
reifyCTerm); Question (6 modal arms + 6 IsModalLine classifier
predicates with their Decidable instances); FFITest (cval/cterm
summary arms).

No Rust changes (Phase 2).  No Modal.lean module (Phase 3).  No
Crisp / CContext.crispVar / cohesive_triple theorems (Phase 3).

Build: lake build (48 jobs) + lake build CubicalTransport (42 jobs) PASS.
+664 lines across 11 files, 0 removed, 0 new sorries.

Honest deferrals documented:
  · Modal type-formers do not yet reduce under transport/comp; the
    match A blocks have wildcards so transp i (flat A) φ t produces a
    stuck ntransp neutral (correct under current axiom set; cohesion-
    driven reductions land in Phase 3).
  · HasType.flatElim et al carry the bare recursion-principle shape;
    the cohesive-HoTT-correct dependent-motive form requires the modal
    predicate lattice from Phase 3.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 22:22:03 -06:00

171 lines
7.5 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/-
CubicalTransport.Value
======================
Weak-head normal forms for the universe-stratified cubical calculus
(cells-spec §5.4, Layer 0 §0.1 cascade).
Named-variable adaptation: our `CTerm` uses `String` binders rather than
de Bruijn indices, so `Env` is a name-keyed association list instead of
an `Array`. The three inductives (`CEnv`, `CVal`, `CNeu`) are mutually
recursive: `CVal` contains closures (which capture their `CEnv`), `CNeu`
(stuck terms) carries already-evaluated sub-values, and `CEnv` stores
`CVal`s.
## Universe-aware shape
CVal and CNeu constructors that carry a `CType` payload carry it at an
implicit `{ : ULevel}` parameter — mirroring the corresponding CTerm
constructors in `Syntax.lean`. At the value level the level is
existentially packaged (forgotten by the constructor); the kernel-side
level discipline lives on CType, not on CVal.
Where a constructor stores TWO CTypes that must live at related levels
(e.g. domain at and codomain at '), both levels are bound implicitly.
Coverage matches the cells-spec's "λ-calculus fragment" milestone:
· function abstractions and applications (`vlam`/`napp`)
· dimension abstractions and applications (`vplam`/`npapp`)
· transport and composition as *stuck* values (`ntransp`/`ncomp`) —
reduction rules in `Transport.lean`/`Comp.lean`.
-/
import CubicalTransport.Syntax
mutual
/-- Name-keyed environment: a cons-list of `(name, value)` bindings. The
most-recently-extended binding shadows earlier ones of the same name. -/
inductive CEnv : Type where
| nil : CEnv
| cons : String → CVal → CEnv → CEnv
deriving Inhabited
/-- Weak-head normal-form values. -/
inductive CVal : Type where
/-- Function closure `(λ x. body)` with captured environment. -/
| vlam : CEnv → String → CTerm → CVal
/-- Dimension-abstraction closure `(⟨i⟩ body)` with captured environment. -/
| vplam : CEnv → DimVar → CTerm → CVal
/-- Embedded neutral term — a stuck computation. -/
| vneu : CNeu → CVal
/-- A *transported function value*: result of `transp^i (pi domA codA) φ f`.
Domain at level ``, codomain at level `'`; the result type
lives at `ULevel.max '` (CCHM Π rule). Levels are
existentially packaged at the value level. -/
| vTranspFun { ' : ULevel} :
DimVar → CType → CType ' → FaceFormula → CVal → CVal
/-- A *composed function value*: result of `hcomp (pi domA codA) φ tube base`.
Stores only `codA` (homogeneous comp on the domain is trivial
since A is fixed). -/
| vHCompFun { : ULevel} :
CType → FaceFormula → CVal → CVal → CVal
/-- A *point-wise applied tube*: represents `λj. (tube @ j) arg`. -/
| vTubeApp : CVal → CVal → CVal
/-- A *heterogeneous-composition function value*: result of
`comp^i (Π domA codA) φ u u₀` at the value level. -/
| vCompFun { ' : ULevel} :
CEnv → DimVar → CType → CType ' → FaceFormula →
CTerm → CTerm → CVal
/-- A *path-transport value*: result of `transp^i (Path A(i) a(i) b(i)) φ p`. -/
| vPathTransp { : ULevel} :
CEnv → DimVar → CType → CTerm → CTerm → FaceFormula →
CTerm → CVal
/-- A Σ pair value. -/
| vpair : CVal → CVal → CVal
/-- Schema constructor application — fully-evaluated, canonical
constructor of an inductive (or higher-inductive) type (REL1).
`params` is level-heterogeneous: each entry carries its own ULevel. -/
| vctor : CTypeSchema → String →
List (Σ : ULevel, CType ) → List CVal → CVal
/-- Lifted dimension-expression value (REL1). -/
| vdimExpr : DimExpr → CVal
/-- Value form of `CTerm.code A`. Carries the encoded CType. -/
| vcode { : ULevel} : CType → CVal
/-- Value form of `CTerm.flatIntro a`: the η-introduction value
for the flat (♭) modality, carrying the wrapped value. -/
| vFlatIntro : CVal → CVal
/-- Value form of `CTerm.sharpIntro a`. -/
| vSharpIntro : CVal → CVal
/-- Value form of `CTerm.shapeIntro a`. -/
| vShapeIntro : CVal → CVal
/-- Neutral (stuck) terms. -/
inductive CNeu : Type where
/-- A free variable (name not bound in the current environment). -/
| nvar : String → CNeu
/-- Stuck function application. -/
| napp : CNeu → CVal → CNeu
/-- Stuck dimension application. -/
| npapp : CNeu → DimExpr → CNeu
/-- Transport with an already-evaluated argument. CType at any level. -/
| ntransp { : ULevel} :
DimVar → CType → FaceFormula → CVal → CNeu
/-- Heterogeneous composition (varying line) with already-evaluated
system body and base. -/
| ncomp { : ULevel} :
DimVar → CType → FaceFormula → CVal → CVal → CNeu
/-- Homogeneous composition (fixed type) with already-evaluated tube
and base. -/
| nhcomp { : ULevel} :
CType → FaceFormula → CVal → CVal → CNeu
/-- A stuck multi-clause heterogeneous composition. -/
| ncompN { : ULevel} :
CEnv → DimVar → CType
List (FaceFormula × CVal) → CVal → CNeu
/-- A stuck glue introduction. -/
| nglueIn : FaceFormula → CVal → CVal → CNeu
/-- A stuck unglue. -/
| nunglue : FaceFormula → CVal → CVal → CNeu
/-- A stuck first projection. -/
| nfst : CNeu → CNeu
/-- A stuck second projection. -/
| nsnd : CNeu → CNeu
/-- A stuck inductive eliminator (REL1). `params` is level-heterogeneous. -/
| nIndElim : CTypeSchema → List (Σ : ULevel, CType ) → CVal →
List (String × CVal) → CNeu → CNeu
/-- A stuck flat-modality eliminator: `flatElim f m` where the
scrutinee `m` is a stuck CNeu (so β can't fire). Stores the
evaluated eliminator function and the stuck scrutinee. -/
| nflatElim : CVal → CNeu → CNeu
/-- A stuck sharp-modality eliminator. -/
| nsharpElim : CVal → CNeu → CNeu
/-- A stuck shape-modality eliminator. -/
| nshapeElim : CVal → CNeu → CNeu
end
-- Inhabited instances — needed so `partial def` evaluators can be elaborated
-- (Lean's partial-fixpoint compilation requires a default value for divergence).
instance : Inhabited CNeu := ⟨.nvar "⊥"⟩
instance : Inhabited CVal := ⟨.vneu default⟩
namespace CEnv
/-- Look up a variable name; returns `none` if the name is free. -/
def lookup : CEnv → String → Option CVal
| .nil, _ => none
| .cons n v rest, x => if x = n then some v else rest.lookup x
/-- Extend an environment with a new `(name, value)` binding. -/
def extend (env : CEnv) (x : String) (v : CVal) : CEnv :=
.cons x v env
@[simp] theorem lookup_nil (x : String) : CEnv.lookup .nil x = none := rfl
@[simp] theorem lookup_cons_hit (x : String) (v : CVal) (rest : CEnv) :
(CEnv.cons x v rest).lookup x = some v := by
simp [lookup]
theorem lookup_cons_miss (x y : String) (v : CVal) (rest : CEnv) (h : y ≠ x) :
(CEnv.cons x v rest).lookup y = rest.lookup y := by
simp [lookup, if_neg h]
@[simp] theorem extend_lookup_hit (env : CEnv) (x : String) (v : CVal) :
(env.extend x v).lookup x = some v := by
simp [extend]
theorem extend_lookup_miss (env : CEnv) (x y : String) (v : CVal) (h : y ≠ x) :
(env.extend x v).lookup y = env.lookup y := by
simp [extend, lookup, if_neg h]
end CEnv