| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Some properties about subsets |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Data.Fin.Subset.Properties where |
| 10 |
|
| 11 |
import Algebra.Definitions as AlgebraicDefinitions |
| 12 |
import Algebra.Structures as AlgebraicStructures |
| 13 |
using (IsMagma; IsSemigroup; IsMonoid; IsBand; IsCommutativeMonoid |
| 14 |
; IsIdempotentCommutativeMonoid) |
| 15 |
import Algebra.Lattice.Structures as AlgebraicLatticeStructures |
| 16 |
using (IsSemilattice; IsLattice; IsDistributiveLattice; IsBooleanAlgebra) |
| 17 |
open import Algebra.Bundles |
| 18 |
using (Magma; Semigroup; Monoid; Band; CommutativeMonoid |
| 19 |
; IdempotentCommutativeMonoid) |
| 20 |
open import Algebra.Lattice.Bundles |
| 21 |
using (Semilattice; Lattice; DistributiveLattice; BooleanAlgebra) |
| 22 |
import Algebra.Lattice.Properties.Lattice as L |
| 23 |
import Algebra.Lattice.Properties.DistributiveLattice as DL |
| 24 |
import Algebra.Lattice.Properties.BooleanAlgebra as BA |
| 25 |
open import Data.Bool.Base using (not) |
| 26 |
open import Data.Bool.Properties |
| 27 |
open import Data.Fin.Base using (Fin; suc; zero) |
| 28 |
open import Data.Fin.Subset |
| 29 |
open import Data.Fin.Properties using (any?; decFinSubset) |
| 30 |
open import Data.Nat.Base hiding (∣_-_∣) |
| 31 |
import Data.Nat.Properties as ℕ |
| 32 |
open import Data.Product as Product using (∃; ∄; _×_; _,_; proj₁) |
| 33 |
open import Data.Sum.Base as Sum using (_⊎_; inj₁; inj₂; [_,_]′) |
| 34 |
open import Data.Vec.Base using (Vec; []; _∷_; here; there) |
| 35 |
open import Data.Vec.Properties |
| 36 |
open import Function.Base using (_∘_; const; id; case_of_) |
| 37 |
open import Function.Bundles using (_⇔_; mk⇔) |
| 38 |
open import Level using (Level) |
| 39 |
open import Relation.Binary.Core using (_⇒_) |
| 40 |
open import Relation.Binary.Structures |
| 41 |
using (IsPreorder; IsPartialOrder; IsStrictPartialOrder; IsDecStrictPartialOrder) |
| 42 |
open import Relation.Binary.Bundles |
| 43 |
using (Preorder; Poset; StrictPartialOrder; DecStrictPartialOrder) |
| 44 |
open import Relation.Binary.Definitions as B hiding (Decidable; Empty) |
| 45 |
open import Relation.Binary.PropositionalEquality.Core |
| 46 |
using (_≡_; refl; cong; cong₂; subst; _≢_; sym) |
| 47 |
open import Relation.Binary.PropositionalEquality.Properties |
| 48 |
using (module ≡-Reasoning; isEquivalence) |
| 49 |
open import Relation.Nullary.Decidable as Dec using (Dec; yes; no; _⊎-dec_) |
| 50 |
open import Relation.Nullary.Negation using (contradiction) |
| 51 |
open import Relation.Unary using (Pred; Decidable; Satisfiable) |
| 52 |
|
| 53 |
private |
| 54 |
variable |
| 55 |
ℓ : Level |
| 56 |
n : ℕ |
| 57 |
s t : Side |
| 58 |
x y : Fin n |
| 59 |
p q : Subset n |
| 60 |
|
| 61 |
------------------------------------------------------------------------ |
| 62 |
-- Constructor mangling |
| 63 |
|
| 64 |
drop-there : suc x ∈ s ∷ p → x ∈ p |
| 65 |
drop-there (there x∈p) = x∈p |
| 66 |
|
| 67 |
drop-not-there : suc x ∉ s ∷ p → x ∉ p |
| 68 |
drop-not-there x∉sp x∈p = contradiction (there x∈p) x∉sp |
| 69 |
|
| 70 |
drop-∷-⊆ : s ∷ p ⊆ t ∷ q → p ⊆ q |
| 71 |
drop-∷-⊆ sp⊆tq x∈p = drop-there (sp⊆tq (there x∈p)) |
| 72 |
|
| 73 |
drop-∷-⊂ : s ∷ p ⊂ s ∷ q → p ⊂ q |
| 74 |
drop-∷-⊂ {s = inside} (_ , zero , _ , x∉sp) = contradiction here x∉sp |
| 75 |
drop-∷-⊂ {s} (sp⊆sq , suc x , there x∈q , x∉sp) = drop-∷-⊆ sp⊆sq , x , x∈q , drop-not-there x∉sp |
| 76 |
|
| 77 |
out⊆ : p ⊆ q → outside ∷ p ⊆ s ∷ q |
| 78 |
out⊆ p⊆q (there ∈p) = there (p⊆q ∈p) |
| 79 |
|
| 80 |
out⊆-⇔ : p ⊆ q ⇔ outside ∷ p ⊆ s ∷ q |
| 81 |
out⊆-⇔ = mk⇔ out⊆ drop-∷-⊆ |
| 82 |
|
| 83 |
in⊆in : p ⊆ q → inside ∷ p ⊆ inside ∷ q |
| 84 |
in⊆in p⊆q here = here |
| 85 |
in⊆in p⊆q (there ∈p) = there (p⊆q ∈p) |
| 86 |
|
| 87 |
in⊆in-⇔ : p ⊆ q ⇔ inside ∷ p ⊆ inside ∷ q |
| 88 |
in⊆in-⇔ = mk⇔ in⊆in drop-∷-⊆ |
| 89 |
|
| 90 |
s⊆s : p ⊆ q → s ∷ p ⊆ s ∷ q |
| 91 |
s⊆s p⊆q here = here |
| 92 |
s⊆s p⊆q (there ∈p) = there (p⊆q ∈p) |
| 93 |
|
| 94 |
s⊂s : p ⊂ q → s ∷ p ⊂ s ∷ q |
| 95 |
s⊂s (p⊆q , v , v∈p , v∉q) = s⊆s p⊆q , suc v , there v∈p , v∉q ∘ drop-there |
| 96 |
|
| 97 |
out⊂ : p ⊂ q → outside ∷ p ⊂ s ∷ q |
| 98 |
out⊂ (p⊆q , x , x∈q , x∉p) = out⊆ p⊆q , suc x , there x∈q , x∉p ∘ drop-there |
| 99 |
|
| 100 |
in⊂in : p ⊂ q → inside ∷ p ⊂ inside ∷ q |
| 101 |
in⊂in = s⊂s |
| 102 |
|
| 103 |
out⊂in : p ⊆ q → outside ∷ p ⊂ inside ∷ q |
| 104 |
out⊂in p⊆q = out⊆ p⊆q , zero , here , λ () |
| 105 |
|
| 106 |
out⊂in-⇔ : p ⊆ q ⇔ outside ∷ p ⊂ inside ∷ q |
| 107 |
out⊂in-⇔ = mk⇔ out⊂in (drop-∷-⊆ ∘ proj₁) |
| 108 |
|
| 109 |
out⊂out-⇔ : p ⊂ q ⇔ outside ∷ p ⊂ outside ∷ q |
| 110 |
out⊂out-⇔ = mk⇔ out⊂ drop-∷-⊂ |
| 111 |
|
| 112 |
in⊂in-⇔ : p ⊂ q ⇔ inside ∷ p ⊂ inside ∷ q |
| 113 |
in⊂in-⇔ = mk⇔ in⊂in drop-∷-⊂ |
| 114 |
|
| 115 |
------------------------------------------------------------------------ |
| 116 |
-- _∈_ |
| 117 |
|
| 118 |
infix 4 _∈?_ |
| 119 |
_∈?_ : ∀ x (p : Subset n) → Dec (x ∈ p) |
| 120 |
zero ∈? inside ∷ p = yes here |
| 121 |
zero ∈? outside ∷ p = no λ() |
| 122 |
suc n ∈? s ∷ p = Dec.map′ there drop-there (n ∈? p) |
| 123 |
|
| 124 |
------------------------------------------------------------------------ |
| 125 |
-- Empty |
| 126 |
|
| 127 |
drop-∷-Empty : Empty (s ∷ p) → Empty p |
| 128 |
drop-∷-Empty ¬∃∈ (x , x∈p) = ¬∃∈ (suc x , there x∈p) |
| 129 |
|
| 130 |
Empty-unique : Empty p → p ≡ ⊥ |
| 131 |
Empty-unique {p = []} ¬∃∈ = refl |
| 132 |
Empty-unique {p = inside ∷ p} ¬∃∈ = contradiction (zero , here) ¬∃∈ |
| 133 |
Empty-unique {p = outside ∷ p} ¬∃∈ = |
| 134 |
cong (outside ∷_) (Empty-unique (drop-∷-Empty ¬∃∈)) |
| 135 |
|
| 136 |
nonempty? : Decidable {A = Subset n} Nonempty |
| 137 |
nonempty? p = any? (_∈? p) |
| 138 |
|
| 139 |
------------------------------------------------------------------------ |
| 140 |
-- ∣_∣ |
| 141 |
|
| 142 |
∣p∣≤n : ∀ (p : Subset n) → ∣ p ∣ ≤ n |
| 143 |
∣p∣≤n = count≤n (_≟ inside) |
| 144 |
|
| 145 |
∣p∣≤∣x∷p∣ : ∀ x (p : Subset n) → ∣ p ∣ ≤ ∣ x ∷ p ∣ |
| 146 |
∣p∣≤∣x∷p∣ outside p = ℕ.≤-refl |
| 147 |
∣p∣≤∣x∷p∣ inside p = ℕ.n≤1+n ∣ p ∣ |
| 148 |
|
| 149 |
------------------------------------------------------------------------ |
| 150 |
-- ⊥ |
| 151 |
|
| 152 |
∉⊥ : x ∉ ⊥ |
| 153 |
∉⊥ (there p) = ∉⊥ p |
| 154 |
|
| 155 |
⊥⊆ : ⊥ ⊆ p |
| 156 |
⊥⊆ x∈⊥ = contradiction x∈⊥ ∉⊥ |
| 157 |
|
| 158 |
∣⊥∣≡0 : ∀ n → ∣ ⊥ {n = n} ∣ ≡ 0 |
| 159 |
∣⊥∣≡0 zero = refl |
| 160 |
∣⊥∣≡0 (suc n) = ∣⊥∣≡0 n |
| 161 |
|
| 162 |
------------------------------------------------------------------------ |
| 163 |
-- ⊤ |
| 164 |
|
| 165 |
∈⊤ : x ∈ ⊤ |
| 166 |
∈⊤ {x = zero} = here |
| 167 |
∈⊤ {x = suc x} = there ∈⊤ |
| 168 |
|
| 169 |
⊆⊤ : p ⊆ ⊤ |
| 170 |
⊆⊤ = const ∈⊤ |
| 171 |
|
| 172 |
∣⊤∣≡n : ∀ n → ∣ ⊤ {n} ∣ ≡ n |
| 173 |
∣⊤∣≡n zero = refl |
| 174 |
∣⊤∣≡n (suc n) = cong suc (∣⊤∣≡n n) |
| 175 |
|
| 176 |
∣p∣≡n⇒p≡⊤ : ∣ p ∣ ≡ n → p ≡ ⊤ {n} |
| 177 |
∣p∣≡n⇒p≡⊤ {p = []} _ = refl |
| 178 |
∣p∣≡n⇒p≡⊤ {p = outside ∷ p} |p|≡n = contradiction |p|≡n (ℕ.<⇒≢ (s≤s (∣p∣≤n p))) |
| 179 |
∣p∣≡n⇒p≡⊤ {p = inside ∷ p} |p|≡n = cong (inside ∷_) (∣p∣≡n⇒p≡⊤ (ℕ.suc-injective |p|≡n)) |
| 180 |
|
| 181 |
------------------------------------------------------------------------ |
| 182 |
-- ⁅_⁆ |
| 183 |
|
| 184 |
x∈⁅x⁆ : ∀ (x : Fin n) → x ∈ ⁅ x ⁆ |
| 185 |
x∈⁅x⁆ zero = here |
| 186 |
x∈⁅x⁆ (suc x) = there (x∈⁅x⁆ x) |
| 187 |
|
| 188 |
x∈⁅y⁆⇒x≡y : ∀ {x} (y : Fin n) → x ∈ ⁅ y ⁆ → x ≡ y |
| 189 |
x∈⁅y⁆⇒x≡y zero here = refl |
| 190 |
x∈⁅y⁆⇒x≡y zero (there p) = contradiction p ∉⊥ |
| 191 |
x∈⁅y⁆⇒x≡y (suc y) (there p) = cong suc (x∈⁅y⁆⇒x≡y y p) |
| 192 |
|
| 193 |
x∈⁅y⁆⇔x≡y : x ∈ ⁅ y ⁆ ⇔ x ≡ y |
| 194 |
x∈⁅y⁆⇔x≡y {x = x} {y = y} = mk⇔ |
| 195 |
(x∈⁅y⁆⇒x≡y y) |
| 196 |
(λ x≡y → subst (λ y → x ∈ ⁅ y ⁆) x≡y (x∈⁅x⁆ x)) |
| 197 |
|
| 198 |
x≢y⇒x∉⁅y⁆ : x ≢ y → x ∉ ⁅ y ⁆ |
| 199 |
x≢y⇒x∉⁅y⁆ x≢y = x≢y ∘ x∈⁅y⁆⇒x≡y _ |
| 200 |
|
| 201 |
x∉⁅y⁆⇒x≢y : x ∉ ⁅ y ⁆ → x ≢ y |
| 202 |
x∉⁅y⁆⇒x≢y x∉⁅x⁆ refl = x∉⁅x⁆ (x∈⁅x⁆ _) |
| 203 |
|
| 204 |
∣⁅x⁆∣≡1 : ∀ (i : Fin n) → ∣ ⁅ i ⁆ ∣ ≡ 1 |
| 205 |
∣⁅x⁆∣≡1 {suc n} zero = cong suc (∣⊥∣≡0 n) |
| 206 |
∣⁅x⁆∣≡1 {_} (suc i) = ∣⁅x⁆∣≡1 i |
| 207 |
|
| 208 |
------------------------------------------------------------------------ |
| 209 |
-- _⊆_ |
| 210 |
|
| 211 |
⊆-refl : Reflexive {A = Subset n} _⊆_ |
| 212 |
⊆-refl = id |
| 213 |
|
| 214 |
⊆-reflexive : _≡_ {A = Subset n} ⇒ _⊆_ |
| 215 |
⊆-reflexive refl = ⊆-refl |
| 216 |
|
| 217 |
⊆-trans : Transitive {A = Subset n} _⊆_ |
| 218 |
⊆-trans p⊆q q⊆r x∈p = q⊆r (p⊆q x∈p) |
| 219 |
|
| 220 |
⊆-antisym : Antisymmetric {A = Subset n} _≡_ _⊆_ |
| 221 |
⊆-antisym {i = []} {[]} p⊆q q⊆p = refl |
| 222 |
⊆-antisym {i = x ∷ xs} {y ∷ ys} p⊆q q⊆p with x | y |
| 223 |
... | inside | inside = cong₂ _∷_ refl (⊆-antisym (drop-∷-⊆ p⊆q) (drop-∷-⊆ q⊆p)) |
| 224 |
... | inside | outside = contradiction (p⊆q here) λ() |
| 225 |
... | outside | inside = contradiction (q⊆p here) λ() |
| 226 |
... | outside | outside = cong₂ _∷_ refl (⊆-antisym (drop-∷-⊆ p⊆q) (drop-∷-⊆ q⊆p)) |
| 227 |
|
| 228 |
⊆-min : Minimum {A = Subset n} _⊆_ ⊥ |
| 229 |
⊆-min p = ⊥⊆ |
| 230 |
|
| 231 |
⊆-max : Maximum {A = Subset n} _⊆_ ⊤ |
| 232 |
⊆-max p = ⊆⊤ |
| 233 |
|
| 234 |
infix 4 _⊆?_ |
| 235 |
_⊆?_ : B.Decidable {A = Subset n} _⊆_ |
| 236 |
[] ⊆? [] = yes id |
| 237 |
outside ∷ p ⊆? y ∷ q = Dec.map out⊆-⇔ (p ⊆? q) |
| 238 |
inside ∷ p ⊆? outside ∷ q = no (λ p⊆q → case (p⊆q here) of λ()) |
| 239 |
inside ∷ p ⊆? inside ∷ q = Dec.map in⊆in-⇔ (p ⊆? q) |
| 240 |
|
| 241 |
module _ (n : ℕ) where |
| 242 |
|
| 243 |
⊆-isPreorder : IsPreorder {A = Subset n} _≡_ _⊆_ |
| 244 |
⊆-isPreorder = record |
| 245 |
{ isEquivalence = isEquivalence |
| 246 |
; reflexive = ⊆-reflexive |
| 247 |
; trans = ⊆-trans |
| 248 |
} |
| 249 |
|
| 250 |
⊆-isPartialOrder : IsPartialOrder {A = Subset n} _≡_ _⊆_ |
| 251 |
⊆-isPartialOrder = record |
| 252 |
{ isPreorder = ⊆-isPreorder |
| 253 |
; antisym = ⊆-antisym |
| 254 |
} |
| 255 |
|
| 256 |
⊆-preorder : Preorder _ _ _ |
| 257 |
⊆-preorder = record |
| 258 |
{ isPreorder = ⊆-isPreorder |
| 259 |
} |
| 260 |
|
| 261 |
⊆-poset : Poset _ _ _ |
| 262 |
⊆-poset = record |
| 263 |
{ isPartialOrder = ⊆-isPartialOrder |
| 264 |
} |
| 265 |
|
| 266 |
p⊆q⇒∣p∣≤∣q∣ : p ⊆ q → ∣ p ∣ ≤ ∣ q ∣ |
| 267 |
p⊆q⇒∣p∣≤∣q∣ {p = []} {[]} p⊆q = z≤n |
| 268 |
p⊆q⇒∣p∣≤∣q∣ {p = outside ∷ p} {outside ∷ q} p⊆q = p⊆q⇒∣p∣≤∣q∣ (drop-∷-⊆ p⊆q) |
| 269 |
p⊆q⇒∣p∣≤∣q∣ {p = outside ∷ p} {inside ∷ q} p⊆q = ℕ.m≤n⇒m≤1+n (p⊆q⇒∣p∣≤∣q∣ (drop-∷-⊆ p⊆q)) |
| 270 |
p⊆q⇒∣p∣≤∣q∣ {p = inside ∷ p} {outside ∷ q} p⊆q = contradiction (p⊆q here) λ() |
| 271 |
p⊆q⇒∣p∣≤∣q∣ {p = inside ∷ p} {inside ∷ q} p⊆q = s≤s (p⊆q⇒∣p∣≤∣q∣ (drop-∷-⊆ p⊆q)) |
| 272 |
|
| 273 |
|
| 274 |
------------------------------------------------------------------------ |
| 275 |
-- _⊂_ |
| 276 |
|
| 277 |
p⊂q⇒p⊆q : p ⊂ q → p ⊆ q |
| 278 |
p⊂q⇒p⊆q = proj₁ |
| 279 |
|
| 280 |
⊂-trans : Transitive {A = Subset n} _⊂_ |
| 281 |
⊂-trans (p⊆q , x , x∈q , x∉p) (q⊆r , _ , _ , _) = ⊆-trans p⊆q q⊆r , x , q⊆r x∈q , x∉p |
| 282 |
|
| 283 |
⊂-⊆-trans : Trans {A = Subset n} _⊂_ _⊆_ _⊂_ |
| 284 |
⊂-⊆-trans (p⊆q , x , x∈q , x∉p) q⊆r = ⊆-trans p⊆q q⊆r , x , q⊆r x∈q , x∉p |
| 285 |
|
| 286 |
⊆-⊂-trans : Trans {A = Subset n} _⊆_ _⊂_ _⊂_ |
| 287 |
⊆-⊂-trans p⊆q (q⊆r , x , x∈r , x∉q) = ⊆-trans p⊆q q⊆r , x , x∈r , x∉q ∘ p⊆q |
| 288 |
|
| 289 |
⊂-irref : Irreflexive {A = Subset n} _≡_ _⊂_ |
| 290 |
⊂-irref refl (_ , x , x∈p , x∉q) = contradiction x∈p x∉q |
| 291 |
|
| 292 |
⊂-antisym : Antisymmetric {A = Subset n} _≡_ _⊂_ |
| 293 |
⊂-antisym (p⊆q , _) (q⊆p , _) = ⊆-antisym p⊆q q⊆p |
| 294 |
|
| 295 |
⊂-asymmetric : Asymmetric {A = Subset n} _⊂_ |
| 296 |
⊂-asymmetric (p⊆q , _) (_ , x , x∈p , x∉q) = contradiction (p⊆q x∈p) x∉q |
| 297 |
|
| 298 |
infix 4 _⊂?_ |
| 299 |
|
| 300 |
_⊂?_ : B.Decidable {A = Subset n} _⊂_ |
| 301 |
[] ⊂? [] = no λ () |
| 302 |
outside ∷ p ⊂? outside ∷ q = Dec.map out⊂out-⇔ (p ⊂? q) |
| 303 |
outside ∷ p ⊂? inside ∷ q = Dec.map out⊂in-⇔ (p ⊆? q) |
| 304 |
inside ∷ p ⊂? outside ∷ q = no (λ {(p⊆q , _) → case (p⊆q here) of λ ()}) |
| 305 |
inside ∷ p ⊂? inside ∷ q = Dec.map in⊂in-⇔ (p ⊂? q) |
| 306 |
|
| 307 |
module _ (n : ℕ) where |
| 308 |
|
| 309 |
⊂-isStrictPartialOrder : IsStrictPartialOrder {A = Subset n} _≡_ _⊂_ |
| 310 |
⊂-isStrictPartialOrder = record |
| 311 |
{ isEquivalence = isEquivalence |
| 312 |
; irrefl = ⊂-irref |
| 313 |
; trans = ⊂-trans |
| 314 |
; <-resp-≈ = (λ {refl → id}) , (λ {refl → id}) |
| 315 |
} |
| 316 |
|
| 317 |
⊂-isDecStrictPartialOrder : IsDecStrictPartialOrder {A = Subset n} _≡_ _⊂_ |
| 318 |
⊂-isDecStrictPartialOrder = record |
| 319 |
{ isStrictPartialOrder = ⊂-isStrictPartialOrder |
| 320 |
; _≟_ = ≡-dec _≟_ |
| 321 |
; _<?_ = _⊂?_ |
| 322 |
} |
| 323 |
|
| 324 |
⊂-strictPartialOrder : StrictPartialOrder _ _ _ |
| 325 |
⊂-strictPartialOrder = record |
| 326 |
{ isStrictPartialOrder = ⊂-isStrictPartialOrder |
| 327 |
} |
| 328 |
|
| 329 |
⊂-decStrictPartialOrder : DecStrictPartialOrder _ _ _ |
| 330 |
⊂-decStrictPartialOrder = record |
| 331 |
{ isDecStrictPartialOrder = ⊂-isDecStrictPartialOrder |
| 332 |
} |
| 333 |
|
| 334 |
p⊂q⇒∣p∣<∣q∣ : p ⊂ q → ∣ p ∣ < ∣ q ∣ |
| 335 |
p⊂q⇒∣p∣<∣q∣ {p = outside ∷ p} {outside ∷ q} op⊂oq@(_ , _ , _ , _) = p⊂q⇒∣p∣<∣q∣ (drop-∷-⊂ op⊂oq) |
| 336 |
p⊂q⇒∣p∣<∣q∣ {p = outside ∷ p} {inside ∷ q} (op⊆iq , _ , _ , _) = s≤s (p⊆q⇒∣p∣≤∣q∣ (drop-∷-⊆ op⊆iq)) |
| 337 |
p⊂q⇒∣p∣<∣q∣ {p = inside ∷ p} {outside ∷ q} (ip⊆oq , _ , _ , _) = contradiction (ip⊆oq here) λ() |
| 338 |
p⊂q⇒∣p∣<∣q∣ {p = inside ∷ p} {inside ∷ q} (_ , zero , _ , x∉ip) = contradiction here x∉ip |
| 339 |
p⊂q⇒∣p∣<∣q∣ {p = inside ∷ p} {inside ∷ q} ip⊂iq@(_ , suc x , _ , _) = s≤s (p⊂q⇒∣p∣<∣q∣ (drop-∷-⊂ ip⊂iq)) |
| 340 |
|
| 341 |
------------------------------------------------------------------------ |
| 342 |
-- ∁ |
| 343 |
|
| 344 |
x∈p⇒x∉∁p : x ∈ p → x ∉ ∁ p |
| 345 |
x∈p⇒x∉∁p (there x∈p) (there x∈∁p) = x∈p⇒x∉∁p x∈p x∈∁p |
| 346 |
|
| 347 |
x∈∁p⇒x∉p : x ∈ ∁ p → x ∉ p |
| 348 |
x∈∁p⇒x∉p (there x∈∁p) (there x∈p) = x∈∁p⇒x∉p x∈∁p x∈p |
| 349 |
|
| 350 |
x∉∁p⇒x∈p : x ∉ ∁ p → x ∈ p |
| 351 |
x∉∁p⇒x∈p {x = zero} {outside ∷ p} x∉∁p = contradiction here x∉∁p |
| 352 |
x∉∁p⇒x∈p {x = zero} {inside ∷ p} x∉∁p = here |
| 353 |
x∉∁p⇒x∈p {x = suc x} {_ ∷ p} x∉∁p = there (x∉∁p⇒x∈p (x∉∁p ∘ there)) |
| 354 |
|
| 355 |
x∉p⇒x∈∁p : x ∉ p → x ∈ ∁ p |
| 356 |
x∉p⇒x∈∁p {x = zero} {outside ∷ p} x∉p = here |
| 357 |
x∉p⇒x∈∁p {x = zero} {inside ∷ p} x∉p = contradiction here x∉p |
| 358 |
x∉p⇒x∈∁p {x = suc x} {_ ∷ p} x∉p = there (x∉p⇒x∈∁p (x∉p ∘ there)) |
| 359 |
|
| 360 |
p∪∁p≡⊤ : ∀ (p : Subset n) → p ∪ ∁ p ≡ ⊤ |
| 361 |
p∪∁p≡⊤ [] = refl |
| 362 |
p∪∁p≡⊤ (outside ∷ p) = cong (inside ∷_) (p∪∁p≡⊤ p) |
| 363 |
p∪∁p≡⊤ (inside ∷ p) = cong (inside ∷_) (p∪∁p≡⊤ p) |
| 364 |
|
| 365 |
∣∁p∣≡n∸∣p∣ : ∀ (p : Subset n) → ∣ ∁ p ∣ ≡ n ∸ ∣ p ∣ |
| 366 |
∣∁p∣≡n∸∣p∣ [] = refl |
| 367 |
∣∁p∣≡n∸∣p∣ (inside ∷ p) = ∣∁p∣≡n∸∣p∣ p |
| 368 |
∣∁p∣≡n∸∣p∣ (outside ∷ p) = begin |
| 369 |
suc ∣ ∁ p ∣ ≡⟨ cong suc (∣∁p∣≡n∸∣p∣ p) ⟩ |
| 370 |
suc (_ ∸ ∣ p ∣) ≡⟨ sym (ℕ.+-∸-assoc 1 (∣p∣≤n p)) ⟩ |
| 371 |
suc _ ∸ ∣ p ∣ ∎ |
| 372 |
where open ≡-Reasoning |
| 373 |
|
| 374 |
p⊆q⇒∁p⊇∁q : p ⊆ q → ∁ p ⊇ ∁ q |
| 375 |
p⊆q⇒∁p⊇∁q p⊆q x∈∁q = x∉p⇒x∈∁p (x∈∁p⇒x∉p x∈∁q ∘ p⊆q) |
| 376 |
|
| 377 |
∁p⊆∁q⇒p⊇q : ∁ p ⊆ ∁ q → p ⊇ q |
| 378 |
∁p⊆∁q⇒p⊇q ∁p⊆∁q x∈q = x∉∁p⇒x∈p (x∈p⇒x∉∁p x∈q ∘ ∁p⊆∁q) |
| 379 |
|
| 380 |
p⊂q⇒∁p⊃∁q : p ⊂ q → ∁ p ⊃ ∁ q |
| 381 |
p⊂q⇒∁p⊃∁q (p⊆q , x , x∈q , x∉p) = p⊆q⇒∁p⊇∁q p⊆q , x , x∉p⇒x∈∁p x∉p , x∈p⇒x∉∁p x∈q |
| 382 |
|
| 383 |
∁p⊂∁q⇒p⊃q : ∁ p ⊂ ∁ q → p ⊃ q |
| 384 |
∁p⊂∁q⇒p⊃q (∁p⊆∁q , x , x∈∁q , x∉∁p) = ∁p⊆∁q⇒p⊇q ∁p⊆∁q , x , x∉∁p⇒x∈p x∉∁p , x∈∁p⇒x∉p x∈∁q |
| 385 |
|
| 386 |
------------------------------------------------------------------------ |
| 387 |
-- _∩_ |
| 388 |
|
| 389 |
module _ {n : ℕ} where |
| 390 |
|
| 391 |
open AlgebraicDefinitions {A = Subset n} _≡_ |
| 392 |
|
| 393 |
∩-assoc : Associative _∩_ |
| 394 |
∩-assoc = zipWith-assoc ∧-assoc |
| 395 |
|
| 396 |
∩-comm : Commutative _∩_ |
| 397 |
∩-comm = zipWith-comm ∧-comm |
| 398 |
|
| 399 |
∩-idem : Idempotent _∩_ |
| 400 |
∩-idem = zipWith-idem ∧-idem |
| 401 |
|
| 402 |
∩-identityˡ : LeftIdentity ⊤ _∩_ |
| 403 |
∩-identityˡ = zipWith-identityˡ ∧-identityˡ |
| 404 |
|
| 405 |
∩-identityʳ : RightIdentity ⊤ _∩_ |
| 406 |
∩-identityʳ = zipWith-identityʳ ∧-identityʳ |
| 407 |
|
| 408 |
∩-identity : Identity ⊤ _∩_ |
| 409 |
∩-identity = ∩-identityˡ , ∩-identityʳ |
| 410 |
|
| 411 |
∩-zeroˡ : LeftZero ⊥ _∩_ |
| 412 |
∩-zeroˡ = zipWith-zeroˡ ∧-zeroˡ |
| 413 |
|
| 414 |
∩-zeroʳ : RightZero ⊥ _∩_ |
| 415 |
∩-zeroʳ = zipWith-zeroʳ ∧-zeroʳ |
| 416 |
|
| 417 |
∩-zero : Zero ⊥ _∩_ |
| 418 |
∩-zero = ∩-zeroˡ , ∩-zeroʳ |
| 419 |
|
| 420 |
∩-inverseˡ : LeftInverse ⊥ ∁ _∩_ |
| 421 |
∩-inverseˡ = zipWith-inverseˡ ∧-inverseˡ |
| 422 |
|
| 423 |
∩-inverseʳ : RightInverse ⊥ ∁ _∩_ |
| 424 |
∩-inverseʳ = zipWith-inverseʳ ∧-inverseʳ |
| 425 |
|
| 426 |
∩-inverse : Inverse ⊥ ∁ _∩_ |
| 427 |
∩-inverse = ∩-inverseˡ , ∩-inverseʳ |
| 428 |
|
| 429 |
module _ (n : ℕ) where |
| 430 |
|
| 431 |
open AlgebraicStructures {A = Subset n} _≡_ |
| 432 |
open AlgebraicLatticeStructures {A = Subset n} _≡_ |
| 433 |
|
| 434 |
∩-isMagma : IsMagma _∩_ |
| 435 |
∩-isMagma = record |
| 436 |
{ isEquivalence = isEquivalence |
| 437 |
; ∙-cong = cong₂ _∩_ |
| 438 |
} |
| 439 |
|
| 440 |
∩-isSemigroup : IsSemigroup _∩_ |
| 441 |
∩-isSemigroup = record |
| 442 |
{ isMagma = ∩-isMagma |
| 443 |
; assoc = ∩-assoc |
| 444 |
} |
| 445 |
|
| 446 |
∩-isBand : IsBand _∩_ |
| 447 |
∩-isBand = record |
| 448 |
{ isSemigroup = ∩-isSemigroup |
| 449 |
; idem = ∩-idem |
| 450 |
} |
| 451 |
|
| 452 |
∩-isSemilattice : IsSemilattice _∩_ |
| 453 |
∩-isSemilattice = record |
| 454 |
{ isBand = ∩-isBand |
| 455 |
; comm = ∩-comm |
| 456 |
} |
| 457 |
|
| 458 |
∩-isMonoid : IsMonoid _∩_ ⊤ |
| 459 |
∩-isMonoid = record |
| 460 |
{ isSemigroup = ∩-isSemigroup |
| 461 |
; identity = ∩-identity |
| 462 |
} |
| 463 |
|
| 464 |
∩-isCommutativeMonoid : IsCommutativeMonoid _∩_ ⊤ |
| 465 |
∩-isCommutativeMonoid = record |
| 466 |
{ isMonoid = ∩-isMonoid |
| 467 |
; comm = ∩-comm |
| 468 |
} |
| 469 |
|
| 470 |
∩-isIdempotentCommutativeMonoid : IsIdempotentCommutativeMonoid _∩_ ⊤ |
| 471 |
∩-isIdempotentCommutativeMonoid = record |
| 472 |
{ isCommutativeMonoid = ∩-isCommutativeMonoid |
| 473 |
; idem = ∩-idem |
| 474 |
} |
| 475 |
|
| 476 |
∩-magma : Magma _ _ |
| 477 |
∩-magma = record |
| 478 |
{ isMagma = ∩-isMagma |
| 479 |
} |
| 480 |
|
| 481 |
∩-semigroup : Semigroup _ _ |
| 482 |
∩-semigroup = record |
| 483 |
{ isSemigroup = ∩-isSemigroup |
| 484 |
} |
| 485 |
|
| 486 |
∩-band : Band _ _ |
| 487 |
∩-band = record |
| 488 |
{ isBand = ∩-isBand |
| 489 |
} |
| 490 |
|
| 491 |
∩-semilattice : Semilattice _ _ |
| 492 |
∩-semilattice = record |
| 493 |
{ isSemilattice = ∩-isSemilattice |
| 494 |
} |
| 495 |
|
| 496 |
∩-monoid : Monoid _ _ |
| 497 |
∩-monoid = record |
| 498 |
{ isMonoid = ∩-isMonoid |
| 499 |
} |
| 500 |
|
| 501 |
∩-commutativeMonoid : CommutativeMonoid _ _ |
| 502 |
∩-commutativeMonoid = record |
| 503 |
{ isCommutativeMonoid = ∩-isCommutativeMonoid |
| 504 |
} |
| 505 |
|
| 506 |
∩-idempotentCommutativeMonoid : IdempotentCommutativeMonoid _ _ |
| 507 |
∩-idempotentCommutativeMonoid = record |
| 508 |
{ isIdempotentCommutativeMonoid = ∩-isIdempotentCommutativeMonoid |
| 509 |
} |
| 510 |
|
| 511 |
p∩q⊆p : ∀ (p q : Subset n) → p ∩ q ⊆ p |
| 512 |
p∩q⊆p [] [] x∈p∩q = x∈p∩q |
| 513 |
p∩q⊆p (inside ∷ p) (inside ∷ q) here = here |
| 514 |
p∩q⊆p (inside ∷ p) (_ ∷ q) (there ∈p∩q) = there (p∩q⊆p p q ∈p∩q) |
| 515 |
p∩q⊆p (outside ∷ p) (_ ∷ q) (there ∈p∩q) = there (p∩q⊆p p q ∈p∩q) |
| 516 |
|
| 517 |
p∩q⊆q : ∀ (p q : Subset n) → p ∩ q ⊆ q |
| 518 |
p∩q⊆q p q rewrite ∩-comm p q = p∩q⊆p q p |
| 519 |
|
| 520 |
x∈p∩q⁺ : x ∈ p × x ∈ q → x ∈ p ∩ q |
| 521 |
x∈p∩q⁺ (here , here) = here |
| 522 |
x∈p∩q⁺ (there x∈p , there x∈q) = there (x∈p∩q⁺ (x∈p , x∈q)) |
| 523 |
|
| 524 |
x∈p∩q⁻ : ∀ (p q : Subset n) → x ∈ p ∩ q → x ∈ p × x ∈ q |
| 525 |
x∈p∩q⁻ (inside ∷ p) (inside ∷ q) here = here , here |
| 526 |
x∈p∩q⁻ (s ∷ p) (t ∷ q) (there x∈p∩q) = |
| 527 |
Product.map there there (x∈p∩q⁻ p q x∈p∩q) |
| 528 |
|
| 529 |
∩⇔× : x ∈ p ∩ q ⇔ (x ∈ p × x ∈ q) |
| 530 |
∩⇔× = mk⇔ (x∈p∩q⁻ _ _) x∈p∩q⁺ |
| 531 |
|
| 532 |
∣p∩q∣≤∣p∣ : ∀ (p q : Subset n) → ∣ p ∩ q ∣ ≤ ∣ p ∣ |
| 533 |
∣p∩q∣≤∣p∣ p q = p⊆q⇒∣p∣≤∣q∣ (p∩q⊆p p q) |
| 534 |
|
| 535 |
∣p∩q∣≤∣q∣ : ∀ (p q : Subset n) → ∣ p ∩ q ∣ ≤ ∣ q ∣ |
| 536 |
∣p∩q∣≤∣q∣ p q = p⊆q⇒∣p∣≤∣q∣ (p∩q⊆q p q) |
| 537 |
|
| 538 |
∣p∩q∣≤∣p∣⊓∣q∣ : ∀ (p q : Subset n) → ∣ p ∩ q ∣ ≤ ∣ p ∣ ⊓ ∣ q ∣ |
| 539 |
∣p∩q∣≤∣p∣⊓∣q∣ p q = ℕ.⊓-glb (∣p∩q∣≤∣p∣ p q) (∣p∩q∣≤∣q∣ p q) |
| 540 |
|
| 541 |
------------------------------------------------------------------------ |
| 542 |
-- _∪_ |
| 543 |
|
| 544 |
module _ {n : ℕ} where |
| 545 |
|
| 546 |
open AlgebraicDefinitions {A = Subset n} _≡_ |
| 547 |
|
| 548 |
∪-assoc : Associative _∪_ |
| 549 |
∪-assoc = zipWith-assoc ∨-assoc |
| 550 |
|
| 551 |
∪-comm : Commutative _∪_ |
| 552 |
∪-comm = zipWith-comm ∨-comm |
| 553 |
|
| 554 |
∪-idem : Idempotent _∪_ |
| 555 |
∪-idem = zipWith-idem ∨-idem |
| 556 |
|
| 557 |
∪-identityˡ : LeftIdentity ⊥ _∪_ |
| 558 |
∪-identityˡ = zipWith-identityˡ ∨-identityˡ |
| 559 |
|
| 560 |
∪-identityʳ : RightIdentity ⊥ _∪_ |
| 561 |
∪-identityʳ = zipWith-identityʳ ∨-identityʳ |
| 562 |
|
| 563 |
∪-identity : Identity ⊥ _∪_ |
| 564 |
∪-identity = ∪-identityˡ , ∪-identityʳ |
| 565 |
|
| 566 |
∪-zeroˡ : LeftZero ⊤ _∪_ |
| 567 |
∪-zeroˡ = zipWith-zeroˡ ∨-zeroˡ |
| 568 |
|
| 569 |
∪-zeroʳ : RightZero ⊤ _∪_ |
| 570 |
∪-zeroʳ = zipWith-zeroʳ ∨-zeroʳ |
| 571 |
|
| 572 |
∪-zero : Zero ⊤ _∪_ |
| 573 |
∪-zero = ∪-zeroˡ , ∪-zeroʳ |
| 574 |
|
| 575 |
∪-inverseˡ : LeftInverse ⊤ ∁ _∪_ |
| 576 |
∪-inverseˡ = zipWith-inverseˡ ∨-inverseˡ |
| 577 |
|
| 578 |
∪-inverseʳ : RightInverse ⊤ ∁ _∪_ |
| 579 |
∪-inverseʳ = zipWith-inverseʳ ∨-inverseʳ |
| 580 |
|
| 581 |
∪-inverse : Inverse ⊤ ∁ _∪_ |
| 582 |
∪-inverse = ∪-inverseˡ , ∪-inverseʳ |
| 583 |
|
| 584 |
∪-distribˡ-∩ : _∪_ DistributesOverˡ _∩_ |
| 585 |
∪-distribˡ-∩ = zipWith-distribˡ ∨-distribˡ-∧ |
| 586 |
|
| 587 |
∪-distribʳ-∩ : _∪_ DistributesOverʳ _∩_ |
| 588 |
∪-distribʳ-∩ = zipWith-distribʳ ∨-distribʳ-∧ |
| 589 |
|
| 590 |
∪-distrib-∩ : _∪_ DistributesOver _∩_ |
| 591 |
∪-distrib-∩ = ∪-distribˡ-∩ , ∪-distribʳ-∩ |
| 592 |
|
| 593 |
∩-distribˡ-∪ : _∩_ DistributesOverˡ _∪_ |
| 594 |
∩-distribˡ-∪ = zipWith-distribˡ ∧-distribˡ-∨ |
| 595 |
|
| 596 |
∩-distribʳ-∪ : _∩_ DistributesOverʳ _∪_ |
| 597 |
∩-distribʳ-∪ = zipWith-distribʳ ∧-distribʳ-∨ |
| 598 |
|
| 599 |
∩-distrib-∪ : _∩_ DistributesOver _∪_ |
| 600 |
∩-distrib-∪ = ∩-distribˡ-∪ , ∩-distribʳ-∪ |
| 601 |
|
| 602 |
∪-abs-∩ : _∪_ Absorbs _∩_ |
| 603 |
∪-abs-∩ = zipWith-absorbs ∨-abs-∧ |
| 604 |
|
| 605 |
∩-abs-∪ : _∩_ Absorbs _∪_ |
| 606 |
∩-abs-∪ = zipWith-absorbs ∧-abs-∨ |
| 607 |
|
| 608 |
module _ (n : ℕ) where |
| 609 |
|
| 610 |
open AlgebraicStructures {A = Subset n} _≡_ |
| 611 |
open AlgebraicLatticeStructures {A = Subset n} _≡_ |
| 612 |
|
| 613 |
∪-isMagma : IsMagma _∪_ |
| 614 |
∪-isMagma = record |
| 615 |
{ isEquivalence = isEquivalence |
| 616 |
; ∙-cong = cong₂ _∪_ |
| 617 |
} |
| 618 |
|
| 619 |
∪-magma : Magma _ _ |
| 620 |
∪-magma = record |
| 621 |
{ isMagma = ∪-isMagma |
| 622 |
} |
| 623 |
|
| 624 |
∪-isSemigroup : IsSemigroup _∪_ |
| 625 |
∪-isSemigroup = record |
| 626 |
{ isMagma = ∪-isMagma |
| 627 |
; assoc = ∪-assoc |
| 628 |
} |
| 629 |
|
| 630 |
∪-semigroup : Semigroup _ _ |
| 631 |
∪-semigroup = record |
| 632 |
{ isSemigroup = ∪-isSemigroup |
| 633 |
} |
| 634 |
|
| 635 |
∪-isBand : IsBand _∪_ |
| 636 |
∪-isBand = record |
| 637 |
{ isSemigroup = ∪-isSemigroup |
| 638 |
; idem = ∪-idem |
| 639 |
} |
| 640 |
|
| 641 |
∪-band : Band _ _ |
| 642 |
∪-band = record |
| 643 |
{ isBand = ∪-isBand |
| 644 |
} |
| 645 |
|
| 646 |
∪-isSemilattice : IsSemilattice _∪_ |
| 647 |
∪-isSemilattice = record |
| 648 |
{ isBand = ∪-isBand |
| 649 |
; comm = ∪-comm |
| 650 |
} |
| 651 |
|
| 652 |
∪-semilattice : Semilattice _ _ |
| 653 |
∪-semilattice = record |
| 654 |
{ isSemilattice = ∪-isSemilattice |
| 655 |
} |
| 656 |
|
| 657 |
∪-isMonoid : IsMonoid _∪_ ⊥ |
| 658 |
∪-isMonoid = record |
| 659 |
{ isSemigroup = ∪-isSemigroup |
| 660 |
; identity = ∪-identity |
| 661 |
} |
| 662 |
|
| 663 |
∪-monoid : Monoid _ _ |
| 664 |
∪-monoid = record |
| 665 |
{ isMonoid = ∪-isMonoid |
| 666 |
} |
| 667 |
|
| 668 |
∪-isCommutativeMonoid : IsCommutativeMonoid _∪_ ⊥ |
| 669 |
∪-isCommutativeMonoid = record |
| 670 |
{ isMonoid = ∪-isMonoid |
| 671 |
; comm = ∪-comm |
| 672 |
} |
| 673 |
|
| 674 |
∪-commutativeMonoid : CommutativeMonoid _ _ |
| 675 |
∪-commutativeMonoid = record |
| 676 |
{ isCommutativeMonoid = ∪-isCommutativeMonoid |
| 677 |
} |
| 678 |
|
| 679 |
∪-isIdempotentCommutativeMonoid : IsIdempotentCommutativeMonoid _∪_ ⊥ |
| 680 |
∪-isIdempotentCommutativeMonoid = record |
| 681 |
{ isCommutativeMonoid = ∪-isCommutativeMonoid |
| 682 |
; idem = ∪-idem |
| 683 |
} |
| 684 |
|
| 685 |
∪-idempotentCommutativeMonoid : IdempotentCommutativeMonoid _ _ |
| 686 |
∪-idempotentCommutativeMonoid = record |
| 687 |
{ isIdempotentCommutativeMonoid = ∪-isIdempotentCommutativeMonoid |
| 688 |
} |
| 689 |
|
| 690 |
∪-∩-isLattice : IsLattice _∪_ _∩_ |
| 691 |
∪-∩-isLattice = record |
| 692 |
{ isEquivalence = isEquivalence |
| 693 |
; ∨-comm = ∪-comm |
| 694 |
; ∨-assoc = ∪-assoc |
| 695 |
; ∨-cong = cong₂ _∪_ |
| 696 |
; ∧-comm = ∩-comm |
| 697 |
; ∧-assoc = ∩-assoc |
| 698 |
; ∧-cong = cong₂ _∩_ |
| 699 |
; absorptive = ∪-abs-∩ , ∩-abs-∪ |
| 700 |
} |
| 701 |
|
| 702 |
∪-∩-lattice : Lattice _ _ |
| 703 |
∪-∩-lattice = record |
| 704 |
{ isLattice = ∪-∩-isLattice |
| 705 |
} |
| 706 |
|
| 707 |
∪-∩-isDistributiveLattice : IsDistributiveLattice _∪_ _∩_ |
| 708 |
∪-∩-isDistributiveLattice = record |
| 709 |
{ isLattice = ∪-∩-isLattice |
| 710 |
; ∨-distrib-∧ = ∪-distrib-∩ |
| 711 |
; ∧-distrib-∨ = ∩-distrib-∪ |
| 712 |
} |
| 713 |
|
| 714 |
∪-∩-distributiveLattice : DistributiveLattice _ _ |
| 715 |
∪-∩-distributiveLattice = record |
| 716 |
{ isDistributiveLattice = ∪-∩-isDistributiveLattice |
| 717 |
} |
| 718 |
|
| 719 |
∪-∩-isBooleanAlgebra : IsBooleanAlgebra _∪_ _∩_ ∁ ⊤ ⊥ |
| 720 |
∪-∩-isBooleanAlgebra = record |
| 721 |
{ isDistributiveLattice = ∪-∩-isDistributiveLattice |
| 722 |
; ∨-complement = ∪-inverse |
| 723 |
; ∧-complement = ∩-inverse |
| 724 |
; ¬-cong = cong ∁ |
| 725 |
} |
| 726 |
|
| 727 |
∪-∩-booleanAlgebra : BooleanAlgebra _ _ |
| 728 |
∪-∩-booleanAlgebra = record |
| 729 |
{ isBooleanAlgebra = ∪-∩-isBooleanAlgebra |
| 730 |
} |
| 731 |
|
| 732 |
∩-∪-isLattice : IsLattice _∩_ _∪_ |
| 733 |
∩-∪-isLattice = L.∧-∨-isLattice ∪-∩-lattice |
| 734 |
|
| 735 |
∩-∪-lattice : Lattice _ _ |
| 736 |
∩-∪-lattice = L.∧-∨-lattice ∪-∩-lattice |
| 737 |
|
| 738 |
∩-∪-isDistributiveLattice : IsDistributiveLattice _∩_ _∪_ |
| 739 |
∩-∪-isDistributiveLattice = DL.∧-∨-isDistributiveLattice ∪-∩-distributiveLattice |
| 740 |
|
| 741 |
∩-∪-distributiveLattice : DistributiveLattice _ _ |
| 742 |
∩-∪-distributiveLattice = DL.∧-∨-distributiveLattice ∪-∩-distributiveLattice |
| 743 |
|
| 744 |
∩-∪-isBooleanAlgebra : IsBooleanAlgebra _∩_ _∪_ ∁ ⊥ ⊤ |
| 745 |
∩-∪-isBooleanAlgebra = BA.∧-∨-isBooleanAlgebra ∪-∩-booleanAlgebra |
| 746 |
|
| 747 |
∩-∪-booleanAlgebra : BooleanAlgebra _ _ |
| 748 |
∩-∪-booleanAlgebra = BA.∧-∨-booleanAlgebra ∪-∩-booleanAlgebra |
| 749 |
|
| 750 |
p⊆p∪q : ∀ (q : Subset n) → p ⊆ p ∪ q |
| 751 |
p⊆p∪q (s ∷ q) here = here |
| 752 |
p⊆p∪q (s ∷ q) (there x∈p) = there (p⊆p∪q q x∈p) |
| 753 |
|
| 754 |
q⊆p∪q : ∀ (p q : Subset n) → q ⊆ p ∪ q |
| 755 |
q⊆p∪q p q rewrite ∪-comm p q = p⊆p∪q p |
| 756 |
|
| 757 |
x∈p∪q⁻ : ∀ (p q : Subset n) → x ∈ p ∪ q → x ∈ p ⊎ x ∈ q |
| 758 |
x∈p∪q⁻ (inside ∷ p) (t ∷ q) here = inj₁ here |
| 759 |
x∈p∪q⁻ (outside ∷ p) (inside ∷ q) here = inj₂ here |
| 760 |
x∈p∪q⁻ (s ∷ p) (t ∷ q) (there x∈p∪q) = |
| 761 |
Sum.map there there (x∈p∪q⁻ p q x∈p∪q) |
| 762 |
|
| 763 |
x∈p∪q⁺ : x ∈ p ⊎ x ∈ q → x ∈ p ∪ q |
| 764 |
x∈p∪q⁺ (inj₁ x∈p) = p⊆p∪q _ x∈p |
| 765 |
x∈p∪q⁺ (inj₂ x∈q) = q⊆p∪q _ _ x∈q |
| 766 |
|
| 767 |
∪⇔⊎ : x ∈ p ∪ q ⇔ (x ∈ p ⊎ x ∈ q) |
| 768 |
∪⇔⊎ = mk⇔ (x∈p∪q⁻ _ _) x∈p∪q⁺ |
| 769 |
|
| 770 |
∣p∣≤∣p∪q∣ : ∀ (p q : Subset n) → ∣ p ∣ ≤ ∣ p ∪ q ∣ |
| 771 |
∣p∣≤∣p∪q∣ p q = p⊆q⇒∣p∣≤∣q∣ (p⊆p∪q {p = p} q) |
| 772 |
|
| 773 |
∣q∣≤∣p∪q∣ : ∀ (p q : Subset n) → ∣ q ∣ ≤ ∣ p ∪ q ∣ |
| 774 |
∣q∣≤∣p∪q∣ p q = p⊆q⇒∣p∣≤∣q∣ (q⊆p∪q p q) |
| 775 |
|
| 776 |
∣p∣⊔∣q∣≤∣p∪q∣ : ∀ (p q : Subset n) → ∣ p ∣ ⊔ ∣ q ∣ ≤ ∣ p ∪ q ∣ |
| 777 |
∣p∣⊔∣q∣≤∣p∪q∣ p q = ℕ.⊔-lub (∣p∣≤∣p∪q∣ p q) (∣q∣≤∣p∪q∣ p q) |
| 778 |
|
| 779 |
------------------------------------------------------------------------ |
| 780 |
-- Properties of _─_ |
| 781 |
|
| 782 |
p─⊥≡p : ∀ (p : Subset n) → p ─ ⊥ ≡ p |
| 783 |
p─⊥≡p [] = refl |
| 784 |
p─⊥≡p (x ∷ p) = cong (x ∷_) (p─⊥≡p p) |
| 785 |
|
| 786 |
p─⊤≡⊥ : ∀ (p : Subset n) → p ─ ⊤ ≡ ⊥ |
| 787 |
p─⊤≡⊥ [] = refl |
| 788 |
p─⊤≡⊥ (x ∷ p) = cong (outside ∷_) (p─⊤≡⊥ p) |
| 789 |
|
| 790 |
p─q─r≡p─q∪r : ∀ (p q r : Subset n) → p ─ q ─ r ≡ p ─ (q ∪ r) |
| 791 |
p─q─r≡p─q∪r [] [] [] = refl |
| 792 |
p─q─r≡p─q∪r (x ∷ p) (outside ∷ q) (outside ∷ r) = cong (x ∷_) (p─q─r≡p─q∪r p q r) |
| 793 |
p─q─r≡p─q∪r (x ∷ p) (inside ∷ q) (outside ∷ r) = cong (outside ∷_) (p─q─r≡p─q∪r p q r) |
| 794 |
p─q─r≡p─q∪r (x ∷ p) (outside ∷ q) (inside ∷ r) = cong (outside ∷_) (p─q─r≡p─q∪r p q r) |
| 795 |
p─q─r≡p─q∪r (x ∷ p) (inside ∷ q) (inside ∷ r) = cong (outside ∷_) (p─q─r≡p─q∪r p q r) |
| 796 |
|
| 797 |
p─q─q≡p─q : ∀ (p q : Subset n) → p ─ q ─ q ≡ p ─ q |
| 798 |
p─q─q≡p─q p q = begin |
| 799 |
p ─ q ─ q ≡⟨ p─q─r≡p─q∪r p q q ⟩ |
| 800 |
p ─ q ∪ q ≡⟨ cong (p ─_) (∪-idem q) ⟩ |
| 801 |
p ─ q ∎ |
| 802 |
where open ≡-Reasoning |
| 803 |
|
| 804 |
p─q─r≡p─r─q : ∀ (p q r : Subset n) → p ─ q ─ r ≡ p ─ r ─ q |
| 805 |
p─q─r≡p─r─q p q r = begin |
| 806 |
(p ─ q) ─ r ≡⟨ p─q─r≡p─q∪r p q r ⟩ |
| 807 |
p ─ (q ∪ r) ≡⟨ cong (p ─_) (∪-comm q r) ⟩ |
| 808 |
p ─ (r ∪ q) ≡⟨ p─q─r≡p─q∪r p r q ⟨ |
| 809 |
(p ─ r) ─ q ∎ |
| 810 |
where open ≡-Reasoning |
| 811 |
|
| 812 |
x∈p∧x∉q⇒x∈p─q : x ∈ p → x ∉ q → x ∈ p ─ q |
| 813 |
x∈p∧x∉q⇒x∈p─q {q = outside ∷ q} here i∉q = here |
| 814 |
x∈p∧x∉q⇒x∈p─q {q = inside ∷ q} here i∉q = contradiction here i∉q |
| 815 |
x∈p∧x∉q⇒x∈p─q {q = outside ∷ q} (there i∈p) i∉q = there (x∈p∧x∉q⇒x∈p─q i∈p (i∉q ∘ there)) |
| 816 |
x∈p∧x∉q⇒x∈p─q {q = inside ∷ q} (there i∈p) i∉q = there (x∈p∧x∉q⇒x∈p─q i∈p (i∉q ∘ there)) |
| 817 |
|
| 818 |
p─q⊆p : ∀ (p q : Subset n) → p ─ q ⊆ p |
| 819 |
p─q⊆p (inside ∷ p) (outside ∷ q) here = here |
| 820 |
p─q⊆p (inside ∷ p) (outside ∷ q) (there x∈p) = there (p─q⊆p p q x∈p) |
| 821 |
p─q⊆p (outside ∷ p) (outside ∷ q) (there x∈p) = there (p─q⊆p p q x∈p) |
| 822 |
p─q⊆p (_ ∷ p) (inside ∷ q) (there x∈p) = there (p─q⊆p p q x∈p) |
| 823 |
|
| 824 |
p∩q≢∅⇒p─q⊂p : ∀ (p q : Subset n) → Nonempty (p ∩ q) → p ─ q ⊂ p |
| 825 |
p∩q≢∅⇒p─q⊂p (inside ∷ p) (inside ∷ q) (zero , here) = out⊂in (p─q⊆p p q) |
| 826 |
p∩q≢∅⇒p─q⊂p (x ∷ p) (inside ∷ q) (suc i , there i∈p∩q) = out⊂ (p∩q≢∅⇒p─q⊂p p q (i , i∈p∩q)) |
| 827 |
p∩q≢∅⇒p─q⊂p (outside ∷ p) (outside ∷ q) (suc i , there i∈p∩q) = out⊂ (p∩q≢∅⇒p─q⊂p p q (i , i∈p∩q)) |
| 828 |
p∩q≢∅⇒p─q⊂p (inside ∷ p) (outside ∷ q) (suc i , there i∈p∩q) = s⊂s (p∩q≢∅⇒p─q⊂p p q (i , i∈p∩q)) |
| 829 |
|
| 830 |
∣p─q∣≤∣p∣ : ∀ (p q : Subset n) → ∣ p ─ q ∣ ≤ ∣ p ∣ |
| 831 |
∣p─q∣≤∣p∣ p q = p⊆q⇒∣p∣≤∣q∣ (p─q⊆p p q) |
| 832 |
|
| 833 |
p∩q≢∅⇒∣p─q∣<∣p∣ : ∀ (p q : Subset n) → Nonempty (p ∩ q) → ∣ p ─ q ∣ < ∣ p ∣ |
| 834 |
p∩q≢∅⇒∣p─q∣<∣p∣ p q ne = p⊂q⇒∣p∣<∣q∣ (p∩q≢∅⇒p─q⊂p p q ne) |
| 835 |
|
| 836 |
------------------------------------------------------------------------ |
| 837 |
-- Properties of _-_ |
| 838 |
|
| 839 |
x∈p∧x≢y⇒x∈p-y : x ∈ p → x ≢ y → x ∈ p - y |
| 840 |
x∈p∧x≢y⇒x∈p-y x∈p x≢y = x∈p∧x∉q⇒x∈p─q x∈p (x≢y⇒x∉⁅y⁆ x≢y) |
| 841 |
|
| 842 |
p─x─y≡p─y─x : ∀ (p : Subset n) x y → p - x - y ≡ p - y - x |
| 843 |
p─x─y≡p─y─x p x y = p─q─r≡p─r─q p ⁅ x ⁆ ⁅ y ⁆ |
| 844 |
|
| 845 |
x∈p⇒p-x⊂p : x ∈ p → p - x ⊂ p |
| 846 |
x∈p⇒p-x⊂p {n} {x} {p} x∈p = p∩q≢∅⇒p─q⊂p p ⁅ x ⁆ (x , x∈p∩q⁺ (x∈p , x∈⁅x⁆ x)) |
| 847 |
|
| 848 |
x∈p⇒∣p-x∣<∣p∣ : x ∈ p → ∣ p - x ∣ < ∣ p ∣ |
| 849 |
x∈p⇒∣p-x∣<∣p∣ x∈p = p⊂q⇒∣p∣<∣q∣ (x∈p⇒p-x⊂p x∈p) |
| 850 |
|
| 851 |
------------------------------------------------------------------------ |
| 852 |
-- Lift |
| 853 |
|
| 854 |
Lift? : ∀ {P : Pred (Fin n) ℓ} → Decidable P → Decidable (Lift P) |
| 855 |
Lift? P? p = decFinSubset (_∈? p) (λ {x} _ → P? x) |
| 856 |
|
| 857 |
------------------------------------------------------------------------ |
| 858 |
-- Other |
| 859 |
|
| 860 |
module _ {P : Pred (Subset 0) ℓ} where |
| 861 |
|
| 862 |
∃-Subset-zero : ∃⟨ P ⟩ → P [] |
| 863 |
∃-Subset-zero ([] , P[]) = P[] |
| 864 |
|
| 865 |
∃-Subset-[]-⇔ : P [] ⇔ ∃⟨ P ⟩ |
| 866 |
∃-Subset-[]-⇔ = mk⇔ ([] ,_) ∃-Subset-zero |
| 867 |
|
| 868 |
module _ {P : Pred (Subset (suc n)) ℓ} where |
| 869 |
|
| 870 |
∃-Subset-suc : ∃⟨ P ⟩ → ∃⟨ P ∘ (inside ∷_) ⟩ ⊎ ∃⟨ P ∘ (outside ∷_) ⟩ |
| 871 |
∃-Subset-suc (outside ∷ p , Pop) = inj₂ (p , Pop) |
| 872 |
∃-Subset-suc ( inside ∷ p , Pip) = inj₁ (p , Pip) |
| 873 |
|
| 874 |
∃-Subset-∷-⇔ : (∃⟨ P ∘ (inside ∷_) ⟩ ⊎ ∃⟨ P ∘ (outside ∷_) ⟩) ⇔ ∃⟨ P ⟩ |
| 875 |
∃-Subset-∷-⇔ = mk⇔ |
| 876 |
[ Product.map _ id , Product.map _ id ]′ |
| 877 |
∃-Subset-suc |
| 878 |
|
| 879 |
anySubset? : ∀ {P : Pred (Subset n) ℓ} → Decidable P → Dec ∃⟨ P ⟩ |
| 880 |
anySubset? {n = zero} P? = Dec.map ∃-Subset-[]-⇔ (P? []) |
| 881 |
anySubset? {n = suc n} P? = Dec.map ∃-Subset-∷-⇔ |
| 882 |
(anySubset? (P? ∘ (inside ∷_)) ⊎-dec anySubset? (P? ∘ (outside ∷_))) |
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
------------------------------------------------------------------------ |
| 887 |
-- DEPRECATED NAMES |
| 888 |
------------------------------------------------------------------------ |
| 889 |
-- Please use the new names as continuing support for the old names is |
| 890 |
-- not guaranteed. |
| 891 |
|
| 892 |
-- Version 1.3 |
| 893 |
|
| 894 |
p⊆q⇒∣p∣<∣q∣ = p⊆q⇒∣p∣≤∣q∣ |
| 895 |
{-# WARNING_ON_USAGE p⊆q⇒∣p∣<∣q∣ |
| 896 |
"Warning: p⊆q⇒∣p∣<∣q∣ was deprecated in v1.3. |
| 897 |
Please use p⊆q⇒∣p∣≤∣q∣ instead." |
| 898 |
#-} |