Functor#
- class discopy.cat.Functor(ob, ar, ob_factory=None, ar_factory=None)[source]#
Bases:
object
Defines a dagger functor which can be applied to objects and arrows.
By default, Functor defines an endofunctor from the free dagger category to itself. The codomain can be changed with the optional parameters ob_factory and ar_factory.
- Parameters:
ob (dict_like) – Mapping from
cat.Ob
to ob_factory.ar (dict_like) – Mapping from
cat.Box
to ar_factory.ob_factory (type, optional) – Class to be used as objects for the codomain of the functor. If None, this will be set to
cat.Ob
.ar_factory (type, optional) – Class to be used as arrows for the codomain of the functor. If None, this will be set to
cat.Arrow
.
Examples
>>> x, y, z = Ob('x'), Ob('y'), Ob('z') >>> f, g = Box('f', x, y), Box('g', y, z) >>> ob, ar = {x: y, y: z, z: y}, {f: g, g: g[::-1]} >>> F = Functor(ob, ar) >>> assert F(x) == y and F(f) == g
Notes
We can check the axioms of dagger functors.
>>> assert F(Id(x)) == Id(F(x)) >>> assert F(f >> g) == F(f) >> F(g) >>> assert F(f[::-1]) == F(f)[::-1] >>> assert F(f.dom) == F(f).dom and F(f.cod) == F(f).cod
Functors are bubble-preserving.
>>> assert F(f.bubble()) == F(f).bubble()
See also
Quiver
For functors from infinitely-generated categories, use quivers to create dict-like objects from functions.
- property ob#
Mapping on objects.
>>> F = Functor({Ob('x'): Ob('y')}, {}) >>> assert F.ob == {Ob('x'): Ob('y')}
- property ar#
Mapping on arrows.
>>> f, g = Box('f', Ob('x'), Ob('y')), Box('g', Ob('y'), Ob('z')) >>> F = Functor({}, {f: g}) >>> assert F.ar == {f: g}