definition example

If is a Set, a partition of consists of a set and, for each , a nonempty Subset , such that

We denote the partition by , call the set of part labels and the -th part. The conditions say that each lies in exactly one part.

Two partitions and are considered the same if for each there is with (only the labels changed; cf. 7S Exercise 1.16).

Sources: 7 Sketches Definition 1.14, Examples 1.26, 1.49, 1.52; Section 1.1 (systems as partitions); CTfS Example 2.6.1.4, Exercise 2.6.1.5

Partitions as surjections (Example 1.26)

A partition of is the same thing as a surjective function : the preimages form the parts. For partitioned into , take and , , , .

Partitions as equivalence relations

Partitions Correspond to Equivalence Relations (Proposition 1.19): the parts are the equivalence classes, and the set of parts is the Quotient Set .

The preorder of partitions

The set of all partitions of is ordered by fineness; see Preorder of Partitions. The motivating “systems” of 7 Sketches §1.1 — ways of connecting the points — are exactly the five partitions of a three-element set, and joining systems is the Join in . See Generative Effect.

Any function induces a Galois Connection between and ; see Pushforward and Pullback of Partitions.

Docs: FinSets · C-set morphisms · Vignette: partitions — Kittenlab Lecture 9

# A partition of {1,…,n} as a surjection {1,…,n} → {1,…,k}; parts are preimages
using Catlab
f = FinFunction([1,1,2,3,4,4], 4)      # partition {11,12},{13},{21},{22,23}
parts = [preimage(f, p) for p in 1:4]  # [[1,2],[3],[4],[5,6]]
is_epic(f)                              # true: every part is nonempty
 
# Kittenlab Lecture 9: equivalence classes via union-find (see [[Equivalence Relation]])
-- Mathlib: `Setoid.IsPartition` and the equivalence with setoids
#check @Setoid.IsPartition          -- (c : Set (Set α)) : Prop
#check @Setoid.partition_iff_setoid -- partitions ↔ equivalence relations
-- the parts of a setoid are its classes
#check @Setoid.classes
import Data.List (groupBy, sortOn)
import Data.Function (on)
 
-- a partition of xs induced by a "surjection" f (parts = fibres of f)
partitionBy :: Ord b => (a -> b) -> [a] -> [[a]]
partitionBy f = groupBy ((==) `on` f) . sortOn f
 
-- partitionBy (`div` 10) [11,12,13,21,22,23] == [[11,12,13],[21,22,23]]