{-# OPTIONS --cubical --safe #-} module Algebra.Construct.Free.Semilattice.Eliminators where open import Algebra.Construct.Free.Semilattice.Definition open import Prelude open import Algebra record _β_ {a p} (A : Type a) (P : π¦ A β Type p) : Type (a ββ p) where no-eta-equality constructor elim field β¦_β§-set : β {xs} β isSet (P xs) β¦_β§[] : P [] β¦_β§_β·_β¨_β© : β x xs β P xs β P (x β· xs) private z = β¦_β§[]; f = β¦_β§_β·_β¨_β© field β¦_β§-com : β x y xs pxs β f x (y β· xs) (f y xs pxs) β‘[ i β P (com x y xs i) ]β‘ f y (x β· xs) (f x xs pxs) β¦_β§-dup : β x xs pxs β f x (x β· xs) (f x xs pxs) β‘[ i β P (dup x xs i) ]β‘ f x xs pxs β¦_β§β : β xs β P xs β¦ [] β§β = z β¦ x β· xs β§β = f x xs β¦ xs β§β β¦ com x y xs i β§β = β¦_β§-com x y xs β¦ xs β§β i β¦ dup x xs i β§β = β¦_β§-dup x xs β¦ xs β§β i β¦ trunc xs ys x y i j β§β = isOfHLevelβisOfHLevelDep 2 (Ξ» xs β β¦_β§-set {xs}) β¦ xs β§β β¦ ys β§β (cong β¦_β§β x) (cong β¦_β§β y) (trunc xs ys x y) i j {-# INLINE β¦_β§β #-} open _β_ public infixr 0 β-syntax β-syntax = _β_ syntax β-syntax A (Ξ» xs β Pxs) = xs βπ¦ A β Pxs record _β²_ {a p} (A : Type a) (P : π¦ A β Type p) : Type (a ββ p) where no-eta-equality constructor elim-prop field β₯_β₯-prop : β {xs} β isProp (P xs) β₯_β₯[] : P [] β₯_β₯_β·_β¨_β© : β x xs β P xs β P (x β· xs) private z = β₯_β₯[]; f = β₯_β₯_β·_β¨_β© β₯_β₯β = elim (Ξ» {xs} β isPropβisSet (β₯_β₯-prop {xs})) z f (Ξ» x y xs pxs β toPathP (β₯_β₯-prop (transp (Ξ» i β P (com x y xs i)) i0 (f x (y β· xs) (f y xs pxs))) (f y (x β· xs) (f x xs pxs)))) (Ξ» x xs pxs β toPathP (β₯_β₯-prop (transp (Ξ» i β P (dup x xs i)) i0 (f x (x β· xs) (f x xs pxs))) (f x xs pxs) )) β₯_β₯β = β¦ β₯_β₯β β§β {-# INLINE β₯_β₯β #-} {-# INLINE β₯_β₯β #-} open _β²_ public elim-prop-syntax : β {a p} β (A : Type a) β (π¦ A β Type p) β Type (a ββ p) elim-prop-syntax = _β²_ syntax elim-prop-syntax A (Ξ» xs β Pxs) = xs βπ¦ A ββ₯ Pxs β₯ record _ββ₯_β₯ {a p} (A : Type a) (P : π¦ A β Type p) : Type (a ββ p) where no-eta-equality constructor elim-to-prop field β£_β£[] : P [] β£_β£_β·_β¨_β© : β x xs β P xs β P (x β· xs) private z = β£_β£[]; f = β£_β£_β·_β¨_β© open import HITs.PropositionalTruncation.Sugar open import HITs.PropositionalTruncation β£_β£β : xs βπ¦ A ββ₯ β₯ P xs β₯ β₯ β£_β£β = elim-prop squash β£ z β£ Ξ» x xs β£Pxsβ£ β f x xs β₯$β₯ β£Pxsβ£ β£_β£β = β₯ β£_β£β β₯β open _ββ₯_β₯ public elim-to-prop-syntax : β {a p} β (A : Type a) β (π¦ A β Type p) β Type (a ββ p) elim-to-prop-syntax = _ββ₯_β₯ syntax elim-to-prop-syntax A (Ξ» xs β Pxs) = xs βπ¦ A ββ£ Pxs β£ infixr 0 _β_ record _β_ {a b} (A : Type a) (B : Type b) : Type (a ββ b) where no-eta-equality constructor rec field [_]-set : isSet B [_]_β·_ : A β B β B [_][] : B private f = [_]_β·_; z = [_][] field [_]-dup : β x xs β f x (f x xs) β‘ f x xs [_]-com : β x y xs β f x (f y xs) β‘ f y (f x xs) [_]β = elim [_]-set z (Ξ» x _ xs β f x xs) (Ξ» x y xs β [_]-com x y) (Ξ» x xs β [_]-dup x) [_]β = β¦ [_]β β§β {-# INLINE [_]β #-} {-# INLINE [_]β #-} open _β_ public module _ {a p} {A : Type a} {P : π¦ A β Type p} where π¦-elim-prop : (β {xs} β isProp (P xs)) β (β x xs β P xs β P (x β· xs)) β (P []) β β xs β P xs π¦-elim-prop isPropB f n = go where go : β xs β P xs go [] = n go (x β· xs) = f x xs (go xs) go (com x y xs j) = toPathP {A = Ξ» i β P (com x y xs i)} (isPropB (transp (Ξ» i β P (com x y xs i)) i0 (f x (y β· xs) (f y xs (go xs)))) (f y (x β· xs) (f x xs (go xs)))) j go (dup x xs j) = toPathP {A = Ξ» i β P (dup x xs i)} (isPropB (transp (Ξ» i β P (dup x xs i)) i0 (f x (x β· xs) (f x xs (go xs)))) (f x xs (go xs)) ) j go (trunc xs ys x y i j) = isOfHLevelβisOfHLevelDep 2 (Ξ» xs β isPropβisSet (isPropB {xs})) (go xs) (go ys) (cong go x) (cong go y) (trunc xs ys x y) i j module _ {a b} {A : Type a} {B : Type b} where π¦-rec : isSet B β (f : A β B β B) β (n : B) β (fdup : β x xs β f x (f x xs) β‘ f x xs) β (fcom : β x y xs β f x (f y xs) β‘ f y (f x xs)) β π¦ A β B π¦-rec isSetB f n fdup fcom = go where go : π¦ A β B go [] = n go (x β· xs) = f x (go xs) go (com x y xs i) = fcom x y (go xs) i go (dup x xs i) = fdup x (go xs) i go (trunc xs ys x y i j) = isOfHLevelβisOfHLevelDep 2 (Ξ» xs β isSetB) (go xs) (go ys) (cong go x) (cong go y) (trunc xs ys x y) i j