definition example

The category of sets, :

(i) is the collection of all sets; (ii) ; (iii) the identity is ; (iv) composition is .

Unitality and associativity hold, so is a category — “the most important category in mathematics”.

Sources: 7 Sketches Definition 3.24, Remark 3.26, Example 3.29, Exercise 3.25, §3.5.3, §7.2; Kittenlab Lecture 3 (“sets” as predicates; , the category of Julia types); DaoFP §8.1 (“Category of sets”), §10.11; CTfS Chapter 2 (“The category of sets”: all of it is “an investigation of our first category”), Example 4.1.1.3, §5.2.1 (the dictionary between and -)

Properties and role

Docs: Sets — Kittenlab Lecture 3

Builds on: Set (ComputableSet) — run that note’s Julia code first.

# Kittenlab Lecture 3: a set is a predicate `Any -> Bool`; morphisms are Julia callables
struct TypeSet <: ComputableSet; T::Type end
Base.in(x, χ::TypeSet) = x isa χ.T
# A → B is the set of callables f with f(a) ∈ B for all a ∈ A (not checkable for infinite A)

Catlab version (run in a fresh Julia session — Catlab exports its own compose, id, FinFunction, …):

# Catlab: SetOb / SetFunction model Set (types as sets), FinSet models FinSet
using Catlab
X = TypeSet(Int)                        # the set of Ints as an object of Set
f = SetFunction(x -> x + 1, X, X)
compose(f, f)(1)                        # 3
open CategoryTheory
#check (Type u)                               -- the category of types (sets in universe u)
example : Category (Type u) := inferInstance  -- types.instCategory: Hom X Y := X → Y
#check @CategoryTheory.mono_iff_injective
#check @CategoryTheory.epi_iff_surjective
#check @CategoryTheory.types.terminal          -- PUnit; initial: PEmpty
-- Hask: objects are types, morphisms are functions; composition is (.), identity is id
-- (Hask is only approximately Set: laziness, bottom, and non-total functions differ.)
newtype Hask a b = Hask (a -> b)