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

Support morphisms in Matroid constructor #37940

Merged
merged 4 commits into from
May 12, 2024

Conversation

gmou3
Copy link
Contributor

@gmou3 gmou3 commented May 5, 2024

This follows the merging of #37692 and it enables the (re-)feeding of a linear matroid's morphism representation into the Matroid constructor.

Example:

sage: M = matroids.catalog.Fano()
sage: A = M.representation(order=True); A
Generic morphism:
  From: Free module generated by {'a', 'b', 'c', 'd', 'e', 'f', 'g'} over Finite Field of size 2
  To:   Free module generated by {0, 1, 2} over Finite Field of size 2
sage: Matroid(A)
Binary matroid of rank 3 on 7 elements, type (3, 0)

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.

LGTM.

@gmou3
Copy link
Contributor Author

gmou3 commented May 6, 2024

Thanks!

@mkoeppe you may wish to have a look.

@gmou3 gmou3 force-pushed the matroid_morphism branch from e6e9bab to 796dd16 Compare May 6, 2024 23:43
@@ -734,6 +778,10 @@ def Matroid(groundset=None, data=None, **kwds):
key = 'graph'
elif is_Matrix(data):
key = 'matrix'
elif isinstance(data, sage.modules.with_basis.morphism.ModuleMorphism) or (
isinstance(data, tuple) and
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 not sure if I find "tuple" input very convincing.
Does it have a clear benefit over just passing the groundset via the groundset parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason I did this is so that the following works:

sage: M = matroids.catalog.Fano()
sage: A = M.representation(order=True, labels=True)
sage: Matroid(A)
...

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, ok

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 need to do something similar for matrices though.

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 made it so that this also works and retains the groundset labels:

sage: M = matroids.catalog.Fano()
sage: A = M.representation(labels=True)
sage: Matroid(A)
...

@@ -734,6 +778,10 @@ def Matroid(groundset=None, data=None, **kwds):
key = 'graph'
elif is_Matrix(data):
key = 'matrix'
elif isinstance(data, sage.modules.with_basis.morphism.ModuleMorphism) or (
Copy link
Contributor

@mkoeppe mkoeppe May 7, 2024

Choose a reason for hiding this comment

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

instead of using isinstance with this class, I think it's better to use isinstance(data, Morphism) and data.category_for().is_subcategory(Modules(data.base_ring()).WithBasis())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what's best but the above doesn't seem to work.

@gmou3 gmou3 force-pushed the matroid_morphism branch from 49ad4fb to 0ca6cd8 Compare May 7, 2024 01:07
@mkoeppe
Copy link
Contributor

mkoeppe commented May 7, 2024

LGTM, thanks!

Copy link

github-actions bot commented May 8, 2024

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

vbraun pushed a commit to vbraun/sage that referenced this pull request May 9, 2024
    
This follows the merging of sagemath#37692 and it enables the (re-)feeding of a
linear matroid's morphism representation into the `Matroid` constructor.

Example:
```
sage: M = matroids.catalog.Fano()
sage: A = M.representation(order=True); A
Generic morphism:
  From: Free module generated by {'a', 'b', 'c', 'd', 'e', 'f', 'g'}
over Finite Field of size 2
  To:   Free module generated by {0, 1, 2} over Finite Field of size 2
sage: Matroid(A)
Binary matroid of rank 3 on 7 elements, type (3, 0)
```
    
URL: sagemath#37940
Reported by: gmou3
Reviewer(s): gmou3, Matthias Köppe, Travis Scrimshaw
vbraun pushed a commit to vbraun/sage that referenced this pull request May 11, 2024
    
This follows the merging of sagemath#37692 and it enables the (re-)feeding of a
linear matroid's morphism representation into the `Matroid` constructor.

Example:
```
sage: M = matroids.catalog.Fano()
sage: A = M.representation(order=True); A
Generic morphism:
  From: Free module generated by {'a', 'b', 'c', 'd', 'e', 'f', 'g'}
over Finite Field of size 2
  To:   Free module generated by {0, 1, 2} over Finite Field of size 2
sage: Matroid(A)
Binary matroid of rank 3 on 7 elements, type (3, 0)
```
    
URL: sagemath#37940
Reported by: gmou3
Reviewer(s): gmou3, Matthias Köppe, Travis Scrimshaw
vbraun pushed a commit to vbraun/sage that referenced this pull request May 12, 2024
    
This follows the merging of sagemath#37692 and it enables the (re-)feeding of a
linear matroid's morphism representation into the `Matroid` constructor.

Example:
```
sage: M = matroids.catalog.Fano()
sage: A = M.representation(order=True); A
Generic morphism:
  From: Free module generated by {'a', 'b', 'c', 'd', 'e', 'f', 'g'}
over Finite Field of size 2
  To:   Free module generated by {0, 1, 2} over Finite Field of size 2
sage: Matroid(A)
Binary matroid of rank 3 on 7 elements, type (3, 0)
```
    
URL: sagemath#37940
Reported by: gmou3
Reviewer(s): gmou3, Matthias Köppe, Travis Scrimshaw
@vbraun vbraun merged commit 3fdc4d2 into sagemath:develop May 12, 2024
15 checks passed
@mkoeppe mkoeppe added this to the sage-10.4 milestone May 12, 2024
@gmou3 gmou3 deleted the matroid_morphism branch May 25, 2024 15:28
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.

4 participants