The areas / V33. Data structures and computation
Mathlib.Data.Stream.Defs
37 declarations. Mathlib docs · Source
Definition of Stream' and functions on streams
A stream Stream' α is an infinite sequence of elements of α. One can also think about it as an
infinite list. In this file we define Stream' and some functions that take and/or return streams.
Note that we already have Stream to represent a similar object, hence the awkward naming.
def Stream' E3 #
Type u → Type u
A stream Stream' α is an infinite sequence of elements of α.
def Stream'.cons E1 #
{α : Type u} → α → Stream' α → Stream' α
Prepend an element to a stream.
def Stream'.«term_::_» E1 #
Lean.TrailingParserDescr
Prepend an element to a stream.
def Stream'.get E1 #
{α : Type u} → Stream' α → ℕ → α
Get the n-th element of a stream.
abbrev Stream'.head E1 #
{α : Type u} → Stream' α → α
Head of a stream: Stream'.head s = Stream'.get s 0.
def Stream'.tail E1 #
{α : Type u} → Stream' α → Stream' α
Tail of a stream: Stream'.tail (h :: t) = t.
def Stream'.drop E1 #
{α : Type u} → ℕ → Stream' α → Stream' α
Drop first n elements of a stream.
def Stream'.All E1 #
{α : Type u} → (α → Prop) → Stream' α → Prop
Proposition saying that all elements of a stream satisfy a predicate.
def Stream'.Any E1 #
{α : Type u} → (α → Prop) → Stream' α → Prop
Proposition saying that at least one element of a stream satisfies a predicate.
instance Stream'.instMembership E0 #
{α : Type u} → Membership α (Stream' α)
a ∈ s means that a = Stream'.get n s for some n.
def Stream'.map E1 #
{α : Type u} → {β : Type v} → (α → β) → Stream' α → Stream' β
Apply a function f to all elements of a stream s.
def Stream'.zip E1 #
{α : Type u} → {β : Type v} → {δ : Type w} → (α → β → δ) → Stream' α → Stream' β → Stream' δ
Zip two streams using a binary operation:
Stream'.get n (Stream'.zip f s₁ s₂) = f (Stream'.get s₁) (Stream'.get s₂).
def Stream'.enum E1 #
{α : Type u} → Stream' α → Stream' (ℕ × α)
Enumerate a stream by tagging each element with its index.
def Stream'.const E1 #
{α : Type u} → α → Stream' α
The constant stream: Stream'.get n (Stream'.const a) = a.
def Stream'.iterate E1 #
{α : Type u} → (α → α) → α → Stream' α
Iterates of a function as a stream.
def Stream'.corec E1 #
{α : Type u} → {β : Type v} → (α → β) → (α → α) → α → Stream' β
Given functions f : α → β and g : α → α, corec f g creates a stream by:
- Starting with an initial value
a : α - Applying
grepeatedly to get a stream of α values - Applying
fto each value to convert them to β
def Stream'.corecOn E1 #
{α : Type u} → {β : Type v} → α → (α → β) → (α → α) → Stream' β
Given an initial value a : α and functions f : α → β and g : α → α,
corecOn a f g creates a stream by repeatedly:
- Applying
fto the current value to get the next stream element - Applying
gto get the next value to process
This is equivalent to corec f g a.
def Stream'.corec' E1 #
{α : Type u} → {β : Type v} → (α → β × α) → α → Stream' β
Given a function f : α → β × α, corec' f creates a stream by repeatedly:
- Starting with an initial value
a : α - Applying
fto get both the next stream element (β) and next state value (α)
This is a more convenient form when the next element and state are computed together.
def Stream'.corecState E1 #
{σ α : Type u_1} → StateM σ α → σ → Stream' α
Use a state monad to generate a stream through corecursion
abbrev Stream'.unfolds E1 #
{α : Type u} → {β : Type v} → (α → β) → (α → α) → α → Stream' β
def Stream'.interleave E1 #
{α : Type u} → Stream' α → Stream' α → Stream' α
Interleave two streams.
def Stream'.«term_⋈_» E1 #
Lean.TrailingParserDescr
Interleave two streams.
def Stream'.even E1 #
{α : Type u} → Stream' α → Stream' α
Elements of a stream with even indices.
def Stream'.odd E1 #
{α : Type u} → Stream' α → Stream' α
Elements of a stream with odd indices.
def Stream'.appendStream' E1 #
{α : Type u} → List α → Stream' α → Stream' α
Append a stream to a list.
def Stream'.«term_++ₛ_» E1 #
Lean.TrailingParserDescr
Append a stream to a list.
def Stream'.take E1 #
{α : Type u} → ℕ → Stream' α → List α
take n s returns a list of the n first elements of stream s
def Stream'.cycleF E1 #
{α : Type u} → α × List α × α × List α → α
An auxiliary definition for Stream'.cycle corecursive def
def Stream'.cycleG E1 #
{α : Type u} → α × List α × α × List α → α × List α × α × List α
An auxiliary definition for Stream'.cycle corecursive def
def Stream'.cycle E1 #
{α : Type u} → (l : List α) → l ≠ [] → Stream' α
Interpret a nonempty list as a cyclic stream.
def Stream'.tails E1 #
{α : Type u} → Stream' α → Stream' (Stream' α)
Tails of a stream, starting with Stream'.tail s.
def Stream'.initsCore E1 #
{α : Type u} → List α → Stream' α → Stream' (List α)
An auxiliary definition for Stream'.inits.
def Stream'.inits E1 #
{α : Type u} → Stream' α → Stream' (List α)
Nonempty initial segments of a stream.
def Stream'.pure E1 #
{α : Type u} → α → Stream' α
A constant stream, same as Stream'.const.
def Stream'.apply E1 #
{α : Type u} → {β : Type v} → Stream' (α → β) → Stream' α → Stream' β
Given a stream of functions and a stream of values, apply n-th function to n-th value.
def Stream'.«term_⊛_» E1 #
Lean.TrailingParserDescr
Given a stream of functions and a stream of values, apply n-th function to n-th value.
def Stream'.nats E1 #
Stream' ℕ
The stream of natural numbers: Stream'.get n Stream'.nats = n.