Skip to content

Commit 31d6130

Browse files
committed
Speedup database_matroids.py tests
1 parent 30b3d78 commit 31d6130

File tree

3 files changed

+68
-115
lines changed

3 files changed

+68
-115
lines changed

src/sage/matroids/database_matroids.py

Lines changed: 65 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,25 +1088,20 @@ def P8pp():
10881088
10891089
sage: from sage.matroids.advanced import *
10901090
sage: M = matroids.catalog.P8pp(); M
1091-
P8'': Matroid of rank 4 on 8 elements with circuit-closures
1092-
{3: {{'a', 'b', 'f', 'h'}, {'a', 'c', 'e', 'f'}, {'a', 'c', 'g', 'h'},
1093-
{'a', 'd', 'e', 'g'}, {'b', 'c', 'e', 'g'}, {'b', 'd', 'e', 'h'},
1094-
{'b', 'd', 'f', 'g'}, {'c', 'd', 'f', 'h'}},
1095-
4: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}}}
1091+
P8'': Matroid of rank 4 on 8 elements with 8 nonspanning circuits
10961092
sage: M.is_isomorphic(M.dual()) and not M.equals(M.dual())
10971093
True
10981094
sage: len(get_nonisomorphic_matroids([M.contract(i) for i in M.groundset()]))
10991095
1
1100-
sage: M.is_valid() # long time
1096+
sage: M.is_valid() and M.is_paving()
11011097
True
11021098
11031099
REFERENCES:
11041100
11051101
[Oxl2011]_, p. 651.
11061102
"""
1107-
CC = {3: ['abfh', 'bceg', 'cdfh', 'adeg', 'acef', 'bdfg', 'acgh', 'bdeh'],
1108-
4: ['abcdefgh']}
1109-
M = CircuitClosuresMatroid(groundset='abcdefgh', circuit_closures=CC)
1103+
NSC = ['abfh', 'bceg', 'cdfh', 'adeg', 'acef', 'bdfg', 'acgh', 'bdeh']
1104+
M = Matroid(groundset='abcdefgh', rank=4, nonspanning_circuits=NSC)
11101105
M.rename("P8'': " + repr(M))
11111106
return M
11121107

@@ -1336,11 +1331,7 @@ def Pappus(groundset=None):
13361331
13371332
sage: from sage.matroids.advanced import setprint
13381333
sage: M = matroids.catalog.Pappus(); M
1339-
Pappus: Matroid of rank 3 on 9 elements with circuit-closures
1340-
{2: {{'a', 'b', 'c'}, {'a', 'e', 'i'}, {'a', 'f', 'h'},
1341-
{'b', 'd', 'i'}, {'b', 'f', 'g'}, {'c', 'd', 'h'},
1342-
{'c', 'e', 'g'}, {'d', 'e', 'f'}, {'g', 'h', 'i'}},
1343-
3: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'}}}
1334+
Pappus: Matroid of rank 3 on 9 elements with 9 nonspanning circuits
13441335
sage: setprint(M.nonspanning_circuits())
13451336
[{'a', 'b', 'c'}, {'a', 'e', 'i'}, {'a', 'f', 'h'}, {'b', 'd', 'i'},
13461337
{'b', 'f', 'g'}, {'c', 'd', 'h'}, {'c', 'e', 'g'}, {'d', 'e', 'f'},
@@ -1356,9 +1347,8 @@ def Pappus(groundset=None):
13561347
13571348
[Oxl2011]_, p. 655.
13581349
"""
1359-
CC = {2: ['abc', 'def', 'ceg', 'bfg', 'cdh', 'afh', 'bdi', 'aei', 'ghi'],
1360-
3: ['abcdefghi']}
1361-
M = CircuitClosuresMatroid(groundset='abcdefghi', circuit_closures=CC)
1350+
NSC = ['abc', 'def', 'ceg', 'bfg', 'cdh', 'afh', 'bdi', 'aei', 'ghi']
1351+
M = Matroid(groundset='abcdefghi', rank=3, nonspanning_circuits=NSC)
13621352
M.rename("Pappus: " + repr(M))
13631353
return M
13641354

