sublists #
List.Sublists
gives a list of all (not necessarily contiguous) sublists of a list.
This file contains basic results on this function.
sublists #
theorem
List.sublists'Aux_eq_array_foldl
{α : Type u}
(a : α)
(r₁ r₂ : List (List α))
:
List.sublists'Aux a r₁ r₂ = (Array.foldl (fun (r : Array (List α)) (l : List α) => r.push (a :: l)) r₂.toArray r₁.toArray).toList
theorem
List.sublists'_eq_sublists'Aux
{α : Type u}
(l : List α)
:
l.sublists' = List.foldr (fun (a : α) (r : List (List α)) => List.sublists'Aux a r r) [[]] l
theorem
List.sublists'Aux_eq_map
{α : Type u}
(a : α)
(r₁ r₂ : List (List α))
:
List.sublists'Aux a r₁ r₂ = r₂ ++ List.map (List.cons a) r₁
@[deprecated List.sublistsAux_eq_flatMap]
Alias of List.sublistsAux_eq_flatMap
.
theorem
List.map_pure_sublist_sublists
{α : Type u}
(l : List α)
:
(List.map pure l).Sublist l.sublists
@[deprecated List.map_pure_sublist_sublists]
theorem
List.map_ret_sublist_sublists
{α : Type u}
(l : List α)
:
(List.map List.ret l).Sublist l.sublists
sublistsLen #
Auxiliary function to construct the list of all sublists of a given length. Given an
integer n
, a list l
, a function f
and an auxiliary list L
, it returns the list made of
f
applied to all sublists of l
of length n
, concatenated with L
.
Equations
- List.sublistsLenAux 0 x✝² x✝¹ x✝ = x✝¹ [] :: x✝
- List.sublistsLenAux n.succ [] x✝¹ x✝ = x✝
- List.sublistsLenAux n.succ (a :: l) x✝¹ x✝ = List.sublistsLenAux (n + 1) l x✝¹ (List.sublistsLenAux n l (x✝¹ ∘ List.cons a) x✝)
Instances For
The list of all sublists of a list l
that are of length n
. For instance, for
l = [0, 1, 2, 3]
and n = 2
, one gets
[[2, 3], [1, 3], [1, 2], [0, 3], [0, 2], [0, 1]]
.
Equations
- List.sublistsLen n l = List.sublistsLenAux n l id []
Instances For
theorem
List.sublistsLenAux_eq
{α : Type u}
{β : Type v}
(l : List α)
(n : ℕ)
(f : List α → β)
(r : List β)
:
List.sublistsLenAux n l f r = List.map f (List.sublistsLen n l) ++ r
theorem
List.sublistsLenAux_zero
{α : Type u}
{β : Type v}
(l : List α)
(f : List α → β)
(r : List β)
:
List.sublistsLenAux 0 l f r = f [] :: r
@[simp]
@[simp]
theorem
List.sublistsLen_succ_cons
{α : Type u}
(n : ℕ)
(a : α)
(l : List α)
:
List.sublistsLen (n + 1) (a :: l) = List.sublistsLen (n + 1) l ++ List.map (List.cons a) (List.sublistsLen n l)
theorem
List.sublistsLen_one
{α : Type u}
(l : List α)
:
List.sublistsLen 1 l = List.map (fun (x : α) => [x]) l.reverse
@[simp]
theorem
List.length_sublistsLen
{α : Type u}
(n : ℕ)
(l : List α)
:
(List.sublistsLen n l).length = l.length.choose n
theorem
List.sublistsLen_sublist_sublists'
{α : Type u}
(n : ℕ)
(l : List α)
:
(List.sublistsLen n l).Sublist l.sublists'
theorem
List.sublistsLen_sublist_of_sublist
{α : Type u}
(n : ℕ)
{l₁ l₂ : List α}
(h : l₁.Sublist l₂)
:
(List.sublistsLen n l₁).Sublist (List.sublistsLen n l₂)
theorem
List.length_of_sublistsLen
{α : Type u}
{n : ℕ}
{l l' : List α}
:
l' ∈ List.sublistsLen n l → l'.length = n
theorem
List.mem_sublistsLen_self
{α : Type u}
{l l' : List α}
(h : l'.Sublist l)
:
l' ∈ List.sublistsLen l'.length l
@[simp]
theorem
List.mem_sublistsLen
{α : Type u}
{n : ℕ}
{l l' : List α}
:
l' ∈ List.sublistsLen n l ↔ l'.Sublist l ∧ l'.length = n
theorem
List.sublistsLen_of_length_lt
{α : Type u}
{n : ℕ}
{l : List α}
(h : l.length < n)
:
List.sublistsLen n l = []
@[simp]
theorem
List.Pairwise.sublists'
{α : Type u}
{R : α → α → Prop}
{l : List α}
:
List.Pairwise R l → List.Pairwise (List.Lex (Function.swap R)) l.sublists'
theorem
List.pairwise_sublists
{α : Type u}
{R : α → α → Prop}
{l : List α}
(H : List.Pairwise R l)
:
List.Pairwise (List.Lex R on List.reverse) l.sublists
Alias of the reverse direction of List.nodup_sublists
.
Alias of the forward direction of List.nodup_sublists
.
Alias of the forward direction of List.nodup_sublists'
.
theorem
List.nodup_sublistsLen
{α : Type u}
(n : ℕ)
{l : List α}
(h : l.Nodup)
:
(List.sublistsLen n l).Nodup
theorem
List.range_bind_sublistsLen_perm
{α : Type u}
(l : List α)
:
((List.range (l.length + 1)).flatMap fun (n : ℕ) => List.sublistsLen n l).Perm l.sublists'