Functor#
- class discopy.traced.Functor(ob=None, ar=None, dom=None, cod=None)[source]#
Bases:
discopy.monoidal.Functor
A traced functor is a monoidal functor that preserves traces.
- Parameters:
ob (Mapping[monoidal.Ty, monoidal.Ty]) – Map from
monoidal.Ty
tocod.ob
.cod (Category) – The codomain,
Category(Ty, Diagram)
by default.dom (T) –
Example
Let’s compute the golden ratio by applying a (hacky) traced functor.
>>> from math import sqrt >>> from discopy import python >>> x = Ty('$\\mathbb{R}$') >>> f = Box('$\\lambda x . (x, 1 + 1 / x)$', x, x @ x) >>> g = Box('$\\frac{1 + \\sqrt{5}}{2}$', Ty(), x) >>> F = Functor( ... ob={x: (float, )}, ... ar={f: lambda x=1.: (x, 1 + 1. / x), g: lambda: (1 + sqrt(5)) / 2}, ... cod=Category(python.Ty, python.Function)) >>> with python.Function.no_type_checking: ... assert F(f.trace())() == F(g)()
>>> from discopy.drawing import Equation >>> Equation(f.trace(), g).draw(path="docs/_static/traced/golden.png")