Skip to content
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

Add Algebra.Action.* and friends #2350

Draft
wants to merge 37 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b9845ce
beginnings
jamesmckinna Apr 2, 2024
43c9fdb
factored out `MonoidAction`
jamesmckinna Apr 9, 2024
a503156
second beginning
jamesmckinna Apr 9, 2024
e2a9815
start small(er)
jamesmckinna Apr 9, 2024
d9e6bc0
`fix-whitespace`
jamesmckinna Apr 9, 2024
d7a4ceb
refactor in favour of `Pointwise` congruence
jamesmckinna Apr 11, 2024
aa6788e
begin refactoring
jamesmckinna Apr 11, 2024
48a79e5
more refactoring
jamesmckinna Apr 11, 2024
56d9902
more refactoring
jamesmckinna Apr 11, 2024
ace7e4d
factored out regular and free monoid actions
jamesmckinna Apr 11, 2024
d579e31
nearly there
jamesmckinna Apr 11, 2024
361ac24
little by little...
jamesmckinna Apr 11, 2024
160837f
`Self` just needs tidying up: `Biased` smart constructor
jamesmckinna Apr 11, 2024
8d0ed22
temp commit
jamesmckinna Apr 11, 2024
a5995f3
fixed `Free`
jamesmckinna Apr 11, 2024
0eebed1
refactored `Self`
jamesmckinna Apr 11, 2024
8be311d
`fix-whitespace`
jamesmckinna Apr 11, 2024
47a5e71
tidy up!
jamesmckinna Apr 11, 2024
364925d
some response to review comments: give up on `Raw` structures; tweak …
jamesmckinna Apr 12, 2024
110d576
fixed comment
jamesmckinna Apr 12, 2024
63ef07e
removed more qualifications
jamesmckinna Apr 12, 2024
2f2c9b9
long opening comment on naming added
jamesmckinna Apr 12, 2024
8e6b130
notation
jamesmckinna Apr 25, 2024
c0aa8b6
flip notation; simplify `Bundles`
jamesmckinna Apr 25, 2024
79728c5
congruence for `List⁺` actions
jamesmckinna Apr 25, 2024
937823d
simplify `Self` actions
jamesmckinna Apr 25, 2024
654eda0
renamed `Free` to `FreeMonoid`: needs simplifying!
jamesmckinna Apr 25, 2024
04c535d
fix-up
jamesmckinna Apr 25, 2024
305173d
tidied up `FreeMonoid`
jamesmckinna Apr 29, 2024
5702c46
`open` API more eagerly
jamesmckinna Apr 29, 2024
f1f73bf
`fix-whitespace`
jamesmckinna Apr 29, 2024
7df8e8c
things in their right places, now
jamesmckinna May 1, 2024
753e216
rethink notation
jamesmckinna May 1, 2024
7570960
knock-on
jamesmckinna May 1, 2024
3981c4c
tightened up dependencies
jamesmckinna May 1, 2024
2e292e7
inline uses of `ListAction`
jamesmckinna May 3, 2024
9b775da
refactored to streamline `FreeMonoid`'s use of iterated `List` actions
jamesmckinna May 8, 2024
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
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ Deprecated names
New modules
-----------

* Bundles for left- and right- actions:
```
Algebra.Action.Bundles
```

* The free `Monoid` actions over a `SetoidAction`:
```
Algebra.Action.Construct.FreeMonoid
```

* The left- and right- regular actions (of a `Monoid`) over itself:
```
Algebra.Action.Construct.Self
jamesmckinna marked this conversation as resolved.
Show resolved Hide resolved
```

* Structures for left- and right- actions:
```
Algebra.Action.Structures
```