@@ -1375,11 +1365,7 @@ def NonPappus():
13751365
13761366
sage: from sage.matroids.advanced import setprint
13771367
sage: M = matroids.catalog.NonPappus(); M
1378-
NonPappus: Matroid of rank 3 on 9 elements with circuit-closures
1379-
{2: {{'a', 'b', 'c'}, {'a', 'e', 'i'}, {'a', 'f', 'h'},
1380-
{'b', 'd', 'i'}, {'b', 'f', 'g'}, {'c', 'd', 'h'},
1381-
{'c', 'e', 'g'}, {'g', 'h', 'i'}},
1382-
3: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'}}}
1368+
NonPappus: Matroid of rank 3 on 9 elements with 8 nonspanning circuits
13831369
sage: setprint(M.nonspanning_circuits())
13841370
[{'a', 'b', 'c'}, {'a', 'e', 'i'}, {'a', 'f', 'h'}, {'b', 'd', 'i'},
13851371
{'b', 'f', 'g'}, {'c', 'd', 'h'}, {'c', 'e', 'g'}, {'g', 'h', 'i'}]
@@ -1394,9 +1380,8 @@ def NonPappus():
13941380
13951381
[Oxl2011]_, p. 655.
13961382
"""
1397-
CC = {2: ['abc', 'ceg', 'bfg', 'cdh', 'afh', 'bdi', 'aei', 'ghi'],
1398-
3: ['abcdefghi']}
1399-
M = CircuitClosuresMatroid(groundset='abcdefghi', circuit_closures=CC)
1383+
NSC = ['abc', 'ceg', 'bfg', 'cdh', 'afh', 'bdi', 'aei', 'ghi']
1384+
M = Matroid(groundset='abcdefghi', rank=3, nonspanning_circuits=NSC)
14001385
M.rename("NonPappus: " + repr(M))
14011386
return M
14021387

@@ -1447,6 +1432,7 @@ def K5dual():
14471432
[Oxl2011]_, p. 656.
14481433
"""
14491434
M = CompleteGraphic(5).dual()
1435+
# M = Matroid(circuits=M.circuits())
14501436
M.rename("M*(K5): " + repr(M))
14511437
return M
14521438

@@ -2284,7 +2270,7 @@ def Psi(r):
22842270
EXAMPLES::
22852271
22862272
sage: matroids.Psi(7)
2287-
Psi_7: Matroid of rank 7 on 14 elements with 2060 bases
2273+
Psi_7: Matroid of rank 7 on 14 elements with 105 nonspanning circuits
22882274
22892275
The matroid `\Psi_r` is `3`-connected but, for all `r \ge 4`, not `4`-connected::
22902276
@@ -2346,18 +2332,7 @@ def genbin(n, bs=""):
23462332
j += 1
23472333
NSC += [C]
23482334

2349-
import itertools
2350-
B = [] # bases
2351-
for b in itertools.combinations(E, r):
2352-
flag = True
2353-
for C in NSC:
2354-
if set(b) >= set(C):
2355-
flag = False
2356-
break
2357-
if flag:
2358-
B += [list(b)]
2359-
2360-
M = Matroid(groundset=E, bases=B)
2335+
M = Matroid(groundset=E, rank=r, nonspanning_circuits=NSC)
23612336
M.rename("Psi_" + str(r) + ": " + repr(M))
23622337
return M
23632338

@@ -4253,6 +4228,7 @@ def complement(groundset, subset):
42534228
6: [gs],
42544229
},
42554230
)
4231+
M = Matroid(circuits=M.circuits())
42564232
M.rename("NestOfTwistedCubes: " + repr(M))
42574233
return M
42584234

