Documentation

CompPoly.Data.Vector.Basic

Definitions and lemmas for Vector #

accumulateProducts separates product accumulation from reduction. Its reduction theorem recovers dotProduct whenever reduction preserves zero, addition, and the chosen products.

def Vector.induction₂_temp {α : Type u_2} {β : Type u_3} {motive : {n : } → Vector α nVector β nSort u_1} (v_empty : motive #v[] #v[]) (v_insert : {n : } → (hd : α) → (tl : Vector α n) → (hd' : β) → (tl' : Vector β n) → motive tl tl'motive (tl.insertIdx 0 hd ) (tl'.insertIdx 0 hd' )) {m : } (v : Vector α m) (v' : Vector β m) :
motive v v'
Instances For
    def Vector.nil {α : Type u_1} :
    Vector α 0

    The empty vector.

    Instances For
      def Vector.cons {α : Type u_1} {n : } (hd : α) (tl : Vector α n) :
      Vector α (n + 1)

      Construct a vector by prepending an element to the front of a vector, using insertIdx at 0.

      Instances For
        @[simp]
        theorem Vector.head_cons {α : Type u_1} {n : } (hd : α) (tl : Vector α n) :
        (cons hd tl).head = hd
        theorem Vector.cons_get_eq {α : Type u_1} {n : } (hd : α) (tl : Vector α n) (i : Fin (n + 1)) :
        (cons hd tl).get i = if hi : (i == 0) = true then hd else tl.get i - 1,
        @[simp]
        theorem Vector.cons_empty_tail_eq_nil {α : Type u_1} (hd : α) (tl : Vector α 0) :
        cons hd tl = #v[hd]
        @[simp]
        theorem Vector.tail_cons {α : Type u_1} {n : } (hd : α) (tl : Vector α n) :
        (cons hd tl).tail = tl
        @[simp]
        theorem Vector.cons_toList_eq_List_cons {α : Type u_1} {n : } (hd : α) (tl : Vector α n) :
        (cons hd tl).toList = hd :: tl.toList
        theorem Vector.foldl_eq_toList_foldl {α : Type u_1} {β : Type u_2} {n : } (f : βαβ) (init : β) (v : Vector α n) :
        foldl f init v = List.foldl f init v.toList
        theorem Vector.foldl_succ {α : Type u_1} {β : Type u_2} {n : } [NeZero n] (f : βαβ) (init : β) (v : Vector α n) :
        foldl f init v = foldl f (f init v.head) v.tail
        theorem Vector.zipWith_cons {α : Type u_1} {β : Type u_2} {γ : Type u_3} {n : } (f : αβγ) (a : α) (b : Vector α n) (c : β) (d : Vector β n) :
        zipWith f (cons a b) (cons c d) = cons (f a c) (zipWith f b d)
        def Vector.dotProduct {R : Type u_1} {n : } [Zero R] [Add R] [Mul R] (a b : Vector R n) :
        R

        Inner product between two vectors of the same size. Should be faster than _root_.dotProduct due to efficient operations on Vectors.

        Instances For

          Inner product between two vectors of the same size. Should be faster than _root_.dotProduct due to efficient operations on Vectors.

          Instances For
            def Vector.accumulateProducts {R : Type u_1} {n : } {W : Type u_2} [Add W] (product : RRW) (init : W) (a b : Vector R n) :
            W

            Accumulate paired products from equal-length vectors, from left to right, starting at init. The products and accumulator lie in W; no reduction is performed.

            Instances For
              theorem Vector.reduce_accumulateProducts {R : Type u_1} {n : } {W : Type u_2} [AddZero W] [AddMonoid R] [Mul R] (reduce : W →+ R) (product : RRW) (hproduct : ∀ (x y : R), reduce (product x y) = x * y) (init : W) (a b : Vector R n) :
              reduce (accumulateProducts product init a b) = reduce init + a.dotProduct b

              If reduction preserves addition and each paired product, reducing the accumulator gives the reduced initial value plus the dot product of the input vectors.

              theorem Vector.reduce_accumulateProducts_zero {R : Type u_1} {n : } {W : Type u_2} [AddZero W] [AddMonoid R] [Mul R] (reduce : W →+ R) (product : RRW) (hproduct : ∀ (x y : R), reduce (product x y) = x * y) (a b : Vector R n) :
              reduce (accumulateProducts product 0 a b) = a.dotProduct b

              Reducing a product accumulator initialized at zero recovers the dot product.

              theorem Vector.accumulateProducts_mul {R : Type u_1} {n : } [AddMonoid R] [Mul R] (init : R) (a b : Vector R n) :
              accumulateProducts (fun (x1 x2 : R) => x1 * x2) init a b = init + a.dotProduct b

              Ordinary multiplication is an eager product accumulator, with identity reduction.

              @[simp]
              theorem Vector.dotProduct_cons {R : Type u_1} {n : } [AddCommMonoid R] [Mul R] (a : R) (b : Vector R n) (c : R) (d : Vector R n) :
              (cons a b).dotProduct (cons c d) = a * c + b.dotProduct d
              def Vector.Matrix (α : Type u_2) (m n : ) :
              Type u_2

              A matrix represented as iterated vectors in row-major order. m is the number of rows, and n is the number of columns

              Instances For
                def Vector.Matrix.mulVec {α : Type u_2} [Zero α] [Add α] [Mul α] {numRows numCols : } (M : Vector (Vector α numCols) numRows) (x : Vector α numCols) :
                Vector α numRows

                Matrix-vector multiplication over α. M is given as a vector of row-vectors.

                Instances For
                  def Vector.Matrix.ofFlatten {α : Type u_2} {m n : } (v : Vector α (m * n)) :
                  Matrix α m n

                  Convert a flat row-major vector of length m*n into an m × n row-major matrix represented as Vector (Vector α n) m.

                  Instances For
                    def Vector.Matrix.toFinMatrix {α : Type u_2} {m n : } (matrix : Matrix α m n) :
                    _root_.Matrix (Fin m) (Fin n) α

                    Convert to a Fin-indexed matrix (the definition in Mathlib): Fin m → Fin n → α

                    Instances For
                      def Vector.Matrix.ofFinMatrix {α : Type u_2} {m n : } (matrix : _root_.Matrix (Fin m) (Fin n) α) :
                      Matrix α m n

                      Convert from a Fin-indexed matrix (the definition in Mathlib): Fin m → Fin n → α

                      Instances For
                        def Vector.Matrix.transpose {α : Type u_2} {m n : } (matrix : Matrix α m n) :
                        Matrix α n m

                        Transpose a matrix by swapping rows and columns.

                        Instances For
                          @[simp]
                          theorem dotProduct_cons {R : Type u_1} [AddCommMonoid R] [Mul R] {n : } (a : R) (b : Vector R n) (c : R) (d : Vector R n) :
                          theorem Vector.dotProduct_eq_root_dotProduct {R : Type u_1} [AddCommMonoid R] [Mul R] {n : } (a b : Vector R n) :
                          theorem Vector.map_dotProduct {R : Type u_1} {S : Type u_2} [NonAssocSemiring R] [NonAssocSemiring S] (f : R →+* S) {n : } (a b : Vector R n) :
                          f (a.dotProduct b) = (map (⇑f) a).dotProduct (map (⇑f) b)

                          A ring homomorphism maps a dot product to the dot product of the mapped vectors.