mathlib documentation

data.seq.computation

def computation (α : Type u) :
Type u

computation α is the type of unbounded computations returning α. An element of computation α is an infinite sequence of option α such that if f n = some a for some n then it is constantly some a after that.

Equations
def computation.return {α : Type u} (a : α) :

return a is the computation that immediately terminates with result a.

Equations
@[instance]
def computation.has_coe_t {α : Type u} :

Equations
def computation.think {α : Type u} (c : computation α) :

think c is the computation that delays for one "tick" and then performs computation c.

Equations
def computation.thinkN {α : Type u} (c : computation α) (a : ) :

thinkN c n is the computation that delays for n ticks and then performs computation c.

Equations
def computation.head {α : Type u} (c : computation α) :

head c is the first step of computation, either some a if c = return a or none if c = think c'.

Equations
def computation.tail {α : Type u} (c : computation α) :

tail c is the remainder of computation, either c if c = return a or c' if c = think c'.

Equations
def computation.empty (α : Type u_1) :

empty α is the computation that never returns, an infinite sequence of thinks.

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

Equations
def computation.run_for {α : Type u} (a : computation α) (a_1 : ) :

run_for c n evaluates c for n steps and returns the result, or none if it did not terminate after n steps.

Equations
def computation.destruct {α : Type u} (c : computation α) :

destruct c is the destructor for computation α as a coinductive type. It returns inl a if c = return a and inr c' if c = think c'.

Equations
meta def computation.run {α : Type u} (a : computation α) :
α

run c is an unsound meta function that runs c to completion, possibly resulting in an infinite loop in the VM.

theorem computation.destruct_eq_ret {α : Type u} {s : computation α} {a : α} (a_1 : s.destruct = sum.inl a) :

theorem computation.destruct_eq_think {α : Type u} {s s' : computation α} (a : s.destruct = sum.inr s') :
s = s'.think

@[simp]
theorem computation.destruct_ret {α : Type u} (a : α) :

@[simp]
theorem computation.destruct_think {α : Type u} (s : computation α) :

@[simp]
theorem computation.head_ret {α : Type u} (a : α) :

@[simp]
theorem computation.head_think {α : Type u} (s : computation α) :

@[simp]
theorem computation.head_empty {α : Type u} :

@[simp]
theorem computation.tail_ret {α : Type u} (a : α) :

@[simp]
theorem computation.tail_think {α : Type u} (s : computation α) :

@[simp]

def computation.cases_on {α : Type u} {C : computation αSort v} (s : computation α) (h1 : Π (a : α), C (computation.return a)) (h2 : Π (s : computation α), C s.think) :
C s

Equations
def computation.corec.F {α : Type u} {β : Type v} (f : β → α β) (a : α β) :
option α × β)

Equations
def computation.corec {α : Type u} {β : Type v} (f : β → α β) (b : β) :

corec f b is the corecursor for computation α as a coinductive type. If f b = inl a then corec f b = return a, and if f b = inl b' then corec f b = think (corec f b').

Equations
@[simp]
def computation.lmap {α : Type u} {β : Type v} {γ : Type w} (f : α → β) (a : α γ) :
β γ

left map of

Equations
@[simp]
def computation.rmap {α : Type u} {β : Type v} {γ : Type w} (f : β → γ) (a : α β) :
α γ

right map of

Equations
@[simp]
theorem computation.corec_eq {α : Type u} {β : Type v} (f : β → α β) (b : β) :

@[simp]
def computation.bisim_o {α : Type u} (R : computation αcomputation α → Prop) (a a_1 : α computation α) :
Prop

Equations
def computation.is_bisimulation {α : Type u} (R : computation αcomputation α → Prop) :
Prop

Equations
theorem computation.eq_of_bisim {α : Type u} (R : computation αcomputation α → Prop) (bisim : computation.is_bisimulation R) {s₁ s₂ : computation α} (r : R s₁ s₂) :
s₁ = s₂

def computation.mem {α : Type u} (a : α) (s : computation α) :
Prop

Equations
@[instance]
def computation.has_mem {α : Type u} :

Equations
theorem computation.le_stable {α : Type u} (s : computation α) {a : α} {m n : } (h : m n) (a_1 : s.val m = some a) :
s.val n = some a

