{-# OPTIONS --safe #-}
open import Prelude
open import Data.Vec
open import FinitenessConditions
module Data.Vec.SetQuotients where
private
variable
n m : ℕ
_~_ : A → A → Type b
open SplitQuotientedChoiceAt
module FinInst where
infixr 5 _◂~_
_◂~_ : A / _~_ → Vec A n / Pointwise _~_ → Vec A (suc n) / Pointwise _~_
_◂~_ =
rec2/
squash/
(λ x xs → [ x ◂ xs ])
(λ x y xs p → eq/ _ _ λ { zero → eq/ x y p ; (suc i) → refl })
λ x ys zs p → eq/ _ _ λ { zero → refl ; (suc i) → p i}
finTrav : Vec (A / _~_) n → Vec A n / Pointwise _~_
finTrav {A = A} {_~_ = _~_} {n = n} = vec-foldr (λ n → Vec _ n / Pointwise _~_) _◂~_ [ ⟅⟆ ]
fin-SplitQuotientedChoice : SplitQuotientedChoice (Fin n) b c
fin-SplitQuotientedChoice {B = A} {_~_} .undistrib xs = finTrav xs , funExt (lemma xs)
where
lemma : (x : Vec (A / _~_) n) (i : Fin n) → dist (finTrav x) i ≡ x i
lemma {n = .(suc _)} x zero =
elimProp2/
{P = λ xz xs → xz ≡ x zero → dist (xz ◂~ xs) zero ≡ x zero }
(λ _ _ → isProp→ (squash/ _ _))
(λ xz xs xzp → xzp)
(x zero)
(finTrav (x ∘ suc))
refl
lemma {n = .(suc _)} x (suc i) =
elimProp2/
{P = λ xz xs → xs ≡ finTrav (x ∘ suc) → dist (xz ◂~ xs) (suc i) ≡ x (suc i) }
(λ _ _ → isProp→ (squash/ _ _))
(λ xz xs xsp → cong (λ k → dist k i) xsp ; lemma (x ∘ suc) i)
(x zero)
(finTrav (x ∘ suc))
refl
open FinInst using (fin-SplitQuotientedChoice) public