Equations
- seq.inhabited = {default := seq.nil α}
A sequence has terminated at position n
if the value at position n
equals none
.
Equations
- s.terminated_at n = (s.nth n = none)
It is decidable whether a sequence terminates at a given position.
Equations
- s.terminated_at_decidable n = decidable_of_iff' ↥((s.nth n).is_none) _
A sequence terminates if there is some position n
at which it has terminated.
Equations
- s.terminates = ∃ (n : ℕ), s.terminated_at n
Equations
- seq.has_mem = {mem := seq.mem α}
If a sequence terminated at position n
, it also terminated at m ≥ n
.
Embed a list as a sequence
Equations
- seq.of_list l = ⟨l.nth, _⟩
Equations
- seq.coe_list = {coe := seq.of_list α}
Equations
- seq.is_bisimulation R = ∀ ⦃s₁ s₂ : seq α⦄, R s₁ s₂ → seq.bisim_o R s₁.destruct s₂.destruct
Embed an infinite stream as a sequence
Equations
- seq.of_stream s = ⟨stream.map some s, _⟩
Equations
- seq.coe_stream = {coe := seq.of_stream α}
Embed a lazy_list α
as a sequence. Note that even though this
is non-meta, it will produce infinite sequences if used with
cyclic lazy_list
s created by meta constructions.
Equations
- seq.of_lazy_list = seq.corec (λ (l : lazy_list α), seq.of_lazy_list._match_1 l)
- seq.of_lazy_list._match_1 (lazy_list.cons a l') = some (a, l' ())
- seq.of_lazy_list._match_1 lazy_list.nil = none
Equations
Translate a sequence to a list. This function will run forever if run on an infinite sequence.
Append two sequences. If s₁
is infinite, then s₁ ++ s₂ = s₁
,
otherwise it puts s₂
at the location of the nil
in s₁
.
Equations
Map a function over a sequence.
Equations
- seq.map f ⟨s, al⟩ = ⟨stream.map (option.map f) s, _⟩
Flatten a sequence of sequences. (It is required that the
sequences be nonempty to ensure productivity; in the case
of an infinite sequence of nil
, the first element is never
generated.)
Take the first n
elements of the sequence (producing a list)
Split a sequence at n
, producing a finite initial segment
and an infinite tail.
Equations
- seq.split_at (n + 1) s = seq.split_at._match_1 (λ (s' : seq α), seq.split_at n s') s.destruct
- seq.split_at 0 s = (list.nil α, s)
- seq.split_at._match_1 _f_1 (some (x, s')) = seq.split_at._match_2 x (_f_1 s')
- seq.split_at._match_1 _f_1 none = (list.nil α, seq.nil α)
- seq.split_at._match_2 x (l, r) = (x :: l, r)
Combine two sequences with a function
Equations
- seq.functor = {map := seq.map, map_const := λ (α β : Type u_1), seq.map ∘ function.const β}
Convert a sequence into a list, embedded in a computation to allow for the possibility of infinite sequences (in which case the computation never returns anything).
Convert a seq1
to a sequence.
Equations
- seq1.to_seq (a, s) = seq.cons a s
Equations
- seq1.coe_seq = {coe := seq1.to_seq α}
The bind
operator for the seq1
monad,
which maps f
on each element of s
and appends the results together.
(Not all of s
may be evaluated, because the first few elements of s
may already produce an infinite result.)