LaPToP Blueprint

4. Data Structures🔗

Definition4.1
Group: Data structures as they appear in LaPToP: lists/strings, functions as data, and related theories used when specifying programs that manipulate structure. The string and list material is Hehner's Sections 2.2 and 2.3; the formal counterparts are the Lean modules LaPToP.DataStructures.Strings and LaPToP.DataStructures.Lists . (11)
Group member previews
Preview
Theorem 4.2
Loading preview
Group member preview content is loaded from the rendered-fragment cache.
uses 0
Used by 5
Reverse dependency previews
Preview
Theorem 4.2
Loading preview
Reverse dependency preview content is loaded from the rendered-fragment cache.
L∃∀N

Hehner treats finite sequences uniformly (often called strings or lists). Concatenation, length, and indexing are the primitive operations; many program specifications are expressed directly in this theory.

"Bunches are uncontained collections and sets are contained collections. Similarly, strings are uncontained sequences and lists are contained sequences." A string of items of type \alpha is modelled as a Lean List α (Str α): \mathit{nil} is [], a one-item string i is [i], join S; T is S ++ T, and the length \leftrightarrow S is Str.len S, valued in the extended naturals like the book's. Only finite strings are modelled, so the book's provisos \leftrightarrow S < \infty hold automatically.

Lean code for Definition4.14 definitions
  • complete
    abbrev LaPToP.DataStructures.Str.{u} (α : Type u) : Type u
    abbrev LaPToP.DataStructures.Str.{u}
      (α : Type u) : Type u
    A *string* of items of type `α` (aPToP §2.2), modelled as a list. 
  • complete
    abbrev LaPToP.DataStructures.Str.nil.{u} {α : Type u} :
      LaPToP.DataStructures.Str α
    abbrev LaPToP.DataStructures.Str.nil.{u}
      {α : Type u} :
      LaPToP.DataStructures.Str α
    `nil`, the empty string. 
  • complete
    abbrev LaPToP.DataStructures.Str.item.{u} {α : Type u} (i : α) :
      LaPToP.DataStructures.Str α
    abbrev LaPToP.DataStructures.Str.item.{u}
      {α : Type u} (i : α) :
      LaPToP.DataStructures.Str α
    The one-item string consisting of the item `i`; the book writes it just `i`. 
  • complete
    def LaPToP.DataStructures.Str.len.{u} {α : Type u}
      (S : LaPToP.DataStructures.Str α) : ℕ∞
    def LaPToP.DataStructures.Str.len.{u}
      {α : Type u}
      (S : LaPToP.DataStructures.Str α) : ℕ∞
    `↔S`, the length of a string, as an extended natural number (the book's
    lengths live in `xnat`). 
Theorem4.2
Group: Data structures as they appear in LaPToP: lists/strings, functions as data, and related theories used when specifying programs that manipulate structure. The string and list material is Hehner's Sections 2.2 and 2.3; the formal counterparts are the Lean modules LaPToP.DataStructures.Strings and LaPToP.DataStructures.Lists . (11)
Group member previews
Preview
Definition 4.1
Loading preview
Group member preview content is loaded from the rendered-fragment cache.
uses 1used by 1L∃∀N

Appending the empty list on the right is an identity: xs \mathbin{+\hspace{-0.4em}+} [\,] = xs. This is the first identity for Definition 4.1.

Lean code for Theorem4.21 theorem
  • complete
    theorem LaPToP.DataStructures.Str.append_nil.{u} {α : Type u}
      (S : LaPToP.DataStructures.Str α) :
      S ++ LaPToP.DataStructures.Str.nil = S
    theorem LaPToP.DataStructures.Str.append_nil.{u}
      {α : Type u}
      (S : LaPToP.DataStructures.Str α) :
      S ++ LaPToP.DataStructures.Str.nil = S
    `S; nil = S` (identity, left equation). 
Proof for Theorem 4.2
uses 0

By the definition of list append / List.concat.

Lean code for Theorem4.2theorem list_append_nil (xs : List α) : xs ++ ([] : List α) = xs := α:Type u_1xs:List αxs ++ [] = xs All goals completed! 🐙
Definition4.3
Group: Data structures as they appear in LaPToP: lists/strings, functions as data, and related theories used when specifying programs that manipulate structure. The string and list material is Hehner's Sections 2.2 and 2.3; the formal counterparts are the Lean modules LaPToP.DataStructures.Strings and LaPToP.DataStructures.Lists . (11)
Group member previews
Preview
Definition 4.1
Loading preview
Group member preview content is loaded from the rendered-fragment cache.
uses 1
Used by 4
Reverse dependency previews
Preview
Theorem 4.5
Loading preview
Reverse dependency preview content is loaded from the rendered-fragment cache.
L∃∀N

The syntax of strings beyond join and length: S\,n is item n of S (indexing from 0: "the index of an item is the number of items that precede it"); S\,T for a string of indexes T selects a whole string of items, as in (3; 5; 7; 9)\,(2; 1; 2) = 7; 5; 7; n*S is n copies of S joined together; *S is the bunch of all such copies; S \triangleleft n \triangleright i ("S but at n is i") replaces the item at index n; and x;..y is the string x; x+1; \ldots; y-1. The book leaves S\,n unspecified for an index out of range; the Lean model returns default there. Extends Definition 4.1.