@[class]
def computation.terminates {α : Type u} (s : computation α) :
Prop

terminates s asserts that the computation s eventually terminates with some value.

Equations
Instances
theorem computation.terminates_of_mem {α : Type u} {s : computation α} {a : α} (a_1 : a s) :

theorem computation.terminates_def {α : Type u} (s : computation α) :
s.terminates ∃ (n : ), ((s.val n).is_some)

theorem computation.ret_mem {α : Type u} (a : α) :

theorem computation.eq_of_ret_mem {α : Type u} {a a' : α} (h : a' computation.return a) :
a' = a

@[instance]
def computation.ret_terminates {α : Type u} (a : α) :

theorem computation.think_mem {α : Type u} {s : computation α} {a : α} (a_1 : a s) :

@[instance]

theorem computation.of_think_mem {α : Type u} {s : computation α} {a : α} (a_1 : a s.think) :
a s

theorem computation.of_think_terminates {α : Type u} {s : computation α} (a : s.think.terminates) :

theorem computation.not_mem_empty {α : Type u} (a : α) :

theorem computation.thinkN_mem {α : Type u} {s : computation α} {a : α} (n : ) :
a s.thinkN n a s

@[instance]
def computation.thinkN_terminates {α : Type u} (s : computation α) [s.terminates] (n : ) :

theorem computation.of_thinkN_terminates {α : Type u} (s : computation α) (n : ) (a : (s.thinkN n).terminates) :

def computation.promises {α : Type u} (s : computation α) (a : α) :
Prop

promises s a, or s ~> a, asserts that although the computation s may not terminate, if it does, then the result is a.

Equations
  • s ~> a = ∀ ⦃a' : α⦄, a' sa = a'
theorem computation.mem_promises {α : Type u} {s : computation α} {a : α} (a_1 : a s) :
s ~> a

theorem computation.empty_promises {α : Type u} (a : α) :

def computation.length {α : Type u} (s : computation α) [h : s.terminates] :

length s gets the number of steps of a terminating computation

Equations
def computation.get {α : Type u} (s : computation α) [h : s.terminates] :
α

get s returns the result of a terminating computation

Equations
theorem computation.get_mem {α : Type u} (s : computation α) [h : s.terminates] :
s.get s

theorem computation.get_eq_of_mem {α : Type u} (s : computation α) [h : s.terminates] {a : α} (a_1 : a s) :
s.get = a

theorem computation.mem_of_get_eq {α : Type u} (s : computation α) [h : s.terminates] {a : α} (a_1 : s.get = a) :
a s

@[simp]
theorem computation.get_think {α : Type u} (s : computation α) [h : s.terminates] :

@[simp]
theorem computation.get_thinkN {α : Type u} (s : computation α) [h : s.terminates] (n : ) :
(s.thinkN n).get = s.get

theorem computation.get_promises {α : Type u} (s : computation α) [h : s.terminates] :
s ~> s.get

theorem computation.mem_of_promises {α : Type u} (s : computation α) [h : s.terminates] {a : α} (p : s ~> a) :
a s

theorem computation.get_eq_of_promises {α : Type u} (s : computation α) [h : s.terminates] {a : α} (a_1 : s ~> a) :
s.get = a

def computation.results {α : Type u} (s : computation α) (a : α) (n : ) :
Prop

results s a n completely characterizes a terminating computation: it asserts that s terminates after exactly n steps, with result a.

Equations
theorem computation.results_of_terminates {α : Type u} (s : computation α) [T : s.terminates] :

theorem computation.results_of_terminates' {α : Type u} (s : computation α) [T : s.terminates] {a : α} (h : a s) :

theorem computation.results.mem {α : Type u} {s : computation α} {a : α} {n : } (a_1 : s.results a n) :
a s

theorem computation.results.terminates {α : Type u} {s : computation α} {a : α} {n : } (h : s.results a n) :

theorem computation.results.length {α : Type u} {s : computation α} {a : α} {n : } [T : s.terminates] (a_1 : s.results a n) :
s.length = n

theorem computation.results.val_unique {α : Type u} {s : computation α} {a b : α} {m n : } (h1 : s.results a m) (h2 : s.results b n) :
a = b

