Skip to content

implement naive default inverse methods for finite monoids #40024

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

Merged
merged 3 commits into from
May 11, 2025

Conversation

fchapoton
Copy link
Contributor

@fchapoton fchapoton commented Apr 29, 2025

This is implementing very naive one and __invert__ methods in the category of finite monoids.

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

Copy link
Collaborator

@tscrim tscrim left a comment

Choose a reason for hiding this comment

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

These are real failures by the bots. Magmas implements a generic one() by return self(1). Perhaps we should try that first (or more generally

def one(self):
    try:
        return super().one()
    except (TypeError,, ValueError, AttributeError):
        pass
    it = (v for v in self if all(v * w == w for w in self))
    return next(it)

I think there is an implicit general problem as the default iteration starts from one() and multiplies by all of the generators. Of course, this is not unreasonable as we expect the user to implement one of these as part of the monoid. That being said, perhaps it is better to require one be implemented in some more explicit way?

For both methods, perhaps we should cache that result? Also, wouldn't it be better raise a different error than StopIteration if it is not invertible?

@fchapoton
Copy link
Contributor Author

This is apparently not enough. Maybe I should remove this default one and keep only the default invert ?

@fchapoton fchapoton force-pushed the naive_one_for_finite_monoids branch from 15b60d8 to a7a6d45 Compare May 2, 2025 07:01
Copy link
Collaborator

@tscrim tscrim left a comment

Choose a reason for hiding this comment

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

That's very curious and unexpected. Now I wonder how that code is even working. It would need some non-generic way to create things (either an iterator or be able to construct one() somehow). I figured the super() call was sufficient, but I guess we should in principle, check that the one from Magmas.Unital is being called (or we could just explicitly add it in as return self(1) instead).

Well, I guess we can just revert like this, but at least it didn't seem like a widespread problem... How much time do you want to spend on this?

Co-authored-by: Travis Scrimshaw <clfrngrown@aol.com>
@fchapoton
Copy link
Contributor Author

Thanks Travis, for your time and helpful feedback. I would indeed prefer not to spend more time.

Copy link

github-actions bot commented May 2, 2025

Documentation preview for this PR (built with commit e39604c; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@tscrim tscrim changed the title implement naive default one and inverse methods for finite monoids implement naive default inverse methods for finite monoids May 7, 2025
Copy link
Collaborator

@tscrim tscrim left a comment

Choose a reason for hiding this comment

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

Thank you. LGTM.

@vbraun vbraun merged commit aa550b1 into sagemath:develop May 11, 2025
21 of 22 checks passed
@fchapoton fchapoton deleted the naive_one_for_finite_monoids branch May 11, 2025 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants