The areas / V33. Data structures and computation
Mathlib.Data.QPF.Multivariate.Constructions.Cofix
35 declarations. Mathlib docs · Source
The final co-algebra of a multivariate qpf is again a qpf.
For a (n+1)-ary QPF F (α₀,..,αₙ), we take the least fixed point of F with
regards to its last argument αₙ. The result is an n-ary functor: Fix F (α₀,..,αₙ₋₁).
Making Fix F into a functor allows us to take the fixed point, compose with other functors
and take a fixed point again.
Main definitions
Cofix.mk- constructorCofix.dest- destructorCofix.corec- corecursor: useful for formulating infinite, productive computationsCofix.bisim- bisimulation: proof technique to show the equality of possibly infinite values ofCofix F α
Implementation notes
For F a QPF, we define Cofix F α in terms of the M-type of the polynomial functor P of F.
We define the relation Mcongr and take its quotient as the definition of Cofix F α.
Mcongr is taken as the weakest bisimulation on M-type. See
[avigad-carneiro-hudon2019] for more details.
References
- Jeremy Avigad, Mario M. Carneiro and Simon Hudon. [Data Types as Quotients of Polynomial Functors][avigad-carneiro-hudon2019]
Bisimulation principles for Cofix F
The following theorems are bisimulation principles. The general idea
is to use a bisimulation relation to prove the equality between
specific values of type Cofix F α.
A bisimulation relation R for values x y : Cofix F α:
- holds for
x y:R x y - for any values
x ythat satisfyR, their root has the same shape and their children can be paired in such a way that they satisfyR.
liftR_map, liftR_map_last and liftR_map_last' are useful for reasoning about
the induction step in bisimulation proofs.
def MvQPF.corecF E1 #
{n : ℕ} →
{F : TypeVec.{u} (n + 1) → Type u} →
[q : MvQPF F] → {α : TypeVec.{u} n} → {β : Type u} → (β → F (α ::: β)) → β → (MvQPF.P F).M α
corecF is used as a basis for defining the corecursor of Cofix F α. corecF
uses corecursion to construct the M-type generated by q.P and uses function on F
as a corecursive step
theorem MvQPF.corecF_eq E0 #
∀ {n : ℕ} {F : TypeVec.{u} (n + 1) → Type u} [q : MvQPF F] {α : TypeVec.{u} n} {β : Type u} (g : β → F (α ::: β))
(x : β),
MvPFunctor.M.dest (MvQPF.P F) (MvQPF.corecF g x) = MvFunctor.map (TypeVec.id ::: MvQPF.corecF g) (MvQPF.repr (g x))
def MvQPF.IsPrecongr E1 #
{n : ℕ} →
{F : TypeVec.{u} (n + 1) → Type u} →
[q : MvQPF F] → {α : TypeVec.{u} n} → ((MvQPF.P F).M α → (MvQPF.P F).M α → Prop) → Prop
Characterization of desirable equivalence relations on M-types
def MvQPF.Mcongr E1 #
{n : ℕ} →
{F : TypeVec.{u} (n + 1) → Type u} → [q : MvQPF F] → {α : TypeVec.{u} n} → (MvQPF.P F).M α → (MvQPF.P F).M α → Prop
Equivalence relation on M-types representing a value of type Cofix F
def MvQPF.Cofix E1 #
{n : ℕ} → (F : TypeVec.{u} (n + 1) → Type u) → [MvQPF F] → TypeVec.{u} n → Type u
Greatest fixed point of functor F. The result is a functor with one fewer parameters
than the input. For F a b c a ternary functor, fix F is a binary functor such that
Cofix F a b = F a b (Cofix F a b)
instance MvQPF.instInhabitedCofixOfAP E0 #
{n : ℕ} →
{F : TypeVec.{u} (n + 1) → Type u} →
[q : MvQPF F] →
{α : TypeVec.{u} n} → [Inhabited (MvQPF.P F).A] → [(i : Fin2 n) → Inhabited (α i)] → Inhabited (MvQPF.Cofix F α)
def MvQPF.mRepr E1 #
{n : ℕ} → {F : TypeVec.{u} (n + 1) → Type u} → [q : MvQPF F] → {α : TypeVec.{u} n} → (MvQPF.P F).M α → (MvQPF.P F).M α
maps every element of the W type to a canonical representative
def MvQPF.Cofix.map E1 #
{n : ℕ} →
{F : TypeVec.{u} (n + 1) → Type u} →
[q : MvQPF F] → {α β : TypeVec.{u} n} → α.Arrow β → MvQPF.Cofix F α → MvQPF.Cofix F β
the map function for the functor Cofix F
instance MvQPF.Cofix.mvfunctor E0 #
{n : ℕ} → {F : TypeVec.{u} (n + 1) → Type u} → [q : MvQPF F] → MvFunctor (MvQPF.Cofix F)
def MvQPF.Cofix.corec E3 #
{n : ℕ} →
{F : TypeVec.{u} (n + 1) → Type u} →
[q : MvQPF F] → {α : TypeVec.{u} n} → {β : Type u} → (β → F (α ::: β)) → β → MvQPF.Cofix F α
Corecursor for Cofix F
def MvQPF.Cofix.dest E3 #
{n : ℕ} →
{F : TypeVec.{u} (n + 1) → Type u} → [q : MvQPF F] → {α : TypeVec.{u} n} → MvQPF.Cofix F α → F (α ::: MvQPF.Cofix F α)
Destructor for Cofix F
def MvQPF.Cofix.abs E1 #
{n : ℕ} → {F : TypeVec.{u} (n + 1) → Type u} → [q : MvQPF F] → {α : TypeVec.{u} n} → (MvQPF.P F).M α → MvQPF.Cofix F α
Abstraction function for cofix F α
def MvQPF.Cofix.repr E1 #
{n : ℕ} → {F : TypeVec.{u} (n + 1) → Type u} → [q : MvQPF F] → {α : TypeVec.{u} n} → MvQPF.Cofix F α → (MvQPF.P F).M α
Representation function for Cofix F α
def MvQPF.Cofix.corec'₁ E1 #
{n : ℕ} →
{F : TypeVec.{u} (n + 1) → Type u} →
[q : MvQPF F] → {α : TypeVec.{u} n} → {β : Type u} → ({X : Type u} → (β → X) → F (α ::: X)) → β → MvQPF.Cofix F α
Corecursor for Cofix F
def MvQPF.Cofix.corec' E1 #
{n : ℕ} →
{F : TypeVec.{u} (n + 1) → Type u} →
[q : MvQPF F] → {α : TypeVec.{u} n} → {β : Type u} → (β → F (α ::: (MvQPF.Cofix F α ⊕ β))) → β → MvQPF.Cofix F α
More flexible corecursor for Cofix F. Allows the return of a fully formed
value instead of making a recursive call
def MvQPF.Cofix.corec₁ E1 #
{n : ℕ} →
{F : TypeVec.{u} (n + 1) → Type u} →
[q : MvQPF F] →
{α : TypeVec.{u} n} →
{β : Type u} → ({X : Type u} → (MvQPF.Cofix F α → X) → (β → X) → β → F (α ::: X)) → β → MvQPF.Cofix F α
Corecursor for Cofix F. The shape allows recursive calls to
look like recursive calls.
theorem MvQPF.Cofix.dest_corec E1 #
∀ {n : ℕ} {F : TypeVec.{u} (n + 1) → Type u} [q : MvQPF F] {α : TypeVec.{u} n} {β : Type u} (g : β → F (α ::: β))
(x : β), (MvQPF.Cofix.corec g x).dest = MvFunctor.map (TypeVec.id ::: MvQPF.Cofix.corec g) (g x)
def MvQPF.Cofix.mk E3 #
{n : ℕ} →
{F : TypeVec.{u} (n + 1) → Type u} → [q : MvQPF F] → {α : TypeVec.{u} n} → F (α ::: MvQPF.Cofix F α) → MvQPF.Cofix F α
constructor for Cofix F
theorem MvQPF.Cofix.bisim_rel E2 #
∀ {n : ℕ} {F : TypeVec.{u} (n + 1) → Type u} [q : MvQPF F] {α : TypeVec.{u} n}
(r : MvQPF.Cofix F α → MvQPF.Cofix F α → Prop),
(∀ (x y : MvQPF.Cofix F α),
r x y → MvFunctor.map (TypeVec.id ::: Quot.mk r) x.dest = MvFunctor.map (TypeVec.id ::: Quot.mk r) y.dest) →
∀ (x y : MvQPF.Cofix F α), r x y → x = y
Bisimulation principle using map and Quot.mk to match and relate children of two trees.
theorem MvQPF.Cofix.bisim E3 #
∀ {n : ℕ} {F : TypeVec.{u} (n + 1) → Type u} [q : MvQPF F] {α : TypeVec.{u} n}
(r : MvQPF.Cofix F α → MvQPF.Cofix F α → Prop),
(∀ (x y : MvQPF.Cofix F α), r x y → MvFunctor.LiftR (α.RelLast r) x.dest y.dest) →
∀ (x y : MvQPF.Cofix F α), r x y → x = y
Bisimulation principle using LiftR to match and relate children of two trees.
theorem MvQPF.Cofix.bisim₂ E2 #
∀ {n : ℕ} {F : TypeVec.{u} (n + 1) → Type u} [q : MvQPF F] {α : TypeVec.{u} n}
(r : MvQPF.Cofix F α → MvQPF.Cofix F α → Prop),
(∀ (x y : MvQPF.Cofix F α), r x y → MvFunctor.LiftR' (α.RelLast' r) x.dest y.dest) →
∀ (x y : MvQPF.Cofix F α), r x y → x = y
Bisimulation principle using LiftR' to match and relate children of two trees.
theorem MvQPF.Cofix.bisim' E2 #
∀ {n : ℕ} {F : TypeVec.{u} (n + 1) → Type u} [q : MvQPF F] {α : TypeVec.{u} n} {β : Type u_1} (Q : β → Prop)
(u v : β → MvQPF.Cofix F α),
(∀ (x : β),
Q x →
∃ a f' f₀ f₁,
(u x).dest = MvQPF.abs ⟨a, (MvQPF.P F).appendContents f' f₀⟩ ∧
(v x).dest = MvQPF.abs ⟨a, (MvQPF.P F).appendContents f' f₁⟩ ∧
∀ (i : (MvQPF.P F).last.B a), ∃ x', Q x' ∧ f₀ i = u x' ∧ f₁ i = v x') →
∀ (x : β), Q x → u x = v x
Bisimulation principle the values ⟨a,f⟩ of the polynomial functor representing
Cofix F α as well as an invariant Q : β → Prop and a state β generating the
left-hand side and right-hand side of the equality through functions u v : β → Cofix F α
theorem MvQPF.Cofix.mk_dest E1 #
∀ {n : ℕ} {F : TypeVec.{u} (n + 1) → Type u} [q : MvQPF F] {α : TypeVec.{u} n} (x : MvQPF.Cofix F α),
MvQPF.Cofix.mk x.dest = x
theorem MvQPF.Cofix.dest_mk E0 #
∀ {n : ℕ} {F : TypeVec.{u} (n + 1) → Type u} [q : MvQPF F] {α : TypeVec.{u} n} (x : F (α ::: MvQPF.Cofix F α)),
(MvQPF.Cofix.mk x).dest = x
theorem MvQPF.Cofix.ext E1 #
∀ {n : ℕ} {F : TypeVec.{u} (n + 1) → Type u} [q : MvQPF F] {α : TypeVec.{u} n} (x y : MvQPF.Cofix F α),
x.dest = y.dest → x = y
theorem MvQPF.Cofix.ext_mk E0 #
∀ {n : ℕ} {F : TypeVec.{u} (n + 1) → Type u} [q : MvQPF F] {α : TypeVec.{u} n} (x y : F (α ::: MvQPF.Cofix F α)),
MvQPF.Cofix.mk x = MvQPF.Cofix.mk y → x = y
theorem MvQPF.liftR_map E1 #
∀ {n : ℕ} {α β : TypeVec.{u_1} n} {F' : TypeVec.{u_1} n → Type u} [inst : MvFunctor F'] [LawfulMvFunctor F']
(R : (β.prod β).Arrow (TypeVec.repeat n Prop)) (x : F' α) (f g : α.Arrow β) (h : α.Arrow (TypeVec.Subtype_ R)),
TypeVec.comp (TypeVec.subtypeVal R) h = TypeVec.comp (TypeVec.prod.map f g) TypeVec.prod.diag →
MvFunctor.LiftR' R (MvFunctor.map f x) (MvFunctor.map g x)
theorem MvQPF.liftR_map_last E1 #
∀ {n : ℕ} {F : TypeVec.{u} (n + 1) → Type u} [q : MvQPF F] [lawful : LawfulMvFunctor F] {α : TypeVec.{u} n}
{ι ι' : Type u} (R : ι' → ι' → Prop) (x : F (α ::: ι)) (f g : ι → ι'),
(∀ (x : ι), R (f x) (g x)) →
MvFunctor.LiftR' (α.RelLast' R) (MvFunctor.map (TypeVec.id ::: f) x) (MvFunctor.map (TypeVec.id ::: g) x)
theorem MvQPF.liftR_map_last' E1 #
∀ {n : ℕ} {F : TypeVec.{u} (n + 1) → Type u} [q : MvQPF F] {α : TypeVec.{u} n} {ι : Type u} (R : ι → ι → Prop)
(x : F (α ::: ι)) (f : ι → ι),
(∀ (x : ι), R (f x) x) → MvFunctor.LiftR' (α.RelLast' R) (MvFunctor.map (TypeVec.id ::: f) x) x
theorem MvQPF.Cofix.abs_repr E1 #
∀ {n : ℕ} {F : TypeVec.{u} (n + 1) → Type u} [q : MvQPF F] {α : TypeVec.{u} n} (x : MvQPF.Cofix F α),
Quot.mk MvQPF.Mcongr x.repr = x
def Mathlib.Tactic.MvBisim.tacticMv_bisim___With___ E1 #
Lean.ParserDescr
tactic for proof by bisimulation
theorem MvQPF.corec_roll E1 #
∀ {n : ℕ} {F : TypeVec.{u} (n + 1) → Type u} [q : MvQPF F] {α : TypeVec.{u} n} {X Y : Type u} {x₀ : X} (f : X → Y)
(g : Y → F (α ::: X)), MvQPF.Cofix.corec (g ∘ f) x₀ = MvQPF.Cofix.corec (MvFunctor.map (TypeVec.id ::: f) ∘ g) (f x₀)
theorem MvQPF.Cofix.dest_corec' E1 #
∀ {n : ℕ} {F : TypeVec.{u} (n + 1) → Type u} [q : MvQPF F] {α : TypeVec.{u} n} {β : Type u}
(g : β → F (α ::: (MvQPF.Cofix F α ⊕ β))) (x : β),
(MvQPF.Cofix.corec' g x).dest = MvFunctor.map (TypeVec.id ::: Sum.elim id (MvQPF.Cofix.corec' g)) (g x)
theorem MvQPF.Cofix.dest_corec₁ E1 #
∀ {n : ℕ} {F : TypeVec.{u} (n + 1) → Type u} [q : MvQPF F] {α : TypeVec.{u} n} {β : Type u}
(g : {X : Type u} → (MvQPF.Cofix F α → X) → (β → X) → β → F (α ::: X)) (x : β),
(∀ (X Y : Type u) (f : MvQPF.Cofix F α → X) (f' : β → X) (k : X → Y),
g (k ∘ f) (k ∘ f') x = MvFunctor.map (TypeVec.id ::: k) (g f f' x)) →
(MvQPF.Cofix.corec₁ g x).dest = g id (MvQPF.Cofix.corec₁ g) x
instance MvQPF.mvqpfCofix E0 #
{n : ℕ} → {F : TypeVec.{u} (n + 1) → Type u} → [q : MvQPF F] → MvQPF (MvQPF.Cofix F)