The areas / V33. Data structures and computation
Mathlib.Data.PFunctor.Multivariate.M
37 declarations. Mathlib docs · Source
The M construction as a multivariate polynomial functor.
M types are potentially infinite tree-like structures. They are defined as the greatest fixpoint of a polynomial functor.
Main definitions
M.mk- constructorM.dest- destructorM.corec- corecursor: useful for formulating infinite, productive computationsM.bisim- bisimulation: proof technique to show the equality of infinite objects
Implementation notes
Dual view of M-types:
mp: polynomial functorM: greatest fixed point of a polynomial functor
Specifically, we define the polynomial functor mp as:
- A := a possibly infinite tree-like structure without information in the nodes
- B := given the tree-like structure
t,B tis a valid path from the root oftto any given node.
As a result mp α is made of a dataless tree and a function from
its valid paths to values of α
The difference with the polynomial functor of an initial algebra is
that A is a possibly infinite tree.
References
- Jeremy Avigad, Mario M. Carneiro and Simon Hudon. [Data Types as Quotients of Polynomial Functors][avigad-carneiro-hudon2019]
abbrev MvPFunctor.M.Path.ctorElimType E1 #
{n : ℕ} →
{P : MvPFunctor.{u} (n + 1)} →
{motive : (a : P.last.M) → (a_1 : Fin2 n) → MvPFunctor.M.Path P a a_1 → Sort u_1} →
ℕ → Sort (max 1 (imax (u + 1) (u + 1) (u + 1) (u + 1) u_1) (imax (u + 1) (u + 1) (u + 1) (u + 1) (u + 1) u_1))
theorem MvPFunctor.M.Path.brecOn.eq E1 #
∀ {n : ℕ} {P : MvPFunctor.{u} (n + 1)} {motive : (a : P.last.M) → (a_1 : Fin2 n) → MvPFunctor.M.Path P a a_1 → Sort u_1}
{a : P.last.M} {a_1 : Fin2 n} (t : MvPFunctor.M.Path P a a_1)
(F_1 :
(a : P.last.M) → (a_2 : Fin2 n) → (t : MvPFunctor.M.Path P a a_2) → MvPFunctor.M.Path.below t → motive a a_2 t),
MvPFunctor.M.Path.brecOn t F_1 = F_1 a a_1 t (MvPFunctor.M.Path.brecOn.go t F_1).2
abbrev MvPFunctor.M.Path.brecOn.go E1 #
{n : ℕ} →
{P : MvPFunctor.{u} (n + 1)} →
{motive : (a : P.last.M) → (a_1 : Fin2 n) → MvPFunctor.M.Path P a a_1 → Sort u_1} →
{a : P.last.M} →
{a_1 : Fin2 n} →
(t : MvPFunctor.M.Path P a a_1) →
((a : P.last.M) →
(a_2 : Fin2 n) → (t : MvPFunctor.M.Path P a a_2) → MvPFunctor.M.Path.below t → motive a a_2 t) →
motive a a_1 t ×' MvPFunctor.M.Path.below t
theorem MvPFunctor.M.Path.root.injEq E0 #
∀ {n : ℕ} {P : MvPFunctor.{u} (n + 1)} (x : P.last.M) (a : P.A) (f : P.last.B a → P.last.M) (h : x.dest = ⟨a, f⟩)
(i : Fin2 n) (c : P.drop.B a i) (a_1 : P.A) (f_1 : P.last.B a_1 → P.last.M) (h_1 : x.dest = ⟨a_1, f_1⟩)
(c_1 : P.drop.B a_1 i),
(MvPFunctor.M.Path.root x a f h i c = MvPFunctor.M.Path.root x a_1 f_1 h_1 i c_1) = (a = a_1 ∧ f ≍ f_1 ∧ c ≍ c_1)
theorem MvPFunctor.M.Path.child.injEq E0 #
∀ {n : ℕ} {P : MvPFunctor.{u} (n + 1)} (x : P.last.M) (a : P.A) (f : P.last.B a → P.last.M) (h : x.dest = ⟨a, f⟩)
(j : P.last.B a) (i : Fin2 n) (c : MvPFunctor.M.Path P (f j) i) (a_1 : P.A) (f_1 : P.last.B a_1 → P.last.M)
(h_1 : x.dest = ⟨a_1, f_1⟩) (j_1 : P.last.B a_1) (c_1 : MvPFunctor.M.Path P (f_1 j_1) i),
(MvPFunctor.M.Path.child x a f h j i c = MvPFunctor.M.Path.child x a_1 f_1 h_1 j_1 i c_1) =
(a = a_1 ∧ f ≍ f_1 ∧ j ≍ j_1 ∧ c ≍ c_1)
theorem MvPFunctor.M.Path.root.inj E1 #
∀ {n : ℕ} {P : MvPFunctor.{u} (n + 1)} {x : P.last.M} {a : P.A} {f : P.last.B a → P.last.M} {h : x.dest = ⟨a, f⟩}
{i : Fin2 n} {c : P.drop.B a i} {a_1 : P.A} {f_1 : P.last.B a_1 → P.last.M} {h_1 : x.dest = ⟨a_1, f_1⟩}
{c_1 : P.drop.B a_1 i},
MvPFunctor.M.Path.root x a f h i c = MvPFunctor.M.Path.root x a_1 f_1 h_1 i c_1 → a = a_1 ∧ f ≍ f_1 ∧ c ≍ c_1
def MvPFunctor.M.Path.ctorIdx E1 #
{n : ℕ} → {P : MvPFunctor.{u} (n + 1)} → {a : P.last.M} → {a_1 : Fin2 n} → MvPFunctor.M.Path P a a_1 → ℕ
theorem MvPFunctor.M.Path.child.inj E1 #
∀ {n : ℕ} {P : MvPFunctor.{u} (n + 1)} {x : P.last.M} {a : P.A} {f : P.last.B a → P.last.M} {h : x.dest = ⟨a, f⟩}
{j : P.last.B a} {i : Fin2 n} {c : MvPFunctor.M.Path P (f j) i} {a_1 : P.A} {f_1 : P.last.B a_1 → P.last.M}
{h_1 : x.dest = ⟨a_1, f_1⟩} {j_1 : P.last.B a_1} {c_1 : MvPFunctor.M.Path P (f_1 j_1) i},
MvPFunctor.M.Path.child x a f h j i c = MvPFunctor.M.Path.child x a_1 f_1 h_1 j_1 i c_1 →
a = a_1 ∧ f ≍ f_1 ∧ j ≍ j_1 ∧ c ≍ c_1
inductive MvPFunctor.M.Path E1 #
{n : ℕ} → (P : MvPFunctor.{u} (n + 1)) → P.last.M → Fin2 n → Type u
A path from the root of a tree to one of its node
ctor MvPFunctor.M.Path.root E0 #
{n : ℕ} →
{P : MvPFunctor.{u} (n + 1)} →
(x : P.last.M) →
(a : P.A) → (f : P.last.B a → P.last.M) → x.dest = ⟨a, f⟩ → (i : Fin2 n) → P.drop.B a i → MvPFunctor.M.Path P x i
ctor MvPFunctor.M.Path.child E0 #
{n : ℕ} →
{P : MvPFunctor.{u} (n + 1)} →
(x : P.last.M) →
(a : P.A) →
(f : P.last.B a → P.last.M) →
x.dest = ⟨a, f⟩ → (j : P.last.B a) → (i : Fin2 n) → MvPFunctor.M.Path P (f j) i → MvPFunctor.M.Path P x i
instance MvPFunctor.M.Path.inhabited E0 #
{n : ℕ} →
(P : MvPFunctor.{u} (n + 1)) →
(x : P.last.M) → {i : Fin2 n} → [Inhabited (P.drop.B x.head i)] → Inhabited (MvPFunctor.M.Path P x i)
def MvPFunctor.mp E1 #
{n : ℕ} → MvPFunctor.{u} (n + 1) → MvPFunctor.{u} n
Polynomial functor of the M-type of P. A is a data-less
possibly infinite tree whereas, for a given a : A, B a is a valid
path in tree a so that mp α is made of a tree and a function
from its valid paths to the values it contains
def MvPFunctor.M E1 #
{n : ℕ} → MvPFunctor.{u} (n + 1) → TypeVec.{u} n → Type u
n-ary M-type for P
instance MvPFunctor.mvfunctorM E0 #
{n : ℕ} → (P : MvPFunctor.{u} (n + 1)) → MvFunctor P.M
instance MvPFunctor.inhabitedM E0 #
{n : ℕ} →
(P : MvPFunctor.{u} (n + 1)) →
{α : TypeVec.{u} n} → [I : Inhabited P.A] → [(i : Fin2 n) → Inhabited (α i)] → Inhabited (P.M α)
def MvPFunctor.M.corecShape E1 #
{n : ℕ} → (P : MvPFunctor.{u} (n + 1)) → {β : Type v} → (g₀ : β → P.A) → ((b : β) → P.last.B (g₀ b) → β) → β → P.last.M
construct through corecursion the shape of an M-type without its contents
def MvPFunctor.castDropB E1 #
{n : ℕ} → (P : MvPFunctor.{u} (n + 1)) → {a a' : P.A} → a = a' → (P.drop.B a).Arrow (P.drop.B a')
Proof of type equality as an arrow
def MvPFunctor.castLastB E1 #
{n : ℕ} → (P : MvPFunctor.{u} (n + 1)) → {a a' : P.A} → a = a' → P.last.B a → P.last.B a'
Proof of type equality as a function
def MvPFunctor.M.corecContents E1 #
{n : ℕ} →
(P : MvPFunctor.{u} (n + 1)) →
{α : TypeVec.{u} n} →
{β : Type v} →
(g₀ : β → P.A) →
((b : β) → (P.drop.B (g₀ b)).Arrow α) →
(g₂ : (b : β) → P.last.B (g₀ b) → β) →
(x : P.last.M) → (b : β) → x = MvPFunctor.M.corecShape P g₀ g₂ b → TypeVec.Arrow (MvPFunctor.M.Path P x) α
Using corecursion, construct the contents of an M-type
def MvPFunctor.M.corec' E1 #
{n : ℕ} →
(P : MvPFunctor.{u} (n + 1)) →
{α : TypeVec.{u} n} →
{β : Type v} →
(g₀ : β → P.A) → ((b : β) → (P.drop.B (g₀ b)).Arrow α) → ((b : β) → P.last.B (g₀ b) → β) → β → P.M α
Corecursor for M-type of P
def MvPFunctor.M.corec E3 #
{n : ℕ} → (P : MvPFunctor.{u} (n + 1)) → {α : TypeVec.{u} n} → {β : Type u} → (β → ↑P (α ::: β)) → β → P.M α
Corecursor for M-type of P
def MvPFunctor.M.pathDestLeft E1 #
{n : ℕ} →
(P : MvPFunctor.{u} (n + 1)) →
{α : TypeVec.{u_1} n} →
{x : P.last.M} →
{a : P.A} →
{f : P.last.B a → P.last.M} → x.dest = ⟨a, f⟩ → TypeVec.Arrow (MvPFunctor.M.Path P x) α → (P.drop.B a).Arrow α
Implementation of destructor for M-type of P
def MvPFunctor.M.pathDestRight E1 #
{n : ℕ} →
(P : MvPFunctor.{u} (n + 1)) →
{α : TypeVec.{u_1} n} →
{x : P.last.M} →
{a : P.A} →
{f : P.last.B a → P.last.M} →
x.dest = ⟨a, f⟩ →
TypeVec.Arrow (MvPFunctor.M.Path P x) α → (j : P.last.B a) → TypeVec.Arrow (MvPFunctor.M.Path P (f j)) α
Implementation of destructor for M-type of P
def MvPFunctor.M.dest' E1 #
{n : ℕ} →
(P : MvPFunctor.{u} (n + 1)) →
{α : TypeVec.{u} n} →
{x : P.last.M} →
{a : P.A} →
{f : P.last.B a → P.last.M} → x.dest = ⟨a, f⟩ → TypeVec.Arrow (MvPFunctor.M.Path P x) α → ↑P (α ::: P.M α)
Destructor for M-type of P
def MvPFunctor.M.dest E3 #
{n : ℕ} → (P : MvPFunctor.{u} (n + 1)) → {α : TypeVec.{u} n} → P.M α → ↑P (α ::: P.M α)
Destructor for M-types
def MvPFunctor.M.mk E3 #
{n : ℕ} → (P : MvPFunctor.{u} (n + 1)) → {α : TypeVec.{u} n} → ↑P (α ::: P.M α) → P.M α
Constructor for M-types
theorem MvPFunctor.M.dest'_eq_dest' E1 #
∀ {n : ℕ} (P : MvPFunctor.{u} (n + 1)) {α : TypeVec.{u} n} {x : P.last.M} {a₁ : P.A} {f₁ : P.last.B a₁ → P.last.M}
(h₁ : x.dest = ⟨a₁, f₁⟩) {a₂ : P.A} {f₂ : P.last.B a₂ → P.last.M} (h₂ : x.dest = ⟨a₂, f₂⟩)
(f' : TypeVec.Arrow (MvPFunctor.M.Path P x) α), MvPFunctor.M.dest' P h₁ f' = MvPFunctor.M.dest' P h₂ f'
theorem MvPFunctor.M.dest_eq_dest' E1 #
∀ {n : ℕ} (P : MvPFunctor.{u} (n + 1)) {α : TypeVec.{u} n} {x : P.last.M} {a : P.A} {f : P.last.B a → P.last.M}
(h : x.dest = ⟨a, f⟩) (f' : TypeVec.Arrow (MvPFunctor.M.Path P x) α),
MvPFunctor.M.dest P ⟨x, f'⟩ = MvPFunctor.M.dest' P h f'
theorem MvPFunctor.M.dest_corec' E1 #
∀ {n : ℕ} (P : MvPFunctor.{u} (n + 1)) {α : TypeVec.{u} n} {β : Type v} (g₀ : β → P.A)
(g₁ : (b : β) → (P.drop.B (g₀ b)).Arrow α) (g₂ : (b : β) → P.last.B (g₀ b) → β) (x : β),
MvPFunctor.M.dest P (MvPFunctor.M.corec' P g₀ g₁ g₂ x) =
⟨g₀ x, TypeVec.splitFun (g₁ x) (MvPFunctor.M.corec' P g₀ g₁ g₂ ∘ g₂ x)⟩
theorem MvPFunctor.M.dest_corec E1 #
∀ {n : ℕ} (P : MvPFunctor.{u} (n + 1)) {α : TypeVec.{u} n} {β : Type u} (g : β → ↑P (α ::: β)) (x : β),
MvPFunctor.M.dest P (MvPFunctor.M.corec P g x) = MvFunctor.map (TypeVec.id ::: MvPFunctor.M.corec P g) (g x)
theorem MvPFunctor.M.bisim_lemma E1 #
∀ {n : ℕ} (P : MvPFunctor.{u} (n + 1)) {α : TypeVec.{u} n} {a₁ : P.mp.A} {f₁ : (P.mp.B a₁).Arrow α} {a' : P.A}
{f' : (P.B a').drop.Arrow α} {f₁' : (P.B a').last → P.M α},
MvPFunctor.M.dest P ⟨a₁, f₁⟩ = ⟨a', TypeVec.splitFun f' f₁'⟩ →
∃ g₁',
∃ (e₁' : PFunctor.M.dest a₁ = ⟨a', g₁'⟩),
f' = MvPFunctor.M.pathDestLeft P e₁' f₁ ∧ f₁' = fun x ↦ ⟨g₁' x, MvPFunctor.M.pathDestRight P e₁' f₁ x⟩
theorem MvPFunctor.M.bisim E3 #
∀ {n : ℕ} (P : MvPFunctor.{u} (n + 1)) {α : TypeVec.{u} n} (R : P.M α → P.M α → Prop),
(∀ (x y : P.M α),
R x y →
∃ a f f₁ f₂,
MvPFunctor.M.dest P x = ⟨a, TypeVec.splitFun f f₁⟩ ∧
MvPFunctor.M.dest P y = ⟨a, TypeVec.splitFun f f₂⟩ ∧ ∀ (i : (P.B a).last), R (f₁ i) (f₂ i)) →
∀ (x y : P.M α), R x y → x = y
theorem MvPFunctor.M.bisim₀ E1 #
∀ {n : ℕ} (P : MvPFunctor.{u} (n + 1)) {α : TypeVec.{u} n} (R : P.M α → P.M α → Prop),
Equivalence R →
(∀ (x y : P.M α),
R x y →
MvFunctor.map (TypeVec.id ::: Quot.mk R) (MvPFunctor.M.dest P x) =
MvFunctor.map (TypeVec.id ::: Quot.mk R) (MvPFunctor.M.dest P y)) →
∀ (x y : P.M α), R x y → x = y
theorem MvPFunctor.M.bisim' E1 #
∀ {n : ℕ} (P : MvPFunctor.{u} (n + 1)) {α : TypeVec.{u} n} (R : P.M α → P.M α → Prop),
(∀ (x y : P.M α),
R x y →
MvFunctor.map (TypeVec.id ::: Quot.mk R) (MvPFunctor.M.dest P x) =
MvFunctor.map (TypeVec.id ::: Quot.mk R) (MvPFunctor.M.dest P y)) →
∀ (x y : P.M α), R x y → x = y
theorem MvPFunctor.M.dest_map E1 #
∀ {n : ℕ} (P : MvPFunctor.{u} (n + 1)) {α β : TypeVec.{u} n} (g : α.Arrow β) (x : P.M α),
MvPFunctor.M.dest P (MvFunctor.map g x) = MvFunctor.map (g ::: fun x ↦ MvFunctor.map g x) (MvPFunctor.M.dest P x)
theorem MvPFunctor.M.map_dest E0 #
∀ {n : ℕ} (P : MvPFunctor.{u} (n + 1)) {α β : TypeVec.{u} n} (g : (α ::: P.M α).Arrow (β ::: P.M β)) (x : P.M α),
(∀ (x : P.M α), TypeVec.lastFun g x = MvFunctor.map (TypeVec.dropFun g) x) →
MvFunctor.map g (MvPFunctor.M.dest P x) = MvPFunctor.M.dest P (MvFunctor.map (TypeVec.dropFun g) x)