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.
Prepend an element to a stream.
Equations
- Stream'.cons a s 0 = a
- Stream'.cons a s n.succ = s n
Instances For
Prepend an element to a stream.
Equations
- Stream'.«term_::_» = Lean.ParserDescr.trailingNode `Stream'.«term_::_» 67 68 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " :: ") (Lean.ParserDescr.cat `term 67))
Instances For
Tail of a stream: Stream'.tail (h :: t) = t.
Instances For
Proposition saying that all elements of a stream satisfy a predicate.
Equations
- Stream'.All p s = ∀ (n : ℕ), p (s.get n)
Instances For
a ∈ s means that a = Stream'.get n s for some n.
Equations
- Stream'.instMembership = { mem := fun (s : Stream' α) (a : α) => Stream'.Any (fun (b : α) => a = b) s }
Apply a function f to all elements of a stream s.
Equations
- Stream'.map f s n = f (s.get n)
Instances For
Zip two streams using a binary operation:
Stream'.get n (Stream'.zip f s₁ s₂) = f (Stream'.get s₁) (Stream'.get s₂).
Equations
- Stream'.zip f s₁ s₂ n = f (s₁.get n) (s₂.get n)
Instances For
The constant stream: Stream'.get n (Stream'.const a) = a.
Equations
- Stream'.const a x✝ = a
Instances For
Iterates of a function as a stream.
Equations
- Stream'.iterate f a 0 = a
- Stream'.iterate f a n.succ = f (Stream'.iterate f a n)
Instances For
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 β
Equations
- Stream'.corec f g a = Stream'.map f (Stream'.iterate g a)
Instances For
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 tocorec f g a.
Equations
- Stream'.corecOn a f g = Stream'.corec f g a
Instances For
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.
Equations
- Stream'.corec' f = Stream'.corec (Prod.fst ∘ f) (Prod.snd ∘ f)
Instances For
Use a state monad to generate a stream through corecursion
Equations
- Stream'.corecState cmd s = Stream'.corec Prod.fst (StateT.run cmd ∘ Prod.snd) (StateT.run cmd s)
Instances For
Interleave two streams.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Interleave two streams.
Equations
- Stream'.«term_⋈_» = Lean.ParserDescr.trailingNode `Stream'.«term_⋈_» 65 65 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ⋈ ") (Lean.ParserDescr.cat `term 66))
Instances For
Elements of a stream with even indices.
Equations
- s.even = Stream'.corec Stream'.head (fun (s : Stream' α) => s.tail.tail) s
Instances For
Append a stream to a list.
Equations
- Stream'.«term_++ₛ_» = Lean.ParserDescr.trailingNode `Stream'.«term_++ₛ_» 65 65 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ++ₛ ") (Lean.ParserDescr.cat `term 66))
Instances For
take n s returns a list of the n first elements of stream s
Equations
- Stream'.take 0 x✝ = []
- Stream'.take n.succ x✝ = x✝.head :: Stream'.take n x✝.tail
Instances For
Interpret a nonempty list as a cyclic stream.
Equations
- Stream'.cycle [] h = absurd ⋯ h
- Stream'.cycle (a :: l) x_2 = Stream'.corec Stream'.cycleF Stream'.cycleG (a, l, a, l)
Instances For
An auxiliary definition for Stream'.inits.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Given a stream of functions and a stream of values, apply n-th function to n-th value.
Equations
- Stream'.«term_⊛_» = Lean.ParserDescr.trailingNode `Stream'.«term_⊛_» 75 75 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ⊛ ") (Lean.ParserDescr.cat `term 76))
Instances For
The stream of natural numbers: Stream'.get n Stream'.nats = n.
Equations
- Stream'.nats n = n