definition example

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.

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

Catlab 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_surjective
isSurjective :: Eq b => [a] -> [b] -> (a -> b) -> Bool
isSurjective dom cod f = all (`elem` map f dom) cod