A Function is surjective (a surjection, drawn ) if for all there exists with .
Sources: 7 Sketches Definition 1.22, Example 1.26; Kittenlab Lecture 2; DaoFP §2.5 (epimorphisms); CTfS Definition 2.7.5.1, Proposition 2.7.5.4
Quantifier order matters (Kittenlab): “for every there exists ” allows a different for each ; “there exists such that for every ” would force to be a singleton.
Examples. with is surjective and not injective; likewise.
- Surjections out of are the same as partitions of (Example 1.26): the parts are the preimages .
- Surjective functions are exactly the epimorphisms of (DaoFP §2.5). Any arrow into the Terminal Object is an epimorphism.
- A function is a Bijection iff surjective and injective.
- Every function factors as a surjection followed by an injection (Epi-Mono Factorization), which is how partitions are pulled back along arbitrary functions.
Docs: FinSets · C-set morphisms — Kittenlab Lecture 2
Builds on: Function (𝔽Mor) — run that note’s Julia code first.
# Kittenlab Lecture 2
function is_surjective(f::𝔽Mor)
seen = Set([f(x) for x in f.dom])
all(y ∈ seen for y in f.codom)
endCatlab version (run in a fresh Julia session — Catlab exports its own compose, id, FinFunction, …):
# Catlab
using Catlab
f = FinFunction([1, 2, 2], 2)
is_epic(f) # true#check @Function.Surjective -- ∀ b, ∃ a, f a = b
#check @CategoryTheory.epi_iff_surjectiveisSurjective :: Eq b => [a] -> [b] -> (a -> b) -> Bool
isSurjective dom cod f = all (`elem` map f dom) cod