Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ Deprecated names
New modules
-----------

* `Algebra.Construct.Quotient.{{Abelian}Group|Ring}` for the definition of quotient (Abelian) groups and rings.

* `Algebra.Construct.Sub.{Abelian}Group` for the definition of sub-(Abelian)groups.

* `Algebra.Construct.Sub.Group.Normal` for the definition of normal subgroups.

* `Algebra.Construct.Sub.Ring.Ideal` for the definition of ideals of a ring.

* `Algebra.Module.Construct.Sub.Bimodule` for the definition of sub-bimodules.

* `Algebra.Properties.BooleanRing`.

* `Algebra.Properties.BooleanSemiring`.
Expand Down
39 changes: 39 additions & 0 deletions src/Algebra/Construct/Quotient/AbelianGroup.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- Quotient Abelian groups
------------------------------------------------------------------------

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

open import Algebra.Bundles using (Group; AbelianGroup)
import Algebra.Construct.Sub.AbelianGroup as AbelianSubgroup
import Algebra.Construct.Quotient.Group as Quotient

module Algebra.Construct.Quotient.AbelianGroup
{c ℓ} (G : AbelianGroup c ℓ)
(open AbelianSubgroup G using (Subgroup; normalSubgroup))
{c′ ℓ′} (N : Subgroup c′ ℓ′)
where

private
module G = AbelianGroup G

-- Re-export the quotient group

open Quotient G.group (normalSubgroup N) public
hiding (_/_)

-- With its additional bundle

abelianGroup : AbelianGroup c _
abelianGroup = record
{ isAbelianGroup = record
{ isGroup = isGroup
; comm = λ g h → ≈⇒≋ (G.comm g h)
}
} where open Group group

-- Public re-exports

_/_ = abelianGroup
128 changes: 128 additions & 0 deletions src/Algebra/Construct/Quotient/Group.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- Quotient groups
------------------------------------------------------------------------

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

open import Algebra.Bundles using (Group)
open import Algebra.Construct.Sub.Group.Normal using (NormalSubgroup)

module Algebra.Construct.Quotient.Group
{c ℓ} (G : Group c ℓ) {c′ ℓ′} (N : NormalSubgroup G c′ ℓ′) where

open import Algebra.Definitions using (Congruent₁; Congruent₂)
open import Algebra.Morphism.Structures using (IsGroupHomomorphism)
open import Data.Product.Base using (_,_)
open import Function.Base using (_∘_)
open import Function.Definitions using (Surjective)
open import Level using (_⊔_)
open import Relation.Binary.Core using (_⇒_)
open import Relation.Binary.Definitions using (Reflexive; Symmetric; Transitive)

private
open module G = Group G
using (_≈_; _∙_; ε; _⁻¹)
open module N = NormalSubgroup N
using (ι; module ι; conjugate; normal)

open import Algebra.Properties.Group G using (⁻¹-anti-homo-∙)
open import Algebra.Properties.Monoid G.monoid
open import Relation.Binary.Reasoning.Setoid G.setoid

infix 0 _by_

data _≋_ (x y : G.Carrier) : Set (c ⊔ ℓ ⊔ c′) where
_by_ : ∀ g → ι g ∙ x ≈ y → x ≋ y

≈⇒≋ : _≈_ ⇒ _≋_
≈⇒≋ x≈y = N.ε by G.trans (G.∙-cong ι.ε-homo x≈y) (G.identityˡ _)

refl : Reflexive _≋_
refl = ≈⇒≋ G.refl

sym : Symmetric _≋_
sym {x} {y} (g by ιg∙x≈y) = g N.⁻¹ by begin
ι (g N.⁻¹) ∙ y ≈⟨ G.∙-cong (ι.⁻¹-homo g) (G.sym ιg∙x≈y) ⟩
ι g ⁻¹ ∙ (ι g ∙ x) ≈⟨ cancelˡ (G.inverseˡ (ι g)) x ⟩
x ∎

trans : Transitive _≋_
trans {x} {y} {z} (g by ιg∙x≈y) (h by ιh∙y≈z) = h N.∙ g by begin
ι (h N.∙ g) ∙ x ≈⟨ G.∙-congʳ (ι.∙-homo h g) ⟩
(ι h ∙ ι g) ∙ x ≈⟨ uv≈w⇒xu∙v≈xw ιg∙x≈y (ι h) ⟩
ι h ∙ y ≈⟨ ιh∙y≈z ⟩
z ∎

