Finite coproducts in the realizability category Asm #
Realizability/RealizabilityCCC.lean built the carrier RealizabilityCCC.Asm — assemblies over
Kleene's first PCA (Nat.Partrec.Code) — and proved it Cartesian closed (terminal + products +
exponentials). This file adds the missing finite coproducts (initial object + binary coproduct
with its copairing universal property) on that same carrier, and the finite carrier assembly
finAsm.
Why this is new infrastructure (upstreamable) #
The 2026 realizability sweep found no realizability-coproduct in Lean/Mathlib (nor a
realizability category at all beyond what the Realizability modules build here). Coproducts of
assemblies are the standard "tagged union" construction: a realizer of a left/right injection is a
code carrying a tag (0/1, via Nat.pair) alongside a realizer of the injected element;
copairing runs one of two realizers according to the tag (Partrec.cond). We build that layer
directly on Nat.Partrec.Code, reusing the universal machinery of
Realizability/Realizability.lean (exists_code, Code.eval_part). It is genuinely upstreamable.
What this establishes #
initialAsm— the empty assembly;initialAsm_isInitial: it is an initial object ofAsm(the unique map out isEmpty.elim, trackable vacuously; uniqueness isEmpty → Bsubsingleton).coprodAsm A B— the binary coproduct: carrierA ⊕ B, a code realizesinl aiff it isNat.pair 0 (a-realizer)andinr biffNat.pair 1 (b-realizer).inl/inrare tracked morphisms, andcoprod_universalis the copairing universal property — existence and uniqueness of the mediating realized morphism[f, g] : A ⊕ B ⟶ C.finAsm M,trackable_of_fin_dom: the finite assembly onFin (M+1), each element realized by its own value, and the fact that every function out of it is a morphism ofAsm.
The initial object: the empty assembly #
The initial assembly: the empty carrier. Realizability is vacuous, and the unique map out of
it (Empty.elim) is trackable by any code. This is the standard initial object of a category of
assemblies.
Equations
- RealizabilityCoproduct.initialAsm = { carrier := Empty, realizes := fun (x : ℕ) (x_1 : Empty) => x_1.elim, realized := RealizabilityCoproduct.initialAsm._proof_1 }
Instances For
initialAsm is an initial object of Asm. For every assembly B the unique morphism
initialAsm ⟶ B has underlying map Empty.elim, trackable vacuously (no element of Empty has a
realizer, so every code tracks it — we pick idCode); uniqueness is Empty → B.carrier being a
subsingleton.
Equations
Instances For
Binary coproducts: the tagged-union assembly #
The injection and copairing realizer codes #
A code that tags an argument with 0: r · n = ⟨0, n⟩. Built from Nat.pair 0 · via
exists_code.
A code that tags an argument with 1: r · n = ⟨1, n⟩.
The copairing realizer: a single code that reads the tag n.unpair.1 and runs rf on the
payload if the tag is 0, else rg. Built by arithmetically selecting the realizer code
(Primrec.ite at the ℕ level) and feeding it to the universal evaluator
Realizability.universal_evaluator.
Chosen injection/copairing codes. Each is a realizer picked from the corresponding existence
lemma, so the realizers are genuine values; .choose uses only Classical.choice.
The realizer of the left injection: it tags its input with 0 (ap_inlCode).
Instances For
The realizer of the right injection: it tags its input with 1 (ap_inrCode).
Instances For
The realizer of the copairing of two tracked maps: on a tagged input it dispatches to rf or
rg according to the tag (ap_copairCode).
Equations
- RealizabilityCoproduct.copairCode rf rg = ⋯.choose
Instances For
Injections and copairing are tracked #
Copairing preserves tracking: if rf tracks f : A → C and rg tracks g : B → C, then
copairCode rf rg tracks [f, g] = Sum.elim f g : A ⊕ B → C.
The coproduct as a categorical object of Asm #
The left injection as a morphism A ⟶ A ⊕ B.
Equations
- RealizabilityCoproduct.inl A B = ⟨Sum.inl, ⋯⟩
Instances For
The right injection as a morphism B ⟶ A ⊕ B.
Equations
- RealizabilityCoproduct.inr A B = ⟨Sum.inr, ⋯⟩
Instances For
The copairing (mediating) morphism [f, g] : A ⊕ B ⟶ C.
Equations
- RealizabilityCoproduct.copair f g = ⟨Sum.elim ↑f ↑g, ⋯⟩
Instances For
The copairing universal property (finite coproduct on the genuine carrier). For every pair
f : A ⟶ C, g : B ⟶ C there is a unique realized morphism u : A ⊕ B ⟶ C with
u ∘ inl = f and u ∘ inr = g (stated pointwise). Existence is copair f g; uniqueness is
extensional (morphism equality in Asm is function equality, the realizer existentially
quantified), by cases on Sum.
The finite carrier assembly and finite-domain trackability #
The finite assembly on Fin (M+1), each element realized by (exactly) its own value.
Equations
Instances For
Finite-domain trackability. Every function out of the finite assembly finAsm M is
trackable (a morphism of Asm) — the realizer is a finite table keyed on the input value, extracted
via Realizability.tableFn and Nat.Partrec.Code.exists_code. This is the Asm-level counterpart
of Realizability.realizes_of_finite.