Functor#
- class discopy.rigid.Functor(ob, ar, ob_factory=<class 'discopy.rigid.Ty'>, ar_factory=<class 'discopy.rigid.Diagram'>)[source]#
Bases:
Functor
Implements rigid monoidal functors, i.e. preserving cups and caps.
>>> s, n = Ty('s'), Ty('n') >>> Alice, Bob = Box("Alice", Ty(), n), Box("Bob", Ty(), n) >>> loves = Box('loves', Ty(), n.r @ s @ n.l) >>> love_box = Box('loves', n @ n, s) >>> ob = {s: s, n: n} >>> ar = {Alice: Alice, Bob: Bob} >>> ar.update({loves: Cap(n.r, n) @ Cap(n, n.l) ... >> Id(n.r) @ love_box @ Id(n.l)}) >>> F = Functor(ob, ar) >>> sentence = Alice @ loves @ Bob >> Cup(n, n.r) @ Id(s) @ Cup(n.l, n) >>> assert F(sentence).normal_form() == Alice >> Id(n) @ Bob >> love_box >>> from discopy import drawing >>> drawing.equation( ... sentence, F(sentence), symbol='$\\mapsto$', figsize=(5, 2), ... path='docs/_static/imgs/rigid/functor-example.png')