Lean code for Definition4.36 definitions
  • complete
    def LaPToP.DataStructures.Str.at.{u} {α : Type u} [Inhabited α]
      (S : LaPToP.DataStructures.Str α) (n : ) : α
    def LaPToP.DataStructures.Str.at.{u}
      {α : Type u} [Inhabited α]
      (S : LaPToP.DataStructures.Str α)
      (n : ) : α
    `S n`, item `n` of `S`; indexes count the items that precede an item, so
    they start at `0`. Out of range the book leaves the value unspecified; we
    return `default`. 
  • complete
    def LaPToP.DataStructures.Str.sub.{u} {α : Type u} [Inhabited α]
      (S : LaPToP.DataStructures.Str α) (T : LaPToP.DataStructures.Str ) :
      LaPToP.DataStructures.Str α
    def LaPToP.DataStructures.Str.sub.{u}
      {α : Type u} [Inhabited α]
      (S : LaPToP.DataStructures.Str α)
      (T : LaPToP.DataStructures.Str ) :
      LaPToP.DataStructures.Str α
    `S T` for a string of indexes `T`: the string of the items of `S` at those
    indexes, e.g. `(3; 5; 7; 9) (2; 1; 2) = 7; 5; 7`. 
  • complete
    def LaPToP.DataStructures.Str.copies.{u} {α : Type u} (n : )
      (S : LaPToP.DataStructures.Str α) : LaPToP.DataStructures.Str α
    def LaPToP.DataStructures.Str.copies.{u}
      {α : Type u} (n : )
      (S : LaPToP.DataStructures.Str α) :
      LaPToP.DataStructures.Str α
    `n*S`, `n` copies of `S` joined together, e.g. `3*(0; 1) = 0; 1; 0; 1; 0; 1`. 
  • complete
    def LaPToP.DataStructures.Str.star.{u} {α : Type u}
      (S : LaPToP.DataStructures.Str α) : Set (LaPToP.DataStructures.Str α)
    def LaPToP.DataStructures.Str.star.{u}
      {α : Type u}
      (S : LaPToP.DataStructures.Str α) :
      Set (LaPToP.DataStructures.Str α)
    `*S`, the bunch of all strings formed by joining any number of copies of
    `S`: `*(0; 1) = nil, 0;1, 0;1;0;1, ...`. 
  • complete
    def LaPToP.DataStructures.Str.update.{u} {α : Type u}
      (S : LaPToP.DataStructures.Str α) (n : ) (i : α) :
      LaPToP.DataStructures.Str α
    def LaPToP.DataStructures.Str.update.{u}
      {α : Type u}
      (S : LaPToP.DataStructures.Str α)
      (n : ) (i : α) :
      LaPToP.DataStructures.Str α
    `S⊲n⊳i`, "`S` but at `n` is `i`": the string like `S` except that the item
    at index `n` is `i`. 
  • complete
    def LaPToP.DataStructures.Str.interval (x y : ) :
      LaPToP.DataStructures.Str 
    def LaPToP.DataStructures.Str.interval
      (x y : ) : LaPToP.DataStructures.Str 
    `x;..y`, "`x` to `y`": the string `x; x+1; ...; y-1` (empty unless `x < y`). 
Theorem4.4
Group: Data structures as they appear in LaPToP: lists/strings, functions as data, and related theories used when specifying programs that manipulate structure. The string and list material is Hehner's Sections 2.2 and 2.3; the formal counterparts are the Lean modules LaPToP.DataStructures.Strings and LaPToP.DataStructures.Lists . (11)
Group member previews
Preview
Definition 4.1
Loading preview
Group member preview content is loaded from the rendered-fragment cache.
Statement uses 2
Statement dependency previews
Preview
Definition 4.1
Loading preview
Statement dependency preview content is loaded from the rendered-fragment cache.
used by 0L∃∀N

The join and length axioms of String Theory: S; \mathit{nil} = S = \mathit{nil}; S (identity), S; (T; U) = (S; T); U (associativity), \leftrightarrow\mathit{nil} = 0 and \leftrightarrow i = 1 (base), \leftrightarrow(S; T) = \leftrightarrow S + \leftrightarrow T, and (i = j) = (S; i; T = S; j; T). Uses Definition 4.1; the first identity is Theorem 4.2.

Lean code for Theorem4.47 theorems
  • complete
    theorem LaPToP.DataStructures.Str.append_nil.{u} {α : Type u}
      (S : LaPToP.DataStructures.Str α) :
      S ++ LaPToP.DataStructures.Str.nil = S
    theorem LaPToP.DataStructures.Str.append_nil.{u}
      {α : Type u}
      (S : LaPToP.DataStructures.Str α) :
      S ++ LaPToP.DataStructures.Str.nil = S
    `S; nil = S` (identity, left equation). 
  • complete
    theorem LaPToP.DataStructures.Str.nil_append.{u} {α : Type u}
      (S : LaPToP.DataStructures.Str α) :
      LaPToP.DataStructures.Str.nil ++ S = S
    theorem LaPToP.DataStructures.Str.nil_append.{u}
      {α : Type u}
      (S : LaPToP.DataStructures.Str α) :
      LaPToP.DataStructures.Str.nil ++ S = S
    `S = nil; S` (identity, right equation). 
  • complete
    theorem LaPToP.DataStructures.Str.append_assoc.{u} {α : Type u}
      (S T U : LaPToP.DataStructures.Str α) : S ++ (T ++ U) = S ++ T ++ U
    theorem LaPToP.DataStructures.Str.append_assoc.{u}
      {α : Type u}
      (S T U : LaPToP.DataStructures.Str α) :
      S ++ (T ++ U) = S ++ T ++ U
    `S; (T; U) = (S; T); U` (associativity). 
  • complete
    theorem LaPToP.DataStructures.Str.len_nil.{u} {α : Type u} :
      LaPToP.DataStructures.Str.nil.len = 0
    theorem LaPToP.DataStructures.Str.len_nil.{u}
      {α : Type u} :
      LaPToP.DataStructures.Str.nil.len = 0
    `↔nil = 0` (base). 
  • complete
    theorem LaPToP.DataStructures.Str.len_item.{u} {α : Type u} (i : α) :
      (LaPToP.DataStructures.Str.item i).len = 1
    theorem LaPToP.DataStructures.Str.len_item.{u}
      {α : Type u} (i : α) :
      (LaPToP.DataStructures.Str.item i).len =
        1
    `↔i = 1` (base). 
  • complete
    theorem LaPToP.DataStructures.Str.len_append.{u} {α : Type u}
      (S T : LaPToP.DataStructures.Str α) : (S ++ T).len = S.len + T.len
    theorem LaPToP.DataStructures.Str.len_append.{u}
      {α : Type u}
      (S T : LaPToP.DataStructures.Str α) :
      (S ++ T).len = S.len + T.len
    `↔(S; T) = ↔S + ↔T`. 
  • complete
    theorem LaPToP.DataStructures.Str.append_item_append_inj.{u} {α : Type u}
      (S T : LaPToP.DataStructures.Str α) (i j : α) :
      i = j 
        S ++ LaPToP.DataStructures.Str.item i ++ T =
          S ++ LaPToP.DataStructures.Str.item j ++ T
    theorem LaPToP.DataStructures.Str.append_item_append_inj.{u}
      {α : Type u}
      (S T : LaPToP.DataStructures.Str α)
      (i j : α) :
      i = j 
        S ++
              LaPToP.DataStructures.Str.item
                i ++
            T =
          S ++
              LaPToP.DataStructures.Str.item
                j ++
            T
    `i = j = (S; i; T = S; j; T)`: equal strings have equal items at each index.
    (Listed with the order axioms in the book; it needs no order.) 
Proof for Theorem 4.4
uses 0

List.append_nil, List.nil_append, List.append_assoc, List.length_append, and cancellation of a common prefix and suffix.

