Skip to content

Commit 32e395d

Browse files
committed
finish powerset
1 parent c8ebb3b commit 32e395d

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

src/Data/Fin/Finite.lagda.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,12 @@ instance
670670
b ← fb
671671
pure (Listing-Coeq ⦃ a ⦄ ⦃ b ⦄)
672672
673+
Listing-So : ∀ {b} → Listing (So b)
674+
Listing-So = Listing-prop
675+
676+
Finite-So : ∀ {b} → Finite (So b)
677+
Finite-So = inc auto
678+
673679
instance
674680
Discrete-listing-Π : ⦃ _ : Listing A ⦄ ⦃ _ : ∀ {x} → Discrete (P x) ⦄ → Discrete ((x : A) → P x)
675681
Discrete-listing-Π {A = A} ⦃ xa ⦄ ⦃ dp ⦄ {f} {g} with Listing→exhaustible (λ i → ¬ f i ≡ g i)

src/Data/Finset/Properties.agda

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ filter-∈ᶠˢ {P = P} ⦃ d ⦄ {x} xs mem px = ∈ᶠˢ-elim (λ xs _ → x
3535
(λ {y} {xs} q ind case d {y} return (λ p x ∈ᶠˢ cons-if p y (filter P xs)) of λ { (yes _) thereₛ ind ; (no ¬px) ind })
3636
xs mem
3737

38-
∈ᶠˢ-filter : {P : A Type ℓ} ⦃ d : {x} Dec (P x) ⦄ {x : A} xs x ∈ᶠˢ filter P xs ∥ P x ∥
39-
∈ᶠˢ-filter {P = P} ⦃ d = d ⦄ {x = x} = Finset-elim-prop (λ xs x ∈ filter P xs ∥ P x ∥)
38+
∈ᶠˢ-filter : {P : A Type ℓ} ⦃ d : {x} Dec (P x) ⦄ {x : A} xs x ∈ᶠˢ filter P xs x ∈ xs × ∥ P x ∥
39+
∈ᶠˢ-filter {P = P} ⦃ d = d ⦄ {x = x} = Finset-elim-prop (λ xs x ∈ filter P xs x ∈ xs × ∥ P x ∥)
4040
(λ w absurd (¬mem-[] w))
41-
(λ y {xs} ind case d {y} return (λ p x ∈ᶠˢ cons-if p y (filter P xs) ∥ P x ∥) of λ where
42-
(yes py) ∈ᶠˢ-split (λ p inc (substᵢ P (symᵢ p) py)) ind
43-
(no ¬py) q ind q)
41+
(λ y {xs} ind case d {y} return (λ p x ∈ᶠˢ cons-if p y (filter P xs) x ∈ (y ∷ xs) × ∥ P x ∥) of λ where
42+
(yes py) ∈ᶠˢ-split (λ p hereₛ' p , inc (substᵢ P (symᵢ p) py)) λ w case ind w of λ a b thereₛ a , inc b
43+
(no ¬py) q case ind q of λ a b thereₛ a , inc b)
4444

4545
uncons : (x : A) (xs : Finset A) x ∈ᶠˢ xs xs ≡ x ∷ xs
4646
uncons x = Finset-elim-prop _ (λ x absurd (¬mem-[] x)) λ y {xs} ih ∈ᶠˢ-split
@@ -208,3 +208,27 @@ powerset (squash x y p q i j) = hlevel 2 (powerset x) (powerset y) (λ i → pow
208208
ys' p n ∈ᶠˢ-split {P = λ _ y ∈ᶠˢ (x ∷ xs)} hereₛ'
209209
(λ w thereₛ (ih ys' n y w))
210210
(substᵢ (y ∈ᶠˢ_) (symᵢ p) m)
211+
212+
delete : ⦃ _ : Discrete A ⦄ A Finset A Finset A
213+
delete x xs = filter (x ≠_) xs
214+
215+
powerset-∈ᶠˢ : ⦃ _ : Discrete A ⦄ (xs ys : Finset A) ys ⊆ xs ys ∈ powerset xs
216+
powerset-∈ᶠˢ = Finset-elim-prop _
217+
(λ ys sube hereₛ' (Id≃path.from (finset-ext sube (λ a m absurd (¬mem-[] m)))))
218+
λ x {xs} ih ys sube caseᵈ x ∈ ys of λ where
219+
(yes x∈ys)
220+
let
221+
ys' = delete x ys
222+
223+
p : x ∷ ys' ≡ ys
224+
p = finset-ext
225+
(λ a m ∈ᶠˢ-split {P = λ _ a ∈ ys} (λ p substᵢ (_∈ ys) (symᵢ p) x∈ys) (λ w case ∈ᶠˢ-filter {P = x ≠_} ys w of λ p _ p) m)
226+
λ a b case a ≡ᵢ? x of λ { (yes p) hereₛ' p ; (no ¬q) thereₛ (filter-∈ᶠˢ ys b λ a ¬q (Id≃path.from (sym a))) }
227+
228+
s' : delete x ys ⊆ xs
229+
s' a m =
230+
let (m' , a≠x) = ∈ᶠˢ-filter ys m
231+
in ∈ᶠˢ-split {P = λ _ a ∈ xs} (λ p case a≠x of λ ¬x=a absurd (¬x=a (Id≃path.to (symᵢ p)))) (λ w w) (sube a m')
232+
in unionr-∈ᶠˢ _ (powerset xs) _ $ map-∈ᶠˢ' (x ∷_) (powerset xs) p (ih ys' s')
233+
(no x∉ys) unionl-∈ᶠˢ _ (powerset xs) _ $ ih ys λ a m ∈ᶠˢ-split {P = λ _ a ∈ xs}
234+
(λ a=x absurd (x∉ys (substᵢ (_∈ ys) a=x m))) (λ w w) (sube a m)

0 commit comments

Comments
 (0)