This is the Setoid.Functions.Surjective module of the agda-algebras library.
A surjective function from a setoid π¨ = (A, ββ)
to a setoid π© = (B, ββ)
is a function f : π¨ βΆ π©
such that for all b : B
there exists a : A
such that (f β¨$β© a) ββ b
. In other words, the range and codomain of f
agree.
{-# OPTIONS --without-K --exact-split --safe #-} module Setoid.Functions.Surjective where -- Imports from Agda and the Agda Standard Library -------------------------- open import Agda.Primitive using () renaming ( Set to Type ) open import Data.Product using ( _,_ ; Ξ£-syntax ) open import Function using ( Surjection ; IsSurjection ) renaming ( Func to _βΆ_ ) open import Level using ( _β_ ; Level ) open import Relation.Binary using ( Setoid ) open import Function.Construct.Composition renaming ( isSurjection to isOnto ) using () import Function.Definitions as FD -- Imports from agda-algebras ----------------------------------------------- open import Overture using ( β£_β£ ; β₯_β₯ ; β-syntax ; transport ) open import Setoid.Functions.Basic using ( _β_ ) open import Setoid.Functions.Inverses using ( Img_β_ ; Image_β_ ; Inv ; InvIsInverseΚ³ ) private variable Ξ± Οα΅ Ξ² Οα΅ Ξ³ ΟαΆ : Level open Image_β_ module _ {π¨ : Setoid Ξ± Οα΅}{π© : Setoid Ξ² Οα΅} where open Setoid π¨ renaming (Carrier to A; _β_ to _ββ_; isEquivalence to isEqA ) using () open Setoid π© renaming (Carrier to B; _β_ to _ββ_; isEquivalence to isEqB ) using ( trans ; sym ) open Surjection {a = Ξ±}{Οα΅}{Ξ²}{Οα΅}{From = π¨}{To = π©} renaming (f to _β¨$β©_) open _βΆ_ {a = Ξ±}{Οα΅}{Ξ²}{Οα΅}{From = π¨}{To = π©} renaming (f to _β¨$β©_ ) open FD _ββ_ _ββ_ isSurj : (A β B) β Type (Ξ± β Ξ² β Οα΅) isSurj f = β {y} β Img_β_ {π¨ = π¨}{π© = π©} f y IsSurjective : (π¨ βΆ π©) β Type (Ξ± β Ξ² β Οα΅) IsSurjective F = β {y} β Image F β y isSurjβIsSurjective : (F : π¨ βΆ π©) β isSurj (_β¨$β©_ F) β IsSurjective F isSurjβIsSurjective F isSurjF {y} = hyp isSurjF where hyp : Img (_β¨$β©_ F) β y β Image F β y hyp (Img_β_.eq a x) = eq a x open Image_β_ SurjectionIsSurjective : (Surjection π¨ π©) β Ξ£[ g β (π¨ βΆ π©) ] (IsSurjective g) SurjectionIsSurjective s = g , gE where g : π¨ βΆ π© g = (record { f = _β¨$β©_ s ; cong = cong s }) gE : IsSurjective g gE {y} = eq β£ (surjective s) y β£ (sym β₯ (surjective s) y β₯) SurjectionIsSurjection : (Surjection π¨ π©) β Ξ£[ g β (π¨ βΆ π©) ] (IsSurjection _ββ_ _ββ_ (_β¨$β©_ g)) SurjectionIsSurjection s = g , gE where g : π¨ βΆ π© g = (record { f = _β¨$β©_ s ; cong = cong s }) gE : IsSurjection _ββ_ _ββ_ (_β¨$β©_ g) IsSurjection.isCongruent gE = record { cong = cong g ; isEquivalenceβ = isEqA ; isEquivalenceβ = isEqB } IsSurjection.surjective gE y = β£ (surjective s) y β£ , β₯ (surjective s) y β₯
With the next definition we represent a right-inverse of a surjective setoid function.
SurjInv : (f : π¨ βΆ π©) β IsSurjective f β B β A SurjInv f fE b = Inv f (fE {b})
Thus, a right-inverse of f
is obtained by applying Inv
to f
and a proof of IsSurjective f
. Next we prove that this does indeed give the right-inverse.
SurjInvIsInverseΚ³ : (f : π¨ βΆ π©)(fE : IsSurjective f) β β {b} β (f β¨$β© ((SurjInv f fE) b)) ββ b SurjInvIsInverseΚ³ f fE = InvIsInverseΚ³ fE
Next, we prove composition laws for epics.
module _ {π¨ : Setoid Ξ± Οα΅}{π© : Setoid Ξ² Οα΅}{πͺ : Setoid Ξ³ ΟαΆ} where open Setoid π¨ using () renaming (Carrier to A; _β_ to _ββ_) open Setoid π© using ( trans ; sym ) renaming (Carrier to B; _β_ to _ββ_) open Setoid πͺ using () renaming (Carrier to C; _β_ to _ββ_) open Surjection renaming (f to _β¨$β©_) open _βΆ_ renaming (f to _β¨$β©_ ) open FD _ββ_ _ββ_ β-IsSurjective : {G : π¨ βΆ πͺ}{H : πͺ βΆ π©} β IsSurjective G β IsSurjective H β IsSurjective (H β G) β-IsSurjective {G} {H} gE hE {y} = Goal where mp : Image H β y β Image H β G β y mp (eq c p) = Ξ· gE where Ξ· : Image G β c β Image H β G β y Ξ· (eq a q) = eq a (trans p (cong H q)) Goal : Image H β G β y Goal = mp hE β-epic : Surjection π¨ πͺ β Surjection πͺ π© β Surjection π¨ π© Surjection.f (β-epic g h) x = h β¨$β© (g β¨$β© x) Surjection.cong (β-epic g h) {x} {y} xy = cong h (cong g xy) Surjection.surjective (β-epic g h) = IsSurjection.surjective hgSurj where gSurj : Ξ£[ G β (π¨ βΆ πͺ) ] (IsSurjection _ββ_ _ββ_ (_β¨$β©_ G)) gSurj = SurjectionIsSurjection g hSurj : Ξ£[ H β (πͺ βΆ π©) ] (IsSurjection _ββ_ _ββ_ (_β¨$β©_ H)) hSurj = SurjectionIsSurjection h hgSurj : IsSurjection _ββ_ _ββ_ (Ξ» x β h β¨$β© (g β¨$β© x)) hgSurj = isOnto β₯ gSurj β₯ β₯ hSurj β₯ epic-factor : (f : π¨ βΆ π©)(g : π¨ βΆ πͺ)(h : πͺ βΆ π©) β IsSurjective f β (β i β (f β¨$β© i) ββ ((h β g) β¨$β© i)) β IsSurjective h epic-factor f g h fE compId {y} = Goal where finv : B β A finv = SurjInv f fE ΞΆ : y ββ (f β¨$β© (finv y)) ΞΆ = sym (SurjInvIsInverseΚ³ f fE) Ξ· : y ββ ((h β g) β¨$β© (finv y)) Ξ· = trans ΞΆ (compId (finv y)) Goal : Image h β y Goal = eq (g β¨$β© (finv y)) Ξ·
β Setoid.Functions.Injective Setoid.Functions.Bijective β