Theorem4.5
Group: Data structures as they appear in LaPToP: lists/strings, functions as data, and related theories used when specifying programs that manipulate structure. The string and list material is Hehner's Sections 2.2 and 2.3; the formal counterparts are the Lean modules LaPToP.DataStructures.Strings and LaPToP.DataStructures.Lists . (11)
Group member previews
Preview
Definition 4.1
Loading preview
Group member preview content is loaded from the rendered-fragment cache.
uses 1
Used by 2
Reverse dependency previews
Preview
Theorem 4.10
Loading preview
Reverse dependency preview content is loaded from the rendered-fragment cache.
L∃∀N

The indexing axioms: S\,\mathit{nil} = \mathit{nil}, (S; i; T)\,(\leftrightarrow S) = i, S\,(T; U) = S\,T; S\,U, and S\,(T\,U) = (S\,T)\,U. The last law is stated for U a string of indexes of T, since out-of-range indexes are unspecified in the book. Uses Definition 4.3.

Lean code for Theorem4.55 theorems
  • complete
    theorem LaPToP.DataStructures.Str.sub_nil.{u} {α : Type u} [Inhabited α]
      (S : LaPToP.DataStructures.Str α) :
      S.sub LaPToP.DataStructures.Str.nil = LaPToP.DataStructures.Str.nil
    theorem LaPToP.DataStructures.Str.sub_nil.{u}
      {α : Type u} [Inhabited α]
      (S : LaPToP.DataStructures.Str α) :
      S.sub LaPToP.DataStructures.Str.nil =
        LaPToP.DataStructures.Str.nil
    `S nil = nil`. 
  • complete
    theorem LaPToP.DataStructures.Str.at_append_item_append.{u} {α : Type u}
      [Inhabited α] (S T : LaPToP.DataStructures.Str α) (i : α) :
      (S ++ LaPToP.DataStructures.Str.item i ++ T).at (List.length S) = i
    theorem LaPToP.DataStructures.Str.at_append_item_append.{u}
      {α : Type u} [Inhabited α]
      (S T : LaPToP.DataStructures.Str α)
      (i : α) :
      (S ++
                LaPToP.DataStructures.Str.item
                  i ++
              T).at
          (List.length S) =
        i
    `(S; i; T) ↔S = i`: the item at index `↔S` of `S; i; T` is `i`. (The book's
    proviso `↔S < ∞` holds automatically for finite strings.) 
  • complete
    theorem LaPToP.DataStructures.Str.sub_append.{u} {α : Type u} [Inhabited α]
      (S : LaPToP.DataStructures.Str α)
      (T U : LaPToP.DataStructures.Str ) :
      S.sub (T ++ U) = S.sub T ++ S.sub U
    theorem LaPToP.DataStructures.Str.sub_append.{u}
      {α : Type u} [Inhabited α]
      (S : LaPToP.DataStructures.Str α)
      (T U : LaPToP.DataStructures.Str ) :
      S.sub (T ++ U) = S.sub T ++ S.sub U
    `S (T; U) = S T; S U`: indexing distributes over join of index strings. 
  • complete
    theorem LaPToP.DataStructures.Str.sub_sub.{u} {α : Type u} [Inhabited α]
      (S : LaPToP.DataStructures.Str α) (T U : LaPToP.DataStructures.Str )
      (hU :  k  U, k < List.length T) : S.sub (T.sub U) = (S.sub T).sub U
    theorem LaPToP.DataStructures.Str.sub_sub.{u}
      {α : Type u} [Inhabited α]
      (S : LaPToP.DataStructures.Str α)
      (T U : LaPToP.DataStructures.Str )
      (hU :  k  U, k < List.length T) :
      S.sub (T.sub U) = (S.sub T).sub U
    `S (T U) = (S T) U`, for `U` a string of indexes of `T`. 
  • complete
    theorem LaPToP.DataStructures.Str.at_map_of_lt.{u, v} {α : Type u} [Inhabited α]
      {β : Type v} [Inhabited β] (f : α  β)
      (T : LaPToP.DataStructures.Str α) {k : } (hk : k < List.length T) :
      LaPToP.DataStructures.Str.at (List.map f T) k = f (T.at k)
    theorem LaPToP.DataStructures.Str.at_map_of_lt.{u,
        v}
      {α : Type u} [Inhabited α] {β : Type v}
      [Inhabited β] (f : α  β)
      (T : LaPToP.DataStructures.Str α)
      {k : } (hk : k < List.length T) :
      LaPToP.DataStructures.Str.at
          (List.map f T) k =
        f (T.at k)
    Indexing a mapped string at an in-range index. 
Proof for Theorem 4.5
uses 0

Indexing is List.getD; the laws are List.map_append, List.map_map, and the getElem? lemmas for appending and mapping.

Theorem4.6
Group: Data structures as they appear in LaPToP: lists/strings, functions as data, and related theories used when specifying programs that manipulate structure. The string and list material is Hehner's Sections 2.2 and 2.3; the formal counterparts are the Lean modules LaPToP.DataStructures.Strings and LaPToP.DataStructures.Lists . (11)
Group member previews
Preview
Definition 4.1
Loading preview
Group member preview content is loaded from the rendered-fragment cache.
uses 1used by 0L∃∀N

Copies and update: 0*S = \mathit{nil}, (n+1)*S = n*S; S, and (S; i; T) \triangleleft \leftrightarrow S \triangleright j = S; j; T, together with the book's examples 3*(0; 1) = 0; 1; 0; 1; 0; 1 and 3; 5; 9 \triangleleft 2 \triangleright 8 = 3; 5; 8, and the membership condition for *S. The copy count is a natural number here (the book allows \infty). Uses Definition 4.3.

