@@ -188,6 +188,8 @@ def Matroid(groundset=None, data=None, **kwds):
188188 ``reduced_matrix = A``
189189 then the matroid is represented by `[I\ \ A]` where `I` is an
190190 appropriately sized identity matrix.
191+ - ``morphism`` -- A morphism representation of the matroid.
192+ - ``reduced_morphism`` -- A reduced morphism representation of the matroid.
191193 - ``rank_function`` -- A function that computes the rank of each subset.
192194 Can only be provided together with a groundset.
193195 - ``circuit_closures`` -- Either a list of tuples ``(k, C)`` with ``C``
@@ -533,6 +535,48 @@ def Matroid(groundset=None, data=None, **kwds):
533535 sage: M.base_ring()
534536 Integer Ring
535537
538+ A morphism representation of a :class:`LinearMatroid` can also be used as
539+ input::
540+
541+ sage: M = matroids.catalog.Fano()
542+ sage: A = M.representation(order=True); A
543+ Generic morphism:
544+ From: Free module generated by {'a', 'b', 'c', 'd', 'e', 'f', 'g'} over
545+ Finite Field of size 2
546+ To: Free module generated by {0, 1, 2} over Finite Field of size 2
547+ sage: A._unicode_art_matrix()
548+ a b c d e f g
549+ 0⎛1 0 0 0 1 1 1⎞
550+ 1⎜0 1 0 1 0 1 1⎟
551+ 2⎝0 0 1 1 1 0 1⎠
552+ sage: N = Matroid(A); N
553+ Binary matroid of rank 3 on 7 elements, type (3, 0)
554+ sage: N.groundset()
555+ frozenset({'a', 'b', 'c', 'd', 'e', 'f', 'g'})
556+ sage: M == N
557+ True
558+
559+ The keywords ``morphism`` and ``reduced_morphism`` are also available::
560+
561+ sage: M = matroids.catalog.RelaxedNonFano("abcdefg")
562+ sage: A = M.representation(order=True, reduced=True); A
563+ Generic morphism:
564+ From: Free module generated by {'d', 'e', 'f', 'g'} over
565+ Finite Field in w of size 2^2
566+ To: Free module generated by {'a', 'b', 'c'} over
567+ Finite Field in w of size 2^2
568+ sage: A._unicode_art_matrix()
569+ d e f g
570+ a⎛1 1 0 1⎞
571+ b⎜1 0 1 1⎟
572+ c⎝0 1 w 1⎠
573+ sage: N = Matroid(reduced_morphism=A); N
574+ Quaternary matroid of rank 3 on 7 elements
575+ sage: N.groundset()
576+ frozenset({'a', 'b', 'c', 'd', 'e', 'f', 'g'})
577+ sage: M == N
578+ True
579+
536580 #. Rank function:
537581
538582 Any function mapping subsets to integers can be used as input::
@@ -713,8 +757,8 @@ def Matroid(groundset=None, data=None, **kwds):
713757 if data is None :
714758 for k in ['bases' , 'independent_sets' , 'circuits' ,
715759 'nonspanning_circuits' , 'flats' , 'graph' , 'matrix' ,
716- 'reduced_matrix' , 'rank_function ' , 'revlex ' ,
717- 'circuit_closures' , 'matroid' ]:
760+ 'reduced_matrix' , 'morphism ' , 'reduced_morphism ' ,
761+ 'rank_function' , 'revlex' , ' circuit_closures' , 'matroid' ]:
718762 if k in kwds :
719763 data = kwds .pop (k )
720764 key = k
@@ -732,8 +776,13 @@ def Matroid(groundset=None, data=None, **kwds):
732776 Graph = ()
733777 if isinstance (data , Graph ):
734778 key = 'graph'
735- elif is_Matrix (data ):
779+ elif is_Matrix (data ) or (
780+ isinstance (data , tuple ) and is_Matrix (data [0 ])):
736781 key = 'matrix'
782+ elif isinstance (data , sage .modules .with_basis .morphism .ModuleMorphism ) or (
783+ isinstance (data , tuple ) and
784+ isinstance (data [0 ], sage .modules .with_basis .morphism .ModuleMorphism )):
785+ key = 'morphism'
737786 elif isinstance (data , sage .matroids .matroid .Matroid ):
738787 key = 'matroid'
739788 elif isinstance (data , str ):
@@ -856,9 +905,22 @@ def Matroid(groundset=None, data=None, **kwds):
856905 M = GraphicMatroid (G , groundset = groundset )
857906
858907 # Matrices:
859- elif key in ['matrix' , 'reduced_matrix' ]:
908+ elif key in ['matrix' , 'reduced_matrix' , 'morphism' , 'reduced_morphism' ]:
860909 A = data
861- is_reduced = (key == 'reduced_matrix' )
910+ is_reduced = (key == 'reduced_matrix' or key == 'reduced_morphism' )
911+ if isinstance (data , tuple ):
912+ A = data [0 ]
913+ if key == 'matrix' or key == 'reduced_matrix' :
914+ if groundset is None :
915+ groundset = data [1 ]
916+ if is_reduced :
917+ groundset += data [2 ]
918+ if key == 'morphism' or key == 'reduced_morphism' :
919+ if groundset is None :
920+ groundset = list (A .domain ().basis ().keys ())
921+ if is_reduced :
922+ groundset = list (A .codomain ().basis ().keys ()) + groundset
923+ A = A .matrix ()
862924
863925 # Fix the representation
864926 if not is_Matrix (A ):
0 commit comments