theorem computation.results.len_unique {α : Type u} {s : computation α} {a b : α} {m n : } (h1 : s.results a m) (h2 : s.results b n) :
m = n

theorem computation.exists_results_of_mem {α : Type u} {s : computation α} {a : α} (h : a s) :
∃ (n : ), s.results a n

@[simp]
theorem computation.get_ret {α : Type u} (a : α) :

@[simp]
theorem computation.length_ret {α : Type u} (a : α) :

theorem computation.results_ret {α : Type u} (a : α) :

@[simp]
theorem computation.length_think {α : Type u} (s : computation α) [h : s.terminates] :

theorem computation.results_think {α : Type u} {s : computation α} {a : α} {n : } (h : s.results a n) :
s.think.results a (n + 1)

theorem computation.of_results_think {α : Type u} {s : computation α} {a : α} {n : } (h : s.think.results a n) :
∃ (m : ), s.results a m n = m + 1

@[simp]
theorem computation.results_think_iff {α : Type u} {s : computation α} {a : α} {n : } :
s.think.results a (n + 1) s.results a n

theorem computation.results_thinkN {α : Type u} {s : computation α} {a : α} {m : } (n : ) (a_1 : s.results a m) :
(s.thinkN n).results a (m + n)

theorem computation.results_thinkN_ret {α : Type u} (a : α) (n : ) :

@[simp]
theorem computation.length_thinkN {α : Type u} (s : computation α) [h : s.terminates] (n : ) :
(s.thinkN n).length = s.length + n

theorem computation.eq_thinkN {α : Type u} {s : computation α} {a : α} {n : } (h : s.results a n) :

theorem computation.eq_thinkN' {α : Type u} (s : computation α) [h : s.terminates] :

def computation.mem_rec_on {α : Type u} {C : computation αSort v} {a : α} {s : computation α} (M : a s) (h1 : C (computation.return a)) (h2 : Π (s : computation α), C sC s.think) :
C s

Equations
def computation.terminates_rec_on {α : Type u} {C : computation αSort v} (s : computation α) [s.terminates] (h1 : Π (a : α), C (computation.return a)) (h2 : Π (s : computation α), C sC s.think) :
C s

Equations
def computation.map {α : Type u} {β : Type v} (f : α → β) (a : computation α) :

Map a function on the result of a computation.

Equations
def computation.bind.G {α : Type u} {β : Type v} (a : β computation β) :

Equations
def computation.bind.F {α : Type u} {β : Type v} (f : α → computation β) (a : computation α computation β) :

Equations
def computation.bind {α : Type u} {β : Type v} (c : computation α) (f : α → computation β) :

Compose two computations into a monadic bind operation.

Equations
theorem computation.has_bind_eq_bind {α β : Type u} (c : computation α) (f : α → computation β) :
c >>= f = c.bind f

def computation.join {α : Type u} (c : computation (computation α)) :

Flatten a computation of computations into a single computation.

Equations
@[simp]
theorem computation.map_ret {α : Type u} {β : Type v} (f : α → β) (a : α) :

@[simp]
theorem computation.map_think {α : Type u} {β : Type v} (f : α → β) (s : computation α) :

@[simp]
theorem computation.destruct_map {α : Type u} {β : Type v} (f : α → β) (s : computation α) :

@[simp]
theorem computation.map_id {α : Type u} (s : computation α) :

theorem computation.map_comp {α : Type u} {β : Type v} {γ : Type w} (f : α → β) (g : β → γ) (s : computation α) :

@[simp]
theorem computation.ret_bind {α : Type u} {β : Type v} (a : α) (f : α → computation β) :

@[simp]
theorem computation.think_bind {α : Type u} {β : Type v} (c : computation α) (f : α → computation β) :
c.think.bind f = (c.bind f).think

@[simp]
theorem computation.bind_ret {α : Type u} {β : Type v} (f : α → β) (s : computation α) :

@[simp]
theorem computation.bind_ret' {α : Type u} (s : computation α) :

@[simp]
theorem computation.bind_assoc {α : Type u} {β : Type v} {γ : Type w} (s : computation α) (f : α → computation β) (g : β → computation γ) :
(s.bind f).bind g = s.bind (λ (x : α), (f x).bind g)

