diagramize#

Define a diagram using the syntax for Python functions.

param dom:

Domain and codomain of the diagram.

type dom:

discopy.monoidal.Ty

param cod:

Domain and codomain of the diagram.

type cod:

discopy.monoidal.Ty

param boxes:

List of boxes in the signature.

type boxes:

list

param id_factory:

e.g. discopy.monoidal.Id, only needed when there are no boxes.

type id_factory:

type

returns:

decorator – Decorator which turns a function into a diagram.

rtype:

function

Example

>>> from discopy import Ty, Cup, Cap
>>> x = Ty('x')
>>> cup, cap = Cup(x, x.r), Cap(x.r, x)
>>> @diagramize(dom=x, cod=x, boxes=[cup, cap])
... def snake(left):
...     middle, right = cap(offset=1)
...     cup(left, middle)
...     return right
>>> snake.draw(
...     figsize=(3, 3), path='docs/_static/imgs/drawing/diagramize.png')
../_images/diagramize.png