Documentation

Hale.Vector.Data.Vector

@[reducible, inline]
abbrev Data.Vector (α : Type u) :

Boxed vector type. Lean's Array is already the equivalent of Haskell's Vector. $$\text{Vector}\ \alpha := \text{Array}\ \alpha$$

Equations
Instances For
    @[inline]
    def Data.Vector.empty {α : Type u_1} :

    The empty vector. $$\text{empty} : \text{Vector}\ \alpha,\quad |\text{empty}| = 0$$

    Equations
    Instances For
      @[inline]
      def Data.Vector.singleton {α : Type u_1} (x : α) :

      A vector containing a single element. $$\text{singleton}(x) = [x]$$

      Equations
      Instances For
        @[inline]
        def Data.Vector.fromList {α : Type u_1} (xs : List α) :

        Convert a list to a vector. $$\text{fromList}([x_1, \ldots, x_n]) = [x_1, \ldots, x_n]$$

        Equations
        Instances For
          @[inline]
          def Data.Vector.toList {α : Type u_1} (v : Vector α) :
          List α

          Convert a vector to a list. $$\text{toList}([x_1, \ldots, x_n]) = [x_1, \ldots, x_n]$$

          Equations
          Instances For
            @[inline]
            def Data.Vector.replicate {α : Type u_1} (n : Nat) (x : α) :

            Create a vector of n copies of element x. $$\text{replicate}(n, x) = [x, x, \ldots, x],\quad |\text{result}| = n$$

            Equations
            Instances For
              def Data.Vector.generate {α : Type u_1} (n : Nat) (f : Natα) :

              Create a vector of length n by applying f to each index. $$\text{generate}(n, f) = [f(0), f(1), \ldots, f(n-1)]$$

              Equations
              Instances For
                def Data.Vector.generate.go {α : Type u_1} (f : Natα) :
                NatNatVector αVector α
                Equations
                Instances For
                  @[inline]
                  def Data.Vector.length {α : Type u_1} (v : Vector α) :

                  The number of elements. $$\text{length}(v) = |v|$$

                  Equations
                  Instances For
                    @[inline]
                    def Data.Vector.null {α : Type u_1} (v : Vector α) :

                    Is the vector empty? $$\text{null}(v) \iff |v| = 0$$

                    Equations
                    Instances For
                      @[inline]
                      def Data.Vector.getOp {α : Type u_1} (v : Vector α) (i : Nat) :

                      Index into the vector. Returns none if out of bounds. $$v\text{!}(i) = v_i$$

                      Equations
                      Instances For
                        def Data.Vector.head {α : Type u_1} (v : Vector α) (h : Array.size v > 0 := by omega) :
                        α

                        The first element of a non-empty vector. $$\text{head}(v) = v_0,\quad \text{requires } |v| > 0$$

                        Equations
                        Instances For
                          def Data.Vector.last {α : Type u_1} (v : Vector α) (h : Array.size v > 0 := by omega) :
                          α

                          The last element of a non-empty vector. $$\text{last}(v) = v_{|v|-1},\quad \text{requires } |v| > 0$$

                          Equations
                          Instances For
                            def Data.Vector.slice {α : Type u_1} (i n : Nat) (v : Vector α) :

                            Extract a slice from index i of length n. $$\text{slice}(i, n, v) = [v_i, v_{i+1}, \ldots, v_{i+n-1}]$$

                            Equations
                            Instances For
                              def Data.Vector.init {α : Type u_1} (v : Vector α) :

                              All elements except the last. $$\text{init}(v) = v[0..|v|-1],\quad \text{requires } |v| > 0$$

                              Equations
                              Instances For
                                def Data.Vector.tail {α : Type u_1} (v : Vector α) :

                                All elements except the first. $$\text{tail}(v) = v[1..],\quad \text{requires } |v| > 0$$

                                Equations
                                Instances For
                                  @[inline]
                                  def Data.Vector.take {α : Type u_1} (n : Nat) (v : Vector α) :

                                  Take the first n elements. $$\text{take}(n, v) = v[0..n]$$

                                  Equations
                                  Instances For
                                    @[inline]
                                    def Data.Vector.drop {α : Type u_1} (n : Nat) (v : Vector α) :

                                    Drop the first n elements. $$\text{drop}(n, v) = v[n..]$$

                                    Equations
                                    Instances For
                                      @[inline]
                                      def Data.Vector.map {α : Type u_1} {β : Type u_2} (f : αβ) (v : Vector α) :

                                      Apply a function to every element. $$\text{map}(f, [x_1, \ldots, x_n]) = [f(x_1), \ldots, f(x_n)]$$

                                      Equations
                                      Instances For
                                        def Data.Vector.imap {α : Type u_1} {β : Type u_2} (f : Natαβ) (v : Vector α) :

                                        Map with index. $$\text{imap}(f, [x_0, \ldots, x_{n-1}]) = [f(0, x_0), \ldots, f(n-1, x_{n-1})]$$

                                        Equations
                                        Instances For
                                          @[irreducible]
                                          def Data.Vector.imap.go {α : Type u_1} {β : Type u_2} (f : Natαβ) (v : Vector α) (i : Nat) (acc : Array β) :
                                          Equations
                                          Instances For
                                            def Data.Vector.concatMap {α : Type u_1} {β : Type u_2} (f : αVector β) (v : Vector α) :

                                            Map and concatenate. $$\text{concatMap}(f, v) = \text{concat}(\text{map}(f, v))$$

                                            Equations
                                            Instances For
                                              @[inline]
                                              def Data.Vector.filter {α : Type u_1} (p : αBool) (v : Vector α) :

                                              Keep elements satisfying a predicate. $$\text{filter}(p, v) = [x \in v \mid p(x)]$$

                                              Equations
                                              Instances For
                                                def Data.Vector.ifilter {α : Type u_1} (p : NatαBool) (v : Vector α) :

                                                Filter with index. $$\text{ifilter}(p, v) = [v_i \mid p(i, v_i)]$$

                                                Equations
                                                Instances For
                                                  @[irreducible]
                                                  def Data.Vector.ifilter.go {α : Type u_1} (p : NatαBool) (v : Vector α) (i : Nat) (acc : Array α) :
                                                  Equations
                                                  Instances For
                                                    @[inline]
                                                    def Data.Vector.foldl' {β : Type u_1} {α : Type u_2} (f : βαβ) (z : β) (v : Vector α) :
                                                    β

                                                    Strict left fold. $$\text{foldl'}(f, z, [x_1, \ldots, x_n]) = f(\ldots f(f(z, x_1), x_2) \ldots, x_n)$$

                                                    Equations
                                                    Instances For
                                                      def Data.Vector.foldl1' {α : Type u_1} (f : ααα) (v : Vector α) (h : Array.size v > 0 := by omega) :
                                                      α

                                                      Strict left fold on non-empty vector using first element as seed. $$\text{foldl1'}(f, [x_1, \ldots, x_n]) = f(\ldots f(x_1, x_2) \ldots, x_n)$$

                                                      Equations
                                                      Instances For
                                                        @[irreducible]
                                                        def Data.Vector.foldl1'.go {α : Type u_1} (f : ααα) (v : Vector α) (i : Nat) (acc : α) :
                                                        α
                                                        Equations
                                                        Instances For
                                                          @[inline]
                                                          def Data.Vector.foldr {α : Type u_1} {β : Type u_2} (f : αββ) (z : β) (v : Vector α) :
                                                          β

                                                          Right fold. $$\text{foldr}(f, z, [x_1, \ldots, x_n]) = f(x_1, f(x_2, \ldots f(x_n, z)))$$

                                                          Equations
                                                          Instances For
                                                            def Data.Vector.foldr1 {α : Type u_1} (f : ααα) (v : Vector α) (h : Array.size v > 0 := by omega) :
                                                            α

                                                            Right fold on non-empty vector using last element as seed. $$\text{foldr1}(f, [x_1, \ldots, x_n]) = f(x_1, f(x_2, \ldots f(x_{n-1}, x_n)))$$

                                                            Equations
                                                            Instances For
                                                              def Data.Vector.foldr1.go {α : Type u_1} (f : ααα) (v : Vector α) :
                                                              Natαα
                                                              Equations
                                                              Instances For
                                                                def Data.Vector.ifoldl' {β : Sort u_1} {α : Type u_2} (f : βNatαβ) (z : β) (v : Vector α) :
                                                                β

                                                                Strict left fold with index. $$\text{ifoldl'}(f, z, v) = f(\ldots f(f(z, 0, v_0), 1, v_1) \ldots, n-1, v_{n-1})$$

                                                                Equations
                                                                Instances For
                                                                  @[irreducible]
                                                                  def Data.Vector.ifoldl'.go {β : Sort u_1} {α : Type u_2} (f : βNatαβ) (v : Vector α) (i : Nat) (acc : β) :
                                                                  β
                                                                  Equations
                                                                  Instances For
                                                                    def Data.Vector.ifoldr {α : Type u_1} {β : Sort u_2} (f : Natαββ) (z : β) (v : Vector α) :
                                                                    β

                                                                    Right fold with index. $$\text{ifoldr}(f, z, v) = f(0, v_0, f(1, v_1, \ldots f(n-1, v_{n-1}, z)))$$

                                                                    Equations
                                                                    Instances For
                                                                      def Data.Vector.ifoldr.go {α : Type u_1} {β : Sort u_2} (f : Natαββ) (v : Vector α) :
                                                                      Natββ
                                                                      Equations
                                                                      Instances For
                                                                        @[inline]
                                                                        def Data.Vector.all {α : Type u_1} (p : αBool) (v : Vector α) :

                                                                        Do all elements satisfy the predicate? $$\text{all}(p, v) = \forall x \in v.\; p(x)$$

                                                                        Equations
                                                                        Instances For
                                                                          @[inline]
                                                                          def Data.Vector.any {α : Type u_1} (p : αBool) (v : Vector α) :

                                                                          Does any element satisfy the predicate? $$\text{any}(p, v) = \exists x \in v.\; p(x)$$

                                                                          Equations
                                                                          Instances For

                                                                            Are all elements true? $$\text{and}(v) = \bigwedge v$$

                                                                            Equations
                                                                            Instances For

                                                                              Is any element true? $$\text{or}(v) = \bigvee v$$

                                                                              Equations
                                                                              Instances For
                                                                                def Data.Vector.sum {α : Type u_1} [Add α] [OfNat α 0] (v : Vector α) :
                                                                                α

                                                                                Sum of all elements. $$\text{sum}(v) = \sum v$$

                                                                                Equations
                                                                                Instances For
                                                                                  def Data.Vector.product {α : Type u_1} [Mul α] [OfNat α 1] (v : Vector α) :
                                                                                  α

                                                                                  Product of all elements. $$\text{product}(v) = \prod v$$

                                                                                  Equations
                                                                                  Instances For
                                                                                    def Data.Vector.maximum {α : Type u_1} [Ord α] (v : Vector α) (h : Array.size v > 0 := by omega) :
                                                                                    α

                                                                                    Maximum element of a non-empty vector. $$\text{maximum}(v) = \max(v),\quad \text{requires } |v| > 0$$

                                                                                    Equations
                                                                                    Instances For
                                                                                      @[irreducible]
                                                                                      def Data.Vector.maximum.go {α : Type u_1} [Ord α] (v : Vector α) (i : Nat) (best : α) :
                                                                                      α
                                                                                      Equations
                                                                                      Instances For
                                                                                        def Data.Vector.minimum {α : Type u_1} [Ord α] (v : Vector α) (h : Array.size v > 0 := by omega) :
                                                                                        α

                                                                                        Minimum element of a non-empty vector. $$\text{minimum}(v) = \min(v),\quad \text{requires } |v| > 0$$

                                                                                        Equations
                                                                                        Instances For
                                                                                          @[irreducible]
                                                                                          def Data.Vector.minimum.go {α : Type u_1} [Ord α] (v : Vector α) (i : Nat) (best : α) :
                                                                                          α
                                                                                          Equations
                                                                                          Instances For
                                                                                            def Data.Vector.elem {α : Type u_1} [BEq α] (x : α) (v : Vector α) :

                                                                                            Does the element occur in the vector? $$\text{elem}(x, v) = \exists i.\; v_i = x$$

                                                                                            Equations
                                                                                            Instances For
                                                                                              def Data.Vector.notElem {α : Type u_1} [BEq α] (x : α) (v : Vector α) :

                                                                                              Does the element NOT occur in the vector? $$\text{notElem}(x, v) = \neg\text{elem}(x, v)$$

                                                                                              Equations
                                                                                              Instances For
                                                                                                def Data.Vector.find {α : Type u_1} (p : αBool) (v : Vector α) :

                                                                                                Find the first element satisfying a predicate. $$\text{find}(p, v)$$

                                                                                                Equations
                                                                                                Instances For
                                                                                                  @[irreducible]
                                                                                                  def Data.Vector.find.go {α : Type u_1} (p : αBool) (v : Vector α) (i : Nat) :
                                                                                                  Equations
                                                                                                  Instances For
                                                                                                    def Data.Vector.findIndex {α : Type u_1} (p : αBool) (v : Vector α) :

                                                                                                    Find the index of the first element satisfying a predicate. $$\text{findIndex}(p, v)$$

                                                                                                    Equations
                                                                                                    Instances For
                                                                                                      @[irreducible]
                                                                                                      def Data.Vector.findIndex.go {α : Type u_1} (p : αBool) (v : Vector α) (i : Nat) :
                                                                                                      Equations
                                                                                                      Instances For
                                                                                                        def Data.Vector.zip {α : Type u_1} {β : Type u_2} (u : Vector α) (v : Vector β) :
                                                                                                        Vector (α × β)

                                                                                                        Zip two vectors into a vector of pairs. $$\text{zip}(u, v) = [(u_0, v_0), (u_1, v_1), \ldots]$$

                                                                                                        Equations
                                                                                                        Instances For
                                                                                                          def Data.Vector.zipWith {α : Type u_1} {β : Type u_2} {γ : Type u_3} (f : αβγ) (u : Vector α) (v : Vector β) :

                                                                                                          Zip two vectors with a combining function. $$\text{zipWith}(f, u, v) = [f(u_0, v_0), f(u_1, v_1), \ldots]$$

                                                                                                          Equations
                                                                                                          Instances For
                                                                                                            def Data.Vector.unzip {α : Type u_1} {β : Type u_2} (v : Vector (α × β)) :

                                                                                                            Unzip a vector of pairs into a pair of vectors. $$\text{unzip}([(a_1, b_1), \ldots]) = ([a_1, \ldots], [b_1, \ldots])$$

                                                                                                            Equations
                                                                                                            Instances For
                                                                                                              @[inline]
                                                                                                              def Data.Vector.reverse {α : Type u_1} (v : Vector α) :

                                                                                                              Reverse the elements. $$\text{reverse}([x_1, \ldots, x_n]) = [x_n, \ldots, x_1]$$

                                                                                                              Equations
                                                                                                              Instances For
                                                                                                                def Data.Vector.backpermute {α : Type u_1} [Inhabited α] (v : Vector α) (is : Vector Nat) :

                                                                                                                Permute elements according to an index vector. $$\text{backpermute}(v, is) = [v_{is_0}, v_{is_1}, \ldots]$$ Out-of-bounds indices produce a default value.

                                                                                                                Equations
                                                                                                                Instances For
                                                                                                                  def Data.Vector.modify {α : Type u_1} (f : αα) (i : Nat) (v : Vector α) :

                                                                                                                  Modify the element at index i by applying f. $$\text{modify}(f, i, v)$$ returns $v$ with $v_i$ replaced by $f(v_i)$. If i is out of bounds, returns v unchanged.

                                                                                                                  Equations
                                                                                                                  Instances For
                                                                                                                    @[inline]
                                                                                                                    def Data.Vector.snoc {α : Type u_1} (v : Vector α) (x : α) :

                                                                                                                    Append an element to the end. $$\text{snoc}(v, x) = [v_0, \ldots, v_{n-1}, x]$$

                                                                                                                    Equations
                                                                                                                    Instances For
                                                                                                                      def Data.Vector.cons {α : Type u_1} (x : α) (v : Vector α) :

                                                                                                                      Prepend an element to the front. $$\text{cons}(x, v) = [x, v_0, \ldots, v_{n-1}]$$

                                                                                                                      Equations
                                                                                                                      Instances For
                                                                                                                        theorem Data.Vector.toList_fromList {α : Type u_1} (xs : List α) :
                                                                                                                        (fromList xs).toList = xs

                                                                                                                        fromList and toList are inverses. $$\text{toList}(\text{fromList}(xs)) = xs$$

                                                                                                                        length of empty is zero. $$\text{length}(\text{empty}) = 0$$

                                                                                                                        theorem Data.Vector.length_singleton {α : Type u_1} (x : α) :

                                                                                                                        length of singleton is one. $$\text{length}(\text{singleton}(x)) = 1$$

                                                                                                                        null of empty is true. $$\text{null}(\text{empty}) = \text{true}$$

                                                                                                                        theorem Data.Vector.null_singleton {α : Type u_1} (x : α) :

                                                                                                                        null of singleton is false. $$\text{null}(\text{singleton}(x)) = \text{false}$$

                                                                                                                        theorem Data.Vector.length_fromList {α : Type u_1} (xs : List α) :

                                                                                                                        fromList preserves length. $$\text{length}(\text{fromList}(xs)) = \text{List.length}(xs)$$

                                                                                                                        theorem Data.Vector.length_reverse {α : Type u_1} (v : Vector α) :

                                                                                                                        reverse preserves length. $$\text{length}(\text{reverse}(v)) = \text{length}(v)$$

                                                                                                                        theorem Data.Vector.length_map {α : Type u_1} {β : Type u_2} (f : αβ) (v : Vector α) :
                                                                                                                        (map f v).length = v.length

                                                                                                                        map preserves length. $$\text{length}(\text{map}(f, v)) = \text{length}(v)$$

                                                                                                                        theorem Data.Vector.reverse_reverse {α : Type u_1} (v : Vector α) :

                                                                                                                        reverse is an involution. $$\text{reverse}(\text{reverse}(v)) = v$$