{"title": "Subtyping Algebra",
 "producer":
 ["GENERATED by tools/Drivers/Semantics.lean (make gen-semantics); do not edit",
  "format: effect4-semantics-report v8",
  "command: make gen-semantics",
  "inputs: tools/ProofGraph/Registry.lean, tools/Tools/Semantics.lean, tools/Drivers/Semantics.lean, tools/Tools/SemanticsDisplay.lean, tools/Tools/SemanticsDocument.lean, tools/Tools/Document.lean, tools/Tools/Document/Json.lean, src/Effect4/Laws/Auto/Semantics.lean, Test/Counterexamples/REGISTER.md, docs/core/decisions.md, lean-toolchain"],
 "format": "effect4-document/1",
 "body":
 [{"line":
   [{"text": "Preorder laws, normalization, and join-semilattice on CTy. "},
    {"text": "13 claims: "},
    {"text": "13 "},
    {"status": "proved"},
    {"text": "."}],
   "kind": "para"},
  {"title": "Subtyping algebra and normalization",
   "kind": "part",
   "key": "about:concept:subtyping-algebra",
   "body":
   [{"line":
     [{"text":
       "This page explains subtyping algebra and normalization in Effect4. It covers how types normalize into canonical forms, how subtyping evaluates over joins, and why raw subtyping is replaced by normalized subtyping."}],
     "kind": "para"},
    {"title": "The runtime concept",
     "kind": "part",
     "key": "about:concept:subtyping-algebra:runtime-concept",
     "body":
     [{"line":
       [{"text":
         "Effect programs classify data and errors using unions, records, tuples, maps, and primitive types. Subtyping determines whether a produced value or error satisfies an expected type signature."}],
       "kind": "para"},
      {"line":
       [{"text": "Effect4 defines the static type language in "},
        {"code": "Ty"},
        {"text": " ("},
        {"code": "src/Effect4/Program/TyCore.lean"},
        {"text":
         "). Normalization transforms types into canonical normal forms "},
        {"code": "CTy"},
        {"text": "."}],
       "kind": "para"},
      {"line":
       [{"text":
         "Canonical types form a bounded join-semilattice where the least upper bound is computed by "},
        {"code": "Ty.join"},
        {"text": "."}],
       "kind": "para"}]},
    {"title": "Literature foundations",
     "kind": "part",
     "key": "about:concept:subtyping-algebra:literature",
     "body":
     [{"line":
       [{"text":
         "The metatheory adapts subtyping and subsumption from Pierce (TAPL ch. 15–16). In that setting, subtyping forms a preorder equipped with join operations."}],
       "kind": "para"},
      {"line":
       [{"text":
         "Algorithmic subtyping over union and bottom types connects to Castagna (2024). Types order algebraically through set-theoretic unions and canonical representatives."}],
       "kind": "para"}]},
    {"title": "What Effect4 keeps and what it cuts",
     "kind": "part",
     "key": "about:concept:subtyping-algebra:adaptations-and-cuts",
     "body":
     [{"line":
       [{"text":
         "Effect4 keeps algebraic subtyping evaluated on normalized canonical forms through "},
        {"code": "Ty.subN"},
        {"text": " ("},
        {"code": "src/Effect4/Laws/Program/TypeAlgebra.lean"},
        {"text": "):"}],
       "kind": "para"},
      {"lines":
       [[{"text": "Subtyping compares normal forms: "},
         {"code": "subN a b := sub a.normalize b.normalize"},
         {"text": "."}],
        [{"text": "Normalized subtyping is reflexive and transitive."}],
        [{"text":
          "Two types are mutually subtyped exactly when their normal forms are equal ("},
         {"code": "subN_equiv_iff"},
         {"text": ")."}]],
       "kind": "items"},
      {"line":
       [{"text":
         "Effect4 cuts raw subtyping from the checker (decisions row 137, "},
        {"code": "E4-TYPED-CE-009"},
        {"text":
         "). Raw subtyping fails to distribute products over unions, so "},
        {"code": "subN"},
        {"text": " replaces raw "},
        {"code": "sub"},
        {"text": "."}],
       "kind": "para"},
      {"line":
       [{"text": "Effect4 cuts function arrow types from "},
        {"code": "Ty"},
        {"text":
         " (decisions row 163). Types model stored data without arrow subtyping."}],
       "kind": "para"},
      {"line":
       [{"text":
         "Record subtyping has no width rule (decisions row 178). Records with identical canonical names compare field by field covariantly."}],
       "kind": "para"},
      {"line":
       [{"text":
         "Template instantiation replaces match by first occurrence with match by bounds ("},
        {"code": "Bounds.matchB"},
        {"text":
         ", decisions row 303), binding parameters to joins of lower bounds."}],
       "kind": "para"}]},
    {"title": "How to read the claims",
     "kind": "part",
     "key": "about:concept:subtyping-algebra:reading-claims",
     "body":
     [{"line":
       [{"text":
         "The claims under this concept state the algebraic order laws governing type normalization and subtyping checks."}],
       "kind": "para"},
      {"line": [{"text": "Key properties to inspect:"}], "kind": "para"},
      {"lines":
       [[{"ref": "claim:subn-refl", "label": "`subn-refl`"},
         {"text": ": Normalized subtyping is reflexive."}],
        [{"ref": "claim:subn-trans", "label": "`subn-trans`"},
         {"text": ": Normalized subtyping is transitive."}],
        [{"ref": "claim:subn-equiv-iff", "label": "`subn-equiv-iff`"},
         {"text": ": Two-way subtyping coincides with normal-form equality."}]],
       "kind": "items"},
      {"line":
       [{"text":
         "The table of claims on this page gives each claim's status and its statement."}],
       "kind": "para"}]}]},
  {"rows":
   [[[{"ref": "claim:raw-formation", "label": "raw-formation"}],
     [{"text": "decidability"}],
     [{"status": "proved"}],
     [{"code": "Effect4.Program.Formation.checkInput_eq_none_iff"}]],
    [[{"ref": "claim:subn-refl", "label": "subn-refl"}],
     [{"text": "compatibility"}],
     [{"status": "proved"}],
     [{"code": "Effect4.Program.Ty.subN_refl"}]],
    [[{"ref": "claim:subn-trans", "label": "subn-trans"}],
     [{"text": "transitivity"}],
     [{"status": "proved"}],
     [{"code": "Effect4.Program.Ty.subN_trans"}]],
    [[{"ref": "claim:subn-equiv-iff", "label": "subn-equiv-iff"}],
     [{"text": "decidability"}],
     [{"status": "proved"}],
     [{"code": "Effect4.Program.Ty.subN_equiv_iff"}]],
    [[{"ref": "claim:normalize-idem", "label": "normalize-idem"}],
     [{"text": "compatibility"}],
     [{"status": "proved"}],
     [{"code": "Effect4.Program.Ty.normalize_idem"}]],
    [[{"ref": "claim:sub-antisymm-canonical",
       "label": "sub-antisymm-canonical"}],
     [{"text": "antisymmetry"}],
     [{"status": "proved"}],
     [{"code": "Effect4.Program.Ty.sub_antisymm_canonical"}]],
    [[{"ref": "claim:template-match-complete",
       "label": "template-match-complete"}],
     [{"text": "decidability"}],
     [{"status": "proved"}],
     [{"code": "Effect4.Program.Bounds.matchB_complete"}]],
    [[{"ref": "claim:slice-lattice-minimal", "label": "slice-lattice-minimal"}],
     [{"text": "monotonicity"}],
     [{"status": "proved"}],
     [{"code": "Effect4.SliceView.lattice_minimal"}]],
    [[{"ref": "claim:union-rule-lift", "label": "union-rule-lift"}],
     [{"text": "compatibility"}],
     [{"status": "proved"}],
     [{"code": "Effect4.Program.UnionRule.lift_laws"}]],
    [[{"ref": "claim:union-rule-extend", "label": "union-rule-extend"}],
     [{"text": "compatibility"}],
     [{"status": "proved"}],
     [{"code": "Effect4.Program.UnionRule.Eliminator.extendAll_laws"}]],
    [[{"ref": "claim:variance-semiring", "label": "variance-semiring"}],
     [{"text": "compatibility"}],
     [{"status": "proved"}],
     [{"code": "Effect4.Program.Var4.semiring_laws"}]],
    [[{"ref": "claim:instantiate-respects-polarity",
       "label": "instantiate-respects-polarity"}],
     [{"text": "monotonicity"}],
     [{"status": "proved"}],
     [{"code": "Effect4.Program.Ty.sub_instantiate_polarity"}]],
    [[{"ref": "claim:checked-types-closed", "label": "checked-types-closed"}],
     [{"text": "inversion"}],
     [{"status": "proved"}],
     [{"code": "Effect4.Program.check_closed"}]]],
   "kind": "table",
   "headers": ["Claim", "Role", "Status", "Evidence"]},
  {"title": "raw-formation",
   "kind": "part",
   "key": "claim:raw-formation",
   "body":
   [{"line":
     [{"text":
       "Raw formation checking agrees with distinct record names, admitted map keys, a deferred's admitted error column, and no type variable outside a template; a declared service carrier is a strict formation site (decisions rows 288, 297)"}],
     "kind": "para"},
    {"line":
     [{"text": "The "},
      {"code": "raw-formation"},
      {"text": " claim, used by every checked boundary's certificate."}],
     "kind": "para"},
    {"rows":
     [{"line": [{"code": "Effect4.Program.Formation"}], "label": "Module"}],
     "kind": "fields"},
    {"language": "lean",
     "kind": "code",
     "body":
     "∀ {Op : Type} [inst : Effect4.Program.ScopedOp Op] (program : Effect4.Program.Eff Op)\n  (table : List Effect4.Program.Row)\n  (services : optParam (List (Prod Effect4.ServiceKey Effect4.Program.Ty)) List.nil),\n  Iff (Eq (Effect4.Program.Formation.checkInput program table services) Option.none)\n    (Effect4.Program.Formation.InputFormed program table services)"}]},
  {"title": "subn-refl",
   "kind": "part",
   "key": "claim:subn-refl",
   "body":
   [{"line": [{"text": "Reflexivity of normalized subtyping"}], "kind": "para"},
    {"rows":
     [{"line": [{"code": "Effect4.Laws.Program.TypeAlgebra"}],
       "label": "Module"},
      {"line":
       [{"text": "TAPL"},
        {"text": ", "},
        {"text": "§15.2, p. 182"},
        {"text": " (definitionUsed)"}],
       "label": "Literature"}],
     "kind": "fields"},
    {"language": "lean",
     "kind": "code",
     "body": "∀ (a : Effect4.Program.Ty), Eq (a.subN a) Bool.true"}]},
  {"title": "subn-trans",
   "kind": "part",
   "key": "claim:subn-trans",
   "body":
   [{"line": [{"text": "Transitivity of normalized subtyping"}],
     "kind": "para"},
    {"rows":
     [{"line": [{"code": "Effect4.Laws.Program.TypeAlgebra"}],
       "label": "Module"},
      {"line":
       [{"text": "TAPL"},
        {"text": ", "},
        {"text": "§15.2, p. 182"},
        {"text": " (proofTechnique)"}],
       "label": "Literature"}],
     "kind": "fields"},
    {"language": "lean",
     "kind": "code",
     "body":
     "∀ {a b c : Effect4.Program.Ty},\n  Eq (a.subN b) Bool.true → Eq (b.subN c) Bool.true → Eq (a.subN c) Bool.true"}]},
  {"title": "subn-equiv-iff",
   "kind": "part",
   "key": "claim:subn-equiv-iff",
   "body":
   [{"line": [{"text": "Kernel of subN is syntactic normal form equality"}],
     "kind": "para"},
    {"line":
     [{"text":
       "The kernel of the checker's order is equality of normal forms."}],
     "kind": "para"},
    {"rows":
     [{"line": [{"code": "Effect4.Laws.Program.TypeAlgebra"}],
       "label": "Module"},
      {"line":
       [{"text": "TAPL"},
        {"text": ", "},
        {"text": "§16.3, p. 218"},
        {"text": " (adaptedResult)"}],
       "label": "Literature"}],
     "kind": "fields"},
    {"language": "lean",
     "kind": "code",
     "body":
     "∀ (a b : Effect4.Program.Ty),\n  Iff (And (Eq (a.subN b) Bool.true) (Eq (b.subN a) Bool.true)) (Eq a.normalize b.normalize)"}]},
  {"title": "normalize-idem",
   "kind": "part",
   "key": "claim:normalize-idem",
   "body":
   [{"line": [{"text": "Normalization idempotence"}], "kind": "para"},
    {"line":
     [{"text":
       "Construction is total; no checked partial constructor is needed."}],
     "kind": "para"},
    {"rows": [{"line": [{"code": "Effect4.Program.Ty"}], "label": "Module"}],
     "kind": "fields"},
    {"language": "lean",
     "kind": "code",
     "body":
     "∀ (t : Effect4.Program.Ty), Eq t.normalize.normalize t.normalize"}]},
  {"title": "sub-antisymm-canonical",
   "kind": "part",
   "key": "claim:sub-antisymm-canonical",
   "body":
   [{"line":
     [{"text": "Antisymmetry of subtyping on canonical representatives CTy"}],
     "kind": "para"},
    {"rows":
     [{"line": [{"code": "Effect4.Laws.Program.TypeAlgebra"}],
       "label": "Module"},
      {"line":
       [{"text": "Castagna2024"},
        {"text": ", "},
        {"text": "audit P6"},
        {"text": " (adaptedResult)"}],
       "label": "Literature"}],
     "kind": "fields"},
    {"language": "lean",
     "kind": "code",
     "body":
     "∀ (a b : Effect4.Program.CTy),\n  Eq (a.toRaw.sub b.toRaw) Bool.true → Eq (b.toRaw.sub a.toRaw) Bool.true → Eq a b"}]},
  {"title": "template-match-complete",
   "kind": "part",
   "key": "claim:template-match-complete",
   "body":
   [{"line":
     [{"text":
       "The match of a template by bounds is complete: on a template that is its own normal form, is admissible and holds no nominal reference, a normal request below some instance has a match, from any seed that the instance agrees with; no premise asks where a parameter first occurs or where never stands; the match is sound by its guard (matchB_sound), its bindings are the least (matchB_least), an argument list is checked at one final list of bindings (matchArgsB_sound), and smaller arguments have a match with smaller bindings (matchArgsB_monotone); every template of the tree is in reach, as a finite check; the row check and a binder term read the match by bounds with no guard (slice UNGUARD); it does not match under a union head or a nominal reference, and it establishes nothing of tsgo's inference (decisions rows 299, 303)"}],
     "kind": "para"},
    {"line":
     [{"text":
       "The match by bounds is complete: a normal request below some instance of the template has a match. The template is normal, admissible and holds no nominal reference. No premise asks where a parameter first occurs, and none asks where "},
      {"code": "never"},
      {"text": " stands: "},
      {"code": "Ty.anchored"},
      {"text": " and "},
      {"code": "Ty.bottomFree"},
      {"text": " ("},
      {"code": "src/Effect4/Laws/Program/Template.lean"},
      {"text": ") are not premises."}],
     "kind": "para"},
    {"rows":
     [{"line": [{"code": "Effect4.Laws.Program.Bounds"}], "label": "Module"}],
     "kind": "fields"},
    {"language": "lean",
     "kind": "code",
     "body":
     "∀ (seed : Effect4.Program.Bounds.Subst) {t r : Effect4.Program.Ty},\n  Effect4.Program.Bounds.TemplateOK t →\n    r.Normal →\n      ∀ {τ : Effect4.Program.Bounds.Subst},\n        (∀ (j : Nat) (u : Effect4.Program.Ty),\n            Eq (List.lookup j seed) (Option.some u) →\n              Eq (Effect4.Program.Ty.instantiate τ (Effect4.Program.Ty.var j)).normalize\n                u.normalize) →\n          Eq (r.sub (Effect4.Program.Ty.instantiate τ t).normalize) Bool.true →\n            Exists fun σ => Eq (Effect4.Program.Bounds.matchB seed t r) (Option.some σ)"}]},
  {"title": "slice-lattice-minimal",
   "kind": "part",
   "key": "claim:slice-lattice-minimal",
   "body":
   [{"line":
     [{"text":
       "For a monotone map from the type slices of one program to a preorder of types: a minimal valid slice exists below each valid slice, the one-pass descent ends at one below its start, a refined query has a minimal slice below a minimal slice of the wider query, and the join of two valid slices is valid for the join of their queries; no statement names Eff, Ty or the checker (decisions rows 282, 286)"}],
     "kind": "para"},
    {"line":
     [{"text": "The claim "},
      {"code": "slice-lattice-minimal"},
      {"text":
       ", as one statement: its four parts, for one monotone view. A minimal valid type slice exists below each valid slice (Theorem 4.5). The descent ends at one, below its start. A refined query has a minimal slice below a minimal slice of the wider query (Theorem 4.6). The join of two valid slices is valid for the join of their queries (Theorem 4.7). It is the pointer that the claim's row needs, and it adds nothing to its four parts."}],
     "kind": "para"},
    {"rows":
     [{"line": [{"code": "Effect4.Laws.Slice.Lattice"}], "label": "Module"}],
     "kind": "fields"},
    {"language": "lean",
     "kind": "code",
     "body":
     "∀ {α : Type u} {T : Type v} [inst : LE T] [DecidableEq α] [Std.IsPreorder T]\n  [inst_3 : DecidableLE T] [inst_4 : Max T] [Std.LawfulOrderSup T] (v : Effect4.SliceView α T),\n  And\n    (∀ {q : T} {s : Effect4.Slice α},\n      v.Valid q s → Exists fun m => And (Effect4.Slice.instLE.le m s) (v.Minimal q m))\n    (And\n      (∀ {q : T} {s : Effect4.Slice α},\n        v.Valid q s → And (Effect4.Slice.instLE.le (v.descend q s) s) (v.Minimal q (v.descend q s)))\n      (And\n        (∀ {q₁ q₂ : T} {m₂ : Effect4.Slice α},\n          inst.le q₁ q₂ →\n            v.Minimal q₂ m₂ →\n              Exists fun m₁ => And (Effect4.Slice.instLE.le m₁ m₂) (v.Minimal q₁ m₁))\n        (∀ {q₁ q₂ : T} {a b : Effect4.Slice α},\n          v.Valid q₁ a →\n            v.Valid q₂ b → v.Valid (inst_4.max q₁ q₂) (Effect4.Slice.instMax.max a b))))"}]},
  {"title": "union-rule-lift",
   "kind": "part",
   "key": "claim:union-rule-lift",
   "body":
   [{"line":
     [{"text":
       "A member rule lifted to every type by reading the union members of the normal form and joining the answers: it answers the least answer at never; at one normal union member it is the member rule, up to the join with the least answer; two types with one normal form have one answer; a member rule that is monotone in the order lifts to a monotone rule; a property of a value and an answer that the join keeps on each side passes from the union members to the lifted rule; the join law is an equation at a type, at a pair of types and at a carrier whose order is antisymmetric (lift_union_eq, lift_union_eq_pair, lift_union_eq_of_antisymm), and a map with the four properties of the lifted rule is the lifted rule, at a type and at a pair of types (lift_unique, lift_unique_pair); its order is read in Lean core's classes: a carrier with those classes is a carrier of answers (AnswerOrder.ofCore), and the checker's order on raw types is the order of canonical types by definition (subN_iff_le); the two record rules are its instances, and the fiber rule is the first converted rule (union-rule-extend) (decisions rows 282, 285, 293, 298, 300)"}],
     "kind": "para"},
    {"line":
     [{"text": "The claim "},
      {"code": "union-rule-lift"},
      {"text":
       ", as one statement: its five parts of the brief, for one member rule. The lifted rule answers the least answer at "},
      {"code": "never"},
      {"text":
       ". At a normal type that is one union member it is the member rule, up to the join with the least answer. Two types with one normal form have one answer. A member rule that is monotone in the order lifts to a monotone rule. A property of a value and an answer that the join keeps on each side passes from the union members to the lifted rule. It is the pointer that the claim's row needs, and it adds nothing to its parts. "},
      {"code": "lift_all"},
      {"text": ", "},
      {"code": "lift_upper"},
      {"text": " and "},
      {"code": "lift_least"},
      {"text": " stand beside it."}],
     "kind": "para"},
    {"rows":
     [{"line": [{"code": "Effect4.Laws.Program.UnionRule"}],
       "label": "Module"}],
     "kind": "fields"},
    {"language": "lean",
     "kind": "code",
     "body":
     "∀ {α : Type} [inst : Effect4.Program.UnionRule.Answer α]\n  [inst_1 : Effect4.Program.UnionRule.AnswerOrder α] (rule : Effect4.Program.Ty → Option α),\n  And (Eq (Effect4.Program.UnionRule.lift rule Effect4.Program.Ty.never) (Option.some inst.bot))\n    (And\n      (∀ {t : Effect4.Program.Ty},\n        t.Normal →\n          Eq t.isMember Bool.true →\n            Eq (Effect4.Program.UnionRule.lift rule t) (Option.map (inst.join inst.bot) (rule t)))\n      (And\n        (∀ {s t : Effect4.Program.Ty},\n          Eq s.normalize t.normalize →\n            Eq (Effect4.Program.UnionRule.lift rule s) (Effect4.Program.UnionRule.lift rule t))\n        (And\n          (Effect4.Program.UnionRule.Below rule rule →\n            ∀ {s t : Effect4.Program.Ty} {b : α},\n              Eq (s.subN t) Bool.true →\n                Eq (Effect4.Program.UnionRule.lift rule t) (Option.some b) →\n                  Exists fun a =>\n                    And (Eq (Effect4.Program.UnionRule.lift rule s) (Option.some a))\n                      (inst_1.le a b))\n          (∀ {V : Type} {In : V → Effect4.Program.Ty → Prop} {P : V → α → Prop},\n            (∀ {v : V} {t : Effect4.Program.Ty}, In v t → In v t.normalize) →\n              (∀ {v : V} {t : Effect4.Program.Ty},\n                  In v t → Exists fun m => And (List.instMembership.mem t.members m) (In v m)) →\n                (∀ {v : V} (a b : α), P v a → P v (inst.join a b)) →\n                  (∀ {v : V} (a b : α), P v b → P v (inst.join a b)) →\n                    (∀ {m : Effect4.Program.Ty} {a : α} {v : V},\n                        m.Normal →\n                          Eq m.isMember Bool.true → Eq (rule m) (Option.some a) → In v m → P v a) →\n                      ∀ {t : Effect4.Program.Ty} {a : α} {v : V},\n                        Eq (Effect4.Program.UnionRule.lift rule t) (Option.some a) →\n                          In v t → P v a))))"}]},
  {"title": "union-rule-extend",
   "kind": "part",
   "key": "claim:union-rule-extend",
   "body":
   [{"line":
     [{"text":
       "A converted eliminator of the checker is the full fallback of its member rule: the member rule's own answer where the member rule answers at the raw target, and the lifted rule over every normalized union member elsewhere; for every UnionRule.Eliminator it agrees with the member rule, it is the lifted rule where the member rule refuses, and it keeps every answer of the earlier guarded rule (Eliminator.extendAll_laws); it answers a least answer at never; its answer a puts the target below C a in Ty.subN, and an answer b is above a exactly when the target is below C b; a retained member that the member rule refuses refuses the whole target; it is monotone at every smaller type (Eliminator.extendAll_mono), and its answer equals the lifted rule's up to the order (Eliminator.extendAll_lift); the fiber, list and exit rules are instances (fiberTy, Checker.listOf?, Checker.exitOf?); the cause rule reads two heads, so it is the full fallback of Member.cause with four member facts of an upper type (causeInputError_upper); the option rule reads the normal form alone, so it is the lifted rule of Member.option, and it is the earlier normalized-head rule where the normal form has at most one member and is not never (optionTy_eq_normal; decisions row 304); the guarded rule's laws stay for their earlier consumers (Eliminator.extend_laws); it does not establish checker-monotone or anything that tsgo accepts (decisions rows 292 to 294, 296, 298 and 304; slice P2b)"}],
     "kind": "para"},
    {"line":
     [{"text":
       "The full-fallback contract, without a proper-union refusal. Consumer: the fiber classifier reader."}],
     "kind": "para"},
    {"rows":
     [{"line": [{"code": "Effect4.Laws.Program.UnionRule"}],
       "label": "Module"}],
     "kind": "fields"},
    {"language": "lean",
     "kind": "code",
     "body":
     "∀ {α : Type} [inst : Effect4.Program.UnionRule.Answer α]\n  [inst_1 : Effect4.Program.UnionRule.AnswerOrder α] {rule : Effect4.Program.Ty → Option α}\n  {C : α → Effect4.Program.Ty},\n  Effect4.Program.UnionRule.Eliminator rule C →\n    And\n      (∀ {t : Effect4.Program.Ty} {a : α},\n        Eq (rule t) (Option.some a) →\n          Eq (Effect4.Program.UnionRule.extendAll rule t) (Option.some a))\n      (And\n        (∀ {t : Effect4.Program.Ty},\n          Eq (rule t) Option.none →\n            Eq (Effect4.Program.UnionRule.extendAll rule t) (Effect4.Program.UnionRule.lift rule t))\n        (And\n          (Exists fun a =>\n            And\n              (Eq (Effect4.Program.UnionRule.extendAll rule Effect4.Program.Ty.never)\n                (Option.some a))\n              (∀ (b : α), inst_1.le a b))\n          (And\n            (∀ {t : Effect4.Program.Ty} {a : α},\n              Eq (Effect4.Program.UnionRule.extendAll rule t) (Option.some a) →\n                And (Eq (t.subN (C a)) Bool.true)\n                  (∀ (b : α), Iff (inst_1.le a b) (Eq (t.subN (C b)) Bool.true)))\n            (∀ {t : Effect4.Program.Ty} {a : α},\n              Eq (Effect4.Program.UnionRule.extend rule t) (Option.some a) →\n                Eq (Effect4.Program.UnionRule.extendAll rule t) (Option.some a)))))"}]},
  {"title": "variance-semiring",
   "kind": "part",
   "key": "claim:variance-semiring",
   "body":
   [{"line":
     [{"text":
       "The variance semiring: Var4, the four parity sets of the signed paths that reach an occurrence (bi, co, contra, inv), with join and composition, is a commutative idempotent semiring with bi as zero and co as one, ordered by inclusion with join as least upper bound; on the declared alphabet's image the walk's composition (Bounds.comp) is its product and the reference's Boolean reading (Ty.Variance.select) is its select (Bounds.comp_toVar4, Ty.Variance.select_toVar4); the polarity of a template's parameter is one fold of the generated TyAlgebra at a reading of the heads (Ty.polarity, HeadReading.sub); it establishes no subtyping fact of Ty (the OpenAI math review, slice VAR-1)"}],
     "kind": "para"},
    {"line":
     [{"text": "The variance semiring (claim "},
      {"code": "variance-semiring"},
      {"text":
       "): join and composition form a commutative idempotent semiring with "},
      {"code": "bi"},
      {"text": " as zero and "},
      {"code": "co"},
      {"text":
       " as one, composition distributes over join, and the order is a preorder whose join is "},
      {"code": "+"},
      {"text": ". A step of "},
      {"code": "instantiate-respects-polarity"},
      {"text": " (slice VAR-2) and of the row census (slice VAR-3)."}],
     "kind": "para"},
    {"rows":
     [{"line": [{"code": "Effect4.Laws.Program.Polarity"}], "label": "Module"}],
     "kind": "fields"},
    {"language": "lean",
     "kind": "code",
     "body":
     "And (∀ (a b : Effect4.Program.Var4), Eq (instHAdd.hAdd a b) (instHAdd.hAdd b a))\n  (And\n    (∀ (a b c : Effect4.Program.Var4),\n      Eq (instHAdd.hAdd (instHAdd.hAdd a b) c) (instHAdd.hAdd a (instHAdd.hAdd b c)))\n    (And (∀ (a : Effect4.Program.Var4), Eq (instHAdd.hAdd a a) a)\n      (And (∀ (a : Effect4.Program.Var4), Eq (instHAdd.hAdd Effect4.Program.Var4.bi a) a)\n        (And (∀ (a b : Effect4.Program.Var4), Eq (instHMul.hMul a b) (instHMul.hMul b a))\n          (And\n            (∀ (a b c : Effect4.Program.Var4),\n              Eq (instHMul.hMul (instHMul.hMul a b) c) (instHMul.hMul a (instHMul.hMul b c)))\n            (And (∀ (a : Effect4.Program.Var4), Eq (instHMul.hMul Effect4.Program.Var4.co a) a)\n              (And\n                (∀ (a : Effect4.Program.Var4),\n                  Eq (instHMul.hMul Effect4.Program.Var4.bi a) Effect4.Program.Var4.bi)\n                (And\n                  (∀ (a b c : Effect4.Program.Var4),\n                    Eq (instHMul.hMul a (instHAdd.hAdd b c))\n                      (instHAdd.hAdd (instHMul.hMul a b) (instHMul.hMul a c)))\n                  (And (∀ (a : Effect4.Program.Var4), Eq (a.le a) Bool.true)\n                    (∀ (a b c : Effect4.Program.Var4),\n                      Eq ((instHAdd.hAdd a b).le c) ((a.le c).and (b.le c))))))))))))"}]},
  {"title": "instantiate-respects-polarity",
   "kind": "part",
   "key": "claim:instantiate-respects-polarity",
   "body":
   [{"line":
     [{"text":
       "Instantiation respects polarity: if every parameter's two bindings are related by raw Ty.sub at the parameter's polarity in a template (a bivariant parameter asks nothing, an invariant one both directions), the two instances are related; with matchArgsB_monotone it gives a smaller answer at a smaller request where the answer reads its parameters at co or bi; no semantic variance, nothing of tsgo's inference (slice VAR-2)"}],
     "kind": "para"},
    {"line":
     [{"text": "Instantiation respects polarity (claim "},
      {"code": "instantiate-respects-polarity"},
      {"text":
       ", slice VAR-2): if every parameter's two bindings are related by "},
      {"code": "Ty.sub"},
      {"text": " at the parameter's polarity in "},
      {"code": "t"},
      {"text":
       " (a bivariant parameter asks nothing, an invariant one both directions), the two instances are related. It is the probe's "},
      {"code": "eval_respects"},
      {"text": " at the model of "},
      {"code": "Ty"},
      {"text": " (raw "},
      {"code": "Ty.sub"},
      {"text": ", each head read at its variance, "},
      {"code": "HeadReading.sub"},
      {"text": "). Its consumers are "},
      {"code": "checker-monotone"},
      {"text": "'s share at a row (with "},
      {"code": "Bounds.matchArgsB_monotone"},
      {"text":
       ", at an answer that reads its parameters at co or bi) and HO-4's instantiated rows. It establishes no semantic variance and nothing of tsgo's inference."}],
     "kind": "para"},
    {"rows":
     [{"line": [{"code": "Effect4.Laws.Program.Polarity"}], "label": "Module"}],
     "kind": "fields"},
    {"language": "lean",
     "kind": "code",
     "body":
     "∀ (t : Effect4.Program.Ty) (σ σ' : Effect4.Program.Ty.Subst),\n  (∀ (i : Nat),\n      Eq\n        ((Effect4.Program.Ty.polarity Effect4.Program.HeadReading.sub i t).select\n          ((σ.at i).sub (σ'.at i)) ((σ'.at i).sub (σ.at i)))\n        Bool.true) →\n    Eq ((Effect4.Program.Ty.instantiate σ t).sub (Effect4.Program.Ty.instantiate σ' t)) Bool.true"}]},
  {"title": "checked-types-closed",
   "kind": "part",
   "key": "claim:checked-types-closed",
   "body":
   [{"line":
     [{"text":
       "A formed program that the checker admits has closed types: at a closed environment, a typing signature with closed atoms and closed service carriers, and annotations formed outside a template; no premise on a row or on a layer reference; the whole-program checker has the same property, and an admitted program has closed types with no premise (typeOfProgram_closed, AdmittedProgram.closed); the checker alone does not have it (decisions rows 288 point 6 a, 297)"}],
     "kind": "para"},
    {"line":
     [{"text":
       "A formed program that the checker admits has closed types, at a closed environment and a signature with closed atoms and closed service carriers (the claim "},
      {"code": "checked-types-closed"},
      {"text":
       "). The annotations are formed outside a template, so each states a closed type ("},
      {"code": "Formation.closed_of_formed"},
      {"text": "), and each rule of the checker keeps closed types closed ("},
      {"code": "hasTy_closed"},
      {"text":
       "). The path is any path: the checker's answer does not depend on it."}],
     "kind": "para"},
    {"rows":
     [{"line": [{"code": "Effect4.Laws.Program.Typing.Closed"}],
       "label": "Module"}],
     "kind": "fields"},
    {"language": "lean",
     "kind": "code",
     "body":
     "∀ {Op : Type} [inst : Effect4.Program.ScopedOp Op] (sig : Effect4.Program.Signature Op),\n  Effect4.Program.ClosedSig sig →\n    ∀ {env : Effect4.Program.TyEnv},\n      (∀ (t : Effect4.Program.Ty), List.instMembership.mem env t → Eq t.closed Bool.true) →\n        ∀ {p : List Nat} {e : Effect4.Program.Eff Op} {t : Effect4.Program.EffTy},\n          Effect4.Program.Formation.Formed (Effect4.Program.Formation.programSites e) →\n            Eq (Effect4.Program.Checker.check sig env p e) (Except.ok t) →\n              And (Eq t.answer.closed Bool.true) (Eq t.error.closed Bool.true)"}]}]}