@@ -4747,16 +4723,15 @@ def R9A():
47474723
47484724
EXAMPLES::
47494725
4750-
sage: M = matroids.catalog.R9A()
4751-
sage: M.is_valid() # long time
4726+
sage: M = matroids.catalog.R9A(); M
4727+
R9A: Matroid of rank 4 on 9 elements with 13 nonspanning circuits
4728+
sage: M.is_valid()
47524729
True
47534730
"""
4754-
E = 'abcdefghi'
4755-
CC = {3: ['abde', 'bcdf', 'aceg', 'abch', 'aefh', 'adgh', 'acdi', 'abfi',
4756-
'defi', 'begi', 'bdhi', 'cehi', 'fghi'],
4757-
4: [E]}
4758-
M = CircuitClosuresMatroid(groundset=E, circuit_closures=CC)
4759-
M.rename('R9A: ' + repr(M))
4731+
NSC = ['abch', 'abde', 'abfi', 'acdi', 'aceg', 'adgh', 'aefh', 'bcdf',
4732+
'bdhi', 'begi', 'cehi', 'defi', 'fghi']
4733+
M = Matroid(groundset='abcdefghi', rank=4, nonspanning_circuits=NSC)
4734+
M.rename("R9A: " + repr(M))
47604735
return M
47614736

47624737

@@ -4771,16 +4746,15 @@ def R9B():
47714746
47724747
EXAMPLES::
47734748
4774-
sage: M = matroids.catalog.R9B()
4775-
sage: M.is_valid() # long time
4749+
sage: M = matroids.catalog.R9B(); M
4750+
R9B: Matroid of rank 4 on 9 elements with 13 nonspanning circuits
4751+
sage: M.is_valid() and M.is_paving()
47764752
True
47774753
"""
4778-
E = 'abcdefghi'
4779-
CC = {3: ['abde', 'bcdf', 'aceg', 'abch', 'befh', 'cdgh', 'bcei', 'adfi',
4780-
'abgi', 'degi', 'bdhi', 'aehi', 'fghi'],
4781-
4: [E]}
4782-
M = CircuitClosuresMatroid(groundset=E, circuit_closures=CC)
4783-
M.rename('R9B: ' + repr(M))
4754+
NSC = ['abde', 'bcdf', 'aceg', 'abch', 'befh', 'cdgh', 'bcei', 'adfi',
4755+
'abgi', 'degi', 'bdhi', 'aehi', 'fghi']
4756+
M = Matroid(groundset='abcdefghi', rank=4, nonspanning_circuits=NSC)
4757+
M.rename("R9B: " + repr(M))
47844758
return M
47854759

47864760

@@ -4791,22 +4765,20 @@ def Block_9_4():
47914765
47924766
EXAMPLES::
47934767
4794-
sage: M = matroids.catalog.Block_9_4()
4795-
sage: M.is_valid() # long time
4768+
sage: M = matroids.catalog.Block_9_4(); M
4769+
Block(9, 4): Matroid of rank 4 on 9 elements with 18 nonspanning
4770+
circuits
4771+
sage: M.is_valid() and M.is_paving()
47964772
True
47974773
sage: BD = BlockDesign(M.groundset(), M.nonspanning_circuits())
47984774
sage: BD.is_t_design(return_parameters=True)
47994775
(True, (2, 9, 4, 3))
48004776
"""
4801-
E = 'abcdefghi'
4802-
CC = {
4803-
3: ['abcd', 'acef', 'bdef', 'cdeg', 'abfg', 'adeh', 'bcfh', 'acgh',
4804-
'begh', 'dfgh', 'abei', 'cdfi', 'bcgi', 'adgi', 'efgi', 'bdhi',
4805-
'cehi', 'afhi'],
4806-
4: [E]
4807-
}
4808-
M = CircuitClosuresMatroid(groundset=E, circuit_closures=CC)
4809-
M.rename('Block(9, 4): ' + repr(M))
4777+
NSC = ['abcd', 'acef', 'bdef', 'cdeg', 'abfg', 'adeh', 'bcfh', 'acgh',
4778+
'begh', 'dfgh', 'abei', 'cdfi', 'bcgi', 'adgi', 'efgi', 'bdhi',
4779+
'cehi', 'afhi']
4780+
M = Matroid(groundset='abcdefghi', rank=4, nonspanning_circuits=NSC)
4781+
M.rename("Block(9, 4): " + repr(M))
48104782
return M
48114783

48124784

@@ -4819,22 +4791,19 @@ def TicTacToe():
48194791
48204792
EXAMPLES::
48214793
4822-
sage: M = matroids.catalog.TicTacToe()
4823-
sage: M.is_valid() # long time
4794+
sage: M = matroids.catalog.TicTacToe(); M
4795+
TicTacToe: Matroid of rank 5 on 9 elements with 8 nonspanning circuits
4796+
sage: M.is_valid() and M.is_paving()
48244797
True
48254798
48264799
REFERENCES:
48274800
48284801
[Hoc]_
48294802
"""
4830-
E = 'abcdefghi'
4831-
CC = {
4832-
4: ['abcdg', 'adefg', 'abceh', 'abcfi', 'cdefi', 'adghi',
4833-
'beghi', 'cfghi'],
4834-
5: [E]
4835-
}
4836-
M = CircuitClosuresMatroid(groundset=E, circuit_closures=CC)
4837-
M.rename('TicTacToe: ' + repr(M))
4803+
NSC = ['abcdg', 'adefg', 'abceh', 'abcfi', 'cdefi', 'adghi', 'beghi',
4804+
'cfghi']
4805+
M = Matroid(groundset='abcdefghi', rank=5, nonspanning_circuits=NSC)
4806+
M.rename("TicTacToe: " + repr(M))
48384807
return M
48394808

