Permutation#
- class discopy.symmetric.Permutation(dom, perm)[source]#
Bases:
BoxA permutation box, i.e. a
Boxthat reorders its input wires.A permutation holds a
discopy.python.finset.Permutationpermas attribute, with the convention that output wireicomes from input wireperm[i], i.e.cod[i] == dom[perm[i]].A
Layerstores it as routing rather than as a generator, and the identity permutation is the identity diagram. It draws as a single band of crossing wires rather than a staircase of swaps.- Parameters:
dom (C0) – The domain, i.e. the wires to permute.
perm (Sequence[int]) – The permutation as a
finset.Permutationor a list.
Examples
>>> x, y, z, w = map(Ty, "xyzw") >>> perm = Permutation(x @ y @ z, [1, 2, 0]) >>> assert perm.cod == y @ z @ x >>> assert perm.dagger() == Permutation(y @ z @ x, [2, 0, 1]) >>> assert Equation(perm >> perm.dagger(), Id(x @ y @ z)) >>> assert perm @ Id(w) == Permutation(x @ y @ z @ w, [1, 2, 0, 3]) >>> assert Permutation(x @ y, [1, 0]) != Swap(x, y) >>> assert Equation(Permutation(x @ y, [1, 0]), Swap(x, y)) >>> assert Permutation(x @ y, [0, 1]) == Id(x @ y)
Writing permutations by hand keeps swap-heavy diagrams compact: a whole permutation occupies a single layer rather than a quadratic staircase of swaps. Reversing four wires before a single layer of boxes is a permutation layer followed by a box layer.
>>> f0, f1 = Box("f0", w, x), Box("f1", z, y) >>> g0, g1 = Box("g0", y, z), Box("g1", x, w) >>> reverse = Permutation(x @ y @ z @ w, [3, 2, 1, 0]) >>> diagram = reverse >> f0 @ f1 @ g0 @ g1 >>> diagram.depth() 1 >>> diagram.draw( ... doctest='docs/_static/symmetric/foliation.svg', figsize=(4, 4))
- property is_identity: bool#
Whether the underlying permutation is the identity.
>>> assert Permutation(Ty('x', 'y'), [0, 1]).is_identity
- property size: int#
Structural permutations are not generator boxes in a layer.