definition theorem example program
The dependent sum (sigma type) is the type of pairs with and — a sum tagged by elements of ; e.g. counted vectors are pairs (2, (64, 7)), (5, (8,21,14,-1,0)) of a length and a tuple. Categorically, for the dependent sum is the left adjoint of the Base Change Functor:
also written (” lower shriek”): a bundle finely fibered over is automatically, more coarsely, fibered over by post-composition. The adjunction reads
Sources: DaoFP §11.3 (“Dependent Sum”, “Adding the atlas”, “Existential quantification”), §11.2; 7 Sketches §7.4.4 (existential quantification as image); Kittenlab Lecture 13.
- Special case : , and the adjunction exhibits as the sum of its fibers: the left side is a bunch of arrows, one per fiber of , into (” copies of ” generalize the Diagonal Functor ). For counted vectors is infinitely many functions, one per length, defined in practice by recursion (
sumV). - Logic: is the proposition : a term is a witness together with a proof (Quantification).
- The forgetful functor , , is for .
- In , ; in Haskell without full dependent types,
data SomeVec a = forall n. SomeVec (SNat n) (Vec n a)(an existential) plays the role of .
Docs: FinSets — Kittenlab Lecture 13
using Catlab
# Σ_f on a bundle q : S → B along f : B → A is just post-composition
q = FinFunction([1, 2, 2, 3], 3) # S = 4 fibered over B = 3
f = FinFunction([1, 1, 2], 2) # B → A
Σq = compose(q, f) # S fibered over A: fibers of size 3 and 1
[length(preimage(Σq, y)) for y in 1:2] # [3, 1]import Mathlib
#check @Sigma -- Σ x : B, T x with ⟨x, y⟩
#check @Sigma.mk
#check @CategoryTheory.Over.map -- Σ_f : Over X ⥤ Over Y for f : X ⟶ Y (post-composition)
#check @CategoryTheory.Over.mapPullbackAdj -- Over.map f ⊣ Over.pullback f
example : Σ n : ℕ, Fin n := ⟨3, 1⟩ -- a dependent pair{-# LANGUAGE DataKinds, GADTs, ExistentialQuantification #-}
-- the sum over n of Vec n a, as an existential
data SomeVec a = forall n. SomeVec (SNat n) (Vec n a)
data SNat n where
SZ :: SNat 'Z
SS :: SNat n -> SNat ('S n)
-- a mapping out of the dependent sum: one function per fiber, defined by recursion
sumV :: Vec n Int -> Int
sumV VNil = 0
sumV (VCons n v) = n + sumV v