Documentation

Realizability.RealizabilityCoproduct

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 #

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
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 #

      Coproduct assembly A ⊕ B: a code realizes inl a iff its first Nat.pair component is the tag 0 and its second realizes a; symmetrically inr b with tag 1.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For

        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).

        Equations
        Instances For

          The realizer of the right injection: it tags its input with 1 (ap_inrCode).

          Equations
          Instances For
            noncomputable def RealizabilityCoproduct.copairCode (rf rg : ℕ) :

            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
            Instances For

              Injections and copairing are tracked #

              theorem RealizabilityCoproduct.tracks_copair {A B C : RealizabilityCCC.Asm} {rf rg : ℕ} {f : A.carrier → C.carrier} {g : B.carrier → C.carrier} (hrf : RealizabilityCCC.Tracks A C rf f) (hrg : RealizabilityCCC.Tracks B C rg g) :

              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
              Instances For

                The right injection as a morphism B ⟶ A ⊕ B.

                Equations
                Instances For
                  noncomputable def RealizabilityCoproduct.copair {A B C : RealizabilityCCC.Asm} (f : A ⟶ C) (g : B ⟶ C) :

                  The copairing (mediating) morphism [f, g] : A ⊕ B ⟶ C.

                  Equations
                  Instances For
                    theorem RealizabilityCoproduct.coprod_universal {A B C : RealizabilityCCC.Asm} (f : A ⟶ C) (g : B ⟶ C) :
                    ∃! u : coprodAsm A B ⟶ C, (∀ (a : A.carrier), ↑u (Sum.inl a) = ↑f a) ∧ ∀ (b : B.carrier), ↑u (Sum.inr b) = ↑g b

                    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
                      @[simp]
                      theorem RealizabilityCoproduct.finAsm_realizes (M n : ℕ) (k : Fin (M + 1)) :
                      (finAsm M).realizes n k ↔ n = ↑k

                      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.