* Raw bundles for module-like algebraic structures:
```
Algebra.Module.Bundles.Raw
Expand Down
110 changes: 110 additions & 0 deletions src/Algebra/Action/Bundles.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- Setoid Actions and Monoid Actions
------------------------------------------------------------------------

------------------------------------------------------------------------
-- Currently, this module (attempts to) systematically distinguish
-- between left- and right- actions, but unfortunately, trying to avoid
-- long names such as `Algebra.Action.Bundles.MonoidAction.LeftAction`
-- leads to the possibly/probably suboptimal use of `Left` and `Right` as
-- submodule names, when these are intended only to be used qualified by
-- the type of Action to which they refer, eg. as MonoidAction.Left etc.
------------------------------------------------------------------------


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

module Algebra.Action.Bundles where

open import Algebra.Action.Structures using (IsLeftAction; IsRightAction)
open import Algebra.Bundles using (Monoid)
open import Level using (Level; _⊔_)
open import Data.List.Base using ([]; _++_)
import Data.List.Relation.Binary.Equality.Setoid as ≋
open import Relation.Binary.Bundles using (Setoid)

private
variable
a c r ℓ : Level


------------------------------------------------------------------------
-- Basic definition: a Setoid action yields underlying action structure

module SetoidAction (S : Setoid c ℓ) (A : Setoid a r) where

private

module S = Setoid S
module A = Setoid A

open ≋ S using (≋-refl)

record Left : Set (a ⊔ r ⊔ c ⊔ ℓ) where
jamesmckinna marked this conversation as resolved.
Show resolved Hide resolved

field
isLeftAction : IsLeftAction S._≈_ A._≈_

open IsLeftAction isLeftAction public

▷-congˡ : ∀ {m x y} → x A.≈ y → m ▷ x A.≈ m ▷ y
▷-congˡ x≈y = ▷-cong S.refl x≈y

▷-congʳ : ∀ {m n x} → m S.≈ n → m ▷ x A.≈ n ▷ x
▷-congʳ m≈n = ▷-cong m≈n A.refl

[]-act : ∀ x → [] ▷⋆ x A.≈ x
[]-act _ = []-act-cong A.refl

++-act : ∀ ms ns x → (ms ++ ns) ▷⋆ x A.≈ ms ▷⋆ ns ▷⋆ x
++-act ms ns x = ++-act-cong ms ≋-refl A.refl

record Right : Set (a ⊔ r ⊔ c ⊔ ℓ) where

field
isRightAction : IsRightAction S._≈_ A._≈_

open IsRightAction isRightAction public

◁-congˡ : ∀ {x y m} → x A.≈ y → x ◁ m A.≈ y ◁ m
◁-congˡ x≈y = ◁-cong x≈y S.refl

◁-congʳ : ∀ {m n x} → m S.≈ n → x ◁ m A.≈ x ◁ n
◁-congʳ m≈n = ◁-cong A.refl m≈n

++-act : ∀ x ms ns → x ◁⋆ (ms ++ ns) A.≈ x ◁⋆ ms ◁⋆ ns
++-act x ms ns = ++-act-cong A.refl ms ≋-refl

[]-act : ∀ x → x ◁⋆ [] A.≈ x
[]-act x = []-act-cong A.refl


------------------------------------------------------------------------
-- Definition: indexed over an underlying SetoidAction

module MonoidAction (M : Monoid c ℓ) (A : Setoid a r) where

private

open module M = Monoid M using (ε; _∙_; setoid)
open module A = Setoid A using (_≈_)

record Left (leftAction : SetoidAction.Left setoid A) : Set (a ⊔ r ⊔ c ⊔ ℓ)
where

open SetoidAction.Left leftAction public

field
∙-act : ∀ m n x → m ∙ n ▷ x ≈ m ▷ n ▷ x
ε-act : ∀ x → ε ▷ x ≈ x

record Right (rightAction : SetoidAction.Right setoid A) : Set (a ⊔ r ⊔ c ⊔ ℓ)
where

open SetoidAction.Right rightAction public

field
∙-act : ∀ x m n → x ◁ m ∙ n ≈ x ◁ m ◁ n
ε-act : ∀ x → x ◁ ε ≈ x
102 changes: 102 additions & 0 deletions src/Algebra/Action/Construct/FreeMonoid.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- The free MonoidAction on a SetoidAction, arising from ListAction
------------------------------------------------------------------------

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

open import Relation.Binary.Bundles using (Setoid)

module Algebra.Action.Construct.FreeMonoid
{a c r ℓ} (S : Setoid c ℓ) (A : Setoid a r)
where

open import Algebra.Action.Bundles
open import Algebra.Action.Structures using (IsLeftAction; IsRightAction)
open import Algebra.Bundles using (Monoid)
open import Algebra.Structures using (IsMonoid)

open import Data.List.Base using (List; []; _++_)
import Data.List.Properties as List
import Data.List.Relation.Binary.Equality.Setoid as ≋
open import Data.Product.Base using (_,_)

open import Function.Base using (_∘_)

open import Level using (Level; _⊔_)


------------------------------------------------------------------------
-- Temporary: define the Monoid structure on List S.Carrier
-- NB should be defined somewhere under `Data.List`!?
JacquesCarette marked this conversation as resolved.
Show resolved Hide resolved

private

open ≋ S using (_≋_; ≋-refl; ≋-reflexive; ≋-isEquivalence; ++⁺)

isMonoid : IsMonoid _≋_ _++_ []
isMonoid = record
{ isSemigroup = record
{ isMagma = record
{ isEquivalence = ≋-isEquivalence
; ∙-cong = ++⁺
}
; assoc = λ xs ys zs → ≋-reflexive (List.++-assoc xs ys zs)
}
; identity = (λ _ → ≋-refl) , ≋-reflexive ∘ List.++-identityʳ
}

monoid : Monoid c (c ⊔ ℓ)
monoid = record { isMonoid = isMonoid }


------------------------------------------------------------------------
-- A Setoid action yields an iterated ListS action, which is
-- the underlying SetoidAction of the FreeMonoid construction

module SetoidActions where

open SetoidAction
open ≋ S renaming (≋-setoid to ListS)

leftAction : (left : Left S A) → Left ListS A
leftAction left = record
{ isLeftAction = record
{ _▷_ = _▷⋆_
; ▷-cong = ▷⋆-cong
}
}
where open Left left

rightAction : (right : Right S A) → Right ListS A
rightAction right = record
{ isRightAction = record
{ _◁_ = _◁⋆_
; ◁-cong = ◁⋆-cong
}
}
where open Right right


------------------------------------------------------------------------
-- Now: define the MonoidActions of the (Monoid based on) ListS on A

module MonoidActions where

open MonoidAction monoid A

leftAction : (left : SetoidAction.Left S A) → Left (SetoidActions.leftAction left)
leftAction left = record
{ ∙-act = ++-act
; ε-act = []-act
}
where open SetoidAction.Left left

rightAction : (right : SetoidAction.Right S A) → Right (SetoidActions.rightAction right)
rightAction right = record
{ ∙-act = ++-act
; ε-act = []-act
}
where open SetoidAction.Right right

40 changes: 40 additions & 0 deletions src/Algebra/Action/Construct/Self.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- Left- and right- regular actions
------------------------------------------------------------------------

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

module Algebra.Action.Construct.Self where

open import Algebra.Action.Bundles
open import Algebra.Action.Structures using (IsLeftAction; IsRightAction)
open import Algebra.Bundles using (Monoid)

------------------------------------------------------------------------
-- Left- and Right- Actions of a Monoid over itself

module Regular {c ℓ} (M : Monoid c ℓ) where

open Monoid M
open MonoidAction M setoid

isLeftAction : IsLeftAction _≈_ _≈_
isLeftAction = record { _▷_ = _∙_ ; ▷-cong = ∙-cong }

isRightAction : IsRightAction _≈_ _≈_
isRightAction = record { _◁_ = _∙_ ; ◁-cong = ∙-cong }

leftAction : Left record { isLeftAction = isLeftAction }
leftAction = record
{ ∙-act = assoc
; ε-act = identityˡ
}

rightAction : Right record { isRightAction = isRightAction }
rightAction = record
{ ∙-act = λ x m n → sym (assoc x m n)
; ε-act = identityʳ
}

92 changes: 92 additions & 0 deletions src/Algebra/Action/Structures.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- Structure of the Action of one (pre-)Setoid on another
------------------------------------------------------------------------

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

open import Relation.Binary.Core using (Rel)

module Algebra.Action.Structures
{c a ℓ r} {M : Set c} {A : Set a} (_≈ᴹ_ : Rel M ℓ) (_≈_ : Rel A r)
where

open import Data.List.Base
using (List; []; _∷_; _++_; foldl; foldr)
open import Data.List.NonEmpty.Base
using (List⁺; _∷_)
open import Data.List.Relation.Binary.Pointwise as Pointwise
using (Pointwise; []; _∷_)
open import Function.Base using (id)
open import Level using (Level; _⊔_)

private
variable
x y z : A
m n p : M
ms ns ps : List M


------------------------------------------------------------------------
-- Basic definitions: fix notation

record IsLeftAction : Set (a ⊔ r ⊔ c ⊔ ℓ) where
infixr 5 _▷_ _▷⋆_ _▷⁺_

field
_▷_ : M → A → A
▷-cong : m ≈ᴹ n → x ≈ y → (m ▷ x) ≈ (n ▷ y)

-- derived form: iterated action, satisfying congruence

_▷⋆_ : List M → A → A
ms ▷⋆ a = foldr _▷_ a ms

_▷⁺_ : List⁺ M → A → A
(m ∷ ms) ▷⁺ a = m ▷ ms ▷⋆ a

▷⋆-cong : Pointwise _≈ᴹ_ ms ns → x ≈ y → (ms ▷⋆ x) ≈ (ns ▷⋆ y)
▷⋆-cong [] x≈y = x≈y
▷⋆-cong (m≈n ∷ ms≋ns) x≈y = ▷-cong m≈n (▷⋆-cong ms≋ns x≈y)

▷⁺-cong : m ≈ᴹ n → Pointwise _≈ᴹ_ ms ns → x ≈ y → ((m ∷ ms) ▷⁺ x) ≈ ((n ∷ ns) ▷⁺ y)
▷⁺-cong m≈n ms≋ns x≈y = ▷-cong m≈n (▷⋆-cong ms≋ns x≈y)

++-act-cong : ∀ ms → Pointwise _≈ᴹ_ ps (ms ++ ns) →
x ≈ y → (ps ▷⋆ x) ≈ (ms ▷⋆ ns ▷⋆ y)
++-act-cong [] ps≋ns x≈y = ▷⋆-cong ps≋ns x≈y
++-act-cong (m ∷ ms) (p≈m ∷ ps≋ms++ns) x≈y = ▷-cong p≈m (++-act-cong ms ps≋ms++ns x≈y)

[]-act-cong : x ≈ y → ([] ▷⋆ x) ≈ y
[]-act-cong = id

record IsRightAction : Set (a ⊔ r ⊔ c ⊔ ℓ) where
infixl 5 _◁_ _◁⋆_ _◁⁺_

field
_◁_ : A → M → A
◁-cong : x ≈ y → m ≈ᴹ n → (x ◁ m) ≈ (y ◁ n)

-- derived form: iterated action, satisfying congruence

_◁⋆_ : A → List M → A
a ◁⋆ ms = foldl _◁_ a ms

_◁⁺_ : A → List⁺ M → A
a ◁⁺ (m ∷ ms) = a ◁ m ◁⋆ ms

◁⋆-cong : x ≈ y → Pointwise _≈ᴹ_ ms ns → (x ◁⋆ ms) ≈ (y ◁⋆ ns)
◁⋆-cong x≈y [] = x≈y
◁⋆-cong x≈y (m≈n ∷ ms≋ns) = ◁⋆-cong (◁-cong x≈y m≈n) ms≋ns

◁⁺-cong : x ≈ y → m ≈ᴹ n → Pointwise _≈ᴹ_ ms ns → (x ◁⁺ (m ∷ ms)) ≈ (y ◁⁺ (n ∷ ns))
◁⁺-cong x≈y m≈n ms≋ns = ◁⋆-cong (◁-cong x≈y m≈n) (ms≋ns)

++-act-cong : x ≈ y → ∀ ms → Pointwise _≈ᴹ_ ps (ms ++ ns) →
(x ◁⋆ ps) ≈ (y ◁⋆ ms ◁⋆ ns)
++-act-cong x≈y [] ps≋ns = ◁⋆-cong x≈y ps≋ns
++-act-cong x≈y (m ∷ ms) (p≈m ∷ ps≋ms++ns) = ++-act-cong (◁-cong x≈y p≈m) ms ps≋ms++ns

[]-act-cong : x ≈ y → (x ◁⋆ []) ≈ y
[]-act-cong = id
Loading