The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V33. Data structures and computation

Mathlib.Data.Seq.Computation

195 declarations. Mathlib docs · Source

theorem Computation.run.match_1.congr_eq_2 E1 #

∀ {α : Type u_1} (motive : α ⊕ Computation α → Sort u_2) (x : α ⊕ Computation α) (h_1 : (a : α) → motive (Sum.inl a))
  (h_2 : (ca : Computation α) → motive (Sum.inr ca)) (ca : Computation α),
  x = Sum.inr ca →
    (match x with
      | Sum.inl a => h_1 a
      | Sum.inr ca => h_2 ca) ≍
      h_2 ca

theorem Computation.LiftRelAux.match_1.congr_eq_1 E1 #

∀ {α : Type u_1} {β : Type u_2} (motive : α ⊕ Computation α → β ⊕ Computation β → Sort u_3) (x : α ⊕ Computation α)
  (x_1 : β ⊕ Computation β) (h_1 : (a : α) → (b : β) → motive (Sum.inl a) (Sum.inl b))
  (h_2 : (a : α) → (cb : Computation β) → motive (Sum.inl a) (Sum.inr cb))
  (h_3 : (ca : Computation α) → (b : β) → motive (Sum.inr ca) (Sum.inl b))
  (h_4 : (ca : Computation α) → (cb : Computation β) → motive (Sum.inr ca) (Sum.inr cb)) (a : α) (b : β),
  x = Sum.inl a →
    x_1 = Sum.inl b →
      (match x, x_1 with
        | Sum.inl a, Sum.inl b => h_1 a b
        | Sum.inl a, Sum.inr cb => h_2 a cb
        | Sum.inr ca, Sum.inl b => h_3 ca b
        | Sum.inr ca, Sum.inr cb => h_4 ca cb) ≍
        h_1 a b

theorem Computation.BisimO.match_1.congr_eq_2 E1 #

