Documentation

CslibFrontier.Foundations.Data.List.Extract

Adjacent factors of a list #

List.extract l a b is the factor of l from position a (included) to b (excluded). Two adjacent factors concatenate to the factor spanning both (List.extract_append_extract), a factor is an infix (List.extract_isInfix), and a factor of a factor is a factor (List.extract_extract). Proofs about factors of words, such as matched pushes and pops of a run or the factors of a concatenation of languages, split a factor at an intermediate position with it.

Main results #

theorem List.extract_append_extract {α : Type u_1} (l : List α) {a b c : ℕ} (hab : a ≤ b) (hbc : b ≤ c) :
l.extract a b ++ l.extract b c = l.extract a c

Two adjacent factors of a list concatenate to the factor spanning both.

theorem List.take_extract {α : Type u_1} (l : List α) {a b c : ℕ} (hab : a ≤ b) (hbc : b ≤ c) :
take (b - a) (l.extract a c) = l.extract a b

A prefix of a factor is a factor.

theorem List.extract_eq_singleton {α : Type u_1} {l : List α} {a : ℕ} {x : α} (h : l[a]? = some x) :
l.extract a (a + 1) = [x]

The factor of length one at a position is the entry there.

theorem List.getElem?_extract {α : Type u_1} (l : List α) {a b k : ℕ} (hk : k < b - a) :
(l.extract a b)[k]? = l[a + k]?

Entry k of the factor from position a is entry a + k of the list.

theorem List.mem_extract_iff_getElem? {α : Type u_1} {l : List α} {a b : ℕ} {x : α} :
x ∈ l.extract a b ↔ ∃ (k : ℕ), a ≤ k ∧ k < b ∧ l[k]? = some x

The entries of a factor are the entries of the list at the positions inside it.

theorem List.extract_isInfix {α : Type u_1} (l : List α) (a b : ℕ) :
l.extract a b <:+: l

A factor of a list is an infix of it.

theorem List.extract_extract {α : Type u_1} (l : List α) {a b c d : ℕ} (h : a + d ≤ b) :
(l.extract a b).extract c d = l.extract (a + c) (a + d)

A factor of a factor of a list is a factor of the list.

theorem List.extract_cons_succ {α : Type u_1} (x : α) (l : List α) (a b : ℕ) :
(x :: l).extract (a + 1) (b + 1) = l.extract a b

Shifting both ends of a factor past a new head.

theorem List.extract_append_left {α : Type u_1} (l l' : List α) (a b : ℕ) :
(l ++ l').extract (l.length + a) (l.length + b) = l'.extract a b

A factor of the right part of an append, with positions shifted by the left part.

theorem List.extract_append_right {α : Type u_1} (l l' : List α) {a b : ℕ} (hb : b ≤ l.length) :
(l ++ l').extract a b = l.extract a b

A factor that ends inside the left part of an append is a factor of the left part.

theorem List.take_eq_take_append_extract {α : Type u_1} (l : List α) {a b : ℕ} (hab : a ≤ b) :
take b l = take a l ++ l.extract a b

A prefix of a list is a shorter prefix followed by the factor between them.

theorem List.drop_eq_extract_append_drop {α : Type u_1} (l : List α) {a b : ℕ} (hab : a ≤ b) :
drop a l = l.extract a b ++ drop b l

A suffix of a list is the factor up to a later position followed by the shorter suffix.