48404809

@@ -4876,25 +4845,23 @@ def Block_10_5():
48764845
48774846
EXAMPLES::
48784847
4879-
sage: M = matroids.catalog.Block_10_5()
4880-
sage: M.is_valid() # long time
4848+
sage: M = matroids.catalog.Block_10_5(); M
4849+
Block(10, 5): Matroid of rank 5 on 10 elements with 36 nonspanning
4850+
circuits
4851+
sage: M.is_valid() and M.is_paving()
48814852
True
48824853
sage: BD = BlockDesign(M.groundset(), M.nonspanning_circuits())
48834854
sage: BD.is_t_design(return_parameters=True)
48844855
(True, (3, 10, 5, 3))
48854856
"""
4886-
E = 'abcdefghij'
4887-
CC = {
4888-
4: ['abcde', 'acdfg', 'bdefg', 'bcdfh', 'abefh', 'abcgh', 'adegh',
4889-
'cefgh', 'bcefi', 'adefi', 'bcdgi', 'acegi', 'abfgi', 'abdhi',
4890-
'cdehi', 'acfhi', 'beghi', 'dfghi', 'abdfj', 'acefj', 'abegj',
4891-
'cdegj', 'bcfgj', 'acdhj', 'bcehj', 'defhj', 'bdghj', 'afghj',
4892-
'abcij', 'bdeij', 'cdfij', 'adgij', 'efgij', 'aehij', 'bfhij',
4893-
'cghij'],
4894-
5: [E]
4895-
}
4896-
M = CircuitClosuresMatroid(groundset=E, circuit_closures=CC)
4897-
M.rename('Block(10, 5): ' + repr(M))
4857+
NSC = ['abcde', 'acdfg', 'bdefg', 'bcdfh', 'abefh', 'abcgh', 'adegh',
4858+
'cefgh', 'bcefi', 'adefi', 'bcdgi', 'acegi', 'abfgi', 'abdhi',
4859+
'cdehi', 'acfhi', 'beghi', 'dfghi', 'abdfj', 'acefj', 'abegj',
4860+
'cdegj', 'bcfgj', 'acdhj', 'bcehj', 'defhj', 'bdghj', 'afghj',
4861+
'abcij', 'bdeij', 'cdfij', 'adgij', 'efgij', 'aehij', 'bfhij',
4862+
'cghij']
4863+
M = Matroid(groundset='abcdefghij', rank=5, nonspanning_circuits=NSC)
4864+
M.rename("Block(10, 5): " + repr(M))
48984865
return M
48994866

49004867

@@ -4949,20 +4916,19 @@ def BetsyRoss():
49494916
49504917
EXAMPLES::
49514918
4952-
sage: M = matroids.catalog.BetsyRoss()
4919+
sage: M = matroids.catalog.BetsyRoss(); M
4920+
BetsyRoss: Matroid of rank 3 on 11 elements with 25 nonspanning
4921+
circuits
49534922
sage: len(M.circuit_closures()[2])
49544923
10
4955-
sage: M.is_valid() # long time
4924+
sage: M.is_valid()
49564925
True
49574926
"""
4958-
E = 'abcdefghijk'
4959-
CC = {
4960-
2: ['acfg', 'bdgh', 'cehi', 'befj', 'adij', 'dfk',
4961-
'egk', 'ahk', 'bik', 'cjk'],
4962-
3: [E]
4963-
}
4964-
M = CircuitClosuresMatroid(groundset=E, circuit_closures=CC)
4965-
M.rename('BetsyRoss: ' + repr(M))
4927+
NSC = ['acf', 'acg', 'adi', 'adj', 'afg', 'ahk', 'aij', 'bdg', 'bdh',
4928+
'bef', 'bej', 'bfj', 'bgh', 'bik', 'ceh', 'cei', 'cfg', 'chi',
4929+
'cjk', 'dfk', 'dgh', 'dij', 'efj', 'egk', 'ehi']
4930+
M = Matroid(groundset='abcdefghijk', rank=3, nonspanning_circuits=NSC)
4931+
M.rename("BetsyRoss: " + repr(M))
49664932
return M
49674933

