\begin{code} {-# OPTIONS --cubical --safe --postfix-projections #-} open import Algebra open import Level module Control.Monad.Weighted.Eliminators {β} {π : Type β} (rng : Semiring π ) where open Semiring rng open import Level open import Path open import HLevels open import Control.Monad.Weighted.Definition rng open import Control.Monad.Weighted.Functor rng open import Control.Monad.Weighted.Functor.TypeDef open import Data.Sigma private variable p q : Level P : Weighted A β Type p Q : Weighted A β Type q module _ {A : Type a} {P : Weighted A β Type p} where \end{code} %<*coherent> \begin{code} record Coherent (Ο : Alg A P) : Type (p ββ a ββ β) where field c-set : β xs β isSet (P xs) c-dup : β p q x xs Οβ¨xsβ© β Ο (p β x β· (q β x β· xs) β¨ Ο (q β x β· xs β¨ Οβ¨xsβ© β©) β©) β‘[ i β P (dup p q x xs i) ]β‘ Ο ((p + q) β x β· xs β¨ Οβ¨xsβ© β©) c-com : β p x q y xs Οβ¨xsβ© β Ο (p β x β· (q β y β· xs) β¨ Ο (q β y β· xs β¨ Οβ¨xsβ© β©) β©) β‘[ i β P (com p x q y xs i) ]β‘ Ο (q β y β· (p β x β· xs) β¨ Ο (p β x β· xs β¨ Οβ¨xsβ© β©) β©) c-del : β x xs Οβ¨xsβ© β Ο (0# β x β· xs β¨ Οβ¨xsβ© β©) β‘[ i β P (del x xs i) ]β‘ Οβ¨xsβ© \end{code} %</coherent> \begin{code} open Coherent public \end{code} %<*elim-decl> \begin{code} Ξ¨ : (A : Type a) (P : Weighted A β Type p) β Type _ Ξ¨ A P = Ξ£ (Alg A P) Coherent \end{code} %</elim-decl> \begin{code} infixr 1 Ξ¨ syntax Ξ¨ A (Ξ» v β e) = Ξ¨[ v β¦ A ] e \end{code} %<*recursor-decl> \begin{code} Ξ¦ : Type a β Type b β Type (a ββ b ββ β) Ξ¦ A B = Ξ¨ A (Ξ» _ β B) \end{code} %</recursor-decl> %<*runner-ty> \begin{code} β¦_β§ : Ξ¨ A P β (xs : Weighted A) β P xs \end{code} %</runner-ty> \begin{code} β¦ alg β§ [] = alg .fst [] β¦ alg β§ (p β x β· xs) = alg .fst (p β x β· xs β¨ β¦ alg β§ xs β©) β¦ alg β§ (dup p q x xs i) = alg .snd .c-dup p q x xs (β¦ alg β§ xs) i β¦ alg β§ (com p x q y xs i) = alg .snd .c-com p x q y xs (β¦ alg β§ xs) i β¦ alg β§ (del x xs i) = alg .snd .c-del x xs (β¦ alg β§ xs) i β¦ alg β§ (trunc xs ys p q i j) = isOfHLevelβisOfHLevelDep 2 (alg .snd .c-set) (β¦ alg β§ xs) (β¦ alg β§ ys) (cong β¦ alg β§ p) (cong β¦ alg β§ q) (trunc xs ys p q) i j prop-coh : {A : Type a} {P : Weighted A β Type p} {alg : Alg A P} β (β xs β isProp (P xs)) β Coherent alg prop-coh P-isProp .c-set xs = isPropβisSet (P-isProp xs) prop-coh {P = P} {alg = alg} P-isProp .c-dup p q x xs Οβ¨xsβ© = toPathP (P-isProp (p + q β x β· xs) (transp (Ξ» i β P (dup p q x xs i)) i0 (alg (p β x β· (q β x β· xs) β¨ alg (q β x β· xs β¨ Οβ¨xsβ© β©) β©))) (alg ((p + q) β x β· xs β¨ Οβ¨xsβ© β©))) prop-coh {P = P} {alg = alg} P-isProp .c-com p x q y xs Οβ¨xsβ© = toPathP (P-isProp (q β y β· p β x β· xs) (transp (Ξ» i β P (com p x q y xs i)) i0 (alg (p β x β· (q β y β· xs) β¨ alg (q β y β· xs β¨ Οβ¨xsβ© β©) β©))) (alg (q β y β· (p β x β· xs) β¨ alg (p β x β· xs β¨ Οβ¨xsβ© β©) β©))) prop-coh {P = P} {alg = alg} P-isProp .c-del x xs Οβ¨xsβ© = toPathP (P-isProp xs (transp (Ξ» i β P (del x xs i)) i0 (alg (0# β x β· xs β¨ Οβ¨xsβ© β©))) Οβ¨xsβ©) infix 4 _β_ record AnEquality (A : Type a) : Type (a ββ β) where constructor _β_ field lhs rhs : Weighted A open AnEquality public EqualityProof-Alg : {B : Type b} (A : Type a) (P : Weighted A β AnEquality B) β Type (a ββ b ββ β) EqualityProof-Alg A P = Alg A (Ξ» xs β let Pxs = P xs in lhs Pxs β‘ rhs Pxs) eq-coh : {A : Type a} {B : Type b} {P : Weighted A β AnEquality B} {alg : EqualityProof-Alg A P} β Coherent alg eq-coh {P = P} = prop-coh Ξ» xs β let Pxs = P xs in trunc (lhs Pxs) (rhs Pxs) \end{code}