Nat#

class discopy.monoidal.Nat(inside=0, dom=None, cod=None, _scan=True)[source]#

Bases: discopy.abc.Nat, Ty

Nat is a natural number n seen as a type with addition as tensor, i.e. the free monoid on one generator.

Parameters:
  • inside (int | tuple) – The natural number, or a tuple of generators whose length is taken.

  • dom (C0)

  • cod (C0)

  • _scan (bool)

Example

>>> assert Nat(1) @ Nat(2) == Nat(3)

Nat is also a sequence over its unary encoding, so slicing, iterating and taking its length reads it the same way as any other Ty.

>>> assert len(Nat(3)) == 3 and list(Nat(3)) == 3 * [Nat(1)]
>>> assert Nat(3)[:1] == Nat(1) == Nat(3)[0]

Note

If ob is Nat then Diagram will automatically turn any n: int into Nat(n). Thus Nat never needs to be called, and the resulting diagrams live in a discopy.abc.PRO.

>>> @factory
... class Circuit(abc.PRO, Diagram):
...     ob = Nat
>>> class Gate(Box, Circuit): ...
>>> CX = Gate('CX', 2, 2)
>>> assert CX @ 2 >> 2 @ CX == CX @ CX
generator_factory#

alias of int

factory#

alias of Nat