Skip to content

Commit

Permalink
Trac #18427: matroids catalog, optional field of representation
Browse files Browse the repository at this point in the history
Allowing the user to specify an field/ring when creating an matroid.

Example, Wheel would have two new options
{{{
def Wheel(n, field=None, ring=None)
}}}

{{{
matroids.Wheel(4, field=GF(3))
}}}

yields a ternary matroid.

URL: http://trac.sagemath.org/18427
Reported by: chaoxu
Ticket author(s): Chao Xu
Reviewer(s): Rudi
  • Loading branch information
Release Manager authored and vbraun committed May 24, 2015
2 parents bd00304 + b1c4de0 commit e8b4426
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/sage/matroids/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,13 +774,17 @@ def CompleteGraphic(n):
return M


def Wheel(n):
def Wheel(n, field=None, ring=None):
"""
Return the rank-`n` wheel.
INPUT:
- ``n`` -- a positive integer. The rank of the desired matroid.
- ``ring`` -- any ring. If provided, output will be a linear matroid
over the ring or field ``ring``. If the ring is `\ZZ`, then output
will be a regular matroid.
- ``field`` -- any field. Same as ``ring``, but only fields are allowed.
OUTPUT:
Expand All @@ -800,16 +804,35 @@ def Wheel(n):
sage: M = matroids.Wheel(3)
sage: M.is_isomorphic(matroids.CompleteGraphic(4))
True
"""
A = Matrix(ZZ, n, 2 * n, sparse=True)
sage: M.is_isomorphic(matroids.Wheel(3,field=GF(3)))
True
sage: M = matroids.Wheel(3,field=GF(3)); M
Wheel(3): Ternary matroid of rank 3 on 6 elements, type 0+
"""
base_ring = ZZ
if field != None and ring != None :
raise ValueError("only one of ring and field can be specified.")
if field != None :
base_ring = field
try:
if not base_ring.is_field():
raise TypeError("specified ``field`` is not a field.")
except AttributeError:
raise TypeError("specified ``field`` is not a field.")
if ring != None :
base_ring = ring
A = Matrix(base_ring, n, 2 * n, sparse=True)
for i in range(n):
A[i, i] = 1
A[i, n + i] = 1
if i != 0:
A[i, i + n - 1] = -1
else:
A[i, 2 * n - 1] = -1
M = RegularMatroid(A)
if base_ring is ZZ:
M = RegularMatroid(A)
else:
M = Matroid(A)
M.rename('Wheel(' + str(n) + '): ' + repr(M))
return M

Expand Down

0 comments on commit e8b4426

Please sign in to comment.