Skip to content

Commit dfa5b89

Browse files
authored
[ add ] BooleanRing plus Properties (#2763)
* add: `BooleanRing` plus `Properties` * Update CHANGELOG.md Removed spurious entry * refactor: more general API * fix: added note to `CHANGELOG` * refactor: make binomial expansion an explicit step * rename: `*-isIdempotentMonoid` * add: `*-idempotentMonoid` * refactor: use `Cancellative` properties only * add: stub properties for `CommutativeRing` * refactor: `BooleanRing` properties in terms of `CommutativeRing` and `BooleanSemiring` * refactor: put everything together * add: stub properties for `CommutativeRing` * refactor: adjust re-exports * add: `BooleanAlgebra` yields `BooleanRing` etc. * add: more re-exports * add: more inherited properties * add: more properties towards `IsBooleanAlgebra` * add: yet more properties towards `IsBooleanAlgebra` * add: grinding towards `IsBooleanAlgebra` * add: `deMorgan` laws * add: `Semiring` properties as home for `binomial-expansion` * more fiddling * back to square one * fix: finally! * fix: remove shadowing of `isBooleanRing` and `booleanRing` * reset: `CHANGELOG` for v2.4 * fix: whitespace
1 parent e3e94c8 commit dfa5b89

File tree

12 files changed

+643
-25
lines changed

12 files changed

+643
-25
lines changed

CHANGELOG.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,57 @@ Deprecated names
4747
New modules
4848
-----------
4949

50+
* `Algebra.Properties.BooleanRing`.
51+
52+
* `Algebra.Properties.BooleanSemiring`.
53+
54+
* `Algebra.Properties.CommutativeRing`.
55+
56+
* `Algebra.Properties.Semiring`.
57+
5058
* `Data.List.Relation.Binary.Permutation.Algorithmic{.Properties}` for the Choudhury and Fiore definition of permutation, and its equivalence with `Declarative` below.
5159

5260
* `Data.List.Relation.Binary.Permutation.Declarative{.Properties}` for the least congruence on `List` making `_++_` commutative, and its equivalence with the `Setoid` definition.
5361

5462
Additions to existing modules
5563
-----------------------------
5664

65+
* In `Algebra.Bundles`:
66+
```agda
67+
record BooleanSemiring _ _ : Set _
68+
record BooleanRing _ _ : Set _
69+
```
70+
71+
* In `Algebra.Consequences.Propositional`:
72+
```agda
73+
binomial-expansion : Associative _∙_ → _◦_ DistributesOver _∙_ →
74+
∀ w x y z → ((w ∙ x) ◦ (y ∙ z)) ≡ ((((w ◦ y) ∙ (w ◦ z)) ∙ (x ◦ y)) ∙ (x ◦ z))
75+
```
76+
77+
* In `Algebra.Consequences.Setoid`:
78+
```agda
79+
binomial-expansion : Congruent₂ _∙_ → Associative _∙_ → _◦_ DistributesOver _∙_ →
80+
∀ w x y z → ((w ∙ x) ◦ (y ∙ z)) ≈ ((((w ◦ y) ∙ (w ◦ z)) ∙ (x ◦ y)) ∙ (x ◦ z))
81+
```
82+
83+
* In `Algebra.Lattice.Properties.BooleanAlgebra.XorRing`:
84+
```agda
85+
⊕-∧-isBooleanRing : IsBooleanRing _⊕_ _∧_ id ⊥ ⊤
86+
⊕-∧-booleanRing : BooleanRing _ _
87+
```
88+
5789
* In `Algebra.Properties.RingWithoutOne`:
5890
```agda
5991
[-x][-y]≈xy : ∀ x y → - x * - y ≈ x * y
6092
```
6193

94+
* In `Algebra.Structures`:
95+
```agda
96+
record IsBooleanSemiring + * 0# 1# : Set _
97+
record IsBooleanRing + * - 0# 1# : Set _
98+
```
99+
NB. the latter is based on `IsCommutativeRing`, with the former on `IsSemiring`.
100+
62101
* In `Data.Fin.Permutation.Components`:
63102
```agda
64103
transpose[i,i,j]≡j : (i j : Fin n) → transpose i i j ≡ j

src/Algebra/Bundles.agda

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,41 @@ record Quasiring c ℓ : Set (suc (c ⊔ ℓ)) where
921921
; rawMonoid to *-rawMonoid
922922
)
923923

924+
record BooleanSemiring c ℓ : Set (suc (c ⊔ ℓ)) where
925+
infixl 7 _*_
926+
infixl 6 _+_
927+
infix 4 _≈_
928+
field
929+
Carrier : Set c
930+
_≈_ : Rel Carrier ℓ
931+
_+_ : Op₂ Carrier
932+
_*_ : Op₂ Carrier
933+
0# : Carrier
934+
1# : Carrier
935+
isBooleanSemiring : IsBooleanSemiring _≈_ _+_ _*_ 0# 1#
936+
937+
open IsBooleanSemiring isBooleanSemiring public
938+
939+
semiring : Semiring _ _
940+
semiring = record { isSemiring = isSemiring }
941+
942+
open Semiring semiring public
943+
using ( _≉_; +-rawMagma; +-magma; +-unitalMagma; +-commutativeMagma
944+
; +-semigroup; +-commutativeSemigroup
945+
; *-rawMagma; *-magma; *-semigroup
946+
; +-rawMonoid; +-monoid; +-commutativeMonoid
947+
; *-rawMonoid; *-monoid
948+
; rawNearSemiring ; rawSemiring; nearSemiring
949+
; semiringWithoutOne; semiringWithoutAnnihilatingZero
950+
)
951+
952+
*-idempotentMonoid : IdempotentMonoid c ℓ
953+
*-idempotentMonoid = record { isIdempotentMonoid = *-isIdempotentMonoid }
954+
955+
open IdempotentMonoid *-idempotentMonoid public
956+
using () renaming (band to *-band)
957+
958+
924959
------------------------------------------------------------------------
925960
-- Bundles with 2 binary operations, 1 unary operation & 1 element
926961
------------------------------------------------------------------------
@@ -1106,7 +1141,10 @@ record CommutativeRing c ℓ : Set (suc (c ⊔ ℓ)) where
11061141
ring : Ring _ _
11071142
ring = record { isRing = isRing }
11081143

1109-
open Ring ring public using (_≉_; rawRing; +-invertibleMagma; +-invertibleUnitalMagma; +-group; +-abelianGroup)
1144+
open Ring ring public
1145+
using (_≉_; rawRing
1146+
; +-invertibleMagma; +-invertibleUnitalMagma
1147+
; +-group; +-abelianGroup)
11101148

11111149
commutativeSemiring : CommutativeSemiring _ _
11121150
commutativeSemiring =
@@ -1124,6 +1162,47 @@ record CommutativeRing c ℓ : Set (suc (c ⊔ ℓ)) where
11241162
; commutativeSemiringWithoutOne
11251163
)
11261164

1165+
1166+
record BooleanRing c ℓ : Set (suc (c ⊔ ℓ)) where
1167+
infix 8 -_
1168+
infixl 7 _*_
1169+
infixl 6 _+_
1170+
infix 4 _≈_
1171+
field
1172+
Carrier : Set c
1173+
_≈_ : Rel Carrier ℓ
1174+
_+_ : Op₂ Carrier
1175+
_*_ : Op₂ Carrier
1176+
-_ : Op₁ Carrier
1177+
0# : Carrier
1178+
1# : Carrier
1179+
isBooleanRing : IsBooleanRing _≈_ _+_ _*_ -_ 0# 1#
1180+
1181+
open IsBooleanRing isBooleanRing public
1182+
using (isCommutativeRing; *-idem)
1183+
1184+
open IsCommutativeRing isCommutativeRing public
1185+
1186+
commutativeRing : CommutativeRing _ _
1187+
commutativeRing = record { isCommutativeRing = isCommutativeRing }
1188+
1189+
open CommutativeRing commutativeRing public
1190+
using
1191+
(_≉_; rawRing
1192+
; +-invertibleMagma; +-invertibleUnitalMagma
1193+
; +-group; +-abelianGroup
1194+
; +-rawMagma; +-magma; +-unitalMagma; +-commutativeMagma
1195+
; +-semigroup; +-commutativeSemigroup
1196+
; *-rawMagma; *-magma; *-commutativeMagma; *-semigroup; *-commutativeSemigroup
1197+
; +-rawMonoid; +-monoid; +-commutativeMonoid
1198+
; *-rawMonoid; *-monoid; *-commutativeMonoid
1199+
; nearSemiring; semiringWithoutOne
1200+
; semiringWithoutAnnihilatingZero; semiring
1201+
; commutativeSemiringWithoutOne; commutativeSemiring
1202+
; ring
1203+
)
1204+
1205+
11271206
------------------------------------------------------------------------
11281207
-- Bundles with 3 binary operations
11291208
------------------------------------------------------------------------

src/Algebra/Consequences/Propositional.agda

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ open Base public
4242
; subst∧comm⇒sym
4343
; wlog
4444
; sel⇒idem
45+
; binomial-expansion
4546
-- plus all the deprecated versions of the above
4647
; comm+assoc⇒middleFour
4748
; identity+middleFour⇒assoc
@@ -101,6 +102,15 @@ module _ {_∙_ _◦_ : Op₂ A} (∙-comm : Commutative _∙_) where
101102
comm⇒sym[distribˡ] : x Symmetric (λ y z (x ◦ (y ∙ z)) ≡ ((x ◦ y) ∙ (x ◦ z)))
102103
comm⇒sym[distribˡ] = Base.comm⇒sym[distribˡ] (cong₂ _◦_) ∙-comm
103104

105+
module _ {_∙_ _◦_ : Op₂ A}
106+
(∙-assoc : Associative _∙_)
107+
(distrib : _◦_ DistributesOver _∙_)
108+
where
109+
110+
binomial-expansion : w x y z
111+
((w ∙ x) ◦ (y ∙ z)) ≡ ((((w ◦ y) ∙ (w ◦ z)) ∙ (x ◦ y)) ∙ (x ◦ z))
112+
binomial-expansion = Base.binomial-expansion {_∙_} {_◦_} (cong₂ _) ∙-assoc distrib
113+
104114
------------------------------------------------------------------------
105115
-- Selectivity
106116

src/Algebra/Consequences/Setoid.agda

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,21 @@ module _ {_∙_ _◦_ : Op₂ A}
292292
(x ◦ (x ∙ z)) ∙ (y ◦ (x ∙ z)) ≈⟨ ◦-distribʳ-∙ _ _ _ ⟨
293293
(x ∙ y) ◦ (x ∙ z) ∎
294294

295+
module _ {_∙_ _◦_ : Op₂ A}
296+
(∙-cong : Congruent₂ _∙_)
297+
(∙-assoc : Associative _∙_)
298+
(distrib@(distribˡ , distribʳ) : _◦_ DistributesOver _∙_)
299+
where
300+
301+
binomial-expansion : w x y z
302+
((w ∙ x) ◦ (y ∙ z)) ≈ ((((w ◦ y) ∙ (w ◦ z)) ∙ (x ◦ y)) ∙ (x ◦ z))
303+
binomial-expansion w x y z = begin
304+
(w ∙ x) ◦ (y ∙ z) ≈⟨ distribʳ _ _ _ ⟩
305+
(w ◦ (y ∙ z)) ∙ (x ◦ (y ∙ z)) ≈⟨ ∙-cong (distribˡ _ _ _) (distribˡ _ _ _) ⟩
306+
((w ◦ y) ∙ (w ◦ z)) ∙ ((x ◦ y) ∙ (x ◦ z)) ≈⟨ ∙-assoc _ _ _ ⟨
307+
(((w ◦ y) ∙ (w ◦ z)) ∙ (x ◦ y)) ∙ (x ◦ z) ∎
308+
309+
295310
------------------------------------------------------------------------
296311
-- Ring-like structures
297312

src/Algebra/Lattice/Properties/BooleanAlgebra.agda

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,31 @@
66

77
{-# OPTIONS --cubical-compatible --safe #-}
88

9-
open import Algebra.Lattice.Bundles
9+
open import Algebra.Lattice.Bundles using (BooleanAlgebra)
1010

1111
module Algebra.Lattice.Properties.BooleanAlgebra
12-
{b₁ b₂} (B : BooleanAlgebra b₁ b₂)
12+
{c ℓ} (booleanAlgebra : BooleanAlgebra c ℓ)
1313
where
1414

15-
open BooleanAlgebra B
15+
open import Algebra.Bundles
16+
using (CommutativeSemiring; CommutativeRing; BooleanRing)
17+
open import Algebra.Core using (Op₂)
18+
open import Data.Product.Base using (_,_)
19+
open import Function.Base using (id; _$_; _⟨_⟩_)
20+
open import Function.Bundles using (_⇔_; module Equivalence)
1621

17-
import Algebra.Lattice.Properties.DistributiveLattice as DistribLatticeProperties
18-
open import Algebra.Core using (Op₁; Op₂)
22+
open BooleanAlgebra booleanAlgebra
1923
open import Algebra.Structures _≈_
2024
open import Algebra.Definitions _≈_
2125
open import Algebra.Consequences.Setoid setoid
22-
open import Algebra.Bundles using (CommutativeSemiring; CommutativeRing)
2326
open import Algebra.Lattice.Structures _≈_
2427
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+
2829

2930
------------------------------------------------------------------------
3031
-- Export properties from distributive lattices
3132

32-
open DistribLatticeProperties distributiveLattice public
33+
open import Algebra.Lattice.Properties.DistributiveLattice distributiveLattice public
3334

3435
------------------------------------------------------------------------
3536
-- The dual construction is also a boolean algebra
@@ -529,6 +530,12 @@ module XorRing
529530
{ isCommutativeRing = ⊕-∧-isCommutativeRing
530531
}
531532

533+
⊕-∧-isBooleanRing : IsBooleanRing _⊕_ _∧_ id ⊥ ⊤
534+
⊕-∧-isBooleanRing = record
535+
{ isCommutativeRing = ⊕-∧-isCommutativeRing ; *-idem = ∧-idem }
536+
537+
⊕-∧-booleanRing : BooleanRing _ _
538+
⊕-∧-booleanRing = record { isBooleanRing = ⊕-∧-isBooleanRing }
532539

533540
infixl 6 _⊕_
534541

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Some basic properties of Boolean Rings
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --cubical-compatible --safe #-}
8+
9+
open import Algebra.Bundles
10+
using (CommutativeRing; BooleanSemiring; BooleanRing)
11+
12+
module Algebra.Properties.BooleanRing
13+
{c ℓ} (booleanRing : BooleanRing c ℓ) where
14+
15+
open import Function.Base using (_∘_)
16+
open import Data.Product.Base using (_,_)
17+
18+
open BooleanRing booleanRing
19+
open import Algebra.Structures _≈_
20+
using (IsBooleanSemiring)
21+
open import Relation.Binary.Reasoning.Setoid setoid
22+
23+
------------------------------------------------------------------------
24+
-- Re-export properties of Commutative Rings
25+
26+
open import Algebra.Properties.CommutativeRing commutativeRing public
27+
28+
------------------------------------------------------------------------
29+
-- Structures
30+
31+
isBooleanSemiring : IsBooleanSemiring _+_ _*_ 0# 1#
32+
isBooleanSemiring = record
33+
{ isSemiring = isSemiring
34+
; +-cancel = +-cancel
35+
; *-idem = *-idem
36+
}
37+
38+
open IsBooleanSemiring isBooleanSemiring public
39+
using (*-isIdempotentMonoid)
40+
41+
------------------------------------------------------------------------
42+
-- Bundles
43+
44+
booleanSemiring : BooleanSemiring _ _
45+
booleanSemiring = record { isBooleanSemiring = isBooleanSemiring }
46+
47+
open BooleanSemiring booleanSemiring public
48+
using (*-idempotentMonoid)
49+
50+
------------------------------------------------------------------------
51+
-- Export properties of Boolean semirings
52+
53+
open import Algebra.Properties.BooleanSemiring booleanSemiring public
54+
hiding (isBooleanRing; booleanRing)
55+
56+
------------------------------------------------------------------------
57+
-- Further consequences
58+
59+
-x≈x : x - x ≈ x
60+
-x≈x = x+y≈0⇒y≈x ∘ -‿inverseʳ
61+

0 commit comments

Comments
 (0)