Ty#
- class discopy.monoidal.Ty(*objects)[source]#
Bases:
Ob
Implements a type as a list of
discopy.cat.Ob
, used as domain and codomain formonoidal.Diagram
. Types are the free monoid on objects with product@
and unitTy()
.- Parameters:
objects (list of
discopy.cat.Ob
) – List of objects or object names.
Important
Elements that are not instance of
discopy.cat.Ob
are implicitly taken to be the name of an object, i.e.Ty('x', 'y') == Ty(Ob('x'), Ob('y'))
.Notes
We can check the axioms for a monoid.
>>> x, y, z, unit = Ty('x'), Ty('y'), Ty('z'), Ty() >>> assert x @ unit == x == unit @ x >>> assert (x @ y) @ z == x @ y @ z == x @ (y @ z)
- property objects#
List of objects forming a type.
Note
A type may be sliced into subtypes.
>>> t = Ty('x', 'y', 'z') >>> assert t[0] == Ob('x') >>> assert t[:1] == Ty('x') >>> assert t[1:] == Ty('y', 'z')
- tensor(*others)[source]#
Returns the tensor of types, i.e. the concatenation of their lists of objects. This is called with the binary operator @.
>>> Ty('x') @ Ty('y', 'z') Ty('x', 'y', 'z')
- Parameters:
other (monoidal.Ty) –
- Returns:
t – such that
t.objects == self.objects + other.objects
.- Return type:
Note
We can take the sum of a list of type, specifying the unit Ty().
>>> types = Ty('x'), Ty('y'), Ty('z') >>> Ty().tensor(*types) Ty('x', 'y', 'z')
We can take the exponent of a type by any natural number.
>>> Ty('x') ** 3 Ty('x', 'x', 'x')
- count(obj)[source]#
Counts the occurrence of a given object.
- Parameters:
obj (
Ty
orOb
) – either a type of length 1 or an object- Returns:
n – such that
n == self.objects.count(ob)
.- Return type:
int
Examples
>>> x = Ty('x') >>> xs = x ** 5 >>> assert xs.count(x) == xs.count(x[0]) == xs.objects.count(Ob('x'))
- downgrade()[source]#
Downgrades to
discopy.monoidal.Ty
.