Documentation

Hale.Containers.Data.Set

@[reducible, inline]
abbrev Data.Set' (k : Type u) [Ord k] :

An ordered finite set of elements of type k, backed by a red-black tree. $$\text{Set'}(k) \cong \text{RBMap}(k, \text{Unit}, \text{compare})$$ Provides $O(\log n)$ membership, insert, and delete. Named Set' to avoid clashing with Lean's Set (α → Prop).

Equations
Instances For
    @[inline]
    def Data.Set'.empty {k : Type u} [Ord k] :

    The empty set. $$\text{empty} = \emptyset$$

    Equations
    Instances For
      @[inline]
      def Data.Set'.singleton {k : Type u} [Ord k] (x : k) :

      A set with a single element. $$\text{singleton}(x) = \{x\}$$

      Equations
      Instances For
        def Data.Set'.fromList {k : Type u} [Ord k] (l : List k) :

        Build a set from a list of elements. $$\text{fromList}([x_1, \ldots, x_n]) = \{x_1, \ldots, x_n\}$$

        Equations
        Instances For
          @[inline]
          def Data.Set'.member {k : Type u} [Ord k] (x : k) (s : Set' k) :

          Test membership. $$\text{member}(x, s) \iff x \in s$$

          Equations
          Instances For
            @[inline]
            def Data.Set'.null {k : Type u} [Ord k] (s : Set' k) :

            Is the set empty? $$\text{null}(s) \iff s = \emptyset$$

            Equations
            Instances For
              @[inline]
              def Data.Set'.size' {k : Type u} [Ord k] (s : Set' k) :

              The number of elements. $$\text{size}(s) = |s|$$

              Equations
              Instances For
                @[inline]
                def Data.Set'.insert' {k : Type u} [Ord k] (x : k) (s : Set' k) :

                Insert an element. $$\text{insert}(x, s) = s \cup \{x\}$$

                Equations
                Instances For
                  @[inline]
                  def Data.Set'.delete {k : Type u} [Ord k] (x : k) (s : Set' k) :

                  Delete an element. $$\text{delete}(x, s) = s \setminus \{x\}$$

                  Equations
                  Instances For
                    def Data.Set'.union {k : Type u} [Ord k] (s1 s2 : Set' k) :

                    Union of two sets. $$\text{union}(s_1, s_2) = s_1 \cup s_2$$

                    Equations
                    Instances For
                      def Data.Set'.intersection {k : Type u} [Ord k] (s1 s2 : Set' k) :

                      Intersection of two sets. $$\text{intersection}(s_1, s_2) = s_1 \cap s_2$$

                      Equations
                      Instances For
                        def Data.Set'.difference {k : Type u} [Ord k] (s1 s2 : Set' k) :

                        Difference of two sets. $$\text{difference}(s_1, s_2) = s_1 \setminus s_2$$

                        Equations
                        Instances For
                          def Data.Set'.isSubsetOf {k : Type u} [Ord k] (s1 s2 : Set' k) :

                          Is s1 a subset of s2? $$\text{isSubsetOf}(s_1, s_2) \iff s_1 \subseteq s_2$$

                          Equations
                          Instances For
                            def Data.Set'.mapSet {k : Type u} [Ord k] {k₂ : Type u_1} [Ord k₂] (f : kk₂) (s : Set' k) :
                            Set' k₂

                            Map a function over all elements. The result may be smaller if f maps distinct elements to the same value. $$\text{map}(f, s) = \{f(x) \mid x \in s\}$$

                            Equations
                            Instances For
                              def Data.Set'.filter {k : Type u} [Ord k] (p : kBool) (s : Set' k) :

                              Filter elements satisfying a predicate. $$\text{filter}(p, s) = \{x \in s \mid p(x)\}$$

                              Equations
                              Instances For
                                @[inline]
                                def Data.Set'.foldl {k : Type u} [Ord k] {α : Type u_1} (f : αkα) (init : α) (s : Set' k) :
                                α

                                Left fold over elements in ascending order. $$\text{foldl}(f, z, s) = f(\ldots f(f(z, x_1), x_2) \ldots, x_n)$$

                                Equations
                                Instances For
                                  @[inline]
                                  def Data.Set'.foldr {k : Type u} [Ord k] {α : Type u_1} (f : kαα) (init : α) (s : Set' k) :
                                  α

                                  Right fold over elements in ascending order. $$\text{foldr}(f, z, s) = f(x_1, f(x_2, \ldots f(x_n, z)))$$

                                  Equations
                                  Instances For
                                    def Data.Set'.toList' {k : Type u} [Ord k] (s : Set' k) :

                                    Convert the set to a list in ascending order. $$\text{toList}(s) = [x_1, \ldots, x_n]$$ where $x_1 < \cdots < x_n$.

                                    Equations
                                    Instances For
                                      @[inline]
                                      def Data.Set'.toAscList {k : Type u} [Ord k] (s : Set' k) :

                                      Convert the set to an ascending list (same as toList' for an ordered set). $$\text{toAscList} = \text{toList'}$$

                                      Equations
                                      Instances For
                                        def Data.Set'.findMin {k : Type u} [Ord k] (s : Set' k) :

                                        The smallest element, or none if the set is empty. $$\text{findMin}(s) = \min(s)$$

                                        Equations
                                        Instances For
                                          def Data.Set'.findMax {k : Type u} [Ord k] (s : Set' k) :

                                          The largest element, or none if the set is empty. $$\text{findMax}(s) = \max(s)$$

                                          Equations
                                          Instances For
                                            @[implicit_reducible]
                                            Equations
                                            @[implicit_reducible]
                                            instance Data.Set'.instInhabited {k : Type u} [Ord k] :
                                            Equations
                                            @[implicit_reducible]
                                            instance Data.Set'.instRepr {k : Type u} [Ord k] [Repr k] :
                                            Equations
                                            • One or more equations did not get rendered due to their size.
                                            @[implicit_reducible]
                                            instance Data.Set'.instBEq {k : Type u} [Ord k] [BEq k] :
                                            BEq (Set' k)
                                            Equations

                                            The empty set has no elements. $$\text{null}(\emptyset) = \text{true}$$

                                            theorem Data.Set'.member_empty {k : Type u} [Ord k] (x : k) :

                                            Membership in the empty set is always false. $$\text{member}(x, \emptyset) = \text{false}$$

                                            theorem Data.Set'.size_empty {k : Type u} [Ord k] :

                                            The empty set has size zero. $$\text{size'}(\emptyset) = 0$$

                                            theorem Data.Set'.null_singleton {k : Type u} [Ord k] (x : k) :

                                            A singleton set is not null. $$\text{null}(\text{singleton}(x)) = \text{false}$$