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

[fixes #1363] Add Algebra.Literals #2264

Closed
Closed
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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ Deprecated names
New modules
-----------

* Adding a distinguished point `•` (\bu2) to `Monoid`, and using it to define
abstract 'literals' for any `PointedMonoid`, with the intended mode-of-use
being to instantiate the point with `1#` from any (semi)ring-like structure:
```agda
module Algebra.Bundles.Literals
module Algebra.Bundles.Pointed
module Algebra.Structures.Literals
module Algebra.Structures.Pointed
module Algebra.Literals
```

* `Algebra.Module.Bundles.Raw`: raw bundles for module-like algebraic structures

Additions to existing modules
Expand Down
19 changes: 19 additions & 0 deletions src/Algebra/Bundles/Literals.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- Algebra Literals, from a PointedMonoid bundle
------------------------------------------------------------------------

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

open import Algebra.Bundles.Pointed

module Algebra.Bundles.Literals
{c ℓ} (pointedMonoid : PointedMonoid c ℓ)
where

open PointedMonoid pointedMonoid

-- Re-export `Number` instance defined in Algebra.Structures.Literals
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no instance defined in Algebra.Structures.Literals....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, but this seems to be the model in eg Data.Nat.Literals which I had been mindlessly following...


open import Algebra.Structures.Literals isPointedMonoid public using (number)
50 changes: 50 additions & 0 deletions src/Algebra/Bundles/Pointed.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- `Pointed` intermediate between `Monoid` and `SemiringWithoutAnnihilatingZero`
------------------------------------------------------------------------

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

open import Algebra.Bundles
open import Algebra.Bundles.Raw
open import Algebra.Core
open import Algebra.Structures.Pointed as Pointed using (IsPointedMonoid)
import Algebra.Properties.Monoid.Mult as Mult
open import Data.Nat.Base as ℕ using (ℕ)
open import Data.Unit.Base
open import Level using (Level; suc; _⊔_; Lift)
open import Relation.Binary.Core using (Rel)

module Algebra.Bundles.Pointed where

private
variable
c ℓ : Level

------------------------------------------------------------------------
-- Bundles with 1 binary operation & 2 elements
------------------------------------------------------------------------

record PointedMonoid c ℓ : Set (suc (c ⊔ ℓ)) where
field
rawMonoid : RawMonoid c ℓ
open RawMonoid rawMonoid using (Carrier)
field
• : Carrier
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment "1 binary operation & 2 elements" is correct, but the rest of the names (Pointed, etc) give the wrong impression of having a single distinguished element. BiPointed ?

Copy link
Contributor Author

@jamesmckinna jamesmckinna Jan 27, 2024

Choose a reason for hiding this comment

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

Much to think about here. Ever since my abortive Pointed draft PRs #1958 #1963 , I've been thinking about PointedX (and how to formalise the lift map/pointed extension operation from X in a 'signature polymorphic' way) in general...

The two points in PointedMonoid play distinct roles, so I'm unhappy to identify them as '2 points', because one is distinguished as an identity, while the other is an unconstrained extension of the signature...

... that said, BiPointedSet/BiPointedMagma do make sense, especially as Raw bundles, but I've always been resistant to universal algebra ideas in this regard precisely because not all 'freely constructed' such signatures make sense in the absence of additional structure...?

So from my POV, I'd want to keep things more cleanly separated...

Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: they do "make sense", but they are not necessarily sufficiently useful. Phrased that way, I'd say that our current state of knowledge makes this true. [Usefulness is a temporal quality, not absolute.]

Copy link
Contributor

Choose a reason for hiding this comment

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

The next question is: that extra point, is it meant to be preserved by homomorphisms or not? If not, then rather than Pointed what you're describing is Inhabited (I'm writing that up separately, i.e. the observation that the category whose objects are pairs of a type and a point of that type, but whose homomorphisms don't preserve that point, are exactly the inhabited types, without needing to have a notion of truncation).

Of course, a Monoid is always inhabited -- the right name here would be NonTrivialMonoid although that's tricky as the one-point monoid is a model as you don't actually want to assert that the extra point is not unit! Best you might be able to do is to ask that the obvious homomorphism induced by 'swap' not be homotopic to the identity.

Copy link
Contributor Author

@jamesmckinna jamesmckinna Jan 27, 2024

Choose a reason for hiding this comment

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

Also an excellent observation (although I'm still insufficently homotopically-inclined to arbitrate on the last point). I think that points should be preserved (esp. in this setting, because _+ pt is the unary operation at hand, and we want it as (part of) an NNO-instance a SuccessorSet instance to be preserved?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And NonTrivialMonoid...: does that exclude the case 0# = 1#? I wouldn't want to insist on that...?

isPointedMonoid : IsPointedMonoid rawMonoid •

open IsPointedMonoid isPointedMonoid public

------------------------------------------------------------------------
-- instance from any SemiringWithoutAnnihilatingZero

pointedMonoid : SemiringWithoutAnnihilatingZero c ℓ → PointedMonoid c ℓ
pointedMonoid semiringWithoutAnnihilatingZero
= record { isPointedMonoid = isPointedMonoid }
where
open SemiringWithoutAnnihilatingZero semiringWithoutAnnihilatingZero
using (1#; +-rawMonoid; +-isMonoid)
isPointedMonoid : IsPointedMonoid +-rawMonoid 1#
isPointedMonoid = record { isMonoid = +-isMonoid }

20 changes: 20 additions & 0 deletions src/Algebra/Literals.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- Algebra Literals, from a SemiringWithoutAnnihilatingZero
------------------------------------------------------------------------

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

open import Algebra.Bundles using (SemiringWithoutAnnihilatingZero)

module Algebra.Literals {c ℓ}
(semiringWithoutAnnihilatingZero : SemiringWithoutAnnihilatingZero c ℓ)
where

open import Algebra.Bundles.Pointed

-- Re-export `Number` instance defined in Algebra.Bundles.Literals

open import Algebra.Bundles.Literals
(pointedMonoid semiringWithoutAnnihilatingZero) public using (number)
21 changes: 21 additions & 0 deletions src/Algebra/Structures/Literals.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- Algebra Literals
------------------------------------------------------------------------

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

open import Algebra.Bundles.Raw
open import Algebra.Structures.Pointed

module Algebra.Structures.Literals
{c ℓ} {rawMonoid : RawMonoid c ℓ} {•}
(isPointedMonoid : IsPointedMonoid rawMonoid •)
where

open import Agda.Builtin.FromNat
open IsPointedMonoid isPointedMonoid

number : Number Carrier
number = record { Literals }
49 changes: 49 additions & 0 deletions src/Algebra/Structures/Pointed.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- Defines `IsPointedMonoid`
-- intermediate between `Monoid` and `SemiringWithoutAnnihilatingZero`
--
-- By contrast with the rest of `Algebra.Structures`, this is modelled
-- on an underlying `RawMonoid`, rather than a 'flattened' such signature
------------------------------------------------------------------------

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

open import Algebra.Bundles.Raw
import Algebra.Structures as Structures
open import Data.Nat.Base as ℕ using (ℕ)
open import Data.Unit.Base
open import Level using (Level; _⊔_; Lift)

import Algebra.Definitions.RawMonoid as Definitions

module Algebra.Structures.Pointed where

private
variable
c ℓ : Level


------------------------------------------------------------------------
-- Structures with 1 binary operation & 2 elements
------------------------------------------------------------------------

record IsPointedMonoid
(rawMonoid : RawMonoid c ℓ)
(• : RawMonoid.Carrier rawMonoid) : Set (c ⊔ ℓ)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused. You don't have a not equal to assumption between and ε so there's not necessarily two elements...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely! Degenerate instances are/should always be possible: we don't insist that 0# not be equal to 1# in (Semi)ring*, for example.
So perhaps the comment is bad, but this was mindless/lazy cut-and-paste from Algebra.*...

where
open RawMonoid rawMonoid public
open Structures _≈_

field
isMonoid : IsMonoid _∙_ ε

_ו : ℕ → Carrier
n ו = n × • where open Definitions rawMonoid

module Literals where
Copy link
Contributor

Choose a reason for hiding this comment

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

Why define this as a named module, and not just a Number record directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • I had stymied myself with imports from Agda.Builtin.FromNat, perhaps in the mistaken belief that that was how Number instances get introduced...
  • I had (for some reason) wanted to distinguish between the declaration of a module defining the implementation, from its export via a number : Number ... definition elsewhere...

Constraint : ℕ → Set c
Constraint _ = Lift c ⊤
fromNat : ∀ n → {{Constraint n}} → Carrier
fromNat n = n ו