Nat#
- class discopy.monoidal.Nat(inside=0, dom=None, cod=None, _scan=True)[source]#
Bases:
discopy.abc.Nat,TyNatis a natural numbernseen 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)
Natis also a sequence over its unary encoding, so slicing, iterating and taking its length reads it the same way as any otherTy.>>> assert len(Nat(3)) == 3 and list(Nat(3)) == 3 * [Nat(1)] >>> assert Nat(3)[:1] == Nat(1) == Nat(3)[0]
Note
If
obisNatthenDiagramwill automatically turn anyn: intintoNat(n). ThusNatnever needs to be called, and the resulting diagrams live in adiscopy.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