Sum#

class discopy.cat.Sum(terms, dom=None, cod=None)[source]#

Bases: Box

Implements enrichment over monoids, i.e. formal sums of diagrams.

Parameters:
  • terms (list of Arrow) – Terms of the formal sum.

  • dom (Ob, optional) – Domain of the formal sum, optional if diagrams is non-empty.

  • cod (Ob, optional) – Codomain of the formal sum, optional if diagrams is non-empty.

Examples

>>> x, y = Ob('x'), Ob('y')
>>> f, g = Box('f', x, y), Box('g', x, y)
>>> f + g
Sum([Box('f', Ob('x'), Ob('y')), Box('g', Ob('x'), Ob('y'))])
>>> unit = Sum([], x, y)
>>> assert (f + unit) == Sum([f]) == (unit + f)
>>> print((f + g) >> (f + g)[::-1])
(f >> f[::-1]) + (f >> g[::-1]) + (g >> f[::-1]) + (g >> g[::-1])

Note

The sum is non-commutative, i.e. Sum([f, g]) != Sum([g, f]).

A diagram is different from the sum of itself, i.e. Sum([f]) != f