theorem computation.results_bind {α : Type u} {β : Type v} {s : computation α} {f : α → computation β} {a : α} {b : β} {m n : } (h1 : s.results a m) (h2 : (f a).results b n) :
(s.bind f).results b (n + m)

theorem computation.mem_bind {α : Type u} {β : Type v} {s : computation α} {f : α → computation β} {a : α} {b : β} (h1 : a s) (h2 : b f a) :
b s.bind f

@[instance]
def computation.terminates_bind {α : Type u} {β : Type v} (s : computation α) (f : α → computation β) [s.terminates] [(f s.get).terminates] :

@[simp]
theorem computation.get_bind {α : Type u} {β : Type v} (s : computation α) (f : α → computation β) [s.terminates] [(f s.get).terminates] :
(s.bind f).get = (f s.get).get

@[simp]
theorem computation.length_bind {α : Type u} {β : Type v} (s : computation α) (f : α → computation β) [T1 : s.terminates] [T2 : (f s.get).terminates] :
(s.bind f).length = (f s.get).length + s.length

theorem computation.of_results_bind {α : Type u} {β : Type v} {s : computation α} {f : α → computation β} {b : β} {k : } (a : (s.bind f).results b k) :
∃ (a : α) (m n : ), s.results a m (f a).results b n k = n + m

theorem computation.exists_of_mem_bind {α : Type u} {β : Type v} {s : computation α} {f : α → computation β} {b : β} (h : b s.bind f) :
∃ (a : α) (H : a s), b f a

theorem computation.bind_promises {α : Type u} {β : Type v} {s : computation α} {f : α → computation β} {a : α} {b : β} (h1 : s ~> a) (h2 : f a ~> b) :
s.bind f ~> b

theorem computation.has_map_eq_map {α β : Type u} (f : α → β) (c : computation α) :

@[simp]
theorem computation.return_def {α : Type u} (a : α) :

@[simp]
theorem computation.map_ret' {α β : Type u_1} (f : α → β) (a : α) :

@[simp]
theorem computation.map_think' {α β : Type u_1} (f : α → β) (s : computation α) :
f <$> s.think = (f <$> s).think

theorem computation.mem_map {α : Type u} {β : Type v} (f : α → β) {a : α} {s : computation α} (m : a s) :

theorem computation.exists_of_mem_map {α : Type u} {β : Type v} {f : α → β} {b : β} {s : computation α} (h : b computation.map f s) :
∃ (a : α), a s f a = b

@[instance]
def computation.terminates_map {α : Type u} {β : Type v} (f : α → β) (s : computation α) [s.terminates] :

theorem computation.terminates_map_iff {α : Type u} {β : Type v} (f : α → β) (s : computation α) :

def computation.orelse {α : Type u} (c₁ c₂ : computation α) :

c₁ <|> c₂ calculates c₁ and c₂ simultaneously, returning the first one that gives a result.

Equations
@[simp]
theorem computation.ret_orelse {α : Type u} (a : α) (c₂ : computation α) :

@[simp]
theorem computation.orelse_ret {α : Type u} (c₁ : computation α) (a : α) :

@[simp]
theorem computation.orelse_think {α : Type u} (c₁ c₂ : computation α) :
(c₁.think <|> c₂.think) = (c₁ <|> c₂).think

@[simp]
theorem computation.empty_orelse {α : Type u} (c : computation α) :

@[simp]
theorem computation.orelse_empty {α : Type u} (c : computation α) :

def computation.equiv {α : Type u} (c₁ c₂ : computation α) :
Prop

c₁ ~ c₂ asserts that c₁ and c₂ either both terminate with the same result, or both loop forever.

Equations
  • c₁ ~ c₂ = ∀ (a : α), a c₁ a c₂
theorem computation.equiv.refl {α : Type u} (s : computation α) :
s ~ s

theorem computation.equiv.symm {α : Type u} {s t : computation α} (a : s ~ t) :
t ~ s

theorem computation.equiv.trans {α : Type u} {s t u : computation α} (a : s ~ t) (a_1 : t ~ u) :
s ~ u

theorem computation.equiv_of_mem {α : Type u} {s t : computation α} {a : α} (h1 : a s) (h2 : a t) :
s ~ t

