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

Fix AsSemigroup to reject non-associative inputs & declare IsCommutative/IsAssociative for IsCollection #4373

Merged

Conversation

wilfwilson
Copy link
Member

@wilfwilson wilfwilson commented Apr 8, 2021

See #4030.

It might not be fast, but I think it is necessary.

I thought about adding a similar check to SemigroupByGenerators, but that (via the documentation for Semigroup) is explicitly documented as not checking for associativity.

Fixes #4030.

Text for release notes

  • Check for associativity in AsSemigroup, and correctly return fail for non-associative collections, such as non-associative magmas.
  • Declare IsCommutative and IsAssociative more generally for IsCollection, rather than just for IsMagma.

(End of text for release notes)

@wilfwilson wilfwilson added kind: bug Issues describing general bugs, and PRs fixing them kind: bug: wrong result Issues describing bugs that result in mathematically or otherwise wrong results, and PRs fixing them topic: library release notes: use title For PRs: the title of this PR is suitable for direct use in the release notes labels Apr 8, 2021
@wilfwilson wilfwilson changed the title Introduce associativity check to the generic AsSemigroup method Add an associativity check to the generic AsSemigroup method Apr 8, 2021
@wilfwilson wilfwilson force-pushed the as-semigroup-check-associativity branch from a7a788f to 3227966 Compare April 8, 2021 11:47
@wilfwilson

This comment has been minimized.

@ChrisJefferson

This comment has been minimized.

@wilfwilson

This comment has been minimized.

lib/semigrp.gi Outdated Show resolved Hide resolved
lib/semigrp.gi Outdated Show resolved Hide resolved
lib/semigrp.gi Outdated Show resolved Hide resolved
@ThomasBreuer
Copy link
Contributor

Yes, the associativity test is necessary.
The problem is actually worse:

gap> T:= [ [ 1, 2, 6, 5, 4, 3 ], [ 2, 1, 4, 2, 2, 5 ], [ 6, 5, 1, 6, 6, 4 ], 
>          [ 5, 6, 3, 4, 1, 2 ], [ 4, 3, 2, 1, 5, 6 ], [ 3, 4, 5, 3, 3, 1 ] ];;
gap> M:= MagmaByMultiplicationTable( T );
<magma with 6 generators>
gap> IsAssociative( M );
false
gap> AsSemigroup( M );
<semigroup of size 6, with 3 generators>
gap> GroupByGenerators( M ); # AsGroup( M ) returns fail, which is o.k.
<group with 6 generators>
gap> MonoidByGenerators( M ); # AsMonoid(M) runs into an error
<monoid with 6 generators>
gap> Group( Elements( M ) );
<group with 6 generators>

@wilfwilson wilfwilson added the do not merge PRs which are not yet ready to be merged (e.g. submitted for discussion, or test results) label Apr 15, 2021
@wilfwilson
Copy link
Member Author

wilfwilson commented Apr 15, 2021

Thanks for the further information @ThomasBreuer. I'll investigate how that behaviour corresponds to the documentation, and try to add fixes to this PR as appropriate.

@ThomasBreuer
Copy link
Contributor

@wilfwilson I have been thinking about installing a default IsAssociative method for IsCollection, and calling this in the various places where the check is needed. It is not completely clear to me where these places are, apparently several operations are affected.

@wilfwilson wilfwilson force-pushed the as-semigroup-check-associativity branch 2 times, most recently from 20cdc58 to eb0c8ea Compare May 7, 2021 17:42
@wilfwilson wilfwilson removed the do not merge PRs which are not yet ready to be merged (e.g. submitted for discussion, or test results) label May 7, 2021
@wilfwilson
Copy link
Member Author

I've now updated this along the lines you suggested @fingolfin, and removed the "do not merge" label. Let's see what the tests and code coverage say.

@wilfwilson wilfwilson force-pushed the as-semigroup-check-associativity branch from eb0c8ea to cea9c29 Compare May 7, 2021 17:53
@wilfwilson
Copy link
Member Author

@ThomasBreuer here's how things lie with this PR:

gap> T:= [ [ 1, 2, 6, 5, 4, 3 ], [ 2, 1, 4, 2, 2, 5 ], [ 6, 5, 1, 6, 6, 4 ],
>          [ 5, 6, 3, 4, 1, 2 ], [ 4, 3, 2, 1, 5, 6 ], [ 3, 4, 5, 3, 3, 1 ] ];;
gap> M:= MagmaByMultiplicationTable( T );
<magma with 6 generators>
gap> IsAssociative( M );
false
gap> AsSemigroup( M );
fail
gap> AsSubsemigroup( M, M );
fail
gap> GroupByGenerators( M );
<group with 6 generators>
gap> Group( Elements( M ) );
<group with 6 generators>
gap> MonoidByGenerators( M );
<monoid with 6 generators>
gap> SemigroupByGenerators( M );
<semigroup with 6 generators>

