agda-stdlib icon indicating copy to clipboard operation
agda-stdlib copied to clipboard

Add new operations (cf. `RawQuasigroup`) to `IsGroup`

Open jamesmckinna opened this issue 2 years ago • 13 comments

Tackles second item of #2247 .

Issues:

  • deprecation of _-_ in IsGroup?
  • adding operations to Algebra.Bundles.Raw.RawGroup?

Knock-on changes (potentially):

  • Instances of _-_ defined in, and hence would clash with any opening of the RawGroup|IsGroup instance:
  • [ ] Data.Integer.Base|Properties
  • [ ] Data.Rational.Base|Properties
  • [ ] Data.Rational.Unnormalised.Base|Properties
  • Instances of _-_ not defined in, but would be by opening the RawGroup|IsGroup instance:
  • [ ] Data.Parity.Base|Properties
  • [ ] Data.Sign.Base|Properties

jamesmckinna avatar Jan 11 '24 09:01 jamesmckinna

Hmm so a few questions.

  1. Firstly, I think this definitely falls foul of the Fairbairn threshold? I was going to suggest _∙⁻¹_ should be _∙_⁻¹ but then why not just write out the full thing?
  2. Why do you not export them for AbelianGroup?

MatthewDaggitt avatar Jan 15 '24 02:01 MatthewDaggitt

Matthew, thanks for the attentive close reading...

1. Firstly, I think this definitely falls foul of the [Fairbairn threshold](https://wiki.haskell.org/Fairbairn_threshold)? I was going to suggest `_∙⁻¹_` should be `_∙_⁻¹` but then why not just write out the full thing?

So, indeed that's a fair question: one reason to introduce a distinct symbol is to avoid ambiguous parsing, which would otherwise definitely occur with your suggestion. Here the situation is slightly different from #2249 (though clearly cognate, and arising from the same root issue #2247), not least because we don't have so much group theory formalised yet to see the recurrence of the pattern... other than as the derived form _-_, but that doesn't belong in Group... on a 'conventional' reading of the symbol

2. Why do you not export them for `AbelianGroup`?

Again, this was a 'design' choice, underlying the whole PR: I don't think _-_ is a sensible choice of operator symbol for Group at all, while it surely is for (our customary informal intuitions/practice around) AbelianGroup; and once you are commutative, then the two otherwise-distinct Group operations become extensionally equal... (the alternative design would be to add that lemma to Algebra.Consequences.Group), so it struck me that the less invasive thing to do was to retain _-_ for AbelianGroup (again: that could be done by renaming the Group operation, but I wasn't sure about the deprecation consequences for trying to shift the operation symbol to the 'right' place), but not pollute its namespace with all the now-equivalent variants.

jamesmckinna avatar Jan 15 '24 08:01 jamesmckinna

It does make a lot of sense to seriously consider adding some such symbol - basically because 200 years of Group Theory has continued to do so. So they find it adds something useful to the domain, and we would need a solid reason to decide otherwise. There seems to be a strong usability / readability case to be made.

Having said that, neither _∙⁻¹_ nor _∙_⁻¹ seem to actually achieve that! If we can't use some kind of division-like symbol, then the increase in readability is not enough as the suggested symbols are essentially the same as writing it out in full.

It does make sense to call this _-_ in AbelianGroup.

JacquesCarette avatar Jan 19 '24 21:01 JacquesCarette

Thanks for the prompts to rethink, but I would definitely welcome suggestions as to a 'good' notation for these: maybe the Lambek-style left- and right- 'divides' symbols are the way to go? Or does that have the wrong associations wrt Preorder-based symbology?

jamesmckinna avatar Jan 20 '24 10:01 jamesmckinna

I think quasigroup and loop use \\ and // .

JacquesCarette avatar Jan 20 '24 13:01 JacquesCarette

I think quasigroup and loop use \ and // .

yes! It seems as though they could be used, ... in place... if we refactor Algebra.Structures to put IsQuasigroup and IsLoop before IsGroup, and then create+open the relevant instances as manifest fields of IsGroup...

... such a refactoring would, however, perturb the universal-algebra-finitary-signature enumeration currently embodied in that module...

... suggestion(s) welcome as to the 'best'/a 'middle' path to resolving this cleanly.

jamesmckinna avatar Jan 22 '24 09:01 jamesmckinna

I don't have a good suggestion, as I don't really know the actual effect the refactoring would have. It might range from harmless to completely unacceptable.

JacquesCarette avatar Jan 26 '24 21:01 JacquesCarette

... So maybe the correct thing to do is add them in-place on their own terms, and downstream establish a lemma of the form: IsGroup yields IsQuasigroup/IsLoop...?

jamesmckinna avatar Jan 27 '24 11:01 jamesmckinna

Such lemmas would definitely be guaranteed low-disruption. Thus definitely a viable path.

JacquesCarette avatar Jan 27 '24 14:01 JacquesCarette

Hopefully the addition of the isQuasigroup and isLoop structural lemmas now gives more 'weight' to this PR.

Outstanding refactoring opportunities, emerging in the course of doing this:

  • derived operations in IsGroup, or RawGroup? cf. #2252 how to get them correctly re-exported to IsGroup if added to RawGroup, and vice versa...?
  • duplication between proofs of Cancellative properties for Algebra.Properties.Quasigroup and Algebra.Properties.Group; UPDATED: refactored to achieve this;
  • ~~do those proofs belong instead in Algebra.Consequences.Setoid?~~ UPDATED: for another time
  • simplify the new proofs added here to exploit the lemmas in Algebra.Properties.Quasigroup|Loop? UPDATED: refactored to achieve this now.

Plus: adding other derived operations #2268

jamesmckinna avatar Jan 29 '24 05:01 jamesmckinna

Only issue outstanding for me: the current design factors between

  • Structures.IsGroup for the additional derivable operations, and
  • Properties.Group, which takes a Bundled instance to then expose the underlying Structure...

Does the operation material belong under Structures or should it all belong in the Bundle (leaving out the question of which bundle, Raw or otherwise... ;-))?

jamesmckinna avatar Jan 31 '24 08:01 jamesmckinna

Note on reflexive reasoning (comment also left on #2152 already merged into v2.0):

... I've had to use explicit x ≈⟨ refl ⟩... steps, because there is no abbreviation ≈⟨⟩ declared, whereas ≡⟨⟩ is available as an alternative. Was this what you intended, or should there be a bug-fixing issue/PR raised to add the additional syntax?

Originally posted by @jamesmckinna in https://github.com/agda/agda-stdlib/pull/2152#discussion_r1472742455

jamesmckinna avatar Jan 31 '24 12:01 jamesmckinna

On the latest refactorings: they basically consist of moving lemmas from Algebra.Properties.Group to their 'true' homes in Algebra.Properties.Loop/Algebra.Properties.Quasigroup , and publicly (re-)exporting them from ...Group, together with some refactoring to derive existing Group properties from 'simpler' (or: now already proved) lemmas, such as SelfInverse _⁻¹ etc.

But that's it now.

jamesmckinna avatar Feb 04 '24 10:02 jamesmckinna

You beat me to it to resolve the merge conflict... Thanks!

jamesmckinna avatar Mar 16 '24 06:03 jamesmckinna