diff --git a/src/sage/matroids/advanced.py b/src/sage/matroids/advanced.py index 83cfb912a77..b38075bb39c 100644 --- a/src/sage/matroids/advanced.py +++ b/src/sage/matroids/advanced.py @@ -59,4 +59,6 @@ from . import lean_matrix from .extension import LinearSubclasses, MatroidExtensions from .union_matroid import MatroidUnion, MatroidSum, PartitionMatroid -from .graphic_matroid import GraphicMatroid + +from sage.misc.lazy_import import lazy_import +lazy_import('sage.matroids.graphic_matroid', 'GraphicMatroid') diff --git a/src/sage/matroids/basis_exchange_matroid.pyx b/src/sage/matroids/basis_exchange_matroid.pyx index 040e6cebf36..90d10842d46 100644 --- a/src/sage/matroids/basis_exchange_matroid.pyx +++ b/src/sage/matroids/basis_exchange_matroid.pyx @@ -473,8 +473,8 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: sorted(M.groundset()) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: sorted(M.groundset()) ['a', 'b', 'c', 'd', 'e', 'f', 'g'] """ return self._groundset @@ -495,17 +495,17 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: type(M.groundset()) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: type(M.groundset()) <... 'frozenset'> - sage: type(M.groundset_list()) # optional - sage.rings.finite_rings + sage: type(M.groundset_list()) <... 'list'> - sage: sorted(M.groundset_list()) # optional - sage.rings.finite_rings + sage: sorted(M.groundset_list()) ['a', 'b', 'c', 'd', 'e', 'f', 'g'] - sage: E = M.groundset_list() # optional - sage.rings.finite_rings - sage: E.remove('a') # optional - sage.rings.finite_rings - sage: sorted(M.groundset_list()) # optional - sage.rings.finite_rings + sage: E = M.groundset_list() + sage: E.remove('a') + sage: sorted(M.groundset_list()) ['a', 'b', 'c', 'd', 'e', 'f', 'g'] """ return list(self._E) @@ -516,10 +516,10 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: len(M) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: len(M) 7 - sage: len(M.groundset()) # optional - sage.rings.finite_rings + sage: len(M.groundset()) 7 """ @@ -538,10 +538,10 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M.full_rank() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M.full_rank() 3 - sage: M.dual().full_rank() # optional - sage.rings.finite_rings + sage: M.dual().full_rank() 4 """ return self._matroid_rank @@ -564,10 +564,10 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M.full_corank() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M.full_corank() 4 - sage: M.dual().full_corank() # optional - sage.rings.finite_rings + sage: M.dual().full_corank() 3 """ return self._groundset_size - self._matroid_rank @@ -592,12 +592,12 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: sorted(M.basis()) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: sorted(M.basis()) ['a', 'b', 'c'] - sage: M.rank('cd') # optional - sage.rings.finite_rings + sage: M.rank('cd') 2 - sage: sorted(M.basis()) # optional - sage.rings.finite_rings + sage: sorted(M.basis()) ['a', 'c', 'd'] """ @@ -750,8 +750,8 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.P8() # optional - sage.rings.finite_rings - sage: sorted(M._fundamental_circuit('abcd', 'e')) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.P8() + sage: sorted(M._fundamental_circuit('abcd', 'e')) ['a', 'b', 'c', 'e'] """ self.__pack(self._input, B) @@ -906,8 +906,8 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.P8() # optional - sage.rings.finite_rings - sage: sorted(M._fundamental_cocircuit('efgh', 'e')) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.P8() + sage: sorted(M._fundamental_cocircuit('efgh', 'e')) ['b', 'c', 'd', 'e'] """ self.__pack(self._input, B) @@ -1255,8 +1255,8 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.S8() # optional - sage.rings.finite_rings - sage: M.f_vector() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.S8() + sage: M.f_vector() [1, 8, 22, 14, 1] """ @@ -1321,14 +1321,14 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.S8() # optional - sage.rings.finite_rings - sage: M.f_vector() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.S8() + sage: M.f_vector() [1, 8, 22, 14, 1] - sage: len(M.flats(2)) # optional - sage.rings.finite_rings + sage: len(M.flats(2)) 22 - sage: len(M.flats(8)) # optional - sage.rings.finite_rings + sage: len(M.flats(8)) 0 - sage: len(M.flats(4)) # optional - sage.rings.finite_rings + sage: len(M.flats(4)) 1 """ cdef bitset_t *flats @@ -1396,14 +1396,14 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.S8().dual() # optional - sage.rings.finite_rings - sage: M.f_vector() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.S8().dual() + sage: M.f_vector() [1, 8, 22, 14, 1] - sage: len(M.coflats(2)) # optional - sage.rings.finite_rings + sage: len(M.coflats(2)) 22 - sage: len(M.coflats(8)) # optional - sage.rings.finite_rings + sage: len(M.coflats(8)) 0 - sage: len(M.coflats(4)) # optional - sage.rings.finite_rings + sage: len(M.coflats(4)) 1 """ cdef bitset_t *coflats @@ -1529,8 +1529,8 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.N1() # optional - sage.rings.finite_rings - sage: M.bases_count() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.N1() + sage: M.bases_count() 184 """ if self._bcount is not None: @@ -1556,9 +1556,9 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: I = M.independent_sets() # optional - sage.rings.finite_rings - sage: len(I) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: I = M.independent_sets() + sage: len(I) 57 """ cdef bitset_t *I @@ -1617,10 +1617,10 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.N1() # optional - sage.rings.finite_rings - sage: M.bases_count() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.N1() + sage: M.bases_count() 184 - sage: [len(M.independent_r_sets(r)) for r in range(M.full_rank() + 1)] # optional - sage.rings.finite_rings + sage: [len(M.independent_r_sets(r)) for r in range(M.full_rank() + 1)] [1, 10, 45, 120, 201, 184] """ @@ -1649,10 +1649,10 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.N1() # optional - sage.rings.finite_rings - sage: M.bases_count() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.N1() + sage: M.bases_count() 184 - sage: len([B for B in M.bases()]) # optional - sage.rings.finite_rings + sage: len([B for B in M.bases()]) 184 """ return self.independent_r_sets(self.full_rank()) @@ -1671,10 +1671,10 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.N1() # optional - sage.rings.finite_rings - sage: len(M.nonbases()) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.N1() + sage: len(M.nonbases()) 68 - sage: [len(M.dependent_r_sets(r)) for r in range(M.full_rank() + 1)] # optional - sage.rings.finite_rings + sage: [len(M.dependent_r_sets(r)) for r in range(M.full_rank() + 1)] [0, 0, 0, 0, 9, 68] """ @@ -1714,10 +1714,10 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.N1() # optional - sage.rings.finite_rings - sage: binomial(M.size(), M.full_rank())-M.bases_count() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.N1() + sage: binomial(M.size(), M.full_rank())-M.bases_count() # needs sage.symbolic 68 - sage: len([B for B in M.nonbases()]) # optional - sage.rings.finite_rings + sage: len([B for B in M.nonbases()]) 68 """ return self.dependent_r_sets(self.full_rank()) @@ -1740,8 +1740,8 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.N1() # optional - sage.rings.finite_rings - sage: len(M.nonspanning_circuits()) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.N1() + sage: len(M.nonspanning_circuits()) 23 """ cdef SetSystem NSC @@ -1789,8 +1789,8 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.N1() # optional - sage.rings.finite_rings - sage: len(M.noncospanning_cocircuits()) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.N1() + sage: len(M.noncospanning_cocircuits()) 23 """ cdef SetSystem NSC @@ -1835,8 +1835,8 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = Matroid(bases=matroids.named_matroids.NonFano().bases()) # optional - sage.rings.finite_rings - sage: sorted([sorted(C) for C in M.cocircuits()]) # optional - sage.rings.finite_rings + sage: M = Matroid(bases=matroids.named_matroids.NonFano().bases()) + sage: sorted([sorted(C) for C in M.cocircuits()]) [['a', 'b', 'c', 'd', 'g'], ['a', 'b', 'c', 'e', 'g'], ['a', 'b', 'c', 'f', 'g'], ['a', 'b', 'd', 'e'], ['a', 'c', 'd', 'f'], ['a', 'e', 'f', 'g'], ['b', 'c', 'e', 'f'], @@ -1883,8 +1883,8 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = Matroid(matroids.named_matroids.NonFano().bases()) # optional - sage.rings.finite_rings - sage: sorted([sorted(C) for C in M.circuits()]) # optional - sage.rings.finite_rings + sage: M = Matroid(matroids.named_matroids.NonFano().bases()) + sage: sorted([sorted(C) for C in M.circuits()]) [['a', 'b', 'c', 'g'], ['a', 'b', 'd', 'e'], ['a', 'b', 'f'], ['a', 'c', 'd', 'f'], ['a', 'c', 'e'], ['a', 'd', 'e', 'f'], ['a', 'd', 'g'], ['a', 'e', 'f', 'g'], ['b', 'c', 'd'], @@ -1932,10 +1932,10 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = matroids.named_matroids.N1() # optional - sage.rings.finite_rings - sage: M._characteristic_setsystem() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.N1() + sage: M._characteristic_setsystem() Iterator over a system of subsets - sage: len(M._characteristic_setsystem()) # optional - sage.rings.finite_rings + sage: len(M._characteristic_setsystem()) 23 """ if 2 * self._matroid_rank > self._groundset_size: @@ -1958,9 +1958,9 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = Matroid(bases=matroids.named_matroids.Fano().bases()) # optional - sage.rings.finite_rings - sage: N = Matroid(matroids.named_matroids.NonFano().bases()) # optional - sage.rings.finite_rings - sage: M._weak_invariant() == N._weak_invariant() # optional - sage.rings.finite_rings + sage: M = Matroid(bases=matroids.named_matroids.Fano().bases()) + sage: N = Matroid(matroids.named_matroids.NonFano().bases()) + sage: M._weak_invariant() == N._weak_invariant() False """ if self._weak_invariant_var is None: @@ -2003,9 +2003,9 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: - sage: M = Matroid(matroids.named_matroids.Fano().bases()) # optional - sage.rings.finite_rings - sage: N = Matroid(matroids.named_matroids.NonFano().bases()) # optional - sage.rings.finite_rings - sage: M._strong_invariant() == N._strong_invariant() # optional - sage.rings.finite_rings + sage: M = Matroid(matroids.named_matroids.Fano().bases()) + sage: N = Matroid(matroids.named_matroids.NonFano().bases()) + sage: M._strong_invariant() == N._strong_invariant() False """ if self._strong_invariant_var is None: @@ -2132,10 +2132,10 @@ cdef class BasisExchangeMatroid(Matroid): sage: N._is_isomorphism(M, {e:e for e in M.groundset()}) False - sage: M = matroids.named_matroids.Fano() \ ['g'] # optional - sage.rings.finite_rings - sage: N = matroids.Wheel(3) # optional - sage.rings.finite_rings - sage: morphism = {'a':0, 'b':1, 'c': 2, 'd':4, 'e':5, 'f':3} # optional - sage.rings.finite_rings - sage: M._is_isomorphism(N, morphism) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() \ ['g'] + sage: N = matroids.Wheel(3) + sage: morphism = {'a':0, 'b':1, 'c': 2, 'd':4, 'e':5, 'f':3} + sage: M._is_isomorphism(N, morphism) True TESTS: @@ -2146,8 +2146,8 @@ cdef class BasisExchangeMatroid(Matroid): ....: return min(len(X), 2) ....: sage: M = Matroid(groundset='abcd', rank_function=f) - sage: N = Matroid(field=GF(3), reduced_matrix=[[1,1],[1,-1]]) # optional - sage.rings.finite_rings - sage: N._is_isomorphism(M, {0:'a', 1:'b', 2:'c', 3:'d'}) # optional - sage.rings.finite_rings + sage: N = Matroid(field=GF(3), reduced_matrix=[[1,1],[1,-1]]) + sage: N._is_isomorphism(M, {0:'a', 1:'b', 2:'c', 3:'d'}) True """ if not isinstance(other, BasisExchangeMatroid): @@ -2195,13 +2195,13 @@ cdef class BasisExchangeMatroid(Matroid): sage: from sage.matroids.advanced import * sage: M1 = matroids.Wheel(3) - sage: M2 = matroids.CompleteGraphic(4) # optional - sage.graphs - sage: morphism = M1._isomorphism(M2) # optional - sage.graphs - sage: M1._is_isomorphism(M2, morphism) # optional - sage.graphs + sage: M2 = matroids.CompleteGraphic(4) # needs sage.graphs + sage: morphism = M1._isomorphism(M2) # needs sage.graphs + sage: M1._is_isomorphism(M2, morphism) # needs sage.graphs True - sage: M1 = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M2 = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: M1._isomorphism(M2) is None # optional - sage.rings.finite_rings + sage: M1 = matroids.named_matroids.Fano() + sage: M2 = matroids.named_matroids.NonFano() + sage: M1._isomorphism(M2) is None True TESTS: @@ -2212,8 +2212,8 @@ cdef class BasisExchangeMatroid(Matroid): ....: return min(len(X), 2) ....: sage: M = Matroid(groundset='abcd', rank_function=f) - sage: N = Matroid(field=GF(3), reduced_matrix=[[1,1],[1,-1]]) # optional - sage.rings.finite_rings - sage: N._isomorphism(M) is not None # optional - sage.rings.finite_rings + sage: N = Matroid(field=GF(3), reduced_matrix=[[1,1],[1,-1]]) + sage: N._isomorphism(M) is not None True """ if not isinstance(other, BasisExchangeMatroid): @@ -2289,16 +2289,16 @@ cdef class BasisExchangeMatroid(Matroid): sage: from sage.matroids.advanced import * sage: M1 = BasisMatroid(matroids.Wheel(3)) - sage: M2 = matroids.CompleteGraphic(4) # optional - sage.graphs - sage: M1._is_isomorphic(M2) # optional - sage.graphs + sage: M2 = matroids.CompleteGraphic(4) # needs sage.graphs + sage: M1._is_isomorphic(M2) # needs sage.graphs True - sage: M1._is_isomorphic(M2, certificate=True) # optional - sage.graphs + sage: M1._is_isomorphic(M2, certificate=True) # needs sage.graphs (True, {0: 0, 1: 1, 2: 2, 3: 3, 4: 5, 5: 4}) - sage: M1 = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.rings.finite_rings - sage: M2 = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: M1._is_isomorphic(M2) # optional - sage.rings.finite_rings + sage: M1 = BasisMatroid(matroids.named_matroids.Fano()) + sage: M2 = matroids.named_matroids.NonFano() + sage: M1._is_isomorphic(M2) False - sage: M1._is_isomorphic(M2, certificate=True) # optional - sage.rings.finite_rings + sage: M1._is_isomorphic(M2, certificate=True) (False, None) """ @@ -2370,8 +2370,8 @@ cdef class BasisExchangeMatroid(Matroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.rings.finite_rings - sage: M.is_valid() # optional - sage.rings.finite_rings + sage: M = BasisMatroid(matroids.named_matroids.Fano()) + sage: M.is_valid() True sage: M = Matroid(groundset='abcd', bases=['ab', 'cd']) sage: M.is_valid() diff --git a/src/sage/matroids/basis_matroid.pyx b/src/sage/matroids/basis_matroid.pyx index caa5f11fd40..3ac43112627 100644 --- a/src/sage/matroids/basis_matroid.pyx +++ b/src/sage/matroids/basis_matroid.pyx @@ -55,9 +55,9 @@ AUTHORS: TESTS:: - sage: F = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M = Matroid(bases=F.bases()) # optional - sage.rings.finite_rings - sage: TestSuite(M).run() # optional - sage.rings.finite_rings + sage: F = matroids.named_matroids.Fano() + sage: M = Matroid(bases=F.bases()) + sage: TestSuite(M).run() Methods ======= @@ -110,11 +110,11 @@ cdef class BasisMatroid(BasisExchangeMatroid): Create a BasisMatroid instance out of any other matroid:: sage: from sage.matroids.advanced import * - sage: F = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M = BasisMatroid(F) # optional - sage.rings.finite_rings - sage: F.groundset() == M.groundset() # optional - sage.rings.finite_rings + sage: F = matroids.named_matroids.Fano() + sage: M = BasisMatroid(F) + sage: F.groundset() == M.groundset() True - sage: len(set(F.bases()).difference(M.bases())) # optional - sage.rings.finite_rings + sage: len(set(F.bases()).difference(M.bases())) 0 It is possible to provide either bases or nonbases:: @@ -150,11 +150,11 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: F = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M = BasisMatroid(F) # optional - sage.rings.finite_rings - sage: F.groundset() == M.groundset() # optional - sage.rings.finite_rings + sage: F = matroids.named_matroids.Fano() + sage: M = BasisMatroid(F) + sage: F.groundset() == M.groundset() True - sage: len(set(F.bases()).difference(M.bases())) # optional - sage.rings.finite_rings + sage: len(set(F.bases()).difference(M.bases())) 0 """ cdef SetSystem NB @@ -254,8 +254,8 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.rings.finite_rings - sage: repr(M) # indirect doctest # optional - sage.rings.finite_rings + sage: M = BasisMatroid(matroids.named_matroids.Fano()) + sage: repr(M) # indirect doctest 'Matroid of rank 3 on 7 elements with 28 bases' """ @@ -429,12 +429,12 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(bases=matroids.named_matroids.N2().bases()) # optional - sage.rings.finite_rings - sage: M.truncation() # optional - sage.rings.finite_rings + sage: M = Matroid(bases=matroids.named_matroids.N2().bases()) + sage: M.truncation() Matroid of rank 5 on 12 elements with 702 bases - sage: M.f_vector() # optional - sage.rings.finite_rings + sage: M.f_vector() [1, 12, 66, 190, 258, 99, 1] - sage: M.truncation().f_vector() # optional - sage.rings.finite_rings + sage: M.truncation().f_vector() [1, 12, 66, 190, 258, 1] """ @@ -511,10 +511,10 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.rings.finite_rings - sage: M # optional - sage.rings.finite_rings + sage: M = BasisMatroid(matroids.named_matroids.Fano()) + sage: M Matroid of rank 3 on 7 elements with 28 bases - sage: M._with_coloop('x') # optional - sage.rings.finite_rings + sage: M._with_coloop('x') Matroid of rank 4 on 8 elements with 28 bases """ @@ -548,11 +548,11 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.rings.finite_rings - sage: sorted(M.groundset()) # optional - sage.rings.finite_rings + sage: M = BasisMatroid(matroids.named_matroids.Fano()) + sage: sorted(M.groundset()) ['a', 'b', 'c', 'd', 'e', 'f', 'g'] - sage: N = M.relabel({'g':'x'}) # optional - sage.rings.finite_rings - sage: sorted(N.groundset()) # optional - sage.rings.finite_rings + sage: N = M.relabel({'g':'x'}) + sage: sorted(N.groundset()) ['a', 'b', 'c', 'd', 'e', 'f', 'x'] """ @@ -572,10 +572,10 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(bases=matroids.named_matroids.Fano().bases()) # optional - sage.rings.finite_rings - sage: M # optional - sage.rings.finite_rings + sage: M = Matroid(bases=matroids.named_matroids.Fano().bases()) + sage: M Matroid of rank 3 on 7 elements with 28 bases - sage: M.bases_count() # optional - sage.rings.finite_rings + sage: M.bases_count() 28 """ if self._bcount is None: @@ -594,10 +594,10 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(bases=matroids.named_matroids.Fano().bases()) # optional - sage.rings.finite_rings - sage: M # optional - sage.rings.finite_rings + sage: M = Matroid(bases=matroids.named_matroids.Fano().bases()) + sage: M Matroid of rank 3 on 7 elements with 28 bases - sage: len(M.bases()) # optional - sage.rings.finite_rings + sage: len(M.bases()) 28 """ cdef long r, n @@ -630,10 +630,10 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(bases=matroids.named_matroids.Fano().bases()) # optional - sage.rings.finite_rings - sage: M # optional - sage.rings.finite_rings + sage: M = Matroid(bases=matroids.named_matroids.Fano().bases()) + sage: M Matroid of rank 3 on 7 elements with 28 bases - sage: len(M.nonbases()) # optional - sage.rings.finite_rings + sage: len(M.nonbases()) 7 """ if self._nonbases is not None: @@ -674,9 +674,9 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.rings.finite_rings - sage: N = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.rings.finite_rings - sage: M._bases_invariant() == N._bases_invariant() # optional - sage.rings.finite_rings + sage: M = BasisMatroid(matroids.named_matroids.Fano()) + sage: N = BasisMatroid(matroids.named_matroids.Fano()) + sage: M._bases_invariant() == N._bases_invariant() True """ if self._bases_invariant_var is not None: @@ -733,9 +733,9 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.rings.finite_rings - sage: N = BasisMatroid(matroids.named_matroids.NonFano()) # optional - sage.rings.finite_rings - sage: M._bases_invariant2() == N._bases_invariant2() # optional - sage.rings.finite_rings + sage: M = BasisMatroid(matroids.named_matroids.Fano()) + sage: N = BasisMatroid(matroids.named_matroids.NonFano()) + sage: M._bases_invariant2() == N._bases_invariant2() False """ if self._bases_invariant2_var is None: @@ -844,8 +844,8 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = BasisMatroid(matroids.named_matroids.N1()) # optional - sage.rings.finite_rings - sage: sorted([e for e in M.groundset() if M.is_distinguished(e)]) # optional - sage.rings.finite_rings + sage: M = BasisMatroid(matroids.named_matroids.N1()) + sage: sorted([e for e in M.groundset() if M.is_distinguished(e)]) ['c', 'g', 'h', 'j'] """ @@ -886,12 +886,12 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = BasisMatroid(matroids.named_matroids.NonFano()) # optional - sage.rings.finite_rings - sage: N = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.rings.finite_rings - sage: m = {e:e for e in M.groundset()} # optional - sage.rings.finite_rings - sage: M._is_relaxation(N, m) # optional - sage.rings.finite_rings + sage: M = BasisMatroid(matroids.named_matroids.NonFano()) + sage: N = BasisMatroid(matroids.named_matroids.Fano()) + sage: m = {e:e for e in M.groundset()} + sage: M._is_relaxation(N, m) True - sage: N._is_relaxation(M, m) # optional - sage.rings.finite_rings + sage: N._is_relaxation(M, m) False """ cdef long i, j @@ -941,12 +941,12 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = BasisMatroid(matroids.named_matroids.NonFano()) # optional - sage.rings.finite_rings - sage: N = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.rings.finite_rings - sage: m = {e:e for e in M.groundset()} # optional - sage.rings.finite_rings - sage: M._is_relaxation(N, m) # optional - sage.rings.finite_rings + sage: M = BasisMatroid(matroids.named_matroids.NonFano()) + sage: N = BasisMatroid(matroids.named_matroids.Fano()) + sage: m = {e:e for e in M.groundset()} + sage: M._is_relaxation(N, m) True - sage: M._is_isomorphism(N, m) # optional - sage.rings.finite_rings + sage: M._is_isomorphism(N, m) False """ if not isinstance(other, BasisMatroid): @@ -975,13 +975,13 @@ cdef class BasisMatroid(BasisExchangeMatroid): sage: from sage.matroids.advanced import * sage: M = BasisMatroid(matroids.Wheel(3)) - sage: N = BasisMatroid(matroids.CompleteGraphic(4)) # optional - sage.graphs - sage: morphism = M._isomorphism(N) # optional - sage.graphs - sage: M._is_isomorphism(N, morphism) # optional - sage.graphs + sage: N = BasisMatroid(matroids.CompleteGraphic(4)) # needs sage.graphs + sage: morphism = M._isomorphism(N) # needs sage.graphs + sage: M._is_isomorphism(N, morphism) # needs sage.graphs True - sage: M = BasisMatroid(matroids.named_matroids.NonFano()) # optional - sage.rings.finite_rings - sage: N = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.rings.finite_rings - sage: M._isomorphism(N) is not None # optional - sage.rings.finite_rings + sage: M = BasisMatroid(matroids.named_matroids.NonFano()) + sage: N = BasisMatroid(matroids.named_matroids.Fano()) + sage: M._isomorphism(N) is not None False """ if not isinstance(other, BasisMatroid): @@ -1055,11 +1055,11 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = BasisMatroid(matroids.named_matroids.NonFano()) # optional - sage.rings.finite_rings - sage: N = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.rings.finite_rings - sage: M._is_isomorphic(N) # optional - sage.rings.finite_rings + sage: M = BasisMatroid(matroids.named_matroids.NonFano()) + sage: N = BasisMatroid(matroids.named_matroids.Fano()) + sage: M._is_isomorphic(N) False - sage: M._is_isomorphic(N, certificate=True) # optional - sage.rings.finite_rings + sage: M._is_isomorphic(N, certificate=True) (False, None) """ if certificate: @@ -1127,12 +1127,12 @@ cdef class BasisMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = BasisMatroid(matroids.named_matroids.Fano()) # optional - sage.rings.finite_rings - sage: N = BasisMatroid(matroids.named_matroids.Fano().dual()).dual() # optional - sage.rings.finite_rings - sage: O = BasisMatroid(matroids.named_matroids.NonFano()) # optional - sage.rings.finite_rings - sage: hash(M) == hash(N) # optional - sage.rings.finite_rings + sage: M = BasisMatroid(matroids.named_matroids.Fano()) + sage: N = BasisMatroid(matroids.named_matroids.Fano().dual()).dual() + sage: O = BasisMatroid(matroids.named_matroids.NonFano()) + sage: hash(M) == hash(N) True - sage: hash(M) == hash(O) # optional - sage.rings.finite_rings + sage: hash(M) == hash(O) False """ return hash((self.groundset(), self.bases_count(), self._weak_invariant())) diff --git a/src/sage/matroids/catalog.py b/src/sage/matroids/catalog.py index 0397436a5f8..4bc93a6b8a0 100644 --- a/src/sage/matroids/catalog.py +++ b/src/sage/matroids/catalog.py @@ -36,20 +36,15 @@ # **************************************************************************** from sage.matrix.constructor import Matrix -from sage.graphs.graph_generators import graphs - -from sage.rings.integer_ring import ZZ - -import sage.matroids.matroid -import sage.matroids.basis_exchange_matroid from sage.matroids.basis_matroid import BasisMatroid from sage.matroids.circuit_closures_matroid import CircuitClosuresMatroid +from sage.matroids.constructor import Matroid from sage.matroids.linear_matroid import (LinearMatroid, RegularMatroid, BinaryMatroid, TernaryMatroid, QuaternaryMatroid) from sage.matroids.rank_matroid import RankMatroid -from sage.matroids.constructor import Matroid from sage.misc.lazy_import import lazy_import +from sage.rings.integer_ring import ZZ lazy_import('sage.rings.finite_rings.finite_field_constructor', 'GF') lazy_import('sage.schemes.projective.projective_space', 'ProjectiveSpace') @@ -70,13 +65,13 @@ def Q6(): EXAMPLES:: sage: from sage.matroids.advanced import setprint - sage: M = matroids.named_matroids.Q6(); M # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Q6(); M # needs sage.rings.finite_rings Q6: Quaternary matroid of rank 3 on 6 elements - sage: setprint(M.hyperplanes()) # optional - sage.rings.finite_rings + sage: setprint(M.hyperplanes()) # needs sage.rings.finite_rings [{'a', 'b', 'd'}, {'a', 'c'}, {'a', 'e'}, {'a', 'f'}, {'b', 'c', 'e'}, {'b', 'f'}, {'c', 'd'}, {'c', 'f'}, {'d', 'e'}, {'d', 'f'}, {'e', 'f'}] - sage: M.nonspanning_circuits() == M.noncospanning_cocircuits() # optional - sage.rings.finite_rings + sage: M.nonspanning_circuits() == M.noncospanning_cocircuits() # needs sage.rings.finite_rings False """ F = GF(4, 'x') @@ -109,10 +104,10 @@ def P6(): {2: {{'a', 'b', 'c'}}, 3: {{'a', 'b', 'c', 'd', 'e', 'f'}}} sage: len(set(M.nonspanning_circuits()).difference(M.nonbases())) == 0 True - sage: Matroid(matrix=random_matrix(GF(4, 'a'), ncols=5, # optional - sage.rings.finite_rings + sage: Matroid(matrix=random_matrix(GF(4, 'a'), ncols=5, # needs sage.rings.finite_rings ....: nrows=5)).has_minor(M) False - sage: M.is_valid() # optional - sage.rings.finite_rings + sage: M.is_valid() True """ E = 'abcdef' @@ -137,13 +132,13 @@ def R6(): EXAMPLES:: - sage: M = matroids.named_matroids.R6(); M # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.R6(); M R6: Ternary matroid of rank 3 on 6 elements, type 2+ - sage: M.equals(M.dual()) # optional - sage.rings.finite_rings + sage: M.equals(M.dual()) True - sage: M.is_connected() # optional - sage.rings.finite_rings + sage: M.is_connected() True - sage: M.is_3connected() # optional - sage.rings.finite_rings + sage: M.is_3connected() # needs sage.graphs False """ A = Matrix(GF(3), [ @@ -170,12 +165,12 @@ def Fano(): EXAMPLES:: sage: from sage.matroids.advanced import setprint - sage: M = matroids.named_matroids.Fano(); M # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano(); M Fano: Binary matroid of rank 3 on 7 elements, type (3, 0) - sage: setprint(sorted(M.nonspanning_circuits())) # optional - sage.rings.finite_rings + sage: setprint(sorted(M.nonspanning_circuits())) [{'a', 'b', 'f'}, {'a', 'c', 'e'}, {'a', 'd', 'g'}, {'b', 'c', 'd'}, {'b', 'e', 'g'}, {'c', 'f', 'g'}, {'d', 'e', 'f'}] - sage: M.delete(M.groundset_list()[randrange(0, # optional - sage.rings.finite_rings + sage: M.delete(M.groundset_list()[randrange(0, # needs sage.graphs ....: 7)]).is_isomorphic(matroids.CompleteGraphic(4)) True """ @@ -201,14 +196,14 @@ def NonFano(): EXAMPLES:: sage: from sage.matroids.advanced import setprint - sage: M = matroids.named_matroids.NonFano(); M # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.NonFano(); M NonFano: Ternary matroid of rank 3 on 7 elements, type 0- - sage: setprint(M.nonbases()) # optional - sage.rings.finite_rings + sage: setprint(M.nonbases()) [{'a', 'b', 'f'}, {'a', 'c', 'e'}, {'a', 'd', 'g'}, {'b', 'c', 'd'}, {'b', 'e', 'g'}, {'c', 'f', 'g'}] - sage: M.delete('f').is_isomorphic(matroids.CompleteGraphic(4)) # optional - sage.rings.finite_rings + sage: M.delete('f').is_isomorphic(matroids.CompleteGraphic(4)) # needs sage.graphs True - sage: M.delete('g').is_isomorphic(matroids.CompleteGraphic(4)) # optional - sage.rings.finite_rings + sage: M.delete('g').is_isomorphic(matroids.CompleteGraphic(4)) # needs sage.graphs False """ A = Matrix(GF(3), [ @@ -233,11 +228,11 @@ def O7(): EXAMPLES:: - sage: M = matroids.named_matroids.O7(); M # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.O7(); M O7: Ternary matroid of rank 3 on 7 elements, type 0+ - sage: M.delete('e').is_isomorphic(matroids.CompleteGraphic(4)) # optional - sage.rings.finite_rings + sage: M.delete('e').is_isomorphic(matroids.CompleteGraphic(4)) # needs sage.graphs True - sage: M.tutte_polynomial() # optional - sage.rings.finite_rings + sage: M.tutte_polynomial() y^4 + x^3 + x*y^2 + 3*y^3 + 4*x^2 + 5*x*y + 5*y^2 + 4*x + 4*y """ A = Matrix(GF(3), [ @@ -262,13 +257,13 @@ def P7(): EXAMPLES:: - sage: M = matroids.named_matroids.P7(); M # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.P7(); M P7: Ternary matroid of rank 3 on 7 elements, type 1+ - sage: M.f_vector() # optional - sage.rings.finite_rings + sage: M.f_vector() [1, 7, 11, 1] - sage: M.has_minor(matroids.CompleteGraphic(4)) # optional - sage.rings.finite_rings + sage: M.has_minor(matroids.CompleteGraphic(4)) # needs sage.graphs False - sage: M.is_valid() # optional - sage.rings.finite_rings + sage: M.is_valid() True """ A = Matrix(GF(3), [ @@ -302,15 +297,15 @@ def AG32prime(): {'b', 'e', 'g', 'h'}, {'c', 'd', 'e', 'h'}, {'c', 'f', 'g', 'h'}, {'d', 'e', 'f', 'g'}}, 4: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}}} - sage: M.contract('c').is_isomorphic(matroids.named_matroids.Fano()) # optional - sage.rings.finite_rings + sage: M.contract('c').is_isomorphic(matroids.named_matroids.Fano()) True - sage: setprint(M.noncospanning_cocircuits()) # optional - sage.rings.finite_rings + sage: setprint(M.noncospanning_cocircuits()) [{'a', 'b', 'c', 'h'}, {'a', 'b', 'd', 'e'}, {'a', 'b', 'f', 'g'}, {'a', 'c', 'd', 'f'}, {'a', 'd', 'g', 'h'}, {'a', 'e', 'f', 'h'}, {'b', 'c', 'd', 'g'}, {'b', 'c', 'e', 'f'}, {'b', 'd', 'f', 'h'}, {'b', 'e', 'g', 'h'}, {'c', 'd', 'e', 'h'}, {'c', 'f', 'g', 'h'}, {'d', 'e', 'f', 'g'}] - sage: M.is_valid() # long time # optional - sage.rings.finite_rings + sage: M.is_valid() # long time, needs sage.rings.finite_rings True """ E = 'abcdefgh' @@ -335,14 +330,14 @@ def R8(): EXAMPLES:: - sage: M = matroids.named_matroids.R8(); M # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.R8(); M R8: Ternary matroid of rank 4 on 8 elements, type 0+ - sage: M.contract(M.groundset_list()[randrange(0, # optional - sage.rings.finite_rings + sage: M.contract(M.groundset_list()[randrange(0, ....: 8)]).is_isomorphic(matroids.named_matroids.NonFano()) True - sage: M.equals(M.dual()) # optional - sage.rings.finite_rings + sage: M.equals(M.dual()) True - sage: M.has_minor(matroids.named_matroids.Fano()) # optional - sage.rings.finite_rings + sage: M.has_minor(matroids.named_matroids.Fano()) False """ A = Matrix(GF(3), [ @@ -377,11 +372,11 @@ def F8(): ....: for i in M.groundset()]) sage: len(D) 3 - sage: [N.is_isomorphic(matroids.named_matroids.Fano()) for N in D] # optional - sage.rings.finite_rings + sage: [N.is_isomorphic(matroids.named_matroids.Fano()) for N in D] [...True...] - sage: [N.is_isomorphic(matroids.named_matroids.NonFano()) for N in D] # optional - sage.rings.finite_rings + sage: [N.is_isomorphic(matroids.named_matroids.NonFano()) for N in D] [...True...] - sage: M.is_valid() # long time # optional - sage.rings.finite_rings + sage: M.is_valid() # long time, needs sage.rings.finite_rings True """ E = 'abcdefgh' @@ -480,21 +475,21 @@ def S8(): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = matroids.named_matroids.S8(); M # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.S8(); M S8: Binary matroid of rank 4 on 8 elements, type (2, 0) - sage: M.contract('d').is_isomorphic(matroids.named_matroids.Fano()) # optional - sage.rings.finite_rings + sage: M.contract('d').is_isomorphic(matroids.named_matroids.Fano()) True - sage: M.delete('d').is_isomorphic( # optional - sage.rings.finite_rings + sage: M.delete('d').is_isomorphic( ....: matroids.named_matroids.Fano().dual()) False - sage: M.is_graphic() # optional - sage.rings.finite_rings + sage: M.is_graphic() False - sage: D = get_nonisomorphic_matroids( # optional - sage.rings.finite_rings + sage: D = get_nonisomorphic_matroids( ....: list(matroids.named_matroids.Fano().linear_coextensions( ....: cosimple=True))) - sage: len(D) # optional - sage.rings.finite_rings + sage: len(D) 2 - sage: [N.is_isomorphic(M) for N in D] # optional - sage.rings.finite_rings + sage: [N.is_isomorphic(M) for N in D] [...True...] """ @@ -556,13 +551,13 @@ def T8(): EXAMPLES:: - sage: M = matroids.named_matroids.T8(); M # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.T8(); M T8: Ternary matroid of rank 4 on 8 elements, type 0- - sage: M.truncation().is_isomorphic(matroids.Uniform(3, 8)) # optional - sage.rings.finite_rings + sage: M.truncation().is_isomorphic(matroids.Uniform(3, 8)) True - sage: M.contract('e').is_isomorphic(matroids.named_matroids.P7()) # optional - sage.rings.finite_rings + sage: M.contract('e').is_isomorphic(matroids.named_matroids.P7()) True - sage: M.has_minor(matroids.Uniform(3, 8)) # optional - sage.rings.finite_rings + sage: M.has_minor(matroids.Uniform(3, 8)) False """ @@ -588,15 +583,15 @@ def J(): EXAMPLES:: sage: from sage.matroids.advanced import setprint - sage: M = matroids.named_matroids.J(); M # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.J(); M J: Ternary matroid of rank 4 on 8 elements, type 0- - sage: setprint(M.truncation().nonbases()) # optional - sage.rings.finite_rings + sage: setprint(M.truncation().nonbases()) [{'a', 'b', 'f'}, {'a', 'c', 'g'}, {'a', 'd', 'h'}] - sage: M.is_isomorphic(M.dual()) # optional - sage.rings.finite_rings + sage: M.is_isomorphic(M.dual()) True - sage: M.has_minor(matroids.CompleteGraphic(4)) # optional - sage.rings.finite_rings + sage: M.has_minor(matroids.CompleteGraphic(4)) # needs sage.graphs False - sage: M.is_valid() # optional - sage.rings.finite_rings + sage: M.is_valid() True """ A = Matrix(GF(3), [ @@ -622,14 +617,14 @@ def P8(): EXAMPLES:: - sage: M = matroids.named_matroids.P8(); M # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.P8(); M P8: Ternary matroid of rank 4 on 8 elements, type 2+ - sage: M.is_isomorphic(M.dual()) # optional - sage.rings.finite_rings + sage: M.is_isomorphic(M.dual()) True - sage: Matroid(matrix=random_matrix(GF(4, 'a'), ncols=5, # optional - sage.rings.finite_rings + sage: Matroid(matrix=random_matrix(GF(4, 'a'), ncols=5, # needs sage.rings.finite_rings ....: nrows=5)).has_minor(M) False - sage: M.bicycle_dimension() # optional - sage.rings.finite_rings + sage: M.bicycle_dimension() 2 """ @@ -693,14 +688,16 @@ def K33dual(): EXAMPLES:: - sage: M = matroids.named_matroids.K33dual(); M # optional - sage.graphs + sage: M = matroids.named_matroids.K33dual(); M # needs sage.graphs M*(K3, 3): Regular matroid of rank 4 on 9 elements with 81 bases - sage: any(N.is_3connected() # optional - sage.graphs + sage: any(N.is_3connected() # needs sage.graphs ....: for N in M.linear_extensions(simple=True)) False - sage: M.is_valid() # long time # optional - sage.graphs + sage: M.is_valid() # long time, needs sage.graphs True """ + from sage.graphs.graph_generators import graphs + E = 'abcdefghi' G = graphs.CompleteBipartiteGraph(3, 3) M = Matroid(groundset=E, graph=G, regular=True) @@ -722,11 +719,11 @@ def TernaryDowling3(): EXAMPLES:: - sage: M = matroids.named_matroids.TernaryDowling3(); M # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.TernaryDowling3(); M Q3(GF(3)x): Ternary matroid of rank 3 on 9 elements, type 0- - sage: len(list(M.linear_subclasses())) # optional - sage.rings.finite_rings + sage: len(list(M.linear_subclasses())) 72 - sage: M.fundamental_cycle('abc', 'd') # optional - sage.rings.finite_rings + sage: M.fundamental_cycle('abc', 'd') {'a': 2, 'b': 1, 'd': 1} """ @@ -758,19 +755,22 @@ def CompleteGraphic(n): EXAMPLES:: + sage: # needs sage.graphs sage: from sage.matroids.advanced import setprint - sage: M = matroids.CompleteGraphic(5); M # optional - sage.graphs + sage: M = matroids.CompleteGraphic(5); M M(K5): Graphic matroid of rank 4 on 10 elements - sage: M.has_minor(matroids.Uniform(2, 4)) # optional - sage.graphs + sage: M.has_minor(matroids.Uniform(2, 4)) False - sage: simplify(M.contract(randrange(0, # optional - sage.graphs + sage: simplify(M.contract(randrange(0, ....: 10))).is_isomorphic(matroids.CompleteGraphic(4)) True - sage: setprint(M.closure([0, 2, 4, 5])) # optional - sage.graphs + sage: setprint(M.closure([0, 2, 4, 5])) {0, 1, 2, 4, 5, 7} - sage: M.is_valid() # optional - sage.graphs + sage: M.is_valid() True """ + from sage.graphs.graph_generators import graphs + M = Matroid(groundset=list(range((n * (n - 1)) // 2)), graph=graphs.CompleteGraph(n)) M.rename('M(K' + str(n) + '): ' + repr(M)) @@ -805,11 +805,11 @@ def Wheel(n, field=None, ring=None): sage: M.is_valid() True sage: M = matroids.Wheel(3) - sage: M.is_isomorphic(matroids.CompleteGraphic(4)) # optional - sage.graphs + sage: M.is_isomorphic(matroids.CompleteGraphic(4)) # needs sage.graphs True - sage: M.is_isomorphic(matroids.Wheel(3, field=GF(3))) # optional - sage.rings.finite_rings + sage: M.is_isomorphic(matroids.Wheel(3, field=GF(3))) True - sage: M = matroids.Wheel(3, field=GF(3)); M # optional - sage.rings.finite_rings + sage: M = matroids.Wheel(3, field=GF(3)); M Wheel(3): Ternary matroid of rank 3 on 6 elements, type 0+ """ base_ring = ZZ @@ -856,17 +856,17 @@ def Whirl(n): EXAMPLES:: - sage: M = matroids.Whirl(5); M # optional - sage.rings.finite_rings + sage: M = matroids.Whirl(5); M Whirl(5): Ternary matroid of rank 5 on 10 elements, type 0- - sage: M.is_valid() # optional - sage.rings.finite_rings + sage: M.is_valid() True - sage: M.tutte_polynomial() # optional - sage.rings.finite_rings + sage: M.tutte_polynomial() x^5 + y^5 + 5*x^4 + 5*x^3*y + 5*x^2*y^2 + 5*x*y^3 + 5*y^4 + 10*x^3 + 15*x^2*y + 15*x*y^2 + 10*y^3 + 10*x^2 + 15*x*y + 10*y^2 + 5*x + 5*y - sage: M.is_isomorphic(matroids.Wheel(5)) # optional - sage.rings.finite_rings + sage: M.is_isomorphic(matroids.Wheel(5)) False - sage: M = matroids.Whirl(3) # optional - sage.rings.finite_rings - sage: M.is_isomorphic(matroids.CompleteGraphic(4)) # optional - sage.rings.finite_rings + sage: M = matroids.Whirl(3) + sage: M.is_isomorphic(matroids.CompleteGraphic(4)) # needs sage.graphs False .. TODO:: @@ -963,12 +963,12 @@ def PG(n, q, x=None): EXAMPLES:: - sage: M = matroids.PG(2, 2) # optional - sage.rings.finite_rings - sage: M.is_isomorphic(matroids.named_matroids.Fano()) # optional - sage.rings.finite_rings + sage: M = matroids.PG(2, 2) + sage: M.is_isomorphic(matroids.named_matroids.Fano()) True - sage: matroids.PG(5, 4, 'z').size() == (4^6 - 1) / (4 - 1) # optional - sage.rings.finite_rings + sage: matroids.PG(5, 4, 'z').size() == (4^6 - 1) / (4 - 1) # needs sage.rings.finite_rings True - sage: M = matroids.PG(4, 7); M # optional - sage.rings.finite_rings + sage: M = matroids.PG(4, 7); M PG(4, 7): Linear matroid of rank 5 on 2801 elements represented over the Finite Field of size 7 """ @@ -1006,13 +1006,13 @@ def AG(n, q, x=None): EXAMPLES:: - sage: M = matroids.AG(2, 3) \ 8 # optional - sage.rings.finite_rings - sage: M.is_isomorphic(matroids.named_matroids.AG23minus()) # optional - sage.rings.finite_rings + sage: M = matroids.AG(2, 3) \ 8 + sage: M.is_isomorphic(matroids.named_matroids.AG23minus()) True - sage: matroids.AG(5, 4, 'z').size() == ((4 ^ 6 - 1) / (4 - 1) - # optional - sage.rings.finite_rings + sage: matroids.AG(5, 4, 'z').size() == ((4 ^ 6 - 1) / (4 - 1) - # needs sage.rings.finite_rings ....: (4 ^ 5 - 1)/(4 - 1)) True - sage: M = matroids.AG(4, 2); M # optional - sage.rings.finite_rings + sage: M = matroids.AG(4, 2); M AG(4, 2): Binary matroid of rank 5 on 16 elements, type (5, 0) """ @@ -1048,7 +1048,7 @@ def R10(): {4, 6} sage: M.equals(M.dual()) False - sage: M.is_isomorphic(M.dual()) # optional - sage.graphs + sage: M.is_isomorphic(M.dual()) # needs sage.graphs True sage: M.is_valid() True @@ -1086,7 +1086,7 @@ def R12(): R12: Regular matroid of rank 6 on 12 elements with 441 bases sage: M.equals(M.dual()) False - sage: M.is_isomorphic(M.dual()) # optional - sage.graphs + sage: M.is_isomorphic(M.dual()) # needs sage.graphs True sage: M.is_valid() True @@ -1246,10 +1246,10 @@ def Q10(): EXAMPLES:: - sage: M = matroids.named_matroids.Q10() # optional - sage.rings.finite_rings - sage: M.is_isomorphic(M.dual()) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Q10() # needs sage.rings.finite_rings + sage: M.is_isomorphic(M.dual()) # needs sage.rings.finite_rings True - sage: M.is_valid() # optional - sage.rings.finite_rings + sage: M.is_valid() # needs sage.rings.finite_rings True Check the splitter property. By Seymour's Theorem, and using self-duality, @@ -1258,8 +1258,8 @@ def Q10(): are quaternary are `U_{2, 5}, U_{3, 5}, F_7, F_7^*`. As it happens, it suffices to check for `U_{2, 5}`: - sage: S = matroids.named_matroids.Q10().linear_extensions(simple=True) # optional - sage.rings.finite_rings - sage: [M for M in S if not M.has_line_minor(5)] # long time # optional - sage.rings.finite_rings + sage: S = matroids.named_matroids.Q10().linear_extensions(simple=True) # needs sage.rings.finite_rings + sage: [M for M in S if not M.has_line_minor(5)] # long time, needs sage.rings.finite_rings [] """ F = GF(4, 'x') @@ -1284,10 +1284,10 @@ def N1(): EXAMPLES:: - sage: M = matroids.named_matroids.N1() # optional - sage.rings.finite_rings - sage: M.is_field_isomorphic(M.dual()) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.N1() + sage: M.is_field_isomorphic(M.dual()) True - sage: M.is_valid() # optional - sage.rings.finite_rings + sage: M.is_valid() True """ @@ -1311,10 +1311,10 @@ def N2(): EXAMPLES:: - sage: M = matroids.named_matroids.N2() # optional - sage.rings.finite_rings - sage: M.is_field_isomorphic(M.dual()) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.N2() + sage: M.is_field_isomorphic(M.dual()) True - sage: M.is_valid() # optional - sage.rings.finite_rings + sage: M.is_valid() True """ @@ -1369,8 +1369,8 @@ def Block_9_4(): sage: M = matroids.named_matroids.Block_9_4() sage: M.is_valid() # long time True - sage: BD = BlockDesign(M.groundset(), M.nonspanning_circuits()) - sage: BD.is_t_design(return_parameters=True) + sage: BD = BlockDesign(M.groundset(), M.nonspanning_circuits()) # needs sage.graphs + sage: BD.is_t_design(return_parameters=True) # needs sage.graphs (True, (2, 9, 4, 3)) """ E = 'abcdefghi' @@ -1395,8 +1395,8 @@ def Block_10_5(): sage: M = matroids.named_matroids.Block_10_5() sage: M.is_valid() # long time True - sage: BD = BlockDesign(M.groundset(), M.nonspanning_circuits()) - sage: BD.is_t_design(return_parameters=True) + sage: BD = BlockDesign(M.groundset(), M.nonspanning_circuits()) # needs sage.graphs + sage: BD.is_t_design(return_parameters=True) # needs sage.graphs (True, (3, 10, 5, 3)) """ @@ -1425,11 +1425,11 @@ def ExtendedBinaryGolayCode(): EXAMPLES:: - sage: M = matroids.named_matroids.ExtendedBinaryGolayCode() # optional - sage.rings.finite_rings - sage: C = LinearCode(M.representation()) # optional - sage.rings.finite_rings - sage: C.is_permutation_equivalent(codes.GolayCode(GF(2))) # long time # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.ExtendedBinaryGolayCode() + sage: C = LinearCode(M.representation()) + sage: C.is_permutation_equivalent(codes.GolayCode(GF(2))) # long time, needs sage.rings.finite_rings True - sage: M.is_valid() # optional - sage.rings.finite_rings + sage: M.is_valid() True """ A = Matrix(GF(2), [ @@ -1460,11 +1460,11 @@ def ExtendedTernaryGolayCode(): EXAMPLES:: - sage: M = matroids.named_matroids.ExtendedTernaryGolayCode() # optional - sage.rings.finite_rings - sage: C = LinearCode(M.representation()) # optional - sage.rings.finite_rings - sage: C.is_permutation_equivalent(codes.GolayCode(GF(3))) # long time # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.ExtendedTernaryGolayCode() + sage: C = LinearCode(M.representation()) + sage: C.is_permutation_equivalent(codes.GolayCode(GF(3))) # long time, needs sage.rings.finite_rings True - sage: M.is_valid() # optional - sage.rings.finite_rings + sage: M.is_valid() True """ A = Matrix(GF(3), [ @@ -1512,11 +1512,11 @@ def NotP8(): EXAMPLES:: - sage: M = matroids.named_matroids.P8() # optional - sage.rings.finite_rings - sage: N = matroids.named_matroids.NotP8() # optional - sage.rings.finite_rings - sage: M.is_isomorphic(N) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.P8() + sage: N = matroids.named_matroids.NotP8() + sage: M.is_isomorphic(N) False - sage: M.is_valid() # optional - sage.rings.finite_rings + sage: M.is_valid() True """ A = Matrix(GF(3), [ @@ -1541,10 +1541,10 @@ def D16(): # A.K.A. the Carolyn Chun Matroid EXAMPLES:: - sage: M = matroids.named_matroids.D16() # optional - sage.rings.finite_rings - sage: M # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.D16() + sage: M D16: Binary matroid of rank 8 on 16 elements, type (0, 0) - sage: M.is_valid() # optional - sage.rings.finite_rings + sage: M.is_valid() True """ @@ -1572,10 +1572,10 @@ def Terrahawk(): # A.K.A. the Dillon Mayhew Matroid EXAMPLES:: - sage: M = matroids.named_matroids.Terrahawk() # optional - sage.rings.finite_rings - sage: M # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Terrahawk() + sage: M Terrahawk: Binary matroid of rank 8 on 16 elements, type (0, 4) - sage: M.is_valid() # optional - sage.rings.finite_rings + sage: M.is_valid() True """ @@ -1656,10 +1656,10 @@ def T12(): EXAMPLES:: - sage: M = matroids.named_matroids.T12() # optional - sage.rings.finite_rings - sage: M # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.T12() + sage: M T12: Binary matroid of rank 6 on 12 elements, type (2, None) - sage: M.is_valid() # optional - sage.rings.finite_rings + sage: M.is_valid() True """ A = Matrix(GF(2), [ @@ -1684,10 +1684,10 @@ def P9(): EXAMPLES:: - sage: M = matroids.named_matroids.P9() # optional - sage.rings.finite_rings - sage: M # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.P9() + sage: M P9: Binary matroid of rank 4 on 9 elements, type (1, 1) - sage: M.is_valid() # optional - sage.rings.finite_rings + sage: M.is_valid() True """ A = Matrix(GF(2), [ diff --git a/src/sage/matroids/circuit_closures_matroid.pyx b/src/sage/matroids/circuit_closures_matroid.pyx index 3c6200bb48b..402822b2dc6 100644 --- a/src/sage/matroids/circuit_closures_matroid.pyx +++ b/src/sage/matroids/circuit_closures_matroid.pyx @@ -50,8 +50,8 @@ AUTHORS: TESTS:: sage: from sage.matroids.advanced import * - sage: M = CircuitClosuresMatroid(matroids.named_matroids.Fano()) # optional - sage.rings.finite_rings - sage: TestSuite(M).run() # optional - sage.rings.finite_rings + sage: M = CircuitClosuresMatroid(matroids.named_matroids.Fano()) + sage: TestSuite(M).run() Methods ======= @@ -117,8 +117,8 @@ cdef class CircuitClosuresMatroid(Matroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = CircuitClosuresMatroid(matroids.named_matroids.Fano()) # optional - sage.rings.finite_rings - sage: M # optional - sage.rings.finite_rings + sage: M = CircuitClosuresMatroid(matroids.named_matroids.Fano()) + sage: M Matroid of rank 3 on 7 elements with circuit-closures {2: {{'a', 'b', 'f'}, {'a', 'c', 'e'}, {'a', 'd', 'g'}, {'b', 'c', 'd'}, {'b', 'e', 'g'}, {'c', 'f', 'g'}, @@ -127,7 +127,7 @@ cdef class CircuitClosuresMatroid(Matroid): ....: circuit_closures={3: ['edfg', 'acdg', 'bcfg', 'cefh', ....: 'afgh', 'abce', 'abdf', 'begh', 'bcdh', 'adeh'], ....: 4: ['abcdefgh']}) - sage: M.equals(matroids.named_matroids.P8()) # optional - sage.rings.finite_rings + sage: M.equals(matroids.named_matroids.P8()) True """ @@ -140,8 +140,8 @@ cdef class CircuitClosuresMatroid(Matroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = CircuitClosuresMatroid(matroids.named_matroids.Fano()) # optional - sage.rings.finite_rings - sage: M # optional - sage.rings.finite_rings + sage: M = CircuitClosuresMatroid(matroids.named_matroids.Fano()) + sage: M Matroid of rank 3 on 7 elements with circuit-closures {2: {{'a', 'b', 'f'}, {'a', 'c', 'e'}, {'a', 'd', 'g'}, {'b', 'c', 'd'}, {'b', 'e', 'g'}, {'c', 'f', 'g'}, @@ -152,7 +152,7 @@ cdef class CircuitClosuresMatroid(Matroid): ....: circuit_closures={3: ['edfg', 'acdg', 'bcfg', 'cefh', ....: 'afgh', 'abce', 'abdf', 'begh', 'bcdh', 'adeh'], ....: 4: ['abcdefgh']}) - sage: M.equals(matroids.named_matroids.P8()) # optional - sage.rings.finite_rings + sage: M.equals(matroids.named_matroids.P8()) True """ if M is not None: @@ -348,17 +348,17 @@ cdef class CircuitClosuresMatroid(Matroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = CircuitClosuresMatroid(matroids.named_matroids.Fano()) # optional - sage.rings.finite_rings - sage: CC = M.circuit_closures() # optional - sage.rings.finite_rings - sage: len(CC[2]) # optional - sage.rings.finite_rings + sage: M = CircuitClosuresMatroid(matroids.named_matroids.Fano()) + sage: CC = M.circuit_closures() + sage: len(CC[2]) 7 - sage: len(CC[3]) # optional - sage.rings.finite_rings + sage: len(CC[3]) 1 - sage: len(CC[1]) # optional - sage.rings.finite_rings + sage: len(CC[1]) Traceback (most recent call last): ... KeyError: 1 - sage: [sorted(X) for X in CC[3]] # optional - sage.rings.finite_rings + sage: [sorted(X) for X in CC[3]] [['a', 'b', 'c', 'd', 'e', 'f', 'g']] """ return self._circuit_closures @@ -387,16 +387,16 @@ cdef class CircuitClosuresMatroid(Matroid): sage: from sage.matroids.advanced import * sage: M1 = CircuitClosuresMatroid(matroids.Wheel(3)) - sage: M2 = matroids.CompleteGraphic(4) # optional - sage.graphs - sage: M1._is_isomorphic(M2) # optional - sage.graphs + sage: M2 = matroids.CompleteGraphic(4) # needs sage.graphs + sage: M1._is_isomorphic(M2) # needs sage.graphs True - sage: M1._is_isomorphic(M2, certificate=True) # optional - sage.graphs + sage: M1._is_isomorphic(M2, certificate=True) # needs sage.graphs (True, {0: 0, 1: 1, 2: 2, 3: 3, 4: 5, 5: 4}) - sage: M1 = CircuitClosuresMatroid(matroids.named_matroids.Fano()) # optional - sage.rings.finite_rings - sage: M2 = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: M1._is_isomorphic(M2) # optional - sage.rings.finite_rings + sage: M1 = CircuitClosuresMatroid(matroids.named_matroids.Fano()) + sage: M2 = matroids.named_matroids.NonFano() + sage: M1._is_isomorphic(M2) False - sage: M1._is_isomorphic(M2, certificate=True) # optional - sage.rings.finite_rings + sage: M1._is_isomorphic(M2, certificate=True) (False, None) diff --git a/src/sage/matroids/constructor.py b/src/sage/matroids/constructor.py index 12ca5ec2873..acbc4c03d00 100644 --- a/src/sage/matroids/constructor.py +++ b/src/sage/matroids/constructor.py @@ -53,8 +53,8 @@ A number of special matroids are collected under a ``named_matroids`` submenu. To see which, type ``matroids.named_matroids.`` as above:: - sage: F7 = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: len(F7.nonspanning_circuits()) # optional - sage.rings.finite_rings + sage: F7 = matroids.named_matroids.Fano() + sage: len(F7.nonspanning_circuits()) 7 Constructing matroids @@ -68,15 +68,15 @@ EXAMPLES:: - sage: A = Matrix(GF(2), [[1, 0, 0, 0, 1, 1, 1], # optional - sage.rings.finite_rings + sage: A = Matrix(GF(2), [[1, 0, 0, 0, 1, 1, 1], ....: [0, 1, 0, 1, 0, 1, 1], ....: [0, 0, 1, 1, 1, 0, 1]]) - sage: M = Matroid(A) # optional - sage.rings.finite_rings - sage: M.is_isomorphic(matroids.named_matroids.Fano()) # optional - sage.rings.finite_rings + sage: M = Matroid(A) + sage: M.is_isomorphic(matroids.named_matroids.Fano()) True - sage: M = Matroid(graphs.PetersenGraph()) # optional - sage.graphs - sage: M.rank() # optional - sage.graphs + sage: M = Matroid(graphs.PetersenGraph()) # needs sage.graphs + sage: M.rank() # needs sage.graphs 9 AUTHORS: @@ -103,7 +103,6 @@ from itertools import combinations from sage.matrix.constructor import Matrix -from sage.graphs.graph import Graph from sage.structure.element import is_Matrix from sage.rings.integer_ring import ZZ from sage.rings.rational_field import QQ @@ -148,8 +147,8 @@ def Matroid(groundset=None, data=None, **kwds): You will see a list of methods which will construct matroids. For example:: - sage: F7 = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: len(F7.nonspanning_circuits()) # optional - sage.rings.finite_rings + sage: F7 = matroids.named_matroids.Fano() + sage: len(F7.nonspanning_circuits()) 7 or:: @@ -335,44 +334,46 @@ def Matroid(groundset=None, data=None, **kwds): :: - sage: G = graphs.PetersenGraph() # optional - sage.graphs - sage: Matroid(G) # optional - sage.graphs + sage: G = graphs.PetersenGraph() # needs sage.graphs + sage: Matroid(G) # needs sage.graphs Graphic matroid of rank 9 on 15 elements If each edge has a unique label, then those are used as the ground set labels:: - sage: G = Graph([(0, 1, 'a'), (0, 2, 'b'), (1, 2, 'c')]) # optional - sage.graphs - sage: M = Matroid(G) # optional - sage.graphs - sage: sorted(M.groundset()) # optional - sage.graphs + sage: G = Graph([(0, 1, 'a'), (0, 2, 'b'), (1, 2, 'c')]) # needs sage.graphs + sage: M = Matroid(G) # needs sage.graphs + sage: sorted(M.groundset()) # needs sage.graphs ['a', 'b', 'c'] If there are parallel edges, then integers are used for the ground set. If there are no edges in parallel, and is not a complete list of labels, or the labels are not unique, then vertex tuples are used:: - sage: G = Graph([(0, 1, 'a'), (0, 2, 'b'), (1, 2, 'b')]) # optional - sage.graphs - sage: M = Matroid(G) # optional - sage.graphs - sage: sorted(M.groundset()) # optional - sage.graphs + sage: # needs sage.graphs + sage: G = Graph([(0, 1, 'a'), (0, 2, 'b'), (1, 2, 'b')]) + sage: M = Matroid(G) + sage: sorted(M.groundset()) [(0, 1), (0, 2), (1, 2)] - sage: H = Graph([(0, 1, 'a'), (0, 2, 'b'), (1, 2, 'b'), (1, 2, 'c')], # optional - sage.graphs + sage: H = Graph([(0, 1, 'a'), (0, 2, 'b'), (1, 2, 'b'), (1, 2, 'c')], ....: multiedges=True) - sage: N = Matroid(H) # optional - sage.graphs - sage: sorted(N.groundset()) # optional - sage.graphs + sage: N = Matroid(H) + sage: sorted(N.groundset()) [0, 1, 2, 3] The GraphicMatroid object forces its graph to be connected. If a disconnected graph is used as input, it will connect the components:: - sage: G1 = graphs.CycleGraph(3); G2 = graphs.DiamondGraph() # optional - sage.graphs - sage: G = G1.disjoint_union(G2) # optional - sage.graphs - sage: M = Matroid(G); M # optional - sage.graphs + sage: # needs sage.graphs + sage: G1 = graphs.CycleGraph(3); G2 = graphs.DiamondGraph() + sage: G = G1.disjoint_union(G2) + sage: M = Matroid(G); M Graphic matroid of rank 5 on 8 elements - sage: M.graph() # optional - sage.graphs + sage: M.graph() Looped multi-graph on 6 vertices - sage: M.graph().is_connected() # optional - sage.graphs + sage: M.graph().is_connected() True - sage: M.is_connected() # optional - sage.graphs + sage: M.is_connected() False @@ -381,8 +382,8 @@ def Matroid(groundset=None, data=None, **kwds): :: - sage: G = Graph([(0, 1), (0, 2), (1, 2)]) # optional - sage.graphs - sage: M = Matroid(G, regular=True); M # optional - sage.graphs + sage: G = Graph([(0, 1), (0, 2), (1, 2)]) # needs sage.graphs + sage: M = Matroid(G, regular=True); M # needs sage.graphs Regular matroid of rank 2 on 3 elements with 3 bases Note: if a groundset is specified, we assume it is in the same order @@ -390,9 +391,9 @@ def Matroid(groundset=None, data=None, **kwds): :meth:`G.edge_iterator() ` provides:: - sage: G = Graph([(0, 1), (0, 2), (0, 2), (1, 2)], multiedges=True) # optional - sage.graphs - sage: M = Matroid('abcd', G) # optional - sage.graphs - sage: M.rank(['b', 'c']) # optional - sage.graphs + sage: G = Graph([(0, 1), (0, 2), (0, 2), (1, 2)], multiedges=True) # needs sage.graphs + sage: M = Matroid('abcd', G) # needs sage.graphs + sage: M.rank(['b', 'c']) # needs sage.graphs 1 As before, @@ -400,14 +401,14 @@ def Matroid(groundset=None, data=None, **kwds): tuples ``(i, j)`` of endpoints. If that fails, we simply use a list ``[0..m-1]`` :: - sage: G = Graph([(0, 1), (0, 2), (1, 2)]) # optional - sage.graphs - sage: M = Matroid(G, regular=True) # optional - sage.graphs - sage: sorted(M.groundset()) # optional - sage.graphs + sage: G = Graph([(0, 1), (0, 2), (1, 2)]) # needs sage.graphs + sage: M = Matroid(G, regular=True) # needs sage.graphs + sage: sorted(M.groundset()) # needs sage.graphs [(0, 1), (0, 2), (1, 2)] - sage: G = Graph([(0, 1), (0, 2), (0, 2), (1, 2)], multiedges=True) # optional - sage.graphs - sage: M = Matroid(G, regular=True) # optional - sage.graphs - sage: sorted(M.groundset()) # optional - sage.graphs + sage: G = Graph([(0, 1), (0, 2), (0, 2), (1, 2)], multiedges=True) # needs sage.graphs + sage: M = Matroid(G, regular=True) # needs sage.graphs + sage: sorted(M.groundset()) # needs sage.graphs [0, 1, 2, 3] When the ``graph`` keyword is used, a variety of inputs can be @@ -415,12 +416,12 @@ def Matroid(groundset=None, data=None, **kwds): (see the :class:`Graph ` method's documentation):: - sage: Matroid(graph=':I`AKGsaOs`cI]Gb~') # optional - sage.graphs + sage: Matroid(graph=':I`AKGsaOs`cI]Gb~') # needs sage.graphs Graphic matroid of rank 9 on 17 elements However, this method is no more clever than ``Graph()``:: - sage: Matroid(graph=41/2) # optional - sage.graphs + sage: Matroid(graph=41/2) # needs sage.graphs Traceback (most recent call last): ... ValueError: This input cannot be turned into a graph @@ -430,31 +431,31 @@ def Matroid(groundset=None, data=None, **kwds): The basic input is a :mod:`Sage matrix `:: - sage: A = Matrix(GF(2), [[1, 0, 0, 1, 1, 0], # optional - sage.rings.finite_rings + sage: A = Matrix(GF(2), [[1, 0, 0, 1, 1, 0], ....: [0, 1, 0, 1, 0, 1], ....: [0, 0, 1, 0, 1, 1]]) - sage: M = Matroid(matrix=A) # optional - sage.rings.finite_rings - sage: M.is_isomorphic(matroids.CompleteGraphic(4)) # optional - sage.graphs sage.rings.finite_rings + sage: M = Matroid(matrix=A) + sage: M.is_isomorphic(matroids.CompleteGraphic(4)) # needs sage.graphs True Various shortcuts are possible:: - sage: M1 = Matroid(matrix=[[1, 0, 0, 1, 1, 0], # optional - sage.rings.finite_rings + sage: M1 = Matroid(matrix=[[1, 0, 0, 1, 1, 0], ....: [0, 1, 0, 1, 0, 1], ....: [0, 0, 1, 0, 1, 1]], ring=GF(2)) - sage: M2 = Matroid(reduced_matrix=[[1, 1, 0], # optional - sage.rings.finite_rings + sage: M2 = Matroid(reduced_matrix=[[1, 1, 0], ....: [1, 0, 1], ....: [0, 1, 1]], ring=GF(2)) - sage: M3 = Matroid(groundset=[0, 1, 2, 3, 4, 5], # optional - sage.rings.finite_rings + sage: M3 = Matroid(groundset=[0, 1, 2, 3, 4, 5], ....: matrix=[[1, 1, 0], [1, 0, 1], [0, 1, 1]], ....: ring=GF(2)) - sage: A = Matrix(GF(2), [[1, 1, 0], [1, 0, 1], [0, 1, 1]]) # optional - sage.rings.finite_rings - sage: M4 = Matroid([0, 1, 2, 3, 4, 5], A) # optional - sage.rings.finite_rings - sage: M1 == M2 # optional - sage.rings.finite_rings + sage: A = Matrix(GF(2), [[1, 1, 0], [1, 0, 1], [0, 1, 1]]) + sage: M4 = Matroid([0, 1, 2, 3, 4, 5], A) + sage: M1 == M2 True - sage: M1 == M3 # optional - sage.rings.finite_rings + sage: M1 == M3 True - sage: M1 == M4 # optional - sage.rings.finite_rings + sage: M1 == M4 True However, with unnamed arguments the input has to be a ``Matrix`` @@ -469,36 +470,36 @@ def Matroid(groundset=None, data=None, **kwds): identity matrix is prepended. Otherwise the groundset size must equal the number of columns:: - sage: A = Matrix(GF(2), [[1, 1, 0], [1, 0, 1], [0, 1, 1]]) # optional - sage.rings.finite_rings - sage: M = Matroid([0, 1, 2], A) # optional - sage.rings.finite_rings - sage: N = Matroid([0, 1, 2, 3, 4, 5], A) # optional - sage.rings.finite_rings - sage: M.rank() # optional - sage.rings.finite_rings + sage: A = Matrix(GF(2), [[1, 1, 0], [1, 0, 1], [0, 1, 1]]) + sage: M = Matroid([0, 1, 2], A) + sage: N = Matroid([0, 1, 2, 3, 4, 5], A) + sage: M.rank() 2 - sage: N.rank() # optional - sage.rings.finite_rings + sage: N.rank() 3 We automatically create an optimized subclass, if available:: - sage: Matroid([0, 1, 2, 3, 4, 5], # optional - sage.rings.finite_rings + sage: Matroid([0, 1, 2, 3, 4, 5], ....: matrix=[[1, 1, 0], [1, 0, 1], [0, 1, 1]], ....: field=GF(2)) Binary matroid of rank 3 on 6 elements, type (2, 7) - sage: Matroid([0, 1, 2, 3, 4, 5], # optional - sage.rings.finite_rings + sage: Matroid([0, 1, 2, 3, 4, 5], ....: matrix=[[1, 1, 0], [1, 0, 1], [0, 1, 1]], ....: field=GF(3)) Ternary matroid of rank 3 on 6 elements, type 0- - sage: Matroid([0, 1, 2, 3, 4, 5], # optional - sage.rings.finite_rings + sage: Matroid([0, 1, 2, 3, 4, 5], # needs sage.rings.finite_rings ....: matrix=[[1, 1, 0], [1, 0, 1], [0, 1, 1]], ....: field=GF(4, 'x')) Quaternary matroid of rank 3 on 6 elements - sage: Matroid([0, 1, 2, 3, 4, 5], # optional - sage.rings.finite_rings + sage: Matroid([0, 1, 2, 3, 4, 5], # needs sage.graphs ....: matrix=[[1, 1, 0], [1, 0, 1], [0, 1, 1]], ....: field=GF(2), regular=True) Regular matroid of rank 3 on 6 elements with 16 bases Otherwise the generic LinearMatroid class is used:: - sage: Matroid([0, 1, 2, 3, 4, 5], # optional - sage.rings.finite_rings + sage: Matroid([0, 1, 2, 3, 4, 5], ....: matrix=[[1, 1, 0], [1, 0, 1], [0, 1, 1]], ....: field=GF(83)) Linear matroid of rank 3 on 6 elements represented over the Finite @@ -545,7 +546,7 @@ def Matroid(groundset=None, data=None, **kwds): sage: M = Matroid(circuit_closures=[(2, 'abd'), (3, 'abcdef'), ....: (2, 'bce')]) - sage: M.equals(matroids.named_matroids.Q6()) + sage: M.equals(matroids.named_matroids.Q6()) # needs sage.rings.finite_rings True #. RevLex-Index: @@ -592,60 +593,59 @@ def Matroid(groundset=None, data=None, **kwds): Most of the time, the matroid itself is returned:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: N = Matroid(M) # optional - sage.rings.finite_rings - sage: N is M # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: N = Matroid(M) + sage: N is M True But it can be useful with the ``regular`` option:: sage: M = Matroid(circuit_closures={2:['adb', 'bec', 'cfa', ....: 'def'], 3:['abcdef']}) - sage: N = Matroid(M, regular=True) - sage: N + sage: N = Matroid(M, regular=True); N # needs sage.graphs Regular matroid of rank 3 on 6 elements with 16 bases - sage: M == N + sage: M == N # needs sage.graphs False - sage: M.is_isomorphic(N) + sage: M.is_isomorphic(N) # needs sage.graphs True - sage: Matrix(N) # random + sage: Matrix(N) # random # needs sage.graphs [1 0 0 1 1 0] [0 1 0 1 1 1] [0 0 1 0 1 1] The ``regular`` option:: - sage: M = Matroid(reduced_matrix=[[1, 1, 0], # optional - sage.graphs + sage: M = Matroid(reduced_matrix=[[1, 1, 0], # needs sage.graphs ....: [1, 0, 1], ....: [0, 1, 1]], regular=True); M Regular matroid of rank 3 on 6 elements with 16 bases - sage: M.is_isomorphic(matroids.CompleteGraphic(4)) + sage: M.is_isomorphic(matroids.CompleteGraphic(4)) # needs sage.graphs True By default we check if the resulting matroid is actually regular. To increase speed, this check can be skipped:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: N = Matroid(M, regular=True) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: N = Matroid(M, regular=True) # needs sage.graphs Traceback (most recent call last): ... ValueError: input is not a valid regular matroid - sage: N = Matroid(M, regular=True, check=False); N # optional - sage.rings.finite_rings + sage: N = Matroid(M, regular=True, check=False); N # needs sage.graphs Regular matroid of rank 3 on 7 elements with 32 bases - sage: N.is_valid() # optional - sage.rings.finite_rings + sage: N.is_valid() # needs sage.graphs False Sometimes the output is regular, but represents a different matroid from the one you intended:: - sage: M = Matroid(Matrix(GF(3), [[1, 0, 1, 1], [0, 1, 1, 2]])) # optional - sage.rings.finite_rings - sage: N = Matroid(Matrix(GF(3), [[1, 0, 1, 1], [0, 1, 1, 2]]), # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(3), [[1, 0, 1, 1], [0, 1, 1, 2]])) + sage: N = Matroid(Matrix(GF(3), [[1, 0, 1, 1], [0, 1, 1, 2]]), # needs sage.graphs ....: regular=True) - sage: N.is_valid() # optional - sage.rings.finite_rings + sage: N.is_valid() # needs sage.graphs True - sage: N.is_isomorphic(M) # optional - sage.rings.finite_rings + sage: N.is_isomorphic(M) # needs sage.graphs False TESTS:: @@ -710,7 +710,11 @@ def Matroid(groundset=None, data=None, **kwds): groundset = None if key is None: - if isinstance(data, sage.graphs.graph.Graph): + try: + from sage.graphs.graph import Graph + except ImportError: + Graph = () + if isinstance(data, Graph): key = 'graph' elif is_Matrix(data): key = 'matrix' @@ -771,6 +775,8 @@ def Matroid(groundset=None, data=None, **kwds): # Graphs: elif key == 'graph': + from sage.graphs.graph import Graph + if isinstance(data, sage.graphs.generic_graph.GenericGraph): G = data else: diff --git a/src/sage/matroids/dual_matroid.py b/src/sage/matroids/dual_matroid.py index 87dfdda88d0..804e43f035b 100644 --- a/src/sage/matroids/dual_matroid.py +++ b/src/sage/matroids/dual_matroid.py @@ -10,13 +10,13 @@ EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: N = M.dual() # optional - sage.rings.finite_rings - sage: M.is_basis('abc') # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: N = M.dual() + sage: M.is_basis('abc') True - sage: N.is_basis('defg') # optional - sage.rings.finite_rings + sage: N.is_basis('defg') True - sage: M.dual().dual() == M # optional - sage.rings.finite_rings + sage: M.dual().dual() == M True Implementation @@ -455,17 +455,17 @@ def __eq__(self, other): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M1 = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M2 = CircuitClosuresMatroid(M1.dual()) # optional - sage.rings.finite_rings - sage: M3 = CircuitClosuresMatroid(M1).dual() # optional - sage.rings.finite_rings + sage: M1 = matroids.named_matroids.Fano() + sage: M2 = CircuitClosuresMatroid(M1.dual()) + sage: M3 = CircuitClosuresMatroid(M1).dual() sage: M4 = CircuitClosuresMatroid(groundset='abcdefg', ....: circuit_closures={3: ['abcdefg'], 2: ['beg', 'cdb', 'cfg', ....: 'ace', 'fed', 'gad', 'fab']}).dual() - sage: M1.dual() == M2 # indirect doctest # optional - sage.rings.finite_rings + sage: M1.dual() == M2 # indirect doctest False - sage: M2 == M3 # optional - sage.rings.finite_rings + sage: M2 == M3 False - sage: M3 == M4 # optional - sage.rings.finite_rings + sage: M3 == M4 True """ if not isinstance(other, DualMatroid): @@ -487,17 +487,17 @@ def __ne__(self, other): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M1 = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M2 = CircuitClosuresMatroid(M1.dual()) # optional - sage.rings.finite_rings - sage: M3 = CircuitClosuresMatroid(M1).dual() # optional - sage.rings.finite_rings + sage: M1 = matroids.named_matroids.Fano() + sage: M2 = CircuitClosuresMatroid(M1.dual()) + sage: M3 = CircuitClosuresMatroid(M1).dual() sage: M4 = CircuitClosuresMatroid(groundset='abcdefg', ....: circuit_closures={3: ['abcdefg'], 2: ['beg', 'cdb', 'cfg', ....: 'ace', 'fed', 'gad', 'fab']}).dual() - sage: M1.dual() != M2 # indirect doctest # optional - sage.rings.finite_rings + sage: M1.dual() != M2 # indirect doctest True - sage: M2 != M3 # optional - sage.rings.finite_rings + sage: M2 != M3 True - sage: M3 != M4 # optional - sage.rings.finite_rings + sage: M3 != M4 False """ return not self == other diff --git a/src/sage/matroids/extension.pyx b/src/sage/matroids/extension.pyx index d9888c40036..6043b69077c 100644 --- a/src/sage/matroids/extension.pyx +++ b/src/sage/matroids/extension.pyx @@ -59,7 +59,7 @@ cdef class CutNode: EXAMPLES:: - sage: len(list(matroids.named_matroids.Fano().linear_subclasses())) # indirect doctest # optional - sage.rings.finite_rings + sage: len(list(matroids.named_matroids.Fano().linear_subclasses())) # indirect doctest 16 """ cdef CutNode node diff --git a/src/sage/matroids/graphic_matroid.py b/src/sage/matroids/graphic_matroid.py index b20d538030e..5216ef11517 100644 --- a/src/sage/matroids/graphic_matroid.py +++ b/src/sage/matroids/graphic_matroid.py @@ -89,12 +89,10 @@ # **************************************************************************** from .matroid import Matroid -from sage.graphs.graph import Graph from copy import copy, deepcopy from .utilities import newlabel, split_vertex, sanitize_contractions_deletions from itertools import combinations from sage.rings.integer import Integer -from sage.sets.disjoint_set import DisjointSet class GraphicMatroid(Matroid): @@ -186,6 +184,7 @@ def __init__(self, G, groundset=None): running ._test_not_implemented_methods() . . . pass running ._test_pickling() . . . pass """ + from sage.graphs.graph import Graph if groundset is None: # Try to construct a ground set based on the edge labels. @@ -284,6 +283,8 @@ def _rank(self, X): 1 """ + from sage.sets.disjoint_set import DisjointSet + edges = self.groundset_to_edges(X) vertices = set([u for (u, v, l) in edges]).union( [v for (u, v, l) in edges]) @@ -713,6 +714,8 @@ def _corank(self, X): sage: M._corank([1,2,3]) 3 """ + from sage.sets.disjoint_set import DisjointSet + all_vertices = self._G.vertices(sort=False) not_our_edges = self.groundset_to_edges(self._groundset.difference(X)) DS_vertices = DisjointSet(all_vertices) @@ -826,6 +829,8 @@ def _max_independent(self, X): sage: sorted(N._max_independent(frozenset(['a']))) [] """ + from sage.sets.disjoint_set import DisjointSet + edges = self.groundset_to_edges(X) vertices = set([u for (u, v, l) in edges]) vertices.update([v for (u, v, l) in edges]) @@ -861,6 +866,8 @@ def _max_coindependent(self, X): sage: sorted(N.max_coindependent([0,1,2,5])) [1, 2, 5] """ + from sage.sets.disjoint_set import DisjointSet + edges = self.groundset_to_edges(X) all_vertices = self._G.vertices(sort=False) not_our_edges = self.groundset_to_edges(self._groundset.difference(X)) @@ -924,6 +931,8 @@ def _circuit(self, X): [4, 5] """ + from sage.sets.disjoint_set import DisjointSet + edges = self.groundset_to_edges(X) vertices = set([u for (u, v, l) in edges]).union( set([v for (u, v, l) in edges])) diff --git a/src/sage/matroids/linear_matroid.pyx b/src/sage/matroids/linear_matroid.pyx index e9816dde7cf..30bca7bea29 100644 --- a/src/sage/matroids/linear_matroid.pyx +++ b/src/sage/matroids/linear_matroid.pyx @@ -21,25 +21,25 @@ See also :mod:`sage.matroids.advanced`. In both cases, it is possible to provide a reduced matrix `B`, to create the matroid induced by `A = [ I B ]`:: sage: from sage.matroids.advanced import * - sage: A = Matrix(GF(2), [[1, 0, 0, 1, 1, 0, 1], [0, 1, 0, 1, 0, 1, 1], # optional - sage.rings.finite_rings + sage: A = Matrix(GF(2), [[1, 0, 0, 1, 1, 0, 1], [0, 1, 0, 1, 0, 1, 1], ....: [0, 0, 1, 0, 1, 1, 1]]) - sage: B = Matrix(GF(2), [[1, 1, 0, 1], [1, 0, 1, 1], [0, 1, 1, 1]]) # optional - sage.rings.finite_rings - sage: M1 = Matroid(A) # optional - sage.rings.finite_rings - sage: M2 = LinearMatroid(A) # optional - sage.rings.finite_rings - sage: M3 = BinaryMatroid(A) # optional - sage.rings.finite_rings - sage: M4 = Matroid(reduced_matrix=B) # optional - sage.rings.finite_rings - sage: M5 = LinearMatroid(reduced_matrix=B) # optional - sage.rings.finite_rings - sage: isinstance(M1, BinaryMatroid) # optional - sage.rings.finite_rings + sage: B = Matrix(GF(2), [[1, 1, 0, 1], [1, 0, 1, 1], [0, 1, 1, 1]]) + sage: M1 = Matroid(A) + sage: M2 = LinearMatroid(A) + sage: M3 = BinaryMatroid(A) + sage: M4 = Matroid(reduced_matrix=B) + sage: M5 = LinearMatroid(reduced_matrix=B) + sage: isinstance(M1, BinaryMatroid) True - sage: M1.equals(M2) # optional - sage.rings.finite_rings + sage: M1.equals(M2) True - sage: M1.equals(M3) # optional - sage.rings.finite_rings + sage: M1.equals(M3) True - sage: M1 == M4 # optional - sage.rings.finite_rings + sage: M1 == M4 True - sage: M1.is_field_isomorphic(M5) # optional - sage.rings.finite_rings + sage: M1.is_field_isomorphic(M5) True - sage: M2 == M3 # comparing LinearMatroid and BinaryMatroid always yields False # optional - sage.rings.finite_rings + sage: M2 == M3 # comparing LinearMatroid and BinaryMatroid always yields False False Class methods @@ -241,22 +241,22 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: A = Matrix(GF(3), 2, 4, [[1, 0, 1, 1], [0, 1, 1, 2]]) # optional - sage.rings.finite_rings - sage: M = LinearMatroid(A) # optional - sage.rings.finite_rings - sage: M # optional - sage.rings.finite_rings + sage: A = Matrix(GF(3), 2, 4, [[1, 0, 1, 1], [0, 1, 1, 2]]) + sage: M = LinearMatroid(A) + sage: M Linear matroid of rank 2 on 4 elements represented over the Finite Field of size 3 - sage: sorted(M.groundset()) # optional - sage.rings.finite_rings + sage: sorted(M.groundset()) [0, 1, 2, 3] - sage: Matrix(M) # optional - sage.rings.finite_rings + sage: Matrix(M) [1 0 1 1] [0 1 1 2] - sage: M = LinearMatroid(A, 'abcd') # optional - sage.rings.finite_rings - sage: sorted(M.groundset()) # optional - sage.rings.finite_rings + sage: M = LinearMatroid(A, 'abcd') + sage: sorted(M.groundset()) ['a', 'b', 'c', 'd'] - sage: B = Matrix(GF(3), 2, 2, [[1, 1], [1, 2]]) # optional - sage.rings.finite_rings - sage: N = LinearMatroid(reduced_matrix=B, groundset='abcd') # optional - sage.rings.finite_rings - sage: M == N # optional - sage.rings.finite_rings + sage: B = Matrix(GF(3), 2, 2, [[1, 1], [1, 2]]) + sage: N = LinearMatroid(reduced_matrix=B, groundset='abcd') + sage: M == N True """ def __init__(self, matrix=None, groundset=None, reduced_matrix=None, ring=None, keep_initial_representation=True): @@ -266,7 +266,7 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: LinearMatroid(matrix=Matrix(GF(5), [[1, 0, 1, 1, 1], # indirect doctest, optional - sage.rings.finite_rings + sage: LinearMatroid(matrix=Matrix(GF(5), [[1, 0, 1, 1, 1], # indirect doctest ....: [0, 1, 1, 2, 3]])) Linear matroid of rank 2 on 5 elements represented over the Finite Field of size 5 @@ -289,7 +289,7 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = LinearMatroid(matrix=Matrix(GF(5), [[1, 0, 1, 1, 1], # indirect doctest, optional - sage.rings.finite_rings + sage: M = LinearMatroid(matrix=Matrix(GF(5), [[1, 0, 1, 1, 1], # indirect doctest ....: [0, 1, 1, 2, 3]])) sage: M = None """ @@ -355,11 +355,11 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = LinearMatroid(matrix=Matrix(GF(5), [[1, 1, 0, 1, 1], # optional - sage.rings.finite_rings + sage: M = LinearMatroid(matrix=Matrix(GF(5), [[1, 1, 0, 1, 1], ....: [0, 1, 1, 2, 3]])) - sage: A = Matrix(M) # optional - sage.rings.finite_rings - sage: M._forget() # optional - sage.rings.finite_rings - sage: A == Matrix(M) # optional - sage.rings.finite_rings + sage: A = Matrix(M) + sage: M._forget() + sage: A == Matrix(M) False """ self._representation = None @@ -370,9 +370,9 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(matrix=Matrix(GF(5), [[1, 0, 1, 1, 1], # optional - sage.rings.finite_rings + sage: M = Matroid(matrix=Matrix(GF(5), [[1, 0, 1, 1, 1], ....: [0, 1, 1, 2, 3]])) - sage: M.base_ring() # optional - sage.rings.finite_rings + sage: M.base_ring() Finite Field of size 5 """ return self._A.base_ring() @@ -384,9 +384,9 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(matrix=Matrix(GF(5), [[1, 0, 1, 1, 1], # optional - sage.rings.finite_rings + sage: M = Matroid(matrix=Matrix(GF(5), [[1, 0, 1, 1, 1], ....: [0, 1, 1, 2, 3]])) - sage: M.characteristic() # optional - sage.rings.finite_rings + sage: M.characteristic() 5 """ return characteristic(self._A) @@ -442,13 +442,13 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(matrix=Matrix(GF(5), [[1, 1, 0, 1, 1], # optional - sage.rings.finite_rings + sage: M = Matroid(matrix=Matrix(GF(5), [[1, 1, 0, 1, 1], ....: [0, 1, 1, 2, 3]])) - sage: M._matrix_() # optional - sage.rings.finite_rings + sage: M._matrix_() [1 1 0 1 1] [0 1 1 2 3] - sage: M._forget() # optional - sage.rings.finite_rings - sage: M._matrix_() # optional - sage.rings.finite_rings + sage: M._forget() + sage: M._matrix_() [1 0 4 4 3] [0 1 1 2 3] """ @@ -460,9 +460,9 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(matrix=Matrix(GF(5), [[1, 1, 0, 1, 1], # optional - sage.rings.finite_rings + sage: M = Matroid(matrix=Matrix(GF(5), [[1, 1, 0, 1, 1], ....: [0, 1, 1, 2, 3]])) - sage: repr(M) # indirect doctest # optional - sage.rings.finite_rings + sage: repr(M) # indirect doctest 'Linear matroid of rank 2 on 5 elements represented over the Finite Field of size 5' """ @@ -538,44 +538,44 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M.representation() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M.representation() [1 0 0 0 1 1 1] [0 1 0 1 0 1 1] [0 0 1 1 1 0 1] - sage: Matrix(M) == M.representation() # optional - sage.rings.finite_rings + sage: Matrix(M) == M.representation() True - sage: M.representation(labels=True) # optional - sage.rings.finite_rings + sage: M.representation(labels=True) ( [1 0 0 0 1 1 1] [0 1 0 1 0 1 1] [0 0 1 1 1 0 1], ['a', 'b', 'c', 'd', 'e', 'f', 'g'] ) - sage: M.representation(B='efg') # optional - sage.rings.finite_rings + sage: M.representation(B='efg') [1 1 0 1 1 0 0] [1 0 1 1 0 1 0] [1 1 1 0 0 0 1] - sage: M.representation(B='efg', order='efgabcd') # optional - sage.rings.finite_rings + sage: M.representation(B='efg', order='efgabcd') [1 0 0 1 1 0 1] [0 1 0 1 0 1 1] [0 0 1 1 1 1 0] - sage: M.representation(B='abc', reduced=True) # optional - sage.rings.finite_rings + sage: M.representation(B='abc', reduced=True) ( [0 1 1 1] [1 0 1 1] [1 1 0 1], ['a', 'b', 'c'], ['d', 'e', 'f', 'g'] ) - sage: M.representation(B='efg', reduced=True, labels=False, # optional - sage.rings.finite_rings + sage: M.representation(B='efg', reduced=True, labels=False, ....: order='gfeabcd') [1 1 1 0] [1 0 1 1] [1 1 0 1] sage: from sage.matroids.advanced import lift_cross_ratios, lift_map, LinearMatroid - sage: R = GF(7) # optional - sage.rings.finite_rings - sage: A = Matrix(R, [[1, 0, 6, 1, 2],[6, 1, 0, 0, 1],[0, 6, 3, 6, 0]]) # optional - sage.rings.finite_rings - sage: M = LinearMatroid(reduced_matrix=A) # optional - sage.rings.finite_rings - sage: M.representation(lift_map=lift_map('sru')) # optional - sage.rings.finite_rings + sage: R = GF(7) + sage: A = Matrix(R, [[1, 0, 6, 1, 2],[6, 1, 0, 0, 1],[0, 6, 3, 6, 0]]) + sage: M = LinearMatroid(reduced_matrix=A) + sage: M.representation(lift_map=lift_map('sru')) # needs sage.rings.finite_rings [ 1 0 0 1 0 1 1 1] [ 0 1 0 -z + 1 1 0 0 1] [ 0 0 1 0 -z z 1 0] @@ -667,13 +667,13 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: A = M._reduced_representation('efg') # optional - sage.rings.finite_rings - sage: R, C = M._current_rows_cols() # optional - sage.rings.finite_rings - sage: (sorted(R), sorted(C)) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: A = M._reduced_representation('efg') + sage: R, C = M._current_rows_cols() + sage: (sorted(R), sorted(C)) (['e', 'f', 'g'], ['a', 'b', 'c', 'd']) - sage: R, C = M._current_rows_cols(B='abg') # optional - sage.rings.finite_rings - sage: (sorted(R), sorted(C)) # optional - sage.rings.finite_rings + sage: R, C = M._current_rows_cols(B='abg') + sage: (sorted(R), sorted(C)) (['a', 'b', 'g'], ['c', 'd', 'e', 'f']) """ @@ -712,12 +712,12 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(reduced_matrix=Matrix(GF(7), [[1, 1, 1], # optional - sage.rings.finite_rings + sage: M = Matroid(reduced_matrix=Matrix(GF(7), [[1, 1, 1], ....: [1, 2, 3]])) - sage: M._basic_representation() # optional - sage.rings.finite_rings + sage: M._basic_representation() LeanMatrix instance with 2 rows and 5 columns over Finite Field of size 7 - sage: matrix(M._basic_representation([3, 4])) # optional - sage.rings.finite_rings + sage: matrix(M._basic_representation([3, 4])) [3 6 2 1 0] [5 1 6 0 1] @@ -748,9 +748,9 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: E = M.groundset_list() # optional - sage.rings.finite_rings - sage: [M.representation_vectors()[e] for e in E] # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: E = M.groundset_list() + sage: [M.representation_vectors()[e] for e in E] [(1, 0, 0), (0, 1, 0), (0, 0, 1), (0, 1, 1), (1, 0, 1), (1, 1, 0), (1, 1, 1)] """ @@ -781,12 +781,12 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(reduced_matrix=Matrix(GF(7), [[1, 1, 1], # optional - sage.rings.finite_rings + sage: M = Matroid(reduced_matrix=Matrix(GF(7), [[1, 1, 1], ....: [1, 2, 3]])) - sage: M._reduced_representation() # optional - sage.rings.finite_rings + sage: M._reduced_representation() LeanMatrix instance with 2 rows and 3 columns over Finite Field of size 7 - sage: matrix(M._reduced_representation([3, 4])) # optional - sage.rings.finite_rings + sage: matrix(M._reduced_representation([3, 4])) [2 3 6] [6 5 1] """ @@ -819,10 +819,10 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = matroids.named_matroids.Fano() \ ['g'] # optional - sage.rings.finite_rings - sage: N = BinaryMatroid(Matrix(matroids.Wheel(3))) # optional - sage.rings.finite_rings - sage: morphism = {'a':0, 'b':1, 'c': 2, 'd':4, 'e':5, 'f':3} # optional - sage.rings.finite_rings - sage: M._is_field_isomorphism(N, morphism) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() \ ['g'] + sage: N = BinaryMatroid(Matrix(matroids.Wheel(3))) + sage: morphism = {'a':0, 'b':1, 'c': 2, 'd':4, 'e':5, 'f':3} + sage: M._is_field_isomorphism(N, morphism) True """ # TODO: ensure this is safe for noncommutative rings @@ -911,48 +911,48 @@ cdef class LinearMatroid(BasisExchangeMatroid): yields ``False``, even if the matroids are equal:: sage: from sage.matroids.advanced import * - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M1 = LinearMatroid(Matrix(M), groundset=M.groundset_list()) # optional - sage.rings.finite_rings - sage: M2 = Matroid(groundset='abcdefg', # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M1 = LinearMatroid(Matrix(M), groundset=M.groundset_list()) + sage: M2 = Matroid(groundset='abcdefg', ....: reduced_matrix=[[0, 1, 1, 1], ....: [1, 0, 1, 1], ....: [1, 1, 0, 1]], field=GF(2)) - sage: M.equals(M1) # optional - sage.rings.finite_rings + sage: M.equals(M1) True - sage: M.equals(M2) # optional - sage.rings.finite_rings + sage: M.equals(M2) True - sage: M.is_field_equivalent(M1) # optional - sage.rings.finite_rings + sage: M.is_field_equivalent(M1) True - sage: M.is_field_equivalent(M2) # optional - sage.rings.finite_rings + sage: M.is_field_equivalent(M2) True - sage: M == M1 # optional - sage.rings.finite_rings + sage: M == M1 False - sage: M == M2 # optional - sage.rings.finite_rings + sage: M == M2 True ``LinearMatroid`` instances ``M`` and ``N`` satisfy ``M == N`` if the representations are equivalent up to row operations and column scaling:: - sage: M1 = Matroid(groundset='abcd', # optional - sage.rings.finite_rings + sage: M1 = Matroid(groundset='abcd', ....: matrix=Matrix(GF(7), [[1, 0, 1, 1], [0, 1, 1, 2]])) - sage: M2 = Matroid(groundset='abcd', # optional - sage.rings.finite_rings + sage: M2 = Matroid(groundset='abcd', ....: matrix=Matrix(GF(7), [[1, 0, 1, 1], [0, 1, 1, 3]])) - sage: M3 = Matroid(groundset='abcd', # optional - sage.rings.finite_rings + sage: M3 = Matroid(groundset='abcd', ....: matrix=Matrix(GF(7), [[2, 6, 1, 0], [6, 1, 0, 1]])) - sage: M1.equals(M2) # optional - sage.rings.finite_rings + sage: M1.equals(M2) True - sage: M1.equals(M3) # optional - sage.rings.finite_rings + sage: M1.equals(M3) True - sage: M1 == M2 # optional - sage.rings.finite_rings + sage: M1 == M2 False - sage: M1 == M3 # optional - sage.rings.finite_rings + sage: M1 == M3 True - sage: M1.is_field_equivalent(M2) # optional - sage.rings.finite_rings + sage: M1.is_field_equivalent(M2) False - sage: M1.is_field_equivalent(M3) # optional - sage.rings.finite_rings + sage: M1.is_field_equivalent(M3) True - sage: M1.is_field_equivalent(M1) # optional - sage.rings.finite_rings + sage: M1.is_field_equivalent(M1) True """ if self is other: @@ -998,28 +998,28 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: N = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: N.is_field_isomorphism(M, {e:e for e in M.groundset()}) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: N = matroids.named_matroids.NonFano() + sage: N.is_field_isomorphism(M, {e:e for e in M.groundset()}) False - sage: from sage.matroids.advanced import * # optional - sage.rings.finite_rings - sage: M = matroids.named_matroids.Fano() \ ['g'] # optional - sage.rings.finite_rings - sage: N = LinearMatroid(reduced_matrix=Matrix(GF(2), # optional - sage.rings.finite_rings + sage: from sage.matroids.advanced import * + sage: M = matroids.named_matroids.Fano() \ ['g'] + sage: N = LinearMatroid(reduced_matrix=Matrix(GF(2), ....: [[-1, 0, 1], [1, -1, 0], [0, 1, -1]])) - sage: morphism = {'a':0, 'b':1, 'c': 2, 'd':4, 'e':5, 'f':3} # optional - sage.rings.finite_rings - sage: M.is_field_isomorphism(N, morphism) # optional - sage.rings.finite_rings + sage: morphism = {'a':0, 'b':1, 'c': 2, 'd':4, 'e':5, 'f':3} + sage: M.is_field_isomorphism(N, morphism) True - sage: M1 = Matroid(groundset=[0, 1, 2, 3], matrix=Matrix(GF(7), # optional - sage.rings.finite_rings + sage: M1 = Matroid(groundset=[0, 1, 2, 3], matrix=Matrix(GF(7), ....: [[1, 0, 1, 1], [0, 1, 1, 2]])) - sage: M2 = Matroid(groundset=[0, 1, 2, 3], matrix=Matrix(GF(7), # optional - sage.rings.finite_rings + sage: M2 = Matroid(groundset=[0, 1, 2, 3], matrix=Matrix(GF(7), ....: [[1, 0, 1, 1], [0, 1, 2, 1]])) - sage: mf1 = {0:0, 1:1, 2:2, 3:3} # optional - sage.rings.finite_rings - sage: mf2 = {0:0, 1:1, 2:3, 3:2} # optional - sage.rings.finite_rings - sage: M1.is_field_isomorphism(M2, mf1) # optional - sage.rings.finite_rings + sage: mf1 = {0:0, 1:1, 2:2, 3:3} + sage: mf2 = {0:0, 1:1, 2:3, 3:2} + sage: M1.is_field_isomorphism(M2, mf1) False - sage: M1.is_field_isomorphism(M2, mf2) # optional - sage.rings.finite_rings + sage: M1.is_field_isomorphism(M2, mf2) True """ from copy import copy @@ -1076,22 +1076,22 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M1 = BinaryMatroid(reduced_matrix=Matrix(GF(2), # optional - sage.rings.finite_rings + sage: M1 = BinaryMatroid(reduced_matrix=Matrix(GF(2), ....: [[1, 1, 0, 1], [1, 0, 1, 1], [0, 1, 1, 1]])) - sage: M2 = LinearMatroid(reduced_matrix=Matrix(GF(2), # optional - sage.rings.finite_rings + sage: M2 = LinearMatroid(reduced_matrix=Matrix(GF(2), ....: [[1, 1, 0, 1], [1, 0, 1, 1], [1, 1, 0, 1]])) - sage: M3 = BinaryMatroid(reduced_matrix=Matrix(GF(2), # optional - sage.rings.finite_rings + sage: M3 = BinaryMatroid(reduced_matrix=Matrix(GF(2), ....: [[1, 1, 0, 1], [1, 0, 1, 1], [1, 1, 1, 0]])) - sage: M2._fast_isom_test(M1) is None # optional - sage.rings.finite_rings + sage: M2._fast_isom_test(M1) is None True - sage: M1._fast_isom_test(M2) # optional - sage.rings.finite_rings + sage: M1._fast_isom_test(M2) Traceback (most recent call last): ... AttributeError: 'sage.matroids.linear_matroid.LinearMatroid' object has no attribute '_invariant' - sage: M1._fast_isom_test(M3) is None # optional - sage.rings.finite_rings + sage: M1._fast_isom_test(M3) is None True - sage: Matroid(graphs.WheelGraph(6), regular=True)._fast_isom_test( # optional - sage.graphs + sage: Matroid(graphs.WheelGraph(6), regular=True)._fast_isom_test( # needs sage.graphs ....: matroids.Wheel(5)) True """ @@ -1126,8 +1126,8 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: sage: M1 = matroids.Wheel(3) - sage: M2 = Matroid(graphs.CompleteGraph(4), regular=True) # optional - sage.graphs - sage: M1.is_field_isomorphic(M2) # optional - sage.graphs + sage: M2 = Matroid(graphs.CompleteGraph(4), regular=True) # needs sage.graphs + sage: M1.is_field_isomorphic(M2) # needs sage.graphs True sage: M3 = Matroid(bases=M1.bases()) sage: M1.is_field_isomorphic(M3) @@ -1136,19 +1136,19 @@ cdef class LinearMatroid(BasisExchangeMatroid): AttributeError: 'sage.matroids.basis_matroid.BasisMatroid' object has no attribute 'base_ring' sage: from sage.matroids.advanced import * - sage: M4 = BinaryMatroid(Matrix(M1)) # optional - sage.rings.finite_rings - sage: M5 = LinearMatroid(reduced_matrix=Matrix(GF(2), [[-1, 0, 1], # optional - sage.rings.finite_rings + sage: M4 = BinaryMatroid(Matrix(M1)) + sage: M5 = LinearMatroid(reduced_matrix=Matrix(GF(2), [[-1, 0, 1], ....: [1, -1, 0], [0, 1, -1]])) - sage: M4.is_field_isomorphic(M5) # optional - sage.rings.finite_rings + sage: M4.is_field_isomorphic(M5) True - sage: M1 = Matroid(groundset=[0, 1, 2, 3], matrix=Matrix(GF(7), # optional - sage.rings.finite_rings + sage: M1 = Matroid(groundset=[0, 1, 2, 3], matrix=Matrix(GF(7), ....: [[1, 0, 1, 1], [0, 1, 1, 2]])) - sage: M2 = Matroid(groundset=[0, 1, 2, 3], matrix=Matrix(GF(7), # optional - sage.rings.finite_rings + sage: M2 = Matroid(groundset=[0, 1, 2, 3], matrix=Matrix(GF(7), ....: [[1, 0, 1, 1], [0, 1, 2, 1]])) - sage: M1.is_field_isomorphic(M2) # optional - sage.rings.finite_rings + sage: M1.is_field_isomorphic(M2) True - sage: M1.is_field_equivalent(M2) # optional - sage.rings.finite_rings + sage: M1.is_field_equivalent(M2) False """ @@ -1224,19 +1224,19 @@ cdef class LinearMatroid(BasisExchangeMatroid): See docstring for :meth:`LinearMatroid.equals>` for more:: - sage: M1 = Matroid(groundset='abcd', matrix=Matrix(GF(7), # optional - sage.rings.finite_rings + sage: M1 = Matroid(groundset='abcd', matrix=Matrix(GF(7), ....: [[1, 0, 1, 1], [0, 1, 1, 2]])) - sage: M2 = Matroid(groundset='abcd', matrix=Matrix(GF(7), # optional - sage.rings.finite_rings + sage: M2 = Matroid(groundset='abcd', matrix=Matrix(GF(7), ....: [[1, 0, 1, 1], [0, 1, 1, 3]])) - sage: M3 = Matroid(groundset='abcd', matrix=Matrix(GF(7), # optional - sage.rings.finite_rings + sage: M3 = Matroid(groundset='abcd', matrix=Matrix(GF(7), ....: [[2, 6, 1, 0], [6, 1, 0, 1]])) - sage: M1.equals(M2) # optional - sage.rings.finite_rings + sage: M1.equals(M2) True - sage: M1.equals(M3) # optional - sage.rings.finite_rings + sage: M1.equals(M3) True - sage: M1 != M2 # indirect doctest # optional - sage.rings.finite_rings + sage: M1 != M2 # indirect doctest True - sage: M1 == M3 # indirect doctest # optional - sage.rings.finite_rings + sage: M1 == M3 # indirect doctest True """ if op not in [Py_EQ, Py_NE]: @@ -1264,14 +1264,14 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M1 = Matroid(groundset='abcde', matrix=Matrix(GF(7), # optional - sage.rings.finite_rings + sage: M1 = Matroid(groundset='abcde', matrix=Matrix(GF(7), ....: [[1, 0, 1, 1, 1], [0, 1, 1, 2, 3]])) - sage: M2 = Matroid(groundset='abcde', matrix=Matrix(GF(7), # optional - sage.rings.finite_rings + sage: M2 = Matroid(groundset='abcde', matrix=Matrix(GF(7), ....: [[0, 1, 1, 2, 3], [1, 0, 1, 1, 1]])) - sage: hash(M1) == hash(M2) # optional - sage.rings.finite_rings + sage: hash(M1) == hash(M2) True - sage: M2 = M1.dual() # optional - sage.rings.finite_rings - sage: hash(M1) == hash(M2) # optional - sage.rings.finite_rings + sage: M2 = M1.dual() + sage: hash(M1) == hash(M2) False """ return hash((self.groundset(), self.full_rank(), self._weak_invariant())) @@ -1304,11 +1304,11 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(groundset='abcdefgh', ring=GF(5), # optional - sage.rings.finite_rings + sage: M = Matroid(groundset='abcdefgh', ring=GF(5), ....: reduced_matrix=[[2, 1, 1, 0], ....: [1, 1, 0, 1], [1, 0, 1, 1], [0, 1, 1, 2]]) - sage: N = M._minor(contractions=set(['a']), deletions=set([])) # optional - sage.rings.finite_rings - sage: N._minor(contractions=set([]), deletions=set(['b', 'c'])) # optional - sage.rings.finite_rings + sage: N = M._minor(contractions=set(['a']), deletions=set([])) + sage: N._minor(contractions=set([]), deletions=set(['b', 'c'])) Linear matroid of rank 3 on 5 elements represented over the Finite Field of size 5 """ @@ -1340,11 +1340,11 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: A = Matrix(GF(7), [[1, 1, 0, 1], # optional - sage.rings.finite_rings + sage: A = Matrix(GF(7), [[1, 1, 0, 1], ....: [1, 0, 1, 1], ....: [0, 1, 1, 1]]) - sage: B = - A.transpose() # optional - sage.rings.finite_rings - sage: Matroid(reduced_matrix=A).dual() == Matroid( # optional - sage.rings.finite_rings + sage: B = - A.transpose() + sage: Matroid(reduced_matrix=A).dual() == Matroid( ....: reduced_matrix=B, ....: groundset=[3, 4, 5, 6, 0, 1, 2]) True @@ -1381,21 +1381,21 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.N1() # optional - sage.rings.finite_rings - sage: M.has_line_minor(4) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.N1() + sage: M.has_line_minor(4) True - sage: M.has_line_minor(5) # optional - sage.rings.finite_rings + sage: M.has_line_minor(5) False - sage: M.has_line_minor(k=4, hyperlines=[['a', 'b', 'c']]) # optional - sage.rings.finite_rings + sage: M.has_line_minor(k=4, hyperlines=[['a', 'b', 'c']]) False - sage: M.has_line_minor(k=4, hyperlines=[['a', 'b', 'c'], # optional - sage.rings.finite_rings + sage: M.has_line_minor(k=4, hyperlines=[['a', 'b', 'c'], ....: ['a', 'b', 'd' ]]) True - sage: M.has_line_minor(4, certificate=True) # optional - sage.rings.finite_rings + sage: M.has_line_minor(4, certificate=True) (True, frozenset({'a', 'b', 'd'})) - sage: M.has_line_minor(5, certificate=True) # optional - sage.rings.finite_rings + sage: M.has_line_minor(5, certificate=True) (False, None) - sage: M.has_line_minor(k=4, hyperlines=[['a', 'b', 'c'], # optional - sage.rings.finite_rings + sage: M.has_line_minor(k=4, hyperlines=[['a', 'b', 'c'], ....: ['a', 'b', 'd' ]], certificate=True) (True, frozenset({'a', 'b', 'd'})) @@ -1433,10 +1433,10 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = matroids.Whirl(3) # optional - sage.rings.finite_rings - sage: matroids.named_matroids.Fano().has_field_minor(M) # optional - sage.rings.finite_rings + sage: M = matroids.Whirl(3) + sage: matroids.named_matroids.Fano().has_field_minor(M) False - sage: matroids.named_matroids.NonFano().has_field_minor(M) # optional - sage.rings.finite_rings + sage: matroids.named_matroids.NonFano().has_field_minor(M) True """ if self is N: @@ -1489,8 +1489,8 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(Matrix(GF(7), [[1, 0, 1, 1], [0, 1, 1, 4]])) # optional - sage.rings.finite_rings - sage: M._exchange_value(1, 3) # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(7), [[1, 0, 1, 1], [0, 1, 1, 4]])) + sage: M._exchange_value(1, 3) 4 """ return self.__exchange_value(self._idx[e], self._idx[f]) @@ -1522,11 +1522,11 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(Matrix(GF(7), [[1, 0, 1, 1], [0, 1, 1, 4]])) # optional - sage.rings.finite_rings - sage: v = M.fundamental_cycle([0, 1], 3) # optional - sage.rings.finite_rings - sage: [v[0], v[1], v[3]] # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(7), [[1, 0, 1, 1], [0, 1, 1, 4]])) + sage: v = M.fundamental_cycle([0, 1], 3) + sage: [v[0], v[1], v[3]] [6, 3, 1] - sage: frozenset(v.keys()) == M.fundamental_circuit([0, 1], 3) # optional - sage.rings.finite_rings + sage: frozenset(v.keys()) == M.fundamental_circuit([0, 1], 3) True """ if e in B or not self._is_basis(B): @@ -1568,11 +1568,11 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(Matrix(GF(7), [[1, 0, 1, 1], [0, 1, 1, 4]])) # optional - sage.rings.finite_rings - sage: v = M.fundamental_cocycle([0, 1], 0) # optional - sage.rings.finite_rings - sage: [v[0], v[2], v[3]] # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(7), [[1, 0, 1, 1], [0, 1, 1, 4]])) + sage: v = M.fundamental_cocycle([0, 1], 0) + sage: [v[0], v[2], v[3]] [1, 1, 1] - sage: frozenset(v.keys()) == M.fundamental_cocircuit([0, 1], 0) # optional - sage.rings.finite_rings + sage: frozenset(v.keys()) == M.fundamental_cocircuit([0, 1], 0) True """ if e not in B or not self._is_basis(B): @@ -1597,11 +1597,11 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(Matrix(GF(7), [[1, 0, 0, 1, 1, 1], # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(7), [[1, 0, 0, 1, 1, 1], ....: [0, 1, 0, 1, 2, 4], [0, 0, 1, 3, 2, 5]])) - sage: sorted(M._line_ratios(set([2]))) # optional - sage.rings.finite_rings + sage: sorted(M._line_ratios(set([2]))) [1, 2, 4] - sage: sorted(M._line_ratios([0])) # optional - sage.rings.finite_rings + sage: sorted(M._line_ratios([0])) [1, 5] """ self._move_current_basis(F, set()) @@ -1628,11 +1628,11 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(Matrix(GF(7), [[1, 0, 0, 1, 1, 1], # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(7), [[1, 0, 0, 1, 1, 1], ....: [0, 1, 0, 1, 2, 4], [0, 0, 1, 3, 2, 5]])) - sage: M._line_length([2]) # optional - sage.rings.finite_rings + sage: M._line_length([2]) 5 - sage: M._line_length([0]) # optional - sage.rings.finite_rings + sage: M._line_length([0]) 4 """ return 2 + len(self._line_ratios(F)) @@ -1650,11 +1650,11 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(Matrix(GF(7), [[1, 0, 0, 1, 1, 1], # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(7), [[1, 0, 0, 1, 1, 1], ....: [0, 1, 0, 1, 2, 4], [0, 0, 1, 3, 2, 5]])) - sage: sorted(M._line_cross_ratios(set([2]))) # optional - sage.rings.finite_rings + sage: sorted(M._line_cross_ratios(set([2]))) [2, 4] - sage: sorted(M._line_cross_ratios([0])) # optional - sage.rings.finite_rings + sage: sorted(M._line_cross_ratios([0])) [5] """ cr = set() @@ -1701,13 +1701,13 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(Matrix(GF(7), [[1, 0, 0, 1, 1, 1], # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(7), [[1, 0, 0, 1, 1, 1], ....: [0, 1, 0, 1, 2, 4], ....: [0, 0, 1, 3, 2, 5]])) - sage: sorted(M.cross_ratios()) # optional - sage.rings.finite_rings + sage: sorted(M.cross_ratios()) [2, 3, 4, 5, 6] - sage: M = Matroid(graphs.CompleteGraph(5), regular=True) # optional - sage.graphs - sage: M.cross_ratios() # optional - sage.graphs + sage: M = Matroid(graphs.CompleteGraph(5), regular=True) # needs sage.graphs + sage: M.cross_ratios() # needs sage.graphs set() """ if hyperlines is None: @@ -1754,14 +1754,14 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(Matrix(GF(7), [[1, 0, 0, 1, 1, 1], # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(7), [[1, 0, 0, 1, 1, 1], ....: [0, 1, 0, 1, 2, 4], ....: [0, 0, 1, 3, 2, 6]])) - sage: M.cross_ratio([0], 1, 2, 3, 5) # optional - sage.rings.finite_rings + sage: M.cross_ratio([0], 1, 2, 3, 5) 4 - sage: M = Matroid(ring=GF(7), matrix=[[1, 0, 1, 1], [0, 1, 1, 1]]) # optional - sage.rings.finite_rings - sage: M.cross_ratio(set(), 0, 1, 2, 3) # optional - sage.rings.finite_rings + sage: M = Matroid(ring=GF(7), matrix=[[1, 0, 1, 1], [0, 1, 1, 1]]) + sage: M.cross_ratio(set(), 0, 1, 2, 3) Traceback (most recent call last): ... ValueError: points a, b, c, d do not form a 4-point line in M/F @@ -1919,16 +1919,16 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(ring=GF(2), matrix=[[1, 1, 0, 1, 0, 0], # optional - sage.rings.finite_rings + sage: M = Matroid(ring=GF(2), matrix=[[1, 1, 0, 1, 0, 0], ....: [1, 0, 1, 0, 1, 0], ....: [0, 1, 1, 0, 0, 1], ....: [0, 0, 0, 1, 1, 1]]) - sage: M.linear_extension(6, {0:1, 5: 1}).representation() # optional - sage.rings.finite_rings + sage: M.linear_extension(6, {0:1, 5: 1}).representation() [1 1 0 1 0 0 1] [1 0 1 0 1 0 1] [0 1 1 0 0 1 1] [0 0 0 1 1 1 1] - sage: M.linear_extension(6, col=[0, 1, 1, 1]).representation() # optional - sage.rings.finite_rings + sage: M.linear_extension(6, col=[0, 1, 1, 1]).representation() [1 1 0 1 0 0 0] [1 0 1 0 1 0 1] [0 1 1 0 0 1 1] @@ -2007,17 +2007,17 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(ring=GF(2), matrix=[[1, 1, 0, 1, 0, 0], # optional - sage.rings.finite_rings + sage: M = Matroid(ring=GF(2), matrix=[[1, 1, 0, 1, 0, 0], ....: [1, 0, 1, 0, 1, 0], ....: [0, 1, 1, 0, 0, 1], ....: [0, 0, 0, 1, 1, 1]]) - sage: M.linear_coextension(6, {0:1, 5: 1}).representation() # optional - sage.rings.finite_rings + sage: M.linear_coextension(6, {0:1, 5: 1}).representation() [1 1 0 1 0 0 0] [1 0 1 0 1 0 0] [0 1 1 0 0 1 0] [0 0 0 1 1 1 0] [1 0 0 0 0 1 1] - sage: M.linear_coextension(6, row=[0,1,1,1,0,1]).representation() # optional - sage.rings.finite_rings + sage: M.linear_coextension(6, row=[0,1,1,1,0,1]).representation() [1 1 0 1 0 0 0] [1 0 1 0 1 0 0] [0 1 1 0 0 1 0] @@ -2026,11 +2026,11 @@ cdef class LinearMatroid(BasisExchangeMatroid): Coextending commutes with dualizing:: - sage: M = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: chain = {'a': 1, 'b': -1, 'f': 1} # optional - sage.rings.finite_rings - sage: M1 = M.linear_coextension('x', chain) # optional - sage.rings.finite_rings - sage: M2 = M.dual().linear_extension('x', chain) # optional - sage.rings.finite_rings - sage: M1 == M2.dual() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.NonFano() + sage: chain = {'a': 1, 'b': -1, 'f': 1} + sage: M1 = M.linear_coextension('x', chain) + sage: M2 = M.dual().linear_extension('x', chain) + sage: M1 == M2.dual() True """ cdef LeanMatrix col @@ -2082,9 +2082,9 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(ring=GF(2), matrix=[[1, 1, 0, 1, 0, 0], # optional - sage.rings.finite_rings + sage: M = Matroid(ring=GF(2), matrix=[[1, 1, 0, 1, 0, 0], ....: [1, 0, 1, 0, 1, 0], [0, 1, 1, 0, 0, 1], [0, 0, 0, 1, 1, 1]]) - sage: M._linear_extensions(6, [{0:1, 5: 1}])[0].representation() # optional - sage.rings.finite_rings + sage: M._linear_extensions(6, [{0:1, 5: 1}])[0].representation() [1 1 0 1 0 0 1] [1 0 1 0 1 0 1] [0 1 1 0 0 1 1] @@ -2129,9 +2129,9 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(ring=GF(2), matrix=[[1, 1, 0, 1, 0, 0], # optional - sage.rings.finite_rings + sage: M = Matroid(ring=GF(2), matrix=[[1, 1, 0, 1, 0, 0], ....: [1, 0, 1, 0, 1, 0], [0, 1, 1, 0, 0, 1], [0, 0, 0, 1, 1, 1]]) - sage: M._linear_coextensions(6, [{0:1, 5: 1}])[0].representation() # optional - sage.rings.finite_rings + sage: M._linear_coextensions(6, [{0:1, 5: 1}])[0].representation() [1 1 0 1 0 0 0] [1 0 1 0 1 0 0] [0 1 1 0 0 1 0] @@ -2241,15 +2241,15 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(reduced_matrix=Matrix(GF(2), [[1, 1, 0], # optional - sage.rings.finite_rings + sage: M = Matroid(reduced_matrix=Matrix(GF(2), [[1, 1, 0], ....: [1, 0, 1], [0, 1, 1]])) - sage: len(M._linear_extension_chains(F=set([0, 1, 2]))) # optional - sage.rings.finite_rings + sage: len(M._linear_extension_chains(F=set([0, 1, 2]))) 8 - sage: M._linear_extension_chains(F=set()) # optional - sage.rings.finite_rings + sage: M._linear_extension_chains(F=set()) [{}] - sage: M._linear_extension_chains(F=set([1])) # optional - sage.rings.finite_rings + sage: M._linear_extension_chains(F=set([1])) [{}, {1: 1}] - sage: len(M._linear_extension_chains(F=set([0, 1]))) # optional - sage.rings.finite_rings + sage: len(M._linear_extension_chains(F=set([0, 1]))) 4 sage: N = Matroid(ring=QQ, reduced_matrix=[[1, 1, 0], ....: [1, 0, 1], [0, 1, 1]]) @@ -2333,15 +2333,15 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(reduced_matrix=Matrix(GF(2), # optional - sage.rings.finite_rings + sage: M = Matroid(reduced_matrix=Matrix(GF(2), ....: [[1, 1, 0], [1, 0, 1], [0, 1, 1]])) - sage: len(M.linear_extension_chains()) # optional - sage.rings.finite_rings + sage: len(M.linear_extension_chains()) 8 - sage: len(M.linear_extension_chains(F=[0, 1])) # optional - sage.rings.finite_rings + sage: len(M.linear_extension_chains(F=[0, 1])) 4 - sage: len(M.linear_extension_chains(F=[0, 1], simple=True)) # optional - sage.rings.finite_rings + sage: len(M.linear_extension_chains(F=[0, 1], simple=True)) 0 - sage: M.linear_extension_chains(F=[0, 1, 2], simple=True) # optional - sage.rings.finite_rings + sage: M.linear_extension_chains(F=[0, 1, 2], simple=True) [{0: 1, 1: 1, 2: 1}] sage: N = Matroid(ring=QQ, ....: reduced_matrix=[[-1, -1, 0], [1, 0, -1], [0, 1, 1]]) @@ -2433,15 +2433,15 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(reduced_matrix=Matrix(GF(2), # optional - sage.rings.finite_rings + sage: M = Matroid(reduced_matrix=Matrix(GF(2), ....: [[1, 1, 0], [1, 0, 1], [0, 1, 1]])) - sage: len(M.linear_coextension_cochains()) # optional - sage.rings.finite_rings + sage: len(M.linear_coextension_cochains()) 8 - sage: len(M.linear_coextension_cochains(F=[0, 1])) # optional - sage.rings.finite_rings + sage: len(M.linear_coextension_cochains(F=[0, 1])) 4 - sage: len(M.linear_coextension_cochains(F=[0, 1], cosimple=True)) # optional - sage.rings.finite_rings + sage: len(M.linear_coextension_cochains(F=[0, 1], cosimple=True)) 0 - sage: M.linear_coextension_cochains(F=[3, 4, 5], cosimple=True) # optional - sage.rings.finite_rings + sage: M.linear_coextension_cochains(F=[3, 4, 5], cosimple=True) [{3: 1, 4: 1, 5: 1}] sage: N = Matroid(ring=QQ, ....: reduced_matrix=[[-1, -1, 0], [1, 0, -1], [0, 1, 1]]) @@ -2490,13 +2490,13 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(ring=GF(2), # optional - sage.rings.finite_rings + sage: M = Matroid(ring=GF(2), ....: reduced_matrix=[[-1, 0, 1], [1, -1, 0], [0, 1, -1]]) - sage: len(M.linear_extensions()) # optional - sage.rings.finite_rings + sage: len(M.linear_extensions()) 8 - sage: S = M.linear_extensions(simple=True); S # optional - sage.rings.finite_rings + sage: S = M.linear_extensions(simple=True); S [Binary matroid of rank 3 on 7 elements, type (3, 0)] - sage: S[0].is_field_isomorphic(matroids.named_matroids.Fano()) # optional - sage.rings.finite_rings + sage: S[0].is_field_isomorphic(matroids.named_matroids.Fano()) True sage: M = Matroid(ring=QQ, ....: reduced_matrix=[[1, 0, 1], [1, 1, 0], [0, 1, 1]]) @@ -2504,7 +2504,7 @@ cdef class LinearMatroid(BasisExchangeMatroid): ....: fundamentals=[1, -1, 1/2, 2]) sage: len(S) 7 - sage: any(N.is_isomorphic(matroids.named_matroids.NonFano()) # optional - sage.rings.finite_rings + sage: any(N.is_isomorphic(matroids.named_matroids.NonFano()) ....: for N in S) True sage: len(M.linear_extensions(simple=True, @@ -2558,15 +2558,15 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(ring=GF(2), # optional - sage.rings.finite_rings + sage: M = Matroid(ring=GF(2), ....: reduced_matrix=[[-1, 0, 1], [1, -1, 0], [0, 1, -1]]) - sage: len(M.linear_coextensions()) # optional - sage.rings.finite_rings + sage: len(M.linear_coextensions()) 8 - sage: S = M.linear_coextensions(cosimple=True) # optional - sage.rings.finite_rings - sage: S # optional - sage.rings.finite_rings + sage: S = M.linear_coextensions(cosimple=True) + sage: S [Binary matroid of rank 4 on 7 elements, type (3, 7)] - sage: F7 = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: S[0].is_field_isomorphic(F7.dual()) # optional - sage.rings.finite_rings + sage: F7 = matroids.named_matroids.Fano() + sage: S[0].is_field_isomorphic(F7.dual()) True sage: M = Matroid(ring=QQ, ....: reduced_matrix=[[1, 0, 1], [1, 1, 0], [0, 1, 1]]) @@ -2574,10 +2574,10 @@ cdef class LinearMatroid(BasisExchangeMatroid): ....: fundamentals=[1, -1, 1/2, 2]) sage: len(S) 7 - sage: NF7 = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: any(N.is_isomorphic(NF7.dual()) for N in S) # optional - sage.rings.finite_rings + sage: NF7 = matroids.named_matroids.NonFano() + sage: any(N.is_isomorphic(NF7.dual()) for N in S) True - sage: len(M.linear_coextensions(cosimple=True, # optional - sage.rings.finite_rings + sage: len(M.linear_coextensions(cosimple=True, ....: fundamentals=[1, -1, 1/2, 2], ....: F=[3, 4])) 1 @@ -2662,25 +2662,26 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: matroids.Uniform(2, 3)._is_3connected_shifting() # optional - sage.graphs + sage: # needs sage.graphs + sage: matroids.Uniform(2, 3)._is_3connected_shifting() True - sage: M = Matroid(ring=QQ, matrix=[[1, 0, 0, 1, 1, 0], # optional - sage.graphs + sage: M = Matroid(ring=QQ, matrix=[[1, 0, 0, 1, 1, 0], ....: [0, 1, 0, 1, 2, 0], ....: [0, 0, 1, 0, 0, 1]]) - sage: M._is_3connected_shifting() # optional - sage.graphs + sage: M._is_3connected_shifting() False - sage: N = Matroid(circuit_closures={2: ['abc', 'cdef'], # optional - sage.graphs + sage: N = Matroid(circuit_closures={2: ['abc', 'cdef'], ....: 3: ['abcdef']}, ....: groundset='abcdef') - sage: N._is_3connected_shifting() # optional - sage.graphs + sage: N._is_3connected_shifting() False - sage: matroids.named_matroids.BetsyRoss()._is_3connected_shifting() # optional - sage.graphs + sage: matroids.named_matroids.BetsyRoss()._is_3connected_shifting() True - sage: M = matroids.named_matroids.R6() # optional - sage.graphs - sage: M._is_3connected_shifting() # optional - sage.graphs + sage: M = matroids.named_matroids.R6() + sage: M._is_3connected_shifting() # needs sage.rings.finite_rings False - sage: B, X = M._is_3connected_shifting(True) # optional - sage.graphs - sage: M.connectivity(X) < 3 # optional - sage.graphs + sage: B, X = M._is_3connected_shifting(True) # needs sage.rings.finite_rings + sage: M.connectivity(X) < 3 # needs sage.rings.finite_rings True """ if not self.is_connected(): @@ -2741,17 +2742,17 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: sage: M = matroids.Uniform(2, 6) - sage: B, X = M._is_4connected_shifting(True) # optional - sage.graphs - sage: (B, M.connectivity(X)<=3) # optional - sage.graphs + sage: B, X = M._is_4connected_shifting(True) # needs sage.graphs + sage: (B, M.connectivity(X)<=3) # needs sage.graphs (False, True) - sage: matroids.Uniform(4, 8)._is_4connected_shifting() # optional - sage.graphs + sage: matroids.Uniform(4, 8)._is_4connected_shifting() # needs sage.graphs True - sage: M = Matroid(field=GF(2), matrix=[[1,0,0,1,0,1,1,0,0,1,1,1], # optional - sage.rings.finite_rings + sage: M = Matroid(field=GF(2), matrix=[[1,0,0,1,0,1,1,0,0,1,1,1], ....: [0,1,0,1,0,1,0,1,0,0,0,1], ....: [0,0,1,1,0,0,1,1,0,1,0,1], ....: [0,0,0,0,1,1,1,1,0,0,1,1], ....: [0,0,0,0,0,0,0,0,1,1,1,1]]) - sage: M._is_4connected_shifting() # optional - sage.graphs sage.rings.finite_rings + sage: M._is_4connected_shifting() # needs sage.graphs True """ if self.rank()>self.size()-self.rank(): @@ -2843,8 +2844,7 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: sage: M = matroids.Wheel(3) - sage: OS = M.orlik_terao_algebra() - sage: OS + sage: OS = M.orlik_terao_algebra(); OS Orlik-Terao algebra of Wheel(3): Regular matroid of rank 3 on 6 elements with 16 bases over Integer Ring @@ -2853,11 +2853,12 @@ cdef class LinearMatroid(BasisExchangeMatroid): sage: M.orlik_terao_algebra(QQ).base_ring() Rational Field - sage: G = SymmetricGroup(3); - sage: OTG = M.orlik_terao_algebra(QQ, invariant=G) + sage: G = SymmetricGroup(3); # needs sage.groups + sage: OTG = M.orlik_terao_algebra(QQ, invariant=G) # needs sage.groups + sage: # needs sage.groups sage: G = SymmetricGroup(4) - sage: action = lambda g,x: g(x+1)-1 + sage: action = lambda g, x: g(x + 1) - 1 sage: OTG1 = M.orlik_terao_algebra(QQ, invariant=(G,action)) sage: OTG2 = M.orlik_terao_algebra(QQ, invariant=(action,G)) sage: OTG1 is OTG2 @@ -2896,10 +2897,10 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(Matrix(GF(7), [[1, 0, 0, 1, 1], [0, 1, 0, 1, 2], # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(7), [[1, 0, 0, 1, 1], [0, 1, 0, 1, 2], ....: [0, 0, 1, 1, 3]])) - sage: N = copy(M) # indirect doctest # optional - sage.rings.finite_rings - sage: M == N # optional - sage.rings.finite_rings + sage: N = copy(M) # indirect doctest + sage: M == N True """ cdef LinearMatroid N @@ -2917,10 +2918,10 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(Matrix(GF(7), [[1, 0, 0, 1, 1], [0, 1, 0, 1, 2], # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(7), [[1, 0, 0, 1, 1], [0, 1, 0, 1, 2], ....: [0, 0, 1, 1, 3]])) - sage: N = deepcopy(M) # indirect doctest # optional - sage.rings.finite_rings - sage: M == N # optional - sage.rings.finite_rings + sage: N = deepcopy(M) # indirect doctest + sage: M == N True """ cdef LinearMatroid N @@ -2953,16 +2954,16 @@ cdef class LinearMatroid(BasisExchangeMatroid): EXAMPLES:: - sage: M = Matroid(Matrix(GF(7), [[1, 0, 0, 1, 1], [0, 1, 0, 1, 2], # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(7), [[1, 0, 0, 1, 1], [0, 1, 0, 1, 2], ....: [0, 0, 1, 1, 3]])) - sage: M == loads(dumps(M)) # indirect doctest # optional - sage.rings.finite_rings + sage: M == loads(dumps(M)) # indirect doctest True - sage: M.rename("U35") # optional - sage.rings.finite_rings - sage: loads(dumps(M)) # optional - sage.rings.finite_rings + sage: M.rename("U35") + sage: loads(dumps(M)) U35 - sage: M = Matroid(Matrix(GF(7), [[1, 0, 1], [1, 0, 1]])) # optional - sage.rings.finite_rings - sage: N = loads(dumps(M)) # optional - sage.rings.finite_rings - sage: N.representation() # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(7), [[1, 0, 1], [1, 0, 1]])) + sage: N = loads(dumps(M)) + sage: N.representation() [1 0 1] [1 0 1] """ @@ -3036,21 +3037,21 @@ cdef class BinaryMatroid(LinearMatroid): EXAMPLES:: - sage: A = Matrix(GF(2), 2, 4, [[1, 0, 1, 1], [0, 1, 1, 1]]) # optional - sage.rings.finite_rings - sage: M = Matroid(A) # optional - sage.rings.finite_rings - sage: M # optional - sage.rings.finite_rings + sage: A = Matrix(GF(2), 2, 4, [[1, 0, 1, 1], [0, 1, 1, 1]]) + sage: M = Matroid(A) + sage: M Binary matroid of rank 2 on 4 elements, type (0, 6) - sage: sorted(M.groundset()) # optional - sage.rings.finite_rings + sage: sorted(M.groundset()) [0, 1, 2, 3] - sage: Matrix(M) # optional - sage.rings.finite_rings + sage: Matrix(M) [1 0 1 1] [0 1 1 1] - sage: M = Matroid(matrix=A, groundset='abcd') # optional - sage.rings.finite_rings - sage: sorted(M.groundset()) # optional - sage.rings.finite_rings + sage: M = Matroid(matrix=A, groundset='abcd') + sage: sorted(M.groundset()) ['a', 'b', 'c', 'd'] - sage: B = Matrix(GF(2), 2, 2, [[1, 1], [1, 1]]) # optional - sage.rings.finite_rings - sage: N = Matroid(reduced_matrix=B, groundset='abcd') # optional - sage.rings.finite_rings - sage: M == N # optional - sage.rings.finite_rings + sage: B = Matrix(GF(2), 2, 2, [[1, 1], [1, 1]]) + sage: N = Matroid(reduced_matrix=B, groundset='abcd') + sage: M == N True """ def __init__(self, matrix=None, groundset=None, reduced_matrix=None, ring=None, keep_initial_representation=True, basis=None): @@ -3066,7 +3067,7 @@ cdef class BinaryMatroid(LinearMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: BinaryMatroid(matrix=Matrix(GF(5), [[1, 0, 1, 1, 1], # indirect doctest, optional - sage.rings.finite_rings + sage: BinaryMatroid(matrix=Matrix(GF(5), [[1, 0, 1, 1, 1], # indirect doctest ....: [0, 1, 1, 2, 3]])) Binary matroid of rank 2 on 5 elements, type (1, 7) """ @@ -3131,8 +3132,8 @@ cdef class BinaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M.base_ring() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M.base_ring() Finite Field of size 2 """ global GF2 @@ -3145,8 +3146,8 @@ cdef class BinaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M.characteristic() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M.characteristic() 2 """ return 2 @@ -3213,9 +3214,9 @@ cdef class BinaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M.rename() # optional - sage.rings.finite_rings - sage: repr(M) # indirect doctest # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M.rename() + sage: repr(M) # indirect doctest 'Binary matroid of rank 3 on 7 elements, type (3, 0)' """ S = "Binary matroid of rank " + str(self.rank()) + " on " + str(self.size()) + " elements, type (" + str(self.bicycle_dimension()) + ', ' + str(self.brown_invariant()) + ')' @@ -3239,13 +3240,13 @@ cdef class BinaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: A = M._reduced_representation('efg') # optional - sage.rings.finite_rings - sage: R, C = M._current_rows_cols() # optional - sage.rings.finite_rings - sage: (sorted(R), sorted(C)) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: A = M._reduced_representation('efg') + sage: R, C = M._current_rows_cols() + sage: (sorted(R), sorted(C)) (['e', 'f', 'g'], ['a', 'b', 'c', 'd']) - sage: R, C = M._current_rows_cols(B='abg') # optional - sage.rings.finite_rings - sage: (sorted(R), sorted(C)) # optional - sage.rings.finite_rings + sage: R, C = M._current_rows_cols(B='abg') + sage: (sorted(R), sorted(C)) (['a', 'b', 'g'], ['c', 'd', 'e', 'f']) """ @@ -3287,13 +3288,13 @@ cdef class BinaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M._basic_representation() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M._basic_representation() 3 x 7 BinaryMatrix [1000111] [0101011] [0011101] - sage: matrix(M._basic_representation('efg')) # optional - sage.rings.finite_rings + sage: matrix(M._basic_representation('efg')) [1 1 0 1 1 0 0] [1 0 1 1 0 1 0] [1 1 1 0 0 0 1] @@ -3326,13 +3327,13 @@ cdef class BinaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M._reduced_representation() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M._reduced_representation() 3 x 4 BinaryMatrix [0111] [1011] [1101] - sage: matrix(M._reduced_representation('efg')) # optional - sage.rings.finite_rings + sage: matrix(M._reduced_representation('efg')) [1 1 0 1] [1 0 1 1] [1 1 1 0] @@ -3366,23 +3367,23 @@ cdef class BinaryMatroid(LinearMatroid): EXAMPLES:: - sage: M1 = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M2 = Matroid(ring=GF(2), # optional - sage.rings.finite_rings + sage: M1 = matroids.named_matroids.Fano() + sage: M2 = Matroid(ring=GF(2), ....: reduced_matrix=[[1, 0, 1, 1], [0, 1, 1, 1], [1, 1, 0, 1]]) - sage: M1._is_isomorphic(M2) # optional - sage.rings.finite_rings + sage: M1._is_isomorphic(M2) True - sage: M1._is_isomorphic(M2, certificate=True) # optional - sage.rings.finite_rings + sage: M1._is_isomorphic(M2, certificate=True) (True, {'a': 0, 'b': 1, 'c': 2, 'd': 4, 'e': 3, 'f': 5, 'g': 6}) - sage: M1 = matroids.named_matroids.Fano().delete('a') # optional - sage.rings.finite_rings - sage: M2 = matroids.Whirl(3) # optional - sage.rings.finite_rings - sage: M1._is_isomorphic(M2) # optional - sage.rings.finite_rings + sage: M1 = matroids.named_matroids.Fano().delete('a') + sage: M2 = matroids.Whirl(3) + sage: M1._is_isomorphic(M2) False - sage: M1._is_isomorphic(M2, certificate=True) # optional - sage.rings.finite_rings + sage: M1._is_isomorphic(M2, certificate=True) (False, None) - sage: M1._is_isomorphic(matroids.Wheel(3)) # optional - sage.rings.finite_rings + sage: M1._is_isomorphic(matroids.Wheel(3)) True - sage: M1._is_isomorphic(matroids.Wheel(3), certificate=True) # optional - sage.rings.finite_rings + sage: M1._is_isomorphic(matroids.Wheel(3), certificate=True) (True, {'b': 1, 'c': 2, 'd': 4, 'e': 3, 'f': 5, 'g': 0}) """ @@ -3412,10 +3413,10 @@ cdef class BinaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() \ ['a'] # optional - sage.rings.finite_rings - sage: N = matroids.named_matroids.Fano() \ ['b'] # optional - sage.rings.finite_rings - sage: morphism = {'b':'a', 'c':'c', 'd':'e', 'e':'d', 'f':'f', 'g':'g'} # optional - sage.rings.finite_rings - sage: M._is_isomorphism(N, morphism) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() \ ['a'] + sage: N = matroids.named_matroids.Fano() \ ['b'] + sage: morphism = {'b':'a', 'c':'c', 'd':'e', 'e':'d', 'f':'f', 'g':'g'} + sage: M._is_isomorphism(N, morphism) True """ if isinstance(other, BinaryMatroid): @@ -3432,8 +3433,8 @@ cdef class BinaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M._invariant() # indirect doctest # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M._invariant() # indirect doctest (3, 0, 7, 0, 0, 0, 0, 0) """ cdef BinaryMatrix B @@ -3535,8 +3536,8 @@ cdef class BinaryMatroid(LinearMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = BinaryMatroid(matroids.AG(2, 5).representation()) # optional - sage.rings.finite_rings - sage: M._invariant() # optional - sage.rings.finite_rings + sage: M = BinaryMatroid(matroids.AG(2, 5).representation()) + sage: M._invariant() (2, 1, 24, 0, 1, 0, 0, 1) """ if self._b_invariant is None: @@ -3558,8 +3559,8 @@ cdef class BinaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M.bicycle_dimension() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M.bicycle_dimension() 3 """ if self._b_invariant is None: @@ -3590,13 +3591,13 @@ cdef class BinaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M.brown_invariant() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M.brown_invariant() 0 - sage: M = Matroid(Matrix(GF(2), 3, 8, [[1, 0, 0, 1, 1, 1, 1, 1], # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(2), 3, 8, [[1, 0, 0, 1, 1, 1, 1, 1], ....: [0, 1, 0, 1, 1, 0, 0, 0], ....: [0, 0, 1, 0, 0, 1, 1, 0]])) - sage: M.brown_invariant() is None # optional - sage.rings.finite_rings + sage: M.brown_invariant() is None True """ if self._b_invariant is None: @@ -3622,14 +3623,14 @@ cdef class BinaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.S8() # optional - sage.rings.finite_rings - sage: for F in M._principal_tripartition(): print(sorted(F)) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.S8() + sage: for F in M._principal_tripartition(): print(sorted(F)) ['a', 'b', 'c', 'e', 'f', 'g'] ['d'] ['h'] - sage: M.bicycle_dimension() # optional - sage.rings.finite_rings + sage: M.bicycle_dimension() 2 - sage: for i in [-1, 0, 1]: # optional - sage.rings.finite_rings + sage: for i in [-1, 0, 1]: ....: print(sorted(e for e in M.groundset() ....: if (M\e).bicycle_dimension() == 2 + i)) ['a', 'b', 'c', 'e', 'f', 'g'] @@ -3662,8 +3663,8 @@ cdef class BinaryMatroid(LinearMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = BinaryMatroid(matrix(matroids.named_matroids.R12())) # optional - sage.rings.finite_rings - sage: M._projection() # optional - sage.rings.finite_rings + sage: M = BinaryMatroid(matrix(matroids.named_matroids.R12())) + sage: M._projection() 12 x 12 BinaryMatrix [001110111000] [001101110100] @@ -3699,14 +3700,14 @@ cdef class BinaryMatroid(LinearMatroid): An ordered partition. sage: from sage.matroids.advanced import * - sage: M = matroids.named_matroids.R12() # optional - sage.rings.finite_rings - sage: N = BinaryMatroid(reduced_matrix=M.representation(reduced=True, # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.R12() + sage: N = BinaryMatroid(reduced_matrix=M.representation(reduced=True, ....: labels=False), groundset='abcdefghijkl') - sage: Npp = N._projection_partition(); Npp # random # optional - sage.rings.finite_rings + sage: Npp = N._projection_partition(); Npp # random 2 x 12 BinaryMatrix [110011001100] [001100110011] - sage: sorted(Npp._matrix_().rows()) # optional - sage.rings.finite_rings + sage: sorted(Npp._matrix_().rows()) # needs sage.rings.finite_rings [(1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0), (0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1)] """ if self._eq_part is None: @@ -3734,9 +3735,9 @@ cdef class BinaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.S8() # optional - sage.rings.finite_rings - sage: N = matroids.named_matroids.S8() # optional - sage.rings.finite_rings - sage: M._fast_isom_test(N) is None # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.S8() + sage: N = matroids.named_matroids.S8() + sage: M._fast_isom_test(N) is None True """ if self._invariant() != other._invariant(): @@ -3775,9 +3776,9 @@ cdef class BinaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: N = M._minor(contractions=set(['a']), deletions=set([])) # optional - sage.rings.finite_rings - sage: N._minor(contractions=set([]), deletions=set(['b', 'c'])) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: N = M._minor(contractions=set(['a']), deletions=set([])) + sage: N._minor(contractions=set([]), deletions=set(['b', 'c'])) Binary matroid of rank 2 on 4 elements, type (0, 6) """ self._move_current_basis(contractions, deletions) @@ -3808,16 +3809,16 @@ cdef class BinaryMatroid(LinearMatroid): EXAMPLES:: sage: R10 = matroids.named_matroids.R10() - sage: M = Matroid(ring=GF(2), reduced_matrix=R10.representation( # optional - sage.rings.finite_rings + sage: M = Matroid(ring=GF(2), reduced_matrix=R10.representation( ....: reduced=True, labels=False)) - sage: M.is_graphic() # optional - sage.rings.finite_rings + sage: M.is_graphic() False - sage: K5 = Matroid(graphs.CompleteGraph(5), regular=True) # optional - sage.graphs - sage: M = Matroid(ring=GF(2), reduced_matrix=K5.representation( # optional - sage.graphs sage.rings.finite_rings + sage: K5 = Matroid(graphs.CompleteGraph(5), regular=True) # needs sage.graphs + sage: M = Matroid(ring=GF(2), reduced_matrix=K5.representation( # needs sage.graphs sage.rings.finite_rings ....: reduced=True, labels=False)) - sage: M.is_graphic() # optional - sage.graphs sage.rings.finite_rings + sage: M.is_graphic() # needs sage.graphs sage.rings.finite_rings True - sage: M.dual().is_graphic() # optional - sage.graphs sage.rings.finite_rings + sage: M.dual().is_graphic() # needs sage.graphs False ALGORITHM: @@ -3876,8 +3877,8 @@ cdef class BinaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = Matroid(Matrix(GF(2), [[]])) # optional - sage.rings.finite_rings - sage: M.is_valid() # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(2), [[]])) + sage: M.is_valid() True """ return True @@ -3908,8 +3909,8 @@ cdef class BinaryMatroid(LinearMatroid): EXAMPLES:: - sage: N = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: N.binary_matroid() is N # optional - sage.rings.finite_rings + sage: N = matroids.named_matroids.Fano() + sage: N.binary_matroid() is N True """ return self @@ -3936,8 +3937,8 @@ cdef class BinaryMatroid(LinearMatroid): EXAMPLES:: - sage: N = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: N.is_binary() # optional - sage.rings.finite_rings + sage: N = matroids.named_matroids.Fano() + sage: N.is_binary() True """ return True @@ -3948,10 +3949,10 @@ cdef class BinaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = Matroid(Matrix(GF(2), [[1, 0, 0, 1, 1], [0, 1, 0, 1, 2], # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(2), [[1, 0, 0, 1, 1], [0, 1, 0, 1, 2], ....: [0, 0, 1, 1, 3]])) - sage: N = copy(M) # indirect doctest # optional - sage.rings.finite_rings - sage: M == N # optional - sage.rings.finite_rings + sage: N = copy(M) # indirect doctest + sage: M == N True """ cdef BinaryMatroid N @@ -3972,10 +3973,10 @@ cdef class BinaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = Matroid(Matrix(GF(2), [[1, 0, 0, 1, 1], [0, 1, 0, 1, 2], # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(2), [[1, 0, 0, 1, 1], [0, 1, 0, 1, 2], ....: [0, 0, 1, 1, 3]])) - sage: N = deepcopy(M) # indirect doctest # optional - sage.rings.finite_rings - sage: M == N # optional - sage.rings.finite_rings + sage: N = deepcopy(M) # indirect doctest + sage: M == N True """ from copy import deepcopy @@ -4011,15 +4012,15 @@ cdef class BinaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = Matroid(Matrix(GF(2), [[1, 0, 0, 1], [0, 1, 0, 1], # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(2), [[1, 0, 0, 1], [0, 1, 0, 1], ....: [0, 0, 1, 1]])) - sage: M == loads(dumps(M)) # indirect doctest # optional - sage.rings.finite_rings + sage: M == loads(dumps(M)) # indirect doctest True - sage: M.rename("U34") # optional - sage.rings.finite_rings - sage: loads(dumps(M)) # optional - sage.rings.finite_rings + sage: M.rename("U34") + sage: loads(dumps(M)) U34 - sage: M = Matroid(Matrix(GF(2), [[1, 0, 1], [1, 0, 1]])) # optional - sage.rings.finite_rings - sage: loads(dumps(M)).representation() # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(2), [[1, 0, 1], [1, 0, 1]])) + sage: loads(dumps(M)).representation() [1 0 1] [1 0 1] @@ -4027,12 +4028,12 @@ cdef class BinaryMatroid(LinearMatroid): Check that :trac:`23437` is fixed:: - sage: M = matroids.named_matroids.Fano().dual() # optional - sage.rings.finite_rings - sage: B = list(M.bases()) # optional - sage.rings.finite_rings - sage: N = loads(dumps(M)) # optional - sage.rings.finite_rings - sage: N.closure(frozenset({'d'})) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano().dual() + sage: B = list(M.bases()) + sage: N = loads(dumps(M)) + sage: N.closure(frozenset({'d'})) frozenset({'d'}) - sage: N.is_isomorphic(M) # optional - sage.rings.finite_rings + sage: N.is_isomorphic(M) True """ import sage.matroids.unpickling @@ -4103,20 +4104,20 @@ cdef class TernaryMatroid(LinearMatroid): EXAMPLES:: - sage: A = Matrix(GF(3), 2, 4, [[1, 0, 1, 1], [0, 1, 1, 1]]) # optional - sage.rings.finite_rings - sage: M = Matroid(A); M # optional - sage.rings.finite_rings + sage: A = Matrix(GF(3), 2, 4, [[1, 0, 1, 1], [0, 1, 1, 1]]) + sage: M = Matroid(A); M Ternary matroid of rank 2 on 4 elements, type 0- - sage: sorted(M.groundset()) # optional - sage.rings.finite_rings + sage: sorted(M.groundset()) [0, 1, 2, 3] - sage: Matrix(M) # optional - sage.rings.finite_rings + sage: Matrix(M) [1 0 1 1] [0 1 1 1] - sage: M = Matroid(matrix=A, groundset='abcd') # optional - sage.rings.finite_rings - sage: sorted(M.groundset()) # optional - sage.rings.finite_rings + sage: M = Matroid(matrix=A, groundset='abcd') + sage: sorted(M.groundset()) ['a', 'b', 'c', 'd'] - sage: B = Matrix(GF(2), 2, 2, [[1, 1], [1, 1]]) # optional - sage.rings.finite_rings - sage: N = Matroid(ring=GF(3), reduced_matrix=B, groundset='abcd') # optional - sage.rings.finite_rings - sage: M == N # optional - sage.rings.finite_rings + sage: B = Matrix(GF(2), 2, 2, [[1, 1], [1, 1]]) + sage: N = Matroid(ring=GF(3), reduced_matrix=B, groundset='abcd') # needs sage.rings.finite_rings + sage: M == N # needs sage.rings.finite_rings True """ def __init__(self, matrix=None, groundset=None, reduced_matrix=None, ring=None, keep_initial_representation=True, basis=None): @@ -4132,7 +4133,7 @@ cdef class TernaryMatroid(LinearMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: TernaryMatroid(matrix=Matrix(GF(5), [[1, 0, 1, 1, 1], # indirect doctest, optional - sage.rings.finite_rings + sage: TernaryMatroid(matrix=Matrix(GF(5), [[1, 0, 1, 1, 1], # indirect doctest ....: [0, 1, 1, 2, 3]])) Ternary matroid of rank 2 on 5 elements, type 1+ """ @@ -4199,8 +4200,8 @@ cdef class TernaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: M.base_ring() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.NonFano() + sage: M.base_ring() Finite Field of size 3 """ global GF3 @@ -4213,8 +4214,8 @@ cdef class TernaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: M.characteristic() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.NonFano() + sage: M.characteristic() 3 """ return 3 @@ -4283,9 +4284,9 @@ cdef class TernaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: M.rename() # optional - sage.rings.finite_rings - sage: repr(M) # indirect doctest # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.NonFano() + sage: M.rename() + sage: repr(M) # indirect doctest 'Ternary matroid of rank 3 on 7 elements, type 0-' """ S = "Ternary matroid of rank " + str(self.rank()) + " on " + str(self.size()) + " elements, type " + str(self.bicycle_dimension()) @@ -4313,13 +4314,13 @@ cdef class TernaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: A = M._reduced_representation('efg') # optional - sage.rings.finite_rings - sage: R, C = M._current_rows_cols() # optional - sage.rings.finite_rings - sage: (sorted(R), sorted(C)) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.NonFano() + sage: A = M._reduced_representation('efg') + sage: R, C = M._current_rows_cols() + sage: (sorted(R), sorted(C)) (['e', 'f', 'g'], ['a', 'b', 'c', 'd']) - sage: R, C = M._current_rows_cols(B='abg') # optional - sage.rings.finite_rings - sage: (sorted(R), sorted(C)) # optional - sage.rings.finite_rings + sage: R, C = M._current_rows_cols(B='abg') + sage: (sorted(R), sorted(C)) (['a', 'b', 'g'], ['c', 'd', 'e', 'f']) """ @@ -4361,13 +4362,13 @@ cdef class TernaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: M._basic_representation() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.NonFano() + sage: M._basic_representation() 3 x 7 TernaryMatrix [+000+++] [0+0+0++] [00+++0+] - sage: matrix(M._basic_representation('efg')) # optional - sage.rings.finite_rings + sage: matrix(M._basic_representation('efg')) [1 2 0 2 1 0 0] [1 0 2 2 0 1 0] [2 1 1 2 0 0 1] @@ -4400,13 +4401,13 @@ cdef class TernaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: M._reduced_representation() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.NonFano() + sage: M._reduced_representation() 3 x 4 TernaryMatrix [0+++] [+0++] [++0+] - sage: matrix(M._reduced_representation('efg')) # optional - sage.rings.finite_rings + sage: matrix(M._reduced_representation('efg')) [1 2 0 2] [1 0 2 2] [2 1 1 2] @@ -4439,13 +4440,13 @@ cdef class TernaryMatroid(LinearMatroid): EXAMPLES:: - sage: M1 = matroids.named_matroids.NonFano().delete('a') # optional - sage.rings.finite_rings - sage: M2 = matroids.Whirl(3) # optional - sage.rings.finite_rings - sage: M1._is_isomorphic(M2) # optional - sage.rings.finite_rings + sage: M1 = matroids.named_matroids.NonFano().delete('a') + sage: M2 = matroids.Whirl(3) + sage: M1._is_isomorphic(M2) True - sage: M2 = matroids.Wheel(3) # optional - sage.rings.finite_rings - sage: M1._is_isomorphic(M2) # optional - sage.rings.finite_rings + sage: M2 = matroids.Wheel(3) + sage: M1._is_isomorphic(M2) False """ if certificate: @@ -4465,8 +4466,8 @@ cdef class TernaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: M._invariant() # indirect doctest # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.NonFano() + sage: M._invariant() # indirect doctest (0, 2, 0, 4, 3, 0, 12, 12, 3, 0, 0, 0) """ cdef TernaryMatrix T @@ -4550,8 +4551,8 @@ cdef class TernaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: M._invariant() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.NonFano() + sage: M._invariant() (0, 2, 0, 4, 3, 0, 12, 12, 3, 0, 0, 0) """ if self._t_invariant is None: @@ -4573,8 +4574,8 @@ cdef class TernaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: M.bicycle_dimension() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.NonFano() + sage: M.bicycle_dimension() 0 """ if self._t_invariant is None: @@ -4599,8 +4600,8 @@ cdef class TernaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: M.character() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.NonFano() + sage: M.character() 2 """ if self._t_invariant is None: @@ -4617,20 +4618,20 @@ cdef class TernaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.N1() # optional - sage.rings.finite_rings - sage: print(M) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.N1() + sage: print(M) N1: Ternary matroid of rank 5 on 10 elements, type 0+ - sage: P = M._principal_quadripartition() # optional - sage.rings.finite_rings - sage: for e in sorted(P[0]): print("{} {}".format(e, M/e)) # optional - sage.rings.finite_rings - sage: for e in sorted(P[1]): print("{} {}".format(e, M/e)) # optional - sage.rings.finite_rings + sage: P = M._principal_quadripartition() + sage: for e in sorted(P[0]): print("{} {}".format(e, M/e)) + sage: for e in sorted(P[1]): print("{} {}".format(e, M/e)) a Ternary matroid of rank 4 on 9 elements, type 1- b Ternary matroid of rank 4 on 9 elements, type 1- e Ternary matroid of rank 4 on 9 elements, type 1- f Ternary matroid of rank 4 on 9 elements, type 1- - sage: for e in sorted(P[2]): print("{} {}".format(e, M/e)) # optional - sage.rings.finite_rings + sage: for e in sorted(P[2]): print("{} {}".format(e, M/e)) d Ternary matroid of rank 4 on 9 elements, type 0- i Ternary matroid of rank 4 on 9 elements, type 0- - sage: for e in sorted(P[3]): print("{} {}".format(e, M/e)) # optional - sage.rings.finite_rings + sage: for e in sorted(P[3]): print("{} {}".format(e, M/e)) c Ternary matroid of rank 4 on 9 elements, type 0+ g Ternary matroid of rank 4 on 9 elements, type 0+ h Ternary matroid of rank 4 on 9 elements, type 0+ @@ -4662,9 +4663,9 @@ cdef class TernaryMatroid(LinearMatroid): EXAMPLES:: - sage: from sage.matroids.advanced import * # optional - sage.rings.finite_rings - sage: M = TernaryMatroid(matrix(matroids.named_matroids.R12())) # optional - sage.rings.finite_rings - sage: M._projection() # optional - sage.rings.finite_rings + sage: from sage.matroids.advanced import * + sage: M = TernaryMatroid(matrix(matroids.named_matroids.R12())) + sage: M._projection() 12 x 12 TernaryMatrix [++00-0--0+++] [+-+000+0+-+0] @@ -4704,9 +4705,9 @@ cdef class TernaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.T8() # optional - sage.rings.finite_rings - sage: N = matroids.named_matroids.P8() # optional - sage.rings.finite_rings - sage: M._fast_isom_test(N) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.T8() + sage: N = matroids.named_matroids.P8() + sage: M._fast_isom_test(N) False """ if self._invariant() != other._invariant(): @@ -4741,9 +4742,9 @@ cdef class TernaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.P8() # optional - sage.rings.finite_rings - sage: N = M._minor(contractions=set(['a']), deletions=set([])) # optional - sage.rings.finite_rings - sage: N._minor(contractions=set([]), deletions=set(['b', 'c'])) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.P8() + sage: N = M._minor(contractions=set(['a']), deletions=set([])) + sage: N._minor(contractions=set([]), deletions=set(['b', 'c'])) Ternary matroid of rank 3 on 5 elements, type 0- """ self._move_current_basis(contractions, deletions) @@ -4770,8 +4771,8 @@ cdef class TernaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = Matroid(Matrix(GF(3), [[]])) # optional - sage.rings.finite_rings - sage: M.is_valid() # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(3), [[]])) + sage: M.is_valid() True """ return True @@ -4802,8 +4803,8 @@ cdef class TernaryMatroid(LinearMatroid): EXAMPLES:: - sage: N = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: N.ternary_matroid() is N # optional - sage.rings.finite_rings + sage: N = matroids.named_matroids.NonFano() + sage: N.ternary_matroid() is N True """ return self @@ -4830,8 +4831,8 @@ cdef class TernaryMatroid(LinearMatroid): EXAMPLES:: - sage: N = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: N.is_ternary() # optional - sage.rings.finite_rings + sage: N = matroids.named_matroids.NonFano() + sage: N.is_ternary() True """ return True @@ -4842,10 +4843,10 @@ cdef class TernaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = Matroid(Matrix(GF(3), [[1, 0, 0, 1, 1], [0, 1, 0, 1, 2], # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(3), [[1, 0, 0, 1, 1], [0, 1, 0, 1, 2], ....: [0, 0, 1, 1, 3]])) - sage: N = copy(M) # indirect doctest # optional - sage.rings.finite_rings - sage: M == N # optional - sage.rings.finite_rings + sage: N = copy(M) # indirect doctest + sage: M == N True """ cdef TernaryMatroid N @@ -4866,10 +4867,10 @@ cdef class TernaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = Matroid(Matrix(GF(3), [[1, 0, 0, 1, 1], [0, 1, 0, 1, 2], # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(3), [[1, 0, 0, 1, 1], [0, 1, 0, 1, 2], ....: [0, 0, 1, 1, -1]])) - sage: N = deepcopy(M) # indirect doctest # optional - sage.rings.finite_rings - sage: M == N # optional - sage.rings.finite_rings + sage: N = deepcopy(M) # indirect doctest + sage: M == N True """ from copy import deepcopy @@ -4906,15 +4907,15 @@ cdef class TernaryMatroid(LinearMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = TernaryMatroid(Matrix(GF(3), [[1, 0, 0, 1], # optional - sage.rings.finite_rings + sage: M = TernaryMatroid(Matrix(GF(3), [[1, 0, 0, 1], ....: [0, 1, 0, 1], [0, 0, 1, 1]])) - sage: M == loads(dumps(M)) # indirect doctest # optional - sage.rings.finite_rings + sage: M == loads(dumps(M)) # indirect doctest True - sage: M.rename("U34") # optional - sage.rings.finite_rings - sage: loads(dumps(M)) # optional - sage.rings.finite_rings + sage: M.rename("U34") + sage: loads(dumps(M)) U34 - sage: M = TernaryMatroid(Matrix(GF(3), [[1, 0, 1], [1, 0, 1]])) # optional - sage.rings.finite_rings - sage: loads(dumps(M)).representation() # optional - sage.rings.finite_rings + sage: M = TernaryMatroid(Matrix(GF(3), [[1, 0, 1], [1, 0, 1]])) + sage: loads(dumps(M)).representation() [1 0 1] [1 0 1] @@ -4922,15 +4923,15 @@ cdef class TernaryMatroid(LinearMatroid): Check that :trac:`23437` is fixed:: - sage: from sage.matroids.advanced import * # optional - sage.rings.finite_rings - sage: X_bin = matroids.named_matroids.Fano().representation() # optional - sage.rings.finite_rings - sage: X = Matrix(GF(3), X_bin) # optional - sage.rings.finite_rings - sage: M = TernaryMatroid(matrix=X).dual() # optional - sage.rings.finite_rings - sage: B = list(M.bases()) # optional - sage.rings.finite_rings - sage: N = loads(dumps(M)) # optional - sage.rings.finite_rings - sage: N.closure(frozenset({3})) # optional - sage.rings.finite_rings + sage: from sage.matroids.advanced import * + sage: X_bin = matroids.named_matroids.Fano().representation() + sage: X = Matrix(GF(3), X_bin) # needs sage.rings.finite_rings + sage: M = TernaryMatroid(matrix=X).dual() # needs sage.rings.finite_rings + sage: B = list(M.bases()) + sage: N = loads(dumps(M)) + sage: N.closure(frozenset({3})) # needs sage.rings.finite_rings frozenset({3}) - sage: N.is_isomorphic(M) # optional - sage.rings.finite_rings + sage: N.is_isomorphic(M) True """ import sage.matroids.unpickling @@ -5003,25 +5004,26 @@ cdef class QuaternaryMatroid(LinearMatroid): EXAMPLES:: - sage: GF4 = GF(4, 'x') # optional - sage.rings.finite_rings - sage: x = GF4.gens()[0] # optional - sage.rings.finite_rings - sage: A = Matrix(GF4, 2, 4, [[1, 0, 1, 1], [0, 1, 1, x]]) # optional - sage.rings.finite_rings - sage: M = Matroid(A) # optional - sage.rings.finite_rings - sage: M # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: GF4 = GF(4, 'x') + sage: x = GF4.gens()[0] + sage: A = Matrix(GF4, 2, 4, [[1, 0, 1, 1], [0, 1, 1, x]]) + sage: M = Matroid(A) + sage: M Quaternary matroid of rank 2 on 4 elements - sage: sorted(M.groundset()) # optional - sage.rings.finite_rings + sage: sorted(M.groundset()) [0, 1, 2, 3] - sage: Matrix(M) # optional - sage.rings.finite_rings + sage: Matrix(M) [1 0 1 1] [0 1 1 x] - sage: M = Matroid(matrix=A, groundset='abcd') # optional - sage.rings.finite_rings - sage: sorted(M.groundset()) # optional - sage.rings.finite_rings + sage: M = Matroid(matrix=A, groundset='abcd') + sage: sorted(M.groundset()) ['a', 'b', 'c', 'd'] - sage: GF4p = GF(4, 'y') # optional - sage.rings.finite_rings - sage: y = GF4p.gens()[0] # optional - sage.rings.finite_rings - sage: B = Matrix(GF4p, 2, 2, [[1, 1], [1, y]]) # optional - sage.rings.finite_rings - sage: N = Matroid(reduced_matrix=B, groundset='abcd') # optional - sage.rings.finite_rings - sage: M == N # optional - sage.rings.finite_rings + sage: GF4p = GF(4, 'y') + sage: y = GF4p.gens()[0] + sage: B = Matrix(GF4p, 2, 2, [[1, 1], [1, y]]) + sage: N = Matroid(reduced_matrix=B, groundset='abcd') + sage: M == N False """ def __init__(self, matrix=None, groundset=None, reduced_matrix=None, ring=None, keep_initial_representation=True, basis=None): @@ -5037,7 +5039,7 @@ cdef class QuaternaryMatroid(LinearMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: QuaternaryMatroid(matrix=Matrix(GF(4, 'x'), # indirect doctest, optional - sage.rings.finite_rings + sage: QuaternaryMatroid(matrix=Matrix(GF(4, 'x'), # indirect doctest # needs sage.rings.finite_rings ....: [[1, 0, 1, 1, 1], ....: [0, 1, 1, 1, 1]])) Quaternary matroid of rank 2 on 5 elements @@ -5099,9 +5101,9 @@ cdef class QuaternaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = Matroid(ring=GF(4, 'y'), reduced_matrix=[[1, 0, 1], # optional - sage.rings.finite_rings + sage: M = Matroid(ring=GF(4, 'y'), reduced_matrix=[[1, 0, 1], # needs sage.rings.finite_rings ....: [0, 1, 1]]) - sage: M.base_ring() # optional - sage.rings.finite_rings + sage: M.base_ring() # needs sage.rings.finite_rings Finite Field in y of size 2^2 """ return (self._A).base_ring() @@ -5113,9 +5115,9 @@ cdef class QuaternaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = Matroid(ring=GF(4, 'y'), reduced_matrix=[[1, 0, 1], # optional - sage.rings.finite_rings + sage: M = Matroid(ring=GF(4, 'y'), reduced_matrix=[[1, 0, 1], # needs sage.rings.finite_rings ....: [0, 1, 1]]) - sage: M.characteristic() # optional - sage.rings.finite_rings + sage: M.characteristic() # needs sage.rings.finite_rings 2 """ return 2 @@ -5176,9 +5178,9 @@ cdef class QuaternaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = Matroid(ring=GF(4, 'x'), matrix=[[1, 0, 1], [0, 1, 1]]) # optional - sage.rings.finite_rings - sage: M.rename() # optional - sage.rings.finite_rings - sage: repr(M) # indirect doctest # optional - sage.rings.finite_rings + sage: M = Matroid(ring=GF(4, 'x'), matrix=[[1, 0, 1], [0, 1, 1]]) # needs sage.rings.finite_rings + sage: M.rename() # needs sage.rings.finite_rings + sage: repr(M) # indirect doctest # needs sage.rings.finite_rings 'Quaternary matroid of rank 2 on 3 elements' """ S = "Quaternary matroid of rank " + str(self.rank()) + " on " + str(self.size()) + " elements" @@ -5202,13 +5204,14 @@ cdef class QuaternaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.Q10() # optional - sage.rings.finite_rings - sage: A = M._reduced_representation('efghi') # optional - sage.rings.finite_rings - sage: R, C = M._current_rows_cols() # optional - sage.rings.finite_rings - sage: (sorted(R), sorted(C)) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: M = matroids.named_matroids.Q10() + sage: A = M._reduced_representation('efghi') + sage: R, C = M._current_rows_cols() + sage: (sorted(R), sorted(C)) (['e', 'f', 'g', 'h', 'i'], ['a', 'b', 'c', 'd', 'j']) - sage: R, C = M._current_rows_cols(B='abcde') # optional - sage.rings.finite_rings - sage: (sorted(R), sorted(C)) # optional - sage.rings.finite_rings + sage: R, C = M._current_rows_cols(B='abcde') + sage: (sorted(R), sorted(C)) (['a', 'b', 'c', 'd', 'e'], ['f', 'g', 'h', 'i', 'j']) """ @@ -5250,15 +5253,15 @@ cdef class QuaternaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.Q10() # optional - sage.rings.finite_rings - sage: M._basic_representation() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Q10() # needs sage.rings.finite_rings + sage: M._basic_representation() # needs sage.rings.finite_rings 5 x 10 QuaternaryMatrix [100001x00y] [01000y1x00] [001000y1x0] [0001000y1x] [00001x00y1] - sage: matrix(M._basic_representation('efghi')) # optional - sage.rings.finite_rings + sage: matrix(M._basic_representation('efghi')) # needs sage.rings.finite_rings [ 1 0 x + 1 1 0 1 0 0 0 1] [ x x + 1 0 0 0 0 0 1 0 1] [ 0 0 x x + 1 0 0 1 0 0 1] @@ -5293,15 +5296,15 @@ cdef class QuaternaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.Q10() # optional - sage.rings.finite_rings - sage: M._reduced_representation() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Q10() # needs sage.rings.finite_rings + sage: M._reduced_representation() # needs sage.rings.finite_rings 5 x 5 QuaternaryMatrix [1x00y] [y1x00] [0y1x0] [00y1x] [x00y1] - sage: matrix(M._reduced_representation('efghi')) # optional - sage.rings.finite_rings + sage: matrix(M._reduced_representation('efghi')) # needs sage.rings.finite_rings [ 1 0 x + 1 1 1] [ x x + 1 0 0 1] [ 0 0 x x + 1 1] @@ -5321,8 +5324,8 @@ cdef class QuaternaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.Q10() # optional - sage.rings.finite_rings - sage: M._invariant() # indirect doctest # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Q10() # needs sage.rings.finite_rings + sage: M._invariant() # indirect doctest # needs sage.rings.finite_rings (0, 0, 5, 5, 20, 10, 25) """ cdef QuaternaryMatrix Q, QT @@ -5400,8 +5403,8 @@ cdef class QuaternaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.Q10() # optional - sage.rings.finite_rings - sage: M._invariant() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Q10() # needs sage.rings.finite_rings + sage: M._invariant() # needs sage.rings.finite_rings (0, 0, 5, 5, 20, 10, 25) """ @@ -5428,8 +5431,8 @@ cdef class QuaternaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.Q10() # optional - sage.rings.finite_rings - sage: M.bicycle_dimension() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Q10() # needs sage.rings.finite_rings + sage: M.bicycle_dimension() # needs sage.rings.finite_rings 0 """ if self._q_invariant is None: @@ -5455,14 +5458,15 @@ cdef class QuaternaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.Q10()\'a' # optional - sage.rings.finite_rings - sage: for F in M._principal_tripartition(): print(sorted(F)) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: M = matroids.named_matroids.Q10()\'a' + sage: for F in M._principal_tripartition(): print(sorted(F)) ['b', 'c', 'd', 'e', 'h', 'i'] ['f', 'g', 'j'] [] - sage: M.bicycle_dimension() # optional - sage.rings.finite_rings + sage: M.bicycle_dimension() 1 - sage: for i in [-1, 0, 1]: # optional - sage.rings.finite_rings + sage: for i in [-1, 0, 1]: ....: print(sorted(e for e in M.groundset() ....: if (M\e).bicycle_dimension() == 1 + i)) ['b', 'c', 'd', 'e', 'h', 'i'] @@ -5493,9 +5497,9 @@ cdef class QuaternaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.Q10()\'a' # optional - sage.rings.finite_rings - sage: N = matroids.named_matroids.Q10()\'b' # optional - sage.rings.finite_rings - sage: M._fast_isom_test(N) is None # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Q10()\'a' # needs sage.rings.finite_rings + sage: N = matroids.named_matroids.Q10()\'b' # needs sage.rings.finite_rings + sage: M._fast_isom_test(N) is None # needs sage.rings.finite_rings True """ if self._invariant() != other._invariant(): @@ -5529,9 +5533,9 @@ cdef class QuaternaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.Q10() # optional - sage.rings.finite_rings - sage: N = M._minor(contractions=set(['a']), deletions=set([])) # optional - sage.rings.finite_rings - sage: N._minor(contractions=set([]), deletions=set(['b', 'c'])) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Q10() # needs sage.rings.finite_rings + sage: N = M._minor(contractions=set(['a']), deletions=set([])) # needs sage.rings.finite_rings + sage: N._minor(contractions=set([]), deletions=set(['b', 'c'])) # needs sage.rings.finite_rings Quaternary matroid of rank 4 on 7 elements """ self._move_current_basis(contractions, deletions) @@ -5558,8 +5562,8 @@ cdef class QuaternaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = Matroid(Matrix(GF(4, 'x'), [[]])) # optional - sage.rings.finite_rings - sage: M.is_valid() # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(4, 'x'), [[]])) # needs sage.rings.finite_rings + sage: M.is_valid() # needs sage.rings.finite_rings True """ return True @@ -5570,10 +5574,10 @@ cdef class QuaternaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = Matroid(Matrix(GF(4, 'x'), [[1, 0, 0, 1, 1], # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(4, 'x'), [[1, 0, 0, 1, 1], # needs sage.rings.finite_rings ....: [0, 1, 0, 1, 2], [0, 0, 1, 1, 3]])) - sage: N = copy(M) # indirect doctest # optional - sage.rings.finite_rings - sage: M == N # optional - sage.rings.finite_rings + sage: N = copy(M) # indirect doctest # needs sage.rings.finite_rings + sage: M == N # needs sage.rings.finite_rings True """ cdef QuaternaryMatroid N @@ -5594,10 +5598,10 @@ cdef class QuaternaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = Matroid(Matrix(GF(4, 'x'), [[1, 0, 0, 1, 1], # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(4, 'x'), [[1, 0, 0, 1, 1], # needs sage.rings.finite_rings ....: [0, 1, 0, 1, 2], [0, 0, 1, 1, -1]])) - sage: N = deepcopy(M) # indirect doctest # optional - sage.rings.finite_rings - sage: M == N # optional - sage.rings.finite_rings + sage: N = deepcopy(M) # indirect doctest # needs sage.rings.finite_rings + sage: M == N # needs sage.rings.finite_rings True """ from copy import deepcopy @@ -5633,12 +5637,13 @@ cdef class QuaternaryMatroid(LinearMatroid): EXAMPLES:: - sage: M = Matroid(Matrix(GF(4, 'x'), [[1, 0, 0, 1], [0, 1, 0, 1], # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(4, 'x'), [[1, 0, 0, 1], [0, 1, 0, 1], ....: [0, 0, 1, 1]])) - sage: M == loads(dumps(M)) # indirect doctest # optional - sage.rings.finite_rings + sage: M == loads(dumps(M)) # indirect doctest True - sage: M.rename("U34") # optional - sage.rings.finite_rings - sage: loads(dumps(M)) # optional - sage.rings.finite_rings + sage: M.rename("U34") + sage: loads(dumps(M)) U34 TESTS: @@ -5646,14 +5651,14 @@ cdef class QuaternaryMatroid(LinearMatroid): Check that :trac:`23437` is fixed:: sage: from sage.matroids.advanced import QuaternaryMatroid - sage: X_bin = matroids.named_matroids.Fano().representation() # optional - sage.rings.finite_rings - sage: X = Matrix(GF(4), X_bin) # optional - sage.rings.finite_rings - sage: M = QuaternaryMatroid(matrix=X).dual() # optional - sage.rings.finite_rings - sage: B = list(M.bases()) # optional - sage.rings.finite_rings - sage: N = loads(dumps(M)) # optional - sage.rings.finite_rings - sage: N.closure(frozenset({3})) # optional - sage.rings.finite_rings + sage: X_bin = matroids.named_matroids.Fano().representation() + sage: X = Matrix(GF(4), X_bin) # needs sage.rings.finite_rings + sage: M = QuaternaryMatroid(matrix=X).dual() # needs sage.rings.finite_rings + sage: B = list(M.bases()) # needs sage.rings.finite_rings + sage: N = loads(dumps(M)) # needs sage.rings.finite_rings + sage: N.closure(frozenset({3})) # needs sage.rings.finite_rings frozenset({3}) - sage: N.is_isomorphic(M) # optional - sage.rings.finite_rings + sage: N.is_isomorphic(M) # needs sage.rings.finite_rings True """ import sage.matroids.unpickling @@ -5734,15 +5739,15 @@ cdef class RegularMatroid(LinearMatroid): EXAMPLES:: sage: A = Matrix(ZZ, 2, 4, [[1, 0, 1, 1], [0, 1, 1, 1]]) - sage: M = Matroid(A, regular=True); M # optional - sage.graphs + sage: M = Matroid(A, regular=True); M # needs sage.graphs Regular matroid of rank 2 on 4 elements with 5 bases - sage: sorted(M.groundset()) # optional - sage.graphs + sage: sorted(M.groundset()) # needs sage.graphs [0, 1, 2, 3] - sage: Matrix(M) # optional - sage.graphs + sage: Matrix(M) # needs sage.graphs [1 0 1 1] [0 1 1 1] - sage: M = Matroid(matrix=A, groundset='abcd', regular=True) # optional - sage.graphs - sage: sorted(M.groundset()) # optional - sage.graphs + sage: M = Matroid(matrix=A, groundset='abcd', regular=True) # needs sage.graphs + sage: sorted(M.groundset()) # needs sage.graphs ['a', 'b', 'c', 'd'] """ def __init__(self, matrix=None, groundset=None, reduced_matrix=None, ring=None, keep_initial_representation=True): @@ -5758,7 +5763,7 @@ cdef class RegularMatroid(LinearMatroid): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: RegularMatroid(matrix=Matrix(ZZ, [[1, 0, 1, 1, 1], # indirect doctest, optional - sage.graphs + sage: RegularMatroid(matrix=Matrix(ZZ, [[1, 0, 1, 1, 1], # indirect doctest # needs sage.graphs ....: [0, 1, 1, 1, 1]])) Regular matroid of rank 2 on 5 elements with 7 bases """ @@ -5897,8 +5902,8 @@ cdef class RegularMatroid(LinearMatroid): EXAMPLES:: - sage: M = Matroid(graphs.CompleteGraph(5), regular=True) # optional - sage.graphs - sage: M.bases_count() # optional - sage.graphs + sage: M = Matroid(graphs.CompleteGraph(5), regular=True) # needs sage.graphs + sage: M.bases_count() # needs sage.graphs 125 ALGORITHM: @@ -6025,8 +6030,8 @@ cdef class RegularMatroid(LinearMatroid): EXAMPLES:: sage: M = matroids.named_matroids.R10() - sage: PV, tups, G = M._hypergraph() # optional - sage.graphs - sage: G # optional - sage.graphs + sage: PV, tups, G = M._hypergraph() # needs sage.graphs + sage: G # needs sage.graphs Digraph on 55 vertices """ # NEW VERSION, Uses Sage'S Graph Isomorphism @@ -6107,20 +6112,20 @@ cdef class RegularMatroid(LinearMatroid): EXAMPLES:: sage: M1 = matroids.Wheel(3) - sage: M2 = Matroid(groundset=list(range(6)), # optional - sage.graphs + sage: M2 = Matroid(groundset=list(range(6)), # needs sage.graphs ....: graph=graphs.CompleteGraph(4), regular=True) - sage: M1._is_isomorphic(M2) # optional - sage.graphs + sage: M1._is_isomorphic(M2) # needs sage.graphs True - sage: M1._is_isomorphic(M2, certificate=True) # optional - sage.graphs + sage: M1._is_isomorphic(M2, certificate=True) # needs sage.graphs (True, {0: 0, 1: 1, 2: 2, 3: 3, 4: 5, 5: 4}) sage: M1 = matroids.Wheel(3) - sage: M2 = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M1._is_isomorphic(M2) # optional - sage.rings.finite_rings + sage: M2 = matroids.named_matroids.Fano() + sage: M1._is_isomorphic(M2) False - sage: M1._is_isomorphic(M2.delete('a')) # optional - sage.rings.finite_rings + sage: M1._is_isomorphic(M2.delete('a')) True - sage: M1._is_isomorphic(M2.delete('a'), certificate=True) # optional - sage.rings.finite_rings + sage: M1._is_isomorphic(M2.delete('a'), certificate=True) (True, {0: 'g', 1: 'b', 2: 'c', 3: 'e', 4: 'd', 5: 'f'}) Check that :trac:`17316` was fixed:: @@ -6179,7 +6184,7 @@ cdef class RegularMatroid(LinearMatroid): sage: M = matroids.named_matroids.R10()\'a' sage: N = matroids.named_matroids.R10()\'b' - sage: M._fast_isom_test(N) # optional - sage.graphs + sage: M._fast_isom_test(N) # needs sage.graphs True """ if self.bases_count() != other.bases_count(): @@ -6210,9 +6215,9 @@ cdef class RegularMatroid(LinearMatroid): Check that :trac:`22263` was fixed:: - sage: m1 = Matroid(graph='H?ABC~}') # optional - sage.graphs - sage: m2 = Matroid(graph='H?ACNr}') # optional - sage.graphs - sage: m1.is_isomorphic(m2) # optional - sage.graphs + sage: m1 = Matroid(graph='H?ABC~}') # needs sage.graphs + sage: m2 = Matroid(graph='H?ACNr}') # needs sage.graphs + sage: m1.is_isomorphic(m2) # needs sage.graphs False """ from sage.groups.perm_gps.partn_ref.refinement_graphs import isomorphic @@ -6331,13 +6336,13 @@ cdef class RegularMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.R10() # optional - sage.rings.finite_rings - sage: M.is_graphic() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.R10() + sage: M.is_graphic() False - sage: M = Matroid(graphs.CompleteGraph(5), regular=True) # optional - sage.graphs - sage: M.is_graphic() # optional - sage.graphs + sage: M = Matroid(graphs.CompleteGraph(5), regular=True) # needs sage.graphs + sage: M.is_graphic() # needs sage.graphs sage.rings.finite_rings True - sage: M.dual().is_graphic() # optional - sage.graphs + sage: M.dual().is_graphic() # needs sage.graphs False ALGORITHM: @@ -6363,14 +6368,15 @@ cdef class RegularMatroid(LinearMatroid): EXAMPLES:: - sage: M = Matroid(Matrix(ZZ, [[1, 0, 0, 1, 1, 0, 1], # optional - sage.graphs + sage: # needs sage.graphs + sage: M = Matroid(Matrix(ZZ, [[1, 0, 0, 1, 1, 0, 1], ....: [0, 1, 0, 1, 0, 1, 1], ....: [0, 0, 1, 0, 1, 1, 1]]), ....: regular=True, check=False) - sage: M.is_valid() # optional - sage.graphs + sage: M.is_valid() False - sage: M = Matroid(graphs.PetersenGraph()) # optional - sage.graphs - sage: M.is_valid() # optional - sage.graphs + sage: M = Matroid(graphs.PetersenGraph()) + sage: M.is_valid() True """ M = LinearMatroid(ring=QQ, reduced_matrix=self.representation(self.basis(), True, False)) @@ -6403,8 +6409,8 @@ cdef class RegularMatroid(LinearMatroid): EXAMPLES:: - sage: N = matroids.named_matroids.R10() # optional - sage.rings.finite_rings - sage: N.binary_matroid() # optional - sage.rings.finite_rings + sage: N = matroids.named_matroids.R10() + sage: N.binary_matroid() Binary matroid of rank 5 on 10 elements, type (1, None) """ @@ -6433,8 +6439,8 @@ cdef class RegularMatroid(LinearMatroid): EXAMPLES:: - sage: N = matroids.named_matroids.R10() # optional - sage.rings.finite_rings - sage: N.is_binary() # optional - sage.rings.finite_rings + sage: N = matroids.named_matroids.R10() + sage: N.is_binary() True """ return True @@ -6463,8 +6469,8 @@ cdef class RegularMatroid(LinearMatroid): EXAMPLES:: - sage: N = matroids.named_matroids.R10() # optional - sage.rings.finite_rings - sage: N.ternary_matroid() # optional - sage.rings.finite_rings + sage: N = matroids.named_matroids.R10() + sage: N.ternary_matroid() Ternary matroid of rank 5 on 10 elements, type 4+ """ @@ -6493,8 +6499,8 @@ cdef class RegularMatroid(LinearMatroid): EXAMPLES:: - sage: N = matroids.named_matroids.R10() # optional - sage.rings.finite_rings - sage: N.is_ternary() # optional - sage.rings.finite_rings + sage: N = matroids.named_matroids.R10() + sage: N.is_ternary() True """ return True @@ -6507,9 +6513,9 @@ cdef class RegularMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.R10() # optional - sage.rings.finite_rings - sage: N = copy(M) # indirect doctest # optional - sage.rings.finite_rings - sage: M == N # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.R10() + sage: N = copy(M) # indirect doctest + sage: M == N True """ cdef RegularMatroid N @@ -6527,9 +6533,9 @@ cdef class RegularMatroid(LinearMatroid): EXAMPLES:: - sage: M = matroids.named_matroids.R10() # optional - sage.rings.finite_rings - sage: N = deepcopy(M) # indirect doctest # optional - sage.rings.finite_rings - sage: M == N # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.R10() + sage: N = deepcopy(M) # indirect doctest + sage: M == N True """ cdef RegularMatroid N diff --git a/src/sage/matroids/matroid.pyx b/src/sage/matroids/matroid.pyx index a465d47149f..3caac5bea62 100644 --- a/src/sage/matroids/matroid.pyx +++ b/src/sage/matroids/matroid.pyx @@ -216,7 +216,7 @@ in which the partition is specified as a list of lists:: sage: M = PartitionMatroid([[1, 2], [3, 4, 5], [6, 7]]) sage: M.full_rank() 3 - sage: M.tutte_polynomial(var('x'), var('y')) # optional - sage.symbolic + sage: M.tutte_polynomial(var('x'), var('y')) # needs sage.symbolic x^2*y^2 + 2*x*y^3 + y^4 + x^3 + 3*x^2*y + 3*x*y^2 + y^3 .. NOTE:: @@ -330,22 +330,23 @@ Methods # https://www.gnu.org/licenses/ # **************************************************************************** -from cpython.object cimport Py_EQ, Py_NE from collections.abc import Iterable +from cpython.object cimport Py_EQ, Py_NE +from itertools import combinations, product +from sage.matrix.constructor import matrix +from sage.misc.lazy_import import LazyImport +from sage.misc.prandom import shuffle +from sage.rings.integer_ring import ZZ from sage.structure.richcmp cimport rich_to_bool, richcmp from sage.structure.sage_object cimport SageObject -from itertools import combinations, product -from .set_system cimport SetSystem -from sage.graphs.graph import Graph -from sage.matrix.constructor import matrix +MixedIntegerLinearProgram = LazyImport('sage.numerical.mip', 'MixedIntegerLinearProgram') + +from .lean_matrix cimport BinaryMatrix, TernaryMatrix +from .set_system cimport SetSystem from .utilities import newlabel, sanitize_contractions_deletions, spanning_forest, spanning_stars -from sage.rings.integer_ring import ZZ -from sage.numerical.mip import MixedIntegerLinearProgram -from sage.matroids.lean_matrix cimport BinaryMatrix, TernaryMatrix -from sage.misc.prandom import shuffle # On some systems, macros "minor()" and "major()" are defined in system header # files. This will undefine those: @@ -394,7 +395,7 @@ cdef class Matroid(SageObject): sage: M = PartitionMatroid([[1, 2], [3, 4, 5], [6, 7]]) sage: M.full_rank() 3 - sage: M.tutte_polynomial(var('x'), var('y')) # optional - sage.symbolic + sage: M.tutte_polynomial(var('x'), var('y')) # needs sage.symbolic x^2*y^2 + 2*x*y^3 + y^4 + x^3 + 3*x^2*y + 3*x*y^2 + y^3 .. NOTE:: @@ -1133,7 +1134,7 @@ cdef class Matroid(SageObject): EXAMPLES:: sage: M = matroids.named_matroids.Vamos() - sage: M._has_minor(matroids.Whirl(3)) # optional - sage.rings.finite_rings + sage: M._has_minor(matroids.Whirl(3)) False sage: M._has_minor(matroids.Uniform(2, 4)) True @@ -1361,12 +1362,12 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M.rank() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M.rank() 3 - sage: M.rank(['a', 'b', 'f']) # optional - sage.rings.finite_rings + sage: M.rank(['a', 'b', 'f']) 2 - sage: M.rank(['a', 'b', 'x']) # optional - sage.rings.finite_rings + sage: M.rank(['a', 'b', 'x']) Traceback (most recent call last): ... ValueError: ['a', 'b', 'x'] is not a subset of the groundset @@ -1672,12 +1673,12 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M.corank() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M.corank() 4 - sage: M.corank('cdeg') # optional - sage.rings.finite_rings + sage: M.corank('cdeg') 3 - sage: M.rank(['a', 'b', 'x']) # optional - sage.rings.finite_rings + sage: M.rank(['a', 'b', 'x']) Traceback (most recent call last): ... ValueError: ['a', 'b', 'x'] is not a subset of the groundset @@ -1914,10 +1915,10 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M.loops() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M.loops() frozenset() - sage: (M / ['a', 'b']).loops() # optional - sage.rings.finite_rings + sage: (M / ['a', 'b']).loops() frozenset({'f'}) """ return self._closure(set()) @@ -2138,10 +2139,10 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano().dual() # optional - sage.rings.finite_rings - sage: M.coloops() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano().dual() + sage: M.coloops() frozenset() - sage: (M \ ['a', 'b']).coloops() # optional - sage.rings.finite_rings + sage: (M \ ['a', 'b']).coloops() frozenset({'f'}) """ return self._coclosure(set()) @@ -2384,8 +2385,8 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: sorted([sorted(C) for C in M.circuits()]) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: sorted([sorted(C) for C in M.circuits()]) [['a', 'b', 'c', 'g'], ['a', 'b', 'd', 'e'], ['a', 'b', 'f'], ['a', 'c', 'd', 'f'], ['a', 'c', 'e'], ['a', 'd', 'g'], ['a', 'e', 'f', 'g'], ['b', 'c', 'd'], ['b', 'c', 'e', 'f'], @@ -2416,8 +2417,8 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: sorted([sorted(C) for C in M.nonspanning_circuits()]) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: sorted([sorted(C) for C in M.nonspanning_circuits()]) [['a', 'b', 'f'], ['a', 'c', 'e'], ['a', 'd', 'g'], ['b', 'c', 'd'], ['b', 'e', 'g'], ['c', 'f', 'g'], ['d', 'e', 'f']] @@ -2442,8 +2443,8 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: sorted([sorted(C) for C in M.cocircuits()]) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: sorted([sorted(C) for C in M.cocircuits()]) [['a', 'b', 'c', 'g'], ['a', 'b', 'd', 'e'], ['a', 'c', 'd', 'f'], ['a', 'e', 'f', 'g'], ['b', 'c', 'e', 'f'], ['b', 'd', 'f', 'g'], ['c', 'd', 'e', 'g']] @@ -2471,8 +2472,8 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano().dual() # optional - sage.rings.finite_rings - sage: sorted([sorted(C) for C in M.noncospanning_cocircuits()]) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano().dual() + sage: sorted([sorted(C) for C in M.noncospanning_cocircuits()]) [['a', 'b', 'f'], ['a', 'c', 'e'], ['a', 'd', 'g'], ['b', 'c', 'd'], ['b', 'e', 'g'], ['c', 'f', 'g'], ['d', 'e', 'f']] @@ -2497,17 +2498,17 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: CC = M.circuit_closures() # optional - sage.rings.finite_rings - sage: len(CC[2]) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: CC = M.circuit_closures() + sage: len(CC[2]) 7 - sage: len(CC[3]) # optional - sage.rings.finite_rings + sage: len(CC[3]) 1 - sage: len(CC[1]) # optional - sage.rings.finite_rings + sage: len(CC[1]) Traceback (most recent call last): ... KeyError: 1 - sage: [sorted(X) for X in CC[3]] # optional - sage.rings.finite_rings + sage: [sorted(X) for X in CC[3]] [['a', 'b', 'c', 'd', 'e', 'f', 'g']] """ CC = [set([]) for r in range(self.rank() + 1)] @@ -2534,11 +2535,11 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: CC = M.nonspanning_circuit_closures() # optional - sage.rings.finite_rings - sage: len(CC[2]) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: CC = M.nonspanning_circuit_closures() + sage: len(CC[2]) 7 - sage: len(CC[3]) # optional - sage.rings.finite_rings + sage: len(CC[3]) Traceback (most recent call last): ... KeyError: 3 @@ -2737,9 +2738,9 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: F = M._flags(1) # optional - sage.rings.finite_rings - sage: sorted(M._extend_flags(F)) == sorted(M._flags(2)) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: F = M._flags(1) + sage: sorted(M._extend_flags(F)) == sorted(M._flags(2)) True """ newflags = [] @@ -2777,8 +2778,8 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: sorted([M._flags(1)]) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: sorted([M._flags(1)]) [[[frozenset({'a'}), {'a'}, frozenset({'b', 'c', 'd', 'e', 'f', 'g'})], [frozenset({'b'}), {'b'}, frozenset({'c', 'd', 'e', 'f', 'g'})], [frozenset({'c'}), {'c'}, frozenset({'d', 'e', 'f', 'g'})], @@ -2815,8 +2816,8 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: sorted([sorted(F) for F in M.flats(2)]) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: sorted([sorted(F) for F in M.flats(2)]) [['a', 'b', 'f'], ['a', 'c', 'e'], ['a', 'd', 'g'], ['b', 'c', 'd'], ['b', 'e', 'g'], ['c', 'f', 'g'], ['d', 'e', 'f']] @@ -2844,8 +2845,8 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Q6() # optional - sage.rings.finite_rings - sage: sorted([sorted(F) for F in M.coflats(2)]) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Q6() # needs sage.rings.finite_rings + sage: sorted([sorted(F) for F in M.coflats(2)]) # needs sage.rings.finite_rings [['a', 'b'], ['a', 'c'], ['a', 'd', 'f'], ['a', 'e'], ['b', 'c'], ['b', 'd'], ['b', 'e'], ['b', 'f'], ['c', 'd'], ['c', 'e', 'f'], ['d', 'e']] @@ -2858,8 +2859,8 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M.lattice_of_flats() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M.lattice_of_flats() # needs sage.graphs Finite lattice containing 16 elements """ from sage.combinat.posets.lattices import LatticePoset @@ -2973,17 +2974,17 @@ cdef class Matroid(SageObject): EXAMPLES:: sage: M = Matroid(circuits=[[1,2,3], [3,4,5], [1,2,4,5]]) - sage: SimplicialComplex(M.no_broken_circuits_sets()) + sage: SimplicialComplex(M.no_broken_circuits_sets()) # needs sage.graphs Simplicial complex with vertex set (1, 2, 3, 4, 5) and facets {(1, 2, 4), (1, 2, 5), (1, 3, 4), (1, 3, 5)} - sage: SimplicialComplex(M.no_broken_circuits_sets([5,4,3,2,1])) + sage: SimplicialComplex(M.no_broken_circuits_sets([5,4,3,2,1])) # needs sage.graphs Simplicial complex with vertex set (1, 2, 3, 4, 5) and facets {(1, 3, 5), (1, 4, 5), (2, 3, 5), (2, 4, 5)} :: sage: M = Matroid(circuits=[[1,2,3], [1,4,5], [2,3,4,5]]) - sage: SimplicialComplex(M.no_broken_circuits_sets([5,4,3,2,1])) + sage: SimplicialComplex(M.no_broken_circuits_sets([5,4,3,2,1])) # needs sage.graphs Simplicial complex with vertex set (1, 2, 3, 4, 5) and facets {(1, 3, 5), (2, 3, 5), (2, 4, 5), (3, 4, 5)} @@ -3071,9 +3072,10 @@ cdef class Matroid(SageObject): with circuit-closures {3: {{0, 1, 2, 3}}} - sage: G = SymmetricGroup(3); - sage: OSG = M.orlik_solomon_algebra(QQ, invariant=G) + sage: G = SymmetricGroup(3); # needs sage.groups + sage: OSG = M.orlik_solomon_algebra(QQ, invariant=G) # needs sage.groups + sage: # needs sage.groups sage: G = SymmetricGroup(4) sage: action = lambda g,x: g(x+1)-1 sage: OSG1 = M.orlik_solomon_algebra(QQ, invariant=(G,action)) @@ -3125,13 +3127,13 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.Whirl(4) # optional - sage.rings.finite_rings - sage: P = M.matroid_polytope(); P # optional - sage.geometry.polyhedron sage.rings.finite_rings + sage: M = matroids.Whirl(4) + sage: P = M.matroid_polytope(); P # needs sage.geometry.polyhedron sage.rings.finite_rings A 7-dimensional polyhedron in ZZ^8 defined as the convex hull of 46 vertices - sage: M = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: M.matroid_polytope() # optional - sage.geometry.polyhedron sage.rings.finite_rings + sage: M = matroids.named_matroids.NonFano() + sage: M.matroid_polytope() # needs sage.geometry.polyhedron sage.rings.finite_rings A 6-dimensional polyhedron in ZZ^7 defined as the convex hull of 29 vertices @@ -3168,13 +3170,13 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.Whirl(4) # optional - sage.rings.finite_rings - sage: M.independence_matroid_polytope() # optional - sage.geometry.polyhedron sage.rings.finite_rings + sage: M = matroids.Whirl(4) + sage: M.independence_matroid_polytope() # needs sage.geometry.polyhedron sage.rings.finite_rings A 8-dimensional polyhedron in ZZ^8 defined as the convex hull of 135 vertices - sage: M = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: M.independence_matroid_polytope() # optional - sage.geometry.polyhedron sage.rings.finite_rings + sage: M = matroids.named_matroids.NonFano() + sage: M.independence_matroid_polytope() # needs sage.geometry.polyhedron sage.rings.finite_rings A 7-dimensional polyhedron in ZZ^7 defined as the convex hull of 58 vertices @@ -3215,23 +3217,23 @@ cdef class Matroid(SageObject): EXAMPLES:: sage: M1 = matroids.Wheel(3) - sage: M2 = matroids.CompleteGraphic(4) - sage: M1.is_isomorphic(M2) + sage: M2 = matroids.CompleteGraphic(4) # needs sage.graphs + sage: M1.is_isomorphic(M2) # needs sage.graphs True - sage: M1.is_isomorphic(M2, certificate=True) + sage: M1.is_isomorphic(M2, certificate=True) # needs sage.graphs (True, {0: 0, 1: 1, 2: 2, 3: 3, 4: 5, 5: 4}) - sage: G3 = graphs.CompleteGraph(4) - sage: M1.is_isomorphic(G3) + sage: G3 = graphs.CompleteGraph(4) # needs sage.graphs + sage: M1.is_isomorphic(G3) # needs sage.graphs Traceback (most recent call last): ... TypeError: can only test for isomorphism between matroids. - sage: M1 = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M2 = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: M1.is_isomorphic(M2) # optional - sage.rings.finite_rings + sage: M1 = matroids.named_matroids.Fano() + sage: M2 = matroids.named_matroids.NonFano() + sage: M1.is_isomorphic(M2) False - sage: M1.is_isomorphic(M2, certificate=True) # optional - sage.rings.finite_rings + sage: M1.is_isomorphic(M2, certificate=True) (False, None) """ if not isinstance(other, Matroid): @@ -3261,15 +3263,15 @@ cdef class Matroid(SageObject): EXAMPLES:: sage: M1 = matroids.Wheel(3) - sage: M2 = matroids.CompleteGraphic(4) - sage: M1._is_isomorphic(M2) + sage: M2 = matroids.CompleteGraphic(4) # needs sage.graphs + sage: M1._is_isomorphic(M2) # needs sage.graphs True - sage: M1._is_isomorphic(M2, certificate=True) + sage: M1._is_isomorphic(M2, certificate=True) # needs sage.graphs (True, {0: 0, 1: 1, 2: 2, 3: 3, 4: 5, 5: 4}) - sage: M1 = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M2 = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: M1._is_isomorphic(M2) # optional - sage.rings.finite_rings + sage: M1 = matroids.named_matroids.Fano() + sage: M2 = matroids.named_matroids.NonFano() + sage: M1._is_isomorphic(M2) False """ @@ -3299,19 +3301,19 @@ cdef class Matroid(SageObject): EXAMPLES:: sage: M1 = matroids.Wheel(3) - sage: M2 = matroids.CompleteGraphic(4) - sage: morphism=M1.isomorphism(M2) - sage: M1.is_isomorphism(M2, morphism) + sage: M2 = matroids.CompleteGraphic(4) # needs sage.graphs + sage: morphism = M1.isomorphism(M2) # needs sage.graphs + sage: M1.is_isomorphism(M2, morphism) # needs sage.graphs True - sage: G3 = graphs.CompleteGraph(4) - sage: M1.isomorphism(G3) + sage: G3 = graphs.CompleteGraph(4) # needs sage.graphs + sage: M1.isomorphism(G3) # needs sage.graphs Traceback (most recent call last): ... TypeError: can only give isomorphism between matroids. - sage: M1 = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M2 = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: M1.isomorphism(M2) is not None # optional - sage.rings.finite_rings + sage: M1 = matroids.named_matroids.Fano() + sage: M2 = matroids.named_matroids.NonFano() + sage: M1.isomorphism(M2) is not None False """ if not isinstance(other, Matroid): @@ -3335,13 +3337,13 @@ cdef class Matroid(SageObject): EXAMPLES:: sage: M1 = matroids.Wheel(3) - sage: M2 = matroids.CompleteGraphic(4) - sage: morphism=M1.isomorphism(M2) - sage: M1.is_isomorphism(M2, morphism) + sage: M2 = matroids.CompleteGraphic(4) # needs sage.graphs + sage: morphism = M1.isomorphism(M2) # needs sage.graphs + sage: M1.is_isomorphism(M2, morphism) # needs sage.graphs True - sage: M1 = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M2 = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: M1.isomorphism(M2) is not None # optional - sage.rings.finite_rings + sage: M1 = matroids.named_matroids.Fano() + sage: M2 = matroids.named_matroids.NonFano() + sage: M1.isomorphism(M2) is not None False """ if self is other: @@ -3385,38 +3387,37 @@ cdef class Matroid(SageObject): yields ``False``, even if the matroids are equal:: sage: from sage.matroids.advanced import * - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano(); M Fano: Binary matroid of rank 3 on 7 elements, type (3, 0) - sage: M1 = BasisMatroid(M) # optional - sage.rings.finite_rings - sage: M2 = Matroid(groundset='abcdefg', reduced_matrix=[ # optional - sage.rings.finite_rings + sage: M1 = BasisMatroid(M) + sage: M2 = Matroid(groundset='abcdefg', reduced_matrix=[ ....: [0, 1, 1, 1], [1, 0, 1, 1], [1, 1, 0, 1]], field=GF(2)) - sage: M.equals(M1) # optional - sage.rings.finite_rings + sage: M.equals(M1) True - sage: M.equals(M2) # optional - sage.rings.finite_rings + sage: M.equals(M2) True - sage: M == M1 # optional - sage.rings.finite_rings + sage: M == M1 False - sage: M == M2 # optional - sage.rings.finite_rings + sage: M == M2 True :class:`LinearMatroid ` instances ``M`` and ``N`` satisfy ``M == N`` if the representations are equivalent up to row operations and column scaling:: - sage: M1 = LinearMatroid(groundset='abcd', matrix=Matrix(GF(7), # optional - sage.rings.finite_rings + sage: M1 = LinearMatroid(groundset='abcd', matrix=Matrix(GF(7), ....: [[1, 0, 1, 1], [0, 1, 1, 2]])) - sage: M2 = LinearMatroid(groundset='abcd', matrix=Matrix(GF(7), # optional - sage.rings.finite_rings + sage: M2 = LinearMatroid(groundset='abcd', matrix=Matrix(GF(7), ....: [[1, 0, 1, 1], [0, 1, 1, 3]])) - sage: M3 = LinearMatroid(groundset='abcd', matrix=Matrix(GF(7), # optional - sage.rings.finite_rings + sage: M3 = LinearMatroid(groundset='abcd', matrix=Matrix(GF(7), ....: [[2, 6, 1, 0], [6, 1, 0, 1]])) - sage: M1.equals(M2) # optional - sage.rings.finite_rings + sage: M1.equals(M2) True - sage: M1.equals(M3) # optional - sage.rings.finite_rings + sage: M1.equals(M3) True - sage: M1 == M2 # optional - sage.rings.finite_rings + sage: M1 == M2 False - sage: M1 == M3 # optional - sage.rings.finite_rings + sage: M1 == M3 True """ if self is other: @@ -3463,19 +3464,19 @@ cdef class Matroid(SageObject): sage: N.is_isomorphism(M, {e:e for e in M.groundset()}) False - sage: M = matroids.named_matroids.Fano() \ ['g'] # optional - sage.rings.finite_rings - sage: N = matroids.Wheel(3) # optional - sage.rings.finite_rings - sage: morphism = {'a':0, 'b':1, 'c': 2, 'd':4, 'e':5, 'f':3} # optional - sage.rings.finite_rings - sage: M.is_isomorphism(N, morphism) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() \ ['g'] + sage: N = matroids.Wheel(3) + sage: morphism = {'a':0, 'b':1, 'c': 2, 'd':4, 'e':5, 'f':3} + sage: M.is_isomorphism(N, morphism) True A morphism can be specified as a dictionary (above), a permutation, a function, and many other types of maps:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: P = PermutationGroup([[('a', 'b', 'c'), # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: P = PermutationGroup([[('a', 'b', 'c'), # needs sage.rings.finite_rings ....: ('d', 'e', 'f'), ('g')]]).gen() - sage: M.is_isomorphism(M, P) # optional - sage.rings.finite_rings + sage: M.is_isomorphism(M, P) # needs sage.rings.finite_rings True sage: M = matroids.named_matroids.Pappus() @@ -3490,12 +3491,14 @@ cdef class Matroid(SageObject): There is extensive checking for inappropriate input:: + sage: # needs sage.graphs sage: M = matroids.CompleteGraphic(4) - sage: M.is_isomorphism(graphs.CompleteGraph(4), lambda x:x) + sage: M.is_isomorphism(graphs.CompleteGraph(4), lambda x: x) Traceback (most recent call last): ... TypeError: can only test for isomorphism between matroids. + sage: # needs sage.graphs sage: M = matroids.CompleteGraphic(4) sage: sorted(M.groundset()) [0, 1, 2, 3, 4, 5] @@ -3505,6 +3508,7 @@ cdef class Matroid(SageObject): ValueError: domain of morphism does not contain groundset of this matroid. + sage: # needs sage.graphs sage: M = matroids.CompleteGraphic(4) sage: sorted(M.groundset()) [0, 1, 2, 3, 4, 5] @@ -3514,6 +3518,7 @@ cdef class Matroid(SageObject): ValueError: range of morphism does not contain groundset of other matroid. + sage: # needs sage.graphs sage: M = matroids.CompleteGraphic(3) sage: N = Matroid(bases=['ab', 'ac', 'bc']) sage: f = [0, 1, 2] @@ -3524,6 +3529,7 @@ cdef class Matroid(SageObject): ValueError: the morphism argument does not seem to be an isomorphism. + sage: # needs sage.graphs sage: N.is_isomorphism(M, g) True """ @@ -3572,10 +3578,10 @@ cdef class Matroid(SageObject): sage: N._is_isomorphism(M, {e:e for e in M.groundset()}) False - sage: M = matroids.named_matroids.Fano() \ ['g'] # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() \ ['g'] sage: N = matroids.Wheel(3) sage: morphism = {'a':0, 'b':1, 'c': 2, 'd':4, 'e':5, 'f':3} - sage: M._is_isomorphism(N, morphism) # optional - sage.rings.finite_rings + sage: M._is_isomorphism(N, morphism) True """ from . import basis_exchange_matroid @@ -3639,19 +3645,19 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M1 = Matroid(groundset='abcd', matrix=Matrix(GF(7), # optional - sage.rings.finite_rings + sage: M1 = Matroid(groundset='abcd', matrix=Matrix(GF(7), ....: [[1, 0, 1, 1], [0, 1, 1, 2]])) - sage: M2 = Matroid(groundset='abcd', matrix=Matrix(GF(7), # optional - sage.rings.finite_rings + sage: M2 = Matroid(groundset='abcd', matrix=Matrix(GF(7), ....: [[1, 0, 1, 1], [0, 1, 1, 3]])) - sage: M3 = Matroid(groundset='abcd', matrix=Matrix(GF(7), # optional - sage.rings.finite_rings + sage: M3 = Matroid(groundset='abcd', matrix=Matrix(GF(7), ....: [[2, 6, 1, 0], [6, 1, 0, 1]])) - sage: M1.equals(M2) # optional - sage.rings.finite_rings + sage: M1.equals(M2) True - sage: M1.equals(M3) # optional - sage.rings.finite_rings + sage: M1.equals(M3) True - sage: M1 != M2 # indirect doctest # optional - sage.rings.finite_rings + sage: M1 != M2 # indirect doctest True - sage: M1 == M3 # indirect doctest # optional - sage.rings.finite_rings + sage: M1 == M3 # indirect doctest True """ if op not in [Py_EQ, Py_NE]: @@ -3713,10 +3719,10 @@ cdef class Matroid(SageObject): The sets of contractions and deletions need not be independent, respectively coindependent:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M.rank('abf') # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M.rank('abf') 2 - sage: M.minor(contractions='abf') # optional - sage.rings.finite_rings + sage: M.minor(contractions='abf') Binary matroid of rank 1 on 4 elements, type (1, 0) However, they need to be subsets of the groundset, and disjoint:: @@ -3819,26 +3825,26 @@ cdef class Matroid(SageObject): :: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: sorted(M.groundset()) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: sorted(M.groundset()) ['a', 'b', 'c', 'd', 'e', 'f', 'g'] - sage: M.contract(['a', 'c']) # optional - sage.rings.finite_rings + sage: M.contract(['a', 'c']) Binary matroid of rank 1 on 5 elements, type (1, 0) - sage: M.contract(['a']) == M / ['a'] # optional - sage.rings.finite_rings + sage: M.contract(['a']) == M / ['a'] True One can use a single element, rather than a set:: - sage: M = matroids.CompleteGraphic(4) - sage: M.contract(1) == M.contract([1]) + sage: M = matroids.CompleteGraphic(4) # needs sage.graphs + sage: M.contract(1) == M.contract([1]) # needs sage.graphs True - sage: M / 1 + sage: M / 1 # needs sage.graphs Graphic matroid of rank 2 on 5 elements Note that one can iterate over strings:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M / 'abc' # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M / 'abc' Binary matroid of rank 0 on 4 elements, type (0, 0) The following is therefore ambiguous. Sage will contract the single @@ -3857,8 +3863,8 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.CompleteGraphic(4) - sage: M.contract(1) == M.__truediv__(1) + sage: M = matroids.CompleteGraphic(4) # needs sage.graphs + sage: M.contract(1) == M.__truediv__(1) # needs sage.graphs True """ return self.contract(X) @@ -3896,26 +3902,26 @@ cdef class Matroid(SageObject): :: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: sorted(M.groundset()) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: sorted(M.groundset()) ['a', 'b', 'c', 'd', 'e', 'f', 'g'] - sage: M.delete(['a', 'c']) # optional - sage.rings.finite_rings + sage: M.delete(['a', 'c']) Binary matroid of rank 3 on 5 elements, type (1, 6) - sage: M.delete(['a']) == M \ ['a'] # optional - sage.rings.finite_rings + sage: M.delete(['a']) == M \ ['a'] True One can use a single element, rather than a set:: - sage: M = matroids.CompleteGraphic(4) - sage: M.delete(1) == M.delete([1]) + sage: M = matroids.CompleteGraphic(4) # needs sage.graphs + sage: M.delete(1) == M.delete([1]) # needs sage.graphs True - sage: M \ 1 + sage: M \ 1 # needs sage.graphs Graphic matroid of rank 3 on 5 elements Note that one can iterate over strings:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M \ 'abc' # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M \ 'abc' Binary matroid of rank 3 on 4 elements, type (0, 5) The following is therefore ambiguous. Sage will delete the single @@ -3934,8 +3940,8 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.CompleteGraphic(4) - sage: M.delete(1) == M \ 1 # indirect doctest + sage: M = matroids.CompleteGraphic(4) # needs sage.graphs + sage: M.delete(1) == M \ 1 # indirect doctest # needs sage.graphs True """ return self.delete(X) @@ -3994,9 +4000,9 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: N = M.truncation() # optional - sage.rings.finite_rings - sage: N.is_isomorphic(matroids.Uniform(2, 7)) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: N = M.truncation() + sage: N.is_isomorphic(matroids.Uniform(2, 7)) True """ if self.full_rank() == 0: @@ -4034,15 +4040,15 @@ cdef class Matroid(SageObject): EXAMPLES:: sage: M = matroids.Whirl(3) - sage: matroids.named_matroids.Fano().has_minor(M) # optional - sage.rings.finite_rings + sage: matroids.named_matroids.Fano().has_minor(M) False - sage: matroids.named_matroids.NonFano().has_minor(M) # optional - sage.rings.finite_rings + sage: matroids.named_matroids.NonFano().has_minor(M) True - sage: matroids.named_matroids.NonFano().has_minor(M, certificate=True) # optional - sage.rings.finite_rings + sage: matroids.named_matroids.NonFano().has_minor(M, certificate=True) (True, (frozenset(), frozenset({'g'}), {0: 'b', 1: 'c', 2: 'a', 3: 'd', 4: 'e', 5: 'f'})) - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M.has_minor(M, True) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M.has_minor(M, True) (True, (frozenset(), frozenset(), @@ -4083,21 +4089,21 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.N1() # optional - sage.rings.finite_rings - sage: M.has_line_minor(4) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.N1() + sage: M.has_line_minor(4) True - sage: M.has_line_minor(5) # optional - sage.rings.finite_rings + sage: M.has_line_minor(5) False - sage: M.has_line_minor(k=4, hyperlines=[['a', 'b', 'c']]) # optional - sage.rings.finite_rings + sage: M.has_line_minor(k=4, hyperlines=[['a', 'b', 'c']]) False - sage: M.has_line_minor(k=4, hyperlines=[['a', 'b', 'c'], # optional - sage.rings.finite_rings + sage: M.has_line_minor(k=4, hyperlines=[['a', 'b', 'c'], ....: ['a', 'b', 'd' ]]) True - sage: M.has_line_minor(4, certificate=True) # optional - sage.rings.finite_rings + sage: M.has_line_minor(4, certificate=True) (True, frozenset({'a', 'b', 'd'})) - sage: M.has_line_minor(5, certificate=True) # optional - sage.rings.finite_rings + sage: M.has_line_minor(5, certificate=True) (False, None) - sage: M.has_line_minor(k=4, hyperlines=[['a', 'b', 'c'], # optional - sage.rings.finite_rings + sage: M.has_line_minor(k=4, hyperlines=[['a', 'b', 'c'], ....: ['a', 'b', 'd' ]], certificate=True) (True, frozenset({'a', 'b', 'd'})) @@ -4231,9 +4237,9 @@ cdef class Matroid(SageObject): Putting an element in parallel with another:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: N = M.extension('z', ['c']) # optional - sage.rings.finite_rings - sage: N.rank('cz') # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: N = M.extension('z', ['c']) + sage: N.rank('cz') 1 """ r = self.full_rank() - 1 @@ -4304,9 +4310,9 @@ cdef class Matroid(SageObject): Put an element in series with another:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: N = M.coextension('z', ['c']) # optional - sage.rings.finite_rings - sage: N.corank('cz') # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: N = M.coextension('z', ['c']) + sage: N.corank('cz') 1 """ return self.dual().extension(element, subsets).dual() @@ -4374,8 +4380,8 @@ cdef class Matroid(SageObject): The modular cut of the full groundset is equal to just the groundset:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M.modular_cut([M.groundset()]).difference( # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M.modular_cut([M.groundset()]).difference( ....: [frozenset(M.groundset())]) set() """ @@ -4446,12 +4452,12 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: len(list(M.linear_subclasses())) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: len(list(M.linear_subclasses())) 16 - sage: len(list(M.linear_subclasses(line_length=3))) # optional - sage.rings.finite_rings + sage: len(list(M.linear_subclasses(line_length=3))) 8 - sage: len(list(M.linear_subclasses(subsets=[{'a', 'b'}]))) # optional - sage.rings.finite_rings + sage: len(list(M.linear_subclasses(subsets=[{'a', 'b'}]))) 5 The following matroid has an extension by element `e` such that @@ -4515,14 +4521,14 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.P8() # optional - sage.rings.finite_rings - sage: len(list(M.extensions())) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.P8() + sage: len(list(M.extensions())) 1705 - sage: len(list(M.extensions(line_length=4))) # optional - sage.rings.finite_rings + sage: len(list(M.extensions(line_length=4))) 41 - sage: sorted(M.groundset()) # optional - sage.rings.finite_rings + sage: sorted(M.groundset()) ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] - sage: len(list(M.extensions(subsets=[{'a', 'b'}], line_length=4))) # optional - sage.rings.finite_rings + sage: len(list(M.extensions(subsets=[{'a', 'b'}], line_length=4))) 5 """ @@ -4583,14 +4589,14 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.P8() # optional - sage.rings.finite_rings - sage: len(list(M.coextensions())) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.P8() + sage: len(list(M.coextensions())) 1705 - sage: len(list(M.coextensions(coline_length=4))) # optional - sage.rings.finite_rings + sage: len(list(M.coextensions(coline_length=4))) 41 - sage: sorted(M.groundset()) # optional - sage.rings.finite_rings + sage: sorted(M.groundset()) ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] - sage: len(list(M.coextensions(subsets=[{'a', 'b'}], coline_length=4))) # optional - sage.rings.finite_rings + sage: len(list(M.coextensions(subsets=[{'a', 'b'}], coline_length=4))) 5 """ @@ -4624,8 +4630,8 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano().contract('a') # optional - sage.rings.finite_rings - sage: M.size() - M.simplify().size() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano().contract('a') + sage: M.size() - M.simplify().size() 3 """ @@ -4663,8 +4669,8 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano().dual().delete('a') # optional - sage.rings.finite_rings - sage: M.cosimplify().size() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano().dual().delete('a') + sage: M.cosimplify().size() 3 """ @@ -4698,11 +4704,11 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M.is_simple() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M.is_simple() True - sage: N = M / 'a' # optional - sage.rings.finite_rings - sage: N.is_simple() # optional - sage.rings.finite_rings + sage: N = M / 'a' + sage: N.is_simple() False """ if self._closure(frozenset()): @@ -4734,11 +4740,11 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano().dual() # optional - sage.rings.finite_rings - sage: M.is_cosimple() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano().dual() + sage: M.is_cosimple() True - sage: N = M \ 'a' # optional - sage.rings.finite_rings - sage: N.is_cosimple() # optional - sage.rings.finite_rings + sage: N = M \ 'a' + sage: N.is_cosimple() False """ if self._coclosure(frozenset()): @@ -5079,12 +5085,12 @@ cdef class Matroid(SageObject): ....: groundset='abcdef') sage: N.is_kconnected(3) False - sage: matroids.named_matroids.BetsyRoss().is_kconnected(3) + sage: matroids.named_matroids.BetsyRoss().is_kconnected(3) # needs sage.graphs True - sage: matroids.AG(5,2).is_kconnected(4) # optional - sage.rings.finite_rings + sage: matroids.AG(5,2).is_kconnected(4) True sage: M = matroids.named_matroids.R6() - sage: M.is_kconnected(3) + sage: M.is_kconnected(3) # needs sage.graphs False sage: B, X = M.is_kconnected(3,True) sage: M.connectivity(X)<3 @@ -5223,10 +5229,10 @@ cdef class Matroid(SageObject): ....: groundset='abcdef') sage: N.is_3connected() False - sage: matroids.named_matroids.BetsyRoss().is_3connected() + sage: matroids.named_matroids.BetsyRoss().is_3connected() # needs sage.graphs True sage: M = matroids.named_matroids.R6() - sage: M.is_3connected() + sage: M.is_3connected() # needs sage.graphs False sage: B, X = M.is_3connected(True) sage: M.connectivity(X) @@ -5281,14 +5287,14 @@ cdef class Matroid(SageObject): (False, True) sage: matroids.Uniform(4, 8).is_4connected() True - sage: M = Matroid(field=GF(2), matrix=[[1,0,0,1,0,1,1,0,0,1,1,1], # optional - sage.rings.finite_rings + sage: M = Matroid(field=GF(2), matrix=[[1,0,0,1,0,1,1,0,0,1,1,1], ....: [0,1,0,1,0,1,0,1,0,0,0,1], ....: [0,0,1,1,0,0,1,1,0,1,0,1], ....: [0,0,0,0,1,1,1,1,0,0,1,1], ....: [0,0,0,0,0,0,0,0,1,1,1,1]]) - sage: M.is_4connected() == M.is_4connected(algorithm="shifting") # optional - sage.rings.finite_rings + sage: M.is_4connected() == M.is_4connected(algorithm="shifting") # needs sage.graphs True - sage: M.is_4connected() == M.is_4connected(algorithm="intersection") # optional - sage.rings.finite_rings + sage: M.is_4connected() == M.is_4connected(algorithm="intersection") True """ if algorithm is None or algorithm == "intersection": @@ -5446,25 +5452,25 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: matroids.Uniform(2, 3)._is_3connected_shifting() + sage: matroids.Uniform(2, 3)._is_3connected_shifting() # needs sage.graphs True sage: M = Matroid(ring=QQ, matrix=[[1, 0, 0, 1, 1, 0], ....: [0, 1, 0, 1, 2, 0], ....: [0, 0, 1, 0, 0, 1]]) - sage: M._is_3connected_shifting() + sage: M._is_3connected_shifting() # needs sage.graphs False sage: N = Matroid(circuit_closures={2: ['abc', 'cdef'], ....: 3: ['abcdef']}, ....: groundset='abcdef') - sage: N._is_3connected_shifting() + sage: N._is_3connected_shifting() # needs sage.graphs False - sage: matroids.named_matroids.BetsyRoss()._is_3connected_shifting() + sage: matroids.named_matroids.BetsyRoss()._is_3connected_shifting() # needs sage.graphs True sage: M = matroids.named_matroids.R6() - sage: M._is_3connected_shifting() + sage: M._is_3connected_shifting() # needs sage.graphs False - sage: B, X = M._is_3connected_shifting(True) - sage: M.connectivity(X) + sage: B, X = M._is_3connected_shifting(True) # needs sage.graphs + sage: M.connectivity(X) # needs sage.graphs 1 """ if not self.is_connected(): @@ -5525,17 +5531,17 @@ cdef class Matroid(SageObject): EXAMPLES:: sage: M = matroids.Uniform(2, 6) - sage: B, X = M._is_4connected_shifting(True) - sage: (B, M.connectivity(X)<=3) + sage: B, X = M._is_4connected_shifting(True) # needs sage.graphs + sage: (B, M.connectivity(X)<=3) # needs sage.graphs (False, True) - sage: matroids.Uniform(4, 8)._is_4connected_shifting() + sage: matroids.Uniform(4, 8)._is_4connected_shifting() # needs sage.graphs True - sage: M = Matroid(field=GF(2), matrix=[[1,0,0,1,0,1,1,0,0,1,1,1], # optional - sage.rings.finite_rings + sage: M = Matroid(field=GF(2), matrix=[[1,0,0,1,0,1,1,0,0,1,1,1], ....: [0,1,0,1,0,1,0,1,0,0,0,1], ....: [0,0,1,1,0,0,1,1,0,1,0,1], ....: [0,0,0,0,1,1,1,1,0,0,1,1], ....: [0,0,0,0,0,0,0,0,1,1,1,1]]) - sage: M._is_4connected_shifting() # optional - sage.rings.finite_rings + sage: M._is_4connected_shifting() # needs sage.graphs True """ if self.rank()>self.size()-self.rank(): @@ -5636,19 +5642,19 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = Matroid(field=GF(2), matrix=[[1,0,0,1,0,1,1,0,0,1,1,1], # optional - sage.rings.finite_rings + sage: M = Matroid(field=GF(2), matrix=[[1,0,0,1,0,1,1,0,0,1,1,1], ....: [0,1,0,1,0,1,0,1,0,0,0,1], ....: [0,0,1,1,0,0,1,1,0,1,0,1], ....: [0,0,0,0,1,1,1,1,0,0,1,1], ....: [0,0,0,0,0,0,0,0,1,1,1,1]]) - sage: M._shifting_all(M.basis(), # optional - sage.rings.finite_rings + sage: M._shifting_all(M.basis(), ....: set([0,1]), set([0,1]), set([]), set([]), 3) (False, None) - sage: M = Matroid(field=GF(2), reduced_matrix=[[1,0,1,1,1], # optional - sage.rings.finite_rings + sage: M = Matroid(field=GF(2), reduced_matrix=[[1,0,1,1,1], ....: [1,1,1,1,0], ....: [0,1,1,1,0], ....: [0,0,0,1,1]]) - sage: M._shifting_all(M.basis(), # optional - sage.rings.finite_rings + sage: M._shifting_all(M.basis(), ....: set([0,1]), set([5,8]), set([]), set([]), 3)[0] True @@ -5698,19 +5704,19 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = Matroid(field=GF(2), matrix=[[1,0,0,1,0,1,1,0,0,1,1,1], # optional - sage.rings.finite_rings + sage: M = Matroid(field=GF(2), matrix=[[1,0,0,1,0,1,1,0,0,1,1,1], ....: [0,1,0,1,0,1,0,1,0,0,0,1], ....: [0,0,1,1,0,0,1,1,0,1,0,1], ....: [0,0,0,0,1,1,1,1,0,0,1,1], ....: [0,0,0,0,0,0,0,0,1,1,1,1]]) - sage: M._shifting(M.basis(), # optional - sage.rings.finite_rings + sage: M._shifting(M.basis(), ....: set([0,1]), set([0,1]), set([]), set([]), 3) (False, None) - sage: M = Matroid(field=GF(2), reduced_matrix=[[1,0,1,1,1], # optional - sage.rings.finite_rings + sage: M = Matroid(field=GF(2), reduced_matrix=[[1,0,1,1,1], ....: [1,1,1,1,0], ....: [0,1,1,1,0], ....: [0,0,0,1,1]]) - sage: M._shifting(M.basis(), # optional - sage.rings.finite_rings + sage: M._shifting(M.basis(), ....: set([0,1]), set([5,8]), set([]), set([4]), 3)[0] True """ @@ -5792,10 +5798,10 @@ cdef class Matroid(SageObject): ....: groundset='abcdef') sage: N._is_3connected_BC() False - sage: matroids.named_matroids.BetsyRoss()._is_3connected_BC() + sage: matroids.named_matroids.BetsyRoss()._is_3connected_BC() # needs sage.graphs True - sage: M = matroids.named_matroids.R6() # optional - sage.rings.finite_rings - sage: M._is_3connected_BC() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.R6() + sage: M._is_3connected_BC() # needs sage.graphs False """ # The 5 stages of the algorithm @@ -5840,9 +5846,9 @@ cdef class Matroid(SageObject): sage: M._is_3connected_BC_recursion(B, ....: [M.fundamental_cocircuit(B, e) for e in B]) True - sage: M = matroids.named_matroids.R6() # optional - sage.rings.finite_rings - sage: B = M.basis() # optional - sage.rings.finite_rings - sage: M._is_3connected_BC_recursion(B, # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.R6() + sage: B = M.basis() + sage: M._is_3connected_BC_recursion(B, # needs sage.graphs ....: [M.fundamental_cocircuit(B, e) for e in B]) False @@ -5866,6 +5872,8 @@ cdef class Matroid(SageObject): return True # Step 3: Check the avoidance graph of Y + from sage.graphs.graph import Graph + Y_components = {} B_segments = [] for B in bridges: @@ -5932,13 +5940,13 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: N = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M = N._local_binary_matroid() # optional - sage.rings.finite_rings - sage: N.is_isomorphism(M, {e:e for e in N.groundset()}) # optional - sage.rings.finite_rings + sage: N = matroids.named_matroids.Fano() + sage: M = N._local_binary_matroid() + sage: N.is_isomorphism(M, {e:e for e in N.groundset()}) True - sage: N = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: M = N._local_binary_matroid() # optional - sage.rings.finite_rings - sage: N.is_isomorphism(M, {e:e for e in N.groundset()}) # optional - sage.rings.finite_rings + sage: N = matroids.named_matroids.NonFano() + sage: M = N._local_binary_matroid() + sage: N.is_isomorphism(M, {e:e for e in N.groundset()}) False """ if basis is None: @@ -5990,11 +5998,11 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M.binary_matroid() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M.binary_matroid() Fano: Binary matroid of rank 3 on 7 elements, type (3, 0) - sage: N = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: N.binary_matroid() is None # optional - sage.rings.finite_rings + sage: N = matroids.named_matroids.NonFano() + sage: N.binary_matroid() is None True """ @@ -6042,11 +6050,11 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: N = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: N.is_binary() # optional - sage.rings.finite_rings + sage: N = matroids.named_matroids.Fano() + sage: N.is_binary() True - sage: N = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: N.is_binary() # optional - sage.rings.finite_rings + sage: N = matroids.named_matroids.NonFano() + sage: N.is_binary() False """ @@ -6083,15 +6091,17 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: N = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M = N._local_ternary_matroid() # optional - sage.rings.finite_rings - sage: N.is_isomorphism(M, {e:e for e in N.groundset()}) # optional - sage.rings.finite_rings + sage: N = matroids.named_matroids.Fano() + sage: M = N._local_ternary_matroid() # needs sage.graphs + sage: N.is_isomorphism(M, {e:e for e in N.groundset()}) # needs sage.graphs False - sage: N = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: M = N._local_ternary_matroid() # optional - sage.rings.finite_rings - sage: N.is_isomorphism(M, {e:e for e in N.groundset()}) # optional - sage.rings.finite_rings + sage: N = matroids.named_matroids.NonFano() + sage: M = N._local_ternary_matroid() # needs sage.graphs + sage: N.is_isomorphism(M, {e:e for e in N.groundset()}) # needs sage.graphs True """ + from sage.graphs.graph import Graph + if basis is None: basis = self.basis() basis = sorted(basis) @@ -6175,11 +6185,11 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M.ternary_matroid() is None # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M.ternary_matroid() is None # needs sage.graphs True - sage: N = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: N.ternary_matroid() # optional - sage.rings.finite_rings + sage: N = matroids.named_matroids.NonFano() + sage: N.ternary_matroid() # needs sage.graphs NonFano: Ternary matroid of rank 3 on 7 elements, type 0- """ @@ -6227,11 +6237,11 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: N = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: N.is_ternary() # optional - sage.rings.finite_rings + sage: N = matroids.named_matroids.Fano() + sage: N.is_ternary() # needs sage.graphs False - sage: N = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: N.is_ternary() # optional - sage.rings.finite_rings + sage: N = matroids.named_matroids.NonFano() + sage: N.is_ternary() # needs sage.graphs True """ @@ -6248,6 +6258,7 @@ cdef class Matroid(SageObject): EXAMPLES:: + sage: # needs sage.combinat sage: PR = RootSystem(['A',4]).root_lattice().positive_roots() sage: m = matrix([x.to_vector() for x in PR]).transpose() sage: M = Matroid(m) @@ -6256,6 +6267,7 @@ cdef class Matroid(SageObject): sage: M.is_k_closed(4) True + sage: # needs sage.combinat sage: PR = RootSystem(['D',4]).root_lattice().positive_roots() sage: m = matrix([x.to_vector() for x in PR]).transpose() sage: M = Matroid(m) @@ -6295,12 +6307,12 @@ cdef class Matroid(SageObject): sage: M = matroids.Uniform(2,4) sage: [M._is_circuit_chordal(C) for C in M.circuits()] [False, False, False, False] - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M._is_circuit_chordal(frozenset(['b','c','d'])) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M._is_circuit_chordal(frozenset(['b','c','d'])) False - sage: M._is_circuit_chordal(frozenset(['b','c','d']), certificate=True) # optional - sage.rings.finite_rings + sage: M._is_circuit_chordal(frozenset(['b','c','d']), certificate=True) (False, None) - sage: M._is_circuit_chordal(frozenset(['a','b','d','e'])) # optional - sage.rings.finite_rings + sage: M._is_circuit_chordal(frozenset(['a','b','d','e'])) True """ cdef set X @@ -6351,7 +6363,8 @@ cdef class Matroid(SageObject): (False, None) sage: M.is_circuit_chordal(['a','b','d','e']) True - sage: X = M.is_circuit_chordal(frozenset(['a','b','d','e']), certificate=True)[1] + sage: X = M.is_circuit_chordal(frozenset(['a','b','d','e']), + ....: certificate=True)[1] sage: X # random ('c', frozenset({'b', 'c', 'd'}), frozenset({'a', 'c', 'e'})) sage: M.is_circuit(X[1]) and M.is_circuit(X[2]) @@ -6395,15 +6408,15 @@ cdef class Matroid(SageObject): sage: M = matroids.Uniform(2,4) sage: [M.is_chordal(i) for i in range(4, 8)] [True, True, True, True] - sage: M = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: [M.is_chordal(i) for i in range(4, 8)] # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.NonFano() + sage: [M.is_chordal(i) for i in range(4, 8)] [False, True, True, True] - sage: M = matroids.named_matroids.N2() # optional - sage.rings.finite_rings - sage: [M.is_chordal(i) for i in range(4, 10)] # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.N2() + sage: [M.is_chordal(i) for i in range(4, 10)] [False, False, False, False, True, True] - sage: M.is_chordal(4, 5) # optional - sage.rings.finite_rings + sage: M.is_chordal(4, 5) False - sage: M.is_chordal(4, 5, certificate=True) # optional - sage.rings.finite_rings + sage: M.is_chordal(4, 5, certificate=True) (False, frozenset({'a', 'b', 'e', 'f', 'g'})) """ cdef frozenset C @@ -6431,11 +6444,11 @@ cdef class Matroid(SageObject): sage: M = matroids.Uniform(2,4) sage: M.chordality() 4 - sage: M = matroids.named_matroids.NonFano() # optional - sage.rings.finite_rings - sage: M.chordality() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.NonFano() + sage: M.chordality() 5 - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M.chordality() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M.chordality() 4 """ cdef frozenset C @@ -6477,14 +6490,14 @@ cdef class Matroid(SageObject): EXAMPLES:: sage: from sage.matroids.advanced import setprint - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: X = M.max_weight_independent() # optional - sage.rings.finite_rings - sage: M.is_basis(X) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: X = M.max_weight_independent() + sage: M.is_basis(X) True sage: wt = {'a': 1, 'b': 2, 'c': 2, 'd': 1/2, 'e': 1, ....: 'f': 2, 'g': 2} - sage: setprint(M.max_weight_independent(weights=wt)) # optional - sage.rings.finite_rings + sage: setprint(M.max_weight_independent(weights=wt)) {'b', 'f', 'g'} sage: def wt(x): ....: return x @@ -6564,16 +6577,16 @@ cdef class Matroid(SageObject): EXAMPLES:: sage: from sage.matroids.advanced import setprint - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: X = M.max_weight_coindependent() # optional - sage.rings.finite_rings - sage: M.is_cobasis(X) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: X = M.max_weight_coindependent() + sage: M.is_cobasis(X) True sage: wt = {'a': 1, 'b': 2, 'c': 2, 'd': 1/2, 'e': 1, 'f': 2, 'g': 2} - sage: setprint(M.max_weight_coindependent(weights=wt)) # optional - sage.rings.finite_rings + sage: setprint(M.max_weight_coindependent(weights=wt)) {'b', 'c', 'f', 'g'} sage: wt = {'a': 1, 'b': -10, 'c': 2, 'd': 1/2, 'e': 1, 'f': 2, 'g': 2} - sage: setprint(M.max_weight_coindependent(weights=wt)) # optional - sage.rings.finite_rings + sage: setprint(M.max_weight_coindependent(weights=wt)) Traceback (most recent call last): ... ValueError: nonnegative weights were expected. @@ -6659,8 +6672,8 @@ cdef class Matroid(SageObject): EXAMPLES:: sage: from sage.matroids.advanced import setprint - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M.is_max_weight_independent_generic() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M.is_max_weight_independent_generic() False sage: def wt(x): @@ -6809,8 +6822,8 @@ cdef class Matroid(SageObject): EXAMPLES:: sage: from sage.matroids.advanced import setprint - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M.is_max_weight_coindependent_generic() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M.is_max_weight_coindependent_generic() False sage: def wt(x): @@ -6957,18 +6970,18 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.T12() # optional - sage.rings.finite_rings - sage: N = matroids.named_matroids.ExtendedTernaryGolayCode() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.T12() + sage: N = matroids.named_matroids.ExtendedTernaryGolayCode() sage: w = {'a':30, 'b':10, 'c':11, 'd':20, 'e':70, 'f':21, 'g':90, ....: 'h':12, 'i':80, 'j':13, 'k':40, 'l':21} - sage: Y = M.intersection(N, w) # optional - sage.rings.finite_rings - sage: sorted(Y) # optional - sage.rings.finite_rings + sage: Y = M.intersection(N, w) + sage: sorted(Y) ['a', 'd', 'e', 'g', 'i', 'k'] - sage: sum([w[y] for y in Y]) # optional - sage.rings.finite_rings + sage: sum([w[y] for y in Y]) 330 - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() sage: N = matroids.Uniform(4, 7) - sage: M.intersection(N) # optional - sage.rings.finite_rings + sage: M.intersection(N) Traceback (most recent call last): ... ValueError: matroid intersection requires equal groundsets. @@ -7016,14 +7029,14 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.T12() # optional - sage.rings.finite_rings - sage: N = matroids.named_matroids.ExtendedTernaryGolayCode() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.T12() + sage: N = matroids.named_matroids.ExtendedTernaryGolayCode() sage: w = {'a':30, 'b':10, 'c':11, 'd':20, 'e':70, 'f':21, 'g':90, ....: 'h':12, 'i':80, 'j':13, 'k':40, 'l':21} - sage: Y = M._intersection(N, w) # optional - sage.rings.finite_rings - sage: sorted(Y) # optional - sage.rings.finite_rings + sage: Y = M._intersection(N, w) + sage: sorted(Y) ['a', 'd', 'e', 'g', 'i', 'k'] - sage: sum([w[y] for y in Y]) # optional - sage.rings.finite_rings + sage: sum([w[y] for y in Y]) 330 """ Y = set() @@ -7062,14 +7075,14 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.T12() # optional - sage.rings.finite_rings - sage: N = matroids.named_matroids.ExtendedTernaryGolayCode() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.T12() + sage: N = matroids.named_matroids.ExtendedTernaryGolayCode() sage: w = {'a':30, 'b':10, 'c':11, 'd':20, 'e':70, 'f':21, 'g':90, ....: 'h':12, 'i':80, 'j':13, 'k':40, 'l':21} - sage: Y = M.intersection(N, w) # optional - sage.rings.finite_rings - sage: sorted(Y) # optional - sage.rings.finite_rings + sage: Y = M.intersection(N, w) + sage: sorted(Y) ['a', 'd', 'e', 'g', 'i', 'k'] - sage: M._intersection_augmentation(N, w, Y)[0] # optional - sage.rings.finite_rings + sage: M._intersection_augmentation(N, w, Y)[0] False """ X = self.groundset() - Y @@ -7143,13 +7156,13 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.T12() # optional - sage.rings.finite_rings - sage: N = matroids.named_matroids.ExtendedTernaryGolayCode() # optional - sage.rings.finite_rings - sage: len(M.intersection_unweighted(N)) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.T12() + sage: N = matroids.named_matroids.ExtendedTernaryGolayCode() + sage: len(M.intersection_unweighted(N)) 6 - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: N = matroids.Uniform(4, 7) # optional - sage.rings.finite_rings - sage: M.intersection_unweighted(N) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: N = matroids.Uniform(4, 7) + sage: M.intersection_unweighted(N) Traceback (most recent call last): ... ValueError: matroid intersection requires equal groundsets. @@ -7184,9 +7197,9 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.T12() # optional - sage.rings.finite_rings - sage: N = matroids.named_matroids.ExtendedTernaryGolayCode() # optional - sage.rings.finite_rings - sage: len(M._intersection_unweighted(N)) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.T12() + sage: N = matroids.named_matroids.ExtendedTernaryGolayCode() + sage: len(M._intersection_unweighted(N)) 6 """ Y = set() @@ -7218,15 +7231,15 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.T12() # optional - sage.rings.finite_rings - sage: N = matroids.named_matroids.ExtendedTernaryGolayCode() # optional - sage.rings.finite_rings - sage: Y = M.intersection(N) # optional - sage.rings.finite_rings - sage: M._intersection_augmentation_unweighted(N, Y)[0] # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.T12() + sage: N = matroids.named_matroids.ExtendedTernaryGolayCode() + sage: Y = M.intersection(N) + sage: M._intersection_augmentation_unweighted(N, Y)[0] False - sage: Y = M._intersection_augmentation_unweighted(N,set()) # optional - sage.rings.finite_rings - sage: Y[0] # optional - sage.rings.finite_rings + sage: Y = M._intersection_augmentation_unweighted(N,set()) + sage: Y[0] True - sage: len(Y[1])>0 # optional - sage.rings.finite_rings + sage: len(Y[1])>0 True """ E = self.groundset() @@ -7424,10 +7437,10 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: sorted(M._internal({'a', 'b', 'c'})) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: sorted(M._internal({'a', 'b', 'c'})) ['a', 'b', 'c'] - sage: sorted(M._internal({'e', 'f', 'g'})) # optional - sage.rings.finite_rings + sage: sorted(M._internal({'e', 'f', 'g'})) [] """ N = self.groundset() - B @@ -7463,10 +7476,10 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: sorted(M._external({'a', 'b', 'c'})) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: sorted(M._external({'a', 'b', 'c'})) [] - sage: sorted(M._external({'e', 'f', 'g'})) # optional - sage.rings.finite_rings + sage: sorted(M._external({'e', 'f', 'g'})) ['a', 'b', 'c', 'd'] """ @@ -7516,10 +7529,10 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M.tutte_polynomial() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M.tutte_polynomial() y^4 + x^3 + 3*y^3 + 4*x^2 + 7*x*y + 6*y^2 + 3*x + 3*y - sage: M.tutte_polynomial(1, 1) == M.bases_count() # optional - sage.rings.finite_rings + sage: M.tutte_polynomial(1, 1) == M.bases_count() True ALGORITHM: @@ -7564,8 +7577,8 @@ cdef class Matroid(SageObject): EXAMPLES:: sage: from sage.matroids.advanced import setprint - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: setprint(M.flat_cover()) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: setprint(M.flat_cover()) # needs sage.rings.finite_rings [{'a', 'b', 'f'}, {'a', 'c', 'e'}, {'a', 'd', 'g'}, {'b', 'c', 'd'}, {'b', 'e', 'g'}, {'c', 'f', 'g'}, {'d', 'e', 'f'}] @@ -7621,33 +7634,32 @@ cdef class Matroid(SageObject): EXAMPLES:: sage: M = matroids.Wheel(2) - sage: A = M.chow_ring() - sage: A + sage: A = M.chow_ring(); A Chow ring of Wheel(2): Regular matroid of rank 2 on 4 elements with 5 bases over Integer Ring - sage: A.gens() + sage: A.gens() # needs sage.libs.singular (A23, A23, A23) - sage: A23 = A.gen(0) - sage: A23*A23 + sage: A23 = A.gen(0) # needs sage.libs.singular + sage: A23*A23 # needs sage.libs.singular 0 We construct a more interesting example using the Fano matroid:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: A = M.chow_ring(QQ) # optional - sage.rings.finite_rings - sage: A # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: A = M.chow_ring(QQ); A Chow ring of Fano: Binary matroid of rank 3 on 7 elements, type (3, 0) over Rational Field Next we get the non-trivial generators and do some computations:: - sage: G = A.gens()[6:] # optional - sage.rings.finite_rings - sage: Ag, Aabf, Aace, Aadg, Abcd, Abeg, Acfg, Adef = G # optional - sage.rings.finite_rings - sage: Ag * Ag # optional - sage.rings.finite_rings + sage: # needs sage.libs.singular sage.rings.finite_rings + sage: G = A.gens()[6:] + sage: Ag, Aabf, Aace, Aadg, Abcd, Abeg, Acfg, Adef = G + sage: Ag * Ag 2*Adef^2 - sage: Ag * Abeg # optional - sage.rings.finite_rings + sage: Ag * Abeg -Adef^2 - sage: matrix([[x * y for x in G] for y in G]) # optional - sage.rings.finite_rings + sage: matrix([[x * y for x in G] for y in G]) [2*Adef^2 0 0 -Adef^2 0 -Adef^2 -Adef^2 0] [ 0 Adef^2 0 0 0 0 0 0] [ 0 0 Adef^2 0 0 0 0 0] @@ -7722,11 +7734,11 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: G = M.plot() # optional - sage.rings.finite_rings sage.plot - sage: type(G) # optional - sage.rings.finite_rings sage.plot + sage: M = matroids.named_matroids.Fano() + sage: G = M.plot() # needs sage.plot sage.rings.finite_rings + sage: type(G) # needs sage.plot sage.rings.finite_rings - sage: G.show() # optional - sage.rings.finite_rings sage.plot + sage: G.show() # needs sage.plot sage.rings.finite_rings """ from . import matroids_plot_helpers @@ -7779,12 +7791,12 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.TernaryDowling3() # optional - sage.rings.finite_rings - sage: M.show(B=['a','b','c']) # optional - sage.rings.finite_rings sage.plot - sage: M.show(B=['a','b','c'], lineorders=[['f','e','i']]) # optional - sage.rings.finite_rings sage.plot - sage: pos = {'a':(0,0), 'b': (0,1), 'c':(1,0), 'd':(1,1), # optional - sage.rings.finite_rings sage.plot + sage: M = matroids.named_matroids.TernaryDowling3() + sage: M.show(B=['a','b','c']) # needs sage.plot sage.rings.finite_rings + sage: M.show(B=['a','b','c'], lineorders=[['f','e','i']]) # needs sage.plot sage.rings.finite_rings + sage: pos = {'a':(0,0), 'b': (0,1), 'c':(1,0), 'd':(1,1), # needs sage.plot ....: 'e':(1,-1), 'f':(-1,1), 'g':(-1,-1),'h':(2,0), 'i':(0,2)} - sage: M.show(pos_method=1, pos_dict=pos, lims=[-3,3,-3,3]) # optional - sage.rings.finite_rings sage.plot + sage: M.show(pos_method=1, pos_dict=pos, lims=[-3,3,-3,3]) # needs sage.plot sage.rings.finite_rings """ if self.rank() > 3: raise NotImplementedError @@ -7823,15 +7835,15 @@ cdef class Matroid(SageObject): sage: t="fghij" sage: x=1.61 sage: y=1/1.61 - sage: for i in range(5): # optional - sage.symbolic + sage: for i in range(5): # needs sage.symbolic ....: pos[s[i]]=(RR(x*sin(2*pi*i/5)), RR(x*cos(2*pi*i/5))) ....: pos[t[i]]=(RR(y*sin(2*pi*(i+1/2)/5)), RR(y*cos(2*pi*(i+1/2)/5))) ....: sage: pos['k']=(0,0) - sage: M._fix_positions(pos_dict=pos) # optional - sage.symbolic - sage: M._cached_info['lineorders'] is None # optional - sage.symbolic + sage: M._fix_positions(pos_dict=pos) # needs sage.symbolic + sage: M._cached_info['lineorders'] is None # needs sage.symbolic True - sage: M._cached_info['plot_positions']['k'] # optional - sage.symbolic + sage: M._cached_info['plot_positions']['k'] # needs sage.symbolic (0, 0) """ if self.rank() > 3: @@ -7862,10 +7874,10 @@ cdef class Matroid(SageObject): EXAMPLES:: sage: M = Matroid(circuits=[[1,2,3], [3,4,5], [1,2,4,5]]) - sage: M.broken_circuit_complex() + sage: M.broken_circuit_complex() # needs sage.graphs Simplicial complex with vertex set (1, 2, 3, 4, 5) and facets {(1, 2, 4), (1, 2, 5), (1, 3, 4), (1, 3, 5)} - sage: M.broken_circuit_complex([5,4,3,2,1]) + sage: M.broken_circuit_complex([5,4,3,2,1]) # needs sage.graphs Simplicial complex with vertex set (1, 2, 3, 4, 5) and facets {(1, 3, 5), (1, 4, 5), (2, 3, 5), (2, 4, 5)} """ @@ -7886,8 +7898,8 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: B = M.bergman_complex(); B # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: B = M.bergman_complex(); B # needs sage.graphs Simplicial complex with 14 vertices and 21 facets .. SEEALSO:: @@ -7925,12 +7937,12 @@ cdef class Matroid(SageObject): EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: A = M.augmented_bergman_complex(); A # optional - sage.graphs sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: A = M.augmented_bergman_complex(); A # needs sage.graphs Simplicial complex with 22 vertices and 91 facets sage: M = matroids.Uniform(2,3) - sage: A = M.augmented_bergman_complex(); A # optional - sage.graphs + sage: A = M.augmented_bergman_complex(); A # needs sage.graphs Simplicial complex with 7 vertices and 9 facets Both the independent set complex of the matroid and the usual @@ -7939,9 +7951,9 @@ cdef class Matroid(SageObject): to the independent set complex and ``R`` when they belong to the (cone of) the Bergman complex. The cone point is ``'R[]'``:: - sage: sorted(A.faces()[0]) + sage: sorted(A.faces()[0]) # needs sage.graphs [('L0',), ('L1',), ('L2',), ('R[0]',), ('R[1]',), ('R[2]',), ('R[]',)] - sage: sorted(map(sorted, A.faces()[1])) + sage: sorted(map(sorted, A.faces()[1])) # needs sage.graphs [['L0', 'L1'], ['L0', 'L2'], ['L0', 'R[0]'], @@ -8059,7 +8071,7 @@ cdef class Matroid(SageObject): EXAMPLES:: sage: M = matroids.named_matroids.Pappus() - sage: N = matroids.named_matroids.Fano().direct_sum(M); N # optional - sage.rings.finite_rings + sage: N = matroids.named_matroids.Fano().direct_sum(M); N Matroid of rank 6 on 16 elements as matroid sum of Binary matroid of rank 3 on 7 elements, type (3, 0) Matroid of rank 3 on 9 elements with circuit-closures @@ -8067,9 +8079,9 @@ cdef class Matroid(SageObject): {'b', 'd', 'i'}, {'b', 'f', 'g'}, {'c', 'd', 'h'}, {'c', 'e', 'g'}, {'d', 'e', 'f'}, {'g', 'h', 'i'}}, 3: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'}}} - sage: len(N.independent_sets()) # optional - sage.rings.finite_rings + sage: len(N.independent_sets()) 6897 - sage: len(N.bases()) # optional - sage.rings.finite_rings + sage: len(N.bases()) 2100 """ from . import union_matroid diff --git a/src/sage/matroids/matroids_plot_helpers.py b/src/sage/matroids/matroids_plot_helpers.py index dedb0b11df6..0740a938f11 100644 --- a/src/sage/matroids/matroids_plot_helpers.py +++ b/src/sage/matroids/matroids_plot_helpers.py @@ -51,14 +51,14 @@ EXAMPLES:: sage: from sage.matroids import matroids_plot_helpers - sage: M1 = Matroid(ring=GF(2), matrix=[[1, 0, 0, 0, 1, 1, 1,0,1,0,1], # optional - sage.rings.finite_rings + sage: M1 = Matroid(ring=GF(2), matrix=[[1, 0, 0, 0, 1, 1, 1,0,1,0,1], ....: [0, 1, 0, 1, 0, 1, 1,0,0,1,0], ....: [0, 0, 1, 1, 1, 0, 1,0,0,0,0]]) sage: pos_dict = {0: (0, 0), 1: (2, 0), 2: (1, 2), 3: (1.5, 1.0), ....: 4: (0.5, 1.0), 5: (1.0, 0.0), 6: (1.0, 0.666666666666667), ....: 7: (3,3), 8: (4,0), 9: (-1,1), 10: (-2,-2)} - sage: M1._cached_info = {'plot_positions': pos_dict, 'plot_lineorders': None} # optional - sage.rings.finite_rings - sage: matroids_plot_helpers.geomrep(M1, sp=True) # optional - sage.plot sage.rings.finite_rings + sage: M1._cached_info = {'plot_positions': pos_dict, 'plot_lineorders': None} + sage: matroids_plot_helpers.geomrep(M1, sp=True) # needs sage.plot sage.rings.finite_rings Graphics object consisting of 22 graphics primitives """ @@ -328,17 +328,17 @@ def createline(ptsdict, ll, lineorders2=None): ....: ['a','b','c','d']) sage: [len(x), len(y), len(x_i), len(y_i)] [4, 4, 100, 100] - sage: G = line(zip(x_i, y_i), color='black', thickness=3, zorder=1) # optional - sage.plot - sage: G += points(zip(x, y), color='black', size=300, zorder=2) # optional - sage.plot - sage: G.show() # optional - sage.plot + sage: G = line(zip(x_i, y_i), color='black', thickness=3, zorder=1) # needs sage.plot + sage: G += points(zip(x, y), color='black', size=300, zorder=2) # needs sage.plot + sage: G.show() # needs sage.plot sage: x,y,x_i,y_i = matroids_plot_helpers.createline(ptsdict, ....: ['a','b','c','d'],lineorders2=[['b','a','c','d'], ....: ['p','q','r','s']]) sage: [len(x), len(y), len(x_i), len(y_i)] [4, 4, 100, 100] - sage: G = line(zip(x_i, y_i), color='black', thickness=3, zorder=1) # optional - sage.plot - sage: G += points(zip(x, y), color='black', size=300, zorder=2) # optional - sage.plot - sage: G.show() # optional - sage.plot + sage: G = line(zip(x_i, y_i), color='black', thickness=3, zorder=1) # needs sage.plot + sage: G += points(zip(x, y), color='black', size=300, zorder=2) # needs sage.plot + sage: G.show() # needs sage.plot .. NOTE:: @@ -403,23 +403,23 @@ def slp(M1, pos_dict=None, B=None): sage: from sage.matroids import matroids_plot_helpers sage: from sage.matroids.advanced import setprint - sage: M1 = Matroid(ring=GF(2), matrix=[[1, 0, 0, 0, 1, 1, 1,0,1,0,1], # optional - sage.rings.finite_rings + sage: M1 = Matroid(ring=GF(2), matrix=[[1, 0, 0, 0, 1, 1, 1,0,1,0,1], ....: [0, 1, 0, 1, 0, 1, 1,0,0,1,0], ....: [0, 0, 1, 1, 1, 0, 1,0,0,0,0]]) - sage: [M,L,P] = matroids_plot_helpers.slp(M1) # optional - sage.rings.finite_rings - sage: M.is_simple() # optional - sage.rings.finite_rings + sage: [M,L,P] = matroids_plot_helpers.slp(M1) # needs sage.rings.finite_rings + sage: M.is_simple() # needs sage.rings.finite_rings True - sage: setprint([L,P]) # optional - sage.rings.finite_rings + sage: setprint([L,P]) # needs sage.rings.finite_rings [{10, 8, 9}, {7}] - sage: M1 = Matroid(ring=GF(2), matrix=[[1, 0, 0, 0, 1, 1, 1,0,1,0,1], # optional - sage.rings.finite_rings + sage: M1 = Matroid(ring=GF(2), matrix=[[1, 0, 0, 0, 1, 1, 1,0,1,0,1], ....: [0, 1, 0, 1, 0, 1, 1,0,0,1,0], ....: [0, 0, 1, 1, 1, 0, 1,0,0,0,0]]) - sage: posdict = {8: (0, 0), 1: (2, 0), 2: (1, 2), 3: (1.5, 1.0), # optional - sage.rings.finite_rings + sage: posdict = {8: (0, 0), 1: (2, 0), 2: (1, 2), 3: (1.5, 1.0), ....: 4: (0.5, 1.0), 5: (1.0, 0.0), 6: (1.0, 0.6666666666666666)} - sage: [M,L,P] = matroids_plot_helpers.slp(M1, pos_dict=posdict) # optional - sage.rings.finite_rings - sage: M.is_simple() # optional - sage.rings.finite_rings + sage: [M,L,P] = matroids_plot_helpers.slp(M1, pos_dict=posdict) # needs sage.rings.finite_rings + sage: M.is_simple() # needs sage.rings.finite_rings True - sage: setprint([L,P]) # optional - sage.rings.finite_rings + sage: setprint([L,P]) # needs sage.rings.finite_rings [{0, 10, 9}, {7}] .. NOTE:: @@ -487,12 +487,12 @@ def addlp(M, M1, L, P, ptsdict, G=None, limits=None): EXAMPLES:: sage: from sage.matroids import matroids_plot_helpers - sage: M = Matroid(ring=GF(2), matrix=[[1, 0, 0, 0, 1, 1, 1,0,1], # optional - sage.rings.finite_rings + sage: M = Matroid(ring=GF(2), matrix=[[1, 0, 0, 0, 1, 1, 1,0,1], ....: [0, 1, 0, 1, 0, 1, 1,0,0], ....: [0, 0, 1, 1, 1, 0, 1,0,0]]) - sage: [M1,L,P] = matroids_plot_helpers.slp(M) # optional - sage.rings.finite_rings - sage: G, lims = matroids_plot_helpers.addlp(M,M1,L,P,{0:(0,0)}) # optional - sage.plot sage.rings.finite_rings - sage: G.show(axes=False) # optional - sage.plot sage.rings.finite_rings + sage: [M1,L,P] = matroids_plot_helpers.slp(M) # needs sage.rings.finite_rings + sage: G, lims = matroids_plot_helpers.addlp(M,M1,L,P,{0:(0,0)}) # needs sage.plot sage.rings.finite_rings + sage: G.show(axes=False) # needs sage.plot sage.rings.finite_rings .. NOTE:: @@ -669,16 +669,16 @@ def posdict_is_sane(M1, pos_dict): EXAMPLES:: sage: from sage.matroids import matroids_plot_helpers - sage: M1 = Matroid(ring=GF(2), matrix=[[1, 0, 0, 0, 1, 1, 1,0,1,0,1], # optional - sage.rings.finite_rings + sage: M1 = Matroid(ring=GF(2), matrix=[[1, 0, 0, 0, 1, 1, 1,0,1,0,1], ....: [0, 1, 0, 1, 0, 1, 1,0,0,1,0], ....: [0, 0, 1, 1, 1, 0, 1,0,0,0,0]]) - sage: pos_dict = {0: (0, 0), 1: (2, 0), 2: (1, 2), 3: (1.5, 1.0), # optional - sage.rings.finite_rings + sage: pos_dict = {0: (0, 0), 1: (2, 0), 2: (1, 2), 3: (1.5, 1.0), ....: 4: (0.5, 1.0), 5: (1.0, 0.0), 6: (1.0, 0.6666666666666666)} - sage: matroids_plot_helpers.posdict_is_sane(M1,pos_dict) # optional - sage.rings.finite_rings + sage: matroids_plot_helpers.posdict_is_sane(M1,pos_dict) # needs sage.rings.finite_rings True sage: pos_dict = {1: (2, 0), 2: (1, 2), 3: (1.5, 1.0), ....: 4: (0.5, 1.0), 5: (1.0, 0.0), 6: (1.0, 0.6666666666666666)} - sage: matroids_plot_helpers.posdict_is_sane(M1,pos_dict) # optional - sage.rings.finite_rings + sage: matroids_plot_helpers.posdict_is_sane(M1,pos_dict) # needs sage.rings.finite_rings False .. NOTE:: @@ -764,11 +764,11 @@ def geomrep(M1, B1=None, lineorders1=None, pd=None, sp=False): sage: from sage.matroids import matroids_plot_helpers sage: M = matroids.named_matroids.P7() - sage: G = matroids_plot_helpers.geomrep(M) # optional - sage.plot - sage: G.show(xmin=-2, xmax=3, ymin=-2, ymax=3) # optional - sage.plot + sage: G = matroids_plot_helpers.geomrep(M) # needs sage.plot + sage: G.show(xmin=-2, xmax=3, ymin=-2, ymax=3) # needs sage.plot sage: M = matroids.named_matroids.P7() - sage: G = matroids_plot_helpers.geomrep(M, lineorders1=[['f','e','d']]) # optional - sage.plot - sage: G.show(xmin=-2, xmax=3, ymin=-2, ymax=3) # optional - sage.plot + sage: G = matroids_plot_helpers.geomrep(M, lineorders1=[['f','e','d']]) # needs sage.plot + sage: G.show(xmin=-2, xmax=3, ymin=-2, ymax=3) # needs sage.plot .. NOTE:: diff --git a/src/sage/matroids/minor_matroid.py b/src/sage/matroids/minor_matroid.py index 21122fcb59b..c0e756917f5 100644 --- a/src/sage/matroids/minor_matroid.py +++ b/src/sage/matroids/minor_matroid.py @@ -13,23 +13,23 @@ EXAMPLES:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M \ ['a', 'c' ] == M.delete(['a', 'c']) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M \ ['a', 'c' ] == M.delete(['a', 'c']) True - sage: M / 'a' == M.contract('a') # optional - sage.rings.finite_rings + sage: M / 'a' == M.contract('a') True - sage: M / 'c' \ 'ab' == M.minor(contractions='c', deletions='ab') # optional - sage.rings.finite_rings + sage: M / 'c' \ 'ab' == M.minor(contractions='c', deletions='ab') True If a contraction set is not independent (or a deletion set not coindependent), this is taken care of:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M.rank('abf') # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M.rank('abf') 2 - sage: M / 'abf' == M / 'ab' \ 'f' # optional - sage.rings.finite_rings + sage: M / 'abf' == M / 'ab' \ 'f' True - sage: M / 'abf' == M / 'af' \ 'b' # optional - sage.rings.finite_rings + sage: M / 'abf' == M / 'af' \ 'b' True .. SEEALSO:: @@ -132,9 +132,9 @@ def __init__(self, matroid, contractions=None, deletions=None): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = MinorMatroid(matroids.named_matroids.Fano(), # indirect doctest, optional - sage.rings.finite_rings + sage: M = MinorMatroid(matroids.named_matroids.Fano(), # indirect doctest ....: contractions=set(), deletions=set(['g'])) - sage: M.is_isomorphic(matroids.Wheel(3)) # optional - sage.rings.finite_rings + sage: M.is_isomorphic(matroids.Wheel(3)) True """ if not isinstance(matroid, Matroid): @@ -423,15 +423,15 @@ def __eq__(self, other): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M1 = MinorMatroid(M, set('ab'), set('f')) # optional - sage.rings.finite_rings - sage: M2 = MinorMatroid(M, set('af'), set('b')) # optional - sage.rings.finite_rings - sage: M3 = MinorMatroid(M, set('a'), set('f'))._minor(set('b'), set()) # optional - sage.rings.finite_rings - sage: M1 == M2 # indirect doctest # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M1 = MinorMatroid(M, set('ab'), set('f')) + sage: M2 = MinorMatroid(M, set('af'), set('b')) + sage: M3 = MinorMatroid(M, set('a'), set('f'))._minor(set('b'), set()) + sage: M1 == M2 # indirect doctest False - sage: M1.equals(M2) # optional - sage.rings.finite_rings + sage: M1.equals(M2) True - sage: M1 == M3 # optional - sage.rings.finite_rings + sage: M1 == M3 True """ if not isinstance(other, MinorMatroid): @@ -455,15 +455,15 @@ def __ne__(self, other): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M1 = MinorMatroid(M, set('ab'), set('f')) # optional - sage.rings.finite_rings - sage: M2 = MinorMatroid(M, set('af'), set('b')) # optional - sage.rings.finite_rings - sage: M3 = MinorMatroid(M, set('a'), set('f'))._minor(set('b'), set()) # optional - sage.rings.finite_rings - sage: M1 != M2 # indirect doctest # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M1 = MinorMatroid(M, set('ab'), set('f')) + sage: M2 = MinorMatroid(M, set('af'), set('b')) + sage: M3 = MinorMatroid(M, set('a'), set('f'))._minor(set('b'), set()) + sage: M1 != M2 # indirect doctest True - sage: M1.equals(M2) # optional - sage.rings.finite_rings + sage: M1.equals(M2) True - sage: M1 != M3 # optional - sage.rings.finite_rings + sage: M1 != M3 False """ return not self == other diff --git a/src/sage/matroids/set_system.pyx b/src/sage/matroids/set_system.pyx index 1a3696e1eaf..cb4daf4099a 100644 --- a/src/sage/matroids/set_system.pyx +++ b/src/sage/matroids/set_system.pyx @@ -38,8 +38,8 @@ cdef class SetSystem: contents. One is most likely to encounter these as output from some Matroid methods:: - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: M.circuits() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: M.circuits() Iterator over a system of subsets To access the sets in this structure, simply iterate over them. The @@ -729,11 +729,11 @@ cdef class SetSystem: Check that :trac:`15189` is fixed:: - sage: M = Matroid(ring=GF(5), reduced_matrix=[[1,0,3],[0,1,1],[1,1,0]]) # optional - sage.rings.finite_rings - sage: N = Matroid(ring=GF(5), reduced_matrix=[[1,0,1],[0,1,1],[1,1,0]]) # optional - sage.rings.finite_rings - sage: M.is_field_isomorphic(N) # optional - sage.rings.finite_rings + sage: M = Matroid(ring=GF(5), reduced_matrix=[[1,0,3],[0,1,1],[1,1,0]]) + sage: N = Matroid(ring=GF(5), reduced_matrix=[[1,0,1],[0,1,1],[1,1,0]]) + sage: M.is_field_isomorphic(N) False - sage: any(M.is_field_isomorphism(N, p) for p in Permutations(range(6))) # optional - sage.combinat sage.rings.finite_rings + sage: any(M.is_field_isomorphism(N, p) for p in Permutations(range(6))) # needs sage.combinat False """ cdef long v diff --git a/src/sage/matroids/unpickling.pyx b/src/sage/matroids/unpickling.pyx index d89c867544b..94464ecb9f0 100644 --- a/src/sage/matroids/unpickling.pyx +++ b/src/sage/matroids/unpickling.pyx @@ -212,11 +212,11 @@ def unpickle_binary_matrix(version, data): EXAMPLES:: sage: from sage.matroids.lean_matrix import * - sage: A = BinaryMatrix(2, 5) # optional - sage.rings.finite_rings - sage: A == loads(dumps(A)) # indirect doctest # optional - sage.rings.finite_rings + sage: A = BinaryMatrix(2, 5) + sage: A == loads(dumps(A)) # indirect doctest True - sage: C = BinaryMatrix(2, 2, Matrix(GF(2), [[1, 1], [0, 1]])) # optional - sage.rings.finite_rings - sage: C == loads(dumps(C)) # optional - sage.rings.finite_rings + sage: C = BinaryMatrix(2, 2, Matrix(GF(2), [[1, 1], [0, 1]])) + sage: C == loads(dumps(C)) True """ cdef BinaryMatrix A @@ -241,11 +241,11 @@ def unpickle_ternary_matrix(version, data): EXAMPLES:: sage: from sage.matroids.lean_matrix import * - sage: A = TernaryMatrix(2, 5) # optional - sage.rings.finite_rings - sage: A == loads(dumps(A)) # indirect doctest # optional - sage.rings.finite_rings + sage: A = TernaryMatrix(2, 5) + sage: A == loads(dumps(A)) # indirect doctest True - sage: C = TernaryMatrix(2, 2, Matrix(GF(3), [[1, 1], [0, 1]])) # optional - sage.rings.finite_rings - sage: C == loads(dumps(C)) # optional - sage.rings.finite_rings + sage: C = TernaryMatrix(2, 2, Matrix(GF(3), [[1, 1], [0, 1]])) + sage: C == loads(dumps(C)) True """ cdef TernaryMatrix A @@ -270,12 +270,13 @@ def unpickle_quaternary_matrix(version, data): EXAMPLES:: + sage: # needs sage.rings.finite_rings sage: from sage.matroids.lean_matrix import * - sage: A = QuaternaryMatrix(2, 5, ring=GF(4, 'x')) # optional - sage.rings.finite_rings - sage: A == loads(dumps(A)) # indirect doctest # optional - sage.rings.finite_rings + sage: A = QuaternaryMatrix(2, 5, ring=GF(4, 'x')) + sage: A == loads(dumps(A)) # indirect doctest True - sage: C = QuaternaryMatrix(2, 2, Matrix(GF(4, 'x'), [[1, 1], [0, 1]])) # optional - sage.rings.finite_rings - sage: C == loads(dumps(C)) # optional - sage.rings.finite_rings + sage: C = QuaternaryMatrix(2, 2, Matrix(GF(4, 'x'), [[1, 1], [0, 1]])) + sage: C == loads(dumps(C)) True """ cdef QuaternaryMatrix A @@ -390,12 +391,12 @@ def unpickle_linear_matroid(version, data): EXAMPLES:: - sage: M = Matroid(Matrix(GF(7), [[1, 0, 0, 1, 1], [0, 1, 0, 1, 2], # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(7), [[1, 0, 0, 1, 1], [0, 1, 0, 1, 2], ....: [0, 1, 1, 1, 3]])) - sage: M == loads(dumps(M)) # indirect doctest # optional - sage.rings.finite_rings + sage: M == loads(dumps(M)) # indirect doctest True - sage: M.rename("U35") # optional - sage.rings.finite_rings - sage: loads(dumps(M)) # optional - sage.rings.finite_rings + sage: M.rename("U35") + sage: loads(dumps(M)) U35 """ if version != 0: @@ -436,12 +437,12 @@ def unpickle_binary_matroid(version, data): EXAMPLES:: - sage: M = Matroid(Matrix(GF(2), [[1, 0, 0, 1], [0, 1, 0, 1], # optional - sage.rings.finite_rings + sage: M = Matroid(Matrix(GF(2), [[1, 0, 0, 1], [0, 1, 0, 1], ....: [0, 0, 1, 1]])) - sage: M == loads(dumps(M)) # indirect doctest # optional - sage.rings.finite_rings + sage: M == loads(dumps(M)) # indirect doctest True - sage: M.rename("U34") # optional - sage.rings.finite_rings - sage: loads(dumps(M)) # optional - sage.rings.finite_rings + sage: M.rename("U34") + sage: loads(dumps(M)) U34 """ if version != 0: @@ -483,12 +484,12 @@ def unpickle_ternary_matroid(version, data): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = TernaryMatroid(Matrix(GF(3), [[1, 0, 0, 1], [0, 1, 0, 1], # optional - sage.rings.finite_rings + sage: M = TernaryMatroid(Matrix(GF(3), [[1, 0, 0, 1], [0, 1, 0, 1], ....: [0, 0, 1, 1]])) - sage: M == loads(dumps(M)) # indirect doctest # optional - sage.rings.finite_rings + sage: M == loads(dumps(M)) # indirect doctest True - sage: M.rename("U34") # optional - sage.rings.finite_rings - sage: loads(dumps(M)) # optional - sage.rings.finite_rings + sage: M.rename("U34") + sage: loads(dumps(M)) U34 """ if version != 0: @@ -530,16 +531,16 @@ def unpickle_quaternary_matroid(version, data): EXAMPLES:: sage: from sage.matroids.advanced import * - sage: M = QuaternaryMatroid(Matrix(GF(3), [[1, 0, 0, 1], [0, 1, 0, 1], # optional - sage.rings.finite_rings + sage: M = QuaternaryMatroid(Matrix(GF(3), [[1, 0, 0, 1], [0, 1, 0, 1], ....: [0, 0, 1, 1]])) - sage: M == loads(dumps(M)) # indirect doctest # optional - sage.rings.finite_rings + sage: M == loads(dumps(M)) # indirect doctest True - sage: M.rename("U34") # optional - sage.rings.finite_rings - sage: loads(dumps(M)) # optional - sage.rings.finite_rings + sage: M.rename("U34") + sage: loads(dumps(M)) U34 - sage: M = QuaternaryMatroid(Matrix(GF(4, 'x'), [[1, 0, 1], # optional - sage.rings.finite_rings + sage: M = QuaternaryMatroid(Matrix(GF(4, 'x'), [[1, 0, 1], # needs sage.rings.finite_rings ....: [1, 0, 1]])) - sage: loads(dumps(M)).representation() # optional - sage.rings.finite_rings + sage: loads(dumps(M)).representation() # needs sage.rings.finite_rings [1 0 1] [1 0 1] """ @@ -672,8 +673,8 @@ def unpickle_graphic_matroid(version, data): EXAMPLES:: - sage: M = Matroid(graphs.DiamondGraph()) # optional - sage.graphs - sage: M == loads(dumps(M)) # optional - sage.graphs + sage: M = Matroid(graphs.DiamondGraph()) # needs sage.graphs + sage: M == loads(dumps(M)) # needs sage.graphs True """ if version != 0: diff --git a/src/sage/matroids/utilities.py b/src/sage/matroids/utilities.py index ab4985eb0e7..6351c536413 100644 --- a/src/sage/matroids/utilities.py +++ b/src/sage/matroids/utilities.py @@ -26,15 +26,10 @@ from collections.abc import Iterable from sage.matrix.constructor import Matrix -from sage.rings.finite_rings.finite_field_constructor import GF from sage.rings.integer_ring import ZZ from sage.rings.rational_field import QQ -from sage.graphs.graph import Graph -from sage.graphs.bipartite_graph import BipartiteGraph from sage.structure.all import SageObject -from sage.graphs.spanning_tree import kruskal from operator import itemgetter -from sage.rings.number_field.number_field import NumberField def setprint(X): @@ -74,19 +69,19 @@ def setprint(X): Note that for iterables, the effect can be undesirable:: sage: from sage.matroids.advanced import setprint - sage: M = matroids.named_matroids.Fano().delete('efg') # optional - sage.rings.finite_rings - sage: M.bases() # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano().delete('efg') + sage: M.bases() Iterator over a system of subsets - sage: setprint(M.bases()) # optional - sage.rings.finite_rings + sage: setprint(M.bases()) [{'a', 'b', 'c'}, {'a', 'b', 'd'}, {'a', 'c', 'd'}] An exception was made for subclasses of SageObject:: sage: from sage.matroids.advanced import setprint - sage: G = graphs.PetersenGraph() # optional - sage.graphs - sage: list(G) # optional - sage.graphs + sage: G = graphs.PetersenGraph() # needs sage.graphs + sage: list(G) # needs sage.graphs [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - sage: setprint(G) # optional - sage.graphs + sage: setprint(G) # needs sage.graphs Petersen graph: Graph on 10 vertices """ print(setprint_s(X, toplevel=True)) @@ -215,20 +210,20 @@ def sanitize_contractions_deletions(matroid, contractions, deletions): sage: from sage.matroids.utilities import setprint sage: from sage.matroids.utilities import sanitize_contractions_deletions - sage: M = matroids.named_matroids.Fano() # optional - sage.rings.finite_rings - sage: setprint(sanitize_contractions_deletions(M, 'abc', 'defg')) # optional - sage.rings.finite_rings + sage: M = matroids.named_matroids.Fano() + sage: setprint(sanitize_contractions_deletions(M, 'abc', 'defg')) [{'a', 'b', 'c'}, {'d', 'e', 'f', 'g'}] - sage: setprint(sanitize_contractions_deletions(M, 'defg', 'abc')) # optional - sage.rings.finite_rings + sage: setprint(sanitize_contractions_deletions(M, 'defg', 'abc')) [{'a', 'b', 'c', 'f'}, {'d', 'e', 'g'}] - sage: setprint(sanitize_contractions_deletions(M, [1, 2, 3], 'efg')) # optional - sage.rings.finite_rings + sage: setprint(sanitize_contractions_deletions(M, [1, 2, 3], 'efg')) Traceback (most recent call last): ... ValueError: [1, 2, 3] is not a subset of the groundset - sage: setprint(sanitize_contractions_deletions(M, 'efg', [1, 2, 3])) # optional - sage.rings.finite_rings + sage: setprint(sanitize_contractions_deletions(M, 'efg', [1, 2, 3])) Traceback (most recent call last): ... ValueError: [1, 2, 3] is not a subset of the groundset - sage: setprint(sanitize_contractions_deletions(M, 'ade', 'efg')) # optional - sage.rings.finite_rings + sage: setprint(sanitize_contractions_deletions(M, 'ade', 'efg')) Traceback (most recent call last): ... ValueError: contraction and deletion sets are not disjoint. @@ -270,7 +265,7 @@ def make_regular_matroid_from_matroid(matroid): EXAMPLES:: sage: from sage.matroids.utilities import make_regular_matroid_from_matroid - sage: make_regular_matroid_from_matroid( # optional - sage.graphs + sage: make_regular_matroid_from_matroid( # needs sage.graphs ....: matroids.CompleteGraphic(6)).is_isomorphic( ....: matroids.CompleteGraphic(6)) True @@ -279,6 +274,9 @@ def make_regular_matroid_from_matroid(matroid): M = matroid if isinstance(M, sage.matroids.linear_matroid.RegularMatroid): return M + + from sage.graphs.bipartite_graph import BipartiteGraph + rk = M.full_rank() # First create a reduced 0-1 matrix B = list(M.basis()) @@ -379,11 +377,14 @@ def spanning_forest(M): EXAMPLES:: sage: from sage.matroids.utilities import spanning_forest - sage: len(spanning_forest(matrix([[1,1,1],[1,1,1],[1,1,1]]))) # optional - sage.graphs + sage: len(spanning_forest(matrix([[1,1,1],[1,1,1],[1,1,1]]))) # needs sage.graphs 5 - sage: len(spanning_forest(matrix([[0,0,1],[0,1,0],[0,1,0]]))) # optional - sage.graphs + sage: len(spanning_forest(matrix([[0,0,1],[0,1,0],[0,1,0]]))) # needs sage.graphs 3 """ + from sage.graphs.graph import Graph + from sage.graphs.spanning_tree import kruskal + # Given a matrix, produce a spanning tree G = Graph() m = M.ncols() @@ -420,10 +421,11 @@ def spanning_stars(M): EXAMPLES:: sage: from sage.matroids.utilities import spanning_stars - sage: edges = spanning_stars(matrix([[1,1,1],[1,1,1],[1,1,1]])) # optional - sage.graphs - sage: Graph([(x+3, y) for x,y in edges]).is_connected() # optional - sage.graphs + sage: edges = spanning_stars(matrix([[1,1,1],[1,1,1],[1,1,1]])) # needs sage.graphs + sage: Graph([(x+3, y) for x,y in edges]).is_connected() # needs sage.graphs True """ + from sage.graphs.graph import Graph G = Graph() m = M.ncols() @@ -533,29 +535,32 @@ def lift_cross_ratios(A, lift_map=None): EXAMPLES:: + sage: # needs sage.graphs sage: from sage.matroids.advanced import lift_cross_ratios, lift_map, LinearMatroid - sage: R = GF(7) # optional - sage.graphs sage.rings.finite_rings - sage: to_sixth_root_of_unity = lift_map('sru') # optional - sage.graphs sage.rings.number_field - sage: A = Matrix(R, [[1, 0, 6, 1, 2],[6, 1, 0, 0, 1],[0, 6, 3, 6, 0]]) # optional - sage.graphs sage.rings.finite_rings - sage: A # optional - sage.graphs sage.rings.finite_rings + sage: R = GF(7) + sage: to_sixth_root_of_unity = lift_map('sru') # needs sage.rings.number_field + sage: A = Matrix(R, [[1, 0, 6, 1, 2],[6, 1, 0, 0, 1],[0, 6, 3, 6, 0]]) + sage: A [1 0 6 1 2] [6 1 0 0 1] [0 6 3 6 0] - sage: Z = lift_cross_ratios(A, to_sixth_root_of_unity) # optional - sage.graphs sage.rings.finite_rings sage.rings.number_field - sage: Z # optional - sage.graphs sage.rings.finite_rings sage.rings.number_field + sage: Z = lift_cross_ratios(A, to_sixth_root_of_unity) # needs sage.rings.finite_rings sage.rings.number_field + sage: Z # needs sage.rings.finite_rings sage.rings.number_field [ 1 0 1 1 1] [ 1 1 0 0 z] [ 0 -1 z 1 0] - sage: M = LinearMatroid(reduced_matrix=A) # optional - sage.graphs sage.rings.finite_rings - sage: sorted(M.cross_ratios()) # optional - sage.graphs sage.rings.finite_rings + sage: M = LinearMatroid(reduced_matrix=A) + sage: sorted(M.cross_ratios()) [3, 5] - sage: N = LinearMatroid(reduced_matrix=Z) # optional - sage.graphs sage.rings.finite_rings sage.rings.number_field - sage: sorted(N.cross_ratios()) # optional - sage.graphs sage.rings.finite_rings sage.rings.number_field + sage: N = LinearMatroid(reduced_matrix=Z) # needs sage.rings.finite_rings sage.rings.number_field + sage: sorted(N.cross_ratios()) # needs sage.rings.finite_rings sage.rings.number_field [-z + 1, z] - sage: M.is_isomorphism(N, {e:e for e in M.groundset()}) # optional - sage.graphs sage.rings.finite_rings sage.rings.number_field + sage: M.is_isomorphism(N, {e:e for e in M.groundset()}) # needs sage.rings.finite_rings sage.rings.number_field True """ + from sage.graphs.graph import Graph + for s, t in lift_map.items(): source_ring = s.parent() target_ring = t.parent() @@ -692,8 +697,8 @@ def lift_map(target): EXAMPLES:: sage: from sage.matroids.utilities import lift_map - sage: lm = lift_map('gm') # optional - sage.rings.finite_rings sage.rings.number_field - sage: for x in lm: # optional - sage.rings.finite_rings sage.rings.number_field + sage: lm = lift_map('gm') # needs sage.rings.finite_rings sage.rings.number_field + sage: for x in lm: # needs sage.rings.finite_rings sage.rings.number_field ....: if (x == 1) is not (lm[x] == 1): ....: print('not a proper lift map') ....: for y in lm: @@ -706,11 +711,15 @@ def lift_map(target): ....: print('not a proper lift map') """ + from sage.rings.finite_rings.finite_field_constructor import GF + if target == "reg": R = GF(3) return {R(1): ZZ(1)} if target == "sru": + from sage.rings.number_field.number_field import NumberField + R = GF(7) z = ZZ['z'].gen() S = NumberField(z * z - z + 1, 'z') @@ -722,6 +731,8 @@ def lift_map(target): return {R(1): QQ(1), R(-1): QQ(-1), R(2): QQ(2), R(6): QQ((1, 2))} if target == "gm": + from sage.rings.number_field.number_field import NumberField + R = GF(19) t = QQ['t'].gen() G = NumberField(t * t - t - 1, 't') @@ -752,14 +763,15 @@ def split_vertex(G, u, v=None, edges=None): EXAMPLES:: + sage: # needs sage.graphs sage: from sage.matroids.utilities import split_vertex - sage: G = graphs.BullGraph() # optional - sage.graphs - sage: split_vertex(G, u=1, v=55, edges=[(1, 3)]) # optional - sage.graphs + sage: G = graphs.BullGraph() + sage: split_vertex(G, u=1, v=55, edges=[(1, 3)]) Traceback (most recent call last): ... ValueError: the edges are not all incident with u - sage: split_vertex(G, u=1, v=55, edges=[(1, 3, None)]) # optional - sage.graphs - sage: list(G.edges(sort=True)) # optional - sage.graphs + sage: split_vertex(G, u=1, v=55, edges=[(1, 3, None)]) + sage: list(G.edges(sort=True)) [(0, 1, None), (0, 2, None), (1, 2, None), (2, 4, None), (3, 55, None)] """ if v is None: