Layer#

class discopy.monoidal.Layer(left, box, right, *more)[source]#

Bases: Box

A layer is a box in the middle of a pair of types left and right.

Parameters:
  • left (Ty) – The type on the left of the layer.

  • box (Box) – The box in the middle of the layer.

  • right (Ty) – The type on the right of the layer.

  • more – More boxes and types to the right, used by Diagram.foliation().

classmethod cast(box)[source]#

Turns a box into a layer with empty types on the left and right.

Parameters:

box (Box) – The box in the middle of empty types.

Return type:

Layer

Example

>>> f = Box('f', Ty('x'), Ty('y'))
>>> assert Layer.cast(f) == Layer(Ty(), f, Ty())
property boxes_and_offsets: list[tuple[Box, int]]#

The offsets of each box inside the layer.

Example

>>> a, b, c, d, e = map(Ty, "abcde")
>>> f, g = Box('f', a, b), Box('g', c, d)
>>> assert Layer(e, f, e, g, e).boxes_and_offsets == [(f, 1), (g, 3)]
merge(other)[source]#

Merge two layers into one or raise AxiomError, used by Diagram.foliation().

Parameters:

other (Layer) – The other layer with which to merge.

Return type:

Layer

Example

>>> a, b, c, d, e = map(Ty, "abcde")
>>> f, g = Box('f', a, b), Box('g', c, d)
>>> layer0 = Layer(e,  f,  e @ c @ e)
>>> layer1 = Layer(e @ b @ e,  g,  e)
>>> assert layer0.merge(layer1) == Layer(e, f, e, g, e)