theorem computation.terminates_congr {α : Type u} {c₁ c₂ : computation α} (h : c₁ ~ c₂) :

theorem computation.promises_congr {α : Type u} {c₁ c₂ : computation α} (h : c₁ ~ c₂) (a : α) :
c₁ ~> a c₂ ~> a

theorem computation.get_equiv {α : Type u} {c₁ c₂ : computation α} (h : c₁ ~ c₂) [c₁.terminates] [c₂.terminates] :
c₁.get = c₂.get

theorem computation.think_equiv {α : Type u} (s : computation α) :
s.think ~ s

theorem computation.thinkN_equiv {α : Type u} (s : computation α) (n : ) :
s.thinkN n ~ s

theorem computation.bind_congr {α : Type u} {β : Type v} {s1 s2 : computation α} {f1 f2 : α → computation β} (h1 : s1 ~ s2) (h2 : ∀ (a : α), f1 a ~ f2 a) :
s1.bind f1 ~ s2.bind f2

theorem computation.equiv_ret_of_mem {α : Type u} {s : computation α} {a : α} (h : a s) :

def computation.lift_rel {α : Type u} {β : Type v} (R : α → β → Prop) (ca : computation α) (cb : computation β) :
Prop

lift_rel R ca cb is a generalization of equiv to relations other than equality. It asserts that if ca terminates with a, then cb terminates with some b such that R a b, and if cb terminates with b then ca terminates with some a such that R a b.

Equations
theorem computation.lift_rel.swap {α : Type u} {β : Type v} (R : α → β → Prop) (ca : computation α) (cb : computation β) :

theorem computation.lift_eq_iff_equiv {α : Type u} (c₁ c₂ : computation α) :
computation.lift_rel eq c₁ c₂ c₁ ~ c₂

theorem computation.lift_rel.refl {α : Type u} (R : α → α → Prop) (H : reflexive R) :

theorem computation.lift_rel.symm {α : Type u} (R : α → α → Prop) (H : symmetric R) :

theorem computation.lift_rel.trans {α : Type u} (R : α → α → Prop) (H : transitive R) :

theorem computation.lift_rel.equiv {α : Type u} (R : α → α → Prop) (a : equivalence R) :

theorem computation.lift_rel.imp {α : Type u} {β : Type v} {R S : α → β → Prop} (H : ∀ {a : α} {b : β}, R a bS a b) (s : computation α) (t : computation β) (a : computation.lift_rel R s t) :

theorem computation.terminates_of_lift_rel {α : Type u} {β : Type v} {R : α → β → Prop} {s : computation α} {t : computation β} (a : computation.lift_rel R s t) :

theorem computation.rel_of_lift_rel {α : Type u} {β : Type v} {R : α → β → Prop} {ca : computation α} {cb : computation β} (a : computation.lift_rel R ca cb) {a_1 : α} {b : β} (a_2 : a_1 ca) (a_3 : b cb) :
R a_1 b

theorem computation.lift_rel_of_mem {α : Type u} {β : Type v} {R : α → β → Prop} {a : α} {b : β} {ca : computation α} {cb : computation β} (ma : a ca) (mb : b cb) (ab : R a b) :

theorem computation.exists_of_lift_rel_left {α : Type u} {β : Type v} {R : α → β → Prop} {ca : computation α} {cb : computation β} (H : computation.lift_rel R ca cb) {a : α} (h : a ca) :
∃ {b : β}, b cb R a b

theorem computation.exists_of_lift_rel_right {α : Type u} {β : Type v} {R : α → β → Prop} {ca : computation α} {cb : computation β} (H : computation.lift_rel R ca cb) {b : β} (h : b cb) :
∃ {a : α}, a ca R a b

theorem computation.lift_rel_def {α : Type u} {β : Type v} {R : α → β → Prop} {ca : computation α} {cb : computation β} :
computation.lift_rel R ca cb (ca.terminates cb.terminates) ∀ {a : α} {b : β}, a cab cbR a b