∙-cong : Congruent₂ _≋_ _∙_
∙-cong {x} {y} {u} {v} (g by ιg∙x≈y) (h by ιh∙u≈v) = g N.∙ h′ by begin
ι (g N.∙ h′) ∙ (x ∙ u) ≈⟨ G.∙-congʳ (ι.∙-homo g h′) ⟩
(ι g ∙ ι h′) ∙ (x ∙ u) ≈⟨ uv≈wx⇒yu∙vz≈yw∙xz (normal h x) (ι g) u ⟩
(ι g ∙ x) ∙ (ι h ∙ u) ≈⟨ G.∙-cong ιg∙x≈y ιh∙u≈v ⟩
y ∙ v ∎
where h′ = conjugate h x

⁻¹-cong : Congruent₁ _≋_ _⁻¹
⁻¹-cong {x} {y} (g by ιg∙x≈y) = h by begin
ι h ∙ x ⁻¹ ≈⟨ normal (g N.⁻¹) (x ⁻¹) ⟩
x ⁻¹ ∙ ι (g N.⁻¹) ≈⟨ G.∙-congˡ (ι.⁻¹-homo g) ⟩
x ⁻¹ ∙ ι g ⁻¹ ≈⟨ ⁻¹-anti-homo-∙ (ι g) x ⟨
(ι g ∙ x) ⁻¹ ≈⟨ G.⁻¹-cong ιg∙x≈y ⟩
y ⁻¹ ∎
where h = conjugate (g N.⁻¹) (x ⁻¹)

group : Group c (c ⊔ ℓ ⊔ c′)
group = record
{ isGroup = record
{ isMonoid = record
{ isSemigroup = record
{ isMagma = record
{ isEquivalence = record
Copy link
Contributor

@JacquesCarette JacquesCarette Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is just an experiment, but I'd certainly wish that this IsEquivalence record was pulled out.

Copy link
Contributor Author

@jamesmckinna jamesmckinna Nov 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing that impressed me about @Taneb 's code was the extent to which, in various places, it manages to produces huge nested record blocks which nevertheless 'do the right thing'.

I've flip-flopped over the years between this style, and a much more incremental, define every sub-record at top-level, put the pieces together step-by-step style, which the library has to date favoured.

One reason (perhaps two or more!) I am now turning towards the 'one big record' style arises from #2391 :

  • a single large object, suitably re-opened as public, (re-)introduces all the 'correct' substructure, moreover with the 'rectified'/'official' names, rather than trying to invent proxy names for the top-level substructure in the other style
  • when any client imports the new constructions, they aren't faced with a (DRY) choice between cherry-picking the ad-hoc names (which may be the 'correct' ones), or facing a clash/choicepoint between such names and those names introduced by open of substructures

In this instance (as perhaps elsewhere...) the definition of distinct isEquivalence : IsEquivalence ... fields at top-level is starting to emerge as an anti-pattern for me: once an Algebra.Structures.IsX object is in scope, or has been defined, then isEquivalence is available as a canonical projection from that, and indeed that should be the preferred mode-of-access (via open if necessary) for a substructure which exists solely

  • to export canonical names refl, sym, trans for the properties, and their derived forms
  • to construct Setoids from which Relation.Binary.Reasoning.Setoid syntax may then be brought into scope
  • ...

... much of which functionality/behaviour can be achieved at a higher-level of the nesting hierarchy by suitable re-organisation of the Algebra.Properties.X hierarchy #2804 #2858 etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defining every sub-record independently also gets out of hand. I've settled on an approach more 'in the middle' where some particularly re-usable records are given top-level names.

The big record always exists, so users can choose that one if that's what they want, or the big one and open it.

I guess I was thinking of the "developer API" here rather than the "user API". So I think that's where our difference of opinion comes from, we had different modes of use in mind.

This is where natural language and Agda are insufficiently precise.

{ refl = refl
; sym = sym
; trans = trans
}
; ∙-cong = ∙-cong
}
; assoc = λ x y z → ≈⇒≋ (G.assoc x y z)
}
; identity = ≈⇒≋ ∘ G.identityˡ , ≈⇒≋ ∘ G.identityʳ
}
; inverse = ≈⇒≋ ∘ G.inverseˡ , ≈⇒≋ ∘ G.inverseʳ
; ⁻¹-cong = ⁻¹-cong
}
}

