Skip to content

[ add ] BooleanRing plus Properties #2763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7c198cc
add: `BooleanRing` plus `Properties`
jamesmckinna Jul 10, 2025
b219c5e
Update CHANGELOG.md
jamesmckinna Jul 10, 2025
3e5cc88
refactor: more general API
jamesmckinna Jul 11, 2025
9684d71
fix: added note to `CHANGELOG`
jamesmckinna Jul 11, 2025
0f2f44e
refactor: make binomial expansion an explicit step
jamesmckinna Jul 11, 2025
0aff0d9
rename: `*-isIdempotentMonoid`
jamesmckinna Jul 14, 2025
ca6aff1
add: `*-idempotentMonoid`
jamesmckinna Jul 14, 2025
a4b6010
refactor: use `Cancellative` properties only
jamesmckinna Jul 14, 2025
9e3d63b
add: stub properties for `CommutativeRing`
jamesmckinna Jul 15, 2025
0e26669
refactor: `BooleanRing` properties in terms of `CommutativeRing` and …
jamesmckinna Jul 15, 2025
5792887
refactor: put everything together
jamesmckinna Jul 15, 2025
e355a3f
add: stub properties for `CommutativeRing`
jamesmckinna Jul 15, 2025
81d140c
refactor: adjust re-exports
jamesmckinna Jul 15, 2025
a1b4086
add: `BooleanAlgebra` yields `BooleanRing` etc.
jamesmckinna Jul 16, 2025
6a675c0
add: more re-exports
jamesmckinna Jul 17, 2025
a7f4c45
add: more inherited properties
jamesmckinna Jul 17, 2025
fa28407
add: more properties towards `IsBooleanAlgebra`
jamesmckinna Jul 17, 2025
4c1fbc0
add: yet more properties towards `IsBooleanAlgebra`
jamesmckinna Jul 17, 2025
763cac5
add: grinding towards `IsBooleanAlgebra`
jamesmckinna Jul 17, 2025
f10a36b
add: `deMorgan` laws
jamesmckinna Jul 18, 2025
e082ea7
add: `Semiring` properties as home for `binomial-expansion`
jamesmckinna Jul 18, 2025
2d59a88
more fiddling
jamesmckinna Jul 18, 2025
bfc54b2
back to square one
jamesmckinna Jul 18, 2025
94d1b19
fix: finally!
jamesmckinna Jul 18, 2025
0414331
Merge branch 'master' into boolean-ring
jamesmckinna Jul 18, 2025
a9a28a9
fix: remove shadowing of `isBooleanRing` and `booleanRing`
jamesmckinna Jul 18, 2025
05f07f9
reset: `CHANGELOG` for v2.4
jamesmckinna Jul 20, 2025
bccabf6
Merge branch 'master' into boolean-ring
jamesmckinna Jul 20, 2025
79a4ca0
fix: whitespace
jamesmckinna Jul 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,45 @@ Deprecated names
New modules
-----------

* `Algebra.Properties.BooleanRing`.

* `Algebra.Properties.BooleanSemiring`.

* `Algebra.Properties.CommutativeRing`.

* `Algebra.Properties.Semiring`.

Additions to existing modules
-----------------------------

* In `Algebra.Bundles`:
```agda
record BooleanSemiring _ _ : Set _
record BooleanRing _ _ : Set _
```

* In `Algebra.Consequences.Propositional`:
```agda
binomial-expansion : Associative _∙_ → _◦_ DistributesOver _∙_ →
∀ w x y z → ((w ∙ x) ◦ (y ∙ z)) ≡ ((((w ◦ y) ∙ (w ◦ z)) ∙ (x ◦ y)) ∙ (x ◦ z))
```

* In `Algebra.Consequences.Setoid`:
```agda
binomial-expansion : Congruent₂ _∙_ → Associative _∙_ → _◦_ DistributesOver _∙_ →
∀ w x y z → ((w ∙ x) ◦ (y ∙ z)) ≈ ((((w ◦ y) ∙ (w ◦ z)) ∙ (x ◦ y)) ∙ (x ◦ z))
```

