-
Notifications
You must be signed in to change notification settings - Fork 247
[ new ] add definitions of module-like structures #897
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks mostly pretty good. This round of feedback is primarily concerned with the structure. I'll probably add a second round of minor formatting issues once we get everything in the right place.
src/Algebra/Module.agda
Outdated
_*ᵣ_ = flip _*ₗ_ | ||
|
||
*ₗ-comm : L.Commutative _*ₗ_ | ||
*ₗ-comm x y m = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would usually say that these sort of proofs should go in Algebra.Module.Consequences
, and then be imported. But of course LeftAction
and RightAction
aren't under Algebra.Module
...
For the moment I'd put them under Algebra.FunctionProperties.LeftAction.Consequences
and I'll sort them out later when I refactor Algebra
as part of #876.
src/Algebra/Module/Properties.agda
Outdated
|
||
{-# OPTIONS --without-K --safe #-} | ||
|
||
module Algebra.Module.Properties where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm hierarchies don't usually have .Properties
file but instead have a Properties.S
for every structure S
(which are usually parameterised by an S
).
For example semiring⇒leftSemimodule
should live in Algebra.Properties.Semiring
and ring⇒rightModule
should live in Algebra.Properties.Ring
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think Algebra.Properties.LeftSemimodule
&c is the way to go? Also, would this imply simplifying the names of lemmas? E.g, semiring⇒leftSemimodule
becomes fromSemiring
, or something like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like putting a LOT in the module hierarchy, though: {left, right, neuter} * {semi, full}... that's a lot of modules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this was also part of the reasoning. All of these lemmas are pretty similar, so it seems easier to keep them synchronised if they are together. Maybe we should think about how large this file is likely to get.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like putting a LOT in the module hierarchy, though: {left, right, neuter} * {semi, full}... that's a lot of modules.
@wenkokke you're right, but it is the way the library is currently laid out (see Algebra.Properties
). I think best to try and stay consistent.
Do you think Algebra.Properties.LeftSemimodule &c is the way to go? Also, would this imply simplifying the names of lemmas? E.g, semiring⇒leftSemimodule becomes fromSemiring, or something like this.
Yup sounds good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm okay, new plan! Keep this module as is, but rename it to Algebra.Module.Construct.Trivial
? As you suggested earlier @laMudri, we could then ditch the semiring⇒
part of the semiring⇒leftSemimodule
names?
Edit: ah, just seen that you suggested this as well. Great minds think alike 😄
I wasn't going to mention this is as the current definitions match the standard mathematical theory quite well, but having just read #898 I've realised that this should definitely be discussed. This is the first time that we have "structures" taking in a "package" as a parameter. Is this something we want to allow? Although it matches the standard mathematical formalisation, it does introduce various problems with respect to the hierarchy.
I'm a little worried that there might be more problems lurking out there as well. Whenever we deviate from the Although a little more verbose, I might be tempted to go with definitions in the style:
which would circumvent both of these problems and maintain consistency. What are people's thoughts? |
An odd thing is that then an R-module contains a proof that the operations of R form a ring – duplicating what is already contained in R. But still, this might be the way to go. |
@MatthewDaggitt Would it work to give |
@MatthewDaggitt I've been fighting with Agda to get a nice algebra hierarchy myself lately. The heavily parameterized ones are definitely the one to go for now, but are tedious to work with because you need a ton of quantification everywhere. I wonder if Intellij's Arend gets it right, which claims to implement a neat trick where parameters and fields of records are actually one and the same thing: https://arend-lang.github.io/about/arend-features#anonymous-extensions |
Sounds like the "frame type theory" by Cyril Cohen, Assia Mahboubi and Xavier Montillet (types 2019) would be useful here. |
So the way I've avoided this in the
|
Yes, it's definitely preferable to use packages when you can get away with it, but lots of quantification does seem to be required when you want dependencies between different structures.
That sounds really neat! Seems almost too neat to be honest, there must a trade-off somewhere surely? :)
I'm afraid I've temporarily fallen out of academia (working on reversing it!) and don't have journal access at the moment, so I'll have to take your word on that 👍 |
@laMudri I think I'm going to bump this to |
That seems fair. I think there are a few interrelated issues to work through before this can be improved and merged. I'd like to hear more from @JacquesCarette about keeping things coherent before proceeding. |
It's definitely on my list of things to look at. I should be able to do it tomorrow or Friday. |
The definitions of (semi)module are now #985-compliant. An R-module is an R-R-bimodule, defined only when R is commutative. This gives the option to specify both the left scaling and the right scaling operators. There are also helper modules |
Oh, I forgot to add that one of the more surprising modifications to incorporate bimodules was the definitions record IsLeftSemimodule (+ᴹ : Op₂ M) (*ₗ : Opₗ R M) (0ᴹ : M) : Set _ where
field
+ᴹ-isCommutativeMonoid : IsCommutativeMonoid _≈ᴹ_ +ᴹ 0ᴹ
isPreleftSemimodule : IsPreleftSemimodule +ᴹ *ₗ 0ᴹ
record IsBisemimodule (+ᴹ : Op₂ M) (*ₗ : Opₗ R M) (*ᵣ : Opᵣ S M) (0ᴹ : M) : Set _ where
field
+ᴹ-isCommutativeMonoid : IsCommutativeMonoid _≈ᴹ_ +ᴹ 0ᴹ
isPreleftSemimodule : IsPreleftSemimodule R-semiring +ᴹ *ₗ 0ᴹ
isPrerightSemimodule : IsPrerightSemimodule S-semiring +ᴹ *ᵣ 0ᴹ
*ₗ-*ᵣ-assoc : ∀ r m s → *ᵣ (*ₗ r m) s ≈ᴹ *ₗ r (*ᵣ m s) These definitions basically abstract over duplicated code (in lieu of being able to abstract over pure rows); not much else. |
Very nice development. It is also standard mathematical practice to have things like The point is that there are a whole bunch of isomorphic ways of defining the same thing in Agda, and they have different usability profiles in different contexts. So it's not like one is better than any of the others, it's that they are each relatively superior. See points 7-10 of Tom Hales' critique of Lean for many things which apply to Agda too. Bottom line: in current Agda, I think what you've done here is the best you can do, and should be merged in. What will be needed is for someone on the core Agda team to get interested in this kind of library development and see that things have gotten unwieldly but could be fixed. (Hopefully @alhassy and @WolframKahl are paying attention too). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @laMudri, apologies for taking a while to get back to this. It's definitely getting there! I've added a few more comments. Also it's missing a changelog entry but that can probably come when we've got it all nailed down.
-- the result equality. | ||
|
||
module Algebra.FunctionProperties.LeftAction | ||
{a b ℓb} (A : Set a) {B : Set b} (_≈_ : Rel B ℓb) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When is the A
not inferable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This module is made to be used like the old Algebra.FunctionProperties
. In Algebra.Module.Structures
, we do
import Algebra.FunctionProperties.LeftAction as L
and then
record IsPreleftSemimodule (+ᴹ : Op₂ M) (*ₗ : Opₗ R M) (0ᴹ : M)
: Set (r ⊔ m ⊔ ℓr ⊔ ℓm) where
open L R _≈ᴹ_
...
where A
is filled by R
. This open
fails if R
is replaced by _
.
Maybe Algebra.Structures
does something different these days, in which case the thing here probably should be changed. But otherwise, I think it's right.
src/Algebra/Module/Properties.agda
Outdated
|
||
{-# OPTIONS --without-K --safe #-} | ||
|
||
module Algebra.Module.Properties where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like putting a LOT in the module hierarchy, though: {left, right, neuter} * {semi, full}... that's a lot of modules.
@wenkokke you're right, but it is the way the library is currently laid out (see Algebra.Properties
). I think best to try and stay consistent.
Do you think Algebra.Properties.LeftSemimodule &c is the way to go? Also, would this imply simplifying the names of lemmas? E.g, semiring⇒leftSemimodule becomes fromSemiring, or something like this.
Yup sounds good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking really good, I think we're pretty close now!
Do you do anything different for long using lists?
I think we tend to put related names on the same line but other than that not really.
src/Algebra/Module/Structures.agda
Outdated
|
||
record IsPreleftSemimodule (+ᴹ : Op₂ M) (*ₗ : Opₗ R M) (0ᴹ : M) | ||
: Set (r ⊔ m ⊔ ℓr ⊔ ℓm) where | ||
open L R _≈ᴹ_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this really work? 😮
------------------------------------------------------------------------ | ||
-- The Agda standard library | ||
-- | ||
-- Abbreviations of some of the module-like definitions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this comment is quite right?
src/Algebra/Module/Properties.agda
Outdated
|
||
{-# OPTIONS --without-K --safe #-} | ||
|
||
module Algebra.Module.Properties where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm okay, new plan! Keep this module as is, but rename it to Algebra.Module.Construct.Trivial
? As you suggested earlier @laMudri, we could then ditch the semiring⇒
part of the semiring⇒leftSemimodule
names?
Edit: ah, just seen that you suggested this as well. Great minds think alike 😄
Note that now that we are using 2.6.1 on master, you do not need to use |
On my checklist:
|
👍 for later. This is already a pretty big PR. |
For the first todo, maybe this should have its own (simple, but possibly moderately large) pull request, partially to test out the |
Merged in. Thanks for everyone's contributions! |
This pull request introduces modules over rings. In detail, we have:
LeftSemimodule
andRightSemimodule
over semiringsSemimodule
over commutative semiringsLeftModule
andRightModule
over ringsModule
over commutative ringsModules are all really R-modules. For example, the parameters of
Module
are the following.As far as I understand, this best fits mathematical practice. It also means that
IsModule
depends onAlgebra
, motivating the new modules. The added modules are:Algebra.Module
, corresponding toAlgebra
Algebra.Structures.Module
, corresponding toAlgebra.Structures
Algebra.FunctionProperties.Module.Core
, corresponding toAlgebra.FunctionProperties.Core
Algebra.FunctionProperties.Module.(Left|Right)
, corresponding toAlgebra.FunctionProperties
The function properties were named based on what they look like, rather than names more meaningful for linear algebra. This produces names that are familiar from
Algebra.FunctionProperties
, and hopefully are beginner-friendly.The module exports are very complicated, so there may be some bugs in them.