Documentation

HexMatrix.Region

structure Hex.Matrix.Region (N M rows cols : Nat) :

A backing-free descriptor for a rows × cols rectangle inside an N × M matrix.

  • r0 : Nat

    Row offset in the destination matrix.

  • c0 : Nat

    Column offset in the destination matrix.

  • rows_le : self.r0 + rows N

    The described rows lie in the destination.

  • cols_le : self.c0 + cols M

    The described columns lie in the destination.

Instances For
    @[inline]
    def Hex.Matrix.Region.row {N M rows cols : Nat} (D : Region N M rows cols) (i : Fin rows) :
    Fin N

    Destination row corresponding to a local region row.

    Equations
    Instances For
      @[inline]
      def Hex.Matrix.Region.col {N M rows cols : Nat} (D : Region N M rows cols) (j : Fin cols) :
      Fin M

      Destination column corresponding to a local region column.

      Equations
      Instances For
        @[inline]
        def Hex.Matrix.Region.rowStart {N M rows cols : Nat} (D : Region N M rows cols) (i : Fin rows) :

        First flat destination index in a local region row.

        Equations
        Instances For
          @[inline]
          def Hex.Matrix.Region.index {N M rows cols : Nat} (D : Region N M rows cols) (i : Fin rows) (j : Fin cols) :
          Fin (N * M)

          Flat destination index corresponding to local region coordinates. The row-invariant multiplication is kept in rowStart, outside column loops.

          Equations
          Instances For
            @[inline]
            def Hex.Matrix.Region.get {R : Type u} {N M rows cols : Nat} (D : Region N M rows cols) (A : Matrix R N M) (i : Fin rows) (j : Fin cols) :
            R

            Read a matrix entry through a region descriptor.

            Equations
            Instances For
              theorem Hex.Matrix.Region.get_eq_data {R : Type u} {N M rows cols : Nat} (D : Region N M rows cols) (A : Matrix R N M) (i : Fin rows) (j : Fin cols) :
              D.get A i j = A.data[(D.index i j)]

              A region read is a read at its flat index.

              def Hex.Matrix.Region.toMatrix {R : Type u} {N M rows cols : Nat} (D : Region N M rows cols) (A : Matrix R N M) :
              Matrix R rows cols

              Materialize the entries described by a region. This is a proof-facing operation; the storage-scheduled implementation writes through descriptors without calling it.

              Equations
              Instances For
                @[simp]
                theorem Hex.Matrix.Region.getElem_toMatrix {R : Type u} {N M rows cols : Nat} (D : Region N M rows cols) (A : Matrix R N M) (i : Fin rows) (j : Fin cols) :
                (D.toMatrix A)[i][j] = D.get A i j

                Entry formula for a materialized region.

                theorem Hex.Matrix.Region.get_of_toMatrix_eq {R : Type u} {N M rows cols : Nat} (D : Region N M rows cols) (A : Matrix R N M) (B : Matrix R rows cols) (h : D.toMatrix A = B) (i : Fin rows) (j : Fin cols) :
                D.get A i j = B[(i, j)]

                Extract an entry equality from equality of a materialized region and a matrix.

                theorem Hex.Matrix.Region.get_eq_of_toMatrix_eq {R : Type u} {N M rows cols : Nat} (D : Region N M rows cols) (A B : Matrix R N M) (h : D.toMatrix A = D.toMatrix B) (i : Fin rows) (j : Fin cols) :
                D.get A i j = D.get B i j

                Equal materialized regions have equal entries.

                @[inline]
                def Hex.Matrix.Region.full (N M : Nat) :
                Region N M N M

                The descriptor for a whole matrix.

                Equations
                Instances For
                  @[simp]
                  theorem Hex.Matrix.Region.get_full {R : Type u} {N M : Nat} (A : Matrix R N M) (i : Fin N) (j : Fin M) :
                  (full N M).get A i j = A[(i, j)]

                  Reading through a whole-matrix descriptor is ordinary matrix access.

                  @[simp]
                  theorem Hex.Matrix.Region.toMatrix_full {R : Type u} {N M : Nat} (A : Matrix R N M) :
                  (full N M).toMatrix A = A

                  Materializing a whole-matrix descriptor returns the matrix.

                  @[inline]
                  def Hex.Matrix.Region.toBlocks₁₁ {N M h w : Nat} (D : Region N M (h + h) (w + w)) :
                  Region N M h w

                  Top-left quadrant of an evenly split region.

                  Equations
                  Instances For
                    @[inline]
                    def Hex.Matrix.Region.toBlocks₁₂ {N M h w : Nat} (D : Region N M (h + h) (w + w)) :
                    Region N M h w

                    Top-right quadrant of an evenly split region.

                    Equations
                    Instances For
                      @[inline]
                      def Hex.Matrix.Region.toBlocks₂₁ {N M h w : Nat} (D : Region N M (h + h) (w + w)) :
                      Region N M h w

                      Bottom-left quadrant of an evenly split region.

                      Equations
                      Instances For
                        @[inline]
                        def Hex.Matrix.Region.toBlocks₂₂ {N M h w : Nat} (D : Region N M (h + h) (w + w)) :
                        Region N M h w

                        Bottom-right quadrant of an evenly split region.

                        Equations
                        Instances For
                          def Hex.Matrix.Region.Disjoint {N M rows cols rows' cols' : Nat} (D : Region N M rows cols) (E : Region N M rows' cols') :

                          Two region descriptors have disjoint rectangles.

                          Equations
                          Instances For

                            The left and right quadrants in the top row are disjoint.

                            The top-left and bottom-left quadrants are disjoint.

                            The top-left and bottom-right quadrants are disjoint.

                            The top-right and bottom-left quadrants are disjoint.

                            The top-right and bottom-right quadrants are disjoint.

                            The left and right quadrants in the bottom row are disjoint.

                            theorem Hex.Matrix.Region.disjoint_toBlocks₁₁ {N M rows cols h w : Nat} (D : Region N M (h + h) (w + w)) (E : Region N M rows cols) (hDE : D.Disjoint E) :

                            A region disjoint from a parent is disjoint from its top-left quadrant.

                            theorem Hex.Matrix.Region.disjoint_toBlocks₁₂ {N M rows cols h w : Nat} (D : Region N M (h + h) (w + w)) (E : Region N M rows cols) (hDE : D.Disjoint E) :

                            A region disjoint from a parent is disjoint from its top-right quadrant.

                            theorem Hex.Matrix.Region.disjoint_toBlocks₂₁ {N M rows cols h w : Nat} (D : Region N M (h + h) (w + w)) (E : Region N M rows cols) (hDE : D.Disjoint E) :

                            A region disjoint from a parent is disjoint from its bottom-left quadrant.

                            theorem Hex.Matrix.Region.disjoint_toBlocks₂₂ {N M rows cols h w : Nat} (D : Region N M (h + h) (w + w)) (E : Region N M rows cols) (hDE : D.Disjoint E) :

                            A region disjoint from a parent is disjoint from its bottom-right quadrant.

                            theorem Hex.Matrix.Region.toMatrix_toBlocks₁₁ {R : Type u} {N M h w : Nat} (D : Region N M (h + h) (w + w)) (A : Matrix R N M) :

                            Materializing a descriptor's top-left quadrant is matrix block extraction.

                            theorem Hex.Matrix.Region.toMatrix_toBlocks₁₂ {R : Type u} {N M h w : Nat} (D : Region N M (h + h) (w + w)) (A : Matrix R N M) :

                            Materializing a descriptor's top-right quadrant is matrix block extraction.

                            theorem Hex.Matrix.Region.toMatrix_toBlocks₂₁ {R : Type u} {N M h w : Nat} (D : Region N M (h + h) (w + w)) (A : Matrix R N M) :

                            Materializing a descriptor's bottom-left quadrant is matrix block extraction.

                            theorem Hex.Matrix.Region.toMatrix_toBlocks₂₂ {R : Type u} {N M h w : Nat} (D : Region N M (h + h) (w + w)) (A : Matrix R N M) :

                            Materializing a descriptor's bottom-right quadrant is matrix block extraction.

                            theorem Hex.Matrix.Region.disjoint_comm {N M rows cols rows' cols' : Nat} {D : Region N M rows cols} {E : Region N M rows' cols'} :

                            Disjointness of region descriptors is symmetric.

                            @[inline]
                            def Hex.Matrix.Region.overwrite {R : Type u} {N M rows cols : Nat} (D : Region N M rows cols) (A : Matrix R N M) (f : Fin rowsFin colsR) :
                            Matrix R N M

                            Fill a destination region from an entry function, threading the destination array directly through its writes.

                            Equations
                            Instances For
                              theorem Hex.Matrix.Region.get_overwrite {R : Type u} {N M rows cols : Nat} (D : Region N M rows cols) (A : Matrix R N M) (f : Fin rowsFin colsR) (i : Fin rows) (j : Fin cols) :
                              D.get (D.overwrite A f) i j = f i j

                              Reading inside an overwritten region returns the supplied entry.

                              theorem Hex.Matrix.Region.get_overwrite_disjoint {R : Type u} {N M rows cols rows' cols' : Nat} (D : Region N M rows cols) (E : Region N M rows' cols') (h : D.Disjoint E) (A : Matrix R N M) (f : Fin rowsFin colsR) (i : Fin rows') (j : Fin cols') :
                              E.get (D.overwrite A f) i j = E.get A i j

                              Overwriting one region preserves every disjoint region.

                              @[inline]
                              def Hex.Matrix.Region.accumulateWith {R : Type u} {N M rows cols : Nat} (D : Region N M rows cols) (A : Matrix R N M) (f : Fin rowsFin colsR) (op : RRR) :
                              Matrix R N M

                              Combine a destination region with entries supplied by a read-only function, modifying each destination entry directly.

                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For
                                @[inline]
                                def Hex.Matrix.Region.accumulateExternal {R : Type u} {N M rows cols : Nat} (D : Region N M rows cols) (A : Matrix R N M) (B : Matrix R rows cols) (op : RRR) :
                                Matrix R N M

                                Combine a destination region entrywise with a separate matrix, modifying each destination entry directly.

                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For
                                  theorem Hex.Matrix.Region.get_accumulateWith {R : Type u} {N M rows cols : Nat} (D : Region N M rows cols) (A : Matrix R N M) (f : Fin rowsFin colsR) (op : RRR) (i : Fin rows) (j : Fin cols) :
                                  D.get (D.accumulateWith A f op) i j = op (D.get A i j) (f i j)

                                  Reading a region after accumulation with a function returns the entrywise combination.

                                  theorem Hex.Matrix.Region.get_accumulateWith_disjoint {R : Type u} {N M rows cols rows' cols' : Nat} (D : Region N M rows cols) (E : Region N M rows' cols') (h : D.Disjoint E) (A : Matrix R N M) (f : Fin rowsFin colsR) (op : RRR) (i : Fin rows') (j : Fin cols') :
                                  E.get (D.accumulateWith A f op) i j = E.get A i j

                                  Accumulation with a read-only function preserves every disjoint region.

                                  theorem Hex.Matrix.Region.get_accumulateExternal {R : Type u} {N M rows cols : Nat} (D : Region N M rows cols) (A : Matrix R N M) (B : Matrix R rows cols) (op : RRR) (i : Fin rows) (j : Fin cols) :
                                  D.get (D.accumulateExternal A B op) i j = op (D.get A i j) B[(i, j)]

                                  Reading a region after an external accumulation returns the entrywise combination.

                                  theorem Hex.Matrix.Region.get_accumulateExternal_disjoint {R : Type u} {N M rows cols rows' cols' : Nat} (D : Region N M rows cols) (E : Region N M rows' cols') (h : D.Disjoint E) (A : Matrix R N M) (B : Matrix R rows cols) (op : RRR) (i : Fin rows') (j : Fin cols') :
                                  E.get (D.accumulateExternal A B op) i j = E.get A i j

                                  Accumulating into one region preserves every disjoint region.

                                  @[inline]
                                  def Hex.Matrix.Region.accumulate {R : Type u} {N M rows cols : Nat} (D S : Region N M rows cols) (_h : D.Disjoint S) (A : Matrix R N M) (op : RRR) :
                                  Matrix R N M

                                  Combine two disjoint regions of the owned output matrix, writing the first and threading the backing array directly through every entry update.

                                  Equations
                                  Instances For
                                    theorem Hex.Matrix.Region.get_accumulate {R : Type u} {N M rows cols : Nat} (D S : Region N M rows cols) (h : D.Disjoint S) (A : Matrix R N M) (op : RRR) (i : Fin rows) (j : Fin cols) :
                                    D.get (D.accumulate S h A op) i j = op (D.get A i j) (S.get A i j)

                                    Reading the destination of an in-buffer accumulation returns the requested entrywise combination.

                                    theorem Hex.Matrix.Region.get_accumulate_disjoint {R : Type u} {N M rows cols rows' cols' : Nat} (D S : Region N M rows cols) (hDS : D.Disjoint S) (E : Region N M rows' cols') (hDE : D.Disjoint E) (A : Matrix R N M) (op : RRR) (i : Fin rows') (j : Fin cols') :
                                    E.get (D.accumulate S hDS A op) i j = E.get A i j

                                    In-buffer accumulation writes only its destination region.

                                    theorem Hex.Matrix.Region.toMatrix_overwrite_disjoint {R : Type u} {N M rows cols rows' cols' : Nat} (D : Region N M rows cols) (E : Region N M rows' cols') (h : D.Disjoint E) (A : Matrix R N M) (f : Fin rowsFin colsR) :

                                    Matrix-level form of get_overwrite_disjoint.

                                    theorem Hex.Matrix.Region.toMatrix_accumulateWith_disjoint {R : Type u} {N M rows cols rows' cols' : Nat} (D : Region N M rows cols) (E : Region N M rows' cols') (h : D.Disjoint E) (A : Matrix R N M) (f : Fin rowsFin colsR) (op : RRR) :

                                    Matrix-level form of get_accumulateWith_disjoint.

                                    theorem Hex.Matrix.Region.toMatrix_accumulateExternal_disjoint {R : Type u} {N M rows cols rows' cols' : Nat} (D : Region N M rows cols) (E : Region N M rows' cols') (h : D.Disjoint E) (A : Matrix R N M) (B : Matrix R rows cols) (op : RRR) :

                                    Matrix-level form of get_accumulateExternal_disjoint.

                                    theorem Hex.Matrix.Region.toMatrix_accumulate_disjoint {R : Type u} {N M rows cols rows' cols' : Nat} (D S : Region N M rows cols) (hDS : D.Disjoint S) (E : Region N M rows' cols') (hDE : D.Disjoint E) (A : Matrix R N M) (op : RRR) :
                                    E.toMatrix (D.accumulate S hDS A op) = E.toMatrix A

                                    Matrix-level form of get_accumulate_disjoint.