Diagram#

class discopy.grammar.pregroup.Diagram(inside, dom, cod, _scan=True)[source]#

Bases: discopy.rigid.Diagram, discopy.symmetric.Diagram

A pregroup diagram is a rigid diagram with Word boxes.

Parameters
  • inside (tuple[rigid.Layer, ...]) – The layers of the diagram.

  • dom (rigid.Ty) – The domain of the diagram, i.e. its input.

  • cod (rigid.Ty) – The codomain of the diagram, i.e. its output.

Example

>>> s, n = Ty('s'), Ty('n')
>>> Alice, Bob = Word('Alice', n), Word('Bob', n)
>>> loves = Word('loves', n.r @ s @ n.l)
>>> grammar = Cup(n, n.r) @ Id(s) @ Cup(n.l, n)
>>> sentence = grammar << Alice @ loves @ Bob
>>> print(sentence[:4])
Alice >> n @ loves >> n @ n.r @ s @ n.l @ Bob >> Cup(n, n.r) @ s @ n.l @ n
>>> from discopy import tensor, rigid
>>> ob = {s: 1, n: 2}
>>> ar = {Alice: [1, 0], loves: [0, 1, 1, 0], Bob: [0, 1]}
>>> F = tensor.Functor(ob, ar, dom=rigid.Category(), dtype=bool)
>>> assert F(sentence)
normal_form(**params)[source]#

Applies normal form to a pregroup diagram of the form word @ ... @ word >> wires by normalising words and wires seperately before combining them, so it can be drawn with draw().

braid_factory#

alias of Swap

cap_factory#

alias of Cap

cup_factory#

alias of Cup

factory#

alias of Diagram