The areas / V33. Data structures and computation
Mathlib.Data.WSeq.Basic
128 declarations. Mathlib docs · Source
Partially defined possibly infinite lists
This file provides a WSeq α type representing partially defined possibly infinite lists
(referred here as weak sequences).
theorem Stream'.WSeq.join.match_1.congr_eq_2 E1 #
∀ {α : Type u_1} (motive : Option (Stream'.WSeq α) → Sort u_2) (o : Option (Stream'.WSeq α)) (h_1 : Unit → motive none)
(h_2 : (s : Stream'.WSeq α) → motive (some s)) (s : Stream'.WSeq α),
o = some s →
(match o with
| none => h_1 ()
| some s => h_2 s) ≍
h_2 s
theorem Stream'.WSeq.flatten.match_1.congr_eq_2 E1 #
∀ {α : Type u_1} (motive : Stream'.WSeq α ⊕ Computation (Stream'.WSeq α) → Sort u_2)
(x : Stream'.WSeq α ⊕ Computation (Stream'.WSeq α)) (h_1 : (s : Stream'.WSeq α) → motive (Sum.inl s))
(h_2 : (c' : Computation (Stream'.WSeq α)) → motive (Sum.inr c')) (c' : Computation (Stream'.WSeq α)),
x = Sum.inr c' →
(match x with
| Sum.inl s => h_1 s
| Sum.inr c' => h_2 c') ≍
h_2 c'
theorem Stream'.WSeq.tail.aux.match_1.congr_eq_2 E1 #
∀ {α : Type u_1} (motive : Option (α × Stream'.WSeq α) → Sort u_2) (x : Option (α × Stream'.WSeq α))
(h_1 : Unit → motive none) (h_2 : (fst : α) → (s : Stream'.WSeq α) → motive (some (fst, s))) (fst : α)
(s : Stream'.WSeq α),
x = some (fst, s) →
(match x with
| none => h_1 ()
| some (fst, s) => h_2 fst s) ≍
h_2 fst s
theorem Stream'.WSeq.destruct.match_1.congr_eq_1 E1 #
∀ {α : Type u_1} (motive : Option (Stream'.Seq1 (Option α)) → Sort u_2) (x : Option (Stream'.Seq1 (Option α)))
(h_1 : Unit → motive none) (h_2 : (s' : Stream'.Seq (Option α)) → motive (some (none, s')))
(h_3 : (a : α) → (s' : Stream'.Seq (Option α)) → motive (some (some a, s'))),
x = none →
(match x with
| none => h_1 ()
| some (none, s') => h_2 s'
| some (some a, s') => h_3 a s') ≍
h_1 ()
theorem Stream'.WSeq.drop.match_1.congr_eq_1 E1 #
∀ (motive : ℕ → Sort u_1) (x : ℕ) (h_1 : Unit → motive 0) (h_2 : (n : ℕ) → motive n.succ),
x = 0 →
(match x with
| 0 => h_1 ()
| n.succ => h_2 n) ≍
h_1 ()
theorem Stream'.WSeq.drop.match_1.congr_eq_2 E1 #
∀ (motive : ℕ → Sort u_1) (x : ℕ) (h_1 : Unit → motive 0) (h_2 : (n : ℕ) → motive n.succ) (n : ℕ),
x = n.succ →
(match x with
| 0 => h_1 ()
| n.succ => h_2 n) ≍
h_2 n
theorem Stream'.WSeq.destruct.match_1.congr_eq_2 E1 #
∀ {α : Type u_1} (motive : Option (Stream'.Seq1 (Option α)) → Sort u_2) (x : Option (Stream'.Seq1 (Option α)))
(h_1 : Unit → motive none) (h_2 : (s' : Stream'.Seq (Option α)) → motive (some (none, s')))
(h_3 : (a : α) → (s' : Stream'.Seq (Option α)) → motive (some (some a, s'))) (s' : Stream'.Seq (Option α)),
x = some (none, s') →
(match x with
| none => h_1 ()
| some (none, s') => h_2 s'
| some (some a, s') => h_3 a s') ≍
h_2 s'
theorem Stream'.WSeq.destruct.match_1.congr_eq_3 E1 #
∀ {α : Type u_1} (motive : Option (Stream'.Seq1 (Option α)) → Sort u_2) (x : Option (Stream'.Seq1 (Option α)))
(h_1 : Unit → motive none) (h_2 : (s' : Stream'.Seq (Option α)) → motive (some (none, s')))
(h_3 : (a : α) → (s' : Stream'.Seq (Option α)) → motive (some (some a, s'))) (a : α) (s' : Stream'.Seq (Option α)),
x = some (some a, s') →
(match x with
| none => h_1 ()
| some (none, s') => h_2 s'
| some (some a, s') => h_3 a s') ≍
h_3 a s'
theorem Stream'.WSeq.join.match_1.congr_eq_1 E1 #
∀ {α : Type u_1} (motive : Option (Stream'.WSeq α) → Sort u_2) (o : Option (Stream'.WSeq α)) (h_1 : Unit → motive none)
(h_2 : (s : Stream'.WSeq α) → motive (some s)),
o = none →
(match o with
| none => h_1 ()
| some s => h_2 s) ≍
h_1 ()
theorem Stream'.WSeq.flatten.match_1.congr_eq_1 E1 #
∀ {α : Type u_1} (motive : Stream'.WSeq α ⊕ Computation (Stream'.WSeq α) → Sort u_2)
(x : Stream'.WSeq α ⊕ Computation (Stream'.WSeq α)) (h_1 : (s : Stream'.WSeq α) → motive (Sum.inl s))
(h_2 : (c' : Computation (Stream'.WSeq α)) → motive (Sum.inr c')) (s : Stream'.WSeq α),
x = Sum.inl s →
(match x with
| Sum.inl s => h_1 s
| Sum.inr c' => h_2 c') ≍
h_1 s
theorem Stream'.WSeq.destruct_join.aux.match_1.congr_eq_2 E1 #
∀ {α : Type u_1} (motive : Option (Stream'.WSeq α × Stream'.WSeq (Stream'.WSeq α)) → Sort u_2)
(x : Option (Stream'.WSeq α × Stream'.WSeq (Stream'.WSeq α))) (h_1 : Unit → motive none)
(h_2 : (s : Stream'.WSeq α) → (S : Stream'.WSeq (Stream'.WSeq α)) → motive (some (s, S))) (s : Stream'.WSeq α)
(S : Stream'.WSeq (Stream'.WSeq α)),
x = some (s, S) →
(match x with
| none => h_1 ()
| some (s, S) => h_2 s S) ≍
h_2 s S
theorem Stream'.WSeq.destruct_join.aux.match_1.congr_eq_1 E1 #
∀ {α : Type u_1} (motive : Option (Stream'.WSeq α × Stream'.WSeq (Stream'.WSeq α)) → Sort u_2)
(x : Option (Stream'.WSeq α × Stream'.WSeq (Stream'.WSeq α))) (h_1 : Unit → motive none)
(h_2 : (s : Stream'.WSeq α) → (S : Stream'.WSeq (Stream'.WSeq α)) → motive (some (s, S))),
x = none →
(match x with
| none => h_1 ()
| some (s, S) => h_2 s S) ≍
h_1 ()
theorem Stream'.WSeq.tail.aux.match_1.congr_eq_1 E1 #
∀ {α : Type u_1} (motive : Option (α × Stream'.WSeq α) → Sort u_2) (x : Option (α × Stream'.WSeq α))
(h_1 : Unit → motive none) (h_2 : (fst : α) → (s : Stream'.WSeq α) → motive (some (fst, s))),
x = none →
(match x with
| none => h_1 ()
| some (fst, s) => h_2 fst s) ≍
h_1 ()
def Stream'.WSeq E3 #
Type u_1 → Type u_1
Weak sequences.
While the Seq structure allows for lists which may not be finite,
a weak sequence also allows the computation of each element to
involve an indeterminate amount of computation, including possibly
an infinite loop. This is represented as a regular Seq interspersed
with none elements to indicate that computation is ongoing.
This model is appropriate for Haskell style lazy lists, and is closed under most interesting computation patterns on infinite lists, but conversely it is difficult to extract elements from it.
def Stream'.WSeq.ofSeq E1 #
{α : Type u} → Stream'.Seq α → Stream'.WSeq α
Turn a sequence into a weak sequence
def Stream'.WSeq.ofList E1 #
{α : Type u} → List α → Stream'.WSeq α
Turn a list into a weak sequence
def Stream'.WSeq.ofStream E1 #
{α : Type u} → Stream' α → Stream'.WSeq α
Turn a stream into a weak sequence
instance Stream'.WSeq.coeSeq E0 #
{α : Type u} → Coe (Stream'.Seq α) (Stream'.WSeq α)
instance Stream'.WSeq.coeList E0 #
{α : Type u} → Coe (List α) (Stream'.WSeq α)
instance Stream'.WSeq.coeStream E0 #
{α : Type u} → Coe (Stream' α) (Stream'.WSeq α)
def Stream'.WSeq.nil E1 #
{α : Type u} → Stream'.WSeq α
The empty weak sequence
instance Stream'.WSeq.inhabited E0 #
{α : Type u} → Inhabited (Stream'.WSeq α)
def Stream'.WSeq.cons E1 #
{α : Type u} → α → Stream'.WSeq α → Stream'.WSeq α
Prepend an element to a weak sequence
def Stream'.WSeq.think E1 #
{α : Type u} → Stream'.WSeq α → Stream'.WSeq α
Compute for one tick, without producing any elements
def Stream'.WSeq.destruct E1 #
{α : Type u} → Stream'.WSeq α → Computation (Option (α × Stream'.WSeq α))
Destruct a weak sequence, to (eventually possibly) produce either
none for nil or some (a, s) if an element is produced.
def Stream'.WSeq.recOn E1 #
{α : Type u} →
{motive : Stream'.WSeq α → Sort v} →
(s : Stream'.WSeq α) →
motive Stream'.WSeq.nil →
((x : α) → (s : Stream'.WSeq α) → motive (Stream'.WSeq.cons x s)) →
((s : Stream'.WSeq α) → motive s.think) → motive s
Recursion principle for weak sequences, compare with List.recOn.
def Stream'.WSeq.Mem E1 #
{α : Type u} → Stream'.WSeq α → α → Prop
membership for weak sequences
instance Stream'.WSeq.membership E0 #
{α : Type u} → Membership α (Stream'.WSeq α)
theorem Stream'.WSeq.notMem_nil E1 #
∀ {α : Type u} (a : α), a ∉ Stream'.WSeq.nil
def Stream'.WSeq.head E1 #
{α : Type u} → Stream'.WSeq α → Computation (Option α)
Get the head of a weak sequence. This involves a possibly infinite computation.
def Stream'.WSeq.flatten E1 #
{α : Type u} → Computation (Stream'.WSeq α) → Stream'.WSeq α
Encode a computation yielding a weak sequence into additional
think constructors in a weak sequence
def Stream'.WSeq.tail E1 #
{α : Type u} → Stream'.WSeq α → Stream'.WSeq α
Get the tail of a weak sequence. This doesn't need a Computation
wrapper, unlike head, because flatten allows us to hide this
in the construction of the weak sequence itself.
def Stream'.WSeq.drop E1 #
{α : Type u} → Stream'.WSeq α → ℕ → Stream'.WSeq α
drop the first n elements from s.
def Stream'.WSeq.get? E1 #
{α : Type u} → Stream'.WSeq α → ℕ → Computation (Option α)
Get the nth element of s.
def Stream'.WSeq.toList E1 #
{α : Type u} → Stream'.WSeq α → Computation (List α)
Convert s to a list (if it is finite and completes in finite time).
def Stream'.WSeq.append E1 #
{α : Type u} → Stream'.WSeq α → Stream'.WSeq α → Stream'.WSeq α
Append two weak sequences. As with Seq.append, this may not use
the second sequence if the first one takes forever to compute
def Stream'.WSeq.join E1 #
{α : Type u} → Stream'.WSeq (Stream'.WSeq α) → Stream'.WSeq α
Flatten a sequence of weak sequences. (Note that this allows
empty sequences, unlike Seq.join.)
def Stream'.WSeq.map E1 #
{α : Type u} → {β : Type v} → (α → β) → Stream'.WSeq α → Stream'.WSeq β
Map a function over a weak sequence
def Stream'.WSeq.ret E1 #
{α : Type u} → α → Stream'.WSeq α
The monadic return a is a singleton list containing a.
def Stream'.WSeq.bind E1 #
{α : Type u} → {β : Type v} → Stream'.WSeq α → (α → Stream'.WSeq β) → Stream'.WSeq β
Monadic bind operator for weak sequences
instance Stream'.WSeq.monad E0 #
Monad Stream'.WSeq
Unfortunately, WSeq is not a lawful monad, because it does not satisfy the monad laws exactly,
only up to sequence equivalence. Furthermore, even quotienting by the equivalence is not sufficient,
because the join operation involves lists of quotient elements, with a lifted equivalence relation,
and pure quotients cannot handle this type of construction.
theorem Stream'.WSeq.destruct_nil E0 #
∀ {α : Type u}, Stream'.WSeq.nil.destruct = Computation.pure none
theorem Stream'.WSeq.destruct_cons E0 #
∀ {α : Type u} (a : α) (s : Stream'.WSeq α), (Stream'.WSeq.cons a s).destruct = Computation.pure (some (a, s))
theorem Stream'.WSeq.destruct_think E0 #
∀ {α : Type u} (s : Stream'.WSeq α), s.think.destruct = s.destruct.think
theorem Stream'.WSeq.seq_destruct_nil E0 #
∀ {α : Type u}, Stream'.Seq.destruct Stream'.WSeq.nil = none
theorem Stream'.WSeq.seq_destruct_cons E0 #
∀ {α : Type u} (a : α) (s : Stream'.WSeq α), Stream'.Seq.destruct (Stream'.WSeq.cons a s) = some (some a, s)
theorem Stream'.WSeq.seq_destruct_think E0 #
∀ {α : Type u} (s : Stream'.WSeq α), Stream'.Seq.destruct s.think = some (none, s)
theorem Stream'.WSeq.head_nil E0 #
∀ {α : Type u}, Stream'.WSeq.nil.head = Computation.pure none
theorem Stream'.WSeq.head_cons E0 #
∀ {α : Type u} (a : α) (s : Stream'.WSeq α), (Stream'.WSeq.cons a s).head = Computation.pure (some a)
theorem Stream'.WSeq.head_think E0 #
∀ {α : Type u} (s : Stream'.WSeq α), s.think.head = s.head.think
theorem Stream'.WSeq.flatten_pure E0 #
∀ {α : Type u} (s : Stream'.WSeq α), Stream'.WSeq.flatten (Computation.pure s) = s
theorem Stream'.WSeq.flatten_think E0 #
∀ {α : Type u} (c : Computation (Stream'.WSeq α)), Stream'.WSeq.flatten c.think = (Stream'.WSeq.flatten c).think
theorem Stream'.WSeq.destruct_flatten E0 #
∀ {α : Type u} (c : Computation (Stream'.WSeq α)), (Stream'.WSeq.flatten c).destruct = c >>= Stream'.WSeq.destruct
theorem Stream'.WSeq.head_terminates_iff E0 #
∀ {α : Type u} (s : Stream'.WSeq α), s.head.Terminates ↔ s.destruct.Terminates
theorem Stream'.WSeq.tail_nil E0 #
∀ {α : Type u}, Stream'.WSeq.nil.tail = Stream'.WSeq.nil
theorem Stream'.WSeq.tail_cons E0 #
∀ {α : Type u} (a : α) (s : Stream'.WSeq α), (Stream'.WSeq.cons a s).tail = s
theorem Stream'.WSeq.tail_think E0 #
∀ {α : Type u} (s : Stream'.WSeq α), s.think.tail = s.tail.think
theorem Stream'.WSeq.dropn_nil E0 #
∀ {α : Type u} (n : ℕ), Stream'.WSeq.nil.drop n = Stream'.WSeq.nil
theorem Stream'.WSeq.dropn_cons E0 #
∀ {α : Type u} (a : α) (s : Stream'.WSeq α) (n : ℕ), (Stream'.WSeq.cons a s).drop (n + 1) = s.drop n
theorem Stream'.WSeq.dropn_think E0 #
∀ {α : Type u} (s : Stream'.WSeq α) (n : ℕ), s.think.drop n = (s.drop n).think
theorem Stream'.WSeq.dropn_add E1 #
∀ {α : Type u} (s : Stream'.WSeq α) (m n : ℕ), s.drop (m + n) = (s.drop m).drop n
theorem Stream'.WSeq.dropn_tail E1 #
∀ {α : Type u} (s : Stream'.WSeq α) (n : ℕ), s.tail.drop n = s.drop (n + 1)
theorem Stream'.WSeq.get?_add E1 #
∀ {α : Type u} (s : Stream'.WSeq α) (m n : ℕ), s.get? (m + n) = (s.drop m).get? n
theorem Stream'.WSeq.get?_tail E1 #
∀ {α : Type u} (s : Stream'.WSeq α) (n : ℕ), s.tail.get? n = s.get? (n + 1)
theorem Stream'.WSeq.join_nil E0 #
∀ {α : Type u}, Stream'.WSeq.nil.join = Stream'.WSeq.nil
theorem Stream'.WSeq.join_think E0 #
∀ {α : Type u} (S : Stream'.WSeq (Stream'.WSeq α)), S.think.join = S.join.think
theorem Stream'.WSeq.join_cons E0 #
∀ {α : Type u} (s : Stream'.WSeq α) (S : Stream'.WSeq (Stream'.WSeq α)),
(Stream'.WSeq.cons s S).join = (s.append S.join).think
theorem Stream'.WSeq.nil_append E0 #
∀ {α : Type u} (s : Stream'.WSeq α), Stream'.WSeq.nil.append s = s
theorem Stream'.WSeq.cons_append E0 #
∀ {α : Type u} (a : α) (s t : Stream'.WSeq α), (Stream'.WSeq.cons a s).append t = Stream'.WSeq.cons a (s.append t)
theorem Stream'.WSeq.think_append E0 #
∀ {α : Type u} (s t : Stream'.WSeq α), s.think.append t = (s.append t).think
theorem Stream'.WSeq.append_nil E0 #
∀ {α : Type u} (s : Stream'.WSeq α), s.append Stream'.WSeq.nil = s
theorem Stream'.WSeq.append_assoc E0 #
∀ {α : Type u} (s t u : Stream'.WSeq α), (s.append t).append u = s.append (t.append u)
def Stream'.WSeq.tail.aux E1 #
{α : Type u} → Option (α × Stream'.WSeq α) → Computation (Option (α × Stream'.WSeq α))
auxiliary definition of tail over weak sequences
theorem Stream'.WSeq.destruct_tail E1 #
∀ {α : Type u} (s : Stream'.WSeq α), s.tail.destruct = s.destruct >>= Stream'.WSeq.tail.aux
def Stream'.WSeq.drop.aux E1 #
{α : Type u} → ℕ → Option (α × Stream'.WSeq α) → Computation (Option (α × Stream'.WSeq α))
auxiliary definition of drop over weak sequences
theorem Stream'.WSeq.drop.aux_none E1 #
∀ {α : Type u} (n : ℕ), Stream'.WSeq.drop.aux n none = Computation.pure none
theorem Stream'.WSeq.destruct_dropn E1 #
∀ {α : Type u} (s : Stream'.WSeq α) (n : ℕ), (s.drop n).destruct = s.destruct >>= Stream'.WSeq.drop.aux n
theorem Stream'.WSeq.head_terminates_of_head_tail_terminates E1 #
∀ {α : Type u} (s : Stream'.WSeq α) [T : s.tail.head.Terminates], s.head.Terminates
theorem Stream'.WSeq.destruct_some_of_destruct_tail_some E1 #
∀ {α : Type u} {s : Stream'.WSeq α} {a : α × Stream'.WSeq α}, some a ∈ s.tail.destruct → ∃ a', some a' ∈ s.destruct
theorem Stream'.WSeq.head_some_of_head_tail_some E1 #
∀ {α : Type u} {s : Stream'.WSeq α} {a : α}, some a ∈ s.tail.head → ∃ a', some a' ∈ s.head
theorem Stream'.WSeq.head_some_of_get?_some E1 #
∀ {α : Type u} {s : Stream'.WSeq α} {a : α} {n : ℕ}, some a ∈ s.get? n → ∃ a', some a' ∈ s.head
theorem Stream'.WSeq.get?_terminates_le E1 #
∀ {α : Type u} {s : Stream'.WSeq α} {m n : ℕ}, m ≤ n → (s.get? n).Terminates → (s.get? m).Terminates
theorem Stream'.WSeq.head_terminates_of_get?_terminates E1 #
∀ {α : Type u} {s : Stream'.WSeq α} {n : ℕ}, (s.get? n).Terminates → s.head.Terminates
theorem Stream'.WSeq.destruct_terminates_of_get?_terminates E1 #
∀ {α : Type u} {s : Stream'.WSeq α} {n : ℕ}, (s.get? n).Terminates → s.destruct.Terminates
theorem Stream'.WSeq.mem_rec_on E0 #
∀ {α : Type u} {C : Stream'.WSeq α → Prop} {a : α} {s : Stream'.WSeq α},
a ∈ s →
(∀ (b : α) (s' : Stream'.WSeq α), a = b ∨ C s' → C (Stream'.WSeq.cons b s')) →
(∀ (s : Stream'.WSeq α), C s → C s.think) → C s
theorem Stream'.WSeq.mem_think E0 #
∀ {α : Type u} (s : Stream'.WSeq α) (a : α), a ∈ s.think ↔ a ∈ s
theorem Stream'.WSeq.mem_cons_iff E0 #
∀ {α : Type u} (s : Stream'.WSeq α) (b : α) {a : α}, a ∈ Stream'.WSeq.cons b s ↔ a = b ∨ a ∈ s
theorem Stream'.WSeq.mem_cons_of_mem E0 #
∀ {α : Type u} {s : Stream'.WSeq α} (b : α) {a : α}, a ∈ s → a ∈ Stream'.WSeq.cons b s
theorem Stream'.WSeq.mem_cons E0 #
∀ {α : Type u} (s : Stream'.WSeq α) (a : α), a ∈ Stream'.WSeq.cons a s
theorem Stream'.WSeq.mem_of_mem_tail E0 #
∀ {α : Type u} {s : Stream'.WSeq α} {a : α}, a ∈ s.tail → a ∈ s
theorem Stream'.WSeq.mem_of_mem_dropn E0 #
∀ {α : Type u} {s : Stream'.WSeq α} {a : α} {n : ℕ}, a ∈ s.drop n → a ∈ s
theorem Stream'.WSeq.get?_mem E1 #
∀ {α : Type u} {s : Stream'.WSeq α} {a : α} {n : ℕ}, some a ∈ s.get? n → a ∈ s
theorem Stream'.WSeq.exists_get?_of_mem E1 #
∀ {α : Type u} {s : Stream'.WSeq α} {a : α}, a ∈ s → ∃ n, some a ∈ s.get? n
theorem Stream'.WSeq.exists_dropn_of_mem E1 #
∀ {α : Type u} {s : Stream'.WSeq α} {a : α}, a ∈ s → ∃ n s', some (a, s') ∈ (s.drop n).destruct
theorem Stream'.WSeq.head_terminates_of_mem E1 #
∀ {α : Type u} {s : Stream'.WSeq α} {a : α}, a ∈ s → s.head.Terminates
theorem Stream'.WSeq.of_mem_append E1 #
∀ {α : Type u} {s₁ s₂ : Stream'.WSeq α} {a : α}, a ∈ s₁.append s₂ → a ∈ s₁ ∨ a ∈ s₂
theorem Stream'.WSeq.mem_append_left E0 #
∀ {α : Type u} {s₁ s₂ : Stream'.WSeq α} {a : α}, a ∈ s₁ → a ∈ s₁.append s₂
theorem Stream'.WSeq.exists_of_mem_map E1 #
∀ {α : Type u} {β : Type v} {f : α → β} {b : β} {s : Stream'.WSeq α}, b ∈ Stream'.WSeq.map f s → ∃ a ∈ s, f a = b
theorem Stream'.WSeq.ofList_nil E0 #
∀ {α : Type u}, ↑[] = Stream'.WSeq.nil
theorem Stream'.WSeq.ofList_cons E0 #
∀ {α : Type u} (a : α) (l : List α), ↑(a :: l) = Stream'.WSeq.cons a ↑l
theorem Stream'.WSeq.toList'_nil E0 #
∀ {α : Type u} (l : List α),
Computation.corec
(fun x ↦
match x with
| (l, s) =>
match Stream'.Seq.destruct s with
| none => Sum.inl l.reverse
| some (none, s') => Sum.inr (l, s')
| some (some a, s') => Sum.inr (a :: l, s'))
(l, Stream'.WSeq.nil) =
Computation.pure l.reverse
theorem Stream'.WSeq.toList'_cons E0 #
∀ {α : Type u} (l : List α) (s : Stream'.WSeq α) (a : α),
Computation.corec
(fun x ↦
match x with
| (l, s) =>
match Stream'.Seq.destruct s with
| none => Sum.inl l.reverse
| some (none, s') => Sum.inr (l, s')
| some (some a, s') => Sum.inr (a :: l, s'))
(l, Stream'.WSeq.cons a s) =
(Computation.corec
(fun x ↦
match x with
| (l, s) =>
match Stream'.Seq.destruct s with
| none => Sum.inl l.reverse
| some (none, s') => Sum.inr (l, s')
| some (some a, s') => Sum.inr (a :: l, s'))
(a :: l, s)).think
theorem Stream'.WSeq.toList'_think E0 #
∀ {α : Type u} (l : List α) (s : Stream'.WSeq α),
Computation.corec
(fun x ↦
match x with
| (l, s) =>
match Stream'.Seq.destruct s with
| none => Sum.inl l.reverse
| some (none, s') => Sum.inr (l, s')
| some (some a, s') => Sum.inr (a :: l, s'))
(l, s.think) =
(Computation.corec
(fun x ↦
match x with
| (l, s) =>
match Stream'.Seq.destruct s with
| none => Sum.inl l.reverse
| some (none, s') => Sum.inr (l, s')
| some (some a, s') => Sum.inr (a :: l, s'))
(l, s)).think
theorem Stream'.WSeq.toList'_map E1 #
∀ {α : Type u} (l : List α) (s : Stream'.WSeq α),
Computation.corec
(fun x ↦
match x with
| (l, s) =>
match Stream'.Seq.destruct s with
| none => Sum.inl l.reverse
| some (none, s') => Sum.inr (l, s')
| some (some a, s') => Sum.inr (a :: l, s'))
(l, s) =
(fun x ↦ l.reverse ++ x) <$> s.toList
theorem Stream'.WSeq.toList_cons E0 #
∀ {α : Type u} (a : α) (s : Stream'.WSeq α), (Stream'.WSeq.cons a s).toList = (List.cons a <$> s.toList).think
theorem Stream'.WSeq.toList_nil E0 #
∀ {α : Type u}, Stream'.WSeq.nil.toList = Computation.pure []
theorem Stream'.WSeq.toList_ofList E1 #
∀ {α : Type u} (l : List α), l ∈ (↑l).toList
theorem Stream'.WSeq.destruct_ofSeq E0 #
∀ {α : Type u} (s : Stream'.Seq α), (↑s).destruct = Computation.pure (Option.map (fun a ↦ (a, ↑s.tail)) s.head)
theorem Stream'.WSeq.head_ofSeq E0 #
∀ {α : Type u} (s : Stream'.Seq α), (↑s).head = Computation.pure s.head
theorem Stream'.WSeq.tail_ofSeq E0 #
∀ {α : Type u} (s : Stream'.Seq α), (↑s).tail = ↑s.tail
theorem Stream'.WSeq.dropn_ofSeq E0 #
∀ {α : Type u} (s : Stream'.Seq α) (n : ℕ), (↑s).drop n = ↑(s.drop n)
theorem Stream'.WSeq.get?_ofSeq E1 #
∀ {α : Type u} (s : Stream'.Seq α) (n : ℕ), (↑s).get? n = Computation.pure (s.get? n)
theorem Stream'.WSeq.map_nil E0 #
∀ {α : Type u} {β : Type v} (f : α → β), Stream'.WSeq.map f Stream'.WSeq.nil = Stream'.WSeq.nil
theorem Stream'.WSeq.map_cons E0 #
∀ {α : Type u} {β : Type v} (f : α → β) (a : α) (s : Stream'.WSeq α),
Stream'.WSeq.map f (Stream'.WSeq.cons a s) = Stream'.WSeq.cons (f a) (Stream'.WSeq.map f s)
theorem Stream'.WSeq.map_think E0 #
∀ {α : Type u} {β : Type v} (f : α → β) (s : Stream'.WSeq α), Stream'.WSeq.map f s.think = (Stream'.WSeq.map f s).think
theorem Stream'.WSeq.map_id E0 #
∀ {α : Type u} (s : Stream'.WSeq α), Stream'.WSeq.map id s = s
theorem Stream'.WSeq.map_ret E0 #
∀ {α : Type u} {β : Type v} (f : α → β) (a : α), Stream'.WSeq.map f (Stream'.WSeq.ret a) = Stream'.WSeq.ret (f a)
theorem Stream'.WSeq.map_append E0 #
∀ {α : Type u} {β : Type v} (f : α → β) (s t : Stream'.WSeq α),
Stream'.WSeq.map f (s.append t) = (Stream'.WSeq.map f s).append (Stream'.WSeq.map f t)
theorem Stream'.WSeq.map_comp E0 #
∀ {α : Type u} {β : Type v} {γ : Type w} (f : α → β) (g : β → γ) (s : Stream'.WSeq α),
Stream'.WSeq.map (g ∘ f) s = Stream'.WSeq.map g (Stream'.WSeq.map f s)
theorem Stream'.WSeq.mem_map E0 #
∀ {α : Type u} {β : Type v} (f : α → β) {a : α} {s : Stream'.WSeq α}, a ∈ s → f a ∈ Stream'.WSeq.map f s
theorem Stream'.WSeq.exists_of_mem_join E1 #
∀ {α : Type u} {a : α} {S : Stream'.WSeq (Stream'.WSeq α)}, a ∈ S.join → ∃ s ∈ S, a ∈ s
theorem Stream'.WSeq.exists_of_mem_bind E1 #
∀ {α : Type u} {β : Type v} {s : Stream'.WSeq α} {f : α → Stream'.WSeq β} {b : β}, b ∈ s.bind f → ∃ a ∈ s, b ∈ f a
theorem Stream'.WSeq.destruct_map E1 #
∀ {α : Type u} {β : Type v} (f : α → β) (s : Stream'.WSeq α),
(Stream'.WSeq.map f s).destruct = Computation.map (Option.map (Prod.map f (Stream'.WSeq.map f))) s.destruct
def Stream'.WSeq.destruct_append.aux E1 #
{α : Type u} → Stream'.WSeq α → Option (α × Stream'.WSeq α) → Computation (Option (α × Stream'.WSeq α))
auxiliary definition of destruct_append over weak sequences
theorem Stream'.WSeq.destruct_append E1 #
∀ {α : Type u} (s t : Stream'.WSeq α), (s.append t).destruct = s.destruct.bind (Stream'.WSeq.destruct_append.aux t)
def Stream'.WSeq.destruct_join.aux E1 #
{α : Type u} → Option (Stream'.WSeq α × Stream'.WSeq (Stream'.WSeq α)) → Computation (Option (α × Stream'.WSeq α))
auxiliary definition of destruct_join over weak sequences
theorem Stream'.WSeq.destruct_join E1 #
∀ {α : Type u} (S : Stream'.WSeq (Stream'.WSeq α)), S.join.destruct = S.destruct.bind Stream'.WSeq.destruct_join.aux
theorem Stream'.WSeq.map_join E0 #
∀ {α : Type u} {β : Type v} (f : α → β) (S : Stream'.WSeq (Stream'.WSeq α)),
Stream'.WSeq.map f S.join = (Stream'.WSeq.map (Stream'.WSeq.map f) S).join