The real evaluator and the backward flat permutation #
The forward evaluator lowers an axis array to adjacent swaps. The backward operation inverts the same array and linearizes its coordinates. Both implementations therefore describe one bijection of real tensor entries, including tensors with arbitrary rank and zero-length dimensions.
theorem
NN.MLTheory.CROWN.Graph.DirectedBackward.adjacentShape_axisMap
(s : Spec.Shape)
(swaps : List ℕ)
(e : Equiv.Perm (Fin (List.length s)))
(haxes : List.foldl Spec.Shape.swapAdjacentAxes (List.range (List.length s)) swaps = (axisArray e).toList)
:
theorem
NN.MLTheory.CROWN.Graph.DirectedBackward.adjacentCoordinateEquiv_axisMap
(s : Spec.Shape)
(swaps : List ℕ)
(e : Equiv.Perm (Fin (List.length s)))
(haxes : List.foldl Spec.Shape.swapAdjacentAxes (List.range (List.length s)) swaps = (axisArray e).toList)
(c : s.Coord)
:
Spec.Shape.Coord.toList (s.applyAdjacentSwaps swaps) ((adjacentCoordinateEquiv s swaps) c) = axisMap e (Spec.Shape.Coord.toList s c)
noncomputable def
NN.MLTheory.CROWN.Graph.DirectedBackward.adjacentFlatEquiv
(s : Spec.Shape)
(swaps : List ℕ)
:
The forward permutation of flat tensor coordinates, obtained from the actual adjacent swaps.
Instances For
theorem
NN.MLTheory.CROWN.Graph.DirectedBackward.flatCoordEquiv_symm_val
(s : Spec.Shape)
(c : s.Coord)
:
theorem
NN.MLTheory.CROWN.Graph.DirectedBackward.flatAxisPermutation?_adjacent
(s : Spec.Shape)
(swaps : List ℕ)
(e : Equiv.Perm (Fin (List.length s)))
(haxes : List.foldl Spec.Shape.swapAdjacentAxes (List.range (List.length s)) swaps = (axisArray e).toList)
{flat : Fin (s.applyAdjacentSwaps swaps).size → Fin (s.applyAdjacentSwaps swaps).size}
(hflat :
flatAxisPermutation? (s.applyAdjacentSwaps swaps) (axisArray (Equiv.symm e)) (s.applyAdjacentSwaps swaps).size = some flat)
:
The checked backward flat permutation is the inverse-read form of the forward swaps.
theorem
NN.MLTheory.CROWN.Graph.DirectedBackward.realTensor_coord
(s : Spec.Shape)
(f : ℕ → ℝ)
(c : s.Coord)
:
theorem
NN.MLTheory.CROWN.Graph.DirectedBackward.adjacentFlatEquiv_values
(s : Spec.Shape)
(swaps : List ℕ)
(f g : ℕ → ℝ)
(hvalues : (realTensor s f).permuteByAdjacentSwaps swaps = realTensor (s.applyAdjacentSwaps swaps) g)
(i : Fin s.size)
:
theorem
NN.MLTheory.CROWN.Graph.DirectedBackward.permuteSomeTensor_flatEquation
{s t : Spec.Shape}
{forward : Array ℕ}
{f g : ℕ → ℝ}
(heval :
IR.Graph.permuteSomeTensor { shape := s, tensor := realTensor s f } forward = Except.ok { shape := t, tensor := realTensor t g })
:
A successful real permutation evaluator supplies exactly the backward coordinate equation.