# mathlibdocumentation

data.lazy_list.basic

## Definitions on lazy lists

This file contains various definitions and proofs on lazy lists.

TODO: move the lazy_list.lean file from core to mathlib.

def thunk.mk {α : Type u_1} (x : α) :

Creates a thunk with a (non-lazy) constant value.

Equations
@[instance]
def thunk.decidable_eq {α : Type u} [decidable_eq α] :

Equations
def lazy_list.list_equiv_lazy_list (α : Type u_1) :
list α

Isomorphism between strict and lazy lists.

Equations
@[instance]
def lazy_list.inhabited {α : Type u} :

Equations
@[instance]
def lazy_list.decidable_eq {α : Type u} [decidable_eq α] :

Equations
• ys) = dite (x = y) (λ (h : x = y), lazy_list.decidable_eq._match_1 x xs y ys h (lazy_list.decidable_eq (xs ()) (ys ()))) (λ (h : ¬x = y), is_false _)
• = is_true lazy_list.decidable_eq._main._proof_1
• lazy_list.decidable_eq._match_1 x xs y ys h (is_true h2) = have this : xs = ys, from _,
• lazy_list.decidable_eq._match_1 x xs y ys h (is_false h2) =
def lazy_list.traverse {m : Type uType u} [applicative m] {α β : Type u} (f : α → m β) :
m (lazy_list β)

Traversal of lazy lists using an applicative effect.

Equations
@[instance]

Equations
@[instance]

Equations
def lazy_list.init {α : Type u_1} :

init xs, if xs non-empty, drops the last element of the list. Otherwise, return the empty list.

Equations
def lazy_list.find {α : Type u_1} (p : α → Prop)  :

Return the first object contained in the list that satisfies predicate p

Equations
def lazy_list.interleave {α : Type u_1} :

interleave xs ys creates a list where elements of xs and ys alternate.

Equations
def lazy_list.interleave_all {α : Type u_1} :
list (lazy_list α)

interleave_all (xs::ys::zs::xss) creates a list where elements of xs, ys and zs and the rest alternate. Every other element of the resulting list is taken from xs, every fourth is taken from ys, every eighth is taken from zs and so on.

Equations
def lazy_list.bind {α : Type u_1} {β : Type u_2} :
(α →

Monadic bind operation for lazy_list.

Equations
def lazy_list.reverse {α : Type u_1} (xs : lazy_list α) :

Reverse the order of a lazy_list. It is done by converting to a list first because reversal involves evaluating all the list and if the list is all evaluated, list is a better representation for it than a series of thunks.

Equations
@[instance]

Equations
theorem lazy_list.append_nil {α : Type u_1} (xs : lazy_list α) :
xs.append (λ («_» : unit), lazy_list.nil) = xs

theorem lazy_list.append_assoc {α : Type u_1} (xs ys zs : lazy_list α) :
(xs.append (λ («_» : unit), ys)).append (λ («_» : unit), zs) = xs.append (λ («_» : unit), ys.append (λ («_» : unit), zs))

theorem lazy_list.append_bind {α : Type u_1} {β : Type u_2} (xs : lazy_list α) (ys : thunk (lazy_list α)) (f : α → ) :
(xs.append ys).bind f = (xs.bind f).append (λ («_» : unit), (ys ()).bind f)

@[instance]

def lazy_list.mfirst {m : Type u_1Type u_2} [alternative m] {α : Type u_3} {β : Type u_1} (f : α → m β) :
m β

Try applying function f to every element of a lazy_list and return the result of the first attempt that succeeds.

Equations
def lazy_list.mem {α : Type u_1} (x : α) :
→ Prop

Membership in lazy lists

Equations
@[instance]
def lazy_list.has_mem {α : out_param (Type u_1)} :
(lazy_list α)

Equations
@[instance]
def lazy_list.mem.decidable {α : Type u_1} [decidable_eq α] (x : α) (xs : lazy_list α) :
decidable (x xs)

Equations
@[simp]
theorem lazy_list.mem_nil {α : Type u_1} (x : α) :

@[simp]
theorem lazy_list.mem_cons {α : Type u_1} (x y : α) (ys : thunk (lazy_list α)) :
x ys x = y x ys ()

theorem lazy_list.forall_mem_cons {α : Type u_1} {p : α → Prop} {a : α} {l : thunk (lazy_list α)} :
(∀ (x : α), x p x) p a ∀ (x : α), x l ()p x

### map for partial functions

@[simp]
def lazy_list.pmap {α : Type u_1} {β : Type u_2} {p : α → Prop} (f : Π (a : α), p a → β) (l : lazy_list α) :
(∀ (a : α), a lp a)

Partial map. If f : Π a, p a → β is a partial function defined on a : α satisfying p, then pmap f l h is essentially the same as map f l but is defined only when all members of l satisfy p, using the proof to apply f.

Equations
def lazy_list.attach {α : Type u_1} (l : lazy_list α) :
lazy_list {x // x l}

"Attach" the proof that the elements of l are in l to produce a new lazy_list with the same elements but in the type {x // x ∈ l}.

Equations
@[instance]
def lazy_list.has_repr {α : Type u_1} [has_repr α] :

Equations