Plus-Properties
Properties of the disjoint sum _+_ of types.{-# OPTIONS --safe --without-K #-} module MLTT.Plus-Properties where open import MLTT.Plus open import MLTT.Negation open import MLTT.Id open import MLTT.Empty open import MLTT.Unit open import MLTT.Unit-Properties +-commutative : {A : π€ Μ } {B : π₯ Μ } β A + B β B + A +-commutative = cases inr inl +disjoint : {X : π€ Μ } {Y : π₯ Μ } {x : X} {y : Y} β Β¬ (inl x οΌ inr y) +disjoint {π€} {π₯} {X} {Y} p = π-is-not-π q where f : X + Y β π€β Μ f (inl x) = π f (inr y) = π q : π οΌ π q = ap f p +disjoint' : {X : π€ Μ } {Y : π₯ Μ } {x : X} {y : Y} β Β¬ (inr y οΌ inl x) +disjoint' p = +disjoint (p β»ΒΉ) lni : {X : π€ Μ } {Y : π₯ Μ } β X β X + Y β X lni xβ (inl x) = x lni xβ (inr y) = xβ inl-lc : {X : π€ Μ } {Y : π₯ Μ } {x x' : X} β inl {π€} {π₯} {X} {Y} x οΌ inl x' β x οΌ x' inl-lc {π€} {π₯} {X} {Y} {x} = ap (lni x) rni : {X : π€ Μ } {Y : π₯ Μ } β Y β X + Y β Y rni yβ (inl x) = yβ rni yβ (inr y) = y inr-lc : {X : π€ Μ } {Y : π₯ Μ } {y y' : Y} β inr {π€} {π₯} {X} {Y} y οΌ inr y' β y οΌ y' inr-lc {π€} {π₯} {X} {Y} {y} = ap (rni y) equality-cases : {X : π€ Μ } {Y : π₯ Μ } {A : π¦ Μ } (z : X + Y) β ((x : X) β z οΌ inl x β A) β ((y : Y) β z οΌ inr y β A) β A equality-cases (inl x) f g = f x refl equality-cases (inr y) f g = g y refl Cases-equality-l : {X : π€ Μ } {Y : π₯ Μ } {A : π¦ Μ } (f : X β A) (g : Y β A) β (z : X + Y) (x : X) β z οΌ inl x β Cases z f g οΌ f x Cases-equality-l f g z x refl = refl Cases-equality-r : {X : π€ Μ } {Y : π₯ Μ } {A : π¦ Μ } (f : X β A) (g : Y β A) β (z : X + Y) (y : Y) β z οΌ inr y β Cases z f g οΌ g y Cases-equality-r f g z y refl = refl Left-fails-gives-right-holds : {P : π€ Μ } {Q : π₯ Μ } β P + Q β Β¬ P β Q Left-fails-gives-right-holds (inl p) u = π-elim (u p) Left-fails-gives-right-holds (inr q) u = q Right-fails-gives-left-holds : {P : π€ Μ } {Q : π₯ Μ } β P + Q β Β¬ Q β P Right-fails-gives-left-holds (inl p) u = p Right-fails-gives-left-holds (inr q) u = π-elim (u q) open import MLTT.Sigma open import Notation.General inl-preservation : {X : π€ Μ } {Y : π₯ Μ } (f : X + π {π¦} β Y + π {π£}) β f (inr β) οΌ inr β β left-cancellable f β (x : X) β Ξ£ y κ Y , f (inl x) οΌ inl y inl-preservation {π€} {π₯} {π¦} {π£} {X} {Y} f p l x = Ξ³ x (f (inl x)) refl where Ξ³ : (x : X) (z : Y + π) β f (inl x) οΌ z β Ξ£ y κ Y , z οΌ inl y Ξ³ x (inl y) q = y , refl Ξ³ x (inr β) q = π-elim (+disjoint (l r)) where r : f (inl x) οΌ f (inr β) r = q β p β»ΒΉ +functor : {X : π€ Μ } {Y : π₯ Μ } {A : π¦ Μ } {B : π£ Μ } β (X β A) β (Y β B) β X + Y β A + B +functor f g (inl x) = inl (f x) +functor f g (inr y) = inr (g y) +functorβ : {X : π€ Μ } {Y : π₯ Μ } {Z : π¦ Μ } {X' : π€' Μ } {Y' : π₯' Μ } {Z' : π¦' Μ } β (X β X') β (Y β Y') β (Z β Z') β X + Y + Z β X' + Y' + Z' +functorβ f g h = +functor f (+functor g h)Added 29 Sep 2026 by Tom de Jong. Previously, inl-lc-is-section and inr-lc-is-section were in UF.Sets and relied on injectivity of inl (resp. inr) which Agda silently uses when we pattern match on a term of type inl x οΌ inl x'.module encode-decode-inl {X : π€ Μ } {Y : π₯ Μ } {xβ : X} where private C : X + Y β π€ Μ C (inl x) = xβ οΌ x C (inr x) = π encode : (z : X + Y) β (inl xβ οΌ z) β C z encode (inl _) = inl-lc encode (inr _) = Ξ» p β π-elim (+disjoint p) decode : (z : X + Y) β C z β (inl xβ οΌ z) decode (inl _) c = ap inl c decode (inr _) c = π-elim c encode-decode : (z : X + Y) (p : inl xβ οΌ z) β decode z (encode z p) οΌ p encode-decode z refl = refl decode-encode : (z : X + Y) (c : C z) β encode z (decode z c) οΌ c decode-encode (inl _) refl = refl decode-encode (inr _) c = π-elim c inl-lc-is-section : {X : π€ Μ } {Y : π₯ Μ } {x x' : X} (p : inl {π€} {π₯} {X} {Y} x οΌ inl x') β ap inl (inl-lc p) οΌ p inl-lc-is-section = encode-decode-inl.encode-decode (inl _) inl-lc-is-retraction : {X : π€ Μ } {Y : π₯ Μ } {x x' : X} (p : x οΌ x') β inl-lc {π€ } {π₯} {X} {Y} (ap inl p) οΌ p inl-lc-is-retraction = encode-decode-inl.decode-encode (inl _) module encode-decode-inr {X : π€ Μ } {Y : π₯ Μ } {yβ : Y} where private C : X + Y β π₯ Μ C (inl _) = π C (inr y) = yβ οΌ y encode : (z : X + Y) β (inr yβ οΌ z) β C z encode (inl _) = Ξ» p β π-elim (+disjoint (p β»ΒΉ)) encode (inr _) = inr-lc decode : (z : X + Y) β C z β (inr yβ οΌ z) decode (inl _) c = π-elim c decode (inr _) c = ap inr c encode-decode : (z : X + Y) (p : inr yβ οΌ z) β decode z (encode z p) οΌ p encode-decode z refl = refl decode-encode : (z : X + Y) (c : C z) β encode z (decode z c) οΌ c decode-encode (inl _) c = π-elim c decode-encode (inr _) refl = refl inr-lc-is-section : {X : π€ Μ } {Y : π₯ Μ } {y y' : Y} (p : inr {π€} {π₯} {X} {Y} y οΌ inr y') β ap inr (inr-lc p) οΌ p inr-lc-is-section = encode-decode-inr.encode-decode (inr _) inr-lc-is-retraction : {X : π€ Μ } {Y : π₯ Μ } {y y' : Y} (p : y οΌ y') β inr-lc {π€} {π₯} {X} {Y} (ap inr p) οΌ p inr-lc-is-retraction = encode-decode-inr.decode-encode (inr _)