Non-primitive corecursion for sequences #
Primitive corecursive definition of the form
def foo (x : X) := hd x :: foo (tlArg x)
(where hd and tlArg are arbitrary functions) can be encoded via the corecursor Seq.corec.
It is not enough, however, to define multiplication and powser operation for multiseries.
This file implements a more general form of corecursion in the spirit of [BPT15].
This is a bare minimum that needed for the tactic, it justifies a weaker class of
corecursive definitions than [BPT15] does, and only works for Seq.
A function f : Seq α → Seq α is called friendly if for all n : ℕ the n-prefix of its result
f s depends only on the n-prefix of its input s.
In this file we develop a theory that justifies corecursive definitions of the form
def foo (x : X) := hd x :: f (foo (tlArg x))
where f is friendly.
Main definitions #
FriendlyOperation fmeans thatfis friendly.FriendlyOperationClassis a typeclass meaning that some indexed family of operations are friendly.gcorec: a generalization ofSeq.corecthat allows a corecursive call to be guarded by a friendly function.
Implementation details #
To prove that the definition of the form
def foo (x : X) := hd x :: f (foo (tlArg x))
is correct we prove that there exists a function satisfying this equation. For that we employ a
Banach fixed point theorem. We treat Seq α as a metric space here with the metric
d(s, t) := 2 ^ (-n) where n is the minimal index where s and t differ.
Then f is friendly iff it is 1-Lipschitz.
Metric space structure on Stream' α considering α as a discrete metric space.
Instances For
Metric space structure on Seq α considering α as a discrete metric space.
Instances For
A function on sequences is called a "friend" if any n-prefix of its output depends only on
the n-prefix of the input. Such functions can be used in the tail of (non-primitive) corecursive
definitions.
Equations
Instances For
A family of friendly operations on sequences indexed by a type γ.
- friend (c : γ) : FriendlyOperation (F c)
Instances
Main theorem of this file. It shows that there exists a funcion satisfying the corecursive
definition of the form def foo (x : X) := hd x :: op (foo (tlArg x)) where f is friendly.
(General) non-primitive corecursor for Seq α that allows using a friendly operation in the
tail of the corecursive definition.