Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/sage/matroids/catalog.py
8817 views
1
r"""
2
Documentation for the matroids in the catalog
3
4
This module contains implementations for many of the functions accessible
5
through :mod:`matroids. <sage.matroids.matroids_catalog>` and
6
:mod:`matroids.named_matroids. <sage.matroids.matroids_catalog>`
7
(type those lines in Sage and hit ``tab`` for a list).
8
9
The docstrings include educational information about each named matroid with
10
the hopes that this class can be used as a reference. However, for a more
11
comprehensive list of properties we refer to the appendix of [Oxley]_.
12
13
.. TODO::
14
15
Add optional argument ``groundset`` to each method so users can customize
16
the groundset of the matroid. We probably want some means of relabeling to
17
accomplish that.
18
19
Add option to specify the field for represented matroids.
20
21
AUTHORS:
22
23
- Michael Welsh, Stefan van Zwam (2013-04-01): initial version
24
25
Functions
26
=========
27
"""
28
#*****************************************************************************
29
# Copyright (C) 2013 Michael Welsh <[email protected] >
30
# Copyright (C) 2013 Stefan van Zwam <[email protected] >
31
#
32
# Distributed under the terms of the GNU General Public License (GPL)
33
# as published by the Free Software Foundation; either version 2 of
34
# the License, or (at your option) any later version.
35
# http://www.gnu.org/licenses/
36
#*****************************************************************************
37
38
from itertools import combinations
39
40
import sage.matrix.matrix
41
from sage.matrix.constructor import Matrix
42
from sage.graphs.all import Graph, graphs
43
44
from sage.rings.all import ZZ, QQ, FiniteField, GF
45
from sage.schemes.all import ProjectiveSpace
46
from sage.calculus.var import var
47
48
import sage.matroids.matroid
49
import sage.matroids.basis_exchange_matroid
50
from sage.matroids.basis_matroid import BasisMatroid
51
from sage.matroids.circuit_closures_matroid import CircuitClosuresMatroid
52
from sage.matroids.linear_matroid import LinearMatroid, RegularMatroid, BinaryMatroid, TernaryMatroid, QuaternaryMatroid
53
from sage.matroids.rank_matroid import RankMatroid
54
from sage.matroids.constructor import Matroid
55
56
# The order is the same as in Oxley.
57
58
59
def Q6():
60
"""
61
Return the matroid `Q_6`, represented over `GF(4)`.
62
63
The matroid `Q_6` is a 6-element matroid of rank-3.
64
It is representable over a field if and only if that field has at least
65
four elements. It is the unique relaxation of the rank-3 whirl.
66
See [Oxley]_, p. 641.
67
68
EXAMPLES::
69
70
sage: from sage.matroids.advanced import setprint
71
sage: M = matroids.named_matroids.Q6(); M
72
Q6: Quaternary matroid of rank 3 on 6 elements
73
sage: setprint(M.hyperplanes())
74
[{'a', 'b', 'd'}, {'a', 'c'}, {'a', 'e'}, {'a', 'f'}, {'b', 'c', 'e'},
75
{'b', 'f'}, {'c', 'd'}, {'c', 'f'}, {'d', 'e'}, {'d', 'f'},
76
{'e', 'f'}]
77
sage: M.nonspanning_circuits() == M.noncospanning_cocircuits()
78
False
79
"""
80
F = GF(4, 'x')
81
x = F.gens()[0]
82
A = Matrix(F, [
83
[1, 0, 0, 1, 0, 1],
84
[0, 1, 0, 1, 1, x],
85
[0, 0, 1, 0, 1, 1]
86
])
87
M = QuaternaryMatroid(A, 'abcdef')
88
M.rename('Q6: ' + repr(M))
89
return M
90
91
92
def P6():
93
"""
94
Return the matroid `P_6`, represented as circuit closures.
95
96
The matroid `P_6` is a 6-element matroid of rank-3.
97
It is representable over a field if and only if that field has at least
98
five elements.
99
It is the unique relaxation of `Q_6`.
100
It is an excluded minor for the class of quaternary matroids.
101
See [Oxley]_, p. 641.
102
103
EXAMPLES::
104
105
sage: M = matroids.named_matroids.P6(); M
106
P6: Matroid of rank 3 on 6 elements with circuit-closures
107
{2: {{'a', 'b', 'c'}}, 3: {{'a', 'b', 'c', 'd', 'e', 'f'}}}
108
sage: len(set(M.nonspanning_circuits()).difference(M.nonbases())) == 0
109
True
110
sage: Matroid(matrix=random_matrix(GF(4, 'a'), ncols=5,
111
....: nrows=5)).has_minor(M)
112
False
113
sage: M.is_valid()
114
True
115
"""
116
E = 'abcdef'
117
CC = {
118
2: ['abc'],
119
3: [E]
120
}
121
M = CircuitClosuresMatroid(groundset=E, circuit_closures=CC)
122
M.rename('P6: ' + repr(M))
123
return M
124
125
126
def R6():
127
"""
128
Return the matroid `R_6`, represented over `GF(3)`.
129
130
The matroid `R_6` is a 6-element matroid of rank-3.
131
It is representable over a field if and only if that field has at least
132
three elements.
133
It is isomorphic to the 2-sum of two copies of `U_{2, 4}`.
134
See [Oxley]_, p. 642.
135
136
EXAMPLES::
137
138
sage: M = matroids.named_matroids.R6(); M
139
R6: Ternary matroid of rank 3 on 6 elements, type 2+
140
sage: M.equals(M.dual())
141
True
142
sage: M.is_connected()
143
True
144
sage: M.is_3connected()
145
False
146
"""
147
A = Matrix(GF(3), [
148
[1, 0, 0, 1, 1, 1],
149
[0, 1, 0, 1, 2, 1],
150
[0, 0, 1, 1, 0, 2]
151
])
152
M = TernaryMatroid(A, 'abcdef')
153
M.rename('R6: ' + repr(M))
154
return M
155
156
157
def Fano():
158
"""
159
Return the Fano matroid, represented over `GF(2)`.
160
161
The Fano matroid, or Fano plane, or `F_7`, is a 7-element matroid of
162
rank-3.
163
It is representable over a field if and only if that field has
164
characteristic two.
165
It is also the projective plane of order two, i.e. `\mathrm{PG}(2, 2)`.
166
See [Oxley]_, p. 643.
167
168
EXAMPLES::
169
170
sage: from sage.matroids.advanced import setprint
171
sage: M = matroids.named_matroids.Fano(); M
172
Fano: Binary matroid of rank 3 on 7 elements, type (3, 0)
173
sage: setprint(sorted(M.nonspanning_circuits()))
174
[{'b', 'c', 'd'}, {'a', 'c', 'e'}, {'d', 'e', 'f'}, {'a', 'b', 'f'},
175
{'c', 'f', 'g'}, {'b', 'e', 'g'}, {'a', 'd', 'g'}]
176
sage: M.delete(M.groundset_list()[randrange(0,
177
....: 7)]).is_isomorphic(matroids.CompleteGraphic(4))
178
True
179
"""
180
A = Matrix(GF(2), [
181
[1, 0, 0, 0, 1, 1, 1],
182
[0, 1, 0, 1, 0, 1, 1],
183
[0, 0, 1, 1, 1, 0, 1]
184
])
185
M = BinaryMatroid(A, 'abcdefg')
186
M.rename('Fano: ' + repr(M))
187
return M
188
189
190
def NonFano():
191
"""
192
Return the non-Fano matroid, represented over `GF(3)`
193
194
The non-Fano matroid, or `F_7^-`, is a 7-element matroid of rank-3.
195
It is representable over a field if and only if that field has
196
characteristic other than two.
197
It is the unique relaxation of `F_7`. See [Oxley]_, p. 643.
198
199
EXAMPLES::
200
201
sage: from sage.matroids.advanced import setprint
202
sage: M = matroids.named_matroids.NonFano(); M
203
NonFano: Ternary matroid of rank 3 on 7 elements, type 0-
204
sage: setprint(M.nonbases())
205
[{'b', 'c', 'd'}, {'a', 'c', 'e'}, {'a', 'b', 'f'}, {'c', 'f', 'g'},
206
{'b', 'e', 'g'}, {'a', 'd', 'g'}]
207
sage: M.delete('f').is_isomorphic(matroids.CompleteGraphic(4))
208
True
209
sage: M.delete('g').is_isomorphic(matroids.CompleteGraphic(4))
210
False
211
"""
212
A = Matrix(GF(3), [
213
[1, 0, 0, 0, 1, 1, 1],
214
[0, 1, 0, 1, 0, 1, 1],
215
[0, 0, 1, 1, 1, 0, 1]
216
])
217
M = TernaryMatroid(A, 'abcdefg')
218
M.rename('NonFano: ' + repr(M))
219
return M
220
221
222
def O7():
223
"""
224
Return the matroid `O_7`, represented over `GF(3)`.
225
226
The matroid `O_7` is a 7-element matroid of rank-3.
227
It is representable over a field if and only if that field has at least
228
three elements.
229
It is obtained by freely adding a point to any line of `M(K_4)`.
230
See [Oxley]_, p. 644
231
232
EXAMPLES::
233
234
sage: M = matroids.named_matroids.O7(); M
235
O7: Ternary matroid of rank 3 on 7 elements, type 0+
236
sage: M.delete('e').is_isomorphic(matroids.CompleteGraphic(4))
237
True
238
sage: M.tutte_polynomial()
239
y^4 + x^3 + x*y^2 + 3*y^3 + 4*x^2 + 5*x*y + 5*y^2 + 4*x + 4*y
240
"""
241
A = Matrix(GF(3), [
242
[1, 0, 0, 1, 1, 1, 1],
243
[0, 1, 0, 0, 1, 2, 2],
244
[0, 0, 1, 1, 0, 1, 0]
245
])
246
M = TernaryMatroid(A, 'abcdefg')
247
M.rename('O7: ' + repr(M))
248
return M
249
250
251
def P7():
252
"""
253
Return the matroid `P_7`, represented over `GF(3)`.
254
255
The matroid `P_7` is a 7-element matroid of rank-3.
256
It is representable over a field if and only if that field has at least
257
3 elements.
258
It is one of two ternary 3-spikes, with the other being `F_7^-`.
259
See [Oxley]_, p. 644.
260
261
EXAMPLES::
262
263
sage: M = matroids.named_matroids.P7(); M
264
P7: Ternary matroid of rank 3 on 7 elements, type 1+
265
sage: M.f_vector()
266
[1, 7, 11, 1]
267
sage: M.has_minor(matroids.CompleteGraphic(4))
268
False
269
sage: M.is_valid()
270
True
271
"""
272
A = Matrix(GF(3), [
273
[1, 0, 0, 2, 1, 1, 0],
274
[0, 1, 0, 1, 1, 0, 1],
275
[0, 0, 1, 1, 0, 1, 1]
276
])
277
M = TernaryMatroid(A, 'abcdefg')
278
M.rename('P7: ' + repr(M))
279
return M
280
281
# AG(3, 2) - use AG()
282
283
284
def AG32prime():
285
"""
286
Return the matroid `AG(3, 2)'`, represented as circuit closures.
287
288
The matroid `AG(3, 2)'` is a 8-element matroid of rank-4.
289
It is a smallest non-representable matroid.
290
It is the unique relaxation of `AG(3, 2)`. See [Oxley]_, p. 646.
291
292
EXAMPLES::
293
294
sage: from sage.matroids.advanced import setprint
295
sage: M = matroids.named_matroids.AG32prime(); M
296
AG(3, 2)': Matroid of rank 4 on 8 elements with circuit-closures
297
{3: {{'c', 'd', 'e', 'h'}, {'b', 'e', 'g', 'h'}, {'d', 'e', 'f', 'g'},
298
{'a', 'b', 'd', 'e'}, {'b', 'c', 'd', 'g'}, {'c', 'f', 'g', 'h'},
299
{'a', 'c', 'd', 'f'}, {'b', 'c', 'e', 'f'}, {'a', 'c', 'e', 'g'},
300
{'a', 'b', 'f', 'g'}, {'a', 'b', 'c', 'h'}, {'a', 'e', 'f', 'h'},
301
{'a', 'd', 'g', 'h'}},
302
4: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}}}
303
sage: M.contract('c').is_isomorphic(matroids.named_matroids.Fano())
304
True
305
sage: setprint(M.noncospanning_cocircuits())
306
[{'b', 'd', 'f', 'h'}, {'a', 'd', 'g', 'h'}, {'c', 'd', 'e', 'h'},
307
{'a', 'c', 'd', 'f'}, {'b', 'c', 'd', 'g'}, {'a', 'b', 'd', 'e'},
308
{'d', 'e', 'f', 'g'}, {'c', 'f', 'g', 'h'}, {'b', 'c', 'e', 'f'},
309
{'a', 'b', 'f', 'g'}, {'a', 'b', 'c', 'h'}, {'a', 'e', 'f', 'h'},
310
{'b', 'e', 'g', 'h'}]
311
sage: M.is_valid() # long time
312
True
313
"""
314
E = 'abcdefgh'
315
CC = {
316
3: ['abfg', 'bcdg', 'defg', 'cdeh', 'aefh', 'abch', 'abed', 'cfgh', 'bcef', 'adgh', 'acdf', 'begh', 'aceg'],
317
4: [E]
318
}
319
M = CircuitClosuresMatroid(groundset=E, circuit_closures=CC)
320
M.rename('AG(3, 2)\': ' + repr(M))
321
return M
322
323
324
def R8():
325
"""
326
Return the matroid `R_8`, represented over `GF(3)`.
327
328
The matroid `R_8` is a 8-element matroid of rank-4.
329
It is representable over a field if and only if the characteristic of that
330
field is not two.
331
It is the real affine cube. See [Oxley]_, p. 646.
332
333
EXAMPLES::
334
335
sage: M = matroids.named_matroids.R8(); M
336
R8: Ternary matroid of rank 4 on 8 elements, type 0+
337
sage: M.contract(M.groundset_list()[randrange(0,
338
....: 8)]).is_isomorphic(matroids.named_matroids.NonFano())
339
True
340
sage: M.equals(M.dual())
341
True
342
sage: M.has_minor(matroids.named_matroids.Fano())
343
False
344
"""
345
A = Matrix(GF(3), [
346
[1, 0, 0, 0, 2, 1, 1, 1],
347
[0, 1, 0, 0, 1, 2, 1, 1],
348
[0, 0, 1, 0, 1, 1, 2, 1],
349
[0, 0, 0, 1, 1, 1, 1, 2]
350
])
351
M = TernaryMatroid(A, 'abcdefgh')
352
M.rename('R8: ' + repr(M))
353
return M
354
355
356
def F8():
357
"""
358
Return the matroid `F_8`, represented as circuit closures.
359
360
The matroid `F_8` is a 8-element matroid of rank-4.
361
It is a smallest non-representable matroid. See [Oxley]_, p. 647.
362
363
EXAMPLES::
364
365
sage: from sage.matroids.advanced import *
366
sage: M = matroids.named_matroids.F8(); M
367
F8: Matroid of rank 4 on 8 elements with circuit-closures
368
{3: {{'c', 'd', 'e', 'h'}, {'d', 'e', 'f', 'g'}, {'a', 'b', 'd', 'e'},
369
{'b', 'c', 'd', 'g'}, {'c', 'f', 'g', 'h'}, {'a', 'c', 'd', 'f'},
370
{'b', 'c', 'e', 'f'}, {'a', 'c', 'e', 'g'}, {'a', 'b', 'f', 'g'},
371
{'a', 'b', 'c', 'h'}, {'a', 'e', 'f', 'h'}, {'a', 'd', 'g', 'h'}},
372
4: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}}}
373
sage: D = get_nonisomorphic_matroids([M.contract(i)
374
....: for i in M.groundset()])
375
sage: len(D)
376
3
377
sage: [N.is_isomorphic(matroids.named_matroids.Fano()) for N in D]
378
[...True...]
379
sage: [N.is_isomorphic(matroids.named_matroids.NonFano()) for N in D]
380
[...True...]
381
sage: M.is_valid() # long time
382
True
383
"""
384
E = 'abcdefgh'
385
CC = {
386
3: ['abfg', 'bcdg', 'defg', 'cdeh', 'aefh', 'abch', 'abed', 'cfgh', 'bcef', 'adgh', 'acdf', 'aceg'],
387
4: [E]
388
}
389
M = CircuitClosuresMatroid(groundset=E, circuit_closures=CC)
390
M.rename('F8: ' + repr(M))
391
return M
392
393
394
def Q8():
395
"""
396
Return the matroid `Q_8`, represented as circuit closures.
397
398
The matroid `Q_8` is a 8-element matroid of rank-4.
399
It is a smallest non-representable matroid. See [Oxley]_, p. 647.
400
401
EXAMPLES::
402
403
sage: from sage.matroids.advanced import setprint
404
sage: M = matroids.named_matroids.Q8(); M
405
Q8: Matroid of rank 4 on 8 elements with circuit-closures
406
{3: {{'c', 'd', 'e', 'h'}, {'d', 'e', 'f', 'g'}, {'a', 'b', 'd', 'e'},
407
{'b', 'c', 'd', 'g'}, {'c', 'f', 'g', 'h'}, {'a', 'c', 'd', 'f'},
408
{'b', 'c', 'e', 'f'}, {'a', 'b', 'f', 'g'}, {'a', 'b', 'c', 'h'},
409
{'a', 'e', 'f', 'h'}, {'a', 'd', 'g', 'h'}},
410
4: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}}}
411
sage: setprint(M.flats(3))
412
[{'a', 'b', 'c', 'h'}, {'a', 'b', 'd', 'e'}, {'a', 'b', 'f', 'g'},
413
{'a', 'c', 'd', 'f'}, {'a', 'c', 'e'}, {'a', 'c', 'g'},
414
{'a', 'd', 'g', 'h'}, {'a', 'e', 'f', 'h'}, {'a', 'e', 'g'},
415
{'b', 'c', 'd', 'g'}, {'b', 'c', 'e', 'f'}, {'b', 'd', 'f'},
416
{'b', 'd', 'h'}, {'b', 'e', 'g'}, {'b', 'e', 'h'}, {'b', 'f', 'h'},
417
{'b', 'g', 'h'}, {'c', 'd', 'e', 'h'}, {'c', 'e', 'g'},
418
{'c', 'f', 'g', 'h'}, {'d', 'e', 'f', 'g'}, {'d', 'f', 'h'},
419
{'e', 'g', 'h'}]
420
sage: M.is_valid() # long time
421
True
422
"""
423
E = 'abcdefgh'
424
CC = {
425
3: ['abfg', 'bcdg', 'defg', 'cdeh', 'aefh', 'abch', 'abed', 'cfgh', 'bcef', 'adgh', 'acdf'],
426
4: [E]
427
}
428
M = CircuitClosuresMatroid(groundset=E, circuit_closures=CC)
429
M.rename('Q8: ' + repr(M))
430
return M
431
432
433
def L8():
434
"""
435
Return the matroid `L_8`, represented as circuit closures.
436
437
The matroid `L_8` is a 8-element matroid of rank-4.
438
It is representable over all fields with at least five elements.
439
It is a cube, yet it is not a tipless spike. See [Oxley]_, p. 648.
440
441
EXAMPLES::
442
443
sage: from sage.matroids.advanced import setprint
444
sage: M = matroids.named_matroids.L8(); M
445
L8: Matroid of rank 4 on 8 elements with circuit-closures
446
{3: {{'b', 'd', 'f', 'h'}, {'c', 'd', 'e', 'h'}, {'d', 'e', 'f', 'g'},
447
{'b', 'c', 'd', 'g'}, {'a', 'c', 'e', 'g'}, {'a', 'b', 'f', 'g'},
448
{'a', 'b', 'c', 'h'}, {'a', 'e', 'f', 'h'}},
449
4: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}}}
450
sage: M.equals(M.dual())
451
True
452
sage: M.is_valid() # long time
453
True
454
"""
455
E = 'abcdefgh'
456
CC = {
457
3: ['abfg', 'bcdg', 'defg', 'cdeh', 'aefh', 'abch', 'aceg', 'bdfh'],
458
4: [E]
459
}
460
M = CircuitClosuresMatroid(groundset=E, circuit_closures=CC)
461
M.rename('L8: ' + repr(M))
462
return M
463
464
465
def S8():
466
"""
467
Return the matroid `S_8`, represented over `GF(2)`.
468
469
The matroid `S_8` is a 8-element matroid of rank-4.
470
It is representable over a field if and only if that field has
471
characteristic two.
472
It is the unique deletion of a non-tip element from the binary 4-spike.
473
See [Oxley]_, p. 648.
474
475
EXAMPLES::
476
477
sage: from sage.matroids.advanced import *
478
sage: M = matroids.named_matroids.S8(); M
479
S8: Binary matroid of rank 4 on 8 elements, type (2, 0)
480
sage: M.contract('d').is_isomorphic(matroids.named_matroids.Fano())
481
True
482
sage: M.delete('d').is_isomorphic(
483
....: matroids.named_matroids.Fano().dual())
484
False
485
sage: M.is_graphic()
486
False
487
sage: D = get_nonisomorphic_matroids(
488
....: list(matroids.named_matroids.Fano().linear_coextensions(
489
....: cosimple=True)))
490
sage: len(D)
491
2
492
sage: [N.is_isomorphic(M) for N in D]
493
[...True...]
494
495
"""
496
A = Matrix(GF(2), [
497
[1, 0, 0, 0, 0, 1, 1, 1],
498
[0, 1, 0, 0, 1, 0, 1, 1],
499
[0, 0, 1, 0, 1, 1, 0, 1],
500
[0, 0, 0, 1, 1, 1, 1, 1]
501
])
502
M = BinaryMatroid(A, 'abcdefgh')
503
M.rename('S8: ' + repr(M))
504
return M
505
506
507
def Vamos():
508
"""
509
Return the Vamos matroid, represented as circuit closures.
510
511
The Vamos matroid, or Vamos cube, or `V_8` is a 8-element matroid of
512
rank-4.
513
It violates Ingleton's condition for representability over a division
514
ring.
515
It is not algebraic. See [Oxley]_, p. 649.
516
517
EXAMPLES::
518
519
sage: from sage.matroids.advanced import setprint
520
sage: M = matroids.named_matroids.Vamos(); M
521
Vamos: Matroid of rank 4 on 8 elements with circuit-closures
522
{3: {{'a', 'b', 'c', 'd'}, {'a', 'b', 'e', 'f'}, {'e', 'f', 'g', 'h'},
523
{'a', 'b', 'g', 'h'}, {'c', 'd', 'e', 'f'}},
524
4: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}}}
525
sage: setprint(M.nonbases())
526
[{'a', 'b', 'c', 'd'}, {'a', 'b', 'e', 'f'}, {'a', 'b', 'g', 'h'},
527
{'c', 'd', 'e', 'f'}, {'e', 'f', 'g', 'h'}]
528
sage: M.is_dependent(['c', 'd', 'g', 'h'])
529
False
530
sage: M.is_valid() # long time
531
True
532
"""
533
E = 'abcdefgh'
534
CC = {
535
3: ['abcd', 'abef', 'cdef', 'abgh', 'efgh'],
536
4: [E]
537
}
538
M = CircuitClosuresMatroid(groundset=E, circuit_closures=CC)
539
M.rename('Vamos: ' + repr(M))
540
return M
541
542
543
def T8():
544
"""
545
Return the matroid `T_8`, represented over `GF(3)`.
546
547
The matroid `T_8` is a 8-element matroid of rank-4.
548
It is representable over a field if and only if that field has
549
characteristic three.
550
It is an excluded minor for the dyadic matroids. See [Oxley]_, p. 649.
551
552
EXAMPLES::
553
554
sage: M = matroids.named_matroids.T8(); M
555
T8: Ternary matroid of rank 4 on 8 elements, type 0-
556
sage: M.truncation().is_isomorphic(matroids.Uniform(3, 8))
557
True
558
sage: M.contract('e').is_isomorphic(matroids.named_matroids.P7())
559
True
560
sage: M.has_minor(matroids.Uniform(3, 8))
561
False
562
563
"""
564
A = Matrix(GF(3), [
565
[1, 0, 0, 0, 0, 1, 1, 1],
566
[0, 1, 0, 0, 1, 0, 1, 1],
567
[0, 0, 1, 0, 1, 1, 0, 1],
568
[0, 0, 0, 1, 1, 1, 1, 0]
569
])
570
M = TernaryMatroid(A, 'abcdefgh')
571
M.rename('T8: ' + repr(M))
572
return M
573
574
575
def J():
576
"""
577
Return the matroid `J`, represented over `GF(3)`.
578
579
The matroid `J` is a 8-element matroid of rank-4.
580
It is representable over a field if and only if that field has at least
581
three elements. See [Oxley]_, p. 650.
582
583
EXAMPLES::
584
585
sage: from sage.matroids.advanced import setprint
586
sage: M = matroids.named_matroids.J(); M
587
J: Ternary matroid of rank 4 on 8 elements, type 0-
588
sage: setprint(M.truncation().nonbases())
589
[{'a', 'c', 'g'}, {'a', 'b', 'f'}, {'a', 'd', 'h'}]
590
sage: M.is_isomorphic(M.dual())
591
True
592
sage: M.has_minor(matroids.CompleteGraphic(4))
593
False
594
sage: M.is_valid()
595
True
596
"""
597
A = Matrix(GF(3), [
598
[1, 0, 0, 0, 0, 1, 1, 1],
599
[0, 1, 0, 0, 1, 1, 0, 0],
600
[0, 0, 1, 0, 1, 0, 1, 0],
601
[0, 0, 0, 1, 1, 0, 0, 1]
602
])
603
M = TernaryMatroid(A, 'abcdefgh')
604
M.rename('J: ' + repr(M))
605
return M
606
607
608
def P8():
609
"""
610
Return the matroid `P_8`, represented over `GF(3)`.
611
612
The matroid `P_8` is a 8-element matroid of rank-4.
613
It is uniquely representable over all fields of characteristic other than
614
two.
615
It is an excluded minor for all fields of characteristic two with four or
616
more elements. See [Oxley]_, p. 650.
617
618
EXAMPLES::
619
620
sage: M = matroids.named_matroids.P8(); M
621
P8: Ternary matroid of rank 4 on 8 elements, type 2+
622
sage: M.is_isomorphic(M.dual())
623
True
624
sage: Matroid(matrix=random_matrix(GF(4, 'a'), ncols=5,
625
....: nrows=5)).has_minor(M)
626
False
627
sage: M.bicycle_dimension()
628
2
629
630
"""
631
A = Matrix(GF(3), [
632
[1, 0, 0, 0, 2, 1, 1, 0],
633
[0, 1, 0, 0, 1, 1, 0, 1],
634
[0, 0, 1, 0, 1, 0, 1, 1],
635
[0, 0, 0, 1, 0, 1, 1, 2]
636
])
637
M = TernaryMatroid(A, 'abcdefgh')
638
M.rename('P8: ' + repr(M))
639
return M
640
641
642
def P8pp():
643
"""
644
Return the matroid `P_8^=`, represented as circuit closures.
645
646
The matroid `P_8^=` is a 8-element matroid of rank-4.
647
It can be obtained from `P_8` by relaxing the unique pair of disjoint
648
circuit-hyperplanes.
649
It is an excluded minor for `GF(4)`-representability.
650
It is representable over all fields with at least five elements.
651
See [Oxley]_, p. 651.
652
653
EXAMPLES::
654
655
sage: from sage.matroids.advanced import *
656
sage: M = matroids.named_matroids.P8pp(); M
657
P8'': Matroid of rank 4 on 8 elements with circuit-closures
658
{3: {{'a', 'c', 'g', 'h'}, {'a', 'b', 'f', 'h'}, {'b', 'c', 'e', 'g'},
659
{'a', 'd', 'e', 'g'}, {'c', 'd', 'f', 'h'}, {'b', 'd', 'f', 'g'},
660
{'a', 'c', 'e', 'f'}, {'b', 'd', 'e', 'h'}},
661
4: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}}}
662
sage: M.is_isomorphic(M.dual())
663
True
664
sage: len(get_nonisomorphic_matroids([M.contract(i)
665
....: for i in M.groundset()]))
666
1
667
sage: M.is_valid() # long time
668
True
669
670
"""
671
E = 'abcdefgh'
672
CC = {3: ['abfh', 'bceg', 'cdfh', 'adeg', 'acef', 'bdfg', 'acgh', 'bdeh'],
673
4: [E]}
674
M = CircuitClosuresMatroid(groundset=E, circuit_closures=CC)
675
M.rename('P8\'\': ' + repr(M))
676
return M
677
678
679
def K33dual():
680
"""
681
Return the matroid `M*(K_{3, 3})`, represented over the regular partial
682
field.
683
684
The matroid `M*(K_{3, 3})` is a 9-element matroid of rank-4.
685
It is an excluded minor for the class of graphic matroids.
686
It is the graft matroid of the 4-wheel with every vertex except the hub
687
being coloured. See [Oxley]_, p. 652.
688
689
EXAMPLES::
690
691
sage: M = matroids.named_matroids.K33dual(); M
692
M*(K3, 3): Regular matroid of rank 4 on 9 elements with 81 bases
693
sage: any([N.is_3connected()
694
....: for N in M.linear_extensions(simple=True)])
695
False
696
sage: M.is_valid() # long time
697
True
698
699
"""
700
E = 'abcdefghi'
701
G = graphs.CompleteBipartiteGraph(3, 3)
702
M = Matroid(groundset=E, graph=G)
703
M = M.dual()
704
M.rename('M*(K3, 3): ' + repr(M))
705
return M
706
707
# AG(2, 3) - use AG()
708
709
710
def TernaryDowling3():
711
"""
712
Return the matroid `Q_3(GF(3)^\times)`, represented over `GF(3)`.
713
714
The matroid `Q_3(GF(3)^\times)` is a 9-element matroid of rank-3.
715
It is the rank-3 ternary Dowling geometry.
716
It is representable over a field if and only if that field does not have
717
characteristic two. See [Oxley]_, p. 654.
718
719
EXAMPLES::
720
721
sage: M = matroids.named_matroids.TernaryDowling3(); M
722
Q3(GF(3)x): Ternary matroid of rank 3 on 9 elements, type 0-
723
sage: len(list(M.linear_subclasses()))
724
72
725
sage: M.fundamental_cycle('abc', 'd')
726
{'a': 2, 'b': 1, 'd': 1}
727
728
"""
729
A = Matrix(GF(3), [
730
[1, 0, 0, 1, 1, 0, 0, 1, 1],
731
[0, 1, 0, 2, 1, 1, 1, 0, 0],
732
[0, 0, 1, 0, 0, 2, 1, 2, 1]
733
])
734
M = TernaryMatroid(A, 'abcdefghi')
735
M.rename('Q3(GF(3)x): ' + repr(M))
736
return M
737
738
# yomcat's progress flag
739
740
741
def CompleteGraphic(n):
742
"""
743
Return the cycle matroid of the complete graph on `n` vertices.
744
745
INPUT:
746
747
- ``n`` -- an integer, the number of vertices of the underlying complete
748
graph.
749
750
OUTPUT:
751
752
The regular matroid associated with the `n`-vertex complete graph.
753
This matroid has rank `n - 1`.
754
755
The maximum-sized regular matroid of rank `n` is `M(K_n)`.
756
757
EXAMPLES::
758
759
sage: from sage.matroids.advanced import setprint
760
sage: M = matroids.CompleteGraphic(5); M
761
M(K5): Regular matroid of rank 4 on 10 elements with 125 bases
762
sage: M.has_minor(matroids.Uniform(2, 4))
763
False
764
sage: simplify(M.contract(randrange(0,
765
....: 10))).is_isomorphic(matroids.CompleteGraphic(4))
766
True
767
sage: setprint(M.closure([0, 2, 4, 5]))
768
{0, 1, 2, 4, 5, 7}
769
sage: M.is_valid()
770
True
771
"""
772
M = Matroid(groundset=range(n * (n - 1) / 2), graph=graphs.CompleteGraph(n))
773
M.rename('M(K' + str(n) + '): ' + repr(M))
774
return M
775
776
777
def Wheel(n):
778
"""
779
Return the rank-`n` wheel.
780
781
INPUT:
782
783
- ``n`` -- a positive integer. The rank of the desired matroid.
784
785
OUTPUT:
786
787
The rank-`n` wheel matroid, represented as a regular matroid.
788
789
See [Oxley]_, p. 659.
790
791
EXAMPLES::
792
793
sage: M = matroids.Wheel(5); M
794
Wheel(5): Regular matroid of rank 5 on 10 elements with 121 bases
795
sage: M.tutte_polynomial()
796
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 +
797
15*x^2*y + 15*x*y^2 + 10*y^3 + 10*x^2 + 16*x*y + 10*y^2 + 4*x + 4*y
798
sage: M.is_valid()
799
True
800
sage: M = matroids.Wheel(3)
801
sage: M.is_isomorphic(matroids.CompleteGraphic(4))
802
True
803
"""
804
A = Matrix(ZZ, n, 2 * n, sparse=True)
805
for i in range(n):
806
A[i, i] = 1
807
A[i, n + i] = 1
808
if i != 0:
809
A[i, i + n - 1] = -1
810
else:
811
A[i, 2 * n - 1] = -1
812
M = RegularMatroid(A)
813
M.rename('Wheel(' + str(n) + '): ' + repr(M))
814
return M
815
816
817
def Whirl(n):
818
"""
819
Return the rank-`n` whirl.
820
821
INPUT:
822
823
- ``n`` -- a positive integer. The rank of the desired matroid.
824
825
OUTPUT:
826
827
The rank-`n` whirl matroid, represented as a ternary matroid.
828
829
The whirl is the unique relaxation of the wheel. See [Oxley]_, p. 659.
830
831
EXAMPLES::
832
833
sage: M = matroids.Whirl(5); M
834
Whirl(5): Ternary matroid of rank 5 on 10 elements, type 0-
835
sage: M.is_valid()
836
True
837
sage: M.tutte_polynomial()
838
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 +
839
15*x^2*y + 15*x*y^2 + 10*y^3 + 10*x^2 + 15*x*y + 10*y^2 + 5*x + 5*y
840
sage: M.is_isomorphic(matroids.Wheel(5))
841
False
842
sage: M = matroids.Whirl(3)
843
sage: M.is_isomorphic(matroids.CompleteGraphic(4))
844
False
845
846
.. TODO::
847
848
Optional arguments ``ring`` and ``x``, such that the resulting matroid
849
is represented over ``ring`` by a reduced matrix like
850
``[-1 0 x]``
851
``[ 1 -1 0]``
852
``[ 0 1 -1]``
853
"""
854
A = Matrix(GF(3), n, 2 * n, sparse=True)
855
for i in range(n):
856
A[i, i] = 1
857
A[i, n + i] = 1
858
if i != 0:
859
A[i, i + n - 1] = -1
860
else:
861
A[i, 2 * n - 1] = 1
862
M = TernaryMatroid(A)
863
M.rename('Whirl(' + str(n) + '): ' + repr(M))
864
return M
865
866
867
def Uniform(r, n):
868
"""
869
Return the uniform matroid of rank `r` on `n` elements.
870
871
INPUT:
872
873
- ``r`` -- a nonnegative integer. The rank of the uniform matroid.
874
- ``n`` -- a nonnegative integer. The number of elements of the uniform
875
matroid.
876
877
OUTPUT:
878
879
The uniform matroid `U_{r,n}`.
880
881
All subsets of size `r` or less are independent; all larger subsets are
882
dependent. Representable when the field is sufficiently large. The precise
883
bound is the subject of the MDS conjecture from coding theory.
884
See [Oxley]_, p. 660.
885
886
EXAMPLES::
887
888
sage: from sage.matroids.advanced import setprint
889
sage: M = matroids.Uniform(2, 5); M
890
U(2, 5): Matroid of rank 2 on 5 elements with circuit-closures
891
{2: {{0, 1, 2, 3, 4}}}
892
sage: M.dual().is_isomorphic(matroids.Uniform(3, 5))
893
True
894
sage: setprint(M.hyperplanes())
895
[{0}, {1}, {2}, {3}, {4}]
896
sage: M.has_line_minor(6)
897
False
898
sage: M.is_valid()
899
True
900
901
Check that bug #15292 was fixed::
902
903
sage: M = matroids.Uniform(4,4)
904
sage: len(M.circuit_closures())
905
0
906
"""
907
E = range(n)
908
if r < n:
909
CC = {r: [E]}
910
else:
911
CC = {}
912
M = CircuitClosuresMatroid(groundset=E, circuit_closures=CC)
913
M.rename('U(' + str(r) + ', ' + str(n) + '): ' + repr(M))
914
return M
915
916
# Other interesting matroids
917
918
919
def PG(n, q, x=None):
920
"""
921
Return the projective geometry of dimension ``n`` over the finite field
922
of order ``q``.
923
924
INPUT:
925
926
- ``n`` -- a positive integer. The dimension of the projective space. This
927
is one less than the rank of the resulting matroid.
928
- ``q`` -- a positive integer that is a prime power. The order of the
929
finite field.
930
- ``x`` -- (default: ``None``) a string. The name of the generator of a
931
non-prime field, used for non-prime fields. If not supplied, ``'x'`` is
932
used.
933
934
OUTPUT:
935
936
A linear matroid whose elements are the points of `PG(n, q)`.
937
938
EXAMPLES::
939
940
sage: M = matroids.PG(2, 2)
941
sage: M.is_isomorphic(matroids.named_matroids.Fano())
942
True
943
sage: matroids.PG(5, 4, 'z').size() == (4^6 - 1) / (4 - 1)
944
True
945
sage: M = matroids.PG(4, 7); M
946
PG(4, 7): Linear matroid of rank 5 on 2801 elements represented over
947
the Finite Field of size 7
948
"""
949
if x is None:
950
x = var('x')
951
F = GF(q, x)
952
P = ProjectiveSpace(n, F)
953
A = Matrix(F, [list(p) for p in P]).transpose()
954
M = Matroid(A)
955
M.rename('PG(' + str(n) + ', ' + str(q) + '): ' + repr(M))
956
return M
957
958
959
def AG(n, q, x=None):
960
"""
961
Return the affine geometry of dimension ``n`` over the finite field of
962
order ``q``.
963
964
INPUT:
965
966
- ``n`` -- a positive integer. The dimension of the projective space. This
967
is one less than the rank of the resulting matroid.
968
- ``q`` -- a positive integer that is a prime power. The order of the
969
finite field.
970
- ``x`` -- (default: ``None``) a string. The name of the generator of a
971
non-prime field, used for non-prime fields. If not supplied, ``'x'`` is
972
used.
973
974
OUTPUT:
975
976
A linear matroid whose elements are the points of `AG(n, q)`.
977
978
The affine geometry can be obtained from the projective geometry by
979
removing a hyperplane.
980
981
EXAMPLES::
982
983
sage: M = matroids.AG(2, 3) \ 8
984
sage: M.is_isomorphic(matroids.named_matroids.AG23minus())
985
True
986
sage: matroids.AG(5, 4, 'z').size() == ((4 ^ 6 - 1) / (4 - 1) -
987
....: (4 ^ 5 - 1)/(4 - 1))
988
True
989
sage: M = matroids.AG(4, 2); M
990
AG(4, 2): Binary matroid of rank 5 on 16 elements, type (5, 0)
991
992
"""
993
if x is None:
994
x = var('x')
995
F = GF(q, x)
996
P = ProjectiveSpace(n, F)
997
A = Matrix(F, [list(p) for p in P if not list(p)[0] == 0]).transpose()
998
M = Matroid(A)
999
M.rename('AG(' + str(n) + ', ' + str(q) + '): ' + repr(M))
1000
return M
1001
1002
# Named matroids
1003
1004
1005
def R10():
1006
"""
1007
Return the matroid `R_{10}`, represented over the regular partial field.
1008
1009
The matroid `R_{10}` is a 10-element regular matroid of rank-5.
1010
It is the unique splitter for the class of regular matroids.
1011
It is the graft matroid of `K_{3, 3}` in which every vertex is coloured.
1012
See [Oxley]_, p. 656.
1013
1014
EXAMPLES::
1015
1016
sage: M = matroids.named_matroids.R10(); M
1017
R10: Regular matroid of rank 5 on 10 elements with 162 bases
1018
sage: cct = []
1019
sage: for i in M.circuits():
1020
....: cct.append(len(i))
1021
....:
1022
sage: Set(cct)
1023
{4, 6}
1024
sage: M.equals(M.dual())
1025
False
1026
sage: M.is_isomorphic(M.dual())
1027
True
1028
sage: M.is_valid()
1029
True
1030
1031
Check the splitter property::
1032
1033
sage: matroids.named_matroids.R10().linear_extensions(simple=True)
1034
[]
1035
"""
1036
A = Matrix(ZZ, [
1037
[1, 0, 0, 0, 0, -1, 1, 0, 0, 1],
1038
[0, 1, 0, 0, 0, 1, -1, 1, 0, 0],
1039
[0, 0, 1, 0, 0, 0, 1, -1, 1, 0],
1040
[0, 0, 0, 1, 0, 0, 0, 1, -1, 1],
1041
[0, 0, 0, 0, 1, 1, 0, 0, 1, -1]
1042
])
1043
M = RegularMatroid(A, 'abcdefghij')
1044
M.rename('R10: ' + repr(M))
1045
return M
1046
1047
1048
def R12():
1049
"""
1050
Return the matroid `R_{12}`, represented over the regular partial field.
1051
1052
The matroid `R_{12}` is a 12-element regular matroid of rank-6.
1053
It induces a 3-separation in its 3-connected majors within the class of
1054
regular matroids.
1055
An excluded minor for the class of graphic or cographic matroids.
1056
See [Oxley]_, p. 657.
1057
1058
EXAMPLES::
1059
1060
sage: M = matroids.named_matroids.R12(); M
1061
R12: Regular matroid of rank 6 on 12 elements with 441 bases
1062
sage: M.equals(M.dual())
1063
False
1064
sage: M.is_isomorphic(M.dual())
1065
True
1066
sage: M.is_valid()
1067
True
1068
"""
1069
A = Matrix(ZZ, [
1070
[1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0],
1071
[0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0],
1072
[0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0],
1073
[0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1],
1074
[0, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, -1],
1075
[0, 0, 0, 0, 0, 1, 0, 0, 0, 1, -1, -1]
1076
])
1077
M = RegularMatroid(A, 'abcdefghijkl')
1078
M.rename('R12: ' + repr(M))
1079
return M
1080
1081
1082
def NonVamos():
1083
"""
1084
Return the non-Vamos matroid.
1085
1086
The non-Vamos matroid, or `V_8^+` is an 8-element matroid of rank 4. It is
1087
a tightening of the Vamos matroid. It is representable over some field.
1088
See [Oxley]_, p. 72, 84.
1089
1090
EXAMPLES::
1091
1092
sage: from sage.matroids.advanced import setprint
1093
sage: M = matroids.named_matroids.NonVamos(); M
1094
NonVamos: Matroid of rank 4 on 8 elements with circuit-closures
1095
{3: {{'a', 'b', 'g', 'h'}, {'a', 'b', 'c', 'd'}, {'e', 'f', 'g', 'h'},
1096
{'c', 'd', 'e', 'f'}, {'a', 'b', 'e', 'f'}, {'c', 'd', 'g', 'h'}},
1097
4: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}}}
1098
sage: setprint(M.nonbases())
1099
[{'a', 'b', 'c', 'd'}, {'a', 'b', 'e', 'f'}, {'a', 'b', 'g', 'h'},
1100
{'c', 'd', 'e', 'f'}, {'c', 'd', 'g', 'h'}, {'e', 'f', 'g', 'h'}]
1101
sage: M.is_dependent(['c', 'd', 'g', 'h'])
1102
True
1103
sage: M.is_valid() # long time
1104
True
1105
"""
1106
E = 'abcdefgh'
1107
CC = {
1108
3: ['abcd', 'abef', 'cdef', 'abgh', 'cdgh', 'efgh'],
1109
4: [E]
1110
}
1111
M = CircuitClosuresMatroid(groundset=E, circuit_closures=CC)
1112
M.rename('NonVamos: ' + repr(M))
1113
return M
1114
1115
1116
def Pappus():
1117
"""
1118
Return the Pappus matroid.
1119
1120
The Pappus matroid is a 9-element matroid of rank-3.
1121
It is representable over a field if and only if that field either has 4
1122
elements or more than 7 elements.
1123
It is an excluded minor for the class of GF(5)-representable matroids.
1124
See [Oxley]_, p. 655.
1125
1126
EXAMPLES::
1127
1128
sage: from sage.matroids.advanced import setprint
1129
sage: M = matroids.named_matroids.Pappus(); M
1130
Pappus: Matroid of rank 3 on 9 elements with circuit-closures
1131
{2: {{'a', 'b', 'c'}, {'a', 'f', 'h'}, {'c', 'e', 'g'},
1132
{'b', 'f', 'g'}, {'c', 'd', 'h'}, {'d', 'e', 'f'},
1133
{'a', 'e', 'i'}, {'b', 'd', 'i'}, {'g', 'h', 'i'}},
1134
3: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'}}}
1135
sage: setprint(M.nonspanning_circuits())
1136
[{'a', 'b', 'c'}, {'a', 'f', 'h'}, {'c', 'e', 'g'}, {'b', 'f', 'g'},
1137
{'c', 'd', 'h'}, {'b', 'd', 'i'}, {'a', 'e', 'i'}, {'d', 'e', 'f'},
1138
{'g', 'h', 'i'}]
1139
sage: M.is_dependent(['d', 'e', 'f'])
1140
True
1141
sage: M.is_valid() # long time
1142
True
1143
"""
1144
E = 'abcdefghi'
1145
CC = {
1146
2: ['abc', 'def', 'ceg', 'bfg', 'cdh', 'afh', 'bdi', 'aei', 'ghi'],
1147
3: [E]
1148
}
1149
M = CircuitClosuresMatroid(groundset=E, circuit_closures=CC)
1150
M.rename('Pappus: ' + repr(M))
1151
return M
1152
1153
1154
def NonPappus():
1155
"""
1156
Return the non-Pappus matroid.
1157
1158
The non-Pappus matroid is a 9-element matroid of rank-3.
1159
It is not representable over any commutative field.
1160
It is the unique relaxation of the Pappus matroid. See [Oxley]_, p. 655.
1161
1162
EXAMPLES::
1163
1164
sage: from sage.matroids.advanced import setprint
1165
sage: M = matroids.named_matroids.NonPappus(); M
1166
NonPappus: Matroid of rank 3 on 9 elements with circuit-closures
1167
{2: {{'a', 'b', 'c'}, {'a', 'f', 'h'}, {'c', 'e', 'g'},
1168
{'b', 'f', 'g'}, {'c', 'd', 'h'}, {'b', 'd', 'i'},
1169
{'a', 'e', 'i'}, {'g', 'h', 'i'}},
1170
3: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'}}}
1171
sage: setprint(M.nonspanning_circuits())
1172
[{'a', 'b', 'c'}, {'a', 'f', 'h'}, {'c', 'e', 'g'}, {'b', 'f', 'g'},
1173
{'c', 'd', 'h'}, {'b', 'd', 'i'}, {'a', 'e', 'i'}, {'g', 'h', 'i'}]
1174
sage: M.is_dependent(['d', 'e', 'f'])
1175
False
1176
sage: M.is_valid() # long time
1177
True
1178
"""
1179
E = 'abcdefghi'
1180
CC = {
1181
2: ['abc', 'ceg', 'bfg', 'cdh', 'afh', 'bdi', 'aei', 'ghi'],
1182
3: [E]
1183
}
1184
M = CircuitClosuresMatroid(groundset=E, circuit_closures=CC)
1185
M.rename('NonPappus: ' + repr(M))
1186
return M
1187
1188
1189
def TicTacToe():
1190
"""
1191
Return the TicTacToe matroid.
1192
1193
The dual of the TicTacToe matroid is not algebraic; it is unknown whether
1194
the TicTacToe matroid itself is algebraic. See [Hochstaettler]_.
1195
1196
EXAMPLES::
1197
1198
sage: M = matroids.named_matroids.TicTacToe()
1199
sage: M.is_valid() # long time
1200
True
1201
1202
"""
1203
E = 'abcdefghi'
1204
CC = {
1205
4: ['abcdg', 'adefg', 'abceh', 'abcfi', 'cdefi', 'adghi', 'beghi', 'cfghi'],
1206
5: [E]
1207
}
1208
M = CircuitClosuresMatroid(groundset=E, circuit_closures=CC)
1209
M.rename('TicTacToe: ' + repr(M))
1210
return M
1211
1212
1213
def Q10():
1214
"""
1215
Return the matroid `Q_{10}`, represented over `\GF(4)`.
1216
1217
`Q_{10}` is a 10-element, rank-5, self-dual matroid. It is representable
1218
over `\GF(3)` and `\GF(4)`, and hence is a sixth-roots-of-unity matroid.
1219
`Q_{10}` is a splitter for the class of sixth-root-of-unity matroids.
1220
1221
EXAMPLES::
1222
1223
sage: M = matroids.named_matroids.Q10()
1224
sage: M.is_isomorphic(M.dual())
1225
True
1226
sage: M.is_valid()
1227
True
1228
1229
Check the splitter property. By Seymour's Theorem, and using self-duality,
1230
we only need to check that all 3-connected single-element extensions have
1231
an excluded minor for sixth-roots-of-unity. The only excluded minors that
1232
are quaternary are `U_{2, 5}, U_{3, 5}, F_7, F_7^*`. As it happens, it
1233
suffices to check for `U_{2, 5}`:
1234
1235
sage: S = matroids.named_matroids.Q10().linear_extensions(simple=True)
1236
sage: [M for M in S if not M.has_line_minor(5)] # long time
1237
[]
1238
"""
1239
F = GF(4, 'x')
1240
x = F.gens()[0]
1241
A = Matrix(F, [
1242
[1, 0, 0, 0, 0, 1, x, 0, 0, x + 1],
1243
[0, 1, 0, 0, 0, x + 1, 1, x, 0, 0],
1244
[0, 0, 1, 0, 0, 0, x + 1, 1, x, 0],
1245
[0, 0, 0, 1, 0, 0, 0, x + 1, 1, x],
1246
[0, 0, 0, 0, 1, x, 0, 0, x + 1, 1]
1247
])
1248
M = QuaternaryMatroid(A, 'abcdefghij')
1249
M.rename('Q10: ' + repr(M))
1250
return M
1251
1252
1253
def N1():
1254
"""
1255
Return the matroid `N_1`, represented over `\GF(3)`.
1256
1257
`N_1` is an excluded minor for the dyadic matroids. See [Oxley]_, p. 554.
1258
1259
EXAMPLES::
1260
1261
sage: M = matroids.named_matroids.N1()
1262
sage: M.is_field_isomorphic(M.dual())
1263
True
1264
sage: M.is_valid()
1265
True
1266
1267
"""
1268
A = Matrix(GF(3), [
1269
[1, 0, 0, 0, 0, 2, 0, 0, 1, 1],
1270
[0, 1, 0, 0, 0, 1, 2, 0, 0, 1],
1271
[0, 0, 1, 0, 0, 0, 1, 2, 0, 1],
1272
[0, 0, 0, 1, 0, 0, 0, 1, 2, 2],
1273
[0, 0, 0, 0, 1, 1, 1, 1, 2, 0]
1274
])
1275
M = TernaryMatroid(A, 'abcdefghij')
1276
M.rename('N1: ' + repr(M))
1277
return M
1278
1279
1280
def N2():
1281
"""
1282
Return the matroid `N_2`, represented over `\GF(3)`.
1283
1284
`N_2` is an excluded minor for the dyadic matroids. See [Oxley]_, p. 554.
1285
1286
EXAMPLES::
1287
1288
sage: M = matroids.named_matroids.N2()
1289
sage: M.is_field_isomorphic(M.dual())
1290
True
1291
sage: M.is_valid()
1292
True
1293
1294
"""
1295
A = Matrix(GF(3), [
1296
[1, 0, 0, 0, 0, 0, 2, 0, 0, 1, 1, 1],
1297
[0, 1, 0, 0, 0, 0, 1, 2, 0, 0, 0, 1],
1298
[0, 0, 1, 0, 0, 0, 0, 1, 2, 0, 0, 1],
1299
[0, 0, 0, 1, 0, 0, 0, 0, 1, 2, 1, 0],
1300
[0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1],
1301
[0, 0, 0, 0, 0, 1, 1, 2, 2, 1, 0, 1]
1302
])
1303
return TernaryMatroid(A, 'abcdefghijkl')
1304
M.rename('T12: ' + repr(M))
1305
return M
1306
1307
1308
def BetsyRoss():
1309
"""
1310
Return the Betsy Ross matroid, represented by circuit closures.
1311
1312
An extremal golden-mean matroid.
1313
That is, if `M` is simple, rank 3, has the Betsy Ross matroid as a
1314
restriction and is a Golden Mean matroid, then `M` is the Betsy Ross
1315
matroid.
1316
1317
EXAMPLES::
1318
1319
sage: M = matroids.named_matroids.BetsyRoss()
1320
sage: len(M.circuit_closures()[2])
1321
10
1322
sage: M.is_valid() # long time
1323
True
1324
"""
1325
E = 'abcdefghijk'
1326
CC = {
1327
2: ['acfg', 'bdgh', 'cehi', 'befj', 'adij', 'dfk', 'egk', 'ahk', 'bik', 'cjk'],
1328
3: [E]
1329
}
1330
M = CircuitClosuresMatroid(groundset=E, circuit_closures=CC)
1331
M.rename('BetsyRoss: ' + repr(M))
1332
return M
1333
1334
1335
def Block_9_4():
1336
"""
1337
Return the paving matroid whose non-spanning circuits form the blocks of a
1338
`2-(9, 4, 3)` design.
1339
1340
EXAMPLES::
1341
1342
sage: M = matroids.named_matroids.Block_9_4()
1343
sage: M.is_valid() # long time
1344
True
1345
sage: C = M.nonspanning_circuits()
1346
sage: D = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6,
1347
....: 'h': 7, 'i': 8}
1348
sage: B = [[D[x] for x in L] for L in C]
1349
sage: BlockDesign(9, B).is_block_design()
1350
(True, [2, 9, 4, 3])
1351
"""
1352
E = 'abcdefghi'
1353
CC = {
1354
3: ['abcd', 'acef', 'bdef', 'cdeg', 'abfg', 'adeh', 'bcfh', 'acgh', 'begh', 'dfgh', 'abei', 'cdfi', 'bcgi', 'adgi', 'efgi', 'bdhi', 'cehi', 'afhi'],
1355
4: [E]
1356
}
1357
M = CircuitClosuresMatroid(groundset=E, circuit_closures=CC)
1358
M.rename('Block(9, 4): ' + repr(M))
1359
return M
1360
1361
1362
def Block_10_5():
1363
"""
1364
Return the paving matroid whose non-spanning circuits form the blocks of a
1365
`3-(10, 5, 3)` design.
1366
1367
EXAMPLES::
1368
1369
sage: M = matroids.named_matroids.Block_10_5()
1370
sage: M.is_valid() # long time
1371
True
1372
sage: C = M.nonspanning_circuits()
1373
sage: D = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6,
1374
....: 'h': 7, 'i': 8, 'j': 9}
1375
sage: B = [[D[x] for x in L] for L in C]
1376
sage: BlockDesign(10, B).is_block_design()
1377
(True, [3, 10, 5, 3])
1378
"""
1379
1380
E = 'abcdefghij'
1381
CC = {
1382
4: ['abcde', 'acdfg', 'bdefg', 'bcdfh', 'abefh', 'abcgh', 'adegh', 'cefgh', 'bcefi', 'adefi', 'bcdgi', 'acegi', 'abfgi', 'abdhi', 'cdehi', 'acfhi', 'beghi', 'dfghi', 'abdfj', 'acefj', 'abegj', 'cdegj', 'bcfgj', 'acdhj', 'bcehj', 'defhj', 'bdghj', 'afghj', 'abcij', 'bdeij', 'cdfij', 'adgij', 'efgij', 'aehij', 'bfhij', 'cghij'],
1383
5: [E]
1384
}
1385
M = CircuitClosuresMatroid(groundset=E, circuit_closures=CC)
1386
M.rename('Block(10, 5): ' + repr(M))
1387
return M
1388
1389
1390
def ExtendedBinaryGolayCode():
1391
"""
1392
Return the matroid of the extended binary Golay code.
1393
1394
See
1395
:func:`ExtendedBinaryGolayCode <sage.coding.code_constructions.ExtendedBinaryGolayCode>`
1396
documentation for more on this code.
1397
1398
EXAMPLES::
1399
1400
sage: M = matroids.named_matroids.ExtendedBinaryGolayCode()
1401
sage: C = LinearCode(M.representation())
1402
sage: C.is_permutation_equivalent(codes.ExtendedBinaryGolayCode()) # long time
1403
True
1404
sage: M.is_valid()
1405
True
1406
"""
1407
A = Matrix(GF(2), [
1408
[1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0],
1409
[1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1],
1410
[1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0],
1411
[1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0],
1412
[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0],
1413
[1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1],
1414
[1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1],
1415
[1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1],
1416
[1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0],
1417
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1],
1418
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1],
1419
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
1420
])
1421
M = BinaryMatroid(A, 'abcdefghijklmnopqrstuvwx')
1422
M.rename('Extended Binary Golay Code: ' + repr(M))
1423
return M
1424
1425
1426
def ExtendedTernaryGolayCode():
1427
"""
1428
Return the matroid of the extended ternary Golay code.
1429
1430
See
1431
:func:`ExtendedTernaryGolayCode <sage.coding.code_constructions.ExtendedTernaryGolayCode>`
1432
documentation for more on this code.
1433
1434
EXAMPLES::
1435
1436
sage: M = matroids.named_matroids.ExtendedTernaryGolayCode()
1437
sage: C = LinearCode(M.representation())
1438
sage: C.is_permutation_equivalent(codes.ExtendedTernaryGolayCode()) # long time
1439
True
1440
sage: M.is_valid()
1441
True
1442
"""
1443
A = Matrix(GF(3), [
1444
[1, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 0],
1445
[0, 1, 0, 0, 0, 0, 1, 1, 2, 1, 0, 2],
1446
[0, 0, 1, 0, 0, 0, 1, 2, 1, 0, 1, 2],
1447
[0, 0, 0, 1, 0, 0, 1, 2, 0, 1, 2, 1],
1448
[0, 0, 0, 0, 1, 0, 1, 0, 2, 2, 1, 1],
1449
[0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1]
1450
])
1451
M = TernaryMatroid(A, 'abcdefghijkl')
1452
M.rename('Extended Ternary Golay Code: ' + repr(M))
1453
return M
1454
1455
1456
def AG23minus():
1457
"""
1458
Return the ternary affine plane minus a point.
1459
1460
This is a sixth-roots-of-unity matroid, and an excluded minor for the
1461
class of near-regular matroids.
1462
See [Oxley]_, p. 653.
1463
1464
EXAMPLES::
1465
1466
sage: M = matroids.named_matroids.AG23minus()
1467
sage: M.is_valid()
1468
True
1469
1470
"""
1471
E = 'abcdefgh'
1472
CC = {2: ['abc', 'ceh', 'fgh', 'adf', 'aeg', 'cdg', 'bdh', 'bef'],
1473
3: [E]}
1474
M = CircuitClosuresMatroid(groundset=E, circuit_closures=CC)
1475
M.rename('AG23minus: ' + repr(M))
1476
return M
1477
1478
1479
def NotP8():
1480
"""
1481
Return the matroid ``NotP8``.
1482
1483
This is a matroid that is not `P_8`, found on page 512 of [Oxley1]_ (the
1484
first edition).
1485
1486
EXAMPLES::
1487
1488
sage: M = matroids.named_matroids.P8()
1489
sage: N = matroids.named_matroids.NotP8()
1490
sage: M.is_isomorphic(N)
1491
False
1492
sage: M.is_valid()
1493
True
1494
"""
1495
A = Matrix(GF(3), [
1496
[1, 0, 0, 0, 0, 1, 1, -1],
1497
[0, 1, 0, 0, 1, 0, 1, 1],
1498
[0, 0, 1, 0, 1, 1, 0, 1],
1499
[0, 0, 0, 1, -1, 1, 1, 1]
1500
])
1501
M = TernaryMatroid(A, 'abcdefgh')
1502
M.rename('NotP8: ' + repr(M))
1503
return M
1504
1505
1506
def D16(): # A.K.A. the Carolyn Chun Matroid
1507
"""
1508
Return the matroid `D_{16}`.
1509
1510
Let `M` be a 4-connected binary matroid and `N` an internally 4-connected
1511
proper minor of `M` with at least 7 elements. Then some element of `M` can
1512
be deleted or contracted preserving an `N`-minor, unless `M` is `D_{16}`.
1513
See [CMO12]_.
1514
1515
EXAMPLES::
1516
1517
sage: M = matroids.named_matroids.D16()
1518
sage: M
1519
D16: Binary matroid of rank 8 on 16 elements, type (0, 0)
1520
sage: M.is_valid()
1521
True
1522
1523
"""
1524
A = Matrix(GF(2), [
1525
[1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0],
1526
[0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1],
1527
[0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1],
1528
[0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1],
1529
[0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0],
1530
[0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0],
1531
[0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0],
1532
[0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0]
1533
])
1534
M = BinaryMatroid(A, 'abcdefghijklmnop')
1535
M.rename('D16: ' + repr(M))
1536
return M
1537
1538
1539
def Terrahawk(): # A.K.A. the Dillon Mayhew Matroid
1540
"""
1541
Return the Terrahawk matroid.
1542
1543
The Terrahawk is a binary matroid that is a sporadic exception in a chain
1544
theorem for internally 4-connected binary matroids. See [CMO11]_.
1545
1546
EXAMPLES::
1547
1548
sage: M = matroids.named_matroids.Terrahawk()
1549
sage: M
1550
Terrahawk: Binary matroid of rank 8 on 16 elements, type (0, 4)
1551
sage: M.is_valid()
1552
True
1553
1554
"""
1555
A = Matrix(GF(2), [
1556
[1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
1557
[1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0],
1558
[0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
1559
[0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0],
1560
[0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0],
1561
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1],
1562
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0],
1563
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0]
1564
])
1565
M = BinaryMatroid(A, 'abcdefghijklmnop')
1566
M.rename('Terrahawk: ' + repr(M))
1567
return M
1568
1569
1570
def R9A():
1571
"""
1572
Return the matroid `R_9^A`.
1573
1574
The matroid `R_9^A` is not representable over any field, yet none of the
1575
cross-ratios in its Tuttegroup equal 1. It is one of the 4 matroids on at
1576
most 9 elements with this property, the others being `{R_9^A}^*`, `R_9^B`
1577
and `{R_9^B}^*`.
1578
1579
EXAMPLES::
1580
1581
sage: M = matroids.named_matroids.R9A()
1582
sage: M.is_valid() # long time
1583
True
1584
1585
"""
1586
E = 'abcdefghi'
1587
CC = {3: ['abde', 'bcdf', 'aceg', 'abch', 'aefh', 'adgh', 'acdi', 'abfi', 'defi', 'begi', 'bdhi', 'cehi', 'fghi'],
1588
4: [E]}
1589
M = CircuitClosuresMatroid(groundset=E, circuit_closures=CC)
1590
M.rename('R9A: ' + repr(M))
1591
return M
1592
1593
1594
def R9B():
1595
"""
1596
Return the matroid `R_9^B`.
1597
1598
The matroid `R_9^B` is not representable over any field, yet none of the
1599
cross-ratios in its Tuttegroup equal 1.
1600
It is one of the 4 matroids on at most 9 elements with this property, the
1601
others being `{R_9^B}^*`, `R_9^A` and `{R_9^A}^*`.
1602
1603
EXAMPLES::
1604
1605
sage: M = matroids.named_matroids.R9B()
1606
sage: M.is_valid() # long time
1607
True
1608
1609
"""
1610
E = 'abcdefghi'
1611
CC = {3: ['abde', 'bcdf', 'aceg', 'abch', 'befh', 'cdgh', 'bcei', 'adfi', 'abgi', 'degi', 'bdhi', 'aehi', 'fghi'],
1612
4: [E]}
1613
M = CircuitClosuresMatroid(groundset=E, circuit_closures=CC)
1614
M.rename('R9B: ' + repr(M))
1615
return M
1616
1617
1618
def T12():
1619
"""
1620
Return the matroid `T_{12}`.
1621
1622
The edges of the Petersen graph can be labeled by the 4-circuits of
1623
`T_{12}` so that two edges are adjacent if and only if the corresponding
1624
4-circuits overlap in exactly two elements.
1625
Relaxing a circuit-hyperplane yields an excluded minor for the class of
1626
matroids that are either binary or ternary. See [Oxley]_, p. 658.
1627
1628
EXAMPLES::
1629
1630
sage: M = matroids.named_matroids.T12()
1631
sage: M
1632
T12: Binary matroid of rank 6 on 12 elements, type (2, None)
1633
sage: M.is_valid()
1634
True
1635
"""
1636
A = Matrix(GF(2), [
1637
[1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
1638
[0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1],
1639
[0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0],
1640
[0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0],
1641
[0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0],
1642
[0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1]
1643
])
1644
M = BinaryMatroid(A, 'abcdefghijkl')
1645
M.rename('T12: ' + repr(M))
1646
return M
1647
1648
1649
def P9():
1650
"""
1651
Return the matroid `P_9`.
1652
1653
This is the matroid referred to as `P_9` by Oxley in his paper "The binary
1654
matroids with no 4-wheel minor"
1655
1656
EXAMPLES::
1657
1658
sage: M = matroids.named_matroids.P9()
1659
sage: M
1660
P9: Binary matroid of rank 4 on 9 elements, type (1, 1)
1661
sage: M.is_valid()
1662
True
1663
"""
1664
A = Matrix(GF(2), [
1665
[1, 0, 0, 0, 1, 0, 0, 1, 1],
1666
[0, 1, 0, 0, 1, 1, 0, 0, 1],
1667
[0, 0, 1, 0, 0, 1, 1, 0, 1],
1668
[0, 0, 0, 1, 0, 0, 1, 1, 0]
1669
])
1670
M = BinaryMatroid(A, 'abcdefghi')
1671
M.rename('P9: ' + repr(M))
1672
return M
1673
1674