Shall we open a separate issue about this?

@wilfwilson wilfwilson force-pushed the as-semigroup-check-associativity branch from cea9c29 to 011b6ce Compare May 7, 2021 17:59
@wilfwilson wilfwilson changed the title Add an associativity check to the generic AsSemigroup method Add associativity check to AsSemigroup & declare IsCommutative/IsAssociative for IsMultiplicativeElementCollection May 7, 2021
@wilfwilson wilfwilson changed the title Add associativity check to AsSemigroup & declare IsCommutative/IsAssociative for IsMultiplicativeElementCollection Add associativity check to AsSemigroup & declare IsCommutative/IsAssociative for IsMultiplicativeElementCollection May 7, 2021
@wilfwilson wilfwilson added kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements release notes: to be added PRs introducing changes that should be (but have not yet been) mentioned in the release notes and removed release notes: use title For PRs: the title of this PR is suitable for direct use in the release notes labels May 7, 2021
@wilfwilson
Copy link
Member Author

This PR now includes a bugfix and an enhancement; I can break them up if you'd like (the bugfix would have to be based on top of the enhancement). As it stands, I wonder if such a combination will confuse the automated release notes creation script...

Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

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

LGTM

lib/magma.gd Outdated Show resolved Hide resolved
@wilfwilson wilfwilson force-pushed the as-semigroup-check-associativity branch 2 times, most recently from 84f5065 to b1b7c93 Compare May 7, 2021 22:31
Copy link
Contributor

@ThomasBreuer ThomasBreuer left a comment

Choose a reason for hiding this comment

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

Two details (one formulation and one changed requirement in a method installation) may cause problems, otherwise the changes are o.k.
In particular, I agree that we should open a new issue for collecting the problems with missing associativity checks in other domain constructions.

lib/magma.gd Outdated Show resolved Hide resolved
lib/semigrp.gi Outdated Show resolved Hide resolved
@wilfwilson wilfwilson force-pushed the as-semigroup-check-associativity branch 2 times, most recently from cfad551 to 22d917d Compare May 10, 2021 16:11
@wilfwilson wilfwilson changed the title Add associativity check to AsSemigroup & declare IsCommutative/IsAssociative for IsMultiplicativeElementCollection Add associativity check to AsSemigroup & declare IsCommutative/IsAssociative for IsCollection May 11, 2021
@wilfwilson wilfwilson force-pushed the as-semigroup-check-associativity branch from 22d917d to 8afa55d Compare May 18, 2021 08:32
Copy link
Contributor

@ThomasBreuer ThomasBreuer left a comment

Choose a reason for hiding this comment

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

This looks good, apart from a suspicious formulation (for me as a non-native speaker).

lib/semigrp.gd Outdated Show resolved Hide resolved
@wilfwilson wilfwilson force-pushed the as-semigroup-check-associativity branch from 8afa55d to c6d69b6 Compare May 18, 2021 14:18
@wilfwilson wilfwilson merged commit 567922f into gap-system:master May 20, 2021
@wilfwilson wilfwilson deleted the as-semigroup-check-associativity branch May 20, 2021 10:05
@fingolfin fingolfin added release notes: multiple PRs introducing changes that require multiple entries in the release notes (TO BE AVOIDED!!!) and removed release notes: to be added PRs introducing changes that should be (but have not yet been) mentioned in the release notes labels Aug 17, 2022
@fingolfin fingolfin changed the title Add associativity check to AsSemigroup & declare IsCommutative/IsAssociative for IsCollection FixAsSemigroup to reject non-associative inputs & declare IsCommutative/IsAssociative for IsCollection Aug 18, 2022
@fingolfin fingolfin changed the title FixAsSemigroup to reject non-associative inputs & declare IsCommutative/IsAssociative for IsCollection Fix AsSemigroup to reject non-associative inputs & declare IsCommutative/IsAssociative for IsCollection Aug 18, 2022
@fingolfin fingolfin added the release notes: added PRs introducing changes that have since been mentioned in the release notes label Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug: wrong result Issues describing bugs that result in mathematically or otherwise wrong results, and PRs fixing them kind: bug Issues describing general bugs, and PRs fixing them kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements release notes: added PRs introducing changes that have since been mentioned in the release notes release notes: multiple PRs introducing changes that require multiple entries in the release notes (TO BE AVOIDED!!!) topic: library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Non-associative semigroup
4 participants