Function#

class discopy.python.additive.Function(inside, dom, cod, is_swap_of=None)[source]#

Bases: discopy.python.function.Function

Python functions with disjoint union as tensor.

Parameters:
  • inside (Callable) – The callable Python object inside the function.

  • dom (type) – The domain of the function, i.e. its list of input types.

  • cod (type) – The codomain of the function, i.e. its list of output types.

Summary

tensor(other)

The disjoint union of two functions, called with @.

swap(x, y)

Swap the tags of a disjoint union from x + y to y + x.

trace([n, left])

The additive trace of a function.

ty_factory#

alias of tuple[type, …]

tensor(other)[source]#

The disjoint union of two functions, called with @.

Parameters:

other (Function) – The other function to compose in sequence.

Return type:

Function

static swap(x, y)[source]#

Swap the tags of a disjoint union from x + y to y + x.

Parameters:
  • x (tuple[type, ...]) – The tuple of types on the left.

  • y (tuple[type, ...]) – The tuple of types on the right.

Return type:

Function

trace(n=1, left=False)[source]#

The additive trace of a function.

Parameters:

n – The number of types to trace over.

braid(y)#

Swap the tags of a disjoint union from x + y to y + x.

Parameters:
  • x (tuple[type, ...]) – The tuple of types on the left.

  • y (tuple[type, ...]) – The tuple of types on the right.

Return type:

Function

classmethod twist(dom)#

The identity function on a given tuple of types dom.

Parameters:

dom (type) – The typle of types on which to take the identity.

Return type:

Function