∀ {α : Type u_1} (motive : α ⊕ Computation α → α ⊕ Computation α → Sort u_2) (x x_1 : α ⊕ Computation α)
  (h_1 : (a a' : α) → motive (Sum.inl a) (Sum.inl a')) (h_2 : (s s' : Computation α) → motive (Sum.inr s) (Sum.inr s'))
  (h_3 : (x x_2 : α ⊕ Computation α) → motive x x_2) (s s' : Computation α),
  x = Sum.inr s →
    x_1 = Sum.inr s' →
      (match x, x_1 with
        | Sum.inl a, Sum.inl a' => h_1 a a'
        | Sum.inr s, Sum.inr s' => h_2 s s'
        | x, x_2 => h_3 x x_2) ≍
        h_2 s s'

theorem Computation.Bind.f.match_1.congr_eq_2 E1 #

∀ {α : Type u_1} {β : Type u_2} (motive : Computation α ⊕ Computation β → Sort u_3) (x : Computation α ⊕ Computation β)
  (h_1 : (ca : Computation α) → motive (Sum.inl ca)) (h_2 : (cb : Computation β) → motive (Sum.inr cb))
  (cb : Computation β),
  x = Sum.inr cb →
    (match x with
      | Sum.inl ca => h_1 ca
      | Sum.inr cb => h_2 cb) ≍
      h_2 cb

theorem Computation.run.match_1.congr_eq_1 E1 #

∀ {α : Type u_1} (motive : α ⊕ Computation α → Sort u_2) (x : α ⊕ Computation α) (h_1 : (a : α) → motive (Sum.inl a))
  (h_2 : (ca : Computation α) → motive (Sum.inr ca)) (a : α),
  x = Sum.inl a →
    (match x with
      | Sum.inl a => h_1 a
      | Sum.inr ca => h_2 ca) ≍
      h_1 a

theorem Computation.LiftRelAux.match_1.congr_eq_4 E1 #

∀ {α : Type u_1} {β : Type u_2} (motive : α ⊕ Computation α → β ⊕ Computation β → Sort u_3) (x : α ⊕ Computation α)
  (x_1 : β ⊕ Computation β) (h_1 : (a : α) → (b : β) → motive (Sum.inl a) (Sum.inl b))
  (h_2 : (a : α) → (cb : Computation β) → motive (Sum.inl a) (Sum.inr cb))
  (h_3 : (ca : Computation α) → (b : β) → motive (Sum.inr ca) (Sum.inl b))
  (h_4 : (ca : Computation α) → (cb : Computation β) → motive (Sum.inr ca) (Sum.inr cb)) (ca : Computation α)
  (cb : Computation β),
  x = Sum.inr ca →
    x_1 = Sum.inr cb →
      (match x, x_1 with
        | Sum.inl a, Sum.inl b => h_1 a b
        | Sum.inl a, Sum.inr cb => h_2 a cb
        | Sum.inr ca, Sum.inl b => h_3 ca b
        | Sum.inr ca, Sum.inr cb => h_4 ca cb) ≍
        h_4 ca cb

theorem Computation.Corec.f.match_1.congr_eq_1 E1 #

∀ {α : Type u_1} {β : Type u_2} (motive : α ⊕ β → Sort u_3) (x : α ⊕ β) (h_1 : (a : α) → motive (Sum.inl a))
  (h_2 : (val : β) → motive (Sum.inr val)) (a : α),
  x = Sum.inl a →
    (match x with
      | Sum.inl a => h_1 a
      | Sum.inr val => h_2 val) ≍
      h_1 a

theorem Computation.LiftRelAux.match_1.congr_eq_3 E1 #

∀ {α : Type u_1} {β : Type u_2} (motive : α ⊕ Computation α → β ⊕ Computation β → Sort u_3) (x : α ⊕ Computation α)
  (x_1 : β ⊕ Computation β) (h_1 : (a : α) → (b : β) → motive (Sum.inl a) (Sum.inl b))
  (h_2 : (a : α) → (cb : Computation β) → motive (Sum.inl a) (Sum.inr cb))
  (h_3 : (ca : Computation α) → (b : β) → motive (Sum.inr ca) (Sum.inl b))
  (h_4 : (ca : Computation α) → (cb : Computation β) → motive (Sum.inr ca) (Sum.inr cb)) (ca : Computation α) (b : β),
  x = Sum.inr ca →
    x_1 = Sum.inl b →
      (match x, x_1 with
        | Sum.inl a, Sum.inl b => h_1 a b
        | Sum.inl a, Sum.inr cb => h_2 a cb
        | Sum.inr ca, Sum.inl b => h_3 ca b
        | Sum.inr ca, Sum.inr cb => h_4 ca cb) ≍
        h_3 ca b

theorem Computation.LiftRelAux.match_1.congr_eq_2 E1 #

∀ {α : Type u_1} {β : Type u_2} (motive : α ⊕ Computation α → β ⊕ Computation β → Sort u_3) (x : α ⊕ Computation α)
  (x_1 : β ⊕ Computation β) (h_1 : (a : α) → (b : β) → motive (Sum.inl a) (Sum.inl b))
  (h_2 : (a : α) → (cb : Computation β) → motive (Sum.inl a) (Sum.inr cb))
  (h_3 : (ca : Computation α) → (b : β) → motive (Sum.inr ca) (Sum.inl b))
  (h_4 : (ca : Computation α) → (cb : Computation β) → motive (Sum.inr ca) (Sum.inr cb)) (a : α) (cb : Computation β),
  x = Sum.inl a →
    x_1 = Sum.inr cb →
      (match x, x_1 with
        | Sum.inl a, Sum.inl b => h_1 a b
        | Sum.inl a, Sum.inr cb => h_2 a cb
        | Sum.inr ca, Sum.inl b => h_3 ca b
        | Sum.inr ca, Sum.inr cb => h_4 ca cb) ≍
        h_2 a cb

theorem Computation.Bind.f.match_1.congr_eq_1 E1 #

∀ {α : Type u_1} {β : Type u_2} (motive : Computation α ⊕ Computation β → Sort u_3) (x : Computation α ⊕ Computation β)
  (h_1 : (ca : Computation α) → motive (Sum.inl ca)) (h_2 : (cb : Computation β) → motive (Sum.inr cb))
  (ca : Computation α),
  x = Sum.inl ca →
    (match x with
      | Sum.inl ca => h_1 ca
      | Sum.inr cb => h_2 cb) ≍
      h_1 ca

theorem Computation.orElse.match_1.congr_eq_1 E1 #

∀ {α : Type u_1} (motive : Computation α × Computation α → Sort u_2) (x : Computation α × Computation α)
  (h_1 : (c₁ c₂ : Computation α) → motive (c₁, c₂)) (c₁ c₂ : Computation α),
  x = (c₁, c₂) →
    (match x with
      | (c₁, c₂) => h_1 c₁ c₂) ≍
      h_1 c₁ c₂

theorem Computation.map.match_1.congr_eq_1 E1 #

∀ {α : Type u_1} (motive : Computation α → Sort u_2) (x : Computation α)
  (h_1 : (s : Stream' (Option α)) → (al : ∀ ⦃n : ℕ⦄ ⦃a : α⦄, s n = some a → s (n + 1) = some a) → motive ⟨s, al⟩)
  (s : Stream' (Option α)) (al : ∀ ⦃n : ℕ⦄ ⦃a : α⦄, s n = some a → s (n + 1) = some a),
  x = ⟨s, al⟩ →
    (match x with
      | ⟨s, al⟩ => h_1 s al) ≍
      h_1 s al

theorem Computation.BisimO.match_1.congr_eq_1 E1 #

∀ {α : Type u_1} (motive : α ⊕ Computation α → α ⊕ Computation α → Sort u_2) (x x_1 : α ⊕ Computation α)
  (h_1 : (a a' : α) → motive (Sum.inl a) (Sum.inl a')) (h_2 : (s s' : Computation α) → motive (Sum.inr s) (Sum.inr s'))
  (h_3 : (x x_2 : α ⊕ Computation α) → motive x x_2) (a a' : α),
  x = Sum.inl a →
    x_1 = Sum.inl a' →
      (match x, x_1 with
        | Sum.inl a, Sum.inl a' => h_1 a a'
        | Sum.inr s, Sum.inr s' => h_2 s s'
        | x, x_2 => h_3 x x_2) ≍
        h_1 a a'

theorem Computation.Corec.f.match_1.congr_eq_2 E1 #

∀ {α : Type u_1} {β : Type u_2} (motive : α ⊕ β → Sort u_3) (x : α ⊕ β) (h_1 : (a : α) → motive (Sum.inl a))
  (h_2 : (val : β) → motive (Sum.inr val)) (val : β),
  x = Sum.inr val →
    (match x with
      | Sum.inl a => h_1 a
      | Sum.inr val => h_2 val) ≍
      h_2 val

theorem Computation.BisimO.match_1.congr_eq_3 E1 #

∀ {α : Type u_1} (motive : α ⊕ Computation α → α ⊕ Computation α → Sort u_2) (x x_1 : α ⊕ Computation α)
  (h_1 : (a a' : α) → motive (Sum.inl a) (Sum.inl a')) (h_2 : (s s' : Computation α) → motive (Sum.inr s) (Sum.inr s'))
  (h_3 : (x x_2 : α ⊕ Computation α) → motive x x_2) (x_2 x_3 : α ⊕ Computation α),
  x = x_2 →
    x_1 = x_3 →
      (∀ (a a' : α), x_2 = Sum.inl a → x_3 = Sum.inl a' → False) →
        (∀ (s s' : Computation α), x_2 = Sum.inr s → x_3 = Sum.inr s' → False) →
          (match x, x_1 with
            | Sum.inl a, Sum.inl a' => h_1 a a'
            | Sum.inr s, Sum.inr s' => h_2 s s'
            | x, x_6 => h_3 x x_6) ≍
            h_3 x_2 x_3

def Computation E1 #

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.

def Computation.pure E1 #

{α : Type u} → α → Computation α

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

instance Computation.instCoeTC E0 #

{α : Type u} → CoeTC α (Computation α)

def Computation.think E1 #

{α : Type u} → Computation α → Computation α

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

def Computation.thinkN E1 #

{α : Type u} → Computation α → ℕ → Computation α

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

def Computation.head E1 #

{α : Type u} → Computation α → Option α

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

def Computation.tail E1 #

{α : Type u} → Computation α → Computation α

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

def Computation.empty E1 #

(α : Type u_1) → Computation α

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

instance Computation.instInhabited E0 #

{α : Type u} → Inhabited (Computation α)

def Computation.runFor E1 #

{α : Type u} → Computation α → ℕ → Option α

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

def Computation.destruct E1 #

{α : Type u} → Computation α → α ⊕ Computation α

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

def Computation.run E1 #

{α : Type u} → 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_pure E1 #

∀ {α : Type u} {s : Computation α} {a : α}, s.destruct = Sum.inl a → s = Computation.pure a

theorem Computation.destruct_eq_think E1 #

∀ {α : Type u} {s s' : Computation α}, s.destruct = Sum.inr s' → s = s'.think

theorem Computation.destruct_pure E0 #

∀ {α : Type u} (a : α), (Computation.pure a).destruct = Sum.inl a

theorem Computation.destruct_think E0 #

∀ {α : Type u} (s : Computation α), s.think.destruct = Sum.inr s

theorem Computation.destruct_empty E0 #

∀ {α : Type u}, (Computation.empty α).destruct = Sum.inr (Computation.empty α)

theorem Computation.head_pure E0 #

∀ {α : Type u} (a : α), (Computation.pure a).head = some a

theorem Computation.head_think E0 #

∀ {α : Type u} (s : Computation α), s.think.head = none

theorem Computation.head_empty E0 #

∀ {α : Type u}, (Computation.empty α).head = none

theorem Computation.tail_pure E0 #

∀ {α : Type u} (a : α), (Computation.pure a).tail = Computation.pure a

theorem Computation.tail_think E0 #

∀ {α : Type u} (s : Computation α), s.think.tail = s

theorem Computation.tail_empty E0 #

∀ {α : Type u}, (Computation.empty α).tail = Computation.empty α

theorem Computation.think_empty E1 #

∀ {α : Type u}, Computation.empty α = (Computation.empty α).think

def Computation.recOn E1 #

{α : Type u} →
  {motive : Computation α → Sort v} →
    (s : Computation α) → ((a : α) → motive (Computation.pure a)) → ((s : Computation α) → motive s.think) → motive s

Recursion principle for computations, compare with List.recOn.

def Computation.Corec.f E1 #

{α : Type u} → {β : Type v} → (β → α ⊕ β) → α ⊕ β → Option α × (α ⊕ β)

Corecursor constructor for corec

def Computation.corec E1 #

{α : Type u} → {β : Type v} → (β → α ⊕ β) → β → Computation α

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

def Computation.lmap E1 #

{α : Type u} → {β : Type v} → {γ : Type w} → (α → β) → α ⊕ γ → β ⊕ γ

left map of ⊕

def Computation.rmap E1 #

{α : Type u} → {β : Type v} → {γ : Type w} → (β → γ) → α ⊕ β → α ⊕ γ

right map of ⊕

theorem Computation.corec_eq E0 #

∀ {α : Type u} {β : Type v} (f : β → α ⊕ β) (b : β),
  (Computation.corec f b).destruct = Computation.rmap (Computation.corec f) (f b)

def Computation.BisimO E1 #

{α : Type u} → (Computation α → Computation α → Prop) → α ⊕ Computation α → α ⊕ Computation α → Prop

Bisimilarity over a sum of Computations

def Computation.IsBisimulation E1 #

{α : Type u} → (Computation α → Computation α → Prop) → Prop

Attribute expressing bisimilarity over two Computations

def Computation.Mem E1 #

{α : Type u} → Computation α → α → Prop

Assertion that a Computation limits to a given value

instance Computation.instMembership E0 #

{α : Type u} → Membership α (Computation α)

theorem Computation.le_stable E1 #

∀ {α : Type u} (s : Computation α) {a : α} {m n : ℕ}, m ≤ n → ↑s m = some a → ↑s n = some a

theorem Computation.mem_unique E0 #

∀ {α : Type u} {s : Computation α} {a b : α}, a ∈ s → b ∈ s → a = b

theorem Computation.Mem.left_unique E1 #

∀ {α : Type u}, Relator.LeftUnique fun x1 x2 ↦ x1 ∈ x2

class Computation.Terminates E1 #

{α : Type u} → Computation α → Prop

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

ctor Computation.Terminates.mk E0 #

∀ {α : Type u} {s : Computation α}, (∃ a, a ∈ s) → s.Terminates

theorem Computation.Terminates.term E1 #

∀ {α : Type u} {s : Computation α} [self : s.Terminates], ∃ a, a ∈ s

assertion that there is some term a such that the Computation terminates

theorem Computation.terminates_iff E0 #

∀ {α : Type u} (s : Computation α), s.Terminates ↔ ∃ a, a ∈ s

theorem Computation.terminates_of_mem E1 #

∀ {α : Type u} {s : Computation α} {a : α}, a ∈ s → s.Terminates

theorem Computation.terminates_def E0 #

∀ {α : Type u} (s : Computation α), s.Terminates ↔ ∃ n, (↑s n).isSome = true

theorem Computation.ret_mem E1 #

∀ {α : Type u} (a : α), a ∈ Computation.pure a

theorem Computation.mem_pure_iff E0 #

∀ {α : Type u} (a b : α), a ∈ Computation.pure b ↔ a = b

instance Computation.ret_terminates E0 #

∀ {α : Type u} (a : α), (Computation.pure a).Terminates

theorem Computation.think_mem E1 #

∀ {α : Type u} {s : Computation α} {a : α}, a ∈ s → a ∈ s.think

instance Computation.think_terminates E0 #

∀ {α : Type u} (s : Computation α) [s.Terminates], s.think.Terminates

theorem Computation.of_think_mem E1 #

∀ {α : Type u} {s : Computation α} {a : α}, a ∈ s.think → a ∈ s

theorem Computation.of_think_terminates E1 #

∀ {α : Type u} {s : Computation α}, s.think.Terminates → s.Terminates

theorem Computation.notMem_empty E1 #

∀ {α : Type u} (a : α), a ∉ Computation.empty α

theorem Computation.not_terminates_empty E1 #

∀ {α : Type u}, ¬(Computation.empty α).Terminates

theorem Computation.thinkN_mem E1 #

∀ {α : Type u} {s : Computation α} {a : α} (n : ℕ), a ∈ s.thinkN n ↔ a ∈ s

instance Computation.thinkN_terminates E0 #

∀ {α : Type u} (s : Computation α) [s.Terminates] (n : ℕ), (s.thinkN n).Terminates

theorem Computation.of_thinkN_terminates E1 #

∀ {α : Type u} (s : Computation α) (n : ℕ), (s.thinkN n).Terminates → s.Terminates

def Computation.Promises E1 #

{α : Type u} → Computation α → α → Prop

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

def Computation.«term_~>_» E1 #

Lean.TrailingParserDescr

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

theorem Computation.mem_promises E0 #

∀ {α : Type u} {s : Computation α} {a : α}, a ∈ s → s.Promises a

theorem Computation.empty_promises E1 #

∀ {α : Type u} (a : α), (Computation.empty α).Promises a

def Computation.length E1 #

{α : Type u} → (s : Computation α) → [h : s.Terminates] → ℕ

length s gets the number of steps of a terminating computation

def Computation.get E1 #

{α : Type u} → (s : Computation α) → [h : s.Terminates] → α

get s returns the result of a terminating computation

theorem Computation.get_mem E1 #

∀ {α : Type u} (s : Computation α) [h : s.Terminates], s.get ∈ s

theorem Computation.get_eq_of_mem E1 #

∀ {α : Type u} (s : Computation α) [h : s.Terminates] {a : α}, a ∈ s → s.get = a

theorem Computation.mem_of_get_eq E0 #

∀ {α : Type u} (s : Computation α) [h : s.Terminates] {a : α}, s.get = a → a ∈ s

theorem Computation.get_think E0 #

∀ {α : Type u} (s : Computation α) [h : s.Terminates], s.think.get = s.get

theorem Computation.get_thinkN E0 #

∀ {α : Type u} (s : Computation α) [h : s.Terminates] (n : ℕ), (s.thinkN n).get = s.get

theorem Computation.get_promises E1 #

∀ {α : Type u} (s : Computation α) [h : s.Terminates], s.Promises s.get

theorem Computation.mem_of_promises E0 #

∀ {α : Type u} (s : Computation α) [h : s.Terminates] {a : α}, s.Promises a → a ∈ s

theorem Computation.get_eq_of_promises E1 #

∀ {α : Type u} (s : Computation α) [h : s.Terminates] {a : α}, s.Promises a → s.get = a

def Computation.Results E1 #

{α : Type u} → Computation α → α → ℕ → Prop

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

theorem Computation.results_of_terminates E1 #

∀ {α : Type u} (s : Computation α) [_T : s.Terminates], s.Results s.get s.length

theorem Computation.results_of_terminates' E1 #

∀ {α : Type u} (s : Computation α) [T : s.Terminates] {a : α}, a ∈ s → s.Results a s.length

theorem Computation.Results.mem E1 #

∀ {α : Type u} {s : Computation α} {a : α} {n : ℕ}, s.Results a n → a ∈ s

theorem Computation.Results.terminates E1 #

∀ {α : Type u} {s : Computation α} {a : α} {n : ℕ}, s.Results a n → s.Terminates

theorem Computation.Results.length E1 #

∀ {α : Type u} {s : Computation α} {a : α} {n : ℕ} [_T : s.Terminates], s.Results a n → s.length = n

theorem Computation.Results.val_unique E0 #

∀ {α : Type u} {s : Computation α} {a b : α} {m n : ℕ}, s.Results a m → s.Results b n → a = b

theorem Computation.Results.len_unique E1 #

∀ {α : Type u} {s : Computation α} {a b : α} {m n : ℕ}, s.Results a m → s.Results b n → m = n

theorem Computation.exists_results_of_mem E1 #

∀ {α : Type u} {s : Computation α} {a : α}, a ∈ s → ∃ n, s.Results a n

theorem Computation.get_pure E0 #

∀ {α : Type u} (a : α), (Computation.pure a).get = a

theorem Computation.length_pure E0 #

∀ {α : Type u} (a : α), (Computation.pure a).length = 0

theorem Computation.results_pure E1 #

∀ {α : Type u} (a : α), (Computation.pure a).Results a 0

theorem Computation.length_think E0 #

∀ {α : Type u} (s : Computation α) [h : s.Terminates], s.think.length = s.length + 1

theorem Computation.results_think E1 #

∀ {α : Type u} {s : Computation α} {a : α} {n : ℕ}, s.Results a n → s.think.Results a (n + 1)

theorem Computation.of_results_think E1 #

∀ {α : Type u} {s : Computation α} {a : α} {n : ℕ}, s.think.Results a n → ∃ m, s.Results a m ∧ n = m + 1

theorem Computation.results_think_iff E0 #

∀ {α : Type u} {s : Computation α} {a : α} {n : ℕ}, s.think.Results a (n + 1) ↔ s.Results a n

theorem Computation.results_thinkN E1 #

∀ {α : Type u} {s : Computation α} {a : α} {m : ℕ} (n : ℕ), s.Results a m → (s.thinkN n).Results a (m + n)

theorem Computation.results_thinkN_pure E1 #

∀ {α : Type u} (a : α) (n : ℕ), ((Computation.pure a).thinkN n).Results a n

theorem Computation.length_thinkN E0 #

∀ {α : Type u} (s : Computation α) [_h : s.Terminates] (n : ℕ), (s.thinkN n).length = s.length + n

def Computation.memRecOn E1 #

{α : Type u} →
  {C : Computation α → Sort v} →
    {a : α} → {s : Computation α} → a ∈ s → C (Computation.pure a) → ((s : Computation α) → C s → C s.think) → C s

Recursor based on membership

def Computation.terminatesRecOn E1 #

{α : Type u} →
  {C : Computation α → Sort v} →
    (s : Computation α) →
      [s.Terminates] → ((a : α) → C (Computation.pure a)) → ((s : Computation α) → C s → C s.think) → C s

Recursor based on assertion of Terminates

def Computation.map E1 #

{α : Type u} → {β : Type v} → (α → β) → Computation α → Computation β

Map a function on the result of a computation.

def Computation.Bind.g E1 #

{α : Type u} → {β : Type v} → β ⊕ Computation β → β ⊕ Computation α ⊕ Computation β

bind over a Sum of Computation

def Computation.Bind.f E1 #

{α : Type u} → {β : Type v} → (α → Computation β) → Computation α ⊕ Computation β → β ⊕ Computation α ⊕ Computation β

bind over a function mapping α to a Computation

def Computation.bind E1 #

{α : Type u} → {β : Type v} → Computation α → (α → Computation β) → Computation β

Compose two computations into a monadic bind operation.

instance Computation.instBind E0 #

Bind Computation

theorem Computation.has_bind_eq_bind E1 #

∀ {α β : Type u} (c : Computation α) (f : α → Computation β), c >>= f = c.bind f

def Computation.join E1 #

{α : Type u} → Computation (Computation α) → Computation α

Flatten a computation of computations into a single computation.

theorem Computation.map_pure E0 #

∀ {α : Type u} {β : Type v} (f : α → β) (a : α), Computation.map f (Computation.pure a) = Computation.pure (f a)

theorem Computation.map_think E0 #

∀ {α : Type u} {β : Type v} (f : α → β) (s : Computation α), Computation.map f s.think = (Computation.map f s).think

theorem Computation.destruct_map E0 #

∀ {α : Type u} {β : Type v} (f : α → β) (s : Computation α),
  (Computation.map f s).destruct = Computation.lmap f (Computation.rmap (Computation.map f) s.destruct)

theorem Computation.map_id E0 #

∀ {α : Type u} (s : Computation α), Computation.map id s = s

theorem Computation.map_comp E0 #

∀ {α : Type u} {β : Type v} {γ : Type w} (f : α → β) (g : β → γ) (s : Computation α),
  Computation.map (g ∘ f) s = Computation.map g (Computation.map f s)

theorem Computation.ret_bind E0 #

∀ {α : Type u} {β : Type v} (a : α) (f : α → Computation β), (Computation.pure a).bind f = f a

theorem Computation.think_bind E0 #

∀ {α : Type u} {β : Type v} (c : Computation α) (f : α → Computation β), c.think.bind f = (c.bind f).think

theorem Computation.bind_pure E0 #

∀ {α : Type u} {β : Type v} (f : α → β) (s : Computation α), s.bind (Computation.pure ∘ f) = Computation.map f s

theorem Computation.bind_pure' E0 #

∀ {α : Type u} (s : Computation α), s.bind Computation.pure = s

theorem Computation.bind_assoc E0 #

∀ {α : Type u} {β : Type v} {γ : Type w} (s : Computation α) (f : α → Computation β) (g : β → Computation γ),
  (s.bind f).bind g = s.bind fun x ↦ (f x).bind g

theorem Computation.results_bind E1 #

∀ {α : Type u} {β : Type v} {s : Computation α} {f : α → Computation β} {a : α} {b : β} {m n : ℕ},
  s.Results a m → (f a).Results b n → (s.bind f).Results b (n + m)

theorem Computation.mem_bind E0 #

∀ {α : Type u} {β : Type v} {s : Computation α} {f : α → Computation β} {a : α} {b : β}, a ∈ s → b ∈ f a → b ∈ s.bind f

instance Computation.terminates_bind E0 #

∀ {α : Type u} {β : Type v} (s : Computation α) (f : α → Computation β) [inst : s.Terminates] [(f s.get).Terminates],
  (s.bind f).Terminates

theorem Computation.get_bind E0 #

∀ {α : Type u} {β : Type v} (s : Computation α) (f : α → Computation β) [inst : s.Terminates]
  [inst_1 : (f s.get).Terminates], (s.bind f).get = (f s.get).get

theorem Computation.length_bind E0 #

∀ {α : 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 E1 #

∀ {α : Type u} {β : Type v} {s : Computation α} {f : α → Computation β} {b : β} {k : ℕ},
  (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 E1 #

∀ {α : Type u} {β : Type v} {s : Computation α} {f : α → Computation β} {b : β}, b ∈ s.bind f → ∃ a ∈ s, b ∈ f a

theorem Computation.bind_promises E1 #

∀ {α : Type u} {β : Type v} {s : Computation α} {f : α → Computation β} {a : α} {b : β},
  s.Promises a → (f a).Promises b → (s.bind f).Promises b

instance Computation.monad E0 #

Monad Computation

instance Computation.instLawfulMonad E0 #

LawfulMonad Computation

theorem Computation.has_map_eq_map E1 #

∀ {α β : Type u} (f : α → β) (c : Computation α), f <$> c = Computation.map f c

theorem Computation.pure_def E0 #

∀ {α : Type u} (a : α), pure a = Computation.pure a

theorem Computation.map_pure' E0 #

∀ {α β : Type u_1} (f : α → β) (a : α), f <$> Computation.pure a = Computation.pure (f a)

theorem Computation.map_think' E0 #

∀ {α β : Type u_1} (f : α → β) (s : Computation α), f <$> s.think = (f <$> s).think

theorem Computation.mem_map E0 #

∀ {α : Type u} {β : Type v} (f : α → β) {a : α} {s : Computation α}, a ∈ s → f a ∈ Computation.map f s

theorem Computation.exists_of_mem_map E1 #

∀ {α : Type u} {β : Type v} {f : α → β} {b : β} {s : Computation α}, b ∈ Computation.map f s → ∃ a ∈ s, f a = b

instance Computation.terminates_map E0 #

∀ {α : Type u} {β : Type v} (f : α → β) (s : Computation α) [s.Terminates], (Computation.map f s).Terminates

theorem Computation.terminates_map_iff E0 #

∀ {α : Type u} {β : Type v} (f : α → β) (s : Computation α), (Computation.map f s).Terminates ↔ s.Terminates

def Computation.orElse E1 #

{α : Type u} → Computation α → (Unit → Computation α) → Computation α

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

instance Computation.instAlternativeComputation E0 #

Alternative Computation

theorem Computation.ret_orElse E0 #

∀ {α : Type u} (a : α) (c₂ : Computation α), (Computation.pure a <|> c₂) = Computation.pure a

theorem Computation.orElse_pure E0 #

∀ {α : Type u} (c₁ : Computation α) (a : α), (c₁.think <|> Computation.pure a) = Computation.pure a

theorem Computation.orElse_think E0 #

∀ {α : Type u} (c₁ c₂ : Computation α), (c₁.think <|> c₂.think) = (c₁ <|> c₂).think

theorem Computation.empty_orElse E0 #

∀ {α : Type u} (c : Computation α), (Computation.empty α <|> c) = c

theorem Computation.orElse_empty E0 #

∀ {α : Type u} (c : Computation α), (c <|> Computation.empty α) = c

def Computation.Equiv E1 #

{α : Type u} → Computation α → Computation α → Prop

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

def Computation.«term_~__1» E1 #

Lean.TrailingParserDescr

equivalence relation for computations

theorem Computation.Equiv.refl E1 #

∀ {α : Type u} (s : Computation α), s.Equiv s

theorem Computation.Equiv.symm E1 #

∀ {α : Type u} {s t : Computation α}, s.Equiv t → t.Equiv s

theorem Computation.Equiv.trans E1 #

∀ {α : Type u} {s t u : Computation α}, s.Equiv t → t.Equiv u → s.Equiv u

theorem Computation.Equiv.equivalence E1 #

∀ {α : Type u}, Equivalence Computation.Equiv

theorem Computation.equiv_of_mem E1 #

∀ {α : Type u} {s t : Computation α} {a : α}, a ∈ s → a ∈ t → s.Equiv t

theorem Computation.terminates_congr E1 #

∀ {α : Type u} {c₁ c₂ : Computation α}, c₁.Equiv c₂ → (c₁.Terminates ↔ c₂.Terminates)

theorem Computation.promises_congr E1 #

∀ {α : Type u} {c₁ c₂ : Computation α}, c₁.Equiv c₂ → ∀ (a : α), c₁.Promises a ↔ c₂.Promises a

theorem Computation.get_equiv E1 #

∀ {α : Type u} {c₁ c₂ : Computation α}, c₁.Equiv c₂ → ∀ [inst : c₁.Terminates] [inst_1 : c₂.Terminates], c₁.get = c₂.get

theorem Computation.think_equiv E1 #

∀ {α : Type u} (s : Computation α), s.think.Equiv s

theorem Computation.thinkN_equiv E1 #

∀ {α : Type u} (s : Computation α) (n : ℕ), (s.thinkN n).Equiv s

theorem Computation.bind_congr E1 #

∀ {α : Type u} {β : Type v} {s1 s2 : Computation α} {f1 f2 : α → Computation β},
  s1.Equiv s2 → (∀ (a : α), (f1 a).Equiv (f2 a)) → (s1.bind f1).Equiv (s2.bind f2)

theorem Computation.equiv_pure_of_mem E1 #

∀ {α : Type u} {s : Computation α} {a : α}, a ∈ s → s.Equiv (Computation.pure a)

def Computation.LiftRel E1 #

{α : Type u} → {β : Type v} → (α → β → Prop) → Computation α → Computation β → Prop

LiftRel 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.

theorem Computation.LiftRel.swap E1 #

∀ {α : Type u} {β : Type v} (R : α → β → Prop) (ca : Computation α) (cb : Computation β),
  Computation.LiftRel (Function.swap R) cb ca ↔ Computation.LiftRel R ca cb

theorem Computation.lift_eq_iff_equiv E1 #

∀ {α : Type u} (c₁ c₂ : Computation α), Computation.LiftRel (fun x1 x2 ↦ x1 = x2) c₁ c₂ ↔ c₁.Equiv c₂

instance Computation.LiftRel.refl E0 #

∀ {α : Type u} (R : α → α → Prop) [Std.Refl R], Std.Refl (Computation.LiftRel R)

instance Computation.LiftRel.symm E0 #

∀ {α : Type u} (R : α → α → Prop) [Std.Symm R], Std.Symm (Computation.LiftRel R)

instance Computation.LiftRel.trans E0 #

∀ {α : Type u} (R : α → α → Prop) [IsTrans α R], IsTrans (Computation α) (Computation.LiftRel R)

theorem Computation.LiftRel.equiv E1 #

∀ {α : Type u} (R : α → α → Prop), Equivalence R → Equivalence (Computation.LiftRel R)

theorem Computation.LiftRel.imp E1 #

∀ {α : Type u} {β : Type v} {R S : α → β → Prop},
  (∀ {a : α} {b : β}, R a b → S a b) →
    ∀ (s : Computation α) (t : Computation β), Computation.LiftRel R s t → Computation.LiftRel S s t

theorem Computation.terminates_of_liftRel E1 #

∀ {α : Type u} {β : Type v} {R : α → β → Prop} {s : Computation α} {t : Computation β},
  Computation.LiftRel R s t → (s.Terminates ↔ t.Terminates)

theorem Computation.rel_of_liftRel E1 #

∀ {α : Type u} {β : Type v} {R : α → β → Prop} {ca : Computation α} {cb : Computation β},
  Computation.LiftRel R ca cb → ∀ {a : α} {b : β}, a ∈ ca → b ∈ cb → R a b

theorem Computation.liftRel_of_mem E1 #

∀ {α : Type u} {β : Type v} {R : α → β → Prop} {a : α} {b : β} {ca : Computation α} {cb : Computation β},
  a ∈ ca → b ∈ cb → R a b → Computation.LiftRel R ca cb

theorem Computation.exists_of_liftRel_left E1 #

∀ {α : Type u} {β : Type v} {R : α → β → Prop} {ca : Computation α} {cb : Computation β},
  Computation.LiftRel R ca cb → ∀ {a : α}, a ∈ ca → ∃ b ∈ cb, R a b

theorem Computation.exists_of_liftRel_right E1 #

∀ {α : Type u} {β : Type v} {R : α → β → Prop} {ca : Computation α} {cb : Computation β},
  Computation.LiftRel R ca cb → ∀ {b : β}, b ∈ cb → ∃ a ∈ ca, R a b

theorem Computation.liftRel_def E0 #

∀ {α : Type u} {β : Type v} {R : α → β → Prop} {ca : Computation α} {cb : Computation β},
  Computation.LiftRel R ca cb ↔ (ca.Terminates ↔ cb.Terminates) ∧ ∀ {a : α} {b : β}, a ∈ ca → b ∈ cb → R a b

theorem Computation.liftRel_bind E1 #

∀ {α : Type u} {β : Type v} {γ : Type w} {δ : Type u_1} (R : α → β → Prop) (S : γ → δ → Prop) {s1 : Computation α}
  {s2 : Computation β} {f1 : α → Computation γ} {f2 : β → Computation δ},
  Computation.LiftRel R s1 s2 →
    (∀ {a : α} {b : β}, R a b → Computation.LiftRel S (f1 a) (f2 b)) → Computation.LiftRel S (s1.bind f1) (s2.bind f2)

theorem Computation.liftRel_pure_left E0 #

∀ {α : Type u} {β : Type v} (R : α → β → Prop) (a : α) (cb : Computation β),
  Computation.LiftRel R (Computation.pure a) cb ↔ ∃ b ∈ cb, R a b

theorem Computation.liftRel_pure_right E0 #

∀ {α : Type u} {β : Type v} (R : α → β → Prop) (ca : Computation α) (b : β),
  Computation.LiftRel R ca (Computation.pure b) ↔ ∃ a ∈ ca, R a b

theorem Computation.liftRel_pure E1 #

∀ {α : Type u} {β : Type v} (R : α → β → Prop) (a : α) (b : β),
  Computation.LiftRel R (Computation.pure a) (Computation.pure b) ↔ R a b

theorem Computation.liftRel_think_left E0 #

∀ {α : Type u} {β : Type v} (R : α → β → Prop) (ca : Computation α) (cb : Computation β),
  Computation.LiftRel R ca.think cb ↔ Computation.LiftRel R ca cb

theorem Computation.liftRel_think_right E0 #

∀ {α : Type u} {β : Type v} (R : α → β → Prop) (ca : Computation α) (cb : Computation β),
  Computation.LiftRel R ca cb.think ↔ Computation.LiftRel R ca cb

theorem Computation.liftRel_mem_cases E1 #

∀ {α : Type u} {β : Type v} {R : α → β → Prop} {ca : Computation α} {cb : Computation β},
  (∀ a ∈ ca, Computation.LiftRel R ca cb) → (∀ b ∈ cb, Computation.LiftRel R ca cb) → Computation.LiftRel R ca cb

theorem Computation.liftRel_congr E1 #

∀ {α : Type u} {β : Type v} {R : α → β → Prop} {ca ca' : Computation α} {cb cb' : Computation β},
  ca.Equiv ca' → cb.Equiv cb' → (Computation.LiftRel R ca cb ↔ Computation.LiftRel R ca' cb')

theorem Computation.liftRel_map E1 #

∀ {α : Type u} {β : Type v} {γ : Type w} {δ : Type u_1} (R : α → β → Prop) (S : γ → δ → Prop) {s1 : Computation α}
  {s2 : Computation β} {f1 : α → γ} {f2 : β → δ},
  Computation.LiftRel R s1 s2 →
    (∀ {a : α} {b : β}, R a b → S (f1 a) (f2 b)) → Computation.LiftRel S (Computation.map f1 s1) (Computation.map f2 s2)

theorem Computation.map_congr E0 #

∀ {α : Type u} {β : Type v} {s1 s2 : Computation α} {f : α → β},
  s1.Equiv s2 → (Computation.map f s1).Equiv (Computation.map f s2)

def Computation.LiftRelAux E0 #

{α : Type u} →
  {β : Type v} → (α → β → Prop) → (Computation α → Computation β → Prop) → α ⊕ Computation α → β ⊕ Computation β → Prop

Alternate definition of LiftRel over relations between Computations

theorem Computation.liftRelAux_inl_inl E0 #

∀ {α : Type u} {β : Type v} {R : α → β → Prop} {C : Computation α → Computation β → Prop} {a : α} {b : β},
  Computation.LiftRelAux R C (Sum.inl a) (Sum.inl b) = R a b

theorem Computation.liftRelAux_inl_inr E0 #

∀ {α : Type u} {β : Type v} {R : α → β → Prop} {C : Computation α → Computation β → Prop} {a : α} {cb : Computation β},
  Computation.LiftRelAux R C (Sum.inl a) (Sum.inr cb) = ∃ b ∈ cb, R a b

theorem Computation.liftRelAux_inr_inl E0 #

∀ {α : Type u} {β : Type v} {R : α → β → Prop} {C : Computation α → Computation β → Prop} {b : β} {ca : Computation α},
  Computation.LiftRelAux R C (Sum.inr ca) (Sum.inl b) = ∃ a ∈ ca, R a b

theorem Computation.liftRelAux_inr_inr E0 #

∀ {α : Type u} {β : Type v} {R : α → β → Prop} {C : Computation α → Computation β → Prop} {ca : Computation α}
  {cb : Computation β}, Computation.LiftRelAux R C (Sum.inr ca) (Sum.inr cb) = C ca cb

theorem Computation.LiftRelAux.ret_left E0 #

∀ {α : Type u} {β : Type v} (R : α → β → Prop) (C : Computation α → Computation β → Prop) (a : α) (cb : Computation β),
  Computation.LiftRelAux R C (Sum.inl a) cb.destruct ↔ ∃ b ∈ cb, R a b

theorem Computation.LiftRelAux.swap E1 #

∀ {α : Type u} {β : Type v} (R : α → β → Prop) (C : Computation α → Computation β → Prop) (a : α ⊕ Computation α)
  (b : β ⊕ Computation β),
  Computation.LiftRelAux (Function.swap R) (Function.swap C) b a = Computation.LiftRelAux R C a b

theorem Computation.LiftRelAux.ret_right E0 #

∀ {α : Type u} {β : Type v} (R : α → β → Prop) (C : Computation α → Computation β → Prop) (b : β) (ca : Computation α),
  Computation.LiftRelAux R C ca.destruct (Sum.inl b) ↔ ∃ a ∈ ca, R a b

theorem Computation.LiftRelRec.lem E1 #

∀ {α : Type u} {β : Type v} {R : α → β → Prop} (C : Computation α → Computation β → Prop),
  (∀ {ca : Computation α} {cb : Computation β}, C ca cb → Computation.LiftRelAux R C ca.destruct cb.destruct) →
    ∀ (ca : Computation α) (cb : Computation β), C ca cb → ∀ a ∈ ca, Computation.LiftRel R ca cb

theorem Computation.liftRel_rec E1 #

∀ {α : Type u} {β : Type v} {R : α → β → Prop} (C : Computation α → Computation β → Prop),
  (∀ {ca : Computation α} {cb : Computation β}, C ca cb → Computation.LiftRelAux R C ca.destruct cb.destruct) →
    ∀ (ca : Computation α) (cb : Computation β), C ca cb → Computation.LiftRel R ca cb