Permutations as data #
A permutation of the entries of a vector of length n is a sequence of steps (PermS), each a
numpy operation on the vector reshaped, row-major, to a shape dims with n entries:
| step | numpy |
|---|---|
tr dims axes | x.reshape(dims).transpose(axes).reshape(-1) |
flip dims k | jnp.flip(x.reshape(dims), k).reshape(-1) |
roll dims k s | jnp.roll(x.reshape(dims), s, axis=k).reshape(-1) |
The steps apply in order. Each acts as a gather: output position i reads input position
idx i, so the sequence [p₁, p₂, …] reads p₁.idx (p₂.idx (… i)) (PermS.idx). The squeezes
and patchings of the models are transposes, their channel and token reversals flips, and their
rotations rolls.
Nothing here uses Mathlib: the flow signature (Flow.Basic) reads PermS.idx as an
Equiv.Perm, and the printer (Flow.Print) prints the steps.
One step of a permutation, on the vector reshaped to dims.
- tr
(dims axes : List Nat)
: PermStep
Permute the axes: output axis
jis input axisaxes[j]. - flip
(dims : List Nat)
(k : Nat)
: PermStep
Reverse axis
k. - roll
(dims : List Nat)
(k s : Nat)
: PermStep
Rotate axis
kbys: output indexjreadsj - s(mod the axis length).
Instances For
Equations
- One or more equations did not get rendered due to their size.
- RoleFlow.Flow.instDecidableEqPermStep.decEq (RoleFlow.Flow.PermStep.tr dims axes) (RoleFlow.Flow.PermStep.flip dims_1 k) = isFalse ⋯
- RoleFlow.Flow.instDecidableEqPermStep.decEq (RoleFlow.Flow.PermStep.tr dims axes) (RoleFlow.Flow.PermStep.roll dims_1 k s) = isFalse ⋯
- RoleFlow.Flow.instDecidableEqPermStep.decEq (RoleFlow.Flow.PermStep.flip dims k) (RoleFlow.Flow.PermStep.tr dims_1 axes) = isFalse ⋯
- RoleFlow.Flow.instDecidableEqPermStep.decEq (RoleFlow.Flow.PermStep.flip dims k) (RoleFlow.Flow.PermStep.roll dims_1 k_1 s) = isFalse ⋯
- RoleFlow.Flow.instDecidableEqPermStep.decEq (RoleFlow.Flow.PermStep.roll dims k s) (RoleFlow.Flow.PermStep.tr dims_1 axes) = isFalse ⋯
- RoleFlow.Flow.instDecidableEqPermStep.decEq (RoleFlow.Flow.PermStep.roll dims k s) (RoleFlow.Flow.PermStep.flip dims_1 k_1) = isFalse ⋯
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
A permutation: its steps, applied in order.
Equations
Instances For
Equations
- (RoleFlow.Flow.PermStep.tr a a_1).dims = a
- (RoleFlow.Flow.PermStep.flip a a_1).dims = a
- (RoleFlow.Flow.PermStep.roll a a_1 a_2).dims = a
Instances For
The input position that output position i reads.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The step that undoes this one.
Equations
- (RoleFlow.Flow.PermStep.tr a a_1).inv = RoleFlow.Flow.PermStep.tr (List.map (fun (a_2 : Nat) => a.getD a_2 1) a_1) (List.map (fun (a : Nat) => List.idxOf a a_1) (List.range a_1.length))
- (RoleFlow.Flow.PermStep.flip a a_1).inv = RoleFlow.Flow.PermStep.flip a a_1
- (RoleFlow.Flow.PermStep.roll a a_1 a_2).inv = RoleFlow.Flow.PermStep.roll a a_1 ((a.getD a_1 1 - a_2 % a.getD a_1 1) % a.getD a_1 1)
Instances For
The step is well formed on vectors of length n: its shape has n entries, axes is a
permutation of the axes, and k is an axis.
Equations
- One or more equations did not get rendered due to their size.
- RoleFlow.Flow.PermStep.ok n (RoleFlow.Flow.PermStep.flip a a_1) = (List.foldl (fun (x1 x2 : Nat) => x1 * x2) 1 (RoleFlow.Flow.PermStep.flip a a_1).dims == n && decide (a_1 < a.length))
- RoleFlow.Flow.PermStep.ok n (RoleFlow.Flow.PermStep.roll a a_1 a_2) = (List.foldl (fun (x1 x2 : Nat) => x1 * x2) 1 (RoleFlow.Flow.PermStep.roll a a_1 a_2).dims == n && decide (a_1 < a.length))
Instances For
The step does nothing: a transpose with the axes in order, a flip of an axis of length at most
1, a roll by a multiple of the axis length.
Equations
- (RoleFlow.Flow.PermStep.tr a a_1).isId = (a_1 == List.range a_1.length)
- (RoleFlow.Flow.PermStep.flip a a_1).isId = decide (a.getD a_1 1 ≤ 1)
- (RoleFlow.Flow.PermStep.roll a a_1 a_2).isId = (a_2 % a.getD a_1 1 == 0)
Instances For
The step in the surface syntax of the webapp, before its argument: tr<[2, 3], [1, 0]>.
Equations
- (RoleFlow.Flow.PermStep.tr a a_1).text = toString "tr<" ++ toString a ++ toString ", " ++ toString a_1 ++ toString ">"
- (RoleFlow.Flow.PermStep.flip a a_1).text = toString "flip<" ++ toString a ++ toString ", " ++ toString a_1 ++ toString ">"
- (RoleFlow.Flow.PermStep.roll a a_1 a_2).text = toString "roll<" ++ toString a ++ toString ", " ++ toString a_1 ++ toString ", " ++ toString a_2 ++ toString ">"
Instances For
The steps applied to x, in the surface syntax of the webapp.
Equations
- RoleFlow.Flow.PermS.text x ps = List.foldl (fun (x : String) (p : RoleFlow.Flow.PermStep) => toString p.text ++ toString "(" ++ toString x ++ toString ")") x ps
Instances For
The input position that output position i reads.
Equations
- ps.idx i = List.foldr RoleFlow.Flow.PermStep.idx i ps
Instances For
The steps that undo ps.
Equations
Instances For
Every step is well formed on vectors of length n.
Equations
- RoleFlow.Flow.PermS.ok n ps = List.all ps (RoleFlow.Flow.PermStep.ok n)
Instances For
The index list [idx 0, …, idx (n - 1)].
Equations
- RoleFlow.Flow.PermS.idxList n ps = List.map ps.idx (List.range n)
Instances For
ps is a permutation of 0, …, n - 1: well formed, and its index list is one.
Equations
- One or more equations did not get rendered due to their size.