Lean code for Theorem4.66 theorems
  • complete
    theorem LaPToP.DataStructures.Str.copies_zero.{u} {α : Type u}
      (S : LaPToP.DataStructures.Str α) :
      LaPToP.DataStructures.Str.copies 0 S = LaPToP.DataStructures.Str.nil
    theorem LaPToP.DataStructures.Str.copies_zero.{u}
      {α : Type u}
      (S : LaPToP.DataStructures.Str α) :
      LaPToP.DataStructures.Str.copies 0 S =
        LaPToP.DataStructures.Str.nil
    `0*S = nil`. 
  • complete
    theorem LaPToP.DataStructures.Str.copies_succ.{u} {α : Type u}
      (S : LaPToP.DataStructures.Str α) (n : ) :
      LaPToP.DataStructures.Str.copies (n + 1) S =
        LaPToP.DataStructures.Str.copies n S ++ S
    theorem LaPToP.DataStructures.Str.copies_succ.{u}
      {α : Type u}
      (S : LaPToP.DataStructures.Str α)
      (n : ) :
      LaPToP.DataStructures.Str.copies (n + 1)
          S =
        LaPToP.DataStructures.Str.copies n
            S ++
          S
    `(n+1)*S = n*S; S`. 
  • complete
    theorem LaPToP.DataStructures.Str.copies_three_example :
      LaPToP.DataStructures.Str.copies 3 [0, 1] = [0, 1, 0, 1, 0, 1]
    theorem LaPToP.DataStructures.Str.copies_three_example :
      LaPToP.DataStructures.Str.copies 3
          [0, 1] =
        [0, 1, 0, 1, 0, 1]
    `3*(0; 1) = 0; 1; 0; 1; 0; 1`, the book's example. 
  • complete
    theorem LaPToP.DataStructures.Str.mem_star.{u} {α : Type u}
      (S T : LaPToP.DataStructures.Str α) :
      T  S.star   n, LaPToP.DataStructures.Str.copies n S = T
    theorem LaPToP.DataStructures.Str.mem_star.{u}
      {α : Type u}
      (S T : LaPToP.DataStructures.Str α) :
      T  S.star 
         n,
          LaPToP.DataStructures.Str.copies n
              S =
            T
    Membership in `*S`: the strings `n*S`. 
  • complete
    theorem LaPToP.DataStructures.Str.update_append_item_append.{u} {α : Type u}
      (S T : LaPToP.DataStructures.Str α) (i j : α) :
      (S ++ LaPToP.DataStructures.Str.item i ++ T).update (List.length S)
          j =
        S ++ LaPToP.DataStructures.Str.item j ++ T
    theorem LaPToP.DataStructures.Str.update_append_item_append.{u}
      {α : Type u}
      (S T : LaPToP.DataStructures.Str α)
      (i j : α) :
      (S ++
                LaPToP.DataStructures.Str.item
                  i ++
              T).update
          (List.length S) j =
        S ++
            LaPToP.DataStructures.Str.item
              j ++
          T
    `(S; i; T)⊲↔S⊳j = S; j; T`: updating at index `↔S` replaces `i` by `j`. 
  • complete
    theorem LaPToP.DataStructures.Str.update_example :
      LaPToP.DataStructures.Str.update [3, 5, 9] 2 8 = [3, 5, 8]
    theorem LaPToP.DataStructures.Str.update_example :
      LaPToP.DataStructures.Str.update
          [3, 5, 9] 2 8 =
        [3, 5, 8]
    `3; 5; 9⊲2⊳8 = 3; 5; 8`, the book's example. 
Proof for Theorem 4.6
uses 0

List.replicate_succ' with List.flatten_append; List.set_append_right for the update law; the examples are by evaluation.

Theorem4.7
Group: Data structures as they appear in LaPToP: lists/strings, functions as data, and related theories used when specifying programs that manipulate structure. The string and list material is Hehner's Sections 2.2 and 2.3; the formal counterparts are the Lean modules LaPToP.DataStructures.Strings and LaPToP.DataStructures.Lists . (11)
Group member previews
Preview
Definition 4.1
Loading preview
Group member preview content is loaded from the rendered-fragment cache.
uses 1used by 0L∃∀N

"The order of two strings is determined by the items at the first index where they differ. ... If there is no index where they differ, the shorter string comes before the longer one." The axioms: \mathit{nil} \le S < S; i; T and i < j \Rightarrow S; i; T < S; j; U. Lean's lexicographic order on lists is exactly this ordering. Uses Definition 4.1.

Lean code for Theorem4.73 theorems
  • complete
    theorem LaPToP.DataStructures.Str.nil_le.{u} {α : Type u} [LT α]
      (S : LaPToP.DataStructures.Str α) : LaPToP.DataStructures.Str.nil  S
    theorem LaPToP.DataStructures.Str.nil_le.{u}
      {α : Type u} [LT α]
      (S : LaPToP.DataStructures.Str α) :
      LaPToP.DataStructures.Str.nil  S
    `nil ≤ S`. 
  • complete
    theorem LaPToP.DataStructures.Str.lt_append_item_append.{u} {α : Type u} [LT α]
      (S T : LaPToP.DataStructures.Str α) (i : α) :
      S < S ++ LaPToP.DataStructures.Str.item i ++ T
    theorem LaPToP.DataStructures.Str.lt_append_item_append.{u}
      {α : Type u} [LT α]
      (S T : LaPToP.DataStructures.Str α)
      (i : α) :
      S <
        S ++
            LaPToP.DataStructures.Str.item
              i ++
          T
    `S < S; i; T`: a proper prefix comes first. 
  • complete
    theorem LaPToP.DataStructures.Str.append_lt_append_of_lt.{u} {α : Type u} [LT α]
      (S T U : LaPToP.DataStructures.Str α) (i j : α) (h : i < j) :
      S ++ LaPToP.DataStructures.Str.item i ++ T <
        S ++ LaPToP.DataStructures.Str.item j ++ U
    theorem LaPToP.DataStructures.Str.append_lt_append_of_lt.{u}
      {α : Type u} [LT α]
      (S T U : LaPToP.DataStructures.Str α)
      (i j : α) (h : i < j) :
      S ++ LaPToP.DataStructures.Str.item i ++
          T <
        S ++
            LaPToP.DataStructures.Str.item
              j ++
          U
    `i < j ⇒ S; i; T < S; j; U`: strings are ordered by the first differing item. 
Proof for Theorem 4.7
uses 0

Induction on the common prefix S, using List.nil_lt_cons and List.cons_lt_cons_iff.

Theorem4.8
Group: Data structures as they appear in LaPToP: lists/strings, functions as data, and related theories used when specifying programs that manipulate structure. The string and list material is Hehner's Sections 2.2 and 2.3; the formal counterparts are the Lean modules LaPToP.DataStructures.Strings and LaPToP.DataStructures.Lists . (11)
Group member previews
Preview
Definition 4.1
Loading preview
Group member preview content is loaded from the rendered-fragment cache.
Statement uses 2
Statement dependency previews
Preview
Definition 2.12
Loading preview
Statement dependency preview content is loaded from the rendered-fragment cache.
used by 0L∃∀N

The string interval x;..y ("x to y", same pronunciation as the bunch x,..y; x included, y excluded): \leftrightarrow(x;..y) = y - x, x;..x = \mathit{nil}, x;..x+1 = x, and (x;..y); (y;..z) = x;..z for x \le y \le z; its items are exactly the integers i with x \le i < y. As for the bunch interval, the length law uses the difference truncated at 0. Uses Definition 4.3 and Definition 2.12.

