Functor#
- class discopy.traced.Functor(ob_map=None, ar_map=None, dom=None, cod=None, colour_map=None)[source]#
Bases:
discopy.monoidal.FunctorA traced functor is a monoidal functor that preserves traces.
- Parameters:
ob_map (Mapping[monoidal.Ty, monoidal.Ty]) – Map from
monoidal.Tytocod.ob.cod (Category) – The codomain,
Diagramby default.
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_map={x: (float, )}, ... ar_map={ ... f: lambda x=1.: (x, 1 + 1. / x), ... g: lambda: (1 + sqrt(5)) / 2}, ... cod=python.Function) >>> with python.Function.no_type_checking: ... assert F(f.trace())() == F(g)()
>>> from discopy.monoidal import Equation >>> Equation(f.trace(), g).draw(path="docs/_static/traced/golden.svg")