private module Q = Group group

-- Public re-exports

_/_ : Group c (c ⊔ ℓ ⊔ c′)
_/_ = group

π : G.Carrier → Q.Carrier
π x = x -- because we do all the work in the relation _≋_

π-surjective : Surjective _≈_ _≋_ π
π-surjective g = g , ≈⇒≋

π-isGroupHomomorphism : IsGroupHomomorphism G.rawGroup Q.rawGroup π
π-isGroupHomomorphism = record
{ isMonoidHomomorphism = record
{ isMagmaHomomorphism = record
{ isRelHomomorphism = record
{ cong = ≈⇒≋
}
; homo = λ _ _ → Q.refl
}
; ε-homo = Q.refl
}
; ⁻¹-homo = λ _ → Q.refl
}

open IsGroupHomomorphism π-isGroupHomomorphism public
using ()
renaming (isMonoidHomomorphism to π-isMonoidHomomorphism
; isMagmaHomomorphism to π-isMagmaHomomorphism
)
77 changes: 77 additions & 0 deletions src/Algebra/Construct/Quotient/Ring.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- Quotient rings
------------------------------------------------------------------------

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

open import Algebra.Bundles using (AbelianGroup; Ring)
open import Algebra.Construct.Sub.Ring.Ideal using (Ideal)
import Algebra.Construct.Quotient.AbelianGroup as Quotient

module Algebra.Construct.Quotient.Ring
{c ℓ} (R : Ring c ℓ) {c′ ℓ′} (I : Ideal R c′ ℓ′)
where

open import Algebra.Definitions using (Congruent₂)
open import Algebra.Morphism.Structures using (IsRingHomomorphism)
open import Data.Product.Base using (_,_)
open import Function.Base using (_∘_)
open import Level using (_⊔_)

private
module R = Ring R
module I = Ideal I
module R/I = Quotient R.+-abelianGroup I.subgroup


open R/I public
using (_≋_; _by_; ≈⇒≋; π; π-isMonoidHomomorphism; π-surjective)
renaming (abelianGroup to +-abelianGroup)

*-cong : Congruent₂ _≋_ R._*_
*-cong {x} {y} {u} {v} (j by ιj+x≈y) (k by ιk+u≈v) =
ι j *ₗ k +ᴹ j *ᵣ u +ᴹ x *ₗ k by begin
ι (ι j *ₗ k +ᴹ j *ᵣ u +ᴹ x *ₗ k) + x * u ≈⟨ +-congʳ (ι.+ᴹ-homo (ι j *ₗ k +ᴹ j *ᵣ u) (x *ₗ k)) ⟩
ι (ι j *ₗ k +ᴹ j *ᵣ u) + ι (x *ₗ k) + x * u ≈⟨ +-congʳ (+-congʳ (ι.+ᴹ-homo (ι j *ₗ k) (j *ᵣ u))) ⟩
ι (ι j *ₗ k) + ι (j *ᵣ u) + ι (x *ₗ k) + x * u ≈⟨ +-congʳ (+-cong (+-cong (ι.*ₗ-homo (ι j) k) (ι.*ᵣ-homo u j)) (ι.*ₗ-homo x k)) ⟩
ι j * ι k + ι j * u + x * ι k + x * u ≈⟨ binomial-expansion (ι j) x (ι k) u ⟨
(ι j + x) * (ι k + u) ≈⟨ R.*-cong ιj+x≈y ιk+u≈v ⟩
y * v ∎
where
open R using (_+_; _*_; +-congʳ ;+-cong)
open import Algebra.Properties.Semiring R.semiring using (binomial-expansion)
open import Relation.Binary.Reasoning.Setoid R.setoid
open I using (ι; _*ₗ_; _*ᵣ_; _+ᴹ_)

ring : Ring c (c ⊔ ℓ ⊔ c′)
ring = record
{ isRing = record
{ +-isAbelianGroup = isAbelianGroup
; *-cong = *-cong
; *-assoc = λ x y z → ≈⇒≋ (R.*-assoc x y z)
; *-identity = ≈⇒≋ ∘ R.*-identityˡ , ≈⇒≋ ∘ R.*-identityʳ
; distrib = (λ x y z → ≈⇒≋ (R.distribˡ x y z)) , (λ x y z → ≈⇒≋ (R.distribʳ x y z))
}
} where open AbelianGroup +-abelianGroup using (isAbelianGroup)

private module Q = Ring ring

