-
Notifications
You must be signed in to change notification settings - Fork 0
/
MatroidActivities.m2
4105 lines (3893 loc) · 145 KB
/
MatroidActivities.m2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{*
-*- coding: utf-8 -*-
MatroidActivities.m2
Copyright (C) 2016-2018 Aaron Dall <aaronmdall@gmail.com>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This program is free software; you can redistribute it
and/or modify it under the terms of the GNU General
Public License as published by the Free Software Found-
ation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General
Public License along with this program; if not, write
to the Free Software Foundation, Inc., 59 Temple Place,
Suite 330, Boston, MA 02111-1307 USA.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*}
{*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Release 0.2.1 (2018 02)
NEW:
BUGS FIXED:
Made compatible with Matroids package version 0.9.4
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Release 0.2 (2017 03)
NEW:
Methods for constructing a matroid from an ideal, simplicial
complex, or central arrangement;
Methods for constructing the face ring, Chow ring, and
Orlik-Solomon algebra of a matroid or ordered matroid;
Test if a matroid is simple, binary, ternary, (co)graphic,
regular, or paving;
Split the TikZ rendering of active orders into two methods for
improved rendering.
BUGS FIXED:
Fixed a list bug in the internalOrder code which was causing a
problem with the isInternallyPerfect method;
Fixed a TikZ rendering problem when trying to tex active orders on
matroids with more than 9 elements.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Release 0.1 (2016 07 24)
NEW: the class OrderedMatroid and methods bjornersPartition,
matroidHVector, externalOrder, internalOrder, isInternallyPerfect,
texActiveOrder
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*}
newPackage (
"MatroidActivities",
Version => "0.2",
Date => "2017 03 01",
Authors => {{
Name => "Aaron Dall",
Email => "aaronmdall -at- gmail.com",
HomePage => "https://github.com/aarondall/MatroidActivities-M2"}},
PackageImports => {
"Matroids",
"HyperplaneArrangements",
"Posets",
"SimplicialComplexes",
"Depth"
},
PackageExports => {
"HyperplaneArrangements",
"Matroids",
"Posets"
},
Headline => "MatroidActivities",
DebuggingMode => false
)
export {
-- INTERNAL FUNCTIONS --
--"relativeOrder",
--"monomialToList",
--"listToTexString",
-- ORDERED MATROID FUNCTIONALITY --
"OrderedMatroid",
"orderedMatroid",
"orderedBases",
"orderedCircuits",
"orderedCocircuits",
"orderedGround",
"orderedFlats",
"activeElements",
"duallyActiveElements",
"externallyActiveElements",
"externallyPassiveElements",
"internallyActiveElements",
"internallyPassiveElements",
"externalOrder",
"ShowExt",
"internalOrder",
"minimalBasis",
"internalBasisDecomposition",
"basisType",
"bjornersPartition",
"matroidOrlikSolomon",
"brokenCircuitComplex",
"texExternalOrder",
"texInternalOrder",
"isActive",
"isDuallyActive",
"isInternallyPerfect",
"IsInternallyPerfect",
-- MATROID FUNCTIONALITY --
"CircuitIdeal",
"IndependenceComplex",
"Presentations",
--"latticeOfFlats",
-- "Reduced",
"LatticeOfFlats",
"parallelClasses",
"matroidIndependenceComplex",
"ComputePoset",
"complexAsPoset",
"matroidTuttePolynomial",
"matroidHPolynomial",
"matroidFVector",
"betaInvariant",
"matroidChowIdeal",
"matroidChowRing",
"matroidCharacteristicPolynomial",
-- Tests --
"isBinaryMatroid",
"IsBinaryMatroid",
"isCographicMatroid",
"IsCographicMatroid",
"isGraphicMatroid",
"IsGraphicMatroid",
"isPavingMatroid",
"IsPavingMatroid",
"isRegularMatroid",
"IsRegularMatroid",
"isRepresentableMatroid",
"IsRepresentableMatroid",
"isSimpleMatroid",
"IsSimpleMatroid",
"isTernaryMatroid",
"IsTernaryMatroid",
-- GRAPH FUNCTIONALITY --
"signedIncidenceMatrix",
"FullRank",
-- SIMPLICIAL COMPLEX FUNCTIONALITY
"isMatroidIndependenceComplex"
}
hasAttribute = value Core#"private dictionary"#"hasAttribute"
getAttribute = value Core#"private dictionary"#"getAttribute"
ReverseDictionary = value Core#"private dictionary"#"ReverseDictionary"
-- INTERNAL METHODS --
-- A method for ordering sets and (lists of) lists with respect to a given list
-- Elements in the intersection come first with order induced from L
-- Elements in A not in L come later with the order induced by sort
relativeOrder = method(TypicalValue => List)
-- For a set S, assumes all elements are single elements all belonging to the
-- same class having some method for comparison (see: viewHelp "?")
relativeOrder (Set, List) := (S, L) -> (
if S === set {} then toList {} else
SL := select(L, l -> member(l,S));
B := if SL === null then {} else SL;
notSL := select(toList S, s -> not member(s,L));
C := if notSL === null then {} else notSL;
B | sort C)
-- For a list L1, assumes each element is a VisibleList consisting of elements
-- that are also visible lists such that all elements of flatten L1 are of
-- the type ZZ
relativeOrder (List, List) := (L1,L2) -> (
-- First convert all elements of L1 into Lists sorted by sort.
M1 := apply (L1, l -> sort toList l);
-- Next order all the elements appearing in the union of M1 according
-- to L2.
M2 := relativeOrder (set unique flatten M1, L2);
orderEach := apply (
M1,
l -> (
n := #l;
rel := relativeOrder (set l, M2);
{apply (n, i -> position (M2, e -> e == rel#i)),
rel}
)
);
apply(sort orderEach, l -> l#1))
-- Compute the signed incidence matrix of a graph G.
-- This matrix represents the matroid of G over any field, is fast to produce
-- (K60 takes about a second), and allows for easily adding edges with
-- multiplicities.
signedIncidenceMatrix = method (
TypicalValue => Matrix,
Options => {FullRank => true})
signedIncidenceMatrix Graph := Matrix => opts -> G -> (
M := matrix table (
vertexSet G, --
apply(edges G, e -> sort toList e),
(v,e) -> if not member(v,e)
then 0
else if v == first e then 1 else -1);
if not opts.FullRank then M else submatrix' (M, {numRows M -1}, {}))
-- ' kill the apostrophe
-- Convert a monomial in a polynomial ring to its support given as a list of
-- indices of variables. Used in converting a simplicial complex to a matroid
-- if the complex is a matroid complex.
monomialToList = method(TypicalValue => List)
monomialToList RingElement := m -> (
R := ring m;
apply(support m, var -> index var)
)
-- Internal methods for converting between strings and lists.
-- Used to beautify tex output of posets
listToTexString = L -> concatenate apply (
L, l -> (
if class l =!= ZZ
then toString l
else if l < 10
then toString l
else concatenate("\\underline{", toString l, "}")))
-- ORDERED MATROID FUNCTIONALITY --
-- Setting up the OrderedMatroid Type
OrderedMatroid = new Type of HashTable
OrderedMatroid.synonym = "ordered matroid"
-- set output for OrderedMatroid
globalAssignment OrderedMatroid
net OrderedMatroid := X -> (
net ofClass class X | " of rank " | toString(X.matroid.rank) | " on " | toString(#X.orderedGround) | " elements"
)
-- OrderedMatroid equality
OrderedMatroid == OrderedMatroid := (M, N) -> (
areIsomorphic (M.matroid, N.matroid) and
all(M.orderedGround, N.orderedGround, (i,j) -> rank_(M.matroid) {i,j}==1)
)
-- Make an ordered matroid from an ordered subset of the
-- ground set
orderedMatroid = method(TypicalValue => OrderedMatroid)
orderedMatroid (Matroid, List) := (M,L) -> (
r := rank M;
E := relativeOrder(M.groundSet, L);
n := #E;
B := relativeOrder(M.bases, E);
Ci := relativeOrder(Matroids$circuits M, E);
Coci := relativeOrder(Matroids$circuits dual M, E);
OM := new OrderedMatroid from {
symbol matroid => M,
symbol orderedGround => E,
symbol orderedBases => B,
symbol orderedCircuits => Ci,
symbol orderedCocircuits => Coci,
symbol Presentations => new CacheTable,
cache => new CacheTable
};
OM
)
orderedMatroid (Matroid) := M -> (orderedMatroid (M, {}))
orderedMatroid (Matrix, List) := (M, L) -> (
OM := orderedMatroid (matroid M, L);
OM.Presentations.Matrix = M_L;
OM.cache.isRepresentableMatroid =
if isField ring M
then true
else "Unknown. Matrix over a ring that is not a field.";
OM)
orderedMatroid (Matrix) := M -> orderedMatroid (M, toList(0..<numColumns M))
orderedMatroid (Graph, List) := (G, L) -> (
N := signedIncidenceMatrix G;
OM := orderedMatroid (N, L);
OM.Presentations.Graph = G;
OM.cache.isGraphicMatroid = true;
OM.cache.isRepresentableMatroid = true;
OM.cache.isRegular = true;
OM)
orderedMatroid (Graph) := G -> orderedMatroid (G, toList(0..<# edges G))
orderedMatroid (CentralArrangement, List) := (A, L) -> (
R := coefficientRing ring A;
S := if isField R then R
else if R == ZZ then QQ
else error "expected a field or ZZ";
M := sub(coefficients A, S);
OM := orderedMatroid (M, L);
OM.Presentations.CentralArrangement = A;
OM.Presentations.Matrix = M;
OM.cache.isRepresentableMatroid = true;
OM)
orderedMatroid (CentralArrangement) := A -> (
orderedMatroid (A, toList(0..<numColumns coefficients A)))
orderedMatroid (SimplicialComplex, List) := (C, L) -> (
if not SimplicialComplexes$isPure C then error "Complex is not matroidal (not pure)" else
F := flatten entries SimplicialComplexes$facets C;
B := apply (F, m -> monomialToList m);
M := matroid B;
if not isWellDefined M
then error "Complex is not matroidal (basis exchange axiom not satisfied)"
else
OM := orderedMatroid (M, L);
OM.Presentations.IndependenceComplex = C;
OM
)
orderedMatroid (SimplicialComplex) := C -> (orderedMatroid (C, {}))
orderedMatroid (Ideal, List) := (I, L) -> (
if I =!= monomialIdeal I
then error "Expected a monomial ideal; try monomialIdeal (I) or monomialSubideal (I)"
else if not isSquareFree I
then error "Expected a square free ideal; try radical I"
else
OM := orderedMatroid (simplicialComplex I, L);
if instance (OM, OrderedMatroid)
then OM.Presentations.CircuitIdeal = I;
OM)
orderedMatroid (Ideal) := I -> orderedMatroid (I,{})
-- ORDERED ANALOGUES OF MATROIDAL OBJECTS NOT YET CONSTRUCTED
-- Must convert a matroid, matrix, graph, etc to an ordered matroid first
orderedFlats = method(TypicalValue => List)
orderedFlats OrderedMatroid := M -> (
apply(
Matroids$flats (M.matroid),
F -> relativeOrder(F, M.orderedGround))
)
-- MATROID ACTIVITIES
-- Test if an element of an ordered matroid is active with respect to a set --
isActive = method(TypicalValue => Boolean)
isActive (OrderedMatroid, List, ZZ) := (M, A, e) -> (
any (M.orderedCircuits, c -> e == first c and isSubset(c, append(A,e))))
-- Test if an element of an ordered matroid is active in the dual
-- matroid with respect to a set
isDuallyActive = method(TypicalValue => Boolean)
isDuallyActive (OrderedMatroid, List, ZZ) := (M, A, e) -> (
any (
M.orderedCocircuits,
c -> e == first c and isSubset (
c,
append(select(M.orderedGround, f -> not member(f,A)),e)
)
)
)
activeElements = method(TypicalValue=>List)
activeElements (OrderedMatroid, List) := List => (M, A) -> (
if not isSubset(A, M.orderedGround)
then error "expected a subset of the ground set"
else
select(M.orderedGround, e -> isActive(M, A, e)))
duallyActiveElements = method(TypicalValue=>List)
duallyActiveElements (OrderedMatroid, List) := List => (M, A) -> (
if not isSubset(A, M.orderedGround)
then error "expected a subset of the ground set"
else
select(M.orderedGround, e -> isDuallyActive(M, A, e)))
externallyActiveElements = method(TypicalValue => List)
externallyActiveElements (OrderedMatroid, List) := List => (M,A) ->(
relativeOrder (set activeElements(M,A) - set A, M.orderedGround))
externallyPassiveElements = method(TypicalValue => List)
externallyPassiveElements (OrderedMatroid, List) := List => (M,A) -> (
relativeOrder ((set M.orderedGround - set activeElements(M,A)) - set A, M.orderedGround))
internallyActiveElements = method (TypicalValue => List)
internallyActiveElements (OrderedMatroid, List) := List => (M,A) -> (
relativeOrder (set A * set duallyActiveElements(M,A), M.orderedGround)
)
internallyPassiveElements = method (TypicalValue => List)
internallyPassiveElements (OrderedMatroid, List) := List => (M,A) ->(
relativeOrder (set A - set internallyActiveElements(M,A),M.orderedGround))
externalOrder = method (
TypicalValue => Poset,
Options => {symbol ShowExt => false})
externalOrder OrderedMatroid := Poset => opts -> M -> (
h := hashTable apply(M.orderedBases, b -> b => externallyActiveElements(M,b));
cmp := (a,b) -> isSubset(a#0, join(b#0,h#(b#0)));
cmp1 := (a,b) -> isSubset(a, join(b,h#(b)));
if opts.ShowExt == true
then poset (apply(M.orderedBases, b-> {b,h#(b)}),cmp)
else poset (M.orderedBases,cmp1))
internalOrder = method(TypicalValue => Poset)
internalOrder OrderedMatroid := Poset => M -> (
h1 := hashTable apply(M.orderedBases, b -> b => internallyPassiveElements(M,b));
cmp := (a,b) -> (
isSubset(
h1#(relativeOrder (set flatten a, M.orderedGround)),
h1#(relativeOrder (set flatten b,M.orderedGround)))
);
poset(apply(M.orderedBases, b -> internalBasisDecomposition(M,b)), cmp))
--compute the minimal basis containing an independent set
minimalBasis = method(TypicalValue => List)
minimalBasis (OrderedMatroid, List) := List => (M, I) -> (
p := (position(M.orderedBases, b -> isSubset(I, b)));
if class p === ZZ then (M.orderedBases)#p else error "expected an independent set")
internalBasisDecomposition = method(TypicalValue => List)
internalBasisDecomposition (OrderedMatroid, List) := List => (M, b) -> (
B0 := first M.orderedBases;
IA := internallyActiveElements (M, b);
IP := internallyPassiveElements (M, b);
S := relativeOrder (set IP - set B0, M.orderedGround);
T := relativeOrder (set IP - S, M.orderedGround);
{S,T,IA})
basisType = method()
basisType (OrderedMatroid,List) := (M,b) -> (
(S,T,A):= toSequence internalBasisDecomposition(M,b);
-- make the multiset of provisionally passive elements
projections := flatten for f in S list (
newBs := minimalBasis(M, append(T,f));
(internalBasisDecomposition(M,newBs))#1);
-- check if the multiset is a disjoint union and covers T
if sort projections == sort T
then "perfect"
-- check if the multiset covers T
else if sort unique projections == sort T
then "abundant"
else "deficient"
)
isInternallyPerfect = method(TypicalValue => Boolean)
isInternallyPerfect (OrderedMatroid) := Boolean => (M) -> (
if M.cache.?IsInternallyPerfect then M.cache.IsInternallyPerfect else
topElements := apply(maximalElements internalOrder M, b -> flatten b);
check := b -> basisType(M,flatten b) == "perfect";
Bool := all(topElements, check);
M.cache.IsInternallyPerfect = Bool;
Bool
)
-- Test if any permutation makes a matroid into an internally perfect matroid
isInternallyPerfect Matroid := Boolean => M -> (
B := sort apply (M.bases, b -> sort toList b);
checkPermsOfBasis := b -> (
P := permutations toList b;
k := position(P, p-> isInternallyPerfect orderedMatroid (M, p));
if class k === ZZ then P#k else null
);
j := (position(B, b -> checkPermsOfBasis b =!= null));
if class j === ZZ then (print checkPermsOfBasis (B)#j);
return class j === ZZ
)
bjornersPartition = method(TypicalValue => List)
bjornersPartition OrderedMatroid := List => M -> (
n := #M.orderedGround;
B := booleanLattice n;
--convert
labels := apply(B.GroundSet, s ->
s => M.orderedGround_(select(toList(0..<n), i -> s#i == toString 1))
);
labeledB:=labelPoset(B, new HashTable from labels);
apply(M.orderedBases, b -> (
bInterval := closedInterval (
labeledB,
internallyPassiveElements(M,b),
relativeOrder(set join(b, externallyActiveElements (M,b)), M.orderedGround));
[flatten minimalElements bInterval, flatten maximalElements bInterval]))
)
-- ADDITIONAL UNORDERED MATROID FUNCTIONALITY --
-- Properties independent of the ordering of a matroid stored in
-- OM.matroid.cache
isSimpleMatroid = method (TypicalValue => Boolean)
isSimpleMatroid Matroid := M -> (
if M.cache.?IsSimpleMatroid
then return M.cache.IsSimpleMatroid
else
check := # loops M == 0 and all (Matroids$flats (M, 1), f -> #f == 1);
M.cache.IsSimpleMatroid = check;
check)
isSimpleMatroid OrderedMatroid := M -> (
isSimpleMatroid M.matroid)
------------------------------------------
-- matroid classes
------------------------------------------
-- Internal hash of forbidden minors for certain classes of matroids
-- Extend this as much as possible
ForbiddenMinors = new HashTable from {
"binaryMatroids" => {uniformMatroid(2,4)},
"ternaryMatroids" => {
uniformMatroid(2,5),
uniformMatroid(3,5),
specificMatroids "fano",
dual specificMatroids "fano"},
"graphicMatroids" => {
uniformMatroid(2,4),
specificMatroids "fano",
dual specificMatroids "fano",
dual matroid completeGraph 5,
dual matroid completeMultipartiteGraph {3,3}},
"cographicMatroids" => {
uniformMatroid(2,4),
specificMatroids "fano",
dual specificMatroids "fano",
matroid completeGraph 5,
matroid completeMultipartiteGraph {3,3}},
"regularMatroids" => {
uniformMatroid(2,4),
specificMatroids "fano",
dual specificMatroids "fano"}
}
isBinaryMatroid = method(TypicalValue => Boolean)
isBinaryMatroid Matroid := M -> (
if M.cache.?IsBinaryMatroid
then return M.cache.IsBinaryMatroid
else
check := not any (
ForbiddenMinors#"binaryMatroids",
N -> hasMinor (M,N));
M.cache.IsBinaryMatroid = check;
if check == true then
M.cache.IsRepresentableMatroid = check;
check)
isBinaryMatroid OrderedMatroid := M -> (
isBinaryMatroid M.matroid)
isTernaryMatroid = method(TypicalValue => Boolean)
isTernaryMatroid Matroid := M -> (
if M.cache.?IsTernaryMatroid
then return M.cache.IsTernaryMatroid
else
check := not any(ForbiddenMinors#"ternaryMatroids", N -> hasMinor(M,N));
M.cache.IsTernaryMatroid = check;
if check then
M.cache.IsRepresentableMatroid = check;
check)
isTernaryMatroid OrderedMatroid := M -> (
isTernaryMatroid M.matroid)
isGraphicMatroid = method(TypicalValue => Boolean)
isGraphicMatroid Matroid := M -> (
if M.cache.?IsGraphicMatroid
then return M.cache.IsGraphicMatroid
else
check := not any(ForbiddenMinors#"graphicMatroids", N -> hasMinor(M,N));
M.cache.IsGraphicMatroid = check;
if check then (
M.cache.IsRepresentableMatroid = true,
M.cache.IsRegularMatroid = true);
check)
isGraphicMatroid OrderedMatroid := M -> (
isGraphicMatroid M.matroid)
isCographicMatroid = method(TypicalValue => Boolean)
isCographicMatroid Matroid := M -> (
if M.cache.?IsCographicMatroid
then return M.cache.IsCographicMatroid
else
check := not any(
ForbiddenMinors#"cographicMatroids",
N -> hasMinor(M,N));
M.cache.IsCographicMatroid = check;
if check then (
M.cache.IsRepresentableMatroid = check,
M.cache.IsRegularMatroid = check);
check)
isCographicMatroid OrderedMatroid := M -> (
isCographicMatroid M.matroid)
isRegularMatroid = method(TypicalValue => Boolean)
isRegularMatroid Matroid := M -> (
if M.cache.?IsRegularMatroid
then return M.cache.IsRegularMatroid else
check := not any(
ForbiddenMinors#"regularMatroids",
N -> hasMinor(M,N));
M.cache.IsRegularMatroid = check;
if check then (
M.cache.IsRepresentableMatroid = check,
M.cache.IsBinaryMatroid = check,
M.cache.IsTernaryMatroid = check);
check)
isRegularMatroid OrderedMatroid := M -> (
isRegularMatroid M.matroid)
isRepresentableMatroid = method (TypicalValue => Boolean)
isRepresentableMatroid Matroid := M -> (
if M.cache.?IsRepresentableMatroid
then return M.cache.IsRepresentableMatroid
else
try areIsomorphic (M, matroid matrix {M.groundSet})
then (
check := areIsomorphic (M, matroid matrix {M.groundSet});
if check == true
then (
M.cache.IsRepresentableMatroid = true;
return check)
else print "Unknown. Try isBinaryMatroid, isTernaryMatroid, etc.";)
else print "Unknown. Try isBinaryMatroid, isTernaryMatroid, etc.";
)
isRepresentableMatroid OrderedMatroid := M -> (
isRepresentableMatroid M.matroid)
isPavingMatroid = method(TypicalValue => Boolean)
isPavingMatroid Matroid := M -> (
if M.cache.?IsPavingMatroid
then return M.cache.IsPavingMatroid
else
r := rank M;
check := all(
Matroids$circuits M,
c -> member (#c, {r, r+1}));
M.cache.IsPavingMatroid = check;
check)
isPavingMatroid OrderedMatroid := M -> (
isPavingMatroid M.matroid
)
latticeOfFlats OrderedMatroid := M -> latticeOfFlats (M.matroid)
parallelClasses = method(TypicalValue => List)
parallelClasses Matroid := M -> (
select(flatten Matroids$flats M, f -> rank_M f == 1))
parallelClasses OrderedMatroid := OM -> (
select(flatten orderedFlats OM, f -> rank_(OM.matroid) f == 1))
matroidIndependenceComplex = method (
TypicalValue => SimplicialComplex,
Options => {symbol ComputePoset => false})
matroidIndependenceComplex (Matroid, Ring) := SimplicialComplex => opts -> (M, R) -> (
if M.cache.?IndependenceComplex
then return M.cache.IndependenceComplex
else
E := toList M.groundSet;
B := sort apply (M.bases, b -> sort toList b);
x := getSymbol "x";
S := R (
monoid [apply (E, e -> x_e),
Weights => toList(0..<#E)]);
monomialsFromBases := apply(
B, b -> product apply(b, e -> S_e));
C := simplicialComplex monomialsFromBases;
M.cache.CircuitIdeal = C.faceIdeal;
M.cache.IndependenceComplex = C;
if not opts.ComputePoset then C else
M.cache.complexAsPoset = poset (
unique flatten apply (B, b -> subsets b),
isSubset);
C)
matroidIndependenceComplex Matroid := SimplicialComplex => opts -> M -> (
matroidIndependenceComplex (M, QQ, ComputePoset => opts.ComputePoset))
matroidIndependenceComplex (OrderedMatroid, Ring) := SimplicialComplex => opts -> (M,R) -> (
E := M.orderedGround;
B := M.orderedBases;
x := getSymbol "x";
S := R (
monoid[apply(E, e -> x_e),
Weights => toList(0..<#E)]);
monomialsFromBases := apply(B, b -> product apply(b, e -> S_e));
C := simplicialComplex monomialsFromBases;
M.Presentations.CircuitIdeal = C.faceIdeal;
M.Presentations.IndependenceComplex = C;
if opts.ComputePoset == false then C else
M.Presentations.complexAsPoset = poset (
unique flatten apply (B, b -> subsets b),
isSubset);
C)
matroidIndependenceComplex OrderedMatroid := SimplicialComplex => opts -> M -> (
matroidIndependenceComplex (M,QQ, ComputePoset => opts.ComputePoset))
isMatroidIndependenceComplex = method (TypicalValue => Boolean)
isMatroidIndependenceComplex SimplicialComplex := C -> (
if not SimplicialComplexes$isPure C then (
print "Complex is not matroidal (not pure)";
return false;)
else
F := flatten entries SimplicialComplexes$facets C;
B := apply (F, m -> monomialToList m);
M := matroid B;
if not isWellDefined M then (
print ("Complex is not matroidal (basis exchange axiom not satisfied)");
return false;)
else true)
--circuitIdeal = method (TypicalValue => MonomialIdeal)
--circuitIdeal (Matroid, Ring) := (M, R) -> (
-- if M.cache.?CircuitIdeal then M.cache.CircuitIdeal
-- else
-- )
matroidTuttePolynomial = method(TypicalValue => RingElement)
matroidTuttePolynomial OrderedMatroid := M -> (
R := ZZ(monoid[getSymbol "x", getSymbol "y"]);
sum apply(
M.orderedBases,
b -> R_0^(#internallyActiveElements(M,b))
* R_1^(#externallyActiveElements(M,b)))
)
matroidTuttePolynomial Matroid := M -> matroidTuttePolynomial orderedMatroid M
matroidHPolynomial = method(TypicalValue => RingElement)
matroidHPolynomial Matroid := M -> (
h := numerator reduceHilbert hilbertSeries (matroidIndependenceComplex M).faceIdeal;
R := ZZ(monoid[getSymbol "T", getSymbol "q"]);
S := ZZ(monoid[getSymbol "q"]);
sub(sub(sub(h,R), R_0 => R_1),S)
)
matroidHPolynomial OrderedMatroid := M -> (
matroidHPolynomial M.matroid)
matroidFVector = method (TypicalValue => HashTable)
matroidFVector Matroid := M -> (
SimplicialComplexes$fVector matroidIndependenceComplex M)
matroidFVector OrderedMatroid := M -> (matroidFVector M.matroid)
betaInvariant = method (TypicalValue => ZZ)
betaInvariant Matroid := M -> (
r := rank M;
E := M.groundSet;
(-1)^r * sum for s in subsets E list (
(-1)^(#s)*rank(M,s))
)
betaInvariant OrderedMatroid := M -> betaInvariant M.matroid
matroidChowIdeal = method (TypicalValue => Ideal)
matroidChowIdeal (Matroid, Ring) := Ideal => (M, R) -> (
E := toList M.groundSet;
P := latticeOfFlats M;
S := R (monoid [apply (P.GroundSet, f -> (getSymbol "x")_f)]);
I := ideal unique flatten table (
P.GroundSet,
P.GroundSet,
(f, g) -> if compare (P, f, g)
then 0_S
else S_((value "x")_f) * S_((value "x")_g)
);
h := hashTable apply (E, e -> e => delete (
null,
apply (P.GroundSet, f -> if member (e, f) then f else null)
)
);
J := ideal unique flatten table (
E,
E,
(a,b) -> sum apply (h#a, f -> S_((value "x")_f)) - sum (h#b, f-> S_((value "x")_f))
);
I + J)
matroidChowIdeal Matroid := Ideal => M -> (
matroidChowIdeal (M, QQ))
matroidChowRing = method (TypicalValue => QuotientRing)
matroidChowRing (Matroid, Ring) := QuotientRing => (M, R) -> (
I := matroidChowIdeal (M, R);
ring I / I
)
matroidChowRing Matroid := QuotientRing => M -> (
I := matroidChowIdeal M;
ring I / I
)
matroidOrlikSolomon = method (TypicalValue => QuotientRing)
matroidOrlikSolomon OrderedMatroid := QuotientRing => M -> (
e := symbol e;
R := ZZ (monoid [
apply (M.orderedGround, f -> e_f), -- a variable for each f in E
MonomialOrder => { -- set the order of the variables
Weights => toList (0..<#M.orderedGround),
GLex}, --use graded lex as a tie-breaker
SkewCommutative => true -- worank in the exterior algebra
]);
I := ideal apply (
M.orderedCircuits,
C -> sum apply(
toList(0..<#C),
i -> (-1)^i * product apply(
delete(C#i,C),
f -> (e_f)_R)
)
);
R/I
)
brokenCircuitComplex = method (TypicalValue => SimplicialComplex)
brokenCircuitComplex (OrderedMatroid, Ring) := (M, R) -> (
x := getSymbol "x";
S := R[apply(M.orderedGround, e -> (getSymbol "x")_e),
Weights => toList(0..<#M.orderedGround)];
brokenCircuits := apply(M.orderedCircuits, C -> delete(first C, C));
I := monomialIdeal apply(
brokenCircuits,
C -> product apply(C, e -> (value "x")_e));
simplicialComplex I
)
brokenCircuitComplex OrderedMatroid := M -> (
brokenCircuitComplex (M, ZZ/1999))
matroidCharacteristicPolynomial = method(TypicalValue => RingElement)
matroidCharacteristicPolynomial OrderedMatroid := RingElement => M -> (
hilb := numerator reduceHilbert hilbertSeries matroidOrlikSolomon M;
d := (degree hilb)#0;
--R := newRing (ring hilb, Inverses => true, MonomialOrder => Lex);
--hilb := sub (hilb, R);
R := ring hilb;
use R;
T := R_0;
T^d* sub(hilb, T => -1 * T^-1)
)
matroidCharacteristicPolynomial Matroid := RingElement => M -> (
matroidCharacteristicPolynomial orderedMatroid M)
-- TEX ACTIVE ORDERS
-- first we get a nice layout for the internal order
texInternalOrder = method(Options => {symbol Jitter => false})
texInternalOrder Poset := String => opts -> P -> print (
--if not instance(opts.SuppressLabels, Boolean) then error "The option SuppressLabels must be a Boolean.";
if not instance(opts.Jitter, Boolean) then error "The option Jitter must be a Boolean.";
-- edge list to be read into TikZ
if not P.cache.?coveringRelations then coveringRelations P;
edgelist := apply(P.cache.coveringRelations, r -> concatenate(toString first r, "/", toString last r));
-- Find each level of P and set up the positioning of the vertices.
if not P.cache.?filtration then filtration P;
F := P.cache.filtration;
levelsets := apply(F, v -> #v-1);
scalew := min{1.5, 15 / (1 + max levelsets)};
scaleh := min{2 / scalew, 15 / #levelsets};
halflevelsets := apply(levelsets, lvl -> scalew * lvl / 2);
spacings := apply(levelsets, lvl -> scalew * toList(0..lvl));
-- The TeX String
"\n\\tikzstyle{every node} = [draw = black, fill = white, rectangle, inner sep = 1pt]\n\\begin{tikzpicture}[scale = 1]\n" |
concatenate(
for i from 0 to #levelsets - 1 list for j from 0 to levelsets_i list {
" \\node (", toString F_i_j,") at (-",toString halflevelsets_i,"+",toString(0 + spacings_i_j),",",toString(scaleh*i),")",
" {\\scriptsize${",
concatenate(
concatenate ("{",listToTexString ((P.GroundSet_(F_i_j))#0),"}"),
concatenate ("^{",listToTexString ((P.GroundSet_(F_i_j))#1),"}"),
concatenate ("_{",listToTexString ((P.GroundSet_(F_i_j))#2),"}")
),
"}$}",
";\n"}
,
concatenate(
" \\foreach \\to/\\from in ",
toString edgelist,
"\n \\draw [-] (\\to)--(\\from);\n\\end{tikzpicture}\n")
)
)
-- Next we get a nice layout for the external order
texExternalOrder = method(
Options => {symbol Jitter => false})
texExternalOrder Poset := String => opts -> P -> print (
--if not instance(opts.SuppressLabels, Boolean) then error "The option SuppressLabels must be a Boolean.";
if not instance(opts.Jitter, Boolean) then error "The option Jitter must be a Boolean.";
-- edge list to be read into TikZ
if not P.cache.?coveringRelations then coveringRelations P;
edgelist := apply(P.cache.coveringRelations, r -> concatenate(toString first r, "/", toString last r));
-- Find each level of P and set up the positioning of the vertices.
if not P.cache.?filtration then filtration P;
F := P.cache.filtration;
levelsets := apply(F, v -> #v-1);
scalew := min{1.5, 15 / (1 + max levelsets)};
scaleh := min{2 / scalew, 15 / #levelsets};
halflevelsets := apply(levelsets, lvl -> scalew * lvl / 2);
spacings := apply(levelsets, lvl -> scalew * toList(0..lvl));
if class((P.GroundSet)#0#0) === List then
-- The TeX String showing externally active elements as superscripts
"\n\\tikzstyle{every node} = [draw = black, fill = white, rectangle, inner sep = 1pt]\n\\begin{tikzpicture}[scale = 1]\n" |
concatenate(
for i from 0 to #levelsets - 1 list for j from 0 to levelsets_i list {
" \\node (", toString F_i_j,") at (-",toString halflevelsets_i,"+",toString(0 + spacings_i_j),",",toString(scaleh*i),")",
" {\\scriptsize${",
concatenate(
concatenate ("{",listToTexString ((P.GroundSet_(F_i_j))#0),"}"),
concatenate ("^{",listToTexString ((P.GroundSet_(F_i_j))#1),"}")
),
"}$}",
";\n"}
,
concatenate(
" \\foreach \\to/\\from in ",
toString edgelist,
"\n \\draw [-] (\\to)--(\\from);\n\\end{tikzpicture}\n")
)
else
-- The TeX String without externally active elements as superscripts
"\n\\tikzstyle{every node} = [draw = black, fill = white, rectangle, inner sep = 1pt]\n\\begin{tikzpicture}[scale = 1]\n" |
concatenate(
for i from 0 to #levelsets - 1 list for j from 0 to levelsets_i list {
" \\node (", toString F_i_j,") at (-",toString halflevelsets_i,"+",toString(0 + spacings_i_j),",",toString(scaleh*i),")",
" {\\scriptsize${",
concatenate(
concatenate ("{",listToTexString ((P.GroundSet_(F_i_j))),"}"),
),
"}$}",
";\n"}
,
concatenate(
" \\foreach \\to/\\from in ",
toString edgelist,
"\n \\draw [-] (\\to)--(\\from);\n\\end{tikzpicture}\n")
)
)
------------------------
-- End of source code --
------------------------
-------------------------
-- Begin documentation --
-------------------------
beginDocumentation()
doc ///
Key
MatroidActivities
Headline
a package for computations with ordered matroids
Description
Text
@TO "MatroidActivities"@ facilitates computations with @TO2
{matroid, "matroids"}@ and @TO2 {OrderedMatroid, "ordered
matroids"}@. It is an extension of the @TO Matroids@ package and
should eventually be subsumed by it. This package defines the new
class @TO2 {OrderedMatroid, "OrderedMatroid"}@. Just as in the @TO
Matroids@ package, one can make an @TO2 {orderedMatroid, "ordered
matroid"}@ from a @TO2 {matrix, "matrix"}@ or from a @TO2 {graph,
"simple graph"}@. In addition, this package makes it possible to
construct (ordered) matroids from @TO2 {CentralArrangement,
"central hyperplane arrangements"}@ over fields or ZZ, as well as
from @TO2 {SimplicialComplexes, "simplicial complexes"}@ and @TO2
{MonomialIdeal, "monomial ideals"}@.
@TO MatroidActivities@ was initially created to compute general
matroid activities defined by Las Vergnas in [LV01]. (This is also
what inspired the name of the package.) In order to make these
computations we introduce the new type @TO OrderedMatroid@
consisting of a @TO2 {matroid,"matroid"}@ together with a linear
order on the ground set of the matroid. In addition to methods for
computing @TO2 {internallyActiveElements, "internal"}@ and @TO2
{externallyActiveElements, "external activities"}@ of arbitrary
subsets of the ground set of an ordered matroid, one can also
compute the @TO2 {internalOrder, "internal"}@ and @TO2
{externalOrder, "external orders"}@ of an ordered matroid. In
particular, one can test if an ordered matroid is @TO2
{isInternallyPerfect, "internally perfect"}@ as defined in [Da15].
There is also a method for computing the @TO2 {bjornersPartition,
"Bjorner partition"}@ of the boolean lattice (see [Bj92]) induced
by a given linear ordering of the ground set.
In addition to the combinatorial methods described above, @TO
MatroidActivities@ also allows one to compute a number of
algebro-geometric structures associated to a (not necessarily
ordered) matroid M: the @TO2 {matroidIndependenceComplex,
"independence complex"}@ of M and its @TO2 {faceIdeal, "face
ideal"}@ [St83]; the @TO2 {brokenCircuitComplex,"broken circuit
complex"}@ of M and its @TO2 {faceIdeal, "face ideal"}@ (see e.g.
[BZ91]); the @TO2 {matroidChowRing,"Chow ring"}@ of M [AKM15]; and
the @TO2 {matroidOrlikSolomon,"Orlik-Solomon algebra"}@ of M
[OS80].
@BR{}@ @BR{}@
{\bf Setup}
This package uses (and should evenutally be subsumed by) the
package @TO Matroids@, so install this first. The source code for
the Matroids package can be found @HREF{ "https://github.com/
jchen419/Matroids-M2", "here"}@.
Once the Matroids package is installed place the source file for
this package (available @HREF{"https://github.com/ aarondall/
MatroidActivities-M2/blob/master/MatroidActivities.m2", "here"}@)
somewhere into the M2 @TO2 {"path", "search path"}@ and install
the package by calling @TO installPackage@ (MatroidActivities).
{\bf References}@BR{}@
@UL{