| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Some derivable properties of Boolean algebras |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
open import Algebra.Lattice.Bundles |
| 10 |
|
| 11 |
module Algebra.Lattice.Properties.BooleanAlgebra |
| 12 |
{b₁ b₂} (B : BooleanAlgebra b₁ b₂) |
| 13 |
where |
| 14 |
|
| 15 |
open BooleanAlgebra B |
| 16 |
|
| 17 |
import Algebra.Lattice.Properties.DistributiveLattice as DistribLatticeProperties |
| 18 |
open import Algebra.Core using (Op₁; Op₂) |
| 19 |
open import Algebra.Structures _≈_ |
| 20 |
open import Algebra.Definitions _≈_ |
| 21 |
open import Algebra.Consequences.Setoid setoid |
| 22 |
open import Algebra.Bundles using (CommutativeSemiring; CommutativeRing) |
| 23 |
open import Algebra.Lattice.Structures _≈_ |
| 24 |
open import Relation.Binary.Reasoning.Setoid setoid |
| 25 |
open import Function.Base using (id; _$_; _⟨_⟩_) |
| 26 |
open import Function.Bundles using (_⇔_; module Equivalence) |
| 27 |
open import Data.Product.Base using (_,_) |
| 28 |
|
| 29 |
------------------------------------------------------------------------ |
| 30 |
-- Export properties from distributive lattices |
| 31 |
|
| 32 |
open DistribLatticeProperties distributiveLattice public |
| 33 |
|
| 34 |
------------------------------------------------------------------------ |
| 35 |
-- The dual construction is also a boolean algebra |
| 36 |
|
| 37 |
∧-∨-isBooleanAlgebra : IsBooleanAlgebra _∧_ _∨_ ¬_ ⊥ ⊤ |
| 38 |
∧-∨-isBooleanAlgebra = record |
| 39 |
{ isDistributiveLattice = ∧-∨-isDistributiveLattice |
| 40 |
; ∨-complement = ∧-complement |
| 41 |
; ∧-complement = ∨-complement |
| 42 |
; ¬-cong = ¬-cong |
| 43 |
} |
| 44 |
|
| 45 |
∧-∨-booleanAlgebra : BooleanAlgebra _ _ |
| 46 |
∧-∨-booleanAlgebra = record |
| 47 |
{ isBooleanAlgebra = ∧-∨-isBooleanAlgebra |
| 48 |
} |
| 49 |
|
| 50 |
------------------------------------------------------------------------ |
| 51 |
-- (∨, ∧, ⊥, ⊤) and (∧, ∨, ⊤, ⊥) are commutative semirings |
| 52 |
|
| 53 |
∧-identityʳ : RightIdentity ⊤ _∧_ |
| 54 |
∧-identityʳ x = begin |
| 55 |
x ∧ ⊤ ≈⟨ ∧-congˡ (sym (∨-complementʳ _)) ⟩ |
| 56 |
x ∧ (x ∨ ¬ x) ≈⟨ ∧-absorbs-∨ _ _ ⟩ |
| 57 |
x ∎ |
| 58 |
|
| 59 |
∧-identityˡ : LeftIdentity ⊤ _∧_ |
| 60 |
∧-identityˡ = comm∧idʳ⇒idˡ ∧-comm ∧-identityʳ |
| 61 |
|
| 62 |
∧-identity : Identity ⊤ _∧_ |
| 63 |
∧-identity = ∧-identityˡ , ∧-identityʳ |
| 64 |
|
| 65 |
∨-identityʳ : RightIdentity ⊥ _∨_ |
| 66 |
∨-identityʳ x = begin |
| 67 |
x ∨ ⊥ ≈⟨ ∨-congˡ $ sym (∧-complementʳ _) ⟩ |
| 68 |
x ∨ x ∧ ¬ x ≈⟨ ∨-absorbs-∧ _ _ ⟩ |
| 69 |
x ∎ |
| 70 |
|
| 71 |
∨-identityˡ : LeftIdentity ⊥ _∨_ |
| 72 |
∨-identityˡ = comm∧idʳ⇒idˡ ∨-comm ∨-identityʳ |
| 73 |
|
| 74 |
∨-identity : Identity ⊥ _∨_ |
| 75 |
∨-identity = ∨-identityˡ , ∨-identityʳ |
| 76 |
|
| 77 |
∧-zeroʳ : RightZero ⊥ _∧_ |
| 78 |
∧-zeroʳ x = begin |
| 79 |
x ∧ ⊥ ≈⟨ ∧-congˡ (∧-complementʳ x) ⟨ |
| 80 |
x ∧ x ∧ ¬ x ≈⟨ ∧-assoc x x (¬ x) ⟨ |
| 81 |
(x ∧ x) ∧ ¬ x ≈⟨ ∧-congʳ (∧-idem x) ⟩ |
| 82 |
x ∧ ¬ x ≈⟨ ∧-complementʳ x ⟩ |
| 83 |
⊥ ∎ |
| 84 |
|
| 85 |
∧-zeroˡ : LeftZero ⊥ _∧_ |
| 86 |
∧-zeroˡ = comm∧zeʳ⇒zeˡ ∧-comm ∧-zeroʳ |
| 87 |
|
| 88 |
∧-zero : Zero ⊥ _∧_ |
| 89 |
∧-zero = ∧-zeroˡ , ∧-zeroʳ |
| 90 |
|
| 91 |
∨-zeroʳ : ∀ x → x ∨ ⊤ ≈ ⊤ |
| 92 |
∨-zeroʳ x = begin |
| 93 |
x ∨ ⊤ ≈⟨ ∨-congˡ (∨-complementʳ x) ⟨ |
| 94 |
x ∨ x ∨ ¬ x ≈⟨ ∨-assoc x x (¬ x) ⟨ |
| 95 |
(x ∨ x) ∨ ¬ x ≈⟨ ∨-congʳ (∨-idem x) ⟩ |
| 96 |
x ∨ ¬ x ≈⟨ ∨-complementʳ x ⟩ |
| 97 |
⊤ ∎ |
| 98 |
|
| 99 |
∨-zeroˡ : LeftZero ⊤ _∨_ |
| 100 |
∨-zeroˡ = comm∧zeʳ⇒zeˡ ∨-comm ∨-zeroʳ |
| 101 |
|
| 102 |
∨-zero : Zero ⊤ _∨_ |
| 103 |
∨-zero = ∨-zeroˡ , ∨-zeroʳ |
| 104 |
|
| 105 |
∨-⊥-isMonoid : IsMonoid _∨_ ⊥ |
| 106 |
∨-⊥-isMonoid = record |
| 107 |
{ isSemigroup = ∨-isSemigroup |
| 108 |
; identity = ∨-identity |
| 109 |
} |
| 110 |
|
| 111 |
∧-⊤-isMonoid : IsMonoid _∧_ ⊤ |
| 112 |
∧-⊤-isMonoid = record |
| 113 |
{ isSemigroup = ∧-isSemigroup |
| 114 |
; identity = ∧-identity |
| 115 |
} |
| 116 |
|
| 117 |
∨-⊥-isCommutativeMonoid : IsCommutativeMonoid _∨_ ⊥ |
| 118 |
∨-⊥-isCommutativeMonoid = record |
| 119 |
{ isMonoid = ∨-⊥-isMonoid |
| 120 |
; comm = ∨-comm |
| 121 |
} |
| 122 |
|
| 123 |
∧-⊤-isCommutativeMonoid : IsCommutativeMonoid _∧_ ⊤ |
| 124 |
∧-⊤-isCommutativeMonoid = record |
| 125 |
{ isMonoid = ∧-⊤-isMonoid |
| 126 |
; comm = ∧-comm |
| 127 |
} |
| 128 |
|
| 129 |
∨-∧-isSemiring : IsSemiring _∨_ _∧_ ⊥ ⊤ |
| 130 |
∨-∧-isSemiring = record |
| 131 |
{ isSemiringWithoutAnnihilatingZero = record |
| 132 |
{ +-isCommutativeMonoid = ∨-⊥-isCommutativeMonoid |
| 133 |
; *-cong = ∧-cong |
| 134 |
; *-assoc = ∧-assoc |
| 135 |
; *-identity = ∧-identity |
| 136 |
; distrib = ∧-distrib-∨ |
| 137 |
} |
| 138 |
; zero = ∧-zero |
| 139 |
} |
| 140 |
|
| 141 |
∧-∨-isSemiring : IsSemiring _∧_ _∨_ ⊤ ⊥ |
| 142 |
∧-∨-isSemiring = record |
| 143 |
{ isSemiringWithoutAnnihilatingZero = record |
| 144 |
{ +-isCommutativeMonoid = ∧-⊤-isCommutativeMonoid |
| 145 |
; *-cong = ∨-cong |
| 146 |
; *-assoc = ∨-assoc |
| 147 |
; *-identity = ∨-identity |
| 148 |
; distrib = ∨-distrib-∧ |
| 149 |
} |
| 150 |
; zero = ∨-zero |
| 151 |
} |
| 152 |
|
| 153 |
∨-∧-isCommutativeSemiring : IsCommutativeSemiring _∨_ _∧_ ⊥ ⊤ |
| 154 |
∨-∧-isCommutativeSemiring = record |
| 155 |
{ isSemiring = ∨-∧-isSemiring |
| 156 |
; *-comm = ∧-comm |
| 157 |
} |
| 158 |
|
| 159 |
∧-∨-isCommutativeSemiring : IsCommutativeSemiring _∧_ _∨_ ⊤ ⊥ |
| 160 |
∧-∨-isCommutativeSemiring = record |
| 161 |
{ isSemiring = ∧-∨-isSemiring |
| 162 |
; *-comm = ∨-comm |
| 163 |
} |
| 164 |
|
| 165 |
∨-∧-commutativeSemiring : CommutativeSemiring _ _ |
| 166 |
∨-∧-commutativeSemiring = record |
| 167 |
{ isCommutativeSemiring = ∨-∧-isCommutativeSemiring |
| 168 |
} |
| 169 |
|
| 170 |
∧-∨-commutativeSemiring : CommutativeSemiring _ _ |
| 171 |
∧-∨-commutativeSemiring = record |
| 172 |
{ isCommutativeSemiring = ∧-∨-isCommutativeSemiring |
| 173 |
} |
| 174 |
|
| 175 |
------------------------------------------------------------------------ |
| 176 |
-- Some other properties |
| 177 |
|
| 178 |
-- I took the statement of this lemma (called Uniqueness of |
| 179 |
-- Complements) from some course notes, "Boolean Algebra", written |
| 180 |
-- by Gert Smolka. |
| 181 |
|
| 182 |
private |
| 183 |
lemma : ∀ x y → x ∧ y ≈ ⊥ → x ∨ y ≈ ⊤ → ¬ x ≈ y |
| 184 |
lemma x y x∧y=⊥ x∨y=⊤ = begin |
| 185 |
¬ x ≈⟨ ∧-identityʳ _ ⟨ |
| 186 |
¬ x ∧ ⊤ ≈⟨ ∧-congˡ x∨y=⊤ ⟨ |
| 187 |
¬ x ∧ (x ∨ y) ≈⟨ ∧-distribˡ-∨ _ _ _ ⟩ |
| 188 |
¬ x ∧ x ∨ ¬ x ∧ y ≈⟨ ∨-congʳ $ ∧-complementˡ _ ⟩ |
| 189 |
⊥ ∨ ¬ x ∧ y ≈⟨ ∨-congʳ x∧y=⊥ ⟨ |
| 190 |
x ∧ y ∨ ¬ x ∧ y ≈⟨ ∧-distribʳ-∨ _ _ _ ⟨ |
| 191 |
(x ∨ ¬ x) ∧ y ≈⟨ ∧-congʳ $ ∨-complementʳ _ ⟩ |
| 192 |
⊤ ∧ y ≈⟨ ∧-identityˡ _ ⟩ |
| 193 |
y ∎ |
| 194 |
|
| 195 |
¬⊥≈⊤ : ¬ ⊥ ≈ ⊤ |
| 196 |
¬⊥≈⊤ = lemma ⊥ ⊤ (∧-identityʳ _) (∨-zeroʳ _) |
| 197 |
|
| 198 |
¬⊤≈⊥ : ¬ ⊤ ≈ ⊥ |
| 199 |
¬⊤≈⊥ = lemma ⊤ ⊥ (∧-zeroʳ _) (∨-identityʳ _) |
| 200 |
|
| 201 |
¬-involutive : Involutive ¬_ |
| 202 |
¬-involutive x = lemma (¬ x) x (∧-complementˡ _) (∨-complementˡ _) |
| 203 |
|
| 204 |
deMorgan₁ : ∀ x y → ¬ (x ∧ y) ≈ ¬ x ∨ ¬ y |
| 205 |
deMorgan₁ x y = lemma (x ∧ y) (¬ x ∨ ¬ y) lem₁ lem₂ |
| 206 |
where |
| 207 |
lem₁ = begin |
| 208 |
(x ∧ y) ∧ (¬ x ∨ ¬ y) ≈⟨ ∧-distribˡ-∨ _ _ _ ⟩ |
| 209 |
(x ∧ y) ∧ ¬ x ∨ (x ∧ y) ∧ ¬ y ≈⟨ ∨-congʳ $ ∧-congʳ $ ∧-comm _ _ ⟩ |
| 210 |
(y ∧ x) ∧ ¬ x ∨ (x ∧ y) ∧ ¬ y ≈⟨ ∧-assoc _ _ _ ⟨ ∨-cong ⟩ ∧-assoc _ _ _ ⟩ |
| 211 |
y ∧ (x ∧ ¬ x) ∨ x ∧ (y ∧ ¬ y) ≈⟨ (∧-congˡ $ ∧-complementʳ _) ⟨ ∨-cong ⟩ |
| 212 |
(∧-congˡ $ ∧-complementʳ _) ⟩ |
| 213 |
(y ∧ ⊥) ∨ (x ∧ ⊥) ≈⟨ ∧-zeroʳ _ ⟨ ∨-cong ⟩ ∧-zeroʳ _ ⟩ |
| 214 |
⊥ ∨ ⊥ ≈⟨ ∨-identityʳ _ ⟩ |
| 215 |
⊥ ∎ |
| 216 |
|
| 217 |
lem₃ = begin |
| 218 |
(x ∧ y) ∨ ¬ x ≈⟨ ∨-distribʳ-∧ _ _ _ ⟩ |
| 219 |
(x ∨ ¬ x) ∧ (y ∨ ¬ x) ≈⟨ ∧-congʳ $ ∨-complementʳ _ ⟩ |
| 220 |
⊤ ∧ (y ∨ ¬ x) ≈⟨ ∧-identityˡ _ ⟩ |
| 221 |
y ∨ ¬ x ≈⟨ ∨-comm _ _ ⟩ |
| 222 |
¬ x ∨ y ∎ |
| 223 |
|
| 224 |
lem₂ = begin |
| 225 |
(x ∧ y) ∨ (¬ x ∨ ¬ y) ≈⟨ ∨-assoc _ _ _ ⟨ |
| 226 |
((x ∧ y) ∨ ¬ x) ∨ ¬ y ≈⟨ ∨-congʳ lem₃ ⟩ |
| 227 |
(¬ x ∨ y) ∨ ¬ y ≈⟨ ∨-assoc _ _ _ ⟩ |
| 228 |
¬ x ∨ (y ∨ ¬ y) ≈⟨ ∨-congˡ $ ∨-complementʳ _ ⟩ |
| 229 |
¬ x ∨ ⊤ ≈⟨ ∨-zeroʳ _ ⟩ |
| 230 |
⊤ ∎ |
| 231 |
|
| 232 |
deMorgan₂ : ∀ x y → ¬ (x ∨ y) ≈ ¬ x ∧ ¬ y |
| 233 |
deMorgan₂ x y = begin |
| 234 |
¬ (x ∨ y) ≈⟨ ¬-cong $ ((¬-involutive _) ⟨ ∨-cong ⟩ (¬-involutive _)) ⟨ |
| 235 |
¬ (¬ ¬ x ∨ ¬ ¬ y) ≈⟨ ¬-cong $ deMorgan₁ _ _ ⟨ |
| 236 |
¬ ¬ (¬ x ∧ ¬ y) ≈⟨ ¬-involutive _ ⟩ |
| 237 |
¬ x ∧ ¬ y ∎ |
| 238 |
|
| 239 |
------------------------------------------------------------------------ |
| 240 |
-- (⊕, ∧, id, ⊥, ⊤) is a commutative ring |
| 241 |
|
| 242 |
-- This construction is parameterised over the definition of xor. |
| 243 |
|
| 244 |
module XorRing |
| 245 |
(xor : Op₂ Carrier) |
| 246 |
(⊕-def : ∀ x y → xor x y ≈ (x ∨ y) ∧ ¬ (x ∧ y)) |
| 247 |
where |
| 248 |
|
| 249 |
private |
| 250 |
infixl 6 _⊕_ |
| 251 |
|
| 252 |
_⊕_ : Op₂ Carrier |
| 253 |
_⊕_ = xor |
| 254 |
|
| 255 |
helper : ∀ {x y u v} → x ≈ y → u ≈ v → x ∧ ¬ u ≈ y ∧ ¬ v |
| 256 |
helper x≈y u≈v = x≈y ⟨ ∧-cong ⟩ ¬-cong u≈v |
| 257 |
|
| 258 |
⊕-cong : Congruent₂ _⊕_ |
| 259 |
⊕-cong {x} {y} {u} {v} x≈y u≈v = begin |
| 260 |
x ⊕ u ≈⟨ ⊕-def _ _ ⟩ |
| 261 |
(x ∨ u) ∧ ¬ (x ∧ u) ≈⟨ helper (x≈y ⟨ ∨-cong ⟩ u≈v) |
| 262 |
(x≈y ⟨ ∧-cong ⟩ u≈v) ⟩ |
| 263 |
(y ∨ v) ∧ ¬ (y ∧ v) ≈⟨ ⊕-def _ _ ⟨ |
| 264 |
y ⊕ v ∎ |
| 265 |
|
| 266 |
⊕-comm : Commutative _⊕_ |
| 267 |
⊕-comm x y = begin |
| 268 |
x ⊕ y ≈⟨ ⊕-def _ _ ⟩ |
| 269 |
(x ∨ y) ∧ ¬ (x ∧ y) ≈⟨ helper (∨-comm _ _) (∧-comm _ _) ⟩ |
| 270 |
(y ∨ x) ∧ ¬ (y ∧ x) ≈⟨ ⊕-def _ _ ⟨ |
| 271 |
y ⊕ x ∎ |
| 272 |
|
| 273 |
¬-distribˡ-⊕ : ∀ x y → ¬ (x ⊕ y) ≈ ¬ x ⊕ y |
| 274 |
¬-distribˡ-⊕ x y = begin |
| 275 |
¬ (x ⊕ y) ≈⟨ ¬-cong $ ⊕-def _ _ ⟩ |
| 276 |
¬ ((x ∨ y) ∧ (¬ (x ∧ y))) ≈⟨ ¬-cong (∧-distribʳ-∨ _ _ _) ⟩ |
| 277 |
¬ ((x ∧ ¬ (x ∧ y)) ∨ (y ∧ ¬ (x ∧ y))) ≈⟨ ¬-cong $ ∨-congˡ $ ∧-congˡ $ ¬-cong (∧-comm _ _) ⟩ |
| 278 |
¬ ((x ∧ ¬ (x ∧ y)) ∨ (y ∧ ¬ (y ∧ x))) ≈⟨ ¬-cong $ lem _ _ ⟨ ∨-cong ⟩ lem _ _ ⟩ |
| 279 |
¬ ((x ∧ ¬ y) ∨ (y ∧ ¬ x)) ≈⟨ deMorgan₂ _ _ ⟩ |
| 280 |
¬ (x ∧ ¬ y) ∧ ¬ (y ∧ ¬ x) ≈⟨ ∧-congʳ $ deMorgan₁ _ _ ⟩ |
| 281 |
(¬ x ∨ (¬ ¬ y)) ∧ ¬ (y ∧ ¬ x) ≈⟨ helper (∨-congˡ $ ¬-involutive _) (∧-comm _ _) ⟩ |
| 282 |
(¬ x ∨ y) ∧ ¬ (¬ x ∧ y) ≈⟨ ⊕-def _ _ ⟨ |
| 283 |
¬ x ⊕ y ∎ |
| 284 |
where |
| 285 |
lem : ∀ x y → x ∧ ¬ (x ∧ y) ≈ x ∧ ¬ y |
| 286 |
lem x y = begin |
| 287 |
x ∧ ¬ (x ∧ y) ≈⟨ ∧-congˡ $ deMorgan₁ _ _ ⟩ |
| 288 |
x ∧ (¬ x ∨ ¬ y) ≈⟨ ∧-distribˡ-∨ _ _ _ ⟩ |
| 289 |
(x ∧ ¬ x) ∨ (x ∧ ¬ y) ≈⟨ ∨-congʳ $ ∧-complementʳ _ ⟩ |
| 290 |
⊥ ∨ (x ∧ ¬ y) ≈⟨ ∨-identityˡ _ ⟩ |
| 291 |
x ∧ ¬ y ∎ |
| 292 |
|
| 293 |
¬-distribʳ-⊕ : ∀ x y → ¬ (x ⊕ y) ≈ x ⊕ ¬ y |
| 294 |
¬-distribʳ-⊕ x y = begin |
| 295 |
¬ (x ⊕ y) ≈⟨ ¬-cong $ ⊕-comm _ _ ⟩ |
| 296 |
¬ (y ⊕ x) ≈⟨ ¬-distribˡ-⊕ _ _ ⟩ |
| 297 |
¬ y ⊕ x ≈⟨ ⊕-comm _ _ ⟩ |
| 298 |
x ⊕ ¬ y ∎ |
| 299 |
|
| 300 |
⊕-annihilates-¬ : ∀ x y → x ⊕ y ≈ ¬ x ⊕ ¬ y |
| 301 |
⊕-annihilates-¬ x y = begin |
| 302 |
x ⊕ y ≈⟨ ¬-involutive _ ⟨ |
| 303 |
¬ ¬ (x ⊕ y) ≈⟨ ¬-cong $ ¬-distribˡ-⊕ _ _ ⟩ |
| 304 |
¬ (¬ x ⊕ y) ≈⟨ ¬-distribʳ-⊕ _ _ ⟩ |
| 305 |
¬ x ⊕ ¬ y ∎ |
| 306 |
|
| 307 |
⊕-identityˡ : LeftIdentity ⊥ _⊕_ |
| 308 |
⊕-identityˡ x = begin |
| 309 |
⊥ ⊕ x ≈⟨ ⊕-def _ _ ⟩ |
| 310 |
(⊥ ∨ x) ∧ ¬ (⊥ ∧ x) ≈⟨ helper (∨-identityˡ _) (∧-zeroˡ _) ⟩ |
| 311 |
x ∧ ¬ ⊥ ≈⟨ ∧-congˡ ¬⊥≈⊤ ⟩ |
| 312 |
x ∧ ⊤ ≈⟨ ∧-identityʳ _ ⟩ |
| 313 |
x ∎ |
| 314 |
|
| 315 |
⊕-identityʳ : RightIdentity ⊥ _⊕_ |
| 316 |
⊕-identityʳ _ = ⊕-comm _ _ ⟨ trans ⟩ ⊕-identityˡ _ |
| 317 |
|
| 318 |
⊕-identity : Identity ⊥ _⊕_ |
| 319 |
⊕-identity = ⊕-identityˡ , ⊕-identityʳ |
| 320 |
|
| 321 |
⊕-inverseˡ : LeftInverse ⊥ id _⊕_ |
| 322 |
⊕-inverseˡ x = begin |
| 323 |
x ⊕ x ≈⟨ ⊕-def _ _ ⟩ |
| 324 |
(x ∨ x) ∧ ¬ (x ∧ x) ≈⟨ helper (∨-idem _) (∧-idem _) ⟩ |
| 325 |
x ∧ ¬ x ≈⟨ ∧-complementʳ _ ⟩ |
| 326 |
⊥ ∎ |
| 327 |
|
| 328 |
⊕-inverseʳ : RightInverse ⊥ id _⊕_ |
| 329 |
⊕-inverseʳ _ = ⊕-comm _ _ ⟨ trans ⟩ ⊕-inverseˡ _ |
| 330 |
|
| 331 |
⊕-inverse : Inverse ⊥ id _⊕_ |
| 332 |
⊕-inverse = ⊕-inverseˡ , ⊕-inverseʳ |
| 333 |
|
| 334 |
∧-distribˡ-⊕ : _∧_ DistributesOverˡ _⊕_ |
| 335 |
∧-distribˡ-⊕ x y z = begin |
| 336 |
x ∧ (y ⊕ z) ≈⟨ ∧-congˡ $ ⊕-def _ _ ⟩ |
| 337 |
x ∧ ((y ∨ z) ∧ ¬ (y ∧ z)) ≈⟨ ∧-assoc _ _ _ ⟨ |
| 338 |
(x ∧ (y ∨ z)) ∧ ¬ (y ∧ z) ≈⟨ ∧-congˡ $ deMorgan₁ _ _ ⟩ |
| 339 |
(x ∧ (y ∨ z)) ∧ |
| 340 |
(¬ y ∨ ¬ z) ≈⟨ ∨-identityˡ _ ⟨ |
| 341 |
⊥ ∨ |
| 342 |
((x ∧ (y ∨ z)) ∧ |
| 343 |
(¬ y ∨ ¬ z)) ≈⟨ ∨-congʳ lem₃ ⟩ |
| 344 |
((x ∧ (y ∨ z)) ∧ ¬ x) ∨ |
| 345 |
((x ∧ (y ∨ z)) ∧ |
| 346 |
(¬ y ∨ ¬ z)) ≈⟨ ∧-distribˡ-∨ _ _ _ ⟨ |
| 347 |
(x ∧ (y ∨ z)) ∧ |
| 348 |
(¬ x ∨ (¬ y ∨ ¬ z)) ≈⟨ ∧-congˡ $ ∨-congˡ (deMorgan₁ _ _) ⟨ |
| 349 |
(x ∧ (y ∨ z)) ∧ |
| 350 |
(¬ x ∨ ¬ (y ∧ z)) ≈⟨ ∧-congˡ (deMorgan₁ _ _) ⟨ |
| 351 |
(x ∧ (y ∨ z)) ∧ |
| 352 |
¬ (x ∧ (y ∧ z)) ≈⟨ helper refl lem₁ ⟩ |
| 353 |
(x ∧ (y ∨ z)) ∧ |
| 354 |
¬ ((x ∧ y) ∧ (x ∧ z)) ≈⟨ ∧-congʳ $ ∧-distribˡ-∨ _ _ _ ⟩ |
| 355 |
((x ∧ y) ∨ (x ∧ z)) ∧ |
| 356 |
¬ ((x ∧ y) ∧ (x ∧ z)) ≈⟨ ⊕-def _ _ ⟨ |
| 357 |
(x ∧ y) ⊕ (x ∧ z) ∎ |
| 358 |
where |
| 359 |
lem₂ = begin |
| 360 |
x ∧ (y ∧ z) ≈⟨ ∧-assoc _ _ _ ⟨ |
| 361 |
(x ∧ y) ∧ z ≈⟨ ∧-congʳ $ ∧-comm _ _ ⟩ |
| 362 |
(y ∧ x) ∧ z ≈⟨ ∧-assoc _ _ _ ⟩ |
| 363 |
y ∧ (x ∧ z) ∎ |
| 364 |
|
| 365 |
lem₁ = begin |
| 366 |
x ∧ (y ∧ z) ≈⟨ ∧-congʳ (∧-idem _) ⟨ |
| 367 |
(x ∧ x) ∧ (y ∧ z) ≈⟨ ∧-assoc _ _ _ ⟩ |
| 368 |
x ∧ (x ∧ (y ∧ z)) ≈⟨ ∧-congˡ lem₂ ⟩ |
| 369 |
x ∧ (y ∧ (x ∧ z)) ≈⟨ ∧-assoc _ _ _ ⟨ |
| 370 |
(x ∧ y) ∧ (x ∧ z) ∎ |
| 371 |
|
| 372 |
lem₃ = begin |
| 373 |
⊥ ≈⟨ ∧-zeroʳ _ ⟨ |
| 374 |
(y ∨ z) ∧ ⊥ ≈⟨ ∧-congˡ (∧-complementʳ _) ⟨ |
| 375 |
(y ∨ z) ∧ (x ∧ ¬ x) ≈⟨ ∧-assoc _ _ _ ⟨ |
| 376 |
((y ∨ z) ∧ x) ∧ ¬ x ≈⟨ ∧-congʳ (∧-comm _ _) ⟩ |
| 377 |
(x ∧ (y ∨ z)) ∧ ¬ x ∎ |
| 378 |
|
| 379 |
∧-distribʳ-⊕ : _∧_ DistributesOverʳ _⊕_ |
| 380 |
∧-distribʳ-⊕ = comm∧distrˡ⇒distrʳ ⊕-cong ∧-comm ∧-distribˡ-⊕ |
| 381 |
|
| 382 |
∧-distrib-⊕ : _∧_ DistributesOver _⊕_ |
| 383 |
∧-distrib-⊕ = ∧-distribˡ-⊕ , ∧-distribʳ-⊕ |
| 384 |
|
| 385 |
private |
| 386 |
|
| 387 |
lemma₂ : ∀ x y u v → |
| 388 |
(x ∧ y) ∨ (u ∧ v) ≈ |
| 389 |
((x ∨ u) ∧ (y ∨ u)) ∧ |
| 390 |
((x ∨ v) ∧ (y ∨ v)) |
| 391 |
lemma₂ x y u v = begin |
| 392 |
(x ∧ y) ∨ (u ∧ v) ≈⟨ ∨-distribˡ-∧ _ _ _ ⟩ |
| 393 |
((x ∧ y) ∨ u) ∧ ((x ∧ y) ∨ v) ≈⟨ ∨-distribʳ-∧ _ _ _ |
| 394 |
⟨ ∧-cong ⟩ |
| 395 |
∨-distribʳ-∧ _ _ _ ⟩ |
| 396 |
((x ∨ u) ∧ (y ∨ u)) ∧ |
| 397 |
((x ∨ v) ∧ (y ∨ v)) ∎ |
| 398 |
|
| 399 |
⊕-assoc : Associative _⊕_ |
| 400 |
⊕-assoc x y z = sym $ begin |
| 401 |
x ⊕ (y ⊕ z) ≈⟨ ⊕-cong refl (⊕-def _ _) ⟩ |
| 402 |
x ⊕ ((y ∨ z) ∧ ¬ (y ∧ z)) ≈⟨ ⊕-def _ _ ⟩ |
| 403 |
(x ∨ ((y ∨ z) ∧ ¬ (y ∧ z))) ∧ |
| 404 |
¬ (x ∧ ((y ∨ z) ∧ ¬ (y ∧ z))) ≈⟨ ∧-cong lem₃ lem₄ ⟩ |
| 405 |
(((x ∨ y) ∨ z) ∧ ((x ∨ ¬ y) ∨ ¬ z)) ∧ |
| 406 |
(((¬ x ∨ ¬ y) ∨ z) ∧ ((¬ x ∨ y) ∨ ¬ z)) ≈⟨ ∧-assoc _ _ _ ⟩ |
| 407 |
((x ∨ y) ∨ z) ∧ |
| 408 |
(((x ∨ ¬ y) ∨ ¬ z) ∧ |
| 409 |
(((¬ x ∨ ¬ y) ∨ z) ∧ ((¬ x ∨ y) ∨ ¬ z))) ≈⟨ ∧-congˡ lem₅ ⟩ |
| 410 |
((x ∨ y) ∨ z) ∧ |
| 411 |
(((¬ x ∨ ¬ y) ∨ z) ∧ |
| 412 |
(((x ∨ ¬ y) ∨ ¬ z) ∧ ((¬ x ∨ y) ∨ ¬ z))) ≈⟨ ∧-assoc _ _ _ ⟨ |
| 413 |
(((x ∨ y) ∨ z) ∧ ((¬ x ∨ ¬ y) ∨ z)) ∧ |
| 414 |
(((x ∨ ¬ y) ∨ ¬ z) ∧ ((¬ x ∨ y) ∨ ¬ z)) ≈⟨ ∧-cong lem₁ lem₂ ⟩ |
| 415 |
(((x ∨ y) ∧ ¬ (x ∧ y)) ∨ z) ∧ |
| 416 |
¬ (((x ∨ y) ∧ ¬ (x ∧ y)) ∧ z) ≈⟨ ⊕-def _ _ ⟨ |
| 417 |
((x ∨ y) ∧ ¬ (x ∧ y)) ⊕ z ≈⟨ ⊕-cong (⊕-def _ _) refl ⟨ |
| 418 |
(x ⊕ y) ⊕ z ∎ |
| 419 |
where |
| 420 |
lem₁ = begin |
| 421 |
((x ∨ y) ∨ z) ∧ ((¬ x ∨ ¬ y) ∨ z) ≈⟨ ∨-distribʳ-∧ _ _ _ ⟨ |
| 422 |
((x ∨ y) ∧ (¬ x ∨ ¬ y)) ∨ z ≈⟨ ∨-congʳ $ ∧-congˡ (deMorgan₁ _ _) ⟨ |
| 423 |
((x ∨ y) ∧ ¬ (x ∧ y)) ∨ z ∎ |
| 424 |
|
| 425 |
lem₂′ = begin |
| 426 |
(x ∨ ¬ y) ∧ (¬ x ∨ y) ≈⟨ ∧-cong (∧-identityˡ _) (∧-identityʳ _) ⟨ |
| 427 |
(⊤ ∧ (x ∨ ¬ y)) ∧ ((¬ x ∨ y) ∧ ⊤) ≈⟨ ∧-cong |
| 428 |
(∧-cong (∨-complementˡ _) (∨-comm _ _)) |
| 429 |
(∧-congˡ $ ∨-complementˡ _) ⟨ |
| 430 |
((¬ x ∨ x) ∧ (¬ y ∨ x)) ∧ |
| 431 |
((¬ x ∨ y) ∧ (¬ y ∨ y)) ≈⟨ lemma₂ _ _ _ _ ⟨ |
| 432 |
(¬ x ∧ ¬ y) ∨ (x ∧ y) ≈⟨ ∨-cong (deMorgan₂ _ _) (¬-involutive _) ⟨ |
| 433 |
¬ (x ∨ y) ∨ ¬ ¬ (x ∧ y) ≈⟨ deMorgan₁ _ _ ⟨ |
| 434 |
¬ ((x ∨ y) ∧ ¬ (x ∧ y)) ∎ |
| 435 |
|
| 436 |
lem₂ = begin |
| 437 |
((x ∨ ¬ y) ∨ ¬ z) ∧ ((¬ x ∨ y) ∨ ¬ z) ≈⟨ ∨-distribʳ-∧ _ _ _ ⟨ |
| 438 |
((x ∨ ¬ y) ∧ (¬ x ∨ y)) ∨ ¬ z ≈⟨ ∨-congʳ lem₂′ ⟩ |
| 439 |
¬ ((x ∨ y) ∧ ¬ (x ∧ y)) ∨ ¬ z ≈⟨ deMorgan₁ _ _ ⟨ |
| 440 |
¬ (((x ∨ y) ∧ ¬ (x ∧ y)) ∧ z) ∎ |
| 441 |
|
| 442 |
lem₃ = begin |
| 443 |
x ∨ ((y ∨ z) ∧ ¬ (y ∧ z)) ≈⟨ ∨-congˡ $ ∧-congˡ $ deMorgan₁ _ _ ⟩ |
| 444 |
x ∨ ((y ∨ z) ∧ (¬ y ∨ ¬ z)) ≈⟨ ∨-distribˡ-∧ _ _ _ ⟩ |
| 445 |
(x ∨ (y ∨ z)) ∧ (x ∨ (¬ y ∨ ¬ z)) ≈⟨ ∨-assoc _ _ _ ⟨ ∧-cong ⟩ ∨-assoc _ _ _ ⟨ |
| 446 |
((x ∨ y) ∨ z) ∧ ((x ∨ ¬ y) ∨ ¬ z) ∎ |
| 447 |
|
| 448 |
lem₄′ = begin |
| 449 |
¬ ((y ∨ z) ∧ ¬ (y ∧ z)) ≈⟨ deMorgan₁ _ _ ⟩ |
| 450 |
¬ (y ∨ z) ∨ ¬ ¬ (y ∧ z) ≈⟨ deMorgan₂ _ _ ⟨ ∨-cong ⟩ ¬-involutive _ ⟩ |
| 451 |
(¬ y ∧ ¬ z) ∨ (y ∧ z) ≈⟨ lemma₂ _ _ _ _ ⟩ |
| 452 |
((¬ y ∨ y) ∧ (¬ z ∨ y)) ∧ |
| 453 |
((¬ y ∨ z) ∧ (¬ z ∨ z)) ≈⟨ (∨-complementˡ _ ⟨ ∧-cong ⟩ ∨-comm _ _) |
| 454 |
⟨ ∧-cong ⟩ |
| 455 |
(∧-congˡ $ ∨-complementˡ _) ⟩ |
| 456 |
(⊤ ∧ (y ∨ ¬ z)) ∧ |
| 457 |
((¬ y ∨ z) ∧ ⊤) ≈⟨ ∧-identityˡ _ ⟨ ∧-cong ⟩ ∧-identityʳ _ ⟩ |
| 458 |
(y ∨ ¬ z) ∧ (¬ y ∨ z) ∎ |
| 459 |
|
| 460 |
lem₄ = begin |
| 461 |
¬ (x ∧ ((y ∨ z) ∧ ¬ (y ∧ z))) ≈⟨ deMorgan₁ _ _ ⟩ |
| 462 |
¬ x ∨ ¬ ((y ∨ z) ∧ ¬ (y ∧ z)) ≈⟨ ∨-congˡ lem₄′ ⟩ |
| 463 |
¬ x ∨ ((y ∨ ¬ z) ∧ (¬ y ∨ z)) ≈⟨ ∨-distribˡ-∧ _ _ _ ⟩ |
| 464 |
(¬ x ∨ (y ∨ ¬ z)) ∧ |
| 465 |
(¬ x ∨ (¬ y ∨ z)) ≈⟨ ∨-assoc _ _ _ ⟨ ∧-cong ⟩ ∨-assoc _ _ _ ⟨ |
| 466 |
((¬ x ∨ y) ∨ ¬ z) ∧ |
| 467 |
((¬ x ∨ ¬ y) ∨ z) ≈⟨ ∧-comm _ _ ⟩ |
| 468 |
((¬ x ∨ ¬ y) ∨ z) ∧ |
| 469 |
((¬ x ∨ y) ∨ ¬ z) ∎ |
| 470 |
|
| 471 |
lem₅ = begin |
| 472 |
((x ∨ ¬ y) ∨ ¬ z) ∧ |
| 473 |
(((¬ x ∨ ¬ y) ∨ z) ∧ ((¬ x ∨ y) ∨ ¬ z)) ≈⟨ ∧-assoc _ _ _ ⟨ |
| 474 |
(((x ∨ ¬ y) ∨ ¬ z) ∧ ((¬ x ∨ ¬ y) ∨ z)) ∧ |
| 475 |
((¬ x ∨ y) ∨ ¬ z) ≈⟨ ∧-congʳ $ ∧-comm _ _ ⟩ |
| 476 |
(((¬ x ∨ ¬ y) ∨ z) ∧ ((x ∨ ¬ y) ∨ ¬ z)) ∧ |
| 477 |
((¬ x ∨ y) ∨ ¬ z) ≈⟨ ∧-assoc _ _ _ ⟩ |
| 478 |
((¬ x ∨ ¬ y) ∨ z) ∧ |
| 479 |
(((x ∨ ¬ y) ∨ ¬ z) ∧ ((¬ x ∨ y) ∨ ¬ z)) ∎ |
| 480 |
|
| 481 |
⊕-isMagma : IsMagma _⊕_ |
| 482 |
⊕-isMagma = record |
| 483 |
{ isEquivalence = isEquivalence |
| 484 |
; ∙-cong = ⊕-cong |
| 485 |
} |
| 486 |
|
| 487 |
⊕-isSemigroup : IsSemigroup _⊕_ |
| 488 |
⊕-isSemigroup = record |
| 489 |
{ isMagma = ⊕-isMagma |
| 490 |
; assoc = ⊕-assoc |
| 491 |
} |
| 492 |
|
| 493 |
⊕-⊥-isMonoid : IsMonoid _⊕_ ⊥ |
| 494 |
⊕-⊥-isMonoid = record |
| 495 |
{ isSemigroup = ⊕-isSemigroup |
| 496 |
; identity = ⊕-identity |
| 497 |
} |
| 498 |
|
| 499 |
⊕-⊥-isGroup : IsGroup _⊕_ ⊥ id |
| 500 |
⊕-⊥-isGroup = record |
| 501 |
{ isMonoid = ⊕-⊥-isMonoid |
| 502 |
; inverse = ⊕-inverse |
| 503 |
; ⁻¹-cong = id |
| 504 |
} |
| 505 |
|
| 506 |
⊕-⊥-isAbelianGroup : IsAbelianGroup _⊕_ ⊥ id |
| 507 |
⊕-⊥-isAbelianGroup = record |
| 508 |
{ isGroup = ⊕-⊥-isGroup |
| 509 |
; comm = ⊕-comm |
| 510 |
} |
| 511 |
|
| 512 |
⊕-∧-isRing : IsRing _⊕_ _∧_ id ⊥ ⊤ |
| 513 |
⊕-∧-isRing = record |
| 514 |
{ +-isAbelianGroup = ⊕-⊥-isAbelianGroup |
| 515 |
; *-cong = ∧-cong |
| 516 |
; *-assoc = ∧-assoc |
| 517 |
; *-identity = ∧-identity |
| 518 |
; distrib = ∧-distrib-⊕ |
| 519 |
} |
| 520 |
|
| 521 |
⊕-∧-isCommutativeRing : IsCommutativeRing _⊕_ _∧_ id ⊥ ⊤ |
| 522 |
⊕-∧-isCommutativeRing = record |
| 523 |
{ isRing = ⊕-∧-isRing |
| 524 |
; *-comm = ∧-comm |
| 525 |
} |
| 526 |
|
| 527 |
⊕-∧-commutativeRing : CommutativeRing _ _ |
| 528 |
⊕-∧-commutativeRing = record |
| 529 |
{ isCommutativeRing = ⊕-∧-isCommutativeRing |
| 530 |
} |
| 531 |
|
| 532 |
|
| 533 |
infixl 6 _⊕_ |
| 534 |
|
| 535 |
_⊕_ : Op₂ Carrier |
| 536 |
x ⊕ y = (x ∨ y) ∧ ¬ (x ∧ y) |
| 537 |
|
| 538 |
module DefaultXorRing = XorRing _⊕_ (λ _ _ → refl) |
| 539 |
|
| 540 |
|
| 541 |
------------------------------------------------------------------------ |
| 542 |
-- DEPRECATED NAMES |
| 543 |
------------------------------------------------------------------------ |
| 544 |
-- Please use the new names as continuing support for the old names is |
| 545 |
-- not guaranteed. |
| 546 |
|
| 547 |
-- Version 2.3 |
| 548 |
|
| 549 |
⊥≉⊤ = ¬⊥≈⊤ |
| 550 |
{-# WARNING_ON_USAGE ⊥≉⊤ |
| 551 |
"Warning: ⊥≉⊤ was deprecated in v2.3. |
| 552 |
Please use ¬⊥≈⊤ instead." |
| 553 |
#-} |
| 554 |
⊤≉⊥ = ¬⊤≈⊥ |
| 555 |
{-# WARNING_ON_USAGE ⊤≉⊥ |
| 556 |
"Warning: ⊤≉⊥ was deprecated in v2.3. |
| 557 |
Please use ¬⊤≈⊥ instead." |
| 558 |
#-} |