The areas / V33. Data structures and computation
Mathlib.Data.QPF.Multivariate.Basic
28 declarations. Mathlib docs · Source
Multivariate quotients of polynomial functors.
Basic definition of multivariate QPF. QPFs form a compositional framework for defining inductive and coinductive types, their quotients and nesting.
The idea is based on building ever larger functors. For instance, we can define a list using a shape functor:
inductive ListShape (a b : Type)
| nil : ListShape
| cons : a -> b -> ListShape
This shape can itself be decomposed as a sum of products which are themselves QPFs. It follows that the shape is a QPF and we can take its fixed point and create the list itself:
def List (a : Type) := fix ListShape a -- not the actual notation
We can continue and define the quotient on permutation of lists and create the multiset type:
def Multiset (a : Type) := QPF.quot List.perm List a -- not the actual notion
And Multiset is also a QPF. We can then create a novel data type (for Lean):
inductive Tree (a : Type)
| node : a -> Multiset Tree -> Tree
An unordered tree. This is currently not supported by Lean because it nests an inductive type inside of a quotient. We can go further and define unordered, possibly infinite trees:
coinductive Tree' (a : Type)
| node : a -> Multiset Tree' -> Tree'
by using the cofix construct. Those options can all be mixed and
matched because they preserve the properties of QPF. The latter example,
Tree', combines fixed point, co-fixed point and quotients.
Related modules
- constructions
- Fix
- Cofix
- Quot
- Comp
- Sigma / Pi
- Prj
- Const
each proves that some operations on functors preserve the QPF structure
References
[Jeremy Avigad, Mario M. Carneiro and Simon Hudon, Data Types as Quotients of Polynomial Functors][avigad-carneiro-hudon2019]
Show that every MvQPF is a lawful MvFunctor.
def MvQPF.ctorIdx E1 #
{n : ℕ} → {F : TypeVec.{u} n → Type u_1} → MvQPF F → ℕ
class MvQPF E1 #
{n : ℕ} → (TypeVec.{u} n → Type u_1) → Type (max (u + 1) u_1)
Multivariate quotients of polynomial functors.
instance MvQPF.toMvFunctor E0 #
{n : ℕ} → {F : TypeVec.{u} n → Type u_1} → [self : MvQPF F] → MvFunctor F
ctor MvQPF.mk E0 #
{n : ℕ} →
{F : TypeVec.{u} n → Type u_1} →
[toMvFunctor : MvFunctor F] →
(P : MvPFunctor.{u} n) →
(abs : {α : TypeVec.{u} n} → ↑P α → F α) →
(repr : {α : TypeVec.{u} n} → F α → ↑P α) →
(∀ {α : TypeVec.{u} n} (x : F α), abs (repr x) = x) →
(∀ {α β : TypeVec.{u} n} (f : α.Arrow β) (p : ↑P α), abs (MvFunctor.map f p) = MvFunctor.map f (abs p)) →
MvQPF F
abbrev MvQPF.P E1 #
{n : ℕ} → (F : TypeVec.{u} n → Type u_1) → [self : MvQPF F] → MvPFunctor.{u} n
abbrev MvQPF.abs E1 #
{n : ℕ} → {F : TypeVec.{u} n → Type u_1} → [self : MvQPF F] → {α : TypeVec.{u} n} → ↑(MvQPF.P F) α → F α
abbrev MvQPF.repr E1 #
{n : ℕ} → {F : TypeVec.{u} n → Type u_1} → [self : MvQPF F] → {α : TypeVec.{u} n} → F α → ↑(MvQPF.P F) α
theorem MvQPF.abs_repr E1 #
∀ {n : ℕ} {F : TypeVec.{u} n → Type u_1} [self : MvQPF F] {α : TypeVec.{u} n} (x : F α), MvQPF.abs (MvQPF.repr x) = x
theorem MvQPF.abs_map E1 #
∀ {n : ℕ} {F : TypeVec.{u} n → Type u_1} [self : MvQPF F] {α β : TypeVec.{u} n} (f : α.Arrow β) (p : ↑(MvQPF.P F) α),
MvQPF.abs (MvFunctor.map f p) = MvFunctor.map f (MvQPF.abs p)
theorem MvQPF.id_map E1 #
∀ {n : ℕ} {F : TypeVec.{u} n → Type u_1} [q : MvQPF F] {α : TypeVec.{u} n} (x : F α), MvFunctor.map TypeVec.id x = x
theorem MvQPF.comp_map E0 #
∀ {n : ℕ} {F : TypeVec.{u} n → Type u_1} [q : MvQPF F] {α β γ : TypeVec.{u} n} (f : α.Arrow β) (g : β.Arrow γ)
(x : F α), MvFunctor.map (TypeVec.comp g f) x = MvFunctor.map g (MvFunctor.map f x)
instance MvQPF.lawfulMvFunctor E0 #
∀ {n : ℕ} {F : TypeVec.{u} n → Type u_1} [q : MvQPF F], LawfulMvFunctor F
theorem MvQPF.liftP_iff E0 #
∀ {n : ℕ} {F : TypeVec.{u} n → Type u_1} [q : MvQPF F] {α : TypeVec.{u} n} (p : ⦃i : Fin2 n⦄ → α i → Prop) (x : F α),
MvFunctor.LiftP p x ↔ ∃ a f, x = MvQPF.abs ⟨a, f⟩ ∧ ∀ (i : Fin2 n) (j : (MvQPF.P F).B a i), p (f i j)
theorem MvQPF.liftR_iff E0 #
∀ {n : ℕ} {F : TypeVec.{u} n → Type u_1} [q : MvQPF F] {α : TypeVec.{u} n} (r : ⦃i : Fin2 n⦄ → α i → α i → Prop)
(x y : F α),
MvFunctor.LiftR r x y ↔
∃ a f₀ f₁,
x = MvQPF.abs ⟨a, f₀⟩ ∧ y = MvQPF.abs ⟨a, f₁⟩ ∧ ∀ (i : Fin2 n) (j : (MvQPF.P F).B a i), r (f₀ i j) (f₁ i j)
theorem MvQPF.mem_supp E0 #
∀ {n : ℕ} {F : TypeVec.{u} n → Type u_1} [q : MvQPF F] {α : TypeVec.{u} n} (x : F α) (i : Fin2 n) (u : α i),
u ∈ MvFunctor.supp x i ↔
∀ (a : (MvQPF.P F).A) (f : ((MvQPF.P F).B a).Arrow α), MvQPF.abs ⟨a, f⟩ = x → u ∈ f i '' Set.univ
theorem MvQPF.supp_eq E0 #
∀ {n : ℕ} {F : TypeVec.{u} n → Type u_1} [q : MvQPF F] {α : TypeVec.{u} n} {i : Fin2 n} (x : F α),
MvFunctor.supp x i =
{u | ∀ (a : (MvQPF.P F).A) (f : ((MvQPF.P F).B a).Arrow α), MvQPF.abs ⟨a, f⟩ = x → u ∈ f i '' Set.univ}
theorem MvQPF.has_good_supp_iff E0 #
∀ {n : ℕ} {F : TypeVec.{u} n → Type u_1} [q : MvQPF F] {α : TypeVec.{u} n} (x : F α),
(∀ (p : (i : Fin2 n) → α i → Prop), MvFunctor.LiftP p x ↔ ∀ (i : Fin2 n), ∀ u ∈ MvFunctor.supp x i, p i u) ↔
∃ a f,
MvQPF.abs ⟨a, f⟩ = x ∧
∀ (i : Fin2 n) (a' : (MvQPF.P F).A) (f' : ((MvQPF.P F).B a').Arrow α),
MvQPF.abs ⟨a', f'⟩ = x → f i '' Set.univ ⊆ f' i '' Set.univ
def MvQPF.IsUniform E1 #
{n : ℕ} → {F : TypeVec.{u} n → Type u_1} → [q : MvQPF F] → Prop
A qpf is said to be uniform if every polynomial functor representing a single value all have the same range.
def MvQPF.LiftPPreservation E1 #
{n : ℕ} → {F : TypeVec.{u} n → Type u_1} → [q : MvQPF F] → Prop
does abs preserve liftp?
def MvQPF.SuppPreservation E1 #
{n : ℕ} → {F : TypeVec.{u} n → Type u_1} → [q : MvQPF F] → Prop
does abs preserve supp?
theorem MvQPF.supp_eq_of_isUniform E1 #
∀ {n : ℕ} {F : TypeVec.{u} n → Type u_1} [q : MvQPF F],
MvQPF.IsUniform →
∀ {α : TypeVec.{u} n} (a : (MvQPF.P F).A) (f : ((MvQPF.P F).B a).Arrow α) (i : Fin2 n),
MvFunctor.supp (MvQPF.abs ⟨a, f⟩) i = f i '' Set.univ
theorem MvQPF.liftP_iff_of_isUniform E1 #
∀ {n : ℕ} {F : TypeVec.{u} n → Type u_1} [q : MvQPF F],
MvQPF.IsUniform →
∀ {α : TypeVec.{u} n} (x : F α) (p : (i : Fin2 n) → α i → Prop),
MvFunctor.LiftP p x ↔ ∀ (i : Fin2 n), ∀ u ∈ MvFunctor.supp x i, p i u
theorem MvQPF.supp_map E1 #
∀ {n : ℕ} {F : TypeVec.{u} n → Type u_1} [q : MvQPF F],
MvQPF.IsUniform →
∀ {α β : TypeVec.{u} n} (g : α.Arrow β) (x : F α) (i : Fin2 n),
MvFunctor.supp (MvFunctor.map g x) i = g i '' MvFunctor.supp x i
theorem MvQPF.suppPreservation_iff_isUniform E1 #
∀ {n : ℕ} {F : TypeVec.{u} n → Type u_1} [q : MvQPF F], MvQPF.SuppPreservation ↔ MvQPF.IsUniform
theorem MvQPF.suppPreservation_iff_liftpPreservation E1 #
∀ {n : ℕ} {F : TypeVec.{u} n → Type u_1} [q : MvQPF F], MvQPF.SuppPreservation ↔ MvQPF.LiftPPreservation
theorem MvQPF.liftpPreservation_iff_uniform E1 #
∀ {n : ℕ} {F : TypeVec.{u} n → Type u_1} [q : MvQPF F], MvQPF.LiftPPreservation ↔ MvQPF.IsUniform
def MvQPF.ofEquiv E1 #
{n : ℕ} →
{F : TypeVec.{u} n → Type u_2} →
{F' : TypeVec.{u} n → Type u_3} →
[q : MvQPF F'] →
[inst : MvFunctor F] →
(eqv : (α : TypeVec.{u} n) → F α ≃ F' α) →
autoParam
(∀ (α β : TypeVec.{u} n) (f : α.Arrow β) (a : F α),
MvFunctor.map f a = (eqv β).symm (MvFunctor.map f ((eqv α) a)))
MvQPF.ofEquiv._auto_1 →
MvQPF F
Any type function F that is (extensionally) equivalent to a QPF, is itself a QPF,
assuming that the functorial map of F behaves similar to MvFunctor.ofEquiv eqv
instance MvPFunctor.instMvQPFObj E0 #
{n : ℕ} → (P : MvPFunctor.{u_1} n) → MvQPF ↑P
Every polynomial functor is a (trivial) QPF