{-# OPTIONS --cubical --safe #-}
import Equality.Path as P
module Finite-subset.Listed.Alternative
{c⁺} (eq : ∀ {a p} → P.Equality-with-paths a p c⁺) where
open P.Derived-definitions-and-properties eq hiding (elim)
import Equality.Path.Univalence as EPU
open import Logical-equivalence using (_⇔_)
open import Prelude hiding (_∷_; swap)
open import Bijection equality-with-J using (_↔_)
import Bijection P.equality-with-J as PB
open import Equality.Path.Isomorphisms eq
open import Equivalence equality-with-J as Eq using (_≃_)
import Equivalence P.equality-with-J as PEq
import Finite-subset.Listed eq as Listed
import Finite-subset.Listed.Membership eq as LM
open import Function-universe equality-with-J as F hiding (id; _∘_)
import H-level P.equality-with-J as PH
open import H-level.Closure equality-with-J
import H-level.Closure P.equality-with-J as PHC
open import H-level.Truncation.Propositional eq as Trunc
using (∥_∥; _∥⊎∥_)
open import Injection equality-with-J using (Injective)
import Univalence-axiom P.equality-with-J as PU
private
variable
a b p : Level
A B : Type a
P : A → Type p
x x∼y y y₁ y₂ z z₁ z₂ : A
mutual
infixr 5 _∷_
data Finite-subset-of (A : Type a) : Type a where
[] : Finite-subset-of A
_∷_ : A → Finite-subset-of A → Finite-subset-of A
extensionalityᴾ : x ∼ y → x P.≡ y
is-setᴾ : P.Is-set (Finite-subset-of A)
private
Membership :
{A : Type a} → A → Finite-subset-of A → PH.Proposition a
infix 4 _∈_
_∈_ : {A : Type a} → A → Finite-subset-of A → Type a
x ∈ y = proj₁ (Membership x y)
∈-propositionalᴾ : ∀ y → P.Is-proposition (x ∈ y)
∈-propositionalᴾ y = proj₂ (Membership _ y)
infix 4 _∼_
_∼_ :
{A : Type a} → Finite-subset-of A → Finite-subset-of A → Type a
x ∼ y = ∀ z → z ∈ x ⇔ z ∈ y
Membership x [] =
⊥ , PHC.⊥-propositional
Membership x (y ∷ z) =
(x ≡ y ∥⊎∥ x ∈ z) , Trunc.truncation-is-propositionᴾ
Membership x (extensionalityᴾ {x = y} {y = z} y∼z i) =
lemma i
where
lemma : Membership x y P.≡ Membership x z
lemma = P.Σ-≡,≡→≡
(x ∈ y P.≡⟨ PEq._≃_.from
(PU.Propositional-extensionality-is-univalence-for-propositions P.ext)
(λ _ _ → EPU.univ)
(∈-propositionalᴾ y)
(∈-propositionalᴾ z)
(y∼z x) ⟩∎
x ∈ z ∎)
(PHC.H-level-propositional P.ext 1 _ _)
Membership x (is-setᴾ {x = y} {y = z} p q i j) =
P.heterogeneous-UIP₀₀
{x = λ _ → Membership x y}
{y = λ _ → Membership x z}
{p = λ i → Membership x (p i)}
{q = λ i → Membership x (q i)}
(PU.∃-H-level-H-level-1+ P.ext EPU.univ 1)
i j
extensionality : x ∼ y → x ≡ y
extensionality = _↔_.from ≡↔≡ ∘ extensionalityᴾ
is-set : Is-set (Finite-subset-of A)
is-set =
_↔_.from (H-level↔H-level 2) Finite-subset-of.is-setᴾ
∈-propositional : ∀ y → Is-proposition (x ∈ y)
∈-propositional = _↔_.from (H-level↔H-level 1) ∘ ∈-propositionalᴾ
_ : (x ∈ []) ≡ ⊥
_ = refl _
_ : (x ∈ y ∷ z) ≡ (x ≡ y ∥⊎∥ x ∈ z)
_ = refl _
private
record Elimᴾ′ {A : Type a} (P : Finite-subset-of A → Type p) :
Type (a ⊔ p) where
no-eta-equality
field
[]ʳ : P []
∷ʳ : ∀ x → P y → P (x ∷ y)
is-setʳ : ∀ x → P.Is-set (P x)
extensionalityʳ :
(p : P x) (q : P y) →
P.[ (λ i → P (extensionalityᴾ {x = x} {y = y} x∼y i)) ] p ≡ q
open Elimᴾ′
elimᴾ′ : Elimᴾ′ P → (x : Finite-subset-of A) → P x
elimᴾ′ {A} {P} e = helper
where
module E = Elimᴾ′ e
helper : (x : Finite-subset-of A) → P x
helper [] = E.[]ʳ
helper (x ∷ y) = E.∷ʳ x (helper y)
helper (extensionalityᴾ {x} {y} _ i) =
E.extensionalityʳ (helper x) (helper y) i
helper (is-setᴾ x y i j) =
P.heterogeneous-UIP
E.is-setʳ (is-setᴾ x y)
(λ i → helper (x i)) (λ i → helper (y i)) i j
motive-propositional :
Elimᴾ′ P → ∀ x → P.Is-proposition (P x)
motive-propositional {P} e x p q =
p P.≡⟨ P.sym $ P.subst-refl P _ ⟩
P.subst P P.refl p P.≡⟨ P.cong (λ eq → P.subst P eq p) $ is-setᴾ _ _ ⟩
P.subst P (extensionalityᴾ λ _ → F.id) p P.≡⟨ PB._↔_.to (P.heterogeneous↔homogeneous _)
(e .extensionalityʳ {x∼y = λ _ → F.id} p q) ⟩∎
q ∎
record Elimᴾ {A : Type a} (P : Finite-subset-of A → Type p) :
Type (a ⊔ p) where
no-eta-equality
field
[]ʳ : P []
∷ʳ : ∀ x → P y → P (x ∷ y)
is-propositionʳ : ∀ x → P.Is-proposition (P x)
open Elimᴾ public
elimᴾ : Elimᴾ P → (x : Finite-subset-of A) → P x
elimᴾ {A} {P} e = elimᴾ′ e′
where
module E = Elimᴾ e
e′ : Elimᴾ′ _
e′ .[]ʳ = e .[]ʳ
e′ .∷ʳ = e .∷ʳ
e′ .is-setʳ = PH.mono₁ 1 ∘ e .is-propositionʳ
e′ .extensionalityʳ _ _ =
PB._↔_.from (P.heterogeneous↔homogeneous _)
(e .is-propositionʳ _ _ _)
record Recᴾ (A : Type a) (B : Type b) : Type (a ⊔ b) where
no-eta-equality
field
[]ʳ : B
∷ʳ : A → Finite-subset-of A → B → B
is-propositionʳ : P.Is-proposition B
open Recᴾ public
recᴾ : Recᴾ A B → Finite-subset-of A → B
recᴾ {A} {B} r = elimᴾ e
where
module R = Recᴾ r
e : Elimᴾ _
e .[]ʳ = R.[]ʳ
e .∷ʳ {y} x = R.∷ʳ x y
e .is-propositionʳ _ = R.is-propositionʳ
record Elim
{A : Type a} (P : Finite-subset-of A → Type p) :
Type (a ⊔ p) where
field
[]ʳ : P []
∷ʳ : ∀ x → P y → P (x ∷ y)
is-propositionʳ : ∀ x → Is-proposition (P x)
open Elim public
elim : Elim P → (x : Finite-subset-of A) → P x
elim e = elimᴾ e′
where
module E = Elim e
e′ : Elimᴾ _
e′ .[]ʳ = E.[]ʳ
e′ .∷ʳ = E.∷ʳ
e′ .is-propositionʳ = _↔_.to (H-level↔H-level 1) ∘ E.is-propositionʳ
record Rec (A : Type a) (B : Type b) : Type (a ⊔ b) where
field
[]ʳ : B
∷ʳ : A → Finite-subset-of A → B → B
is-propositionʳ : Is-proposition B
open Rec public
rec : Rec A B → Finite-subset-of A → B
rec r = elim e
where
module R = Rec r
e : Elim _
e .[]ʳ = R.[]ʳ
e .∷ʳ {y} x = R.∷ʳ x y
e .is-propositionʳ _ = R.is-propositionʳ
¬-proposition : A → ¬ Is-proposition (Finite-subset-of A)
¬-proposition {A} x =
Is-proposition (Finite-subset-of A) ↝⟨ (λ hyp → hyp _ _) ⟩
x ∷ [] ≡ [] ↝⟨ (λ hyp → subst (x ∈_) hyp (Trunc.∣inj₁∣ (refl _))) ⟩
x ∈ [] ↔⟨ ⊥↔⊥ ⟩□
⊥ □
opaque
drop : x ∷ x ∷ y ≡ x ∷ y
drop {x} {y} = extensionality λ z →
z ≡ x ∥⊎∥ (z ≡ x ∥⊎∥ z ∈ y) ↔⟨ Trunc.drop-left-∥⊎∥ Trunc.∥⊎∥-propositional Trunc.∣inj₁∣ ⟩□
z ≡ x ∥⊎∥ z ∈ y □
swap : x ∷ y ∷ z ≡ y ∷ x ∷ z
swap {x} {y} {z} = extensionality λ u →
u ≡ x ∥⊎∥ (u ≡ y ∥⊎∥ u ∈ z) ↔⟨ Trunc.∥⊎∥-assoc ⟩
(u ≡ x ∥⊎∥ u ≡ y) ∥⊎∥ u ∈ z ↔⟨ Trunc.∥⊎∥-comm Trunc.∥⊎∥-cong F.id ⟩
(u ≡ y ∥⊎∥ u ≡ x) ∥⊎∥ u ∈ z ↔⟨ inverse Trunc.∥⊎∥-assoc ⟩□
u ≡ y ∥⊎∥ (u ≡ x ∥⊎∥ u ∈ z) □
∈→∷≡ : x ∈ y → x ∷ y ≡ y
∈→∷≡ {x} = elim e _
where
e : Elim (λ y → x ∈ y → x ∷ y ≡ y)
e .∷ʳ {y} z hyp =
Trunc.rec is-set
[ (λ x≡z →
x ∷ z ∷ y ≡⟨ cong (λ x → x ∷ _) x≡z ⟩
z ∷ z ∷ y ≡⟨ drop ⟩∎
z ∷ y ∎)
, (λ x∈y →
x ∷ z ∷ y ≡⟨ swap ⟩
z ∷ x ∷ y ≡⟨ cong (_ ∷_) (hyp x∈y) ⟩∎
z ∷ y ∎)
]
e .is-propositionʳ _ =
Π-closure ext 1 λ _ →
is-set
singleton : A → Finite-subset-of A
singleton x = x ∷ []
∈singleton≃ :
(x ∈ singleton y) ≃ ∥ x ≡ y ∥
∈singleton≃ {x} {y} =
x ∈ singleton y ↔⟨⟩
x ≡ y ∥⊎∥ ⊥ ↔⟨ Trunc.∥∥-cong $ drop-⊥-right ⊥↔⊥ ⟩□
∥ x ≡ y ∥ □
member? :
((x y : A) → Dec ∥ x ≡ y ∥) →
(x : A) (y : Finite-subset-of A) → Dec (x ∈ y)
member? equal? x = elim e
where
e : Elim _
e .[]ʳ = no λ ()
e .∷ʳ {y = z} y = case equal? x y of
[ (λ ∥x≡y∥ _ → yes (Trunc.∥∥-map inj₁ ∥x≡y∥))
, (λ ¬∥x≡y∥ →
[ (λ x∈z → yes (Trunc.∣inj₂∣ x∈z))
, (λ x∉z → no (
x ∈ y ∷ z ↔⟨⟩
x ≡ y ∥⊎∥ x ∈ z ↝⟨ Trunc.∥∥-map [ ¬∥x≡y∥ ∘ Trunc.∣_∣ , x∉z ] ⟩
∥ ⊥ ∥ ↔⟨ Trunc.not-inhabited⇒∥∥↔⊥ id ⟩□
⊥ □))
])
]
e .is-propositionʳ y =
Dec-closure-propositional ext (∈-propositional y)
private
Is-union-of :
{A : Type a} (_ _ _ : Finite-subset-of A) → Type a
Is-union-of x y z = ∀ u → (u ∈ z) ≃ (u ∈ x ∥⊎∥ u ∈ y)
Is-union-of-functional :
(x y : Finite-subset-of A) →
Is-union-of x y z₁ → Is-union-of x y z₂ →
z₁ ≡ z₂
Is-union-of-functional {z₁} {z₂} x y p₁ p₂ =
extensionality λ u →
u ∈ z₁ ↔⟨ p₁ u ⟩
u ∈ x ∥⊎∥ u ∈ y ↔⟨ inverse $ p₂ u ⟩□
u ∈ z₂ □
Is-union-of-propositional :
(x y z : Finite-subset-of A) →
Is-proposition (Is-union-of x y z)
Is-union-of-propositional x y z =
Π-closure ext 1 λ _ →
Eq.left-closure ext 0 (∈-propositional z)
union : (x y : Finite-subset-of A) → ∃ (Is-union-of x y)
union = elim e
where
e : Elim _
e .[]ʳ y =
y
, λ u →
u ∈ y ↔⟨ inverse $ Trunc.∥⊎∥-left-identity (∈-propositional y) ⟩□
⊥ ∥⊎∥ u ∈ y □
e .∷ʳ {y} x hyp z =
x ∷ proj₁ (hyp z)
, λ u →
u ∈ x ∷ proj₁ (hyp z) ↔⟨⟩
u ≡ x ∥⊎∥ u ∈ proj₁ (hyp z) ↝⟨ F.id Trunc.∥⊎∥-cong proj₂ (hyp z) u ⟩
u ≡ x ∥⊎∥ (u ∈ y ∥⊎∥ u ∈ z) ↔⟨ Trunc.∥⊎∥-assoc ⟩
(u ≡ x ∥⊎∥ u ∈ y) ∥⊎∥ u ∈ z ↔⟨⟩
u ∈ x ∷ y ∥⊎∥ u ∈ z □
e .is-propositionʳ x f g = ⟨ext⟩ λ y →
Σ-≡,≡→≡
(Is-union-of-functional x y (proj₂ (f y)) (proj₂ (g y)))
(Is-union-of-propositional x y (proj₁ (g y)) _ _)
infixr 5 _∪_
_∪_ :
Finite-subset-of A → Finite-subset-of A →
Finite-subset-of A
x ∪ y = proj₁ (union x y)
_ : [] ∪ x ≡ x
_ = refl _
_ : (x ∷ y) ∪ z ≡ x ∷ (y ∪ z)
_ = refl _
∈∪≃∈∥⊎∥∈ : ∀ y → (x ∈ y ∪ z) ≃ (x ∈ y ∥⊎∥ x ∈ z)
∈∪≃∈∥⊎∥∈ {z} y = proj₂ (union y z) _
∈→∈∪ˡ : ∀ y → x ∈ y → x ∈ y ∪ z
∈→∈∪ˡ y = _≃_.from (∈∪≃∈∥⊎∥∈ y) ∘ Trunc.∣inj₁∣
∈→∈∪ʳ : ∀ y → x ∈ z → x ∈ y ∪ z
∈→∈∪ʳ y = _≃_.from (∈∪≃∈∥⊎∥∈ y) ∘ Trunc.∣inj₂∣
∪[] :
(x : Finite-subset-of A) →
x ∪ [] ≡ x
∪[] = elim e
where
e : Elim _
e .is-propositionʳ _ = is-set
e .[]ʳ = refl _
e .∷ʳ {y} x hyp =
x ∷ y ∪ [] ≡⟨ cong (x ∷_) hyp ⟩∎
x ∷ y ∎
∪∷ :
(x : Finite-subset-of A) →
x ∪ (y ∷ z) ≡ y ∷ x ∪ z
∪∷ {y} {z} = elim e
where
e : Elim _
e .is-propositionʳ _ = is-set
e .[]ʳ = refl _
e .∷ʳ {y = u} x hyp =
(x ∷ u) ∪ (y ∷ z) ≡⟨⟩
x ∷ u ∪ (y ∷ z) ≡⟨ cong (x ∷_) hyp ⟩
x ∷ y ∷ u ∪ z ≡⟨ swap ⟩
y ∷ x ∷ u ∪ z ≡⟨⟩
y ∷ (x ∷ u) ∪ z ∎
∪-assoc :
(x : Finite-subset-of A) →
x ∪ (y ∪ z) ≡ (x ∪ y) ∪ z
∪-assoc {y} {z} = elim e
where
e : Elim _
e .is-propositionʳ _ = is-set
e .[]ʳ = refl _
e .∷ʳ {y = u} x hyp =
x ∷ u ∪ (y ∪ z) ≡⟨ cong (x ∷_) hyp ⟩∎
x ∷ (u ∪ y) ∪ z ∎
∪-comm :
(x : Finite-subset-of A) →
x ∪ y ≡ y ∪ x
∪-comm {y} = elim e
where
e : Elim _
e .is-propositionʳ _ = is-set
e .[]ʳ =
[] ∪ y ≡⟨⟩
y ≡⟨ sym (∪[] y) ⟩∎
y ∪ [] ∎
e .∷ʳ {y = z} x hyp =
x ∷ z ∪ y ≡⟨ cong (x ∷_) hyp ⟩
x ∷ y ∪ z ≡⟨ sym (∪∷ y) ⟩∎
y ∪ (x ∷ z) ∎
∪-idem : (x : Finite-subset-of A) → x ∪ x ≡ x
∪-idem = elim e
where
e : Elim _
e .[]ʳ =
[] ∪ [] ≡⟨⟩
[] ∎
e .∷ʳ {y} x hyp =
(x ∷ y) ∪ (x ∷ y) ≡⟨⟩
x ∷ y ∪ x ∷ y ≡⟨ cong (_ ∷_) (∪∷ y) ⟩
x ∷ x ∷ y ∪ y ≡⟨ drop ⟩
x ∷ y ∪ y ≡⟨ cong (_ ∷_) hyp ⟩∎
x ∷ y ∎
e .is-propositionʳ = λ _ → is-set
∪-distrib-left : ∀ x → x ∪ (y ∪ z) ≡ (x ∪ y) ∪ (x ∪ z)
∪-distrib-left {y} {z} x =
x ∪ (y ∪ z) ≡⟨ cong (_∪ _) $ sym (∪-idem x) ⟩
(x ∪ x) ∪ (y ∪ z) ≡⟨ sym $ ∪-assoc x ⟩
x ∪ (x ∪ (y ∪ z)) ≡⟨ cong (x ∪_) $ ∪-assoc x ⟩
x ∪ ((x ∪ y) ∪ z) ≡⟨ cong ((x ∪_) ∘ (_∪ _)) $ ∪-comm x ⟩
x ∪ ((y ∪ x) ∪ z) ≡⟨ cong (x ∪_) $ sym $ ∪-assoc y ⟩
x ∪ (y ∪ (x ∪ z)) ≡⟨ ∪-assoc x ⟩∎
(x ∪ y) ∪ (x ∪ z) ∎
∪-distrib-right : ∀ x → (x ∪ y) ∪ z ≡ (x ∪ z) ∪ (y ∪ z)
∪-distrib-right {y} {z} x =
(x ∪ y) ∪ z ≡⟨ ∪-comm (x ∪ _) ⟩
z ∪ (x ∪ y) ≡⟨ ∪-distrib-left z ⟩
(z ∪ x) ∪ (z ∪ y) ≡⟨ cong₂ _∪_ (∪-comm z) (∪-comm z) ⟩∎
(x ∪ z) ∪ (y ∪ z) ∎
infix 4 _⊆_
_⊆_ : {A : Type a} → Finite-subset-of A → Finite-subset-of A → Type a
x ⊆ y = ∀ z → z ∈ x → z ∈ y
⊆-propositional :
(x y : Finite-subset-of A) → Is-proposition (x ⊆ y)
⊆-propositional x y =
Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
∈-propositional y
∷-cong-⊆ : ∀ y z → y ⊆ z → x ∷ y ⊆ x ∷ z
∷-cong-⊆ {x} y z y⊆z = λ u →
u ∈ x ∷ y ↔⟨⟩
u ≡ x ∥⊎∥ u ∈ y ↝⟨ id Trunc.∥⊎∥-cong y⊆z _ ⟩
u ≡ x ∥⊎∥ u ∈ z ↔⟨⟩
u ∈ x ∷ z □
∪-mono-⊆ : ∀ x₁ x₂ → x₁ ⊆ x₂ → y₁ ⊆ y₂ → x₁ ∪ y₁ ⊆ x₂ ∪ y₂
∪-mono-⊆ {y₁} {y₂} x₁ x₂ x₁⊆x₂ y₁⊆y₂ = λ u →
u ∈ x₁ ∪ y₁ ↔⟨ ∈∪≃∈∥⊎∥∈ x₁ ⟩
u ∈ x₁ ∥⊎∥ u ∈ y₁ ↝⟨ x₁⊆x₂ u Trunc.∥⊎∥-cong y₁⊆y₂ u ⟩
u ∈ x₂ ∥⊎∥ u ∈ y₂ ↔⟨ inverse $ ∈∪≃∈∥⊎∥∈ x₂ ⟩□
u ∈ x₂ ∪ y₂ □
⊆≃∪≡ : ∀ x → (x ⊆ y) ≃ (x ∪ y ≡ y)
⊆≃∪≡ {y} x = Eq.⇔→≃
(⊆-propositional x y)
is-set
(elim e x)
(λ p z →
z ∈ x ↝⟨ ∈→∈∪ˡ x ⟩
z ∈ x ∪ y ↝⟨ ≡⇒↝ _ (cong (z ∈_) p) ⟩□
z ∈ y □)
where
e : Elim (λ x → x ⊆ y → x ∪ y ≡ y)
e .[]ʳ _ =
[] ∪ y ≡⟨⟩
y ∎
e .∷ʳ {y = z} x hyp x∷z⊆y =
x ∷ z ∪ y ≡⟨ cong (x ∷_) (hyp (λ _ → x∷z⊆y _ ∘ Trunc.∣inj₂∣)) ⟩
x ∷ y ≡⟨ ∈→∷≡ (x∷z⊆y x (Trunc.∣inj₁∣ (refl _))) ⟩∎
y ∎
e .is-propositionʳ _ =
Π-closure ext 1 λ _ →
is-set
⊆-refl : x ⊆ x
⊆-refl _ = id
⊆-trans : x ⊆ y → y ⊆ z → x ⊆ z
⊆-trans x⊆y y⊆z _ = y⊆z _ ∘ x⊆y _
⊆-antisymmetric : x ⊆ y → y ⊆ x → x ≡ y
⊆-antisymmetric x⊆y y⊆x =
extensionality λ z →
record { to = x⊆y z; from = y⊆x z }
≡≃⊆×⊇ : (x ≡ y) ≃ (x ⊆ y × y ⊆ x)
≡≃⊆×⊇ {x} {y} =
x ≡ y ↝⟨ Eq.⇔→≃
is-set
(×-closure 1 is-set is-set)
(λ x≡y →
(x ∪ y ≡⟨ cong (_∪ _) x≡y ⟩
y ∪ y ≡⟨ ∪-idem y ⟩∎
y ∎)
, (y ∪ x ≡⟨ cong (_∪ _) $ sym x≡y ⟩
x ∪ x ≡⟨ ∪-idem x ⟩∎
x ∎))
(λ (p , q) →
x ≡⟨ sym q ⟩
y ∪ x ≡⟨ ∪-comm y ⟩
x ∪ y ≡⟨ p ⟩∎
y ∎) ⟩
x ∪ y ≡ y × y ∪ x ≡ x ↝⟨ inverse $ ⊆≃∪≡ x ×-cong ⊆≃∪≡ y ⟩□
x ⊆ y × y ⊆ x □
∼≃≡ : (x ∼ y) ≃ (x ≡ y)
∼≃≡ {x} {y} =
x ∼ y ↔⟨⟩
(∀ z → z ∈ x ⇔ z ∈ y) ↔⟨ (∀-cong ext λ _ → ⇔↔→×→) ⟩
(∀ z → (z ∈ x → z ∈ y) × (z ∈ y → z ∈ x)) ↔⟨ ΠΣ-comm ⟩
x ⊆ y × y ⊆ x ↝⟨ inverse ≡≃⊆×⊇ ⟩□
x ≡ y □
private
module Listed≃Listed where
from : Listed.Finite-subset-of A → Finite-subset-of A
from = Listed.rec r
where
r : Listed.Rec _ _
r .Listed.Rec.[]ʳ = []
r .Listed.Rec.∷ʳ x _ y = x ∷ y
r .Listed.Rec.dropʳ _ _ _ = drop
r .Listed.Rec.swapʳ _ _ _ _ = swap
r .Listed.Rec.is-setʳ = is-set
∈from≃ : ∀ x → (z ∈ from x) ≃ (z LM.∈ x)
∈from≃ {z} = Listed.elim-prop e
where
e : Listed.Elim-prop _
e .Listed.Elim-prop.[]ʳ =
z ∈ from Listed.[] ↔⟨⟩
⊥ ↔⟨ ⊥↔⊥ ⟩
⊥₀ ↝⟨ inverse $ LM.∈[]≃ ⟩
z LM.∈ Listed.[] □
e .Listed.Elim-prop.∷ʳ {y} x hyp =
z ∈ from (x Listed.∷ y) ↔⟨⟩
z ≡ x ∥⊎∥ z ∈ from y ↝⟨ F.id Trunc.∥⊎∥-cong hyp ⟩
z ≡ x ∥⊎∥ z LM.∈ y ↝⟨ inverse LM.∈∷≃ ⟩□
z LM.∈ x Listed.∷ y □
e .Listed.Elim-prop.is-propositionʳ _ =
Eq.right-closure ext 0 LM.∈-propositional
from⊆from→ :
(x y : Listed.Finite-subset-of A) →
from x ⊆ from y → x LM.⊆ y
from⊆from→ = Listed.elim-prop e
where
e : Listed.Elim-prop _
e .Listed.Elim-prop.[]ʳ = Listed.elim-prop e′
where
e′ : Listed.Elim-prop _
e′ .Listed.Elim-prop.[]ʳ _ = LM.⊆-refl
e′ .Listed.Elim-prop.∷ʳ {y} x _ _ z =
z LM.∈ Listed.[] ↔⟨ LM.∈[]≃ ⟩
⊥₀ ↝⟨ ⊥-elim ⟩□
z LM.∈ x Listed.∷ y □
e′ .Listed.Elim-prop.is-propositionʳ _ =
Π-closure ext 1 λ _ →
LM.⊆-propositional
e .Listed.Elim-prop.∷ʳ {y = y₁} x hyp₁ y₂ =
from (x Listed.∷ y₁) ⊆ from y₂ ↔⟨⟩
(∀ z → z ≡ x ∥⊎∥ z ∈ from y₁ → z ∈ from y₂) ↝⟨ (λ hyp₂ z → Trunc.rec LM.∈-propositional
[ (
z ≡ x ↝⟨ Trunc.∣inj₁∣ ⟩
z ≡ x ∥⊎∥ z ∈ from y₁ ↝⟨ hyp₂ z ⟩
z ∈ from y₂ ↔⟨ ∈from≃ _ ⟩□
z LM.∈ y₂ □)
, ($⟨ (λ z → hyp₂ z ∘ Trunc.∣inj₂∣) ⟩
from y₁ ⊆ from y₂ ↝⟨ hyp₁ y₂ ⟩
y₁ LM.⊆ y₂ ↝⟨ _$ z ⟩□
(z LM.∈ y₁ → z LM.∈ y₂) □)
]) ⟩
(∀ z → z ≡ x ∥⊎∥ z LM.∈ y₁ → z LM.∈ y₂) ↔⟨ (∀-cong ext λ _ → →-cong ext (inverse LM.∈∷≃) F.id) ⟩□
x Listed.∷ y₁ LM.⊆ y₂ □
e .Listed.Elim-prop.is-propositionʳ _ =
Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
LM.⊆-propositional
from-injective : Injective (from {A = A})
from-injective {x} {y} =
from x ≡ from y ↔⟨ ≡≃⊆×⊇ ⟩
from x ⊆ from y × from y ⊆ from x ↝⟨ Σ-map (from⊆from→ _ _) (from⊆from→ _ _) ⟩
x LM.⊆ y × y LM.⊆ x ↝⟨ uncurry LM.⊆-antisymmetric ⟩□
x ≡ y □
to :
(x : Finite-subset-of A) →
∃ λ (y : Listed.Finite-subset-of A) → from y ≡ x
to = elim e
where
e : Elim _
e .Elim.[]ʳ = Listed.[] , refl _
e .Elim.∷ʳ x (y , eq) = x Listed.∷ y , cong (x ∷_) eq
e .Elim.is-propositionʳ x (y₁ , eq₁) (y₂ , eq₂) =
Σ-≡,≡→≡
(from-injective
(from y₁ ≡⟨ eq₁ ⟩
x ≡⟨ sym eq₂ ⟩∎
from y₂ ∎))
(is-set _ _)
to-from :
(x : Listed.Finite-subset-of A) →
proj₁ (to (from x)) ≡ x
to-from = Listed.elim-prop e
where
e : Listed.Elim-prop _
e .Listed.Elim-prop.[]ʳ = refl _
e .Listed.Elim-prop.∷ʳ x = cong (x Listed.∷_)
e .Listed.Elim-prop.is-propositionʳ _ = Listed.is-set
Listed≃Listed : Finite-subset-of A ≃ Listed.Finite-subset-of A
Listed≃Listed = Eq.↔→≃ (proj₁ ∘ to) from to-from (proj₂ ∘ to)
where
open Listed≃Listed
∈≃∈ : ∀ y → (x ∈ y) ≃ (x LM.∈ _≃_.to Listed≃Listed y)
∈≃∈ {x} y =
x ∈ y ↝⟨ ≡⇒↝ _ $ cong (_ ∈_) $ sym $ _≃_.left-inverse-of Listed≃Listed y ⟩
x ∈ _≃_.from Listed≃Listed (_≃_.to Listed≃Listed y) ↝⟨ ∈from≃ _ ⟩□
x LM.∈ _≃_.to Listed≃Listed y □
where
open Listed≃Listed
record Elim′ {A : Type a} (P : Finite-subset-of A → Type p) :
Type (a ⊔ p) where
no-eta-equality
field
[]ʳ : P []
∷ʳ : ∀ x → P y → P (x ∷ y)
dropʳ : ∀ x (p : P y) →
subst P (drop {x = x} {y = y}) (∷ʳ x (∷ʳ x p)) ≡ ∷ʳ x p
swapʳ : ∀ x y (p : P z) →
subst P (swap {x = x} {y = y} {z = z}) (∷ʳ x (∷ʳ y p)) ≡
∷ʳ y (∷ʳ x p)
is-setʳ : ∀ x → Is-set (P x)
open Elim′ public
elim′ : Elim′ P → (x : Finite-subset-of A) → P x
elim′ {P} e x =
subst P (_≃_.left-inverse-of Listed≃Listed x)
(Listed.elim e′ (_≃_.to Listed≃Listed x))
where
module E = Elim′ e
e′ : Listed.Elim (P ∘ _≃_.from Listed≃Listed)
e′ .Listed.[]ʳ = E.[]ʳ
e′ .Listed.∷ʳ = E.∷ʳ
e′ .Listed.dropʳ x p =
subst (P ∘ _≃_.from Listed≃Listed)
Listed.drop
(e .∷ʳ x (e .∷ʳ x p)) ≡⟨ subst-∘ _ _ _ ⟩
subst P
(cong (_≃_.from Listed≃Listed) Listed.drop)
(e .∷ʳ x (e .∷ʳ x p)) ≡⟨ cong (flip (subst P) _) $ is-set _ _ ⟩
subst P drop (e .∷ʳ x (e .∷ʳ x p)) ≡⟨ e .dropʳ x p ⟩∎
e .∷ʳ x p ∎
e′ .Listed.swapʳ x y p =
subst (P ∘ _≃_.from Listed≃Listed)
Listed.swap
(e .∷ʳ x (e .∷ʳ y p)) ≡⟨ subst-∘ _ _ _ ⟩
subst P
(cong (_≃_.from Listed≃Listed) Listed.swap)
(e .∷ʳ x (e .∷ʳ y p)) ≡⟨ cong (flip (subst P) _) $ is-set _ _ ⟩
subst P swap (e .∷ʳ x (e .∷ʳ y p)) ≡⟨ e .swapʳ x y p ⟩∎
e .∷ʳ y (e .∷ʳ x p) ∎
e′ .Listed.is-setʳ _ = E.is-setʳ _