theorem computation.lift_rel_bind {α : Type u} {β : Type v} {γ : Type w} {δ : Type u_1} (R : α → β → Prop) (S : γ → δ → Prop) {s1 : computation α} {s2 : computation β} {f1 : α → computation γ} {f2 : β → computation δ} (h1 : computation.lift_rel R s1 s2) (h2 : ∀ {a : α} {b : β}, R a bcomputation.lift_rel S (f1 a) (f2 b)) :
computation.lift_rel S (s1.bind f1) (s2.bind f2)

@[simp]
theorem computation.lift_rel_return_left {α : Type u} {β : Type v} (R : α → β → Prop) (a : α) (cb : computation β) :
computation.lift_rel R (computation.return a) cb ∃ {b : β}, b cb R a b

@[simp]
theorem computation.lift_rel_return_right {α : Type u} {β : Type v} (R : α → β → Prop) (ca : computation α) (b : β) :
computation.lift_rel R ca (computation.return b) ∃ {a : α}, a ca R a b

@[simp]
theorem computation.lift_rel_return {α : Type u} {β : Type v} (R : α → β → Prop) (a : α) (b : β) :

@[simp]
theorem computation.lift_rel_think_left {α : Type u} {β : Type v} (R : α → β → Prop) (ca : computation α) (cb : computation β) :

@[simp]
theorem computation.lift_rel_think_right {α : Type u} {β : Type v} (R : α → β → Prop) (ca : computation α) (cb : computation β) :

theorem computation.lift_rel_mem_cases {α : Type u} {β : Type v} {R : α → β → Prop} {ca : computation α} {cb : computation β} (Ha : ∀ (a : α), a cacomputation.lift_rel R ca cb) (Hb : ∀ (b : β), b cbcomputation.lift_rel R ca cb) :

theorem computation.lift_rel_congr {α : Type u} {β : Type v} {R : α → β → Prop} {ca ca' : computation α} {cb cb' : computation β} (ha : ca ~ ca') (hb : cb ~ cb') :

theorem computation.lift_rel_map {α : Type u} {β : Type v} {γ : Type w} {δ : Type u_1} (R : α → β → Prop) (S : γ → δ → Prop) {s1 : computation α} {s2 : computation β} {f1 : α → γ} {f2 : β → δ} (h1 : computation.lift_rel R s1 s2) (h2 : ∀ {a : α} {b : β}, R a bS (f1 a) (f2 b)) :

theorem computation.map_congr {α : Type u} {β : Type v} (R : α → α → Prop) (S : β → β → Prop) {s1 s2 : computation α} {f : α → β} (h1 : s1 ~ s2) :

@[simp]
def computation.lift_rel_aux {α : Type u} {β : Type v} (R : α → β → Prop) (C : computation αcomputation β → Prop) (a : α computation α) (a_1 : β computation β) :
Prop

Equations
@[simp]
theorem computation.lift_rel_aux.ret_left {α : Type u} {β : Type v} (R : α → β → Prop) (C : computation αcomputation β → Prop) (a : α) (cb : computation β) :
computation.lift_rel_aux R C (sum.inl a) cb.destruct ∃ {b : β}, b cb R a b

theorem computation.lift_rel_aux.swap {α : Type u} {β : Type v} (R : α → β → Prop) (C : computation αcomputation β → Prop) (a : α computation α) (b : β computation β) :

@[simp]
theorem computation.lift_rel_aux.ret_right {α : Type u} {β : Type v} (R : α → β → Prop) (C : computation αcomputation β → Prop) (b : β) (ca : computation α) :
computation.lift_rel_aux R C ca.destruct (sum.inl b) ∃ {a : α}, a ca R a b

theorem computation.lift_rel_rec.lem {α : Type u} {β : Type v} {R : α → β → Prop} (C : computation αcomputation β → Prop) (H : ∀ {ca : computation α} {cb : computation β}, C ca cbcomputation.lift_rel_aux R C ca.destruct cb.destruct) (ca : computation α) (cb : computation β) (Hc : C ca cb) (a : α) (ha : a ca) :

theorem computation.lift_rel_rec {α : Type u} {β : Type v} {R : α → β → Prop} (C : computation αcomputation β → Prop) (H : ∀ {ca : computation α} {cb : computation β}, C ca cbcomputation.lift_rel_aux R C ca.destruct cb.destruct) (ca : computation α) (cb : computation β) (Hc : C ca cb) :