-- Public re-exports

_/_ : Ring c (c ⊔ ℓ ⊔ c′)
_/_ = ring

π-isRingHomomorphism : IsRingHomomorphism R.rawRing Q.rawRing π
π-isRingHomomorphism = record
{ isSemiringHomomorphism = record
{ isNearSemiringHomomorphism = record
{ +-isMonoidHomomorphism = π-isMonoidHomomorphism
; *-homo = λ _ _ → Q.refl
}
; 1#-homo = Q.refl
}
; -‿homo = λ _ → Q.refl
}

78 changes: 78 additions & 0 deletions src/Algebra/Construct/Sub/AbelianGroup.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- Subgroups of Abelian groups: necessarily Normal
--
-- This is a strict addition/extension to Nathan van Doorn (Taneb)'s PR
-- https://github.com/agda/agda-stdlib/pull/2852
-- and avoids the lemma `Algebra.NormalSubgroup.abelian⇒subgroup-normal`
-- introduced in PR https://github.com/agda/agda-stdlib/pull/2854
-- in favour of the direct definition of the field `normal` below.
------------------------------------------------------------------------

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

open import Algebra.Bundles using (AbelianGroup)

module Algebra.Construct.Sub.AbelianGroup {c ℓ} (G : AbelianGroup c ℓ) where
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is better named: it does construct an AbelianGroup out of a (normal) subgroup. This seems like it is in the right place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes (but still: sigh).


-- As with the corresponding appeal to `IsGroup` in the module
-- `Algebra.Construct.Sub.AbelianGroup`, this import drives the export
-- of the `X` bundle corresponding to the `subX` structure/bundle
-- being defined here.

open import Algebra.Morphism.GroupMonomorphism using (isAbelianGroup)

private
module G = AbelianGroup G

-- Here, we could chose simply to expose the `NormalSubgroup` definition
-- from `Algebra.Construct.Sub.Group.Normal`, but as this module will use
-- type inference to allow the creation of `NormalSubgroup`s based on their
-- `isNormal` fields alone, it makes sense also to export the type `IsNormal`.

open import Algebra.Construct.Sub.Group.Normal G.group
using (IsNormal; NormalSubgroup)

-- Re-export the notion of subgroup of the underlying Group

open import Algebra.Construct.Sub.Group G.group public
using (Subgroup)

-- Then, for any such Subgroup:
-- * it is, in fact, Normal
-- * and defines an AbelianGroup, not just a Group

module _ {c′ ℓ′} (subgroup : Subgroup c′ ℓ′) where

-- Here, we do need both the underlying function `ι` of the mono, and
-- the proof `ι-monomorphism`, in order to be able to construct an
-- `IsAbelianGroup` structure on the way to the `AbelianGroup` bundle.

open Subgroup subgroup public
using (ι; ι-monomorphism)

-- Here, we eta-contract the use of `G.comm` in defining the `normal` field.

isNormal : IsNormal subgroup
isNormal = record { normal = λ n → G.comm (ι n) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eta contract?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! In that, it is itself an eta-contraction of the original

isNormal = record { normal = λ n g  G.comm (ι n) g }

Is it harmful to have done this?

Or are you asking whether the definition could be contracted further? Perhaps, but only via one of those odd Function.Base composition operators which compose only in one argument position of an n+2-ary function, which I find obscure rather than illuminate (my point-free fu is not always as strong as it might be).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I had not noticed that this had been contracted once already! I was thinking that this would be a straightforward composition. Hmm, now I wonder if the eta expanded version isn't easier to understand!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be: but work on #2863 suggests that this, plus commutativity in the Centre constructions, might better be plumbed in by other means. Further experimentation required!


-- And the use of `record`s throughout permits this 'boilerplate' construction.

normalSubgroup : NormalSubgroup c′ ℓ′
normalSubgroup = record { isNormal = isNormal }

-- And the `public` re-export of its substructure.

open NormalSubgroup normalSubgroup public
using (conjugate; normal)

-- As with `Algebra.Construct.Sub.Group`, there seems no need to create
-- an intermediate manifest field `isAbelianGroup`, when this may be, and
-- is, obtained by opening the bundle for `public` export.

abelianGroup : AbelianGroup c′ ℓ′
abelianGroup = record
{ isAbelianGroup = isAbelianGroup ι-monomorphism G.isAbelianGroup }

open AbelianGroup abelianGroup public
Loading