Functor#
- class discopy.tensor.Functor(ob, ar, dom=None, dtype=<class 'int'>)[source]#
Bases:
Functor
A tensor functor is a frobenius functor with a domain category
dom
andCategory(Dim, Tensor[dtype])
as codomain for a givendtype
.- Parameters:
Example
>>> n, s = map(rigid.Ty, "ns") >>> Alice = rigid.Box('Alice', rigid.Ty(), n) >>> loves = rigid.Box('loves', rigid.Ty(), n.r @ s @ n.l) >>> Bob = rigid.Box('Bob', rigid.Ty(), n) >>> diagram = Alice @ loves @ Bob\ ... >> rigid.Cup(n, n.r) @ s @ rigid.Cup(n.l, n)
>>> F = Functor( ... ob={s: 1, n: 2}, ... ar={Alice: [0, 1], loves: [0, 1, 1, 0], Bob: [1, 0]}, ... dom=rigid.Category(), dtype=bool) >>> F(diagram) Tensor[bool]([True], dom=Dim(1), cod=Dim(1))
>>> rewrite = diagram\ ... .transpose_box(2).transpose_box(0, left=True).normal_form() >>> from discopy.drawing import Equation >>> Equation(diagram, rewrite).draw( ... figsize=(8, 3), path='docs/_static/tensor/rewrite.png')
>>> assert F(diagram) == F(rewrite)