Lean code for Theorem4.85 theorems
  • complete
    theorem LaPToP.DataStructures.Str.len_interval (x y : ) :
      (LaPToP.DataStructures.Str.interval x y).len = (y - x).toNat
    theorem LaPToP.DataStructures.Str.len_interval
      (x y : ) :
      (LaPToP.DataStructures.Str.interval x
            y).len =
        (y - x).toNat
    `↔(x;..y) = y – x` (with the difference truncated at `0`; for `x ≤ y` it is
    exactly `y – x`). 
  • complete
    theorem LaPToP.DataStructures.Str.interval_self (x : ) :
      LaPToP.DataStructures.Str.interval x x = LaPToP.DataStructures.Str.nil
    theorem LaPToP.DataStructures.Str.interval_self
      (x : ) :
      LaPToP.DataStructures.Str.interval x x =
        LaPToP.DataStructures.Str.nil
    `x;..x = nil`. 
  • complete
    theorem LaPToP.DataStructures.Str.interval_succ (x : ) :
      LaPToP.DataStructures.Str.interval x (x + 1) =
        LaPToP.DataStructures.Str.item x
    theorem LaPToP.DataStructures.Str.interval_succ
      (x : ) :
      LaPToP.DataStructures.Str.interval x
          (x + 1) =
        LaPToP.DataStructures.Str.item x
    `x;..x+1 = x`. 
  • complete
    theorem LaPToP.DataStructures.Str.interval_append_interval {x y z : }
      (hxy : x  y) (hyz : y  z) :
      LaPToP.DataStructures.Str.interval x y ++
          LaPToP.DataStructures.Str.interval y z =
        LaPToP.DataStructures.Str.interval x z
    theorem LaPToP.DataStructures.Str.interval_append_interval
      {x y z : } (hxy : x  y)
      (hyz : y  z) :
      LaPToP.DataStructures.Str.interval x
            y ++
          LaPToP.DataStructures.Str.interval y
            z =
        LaPToP.DataStructures.Str.interval x z
    `(x;..y); (y;..z) = x;..z` for `x ≤ y ≤ z`. 
  • complete
    theorem LaPToP.DataStructures.Str.mem_interval (i x y : ) :
      i  LaPToP.DataStructures.Str.interval x y  x  i  i < y
    theorem LaPToP.DataStructures.Str.mem_interval
      (i x y : ) :
      i 
          LaPToP.DataStructures.Str.interval x
            y 
        x  i  i < y
    The items of `x;..y` are exactly the integers `i` with `x ≤ i < y`. 
Proof for Theorem 4.8
uses 0

The interval is List.range shifted by x; the join law is List.range_add after splitting z - x = (y - x) + (z - y).

Definition4.9
Group: Data structures as they appear in LaPToP: lists/strings, functions as data, and related theories used when specifying programs that manipulate structure. The string and list material is Hehner's Sections 2.2 and 2.3; the formal counterparts are the Lean modules LaPToP.DataStructures.Strings and LaPToP.DataStructures.Lists . (11)
Group member previews
Preview
Definition 4.1
Loading preview
Group member preview content is loaded from the rendered-fragment cache.
Statement uses 2
Statement dependency previews
Preview
Definition 2.1
Loading preview
Statement dependency preview content is loaded from the rendered-fragment cache.
Used by 6
Reverse dependency previews
Preview
Theorem 3.16
Loading preview
Reverse dependency preview content is loaded from the rendered-fragment cache.
L∃∀N

"A list is a contained string." Although the string 0; 1; 2 is not a single item, the list [0; 1; 2] is. List formation [S] packages a string (Str.pack); contents \sim L unpackages it (HList.contents); \# L is the length, \square L = 0,..\# L the domain (a bunch of naturals), L\,n the item at index n, L\,M composition ("L composed with M": the items of L at the indexes listed in M), L ;; M join, and n \to i \mid L ("n maps to i otherwise L") the list like L except that item n is i. Lists are ordered lexicographically, like strings. In Lean HList α is a one-field structure around a Str α, exactly as HSet packages a bunch in Definition 2.1; the operations act on contents via Definition 4.3.

Lean code for Definition4.99 definitions
  • structure(1 field)defined in LaPToP/DataStructures/Lists.lean
    complete
    structure LaPToP.DataStructures.HList.{u} (α : Type u) : Type u
    structure LaPToP.DataStructures.HList.{u}
      (α : Type u) : Type u
    A Hehner *list* (aPToP §2.3): a string packaged as a single item. The book
    writes `[S]` for the list containing the string `S` (see `Str.pack`) and `~L`
    for the contents of the list `L` (see `HList.contents`). 
    contents : LaPToP.DataStructures.Str α
    `~L`, the contents of the list `L`, a string. 
  • complete
    def LaPToP.DataStructures.Str.pack.{u} {α : Type u}
      (S : LaPToP.DataStructures.Str α) : LaPToP.DataStructures.HList α
    def LaPToP.DataStructures.Str.pack.{u}
      {α : Type u}
      (S : LaPToP.DataStructures.Str α) :
      LaPToP.DataStructures.HList α
    `[S]`, the list containing the string `S` (aPToP §2.3). 
  • complete
    abbrev LaPToP.DataStructures.HList.contents.{u} {α : Type u}
      (self : LaPToP.DataStructures.HList α) : LaPToP.DataStructures.Str α
    abbrev LaPToP.DataStructures.HList.contents.{u}
      {α : Type u}
      (self : LaPToP.DataStructures.HList α) :
      LaPToP.DataStructures.Str α
    `~L`, the contents of the list `L`, a string. 
  • complete
    def LaPToP.DataStructures.HList.length.{u} {α : Type u}
      (L : LaPToP.DataStructures.HList α) : ℕ∞
    def LaPToP.DataStructures.HList.length.{u}
      {α : Type u}
      (L : LaPToP.DataStructures.HList α) : ℕ∞
    `#L`, the length of a list: the number of items it contains. 
  • complete
    def LaPToP.DataStructures.HList.domain.{u} {α : Type u}
      (L : LaPToP.DataStructures.HList α) : LaPToP.BasicTheories.Bunch 
    def LaPToP.DataStructures.HList.domain.{u}
      {α : Type u}
      (L : LaPToP.DataStructures.HList α) :
      LaPToP.BasicTheories.Bunch 
    `☐L`, the domain of a list: the bunch of its indexes `0,..#L`. 
  • complete
    def LaPToP.DataStructures.HList.at.{u} {α : Type u} [Inhabited α]
      (L : LaPToP.DataStructures.HList α) (n : ) : α
    def LaPToP.DataStructures.HList.at.{u}
      {α : Type u} [Inhabited α]
      (L : LaPToP.DataStructures.HList α)
      (n : ) : α
    `L n`, the item of `L` at index `n` (indexing from `0`). 
  • complete
    def LaPToP.DataStructures.HList.comp.{u} {α : Type u} [Inhabited α]
      (L : LaPToP.DataStructures.HList α)
      (M : LaPToP.DataStructures.HList ) : LaPToP.DataStructures.HList α
    def LaPToP.DataStructures.HList.comp.{u}
      {α : Type u} [Inhabited α]
      (L : LaPToP.DataStructures.HList α)
      (M : LaPToP.DataStructures.HList ) :
      LaPToP.DataStructures.HList α
    `L M`, list composition: the list of items of `L` at the indexes listed in
    `M`, e.g. `[3; 5; 7; 4] [2; 1; 2] = [7; 5; 7]`. 
  • complete
    def LaPToP.DataStructures.HList.join.{u} {α : Type u}
      (L M : LaPToP.DataStructures.HList α) : LaPToP.DataStructures.HList α
    def LaPToP.DataStructures.HList.join.{u}
      {α : Type u}
      (L M : LaPToP.DataStructures.HList α) :
      LaPToP.DataStructures.HList α
    `L ;; M`, list join. 
  • complete
    def LaPToP.DataStructures.HList.modify.{u} {α : Type u} (n : ) (i : α)
      (L : LaPToP.DataStructures.HList α) : LaPToP.DataStructures.HList α
    def LaPToP.DataStructures.HList.modify.{u}
      {α : Type u} (n : ) (i : α)
      (L : LaPToP.DataStructures.HList α) :
      LaPToP.DataStructures.HList α
    `n→i | L`, "`n` maps to `i` otherwise `L`": the list like `L` except that
    item `n` is `i`. 
