{-# OPTIONS --safe #-}
module README where
open import Multiset.Prelude
open import Multiset.Util using (isInjective)
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism using (Iso ; section)
open import Cubical.Data.List as List using (List)
open import Cubical.Data.Nat as Nat using (ℕ ; suc)
open import Cubical.Data.SumFin using (Fin)
open import Cubical.HITs.PropositionalTruncation as PT using (∥_∥₁)
open import Cubical.HITs.SetQuotients as SQ using (_/_)
open import Cubical.HITs.SetTruncation as ST using (∥_∥₂ ; ∣_∣₂)
import Multiset.FCM
FCM : ∀ {ℓ} → Type ℓ → Type ℓ
FCM = Multiset.FCM.M
import Multiset.Ordering.Order
import Multiset.Ordering.PermEquiv
Perm : ∀ {A} → List A → List A → Type
Perm = Multiset.Ordering.Order.Perm
List[_]/Perm : Type → Type
List[_]/Perm = Multiset.Ordering.Order.Mset
import Multiset.ListQuotient.Base
DRelator : ∀ {ℓ} {X Y : Type ℓ} (R : X → Y → Type ℓ) → List X → List Y → Type ℓ
DRelator = Multiset.ListQuotient.Base.DRelator
Relator : ∀ {ℓ} {X : Type ℓ} (R : X → X → Type ℓ) → List X → List X → Type ℓ
Relator = Multiset.ListQuotient.Base.Relator
import Multiset.Ordering.PermEquiv
∥Perm∥₁≃Relator≡ : {A : Type} {xs ys : List A} → ∥ Perm xs ys ∥₁ ≃ Relator _≡_ xs ys
∥Perm∥₁≃Relator≡ = Multiset.Ordering.PermEquiv.∥Perm∥₁≃Relator=
import Multiset.FMSet
import Multiset.ListQuotient.FMSetEquiv
FMSet : ∀ {ℓ} → Type ℓ → Type ℓ
FMSet = Multiset.FMSet.FMSet
SymAct : ∀ {X} → (n : ℕ) → (v w : Fin n → X) → Type
SymAct = Multiset.FMSet.SymmetricAction
SymAct∞ : ∀ {X} → (n : ℕ) → (v w : Fin n → X) → Type
SymAct∞ = Multiset.ListQuotient.FMSetEquiv.SymmetricActionΣ
_∼_ = Multiset.FMSet._∼_
import Multiset.FiniteChoice
module FiniteChoice {n : ℕ} (Y : Fin n → Type) where
finChoiceEquiv : ((k : Fin n) → ∥ Y k ∥₂) ≃ ∥ ((k : Fin n) → Y k) ∥₂
finChoiceEquiv = Multiset.FiniteChoice.setFinChoice≃ Y
box : ((k : Fin n) → ∥ Y k ∥₂) → ∥ ((k : Fin n) → Y k) ∥₂
box = Multiset.FiniteChoice.box
unbox : ∥ ((k : Fin n) → Y k) ∥₂ → ((k : Fin n) → ∥ Y k ∥₂)
unbox = Multiset.FiniteChoice.unbox
elim-∥_∥₂-fin : {n : ℕ} (X : Type) {B : (Fin n → ∥ X ∥₂) → Type}
→ ((∣v∣ : Fin n → ∥ X ∥₂) → isSet (B ∣v∣))
→ ((v : Fin n → X) → B (∣_∣₂ ∘ v))
→ (v : Fin n → ∥ X ∥₂) → B v
elim-∥ X ∥₂-fin = Multiset.FiniteChoice.elimₙ
elim-∥_∥₂-finᵝ : {n : ℕ} (X : Type) {B : (Fin n → ∥ X ∥₂) → Type}
→ (setB : (∣v∣ : Fin n → ∥ X ∥₂) → isSet (B ∣v∣))
→ (choice : (v : Fin n → X) → B (∣_∣₂ ∘ v))
→ (v : Fin n → X)
→ elim-∥ X ∥₂-fin setB choice (∣_∣₂ ∘ v) ≡ choice v
elim-∥ X ∥₂-finᵝ = Multiset.FiniteChoice.elimₙ-comp
import Multiset.FMSet.Properties using (module STInvariance)
FMSetTruncInvariance : {X : Type} → FMSet ∥ X ∥₂ ≃ FMSet X
FMSetTruncInvariance = Multiset.FMSet.Properties.STInvariance.STInvarianceEquiv
import Multiset.Equivalences.FCM-PList
import Multiset.Equivalences.PList-RelatorList
FMSetEquivs : ∀ X → FCM X ≃ FMSet X
FMSetEquivs X =
FCM X ≃⟨ Multiset.Equivalences.FCM-PList.M≃PList ⟩
List X / Perm ≃⟨ Multiset.Equivalences.PList-RelatorList.List/Perm≃List/Relator≡ ⟩
List X / Relator _≡_ ≃⟨ invEquiv Multiset.ListQuotient.FMSetEquiv.FMSet≃List/Relator= ⟩
FMSet X ■
FCM≃List/Perm-natural = Multiset.Equivalences.FCM-PList.PListToM-nat
List/Perm≃List/Relator-natural = Multiset.Equivalences.PList-RelatorList.List/Perm→List/Relator≡-nat
FMSet→List/Relator=-natural = Multiset.Equivalences.PList-RelatorList.FMSet→List/Relator=-nat
import Multiset.Util.BundledVec
import Multiset.ListQuotient.ListFinality
List' : Type → Type
List' = Multiset.Util.BundledVec.ΣVec
_ = Multiset.ListQuotient.ListFinality.isTerminalFix⁻
Relator' : _
Relator' = Multiset.Util.BundledVec.Relator
ΣVec-List-nat = Multiset.ListQuotient.ListFinality.ΣVec-List-EquivNat
open import Cubical.HITs.FiniteMultiset.Base using () renaming (FMSet to HeadPList)
import Multiset.Equivalences.FCM-HeadPList
_ : ∀ {X : Type} → FCM X ≃ HeadPList X
_ = Multiset.Equivalences.FCM-HeadPList.M≃HeadPList
import Multiset.Ordering.Order
isLinOrder : {A : Type} (R : A → A → Type) → Type
isLinOrder = Multiset.Ordering.Order.isLinOrder
module LexFMSet {A : Type} (setA : isSet A) (R : A → A → Type) (linR : isLinOrder R) where
import Multiset.Ordering.FMSetOrder
module S = Multiset.Ordering.FMSetOrder.SortingFMSet setA R linR
sort : (n : ℕ) → (Fin n → A) / _∼_ → (Fin n → A)
sort = S.sortPVect
SymActDefinable : (n : ℕ) → section SQ.[_] (sort n)
SymActDefinable = S.sortPVect-section
SymActUntruncate : (n : ℕ) (v w : Fin n → A) → SymAct n v w → SymAct∞ n v w
SymActUntruncate = S.canonicalS
canonPerm : (xs ys : List A) → Perm xs ys → Perm xs ys
canonPerm = Multiset.Ordering.Order.Sorting.canonPerm setA R linR
module BraidExample = Multiset.Ordering.Order.Example
LexFMSet : FMSet A → FMSet A → Type
LexFMSet = S.LexFMSet
linLexFMSet : isLinOrder LexFMSet
linLexFMSet = S.linLexFMSet
import Multiset.Functor
import Multiset.Coalgebra
Functor : (F : Type → Type) → Type _
Functor = Multiset.Functor.Functor
Coalgebra : (F : Type → Type) → ⦃ Functor F ⦄ → _
Coalgebra F = ∀ {A} → A → F A
CoalgebraMorphism : (F : Type → Type) → ⦃ Functor F ⦄ → ∀ {A B} → (α : A → F A) → (β : B → F B) → Type _
CoalgebraMorphism = Multiset.Coalgebra.CoalgebraMorphism
open import Multiset.Limit.TerminalChain as TerminalChain
using
( ch
; _^_
; _map-!^_
; Lim
; ShLim
; isLimitPreserving
)
module IterLimit (F : Type → Type) {{FunctorF : Functor F}} where
shift : Lim F ≃ ShLim F
shift = invEquiv (TerminalChain.ShLim≃Lim F)
ℓ : (n : ℕ) → Lim F → F ^ n
ℓ = TerminalChain.cut F
pres : F (Lim F) → ShLim F
pres = TerminalChain.pres F
fix : isLimitPreserving F → F (Lim F) ≃ Lim F
fix = TerminalChain.fix
coalg : isLimitPreserving F → Lim F → F (Lim F)
coalg = TerminalChain.Fixpoint.fix⁻
open import Multiset.Limit.Chain using (Chain ; ChainEquiv ; Limit)
import Multiset.Limit.Isomorphism
chainEquivToLimitEquiv : ∀ {ℓ} {C C' : Chain ℓ} → ChainEquiv C C' → Limit C ≃ Limit C'
chainEquivToLimitEquiv = Multiset.Limit.Isomorphism.mapLimit-pres-equiv
open IterLimit using (pres)
import Multiset.FCM.Limit
open import Multiset.Omniscience using (LLPO)
InjectiveFMSetPresToLLPO : isInjective (pres FCM) → LLPO
InjectiveFMSetPresToLLPO = Multiset.FCM.Limit.pres-inj⇒llpo
LimitAlternationLemma = TerminalChain.diag-islim-alternating
FMSetAlternationLemma = TerminalChain.diag-islim-alternating (FCM {ℓ = ℓ-zero})
CompleteToLLPO : Multiset.FCM.Limit.Complete → LLPO
CompleteToLLPO = Multiset.FCM.Limit.complete⇒llpo
import Multiset.ListQuotient.ToInjectivity
LLPOToInjectiveFMSetPres : LLPO → isInjective (pres (λ X → List X / Relator _≡_))
LLPOToInjectiveFMSetPres = Multiset.ListQuotient.ToInjectivity.llpo⇒pres-inj
import Multiset.FMSet.Limit
LexFMSet^ : (n : ℕ) → FMSet ^ n → FMSet ^ n → Type
LexFMSet^ = Multiset.FMSet.Limit.LexFMSet^
linLexIterFMSet : ∀ n → isLinOrder (LexFMSet^ n)
linLexIterFMSet = Multiset.FMSet.Limit.linLexFMSet^
FMSetPresSection : section (pres FMSet) Multiset.FMSet.Limit.PresSection.pres⁻¹
FMSetPresSection = Multiset.FMSet.Limit.PresSection.pres-section
import Multiset.ListQuotient.Bisimilarity
Tree = Multiset.ListQuotient.ListFinality.Tree
_ : Tree ≡ Lim List'
_ = refl
coalgList : Tree → List' Tree
coalgList = Multiset.ListQuotient.ListFinality.fix⁻
Approx : (n : ℕ) → List' ^ n → List' ^ n → Type
Approx = Multiset.ListQuotient.Bisimilarity.Approx
!-Approx : (n : ℕ) {s t : (List' ^ (suc n))}
→ Relator' (Approx n) s t → Approx n ((List' map-!^ n) s) ((List' map-!^ n) t)
!-Approx = Multiset.ListQuotient.Bisimilarity.Approx-π
Bisim : (s t : Tree) → Type
Bisim = Multiset.ListQuotient.Bisimilarity.Bisim
open import Multiset.Axioms.Choice as AOC using (AC)
import Multiset.ListQuotient.LLPO
open import Cubical.Categories.Functor using () renaming (Functor to Functor')
import Multiset.Categories.Coalgebra as Cat
open import Cubical.Categories.Instances.Sets using (SET)
module Setoid (isSetoidMorCoalgList : (∀ {s} {t} → Bisim s t → Relator' Bisim (coalgList s) (coalgList t))) where
isSetoidMorphismCoalgListToLLPO : LLPO
isSetoidMorphismCoalgListToLLPO = Multiset.ListQuotient.LLPO.fix⁻-preserves-≈→LLPO isSetoidMorCoalgList
import Multiset.Setoid.Category
open import Cubical.Categories.Category using (Category)
SetoidCategory : Category (ℓ-suc ℓ-zero) ℓ-zero
SetoidCategory = Multiset.Setoid.Category.SetoidCategory ℓ-zero ℓ-zero
FMSetoid : Functor' SetoidCategory SetoidCategory
FMSetoid = Multiset.Util.BundledVec.RelatorFunctor
import Multiset.ListQuotient.Finality
finalFMSetoidCoalgebra : Cat.TerminalCoalgebra FMSetoid
finalFMSetoidCoalgebra = Multiset.ListQuotient.Finality.finalFMSetoidCoalgebra isSetoidMorCoalgList
import Multiset.ListQuotient.Fixpoint
FMSet' : Type → Type
FMSet' X = List' X / (Relator' _≡_)
coalgFMSet : Tree / Bisim → FMSet' (Tree / Bisim)
coalgFMSet = Multiset.ListQuotient.Fixpoint.fixQ⁻ isSetoidMorCoalgList
FMSetFixpointTree/Bisim : FMSet' (Tree / Bisim) ≃ Tree / Bisim
FMSetFixpointTree/Bisim = Multiset.ListQuotient.Fixpoint.FMSetFixpointTree/Bisim isSetoidMorCoalgList
FMSetFunctor : Functor' (SET _) (SET _)
FMSetFunctor = Multiset.ListQuotient.Fixpoint.FMSetFunctor
FinalFMSetCoalgebra : AC _ _ _ → Cat.TerminalCoalgebra FMSetFunctor
FinalFMSetCoalgebra = Multiset.ListQuotient.Fixpoint.TerminalfixQ⁻ isSetoidMorCoalgList
open import Cubical.Data.FinSet.Base using (FinSet)
import Multiset.Tote
Tote : Type₀ → Type₁
Tote = Multiset.Tote.Tote
isGroupoidTote : ∀ {X : Type} → isGroupoid X → isGroupoid (Tote X)
isGroupoidTote = Multiset.Tote.isGroupoidTote
FMSetToteTruncEquiv : {X : Type} → FMSet X ≃ ∥ Tote X ∥₂
FMSetToteTruncEquiv = Multiset.Tote.FMSet≃∥Tote∥₂
FMSet→∥Tote∥₂ : ∀ {X : Type} → FMSet X → ∥ Tote X ∥₂
FMSet→∥Tote∥₂ = equivFun FMSetToteTruncEquiv
isNatural-FMSetToteTruncEquiv : ∀ {X Y : Type} (f : X → Y)
→ FMSet→∥Tote∥₂ ∘ Multiset.FMSet.map f ≡ ST.map (Multiset.Tote.map f) ∘ FMSet→∥Tote∥₂
isNatural-FMSetToteTruncEquiv = Multiset.Tote.isNatural-FMSet≃∥Tote∥₂
import Multiset.Bij
Bij : Type
Bij = Multiset.Bij.Bij
BinFinSetEquiv : Bij ≃ FinSet ℓ-zero
BinFinSetEquiv = Multiset.Bij.Bij≃FinSet
import Multiset.Bag
Bag : Type → Type
Bag = Multiset.Bag.Bag
BagToteEquiv : ∀ {X : Type} → Bag X ≃ Tote X
BagToteEquiv = Multiset.Bag.Bag≃Tote
isNaturalBagToteEquiv : {X Y : Type} → (f : X → Y)
→ equivFun BagToteEquiv ∘ Multiset.Bag.map f ≡ Multiset.Tote.map f ∘ equivFun BagToteEquiv
isNaturalBagToteEquiv = Multiset.Bag.isNaturalBagToteEquiv
isLimitPreservingBag : isEquiv (pres Bag)
isLimitPreservingBag = Multiset.Bag.isLimitPreservingBag
import Multiset.FMSet.Fixpoint
TruncBagFMSetEquiv : {X : Type} → ∥ Bag X ∥₂ ≃ FMSet X
TruncBagFMSetEquiv = Multiset.FMSet.Fixpoint.TruncBagFMSetEquiv
IterTruncBagFMSetEquiv : ∀ n → ∥ Bag ^ n ∥₂ ≃ FMSet ^ n
IterTruncBagFMSetEquiv = Multiset.FMSet.Fixpoint.IterTruncBagFMSetEquiv
FMSetFixpointTruncBagLim : FMSet ∥ Lim Bag ∥₂ ≃ ∥ Lim Bag ∥₂
FMSetFixpointTruncBagLim = Multiset.FMSet.Fixpoint.FMSetFixSetTruncTree
import Multiset.FMSet.Finality
FMSetFunctor' : Functor' (SET _) (SET _)
FMSetFunctor' = Multiset.FMSet.Finality.FMSetFunctor
module _
(ana : {X : Type} → (c : X → Bag X) → X → Lim Bag)
(anaEq : {X : Type} (c : X → Bag X)
→ ana c ≡ Multiset.Bag.fix⁺ ∘ Multiset.Bag.map (ana c) ∘ c)
(anaUniq : {X : Type} (c : X → Bag X)
→ (h : X → Lim Bag)
→ h ≡ Multiset.Bag.fix⁺ ∘ (Multiset.Bag.map h) ∘ c
→ ana c ≡ h)
where
abstract
e : {X : Type} → ∥ Bag X ∥₂ ≃ FMSet X
e = Multiset.FMSet.Fixpoint.TruncBagFMSetEquiv
eNat : ∀ {X Y : Type} (f : X → Y) → equivFun e ∘ ST.map (Multiset.Bag.map f) ≡ Multiset.FMSet.map f ∘ equivFun e
eNat = Multiset.FMSet.Fixpoint.isNaturalTruncBagFMSetEquiv
FMSetFinalCoalgebra : (ac32 : AOC.AC[Gpd,Set] ℓ-zero ℓ-zero) → (ac : AOC.AC[Set,Prop] ℓ-zero ℓ-zero) → Cat.TerminalCoalgebra FMSetFunctor'
FMSetFinalCoalgebra = Multiset.FMSet.Finality.FinalityWithChoice.FMSetFinalCoalgebra ana anaEq anaUniq e eNat
import Multiset.FMSet.FiniteFinality
coalgFinite : Cat.Coalgebra FMSetFunctor'
coalgFinite = Multiset.FMSet.FiniteFinality.FinalityFinite.coalg ana anaEq anaUniq e eNat
uniqueCoalgMorphismFinCarrier : ∀ n (c : Fin n → FMSet (Fin n)) → isContr (Cat.CoalgebraHom FMSetFunctor' (Cat.coalgebra c) coalgFinite)
uniqueCoalgMorphismFinCarrier = Multiset.FMSet.FiniteFinality.FinalityFinite.uniqueFiniteCoalg ana anaEq anaUniq e eNat