Ty#

class discopy.monoidal.Ty(*inside)[source]#

Bases: discopy.cat.Ob

A type is a tuple of objects with Ty.tensor() as concatenation.

Parameters:

inside (str | cat.Ob) – The objects inside the type (or their names).

Tip

Types can be instantiated with a name rather than object.

>>> assert Ty('x') == Ty(cat.Ob('x'))

Tip

A type can be exponentiated by a natural number.

>>> assert Ty('x') ** 3 == Ty('x', 'x', 'x')

Note

Types can be indexed and sliced using square brackets. Indexing behaves like that of strings, i.e. when we index a type we get a type back. The objects inside the type are still accessible using .inside.

>>> t = Ty(*"xyz")
>>> assert t[0] == t[:1] == Ty('x')
>>> assert t[0] != t.inside[0] == Ob('x')
>>> assert t[1:] == t[-2:] == Ty('y', 'z')
ob_factory#

alias of Ob

tensor(*others)[source]#

Returns the tensor of types, i.e. the concatenation of their lists of objects. This is called with the binary operator @.

Parameters:

others (Ty) – The other types to tensor.

Return type:

Ty

Tip

A list of types can be tensored by calling Ty().tensor.

>>> list_of_types = [Ty('x'), Ty('y'), Ty('z')]
>>> assert Ty().tensor(*list_of_types) == Ty('x', 'y', 'z')
count(obj)[source]#

Counts the occurrence of a given object (or a type of length 1).

Parameters:

obj (Ob) – The object to count.

Return type:

int

Example

>>> x = Ty('x')
>>> xs = x ** 5
>>> assert xs.count(x) == xs.inside.count(x.inside[0])
to_drawing()[source]#

Called before Diagram.draw().

Return type:

Ty

property is_atomic: bool#

Whether a type is atomic, i.e. it has length 1.

factory#

alias of Ty