Theorem4.10
Group: Data structures as they appear in LaPToP: lists/strings, functions as data, and related theories used when specifying programs that manipulate structure. The string and list material is Hehner's Sections 2.2 and 2.3; the formal counterparts are the Lean modules LaPToP.DataStructures.Strings and LaPToP.DataStructures.Lists . (11)
Group member previews
Preview
Definition 4.1
Loading preview
Group member preview content is loaded from the rendered-fragment cache.
Statement uses 3
Statement dependency previews
Preview
Definition 2.12
Loading preview
Statement dependency preview content is loaded from the rendered-fragment cache.
Used by 4
Reverse dependency previews
Preview
Theorem 4.11
Loading preview
Reverse dependency preview content is loaded from the rendered-fragment cache.
L∃∀N

Hehner's List Theory axioms, for lists L, strings S, T, an index n of S, an item i, and bunches of strings A, B: [\sim L] = L (list formation), \sim[S] = S (contents), \#[S] = \leftrightarrow S (length), \square L = 0,..\# L (domain), [S] ;; [T] = [S; T] (join), [S]\,n = S\,n (indexing), [S]\,[T] = [S\,T] (composition), n \to i \mid [S] = [S \triangleleft n \triangleright i] (modification), [S] = [T] = (S = T) (equation), [S] < [T] = (S < T) (order), and [A] : [B] = A : B (inclusion, with [A] the bunch of lists [S] for S : A). The domain law is stated on the naturals, with a companion reading it in the integers as the bunch interval Definition 2.12. The remaining axiom [S] \neq S (structure) is not an equation in the typed model: a list and its contents have different Lean types, which is exactly the distinction it records. The book's worked examples (\sim[3;5;7;4], \#[3;5;7;4], [3;5;7;4]\,2, [3;5;7;4]\,[2;1;2], [3;5;7;4];;[2;1;2], 2 \to 22 \mid [10;..15], and the item swap) are checked by evaluation. Uses Definition 4.9 and Theorem 4.5.

Lean code for Theorem4.1021 theorems
  • complete
    theorem LaPToP.DataStructures.HList.pack_contents.{u} {α : Type u}
      (L : LaPToP.DataStructures.HList α) : L.contents.pack = L
    theorem LaPToP.DataStructures.HList.pack_contents.{u}
      {α : Type u}
      (L : LaPToP.DataStructures.HList α) :
      L.contents.pack = L
    `[~L] = L` (list formation). 
  • complete
    theorem LaPToP.DataStructures.HList.contents_pack.{u} {α : Type u}
      (S : LaPToP.DataStructures.Str α) : S.pack.contents = S
    theorem LaPToP.DataStructures.HList.contents_pack.{u}
      {α : Type u}
      (S : LaPToP.DataStructures.Str α) :
      S.pack.contents = S
    `~[S] = S` (contents). 
  • complete
    theorem LaPToP.DataStructures.HList.length_pack.{u} {α : Type u}
      (S : LaPToP.DataStructures.Str α) : S.pack.length = S.len
    theorem LaPToP.DataStructures.HList.length_pack.{u}
      {α : Type u}
      (S : LaPToP.DataStructures.Str α) :
      S.pack.length = S.len
    `#[S] = ↔S` (length). 
  • complete
    theorem LaPToP.DataStructures.HList.domain_eq.{u} {α : Type u}
      (L : LaPToP.DataStructures.HList α) :
      L.domain = {n | n < List.length L.contents}
    theorem LaPToP.DataStructures.HList.domain_eq.{u}
      {α : Type u}
      (L : LaPToP.DataStructures.HList α) :
      L.domain =
        {n | n < List.length L.contents}
    `☐L = 0,..#L` (domain): the indexes of `L` are the naturals below its length. 
  • complete
    theorem LaPToP.DataStructures.HList.image_domain.{u} {α : Type u}
      (L : LaPToP.DataStructures.HList α) :
      Nat.cast '' L.domain =
        LaPToP.BasicTheories.Bunch.interval 0 (List.length L.contents)
    theorem LaPToP.DataStructures.HList.image_domain.{u}
      {α : Type u}
      (L : LaPToP.DataStructures.HList α) :
      Nat.cast '' L.domain =
        LaPToP.BasicTheories.Bunch.interval 0
          (List.length L.contents)
    The domain, read in the integers, is the bunch interval `0,..#L`. 
  • complete
    theorem LaPToP.DataStructures.HList.pack_join_pack.{u} {α : Type u}
      (S T : LaPToP.DataStructures.Str α) :
      S.pack.join T.pack = (S ++ T).pack
    theorem LaPToP.DataStructures.HList.pack_join_pack.{u}
      {α : Type u}
      (S T : LaPToP.DataStructures.Str α) :
      S.pack.join T.pack = (S ++ T).pack
    `[S];;[T] = [S; T]` (join). 
  • complete
    theorem LaPToP.DataStructures.HList.at_pack.{u} {α : Type u}
      (S : LaPToP.DataStructures.Str α) (n : ) [Inhabited α] :
      S.pack.at n = S.at n
    theorem LaPToP.DataStructures.HList.at_pack.{u}
      {α : Type u}
      (S : LaPToP.DataStructures.Str α)
      (n : ) [Inhabited α] :
      S.pack.at n = S.at n
    `[S] n = S n` (indexing). 
  • complete
    theorem LaPToP.DataStructures.HList.pack_comp_pack.{u} {α : Type u}
      (S : LaPToP.DataStructures.Str α) [Inhabited α]
      (T : LaPToP.DataStructures.Str ) :
      S.pack.comp T.pack = (S.sub T).pack
    theorem LaPToP.DataStructures.HList.pack_comp_pack.{u}
      {α : Type u}
      (S : LaPToP.DataStructures.Str α)
      [Inhabited α]
      (T : LaPToP.DataStructures.Str ) :
      S.pack.comp T.pack = (S.sub T).pack
    `[S] [T] = [S T]` (composition). 
  • complete
    theorem LaPToP.DataStructures.HList.modify_pack.{u} {α : Type u}
      (S : LaPToP.DataStructures.Str α) (n : ) (i : α) :
      LaPToP.DataStructures.HList.modify n i S.pack = (S.update n i).pack
    theorem LaPToP.DataStructures.HList.modify_pack.{u}
      {α : Type u}
      (S : LaPToP.DataStructures.Str α)
      (n : ) (i : α) :
      LaPToP.DataStructures.HList.modify n i
          S.pack =
        (S.update n i).pack
    `n→i | [S] = [S⊲n⊳i]` (modification). 
  • complete
    theorem LaPToP.DataStructures.HList.pack_inj.{u} {α : Type u}
      (S T : LaPToP.DataStructures.Str α) : S.pack = T.pack  S = T
    theorem LaPToP.DataStructures.HList.pack_inj.{u}
      {α : Type u}
      (S T : LaPToP.DataStructures.Str α) :
      S.pack = T.pack  S = T
    `[S] = [T] = (S = T)` (equation). 
  • complete
    theorem LaPToP.DataStructures.HList.pack_lt_pack.{u} {α : Type u}
      (S T : LaPToP.DataStructures.Str α) [LT α] : S.pack < T.pack  S < T
    theorem LaPToP.DataStructures.HList.pack_lt_pack.{u}
      {α : Type u}
      (S T : LaPToP.DataStructures.Str α)
      [LT α] : S.pack < T.pack  S < T
    `[S] < [T] = (S < T)` (order). 
  • complete
    theorem LaPToP.DataStructures.HList.image_pack_subset_image_pack.{u}
      {α : Type u}
      (A B : LaPToP.BasicTheories.Bunch (LaPToP.DataStructures.Str α)) :
      LaPToP.DataStructures.Str.pack '' A 
          LaPToP.DataStructures.Str.pack '' B 
        A  B
    theorem LaPToP.DataStructures.HList.image_pack_subset_image_pack.{u}
      {α : Type u}
      (A B :
        LaPToP.BasicTheories.Bunch
          (LaPToP.DataStructures.Str α)) :
      LaPToP.DataStructures.Str.pack '' A 
          LaPToP.DataStructures.Str.pack ''
            B 
        A  B
    `[A]: [B] = A: B` (inclusion), for bunches of strings `A`, `B`; list brackets
    distribute over bunch union, so `[A]` is the bunch of lists `[S]` for `S : A`. 
  • complete
    theorem LaPToP.DataStructures.Str.pack_injective.{u} {α : Type u} :
      Function.Injective LaPToP.DataStructures.Str.pack
    theorem LaPToP.DataStructures.Str.pack_injective.{u}
      {α : Type u} :
      Function.Injective
        LaPToP.DataStructures.Str.pack
    Packaging is injective; `[S] = [T] = (S = T)` is `HList.pack_inj`. 
  • complete
    theorem LaPToP.DataStructures.HList.contents_example :
      (LaPToP.DataStructures.Str.pack [3, 5, 7, 4]).contents = [3, 5, 7, 4]
    theorem LaPToP.DataStructures.HList.contents_example :
      (LaPToP.DataStructures.Str.pack
            [3, 5, 7, 4]).contents =
        [3, 5, 7, 4]
    `~[3; 5; 7; 4] = 3; 5; 7; 4`. 
  • complete
    theorem LaPToP.DataStructures.HList.length_example :
      (LaPToP.DataStructures.Str.pack [3, 5, 7, 4]).length = 4
    theorem LaPToP.DataStructures.HList.length_example :
      (LaPToP.DataStructures.Str.pack
            [3, 5, 7, 4]).length =
        4
    `#[3; 5; 7; 4] = 4`. 
  • complete
    theorem LaPToP.DataStructures.HList.at_example :
      (LaPToP.DataStructures.Str.pack [3, 5, 7, 4]).at 2 = 7
    theorem LaPToP.DataStructures.HList.at_example :
      (LaPToP.DataStructures.Str.pack
              [3, 5, 7, 4]).at
          2 =
        7
    `[3; 5; 7; 4] 2 = 7`. 
  • complete
    theorem LaPToP.DataStructures.HList.comp_example :
      (LaPToP.DataStructures.Str.pack [3, 5, 7, 4]).comp
          (LaPToP.DataStructures.Str.pack [2, 1, 2]) =
        LaPToP.DataStructures.Str.pack [7, 5, 7]
    theorem LaPToP.DataStructures.HList.comp_example :
      (LaPToP.DataStructures.Str.pack
              [3, 5, 7, 4]).comp
          (LaPToP.DataStructures.Str.pack
            [2, 1, 2]) =
        LaPToP.DataStructures.Str.pack
          [7, 5, 7]
    `[3; 5; 7; 4] [2; 1; 2] = [7; 5; 7]`. 
  • complete
    theorem LaPToP.DataStructures.HList.join_example :
      (LaPToP.DataStructures.Str.pack [3, 5, 7, 4]).join
          (LaPToP.DataStructures.Str.pack [2, 1, 2]) =
        LaPToP.DataStructures.Str.pack [3, 5, 7, 4, 2, 1, 2]
    theorem LaPToP.DataStructures.HList.join_example :
      (LaPToP.DataStructures.Str.pack
              [3, 5, 7, 4]).join
          (LaPToP.DataStructures.Str.pack
            [2, 1, 2]) =
        LaPToP.DataStructures.Str.pack
          [3, 5, 7, 4, 2, 1, 2]
    `[3; 5; 7; 4];;[2; 1; 2] = [3; 5; 7; 4; 2; 1; 2]`. 
  • complete
    theorem LaPToP.DataStructures.HList.modify_example :
      LaPToP.DataStructures.HList.modify 2 22
          (LaPToP.DataStructures.Str.interval 10 15).pack =
        LaPToP.DataStructures.Str.pack [10, 11, 22, 13, 14]
    theorem LaPToP.DataStructures.HList.modify_example :
      LaPToP.DataStructures.HList.modify 2 22
          (LaPToP.DataStructures.Str.interval
              10 15).pack =
        LaPToP.DataStructures.Str.pack
          [10, 11, 22, 13, 14]
    `2→22 | [10;..15] = [10; 11; 22; 13; 14]`. 
  • complete
    theorem LaPToP.DataStructures.HList.modify_modify_example :
      LaPToP.DataStructures.HList.modify 2 22
          (LaPToP.DataStructures.HList.modify 3 33
            (LaPToP.DataStructures.Str.interval 10 15).pack) =
        LaPToP.DataStructures.Str.pack [10, 11, 22, 33, 14]
    theorem LaPToP.DataStructures.HList.modify_modify_example :
      LaPToP.DataStructures.HList.modify 2 22
          (LaPToP.DataStructures.HList.modify
            3 33
            (LaPToP.DataStructures.Str.interval
                10 15).pack) =
        LaPToP.DataStructures.Str.pack
          [10, 11, 22, 33, 14]
    `2→22 | 3→33 | [10;..15] = [10; 11; 22; 33; 14]`. 
  • complete
    theorem LaPToP.DataStructures.HList.modify_swap_example :
      have L := (LaPToP.DataStructures.Str.interval 10 15).pack;
      LaPToP.DataStructures.HList.modify 2 (L.at 3)
          (LaPToP.DataStructures.HList.modify 3 (L.at 2) L) =
        LaPToP.DataStructures.Str.pack [10, 11, 13, 12, 14]
    theorem LaPToP.DataStructures.HList.modify_swap_example :
      have L :=
        (LaPToP.DataStructures.Str.interval 10
            15).pack;
      LaPToP.DataStructures.HList.modify 2
          (L.at 3)
          (LaPToP.DataStructures.HList.modify
            3 (L.at 2) L) =
        LaPToP.DataStructures.Str.pack
          [10, 11, 13, 12, 14]
    With `L = [10;..15]`, `2→L 3 | 3→L 2 | L = [10; 11; 13; 12; 14]`: swapping two items. 
Proof for Theorem 4.10
uses 0

Every law is definitional (rfl / Iff.rfl) once the list operators are defined on contents; equation and inclusion follow from injectivity of packaging (Set.image_subset_image_iff).

Theorem4.11
Group: Data structures as they appear in LaPToP: lists/strings, functions as data, and related theories used when specifying programs that manipulate structure. The string and list material is Hehner's Sections 2.2 and 2.3; the formal counterparts are the Lean modules LaPToP.DataStructures.Strings and LaPToP.DataStructures.Lists . (11)
Group member previews
Preview
Definition 4.1
Loading preview
Group member preview content is loaded from the rendered-fragment cache.
Statement uses 2
Statement dependency previews
Preview
Theorem 4.5
Loading preview
Statement dependency preview content is loaded from the rendered-fragment cache.
used by 0L∃∀N

Theorems Hehner derives from the axioms, for lists L, M, N and natural n: (L\,M)\,n = L\,(M\,n) (composition), (L\,M)\,N = L\,(M\,N) (associativity), and L\,(M ;; N) = L\,M ;; L\,N (distributivity). The first two are stated for n an index of M, respectively N a list of indexes of M, because the book leaves out-of-range indexing unspecified. Uses Theorem 4.10 and Theorem 4.5.

Lean code for Theorem4.113 theorems
  • complete
    theorem LaPToP.DataStructures.HList.comp_at.{u} {α : Type u} [Inhabited α]
      (L : LaPToP.DataStructures.HList α)
      (M : LaPToP.DataStructures.HList ) {n : }
      (hn : n < List.length M.contents) : (L.comp M).at n = L.at (M.at n)
    theorem LaPToP.DataStructures.HList.comp_at.{u}
      {α : Type u} [Inhabited α]
      (L : LaPToP.DataStructures.HList α)
      (M : LaPToP.DataStructures.HList )
      {n : }
      (hn : n < List.length M.contents) :
      (L.comp M).at n = L.at (M.at n)
    `(L M) n = L (M n)` (composition), for `n` an index of `M`. 
  • complete
    theorem LaPToP.DataStructures.HList.comp_assoc.{u} {α : Type u} [Inhabited α]
      (L : LaPToP.DataStructures.HList α)
      (M N : LaPToP.DataStructures.HList )
      (hN :  k  N.contents, k < List.length M.contents) :
      (L.comp M).comp N = L.comp (M.comp N)
    theorem LaPToP.DataStructures.HList.comp_assoc.{u}
      {α : Type u} [Inhabited α]
      (L : LaPToP.DataStructures.HList α)
      (M N : LaPToP.DataStructures.HList )
      (hN :
         k  N.contents,
          k < List.length M.contents) :
      (L.comp M).comp N = L.comp (M.comp N)
    `(L M) N = L (M N)` (associativity), for `N` a list of indexes of `M`. 
  • complete
    theorem LaPToP.DataStructures.HList.comp_join.{u} {α : Type u} [Inhabited α]
      (L : LaPToP.DataStructures.HList α)
      (M N : LaPToP.DataStructures.HList ) :
      L.comp (M.join N) = (L.comp M).join (L.comp N)
    theorem LaPToP.DataStructures.HList.comp_join.{u}
      {α : Type u} [Inhabited α]
      (L : LaPToP.DataStructures.HList α)
      (M N : LaPToP.DataStructures.HList ) :
      L.comp (M.join N) =
        (L.comp M).join (L.comp N)
    `L (M;;N) = L M ;; L N` (distributivity). 
Proof for Theorem 4.11
uses 0

Unpack to contents and apply the string indexing laws (Str.at_map_of_lt, Str.sub_sub, Str.sub_append).

Definition4.12
Group: Data structures as they appear in LaPToP: lists/strings, functions as data, and related theories used when specifying programs that manipulate structure. The string and list material is Hehner's Sections 2.2 and 2.3; the formal counterparts are the Lean modules LaPToP.DataStructures.Strings and LaPToP.DataStructures.Lists . (11)
Group member previews
Preview
Definition 4.1
Loading preview
Group member preview content is loaded from the rendered-fragment cache.
uses 1used by 0XL∃∀N

Functions are ordinary data in LaPToP. Higher-order specifications and implementations are therefore first-class, building on Definition 4.1 when the domain is finite or inductive.