Documentation

Init.Data.Range.Polymorphic.UpwardEnumerable

This typeclass provides the function succ? : α → Option α that computes the successor of elements of α, or none if no successor exists. It also provides the function succMany?, which computes n-th successors.

succ? is expected to be acyclic: No element is its own transitive successor. If α is ordered, then every element larger than a : α should be a transitive successor of a. These properties and the compatibility of succ? with succMany? are encoded in the typeclasses LawfulUpwardEnumerable, LawfulUpwardEnumerableLE and LawfulUpwardEnumerableLT.

  • succ? : αOption α

    Maps elements of α to their successor, or none if no successor exists.

  • succMany? (n : Nat) (a : α) : Option α

    Maps elements of α to their n-th successor, or none if no successor exists. This should semantically behave like repeatedly applying succ?, but it might be more efficient.

    LawfulUpwardEnumerable ensures the compatibility with succ?.

    If no other implementation is provided in UpwardEnumerable instance, succMany? repeatedly applies succ?.

Instances
    theorem Std.PRange.UpwardEnumerable.ext {α : Type u} {x y : UpwardEnumerable α} (succ? : succ? = succ?) (succMany? : succMany? = succMany?) :
    x = y

    According to UpwardEnumerable.LE, a is less than or equal to b if b is a or a transitive successor of a.

    Equations
      Instances For

        According to UpwardEnumerable.LT, a is less than b if b is a proper transitive successor of a. 'Proper' means that b is the n-th successor of a, where n > 0.

        Given LawfulUpwardEnumerable α, no element of α is less than itself.

        Equations
          Instances For
            class Std.PRange.Least? (α : Type u) :

            The typeclass Least? α optionally provides a smallest element of α, least? : Option α.

            The main use case of this typeclass is to use it in combination with UpwardEnumerable to obtain a (possibly infinite) ascending enumeration of all elements of α.

            • least? : Option α

              Returns the smallest element of α, or none if α is empty.

              Only empty types are allowed to define least? := none. If α is ordered and nonempty, then the value of least? should be the smallest element according to the order on α.

            Instances

              This typeclass ensures that an UpwardEnumerable α instance is well-behaved.

              • ne_of_lt (a b : α) : UpwardEnumerable.LT a ba b

                There is no cyclic chain of successors.

              • succMany?_zero (a : α) : succMany? 0 a = some a

                The 0-th successor of a is a itself.

              • succMany?_add_one (n : Nat) (a : α) : succMany? (n + 1) a = (succMany? n a).bind succ?

                The n + 1-th successor of a is the successor of the n-th successor, given that said successors actually exist.

              Instances
                @[deprecated Std.PRange.UpwardEnumerable.succMany?_add_one (since := "2025-09-03")]
                @[deprecated Std.PRange.UpwardEnumerable.succMany?_add_one (since := "2025-09-03")]
                theorem Std.PRange.UpwardEnumerable.succMany?_add {α : Type u_1} [UpwardEnumerable α] [LawfulUpwardEnumerable α] {m n : Nat} {a : α} :
                succMany? (m + n) a = (succMany? m a).bind fun (x : α) => succMany? n x
                @[deprecated Std.PRange.UpwardEnumerable.succMany?_add_one_eq_succ?_bind_succMany? (since := "2025-09-03")]
                @[deprecated Std.PRange.UpwardEnumerable.succMany?_add_one_eq_succ?_bind_succMany? (since := "2025-09-03")]

                This propositional typeclass ensures that UpwardEnumerable.succ? will never return none. In other words, it ensures that there will always be a successor.

                Instances

                  This propositional typeclass ensures that UpwardEnumerable.succ? is injective.

                  Instances

                    If a type is infinitely upwardly enumerable, then every element has a successor.

                    @[deprecated Std.PRange.UpwardEnumerable.succ?_inj (since := "2025-09-03")]
                    @[reducible, inline]

                    Maps elements of α to their immediate successor.

                    Equations
                      Instances For
                        @[deprecated Std.PRange.UpwardEnumerable.succ_inj (since := "2025-09-03")]
                        @[inline]

                        Maps elements of α to their n-th successor. This should semantically behave like repeatedly applying succ, but it might be more efficient.

                        This function uses an UpwardEnumerable α instance. LawfulUpwardEnumerable α ensures the compatibility with succ and succ?.

                        If no other implementation is provided in UpwardEnumerable instance, succMany? repeatedly applies succ?.

                        Equations
                          Instances For

                            This typeclass ensures that an UpwardEnumerable α instance is compatible with . In this case, UpwardEnumerable α fully characterizes the LE α instance.

                            • le_iff (a b : α) : a b UpwardEnumerable.LE a b

                              a is less than or equal to b if and only if b is either a or a transitive successor of a.

                            Instances
                              def Std.PRange.UpwardEnumerable.instLETransOfLawfulUpwardEnumerableLE {α : Type u} [LE α] [UpwardEnumerable α] [LawfulUpwardEnumerable α] [LawfulUpwardEnumerableLE α] :
                              Trans (fun (x1 x2 : α) => x1 x2) (fun (x1 x2 : α) => x1 x2) fun (x1 x2 : α) => x1 x2
                              Equations
                                Instances For

                                  This typeclass ensures that an UpwardEnumerable α instance is compatible with <. In this case, UpwardEnumerable α fully characterizes the LT α instance.

                                  • lt_iff (a b : α) : a < b UpwardEnumerable.LT a b

                                    a is less than b if and only if b is a proper transitive successor of a.

                                  Instances
                                    def Std.PRange.UpwardEnumerable.instLTTransOfLawfulUpwardEnumerableLT {α : Type u} [LT α] [UpwardEnumerable α] [LawfulUpwardEnumerable α] [LawfulUpwardEnumerableLT α] :
                                    Trans (fun (x1 x2 : α) => x1 < x2) (fun (x1 x2 : α) => x1 < x2) fun (x1 x2 : α) => x1 < x2
                                    Equations
                                      Instances For

                                        This typeclass ensures that an UpwardEnumerable α instance is compatible with a Least? α instance. For nonempty α, it ensures that least? has a value and that every other value is a transitive successor of it.

                                        Instances
                                          Equations
                                            Instances For