49684934

src/sage/matroids/dual_matroid.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,7 @@ def dual(self):
382382
sage: N.rank()
383383
3
384384
sage: N
385-
Pappus: Matroid of rank 3 on 9 elements with circuit-closures
386-
{2: {{'a', 'b', 'c'}, {'a', 'e', 'i'}, {'a', 'f', 'h'},
387-
{'b', 'd', 'i'}, {'b', 'f', 'g'}, {'c', 'd', 'h'},
388-
{'c', 'e', 'g'}, {'d', 'e', 'f'}, {'g', 'h', 'i'}},
389-
3: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'}}}
385+
Pappus: Matroid of rank 3 on 9 elements with 9 nonspanning circuits
390386
"""
391387
return self._matroid
392388

src/sage/matroids/matroid.pyx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3987,12 +3987,7 @@ cdef class Matroid(SageObject):
39873987
sage: N.rank()
39883988
6
39893989
sage: N
3990-
Dual of 'Pappus: Matroid of rank 3 on 9 elements with
3991-
circuit-closures
3992-
{2: {{'a', 'b', 'c'}, {'a', 'e', 'i'}, {'a', 'f', 'h'},
3993-
{'b', 'd', 'i'}, {'b', 'f', 'g'}, {'c', 'd', 'h'},
3994-
{'c', 'e', 'g'}, {'d', 'e', 'f'}, {'g', 'h', 'i'}},
3995-
3: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'}}}'
3990+
Dual of 'Pappus: Matroid of rank 3 on 9 elements with 9 nonspanning circuits'
39963991
"""
39973992
from sage.matroids import dual_matroid
39983993
return dual_matroid.DualMatroid(self)
@@ -8189,11 +8184,7 @@ cdef class Matroid(SageObject):
81898184
sage: N = matroids.catalog.Fano().direct_sum(M); N
81908185
Matroid of rank 6 on 16 elements as matroid sum of
81918186
Binary matroid of rank 3 on 7 elements, type (3, 0)
8192-
Matroid of rank 3 on 9 elements with circuit-closures
8193-
{2: {{'a', 'b', 'c'}, {'a', 'e', 'i'}, {'a', 'f', 'h'},
8194-
{'b', 'd', 'i'}, {'b', 'f', 'g'}, {'c', 'd', 'h'},
8195-
{'c', 'e', 'g'}, {'d', 'e', 'f'}, {'g', 'h', 'i'}},
8196-
3: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'}}}
8187+
Matroid of rank 3 on 9 elements with 9 nonspanning circuits
81978188
sage: len(N.independent_sets())
81988189
6897
81998190
sage: len(N.bases())

0 commit comments

Comments
 (0)