Coinductive formalization of unbounded computations. #
This file provides a Computation type where Computation α is the type of
unbounded computations returning α.
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
Instances For
pure a is the computation that immediately terminates with result a.
Equations
- Computation.pure a = { val := Stream'.const (some a), property := ⋯ }
Instances For
Equations
- Computation.instCoeTCComputation = { coe := Computation.pure }
think c is the computation that delays for one "tick" and then performs
computation c.
Equations
- Computation.think c = { val := Stream'.cons none ↑c, property := ⋯ }
Instances For
thinkN c n is the computation that delays for n ticks and then performs
computation c.
Equations
- Computation.thinkN c 0 = c
- Computation.thinkN c (Nat.succ n) = Computation.think (Computation.thinkN c n)
Instances For
tail c is the remainder of computation, either c if c = pure a
or c' if c = think c'.
Equations
- Computation.tail c = { val := Stream'.tail ↑c, property := ⋯ }
Instances For
empty α is the computation that never returns, an infinite sequence of
thinks.
Equations
- Computation.empty α = { val := Stream'.const none, property := ⋯ }
Instances For
Equations
- Computation.instInhabitedComputation = { default := Computation.empty α }
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'.
Equations
- Computation.destruct c = match ↑c 0 with | none => Sum.inr (Computation.tail c) | some a => Sum.inl a
Instances For
run c is an unsound meta function that runs c to completion, possibly
resulting in an infinite loop in the VM.
Equations
- Computation.run x = let c := x; match Computation.destruct c with | Sum.inl a => a | Sum.inr ca => Computation.run ca
Instances For
Recursion principle for computations, compare with List.recOn.
Equations
- One or more equations did not get rendered due to their size.
Instances For
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').
Equations
- Computation.corec f b = { val := Stream'.corec' (Computation.Corec.f f) (Sum.inr b), property := ⋯ }
Instances For
Bisimilarity over a sum of Computations
Equations
Instances For
Attribute expressing bisimilarity over two Computations
Equations
- Computation.IsBisimulation R = ∀ ⦃s₁ s₂ : Computation α⦄, R s₁ s₂ → Computation.BisimO R (Computation.destruct s₁) (Computation.destruct s₂)
Instances For
Assertion that a Computation limits to a given value
Equations
- Computation.Mem a s = (some a ∈ ↑s)
Instances For
Equations
- Computation.instMembershipComputation = { mem := Computation.Mem }
Terminates s asserts that the computation s eventually terminates with some value.
- term : ∃ (a : α), a ∈ s
assertion that there is some term
asuch that theComputationterminates
Instances
Equations
- ⋯ = ⋯
Equations
- ⋯ = ⋯
Equations
- ⋯ = ⋯
Promises s a, or s ~> a, asserts that although the computation s
may not terminate, if it does, then the result is a.
Equations
- Computation.Promises s a = ∀ ⦃a' : α⦄, a' ∈ s → a = a'
Instances For
Promises s a, or s ~> a, asserts that although the computation s
may not terminate, if it does, then the result is a.
Equations
- One or more equations did not get rendered due to their size.
Instances For
get s returns the result of a terminating computation
Equations
- Computation.get s = Option.get (↑s (Nat.find ⋯)) ⋯
Instances For
Results s a n completely characterizes a terminating computation:
it asserts that s terminates after exactly n steps, with result a.
Equations
- Computation.Results s a n = ∃ (h : a ∈ s), Computation.length s = n
Instances For
Recursor based on membership
Equations
- One or more equations did not get rendered due to their size.
Instances For
Recursor based on assertion of Terminates
Equations
- Computation.terminatesRecOn s h1 h2 = Computation.memRecOn ⋯ (h1 (Computation.get s)) h2
Instances For
Map a function on the result of a computation.
Equations
- Computation.map f x = match x with | { val := s, property := al } => { val := Stream'.map (fun (o : Option α) => Option.casesOn o none (some ∘ f)) s, property := ⋯ }
Instances For
bind over a Sum of Computation
Equations
Instances For
bind over a function mapping α to a Computation
Equations
- One or more equations did not get rendered due to their size.
Instances For
Compose two computations into a monadic bind operation.
Equations
- Computation.bind c f = Computation.corec (Computation.Bind.f f) (Sum.inl c)
Instances For
Equations
- Computation.instBindComputation = { bind := @Computation.bind }
Flatten a computation of computations into a single computation.
Equations
- Computation.join c = c >>= id
Instances For
Equations
- ⋯ = ⋯
Equations
- ⋯ = ⋯
c₁ <|> c₂ calculates c₁ and c₂ simultaneously, returning
the first one that gives a result.
Equations
- One or more equations did not get rendered due to their size.
Instances For
c₁ ~ c₂ asserts that c₁ and c₂ either both terminate with the same result,
or both loop forever.
Equations
- Computation.Equiv c₁ c₂ = ∀ (a : α), a ∈ c₁ ↔ a ∈ c₂
Instances For
equivalence relation for computations
Equations
- Computation.«term_~_» = Lean.ParserDescr.trailingNode `Computation.term_~_ 50 50 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ~ ") (Lean.ParserDescr.cat `term 51))
Instances For
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.
Equations
Instances For
Alternate definition of LiftRel over relations between Computations
Equations
- One or more equations did not get rendered due to their size.