The name
A functor is a translation that keeps the structure. The company is named after the adjective.
Categories
A category
C \C C has:
Objects
A collection Ob ( C ) \Ob(\C) Ob ( C ) .
Morphisms
For all a , b ∈ Ob ( C ) a, b \in \Ob(\C) a , b ∈ Ob ( C ) , a set Hom ( a , b ) \Hom(a, b) Hom ( a , b ) . Write f : a → b f : a \to b f : a → b for f ∈ Hom ( a , b ) f \in \Hom(a, b) f ∈ Hom ( a , b ) .
Composition
∘ : Hom ( b , c ) × Hom ( a , b ) ⟶ Hom ( a , c ) \circ \; : \; \Hom(b, c) \times \Hom(a, b) \longrightarrow \Hom(a, c) ∘ : Hom ( b , c ) × Hom ( a , b ) ⟶ Hom ( a , c )
Identities
For every a a a , a morphism 1 a ∈ Hom ( a , a ) \id_a \in \Hom(a, a) 1 a ∈ Hom ( a , a ) .
Two axioms, for all f : a → b f : a \to b f : a → b , g : b → c g : b \to c g : b → c , h : c → d h : c \to d h : c → d :
h ∘ ( g ∘ f ) = ( h ∘ g ) ∘ f f ∘ 1 a = f = 1 b ∘ f h \circ (g \circ f) = (h \circ g) \circ f \qquad\qquad f \circ \id_a = f = \id_b \circ f h ∘ ( g ∘ f ) = ( h ∘ g ) ∘ f f ∘ 1 a = f = 1 b ∘ f
Sets and functions form a category. So do types and functions.
The arrows carry the structure.
Functors
A functor
F : C → D F : \C \to \D F : C → D sends each object a a a to an object F ( a ) F(a) F ( a ) , and each morphism to a morphism:
F a , b : Hom C ( a , b ) ⟶ Hom D ( F ( a ) , F ( b ) ) F_{a,b} \; : \; \Hom_{\C}(a, b) \longrightarrow \Hom_{\D}\bigl(F(a), F(b)\bigr) F a , b : Hom C ( a , b ) ⟶ Hom D ( F ( a ) , F ( b ) )
It keeps identities and composition:
F ( 1 a ) = 1 F ( a ) F ( g ∘ f ) = F ( g ) ∘ F ( f ) F(\id_a) = \id_{F(a)} \qquad\qquad F(g \circ f) = F(g) \circ F(f) F ( 1 a ) = 1 F ( a ) F ( g ∘ f ) = F ( g ) ∘ F ( f )
a → f b → g c F ↓ F ↓ F ↓ F ( a ) → F ( f ) F ( b ) → F ( g ) F ( c ) \begin{CD}
a @>{f}>> b @>{g}>> c \\
@V{F}VV @V{F}VV @V{F}VV \\
F(a) @>{F(f)}>> F(b) @>{F(g)}>> F(c)
\end{CD} a F ↓ ⏐ F ( a ) f F ( f ) b F ↓ ⏐ F ( b ) g F ( g ) c F ↓ ⏐ F ( c )
Compose then translate, or translate then compose: same answer.
A construction with this property is called functorial .
Eilenberg and
Mac Lane
defined all this in
1945 .
Mac Lane said they took "functor" from
Carnap .
A functor in Lean
Take types as objects and functions as arrows. Then a functor is this:
class Functor (f : Type u → Type v) : Type (max (u+1 ) v) where
map : {α β : Type u} → (α → β) → f α → f β
mapConst : {α β : Type u} → α → f β → f α :=
Function.comp map (Function.const _)
f acts on objects, map on arrows. Lean writes
map as <$>. Haskell calls it fmap.
#eval (· + 1 ) <$> [1 , 2 , 3 ] -- [2, 3, 4]
#eval toString <$> [1 , 2 , 3 ] -- ["1", "2", "3"]
The two laws, for List:
example (xs : List Nat ) : xs.map id = xs :=
List.map_id xs
example (f : Nat → Nat ) (g : Nat → String ) (xs : List Nat ) :
(xs.map f).map g = xs.map (g ∘ f) :=
List.map_map
Between any two categories, the functor is in
Mathlib :
structure Functor (C : Type u₁) [Category. {v₁} C ] (D : Type u₂) [Category. {v₂} D ] :
Type max v₁ v₂ u₁ u₂ where
obj : C → D
map : ∀ {X Y : C }, (X ⟶ Y ) → ((obj X ) ⟶ (obj Y ))
map_id : ∀ X : C , map (𝟙 X ) = 𝟙 (obj X ) := by cat_disch
map_comp : ∀ {X Y Z : C } (f : X ⟶ Y ) (g : Y ⟶ Z ),
map (f ≫ g) = map f ≫ map g := by cat_disch
Mathlib writes its type as C ⥤ D. That arrow is our logo:
.
Faithful functors
A functor may send two different arrows to the same arrow. It is
faithful
when it never does: every F a , b F_{a,b} F a , b is injective.
F ( f ) = F ( g ) ⟹ f = g for all f , g : a → b F(f) = F(g) \;\implies\; f = g \qquad \text{for all } f, g : a \to b F ( f ) = F ( g ) ⟹ f = g for all f , g : a → b
class Faithful (F : C ⥤ D ) : Prop where
map_injective : ∀ {X Y : C },
Function.Injective (F.map : (X ⟶ Y ) → (F.obj X ⟶ F.obj Y )) := by
cat_disch
List is faithful:
theorem map_faithful {α β : Type } (f g : α → β)
(h : List.map f = List.map g) : f = g := by
funext a
simpa using congrFun h [a]
This one is not. It obeys both laws and forgets everything:
def Forget (_ : Type ) : Type := Unit
instance : Functor Forget where
map _ _ := ()
example (f g : Nat → Nat ) :
(Functor.map f : Forget Nat → Forget Nat ) = Functor.map g :=
rfl
Faithful means distinct things stay distinct.
From faithful functors to Faithful
An autoformalizer
translates a paper into Lean. Lean checks the Lean. It cannot see whether the
translation dropped a hypothesis or merged two claims, any more than you can tell
two functions apart after Forget.
So a person checks the translation, one correspondence at a time. That is a
faithfulness review ,
and faithful.functorial.inc is where you do one.
Open Faithful