* In `Algebra.Lattice.Properties.BooleanAlgebra.XorRing`:
```agda
⊕-∧-isBooleanRing : IsBooleanRing _⊕_ _∧_ id ⊥ ⊤
⊕-∧-booleanRing : BooleanRing _ _
```

* In `Algebra.Structures`:
```agda
record IsBooleanSemiring + * 0# 1# : Set _
record IsBooleanRing + * - 0# 1# : Set _
```
NB. the latter is based on `IsCommutativeRing`, with the former on `IsSemiring`.

81 changes: 80 additions & 1 deletion src/Algebra/Bundles.agda
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,41 @@ record Quasiring c ℓ : Set (suc (c ⊔ ℓ)) where
; rawMonoid to *-rawMonoid
)

record BooleanSemiring c ℓ : Set (suc (c ⊔ ℓ)) where
infixl 7 _*_
infixl 6 _+_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_+_ : Op₂ Carrier
_*_ : Op₂ Carrier
0# : Carrier
1# : Carrier
isBooleanSemiring : IsBooleanSemiring _≈_ _+_ _*_ 0# 1#

open IsBooleanSemiring isBooleanSemiring public

semiring : Semiring _ _
semiring = record { isSemiring = isSemiring }

open Semiring semiring public
using ( _≉_; +-rawMagma; +-magma; +-unitalMagma; +-commutativeMagma
; +-semigroup; +-commutativeSemigroup
; *-rawMagma; *-magma; *-semigroup
; +-rawMonoid; +-monoid; +-commutativeMonoid
; *-rawMonoid; *-monoid
; rawNearSemiring ; rawSemiring; nearSemiring
; semiringWithoutOne; semiringWithoutAnnihilatingZero
)

*-idempotentMonoid : IdempotentMonoid c ℓ
*-idempotentMonoid = record { isIdempotentMonoid = *-isIdempotentMonoid }

open IdempotentMonoid *-idempotentMonoid public
using () renaming (band to *-band)


------------------------------------------------------------------------
-- Bundles with 2 binary operations, 1 unary operation & 1 element
------------------------------------------------------------------------
Expand Down Expand Up @@ -1106,7 +1141,10 @@ record CommutativeRing c ℓ : Set (suc (c ⊔ ℓ)) where
ring : Ring _ _
ring = record { isRing = isRing }

open Ring ring public using (_≉_; rawRing; +-invertibleMagma; +-invertibleUnitalMagma; +-group; +-abelianGroup)
open Ring ring public
using (_≉_; rawRing
; +-invertibleMagma; +-invertibleUnitalMagma
; +-group; +-abelianGroup)

commutativeSemiring : CommutativeSemiring _ _
commutativeSemiring =
Expand All @@ -1124,6 +1162,47 @@ record CommutativeRing c ℓ : Set (suc (c ⊔ ℓ)) where
; commutativeSemiringWithoutOne
)


record BooleanRing c ℓ : Set (suc (c ⊔ ℓ)) where
infix 8 -_
infixl 7 _*_
infixl 6 _+_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_+_ : Op₂ Carrier
_*_ : Op₂ Carrier
-_ : Op₁ Carrier
0# : Carrier
1# : Carrier
isBooleanRing : IsBooleanRing _≈_ _+_ _*_ -_ 0# 1#

open IsBooleanRing isBooleanRing public
using (isCommutativeRing; *-idem)

open IsCommutativeRing isCommutativeRing public

commutativeRing : CommutativeRing _ _
commutativeRing = record { isCommutativeRing = isCommutativeRing }

open CommutativeRing commutativeRing public
using
(_≉_; rawRing
; +-invertibleMagma; +-invertibleUnitalMagma
; +-group; +-abelianGroup
; +-rawMagma; +-magma; +-unitalMagma; +-commutativeMagma
; +-semigroup; +-commutativeSemigroup
; *-rawMagma; *-magma; *-commutativeMagma; *-semigroup; *-commutativeSemigroup
; +-rawMonoid; +-monoid; +-commutativeMonoid
; *-rawMonoid; *-monoid; *-commutativeMonoid
; nearSemiring; semiringWithoutOne
; semiringWithoutAnnihilatingZero; semiring
; commutativeSemiringWithoutOne; commutativeSemiring
; ring
)


------------------------------------------------------------------------
-- Bundles with 3 binary operations
------------------------------------------------------------------------
Expand Down
10 changes: 10 additions & 0 deletions src/Algebra/Consequences/Propositional.agda
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ open Base public
; subst∧comm⇒sym
; wlog
; sel⇒idem
; binomial-expansion
-- plus all the deprecated versions of the above
; comm+assoc⇒middleFour
; identity+middleFour⇒assoc
Expand Down Expand Up @@ -101,6 +102,15 @@ module _ {_∙_ _◦_ : Op₂ A} (∙-comm : Commutative _∙_) where
comm⇒sym[distribˡ] : ∀ x → Symmetric (λ y z → (x ◦ (y ∙ z)) ≡ ((x ◦ y) ∙ (x ◦ z)))
comm⇒sym[distribˡ] = Base.comm⇒sym[distribˡ] (cong₂ _◦_) ∙-comm

module _ {_∙_ _◦_ : Op₂ A}
(∙-assoc : Associative _∙_)
(distrib : _◦_ DistributesOver _∙_)
where

binomial-expansion : ∀ w x y z →
((w ∙ x) ◦ (y ∙ z)) ≡ ((((w ◦ y) ∙ (w ◦ z)) ∙ (x ◦ y)) ∙ (x ◦ z))
binomial-expansion = Base.binomial-expansion {_∙_} {_◦_} (cong₂ _) ∙-assoc distrib

------------------------------------------------------------------------
-- Selectivity

Expand Down
15 changes: 15 additions & 0 deletions src/Algebra/Consequences/Setoid.agda
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,21 @@ module _ {_∙_ _◦_ : Op₂ A}
(x ◦ (x ∙ z)) ∙ (y ◦ (x ∙ z)) ≈⟨ ◦-distribʳ-∙ _ _ _ ⟨
(x ∙ y) ◦ (x ∙ z) ∎

module _ {_∙_ _◦_ : Op₂ A}
(∙-cong : Congruent₂ _∙_)
(∙-assoc : Associative _∙_)
(distrib@(distribˡ , distribʳ) : _◦_ DistributesOver _∙_)
where

binomial-expansion : ∀ w x y z →
((w ∙ x) ◦ (y ∙ z)) ≈ ((((w ◦ y) ∙ (w ◦ z)) ∙ (x ◦ y)) ∙ (x ◦ z))
binomial-expansion w x y z = begin
(w ∙ x) ◦ (y ∙ z) ≈⟨ distribʳ _ _ _ ⟩
(w ◦ (y ∙ z)) ∙ (x ◦ (y ∙ z)) ≈⟨ ∙-cong (distribˡ _ _ _) (distribˡ _ _ _) ⟩
((w ◦ y) ∙ (w ◦ z)) ∙ ((x ◦ y) ∙ (x ◦ z)) ≈⟨ ∙-assoc _ _ _ ⟨
(((w ◦ y) ∙ (w ◦ z)) ∙ (x ◦ y)) ∙ (x ◦ z) ∎


------------------------------------------------------------------------
-- Ring-like structures

Expand Down
27 changes: 17 additions & 10 deletions src/Algebra/Lattice/Properties/BooleanAlgebra.agda
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,31 @@

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

open import Algebra.Lattice.Bundles
open import Algebra.Lattice.Bundles using (BooleanAlgebra)

module Algebra.Lattice.Properties.BooleanAlgebra
{b₁ b₂} (B : BooleanAlgebra b₁ b₂)
{c ℓ} (booleanAlgebra : BooleanAlgebra c ℓ)
where

open BooleanAlgebra B
open import Algebra.Bundles
using (CommutativeSemiring; CommutativeRing; BooleanRing)
open import Algebra.Core using (Op₂)
open import Data.Product.Base using (_,_)
open import Function.Base using (id; _$_; _⟨_⟩_)
open import Function.Bundles using (_⇔_; module Equivalence)

import Algebra.Lattice.Properties.DistributiveLattice as DistribLatticeProperties
open import Algebra.Core using (Op₁; Op₂)
open BooleanAlgebra booleanAlgebra
open import Algebra.Structures _≈_
open import Algebra.Definitions _≈_
open import Algebra.Consequences.Setoid setoid
open import Algebra.Bundles using (CommutativeSemiring; CommutativeRing)
open import Algebra.Lattice.Structures _≈_
open import Relation.Binary.Reasoning.Setoid setoid
open import Function.Base using (id; _$_; _⟨_⟩_)
open import Function.Bundles using (_⇔_; module Equivalence)
open import Data.Product.Base using (_,_)


------------------------------------------------------------------------
-- Export properties from distributive lattices

open DistribLatticeProperties distributiveLattice public
open import Algebra.Lattice.Properties.DistributiveLattice distributiveLattice public

------------------------------------------------------------------------
-- The dual construction is also a boolean algebra
Expand Down Expand Up @@ -529,6 +530,12 @@ module XorRing
{ isCommutativeRing = ⊕-∧-isCommutativeRing
}

⊕-∧-isBooleanRing : IsBooleanRing _⊕_ _∧_ id ⊥ ⊤
⊕-∧-isBooleanRing = record
{ isCommutativeRing = ⊕-∧-isCommutativeRing ; *-idem = ∧-idem }

⊕-∧-booleanRing : BooleanRing _ _
⊕-∧-booleanRing = record { isBooleanRing = ⊕-∧-isBooleanRing }

infixl 6 _⊕_

Expand Down
61 changes: 61 additions & 0 deletions src/Algebra/Properties/BooleanRing.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some basic properties of Boolean Rings
------------------------------------------------------------------------

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

open import Algebra.Bundles
using (CommutativeRing; BooleanSemiring; BooleanRing)

module Algebra.Properties.BooleanRing
{c ℓ} (booleanRing : BooleanRing c ℓ) where

open import Function.Base using (_∘_)
open import Data.Product.Base using (_,_)

open BooleanRing booleanRing
open import Algebra.Structures _≈_
using (IsBooleanSemiring)
open import Relation.Binary.Reasoning.Setoid setoid

------------------------------------------------------------------------
-- Re-export properties of Commutative Rings

open import Algebra.Properties.CommutativeRing commutativeRing public

------------------------------------------------------------------------
-- Structures

isBooleanSemiring : IsBooleanSemiring _+_ _*_ 0# 1#
isBooleanSemiring = record
{ isSemiring = isSemiring
; +-cancel = +-cancel
; *-idem = *-idem
}

open IsBooleanSemiring isBooleanSemiring public
using (*-isIdempotentMonoid)

------------------------------------------------------------------------
-- Bundles

booleanSemiring : BooleanSemiring _ _
booleanSemiring = record { isBooleanSemiring = isBooleanSemiring }

open BooleanSemiring booleanSemiring public
using (*-idempotentMonoid)

------------------------------------------------------------------------
-- Export properties of Boolean semirings

open import Algebra.Properties.BooleanSemiring booleanSemiring public
hiding (isBooleanRing; booleanRing)

------------------------------------------------------------------------
-- Further consequences

-x≈x : ∀ x → - x ≈ x
-x≈x = x+y≈0⇒y≈x ∘ -‿inverseʳ

Loading