-
Notifications
You must be signed in to change notification settings - Fork 1
/
oldPosets.m2
6507 lines (6145 loc) · 237 KB
/
oldPosets.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
-- Copyright 2011, 2012, 2013, 2014: David Cook II, Sonja Mapes, Gwyn Whieldon
-- You may redistribute this file under the terms of the GNU General Public
-- License as published by the Free Software Foundation, either version 2
-- of the License, or any later version.
------------------------------------------
------------------------------------------
-- Header
------------------------------------------
------------------------------------------
newPackage select((
"Posets",
Version => "1.1.2",
Date => "07. August 2014",
Authors => {
{Name => "David Cook II", Email => "dwcook@eiu.edu", HomePage => "http://ux1.eiu.edu/~dwcook/"},
{Name => "Sonja Mapes", Email => "smapes1@nd.edu", HomePage => "http://www.nd.edu/~smapes1/"},
{Name => "Gwyn Whieldon", Email => "whieldon@hood.edu", HomePage => "http://www.hood.edu/Academics/Departments/Mathematics/Faculty/Gwyneth-Whieldon.html"}
},
Headline => "Package for processing partially ordered sets (posets)",
Configuration => {
"DefaultPDFViewer" => "open", -- "open" for Macs and "evince" for Linux
"DefaultPrecompute" => true,
"DefaultSuppressLabels" => true
},
DebuggingMode => false,
PackageExports => {
"SimplicialComplexes",
"Graphs",
"FourTiTwo"
}
), x -> x =!= null)
-- Load configurations
posets'PDFViewer = if instance((options Posets).Configuration#"DefaultPDFViewer", String) then (options Posets).Configuration#"DefaultPDFViewer" else "open";
posets'Precompute = if instance((options Posets).Configuration#"DefaultPrecompute", Boolean) then (options Posets).Configuration#"DefaultPrecompute" else true;
posets'SuppressLabels = if instance((options Posets).Configuration#"DefaultSuppressLabels", Boolean) then (options Posets).Configuration#"DefaultSuppressLabels" else true;
export {
--
-- Data type & constructor
"Poset",
"GroundSet",
"RelationMatrix",
"Relations",
"AntisymmetryStrategy",
"poset",
"transitiveClosure",
--
-- Set default configurations
"setPDFViewer",
"setPrecompute",
"Precompute",
"setSuppressLabels",
--
-- Derivative non-poset structures
"comparabilityGraph",
"hasseDiagram",
"hibiIdeal",
"hibiRing",
"incomparabilityGraph",
"orderComplex",
"VariableName",
"pPartitionRing",
--
-- Derivative posets
"closedInterval",
"dilworthLattice",
"distributiveLattice",
"OriginalPoset",
--"dual",
"filter",
"flagPoset",
"indexLabeling",
"labelPoset",
"naturalLabeling",
"openInterval",
"orderIdeal",
"principalFilter",
"principalOrderIdeal",
"subposet",
--
-- Operations
"adjoinMax",
"adjoinMin",
"areIsomorphic",
"augmentPoset",
"diamondProduct",
"dropElements",
"isomorphism",
--"product",
"removeIsomorphicPosets",
"union",
--
-- Enumerators
"booleanLattice",
"chain",
"divisorPoset",
"dominanceLattice",
"facePoset",
"intersectionLattice",
"lcmLattice",
"ncpLattice",
"ncPartitions",
"NCPartition",
"partitionLattice",
"setPartition",
"plueckerPoset",
"projectivizeArrangement",
"randomPoset",
"Bias",
"resolutionPoset",
"standardMonomialPoset",
"transitiveOrientation",
"Random",
"youngSubposet",
--
-- TeX & GAP
"displayPoset",
"PDFDirectory",
"gapConvertPoset",
"outputTexPoset",
"texPoset",
"Jitter",
"PDFViewer",
"SuppressLabels",
--
-- Vertices & vertex properties
"atoms",
"compare",
--"connectedComponents",
"filtration",
"joinExists",
"joinIrreducibles",
"maximalElements",
"meetExists",
"meetIrreducibles",
"minimalElements",
"posetJoin",
"posetMeet",
"rankFunction",
"rankPoset",
--"rank",
--
-- Relations & relation properties
"allRelations",
"antichains",
"chains",
"coveringRelations",
"flagChains",
"isAntichain",
"linearExtensions",
"maximalAntichains",
"maximalChains",
--
-- Enumerative invariants
"boundedRegions",
"characteristicPolynomial",
"flagfPolynomial",
"flaghPolynomial",
"fPolynomial",
"greeneKleitmanPartition",
"hPolynomial",
"moebiusFunction",
--"poincare",
"poincarePolynomial",
"rankGeneratingFunction",
"realRegions",
"tuttePolynomial",
"zetaPolynomial",
--
-- Properties
"dilworthNumber",
--"height",
"isAtomic",
"isBounded",
"isComparabilityGraph",
--"isConnected",
"isDistributive",
--"isEulerian",
"isGeometric",
"isGraded",
"isLattice",
"isLowerSemilattice",
"isLowerSemimodular",
"isModular",
"isRanked",
"isSperner",
"isStrictSperner",
"isUpperSemilattice",
"isUpperSemimodular"
}
------------------------------------------
------------------------------------------
-- Methods
------------------------------------------
------------------------------------------
------------------------------------------
-- Non-exported functions
------------------------------------------
indexElement := (P, a) -> (
j := position(P.GroundSet, i -> i === a);
if j === null then error("The element [" | toString a | "] is not in the poset.") else j
)
principalOrderIdeal' := (P, i) -> positions(flatten entries(P.RelationMatrix_i), j -> j != 0)
orderIdeal' := (P, L) -> unique flatten apply(L, l -> principalOrderIdeal'(P, l));
principalFilter' := (P, i) -> positions(first entries(P.RelationMatrix^{i}), j -> j != 0)
------------------------------------------
-- Data type & constructor
------------------------------------------
Poset = new Type of HashTable
poset = method(Options => {symbol AntisymmetryStrategy => "rank"})
poset (List, List, Matrix) := Poset => opts -> (G, R, M) -> (
a := if opts.AntisymmetryStrategy === "rank" then rank M === #G
else if opts.AntisymmetryStrategy === "none" then true
else if opts.AntisymmetryStrategy === "digraph" then (
idx := hashTable apply(#G, i -> G_i => i);
R = apply(R, r -> {idx#(first r), idx#(last r)});
not isCyclic digraph merge(applyValues(partition(first, R), v -> last \ v), hashTable apply(#G, i -> i => {}), join)
)
else error "The option AntisymmetryStrategy must be 'digraph', 'none', or 'rank'.";
if not a then error "The relations are not anti-symmetric.";
new Poset from {
symbol GroundSet => G,
symbol Relations => toList \ R,
symbol RelationMatrix => M,
symbol cache => new CacheTable from {"name" => "Unnamed Poset"}
})
poset (List, List) := Poset => opts -> (G, R) -> poset(G, R = toList \ R, transitiveClosure(G, R), opts)
poset (List, Function) := Poset => opts -> (G, cmp) -> (
M := matrix for a in G list for b in G list if cmp(a,b) then 1 else 0;
R := flatten for i to #G-1 list for j to #G-1 list if i != j and M_j_i == 1 then {G_i, G_j} else continue;
poset(G, R, M, opts)
)
poset List := Poset => opts -> R -> poset(unique flatten (R = toList \ R), R, opts);
Poset.GlobalAssignHook = (sym, val) -> (
val.cache#"name" = sym;
)
net Poset := p -> (
if p.cache#"name" === "Unnamed Poset" then "Relation Matrix: " | net p.RelationMatrix else toString p.cache#"name")
toString Poset := p -> toString p.cache#"name"
Poset _ ZZ := Thing => (P, i) -> P.GroundSet#i
Poset _ List := List => (P, L) -> P.GroundSet_L
installMethod(symbol _*, Poset, P -> P.GroundSet)
vertices Poset := List => P -> P.GroundSet
vertexSet Poset := List => P -> P.GroundSet
toExternalString Poset := String => P -> "poset(" | toExternalString P.GroundSet | ", " | toExternalString P.Relations | ", " | toString P.RelationMatrix | ")"
-- Returns a matrix M such that M_(i,j) = 1 if G_i <= G_j, and 0 otherwise
transitiveClosure = method()
transitiveClosure (List, List) := Matrix => (G, R) -> (
idx := hashTable apply(#G, i -> G_i => i);
R = for r in R list if first r === last r then continue else {idx#(first r), idx#(last r)};
D := digraph merge(applyValues(partition(first, R), v -> last \ v), hashTable apply(#G, i -> i => {}), join);
matrix apply(vertexSet D, v -> ( Dv := descendants(D, v); apply(vertexSet D, u -> if u === v or member(u, Dv) then 1 else 0)))
)
------------------------------------------
-- Set default configurations
------------------------------------------
setPDFViewer = method()
setPDFViewer String := String => viewer -> (
alt := posets'PDFViewer;
posets'PDFViewer = viewer;
alt
)
setPrecompute = method()
setPrecompute Boolean := Boolean => pc -> (
alt := posets'Precompute;
posets'Precompute = pc;
alt
)
setSuppressLabels = method()
setSuppressLabels Boolean := Boolean => sl -> (
alt := posets'SuppressLabels;
posets'SuppressLabels = sl;
alt
)
------------------------------------------
-- Derivative non-poset structures
------------------------------------------
-- NB: Renames vertices, otherwise it produces the wrong graph in some cases.
comparabilityGraph = method()
comparabilityGraph Poset := Graph => P -> (
E := flatten for i from 0 to #P.GroundSet - 1 list for j from i+1 to #P.GroundSet - 1 list
if P.RelationMatrix_i_j == 1 or P.RelationMatrix_j_i == 1 then {i, j} else continue;
fE := unique flatten E;
graph(E, Singletons => select(#P.GroundSet, i -> not member(i, fE)))
)
-- NB: Renames vertices, otherwise it produces the wrong graph in some cases.
hasseDiagram = method()
hasseDiagram Poset := Digraph => P -> (
if not P.cache.?coveringRelations then coveringRelations P;
digraph merge(applyValues(partition(first, P.cache.coveringRelations), v -> last \ v), hashTable apply(#P.GroundSet, i -> i => {}), join)
)
-- NB: Renames vertices, otherwise it produces the wrong ideal in some cases.
hibiIdeal = method(Options => { symbol CoefficientRing => QQ })
hibiIdeal Poset := MonomialIdeal => opts -> P -> (
G := toList(0 ..< #P.GroundSet);
if not P.cache.?maximalAntichains then maximalAntichains P;
A := sort unique flatten (subsets \ P.cache.maximalAntichains);
J := apply(A, a -> orderIdeal'(P, a));
x := local x;
y := local y;
R := (opts.CoefficientRing)(monoid [x_0..x_(#P.GroundSet-1),y_0..y_(#P.GroundSet-1)]);
monomialIdeal apply(J, I -> product(I, i -> R_i) * product(G - set I, j -> R_(#P.GroundSet + j)))
)
-- NB: Renames vertices, otherwise it produces the wrong ideal in some cases.
hibiRing = method(Options => { symbol CoefficientRing => QQ, symbol Strategy => "kernel" })
hibiRing Poset := QuotientRing => opts -> P -> (
if opts.Strategy =!= "kernel" and opts.Strategy =!= "4ti2" then error "The option Strategy must either be 'kernel' or '4ti2'.";
t := local t; x := local x; y := local y;
R := (opts.CoefficientRing)(monoid [x_0..x_(#P.GroundSet-1),y_0..y_(#P.GroundSet-1)]);
if not P.cache.?maximalAntichains then maximalAntichains P;
A := sort unique flatten (subsets \ P.cache.maximalAntichains);
J := apply(A, a -> orderIdeal'(P, a));
S := (opts.CoefficientRing)(monoid[apply(J, I -> t_I)]);
G := set toList(0 ..< #P.GroundSet);
M := apply(J, I -> product(I, i -> R_i) * product(toList(G - I), j -> R_(#P.GroundSet + j)));
if opts.Strategy === "kernel" then S/kernel map(R, S, matrix {M})
else if opts.Strategy === "4ti2" then (
N := matrix transpose apply(indices \ M, I -> apply(numgens R, j -> if member(j, I) then 1 else 0));
S/toricGroebner(N, S)
)
)
-- NB: Renames vertices, otherwise it produces the wrong graph in some cases.
incomparabilityGraph = method()
incomparabilityGraph Poset := Graph => P -> (
E := flatten for i from 0 to #P.GroundSet - 1 list for j from i+1 to #P.GroundSet - 1 list
if P.RelationMatrix_i_j == 0 and P.RelationMatrix_j_i == 0 then {i, j} else continue;
S := toList(0 ..< #P.GroundSet) - set unique flatten E;
graph(E, Singletons => S)
)
-- NB: Renames vertices, otherwise it produces the wrong simplicial complex in some cases.
orderComplex = method(Options => { symbol VariableName => getSymbol "v", symbol CoefficientRing => QQ })
orderComplex Poset := SimplicialComplex => opts -> P -> (
E := flatten for i from 0 to #P.GroundSet - 1 list for j from i+1 to #P.GroundSet - 1 list
if P.RelationMatrix_i_j == 0 and P.RelationMatrix_j_i == 0 then {i, j} else continue;
s := opts.VariableName;
R := (opts.CoefficientRing)(monoid [s_0..s_(#P.GroundSet - 1)]);
simplicialComplex if #E > 0 then monomialIdeal apply(E, e -> R_(e_0) * R_(e_1)) else {product gens R}
)
pPartitionRing = method(Options => { symbol CoefficientRing => QQ, symbol Strategy => "kernel" })
pPartitionRing Poset := QuotientRing => opts -> P -> (
if opts.Strategy =!= "kernel" and opts.Strategy =!= "4ti2" then error "The option Strategy must either be 'kernel' or '4ti2'.";
O := unique apply(#P.GroundSet, i -> principalOrderIdeal'(P, i));
if not P.cache.?connectedComponents then connectedComponents P;
J := flatten apply(P.cache.connectedComponents, C -> select(unique apply(subsets C, s -> sort unique flatten O_s), I -> isConnected subposet(P, P.GroundSet_I)));
t := local t;
S := (opts.CoefficientRing)(monoid [apply(J, I -> t_I)]);
if opts.Strategy === "kernel" then (
R := (opts.CoefficientRing)(monoid [t_0..t_(#P.GroundSet-1)]);
M := matrix{apply(J, I -> product(I, i -> R_i))};
S/kernel map(R, S, M)
)
else if opts.Strategy === "4ti2" then (
N := matrix transpose apply(J, I -> apply(#P.GroundSet, j -> if member(j, I) then 1 else 0));
S/toricGroebner(N, S)
)
)
------------------------------------------
-- Derivative posets
------------------------------------------
closedInterval = method()
closedInterval (Poset, Thing, Thing) := Poset => (P, p, q) -> (
if compare(P, p, q) then subposet(P, select(P.GroundSet, x -> compare(P, p, x) and compare(P, x, q)))
else if compare(P, q, p) then subposet(P, select(P.GroundSet, x -> compare(P, q, x) and compare(P, x, p)))
else error "The elements are incomparable."
)
dilworthLattice = method()
dilworthLattice Poset := Poset => P -> (
d := dilworthNumber P;
G := select(maximalAntichains P, a -> #a == d);
cmp := (A, B) -> all(A, a -> any(B, b -> compare(P, a, b)));
Q := poset(G, cmp, AntisymmetryStrategy => "none");
if posets'Precompute then (
Q.cache.isLowerSemilattice = true;
Q.cache.isUpperSemimodular = true;
Q.cache.connectedComponents = {toList(0 ..< #Q.GroundSet)};
);
Q
)
distributiveLattice = method()
distributiveLattice Poset := Poset => P -> (
if not P.cache.?maximalAntichains then maximalAntichains P;
A := sort unique flatten (subsets \ P.cache.maximalAntichains);
J := apply(A, a -> P_(orderIdeal'(P, a)));
Q := poset(J, isSubset, AntisymmetryStrategy => "none");
Q.cache.OriginalPoset = P;
if posets'Precompute then (
Q.cache.isLowerSemilattice = true;
Q.cache.isUpperSemimodular = true;
Q.cache.connectedComponents = {toList(0 ..< #Q.GroundSet)};
);
Q
)
-- The method dual is given in the Core and has options.
-- Since we don't need the options, we simply discard them.
dual Poset := Poset => {} >> opts -> P -> (
Q := poset(P.GroundSet, reverse \ P.Relations, transpose P.RelationMatrix, AntisymmetryStrategy => "none");
if posets'Precompute then (
if P.cache.?connectedComponents then Q.cache.connectedComponents = P.cache.connectedComponents;
if P.cache.?coveringRelations then Q.cache.coveringRelations = reverse \ P.cache.coveringRelations;
if P.cache.?filtration then Q.cache.filtration = reverse P.cache.filtration;
if P.cache.?greeneKleitmanPartition then Q.cache.greeneKleitmanPartition = P.cache.greeneKleitmanPartition;
if P.cache.?isDistributive then Q.cache.isDistributive = P.cache.isDistributive;
if P.cache.?isEulerian then Q.cache.isEulerian = P.cache.isEulerian;
if P.cache.?isLowerSemilattice then Q.cache.isUpperSemilattice = P.cache.isLowerSemilattice;
if P.cache.?isLowerSemimodular then Q.cache.isUpperSemimodular = P.cache.isLowerSemimodular;
if P.cache.?isUpperSemilattice then Q.cache.isLowerSemilattice = P.cache.isUpperSemilattice;
if P.cache.?isUpperSemimodular then Q.cache.isLowerSemimodular = P.cache.isUpperSemimodular;
if P.cache.?maximalAntichains then Q.cache.maximalAntichains = P.cache.maximalAntichains;
if P.cache.?maximalChains then Q.cache.maximalChains = reverse \ P.cache.maximalChains;
if P.cache.?maximalElements then Q.cache.minimalElements = P.cache.maximalElements;
if P.cache.?minimalElements then Q.cache.maximalElements = P.cache.minimalElements;
if P.cache.?rankFunction then Q.cache.rankFunction = if (rk := P.cache.rankFunction) === null then null else (m := max rk; (i -> m - i) \ rk);
);
Q
)
filter = method()
filter (Poset, List) := List => (P, L) -> unique flatten apply(L, l -> principalFilter(P, l))
flagPoset = method()
flagPoset (Poset, List) := Poset => (P, L)-> (
if not isRanked P then error "The poset must be ranked.";
subposet(P, flatten (rankPoset P)_(sort unique L))
)
indexLabeling = method()
indexLabeling Poset := Poset => P -> labelPoset(P, hashTable apply(#P.GroundSet, i -> P.GroundSet_i => i))
labelPoset = method()
labelPoset (Poset, HashTable) := Poset => (P, l) -> new Poset from {
symbol GroundSet => (q -> l#q) \ P.GroundSet,
symbol Relations => apply(P.Relations, r -> (q -> l#q) \ r),
symbol RelationMatrix => P.RelationMatrix,
symbol cache => new CacheTable from P.cache
}
naturalLabeling = method()
naturalLabeling (Poset, ZZ) := Poset => (P, startIndex) -> (
F := flatten filtration P;
labelPoset(P, hashTable for i to #F - 1 list F_i => startIndex + i)
)
naturalLabeling Poset := Poset => P -> naturalLabeling(P, 0)
openInterval = method()
openInterval (Poset, Thing, Thing) := Poset => (P, p, q) -> dropElements(closedInterval(P, p, q), {p, q})
orderIdeal = method()
orderIdeal (Poset, List) := List => (P, L) -> unique flatten apply(L, l -> principalOrderIdeal(P, l))
principalFilter = method()
principalFilter (Poset, Thing) := List => (P, a) -> P.GroundSet_(principalFilter'(P, indexElement(P, a)))
principalOrderIdeal = method()
principalOrderIdeal (Poset, Thing) := List => (P, a) -> P.GroundSet_(principalOrderIdeal'(P, indexElement(P, a)))
subposet = method()
subposet (Poset, List) := Poset => (P, L) -> dropElements(P, toList(set P.GroundSet - set L))
------------------------------------------
-- Operations
------------------------------------------
adjoinMax = method()
adjoinMax (Poset,Thing) := Poset => (P, a) -> (
if member(a, P.GroundSet) then error "The new maximal element must not be a vertex in P.";
Q := poset(P.GroundSet | {a},
P.Relations | apply(P.GroundSet, g-> {g,a}),
matrix{{P.RelationMatrix, transpose matrix {toList (#P.GroundSet:1)}},{matrix {toList((#P.GroundSet):0)},1}},
AntisymmetryStrategy => "none");
if posets'Precompute then (
Q.cache.connectedComponents = {toList(0 ..< #Q.GroundSet)};
if P.cache.?coveringRelations and P.cache.?maximalElements then Q.cache.coveringRelations = join(P.cache.coveringRelations, apply(P.cache.maximalElements, i -> {i, #P.GroundSet}));
if P.cache.?filtration then Q.cache.filtration = append(P.cache.filtration, {#P.GroundSet});
if P.cache.?maximalAntichains then Q.cache.maximalAntichains = append(P.cache.maximalAntichains, {#P.GroundSet});
if P.cache.?maximalChains then Q.cache.maximalChains = (c -> append(c, #P.GroundSet)) \ P.cache.maximalChains;
Q.cache.maximalElements = {#P.GroundSet};
if P.cache.?minimalElements then Q.cache.minimalElements = P.cache.minimalElements;
if P.cache.?rankFunction then Q.cache.rankFunction = append(P.cache.rankFunction, 1 + max P.cache.rankFunction);
);
Q
)
adjoinMax Poset := Poset => P -> adjoinMax(P, 1 + max prepend(0, select(P.GroundSet, x-> class x === ZZ)))
adjoinMin = method()
adjoinMin (Poset,Thing) := Poset => (P, a) -> (
if member(a, P.GroundSet) then error "The new minimal element must not be a vertex in P.";
Q := poset(P.GroundSet | {a},
apply(P.GroundSet, g -> {a,g}) | P.Relations,
matrix{{P.RelationMatrix, transpose matrix {toList (#P.GroundSet:0)}}, {matrix{toList (#P.GroundSet:1)},1}},
AntisymmetryStrategy => "none");
if posets'Precompute then (
Q.cache.connectedComponents = {toList(0 ..< #Q.GroundSet)};
if P.cache.?coveringRelations and P.cache.?minimalElements then Q.cache.coveringRelations = join(P.cache.coveringRelations, apply(P.cache.minimalElements, i -> {#P.GroundSet, i}));
if P.cache.?filtration then Q.cache.filtration = prepend({#P.GroundSet}, P.cache.filtration);
if P.cache.?maximalAntichains then Q.cache.maximalAntichains = append(P.cache.maximalAntichains, {#P.GroundSet});
if P.cache.?maximalChains then Q.cache.maximalChains = (c -> prepend(#P.GroundSet, c)) \ P.cache.maximalChains;
if P.cache.?maximalElements then Q.cache.maximalElements = P.cache.maximalElements;
Q.cache.minimalElements = {#P.GroundSet};
if P.cache.?rankFunction then Q.cache.rankFunction = append((i -> i + 1) \ P.cache.rankFunction, 0);
);
Q
)
adjoinMin Poset := Poset => P -> adjoinMin(P, -1 + min prepend(1, select(P.GroundSet, x -> class x === ZZ)))
areIsomorphic = method()
areIsomorphic (Poset, Poset) := Boolean => (P, Q) -> isomorphism(P, Q) =!= null
Poset == Poset := areIsomorphic
augmentPoset = method()
augmentPoset (Poset, Thing, Thing) := Poset => (P, a, b) -> adjoinMin(adjoinMax(P, b), a)
augmentPoset Poset := Poset => P -> adjoinMin adjoinMax P
diamondProduct = method()
diamondProduct (Poset, Poset) := Poset => (P, Q)->(
if isRanked P and isRanked Q then (
P':=product(dropElements(P, minimalElements P),dropElements(Q, minimalElements Q));
poset(prepend({first minimalElements P, first minimalElements Q}, P'.GroundSet),
join(apply(minimalElements P', p -> ({first minimalElements P, first minimalElements Q}, p)), P'.Relations), AntisymmetryStrategy => "none")
) else error "The posets must be ranked."
)
dropElements = method()
dropElements (Poset, List) := Poset => (P, L) -> (
keptIndices := select(toList(0..#P.GroundSet-1), i -> not member(P.GroundSet#i, L));
newGroundSet := P.GroundSet_keptIndices;
newRelationMatrix := P.RelationMatrix_keptIndices^keptIndices;
newRelations := select(allRelations(P, true), r -> not member(first r, L) and not member(last r, L));
poset(newGroundSet, newRelations, newRelationMatrix, AntisymmetryStrategy => "none")
)
dropElements (Poset, Function) := Poset => (P, f) -> dropElements(P, select(P.GroundSet, p -> f p))
Poset - List := dropElements
-- Inspired by Stembridge's Maple Package
isomorphism = method()
isomorphism (Poset, Poset) := HashTable => (P, Q) -> (
-- Test for a quick bail-out (also puts the covering relations in the cache).
if #P_* != #Q_* or #coveringRelations P != #coveringRelations Q then return null;
-- Partition the vertices based on (#leq, #geq, #covering, #coveredBy).
vertexPartition := P -> (
leq := sum \ entries transpose P.RelationMatrix;
geq := sum \ entries P.RelationMatrix;
cr := transpose P.cache.coveringRelations;
if #cr == 0 then cr = {{}};
covering := tally last cr;
coveredBy := tally first cr;
partition(i -> {leq_i, geq_i, if covering#?i then covering#i else 0, if coveredBy#?i then coveredBy#i else 0}, 0..<#P_*)
);
vpP := vertexPartition P;
vpQ := vertexPartition Q;
-- Check for compatible vertex partitions.
if sort keys vpP != sort keys vpQ or any(keys vpP, k -> #vpP#k != #vpQ#k) then return null;
-- This method attempts to find an isomorphism by considering permutations of each part, one at a time.
buildIsoCand := (vpK, isoCand) -> (
-- If vpK is empty, then we've found an isomorphism!
if #vpK == 0 then return isoCand;
for p in permutations vpK_0_0 do (
isoCand' := merge(isoCand, new HashTable from apply(vpK_0_0, i -> (vpP#(vpK_0_1))#i => (vpQ#(vpK_0_1))#(p#i)), join);
-- Check that the restricted covering relations of P are covering relations of Q.
restrictedCRP := select(P.cache.coveringRelations, c -> member(first c, keys isoCand') and member(last c, keys isoCand'));
isomorph := if isSubset(apply(restrictedCRP, c -> {isoCand'#(first c), isoCand'#(last c)}), Q.cache.coveringRelations) then buildIsoCand(drop(vpK, 1), isoCand');
-- If we found one, then return it.
if isomorph =!= null then return isomorph;
);
);
-- Isolated vertices (key {1,1,0,0}) can be mapped to each other in any order.
isoCand := new HashTable from apply(if vpP#?{1,1,0,0} then #vpP#{1,1,0,0} else 0, i -> (vpP#{1,1,0,0})_i => (vpQ#{1,1,0,0})_i);
iso := buildIsoCand(sort apply(keys vpP - set {{1,1,0,0}}, k -> {#vpP#k, k}), isoCand);
-- If iso is non-null, then it is an isomorphism on the indices. Make it an isomorphism on the vertices.
if iso =!= null then new HashTable from apply(keys iso, k -> P_k => Q_(iso#k))
)
-- The product method is defined in the Core.
product (Poset, Poset) := Poset => (P, Q) ->
poset(flatten for p in P.GroundSet list for q in Q.GroundSet list {p, q},
join(flatten for c in P.Relations list for q in Q.GroundSet list ({c_0, q}, {c_1, q}),
flatten for c in Q.Relations list for p in P.GroundSet list ({p, c_0}, {p, c_1})), AntisymmetryStrategy => "none")
Poset * Poset := product
removeIsomorphicPosets = method()
removeIsomorphicPosets List := List => L -> (
if any(L, p -> not instance(p, Poset)) then error "The list must contain only Posets.";
while #L > 0 list (
p := first L;
pp := partition(q -> p == q, drop(L, 1));
L = if pp#?false then pp#false else {};
p
)
)
union = method()
union (Poset, Poset) := Poset => (P, Q) -> poset(unique join(P.GroundSet, Q.GroundSet), unique join(P.Relations, Q.Relations), AntisymmetryStrategy => "rank")
Poset + Poset := union
------------------------------------------
-- Enumerators
------------------------------------------
booleanLattice = method()
booleanLattice ZZ := Poset => n -> (
if n < 0 then n = -n;
P := booleanLattice' n;
if posets'Precompute then (
P.cache.connectedComponents = {toList(0 ..< #P.GroundSet)};
idx := hashTable apply(#P.GroundSet, i -> P_i => i);
P.cache.coveringRelations = apply(P.Relations, r -> {idx#(first r), idx#(last r)});
P.cache.isAtomic = P.cache.isDistributive = P.cache.isEulerian = P.cache.isLowerSemilattice = P.cache.isLowerSemimodular = P.cache.isUpperSemilattice = P.cache.isUpperSemimodular = true;
P.cache.maximalElements = {#P.GroundSet - 1};
P.cache.minimalElements = {0};
);
P
)
-- Recursive booleanLattice creation method. Builds filtration and rankFunction recursively, if desired.
-- non-exported
booleanLattice' = method()
booleanLattice' ZZ := Poset => n -> (
if n == 0 then (
Q := poset({""}, {}, matrix{{1}}, AntisymmetryStrategy => "none");
if posets'Precompute then (
Q.cache.filtration = {{0}};
Q.cache.rankFunction = {0};
);
Q
)
else (
Bn1 := booleanLattice'(n-1);
G := apply(Bn1.GroundSet, p -> "0" | p) | apply(Bn1.GroundSet, p -> "1" | p);
R := apply(Bn1.Relations, r -> {"0" | first r, "0" | last r}) |
apply(Bn1.Relations, r -> {"1" | first r, "1" | last r}) |
apply(Bn1.GroundSet, p -> {"0" | p, "1" | p});
M := matrix {{Bn1.RelationMatrix, Bn1.RelationMatrix}, {0, Bn1.RelationMatrix}};
P := poset(G, R, M, AntisymmetryStrategy => "none");
if posets'Precompute then (
f := Bn1.cache.filtration; f' := apply(f, l -> apply(l, l -> l + #Bn1.GroundSet));
f = append(f, {}); f' = prepend({}, f');
P.cache.filtration = apply(#f, i -> f_i | f'_i);
P.cache.rankFunction = join(Bn1.cache.rankFunction, apply(Bn1.cache.rankFunction, r -> r + 1));
);
P
)
)
chain = method()
chain ZZ := Poset => n -> (
if n == 0 then error "The integer n must be non-zero.";
if n < 0 then n = -n;
P := poset(toList(1..n), apply(n-1, i -> {i+1, i+2}), matrix toList apply(1..n, i -> toList join((i-1):0, (n-i+1):1)), AntisymmetryStrategy => "none");
if posets'Precompute then (
P.cache.connectedComponents = P.cache.maximalChains = {P.cache.rankFunction = toList(0 ..< n)};
P.cache.coveringRelations = apply(n-1, i -> {i, i+1});
P.cache.filtration = P.cache.maximalAntichains = apply(n, i -> {i});
P.cache.greeneKleitmanPartition = new Partition from {n};
P.cache.isDistributive = P.cache.isLowerSemilattice = P.cache.isLowerSemimodular = P.cache.isUpperSemilattice = P.cache.isUpperSemimodular = true;
P.cache.isAtomic = P.cache.isEulerian = (n <= 2);
P.cache.maximalElements = {n-1};
P.cache.minimalElements = {0};
);
P
)
divisorPoset = method()
divisorPoset RingElement := Poset => m -> (
if m == 0 then error "The RingElement m must be non-zero.";
if #support m == 0 then return poset({m}, {}, AntisymmetryStrategy => "none"); -- Units are special.
F := apply(toList \ toList factor m, m -> set apply(last m + 1, i -> (first m)^i));
-- D is the set of all (positive) divisors of m
D := sort if #F == 1 then toList first F else product \ toList@@deepSplice \ toList fold((a,b) -> a ** b, F);
R := flatten for i to #D-1 list for j to #D-1 list if D_j % D_i == 0 and isPrime(D_j//D_i) then {D_i, D_j} else continue;
M := matrix for i to #D-1 list for j to #D-1 list if D_j % D_i == 0 then 1 else 0;
P := poset(D, R, M, AntisymmetryStrategy => "none");
if posets'Precompute then (
P.cache.connectedComponents = {toList(0 ..< #P.GroundSet)};
idx := hashTable apply(#P.GroundSet, i -> P_i => i);
P.cache.coveringRelations = apply(P.Relations, r -> {idx#(first r), idx#(last r)});
P.cache.isLowerSemilattice = P.cache.isUpperSemilattice = true;
P.cache.maximalElements = {#P.GroundSet - 1};
P.cache.minimalElements = {0};
);
P
)
divisorPoset ZZ := Poset => m -> (
if m == 0 then error "The integer m must be non-zero.";
if m < 0 then m = -m;
if m == 1 then return poset({1}, {}, AntisymmetryStrategy => "none"); -- 1 is special
F := apply(toList \ toList factor m, m -> set apply(last m + 1, i -> (first m)^i));
-- D is the set of all (positive) divisors of m
D := sort if #F == 1 then toList first F else product \ toList@@deepSplice \ toList fold((a,b) -> a ** b, F);
R := flatten for i to #D-1 list for j to #D-1 list if D_j % D_i == 0 and isPrime(D_j//D_i) then {D_i, D_j} else continue;
M := matrix for i to #D-1 list for j to #D-1 list if D_j % D_i == 0 then 1 else 0;
P := poset(D, R, M, AntisymmetryStrategy => "none");
if posets'Precompute then (
P.cache.connectedComponents = {toList(0 ..< #P.GroundSet)};
idx := hashTable apply(#P.GroundSet, i -> P_i => i);
P.cache.coveringRelations = apply(P.Relations, r -> {idx#(first r), idx#(last r)});
P.cache.isLowerSemilattice = P.cache.isUpperSemilattice = true;
P.cache.maximalElements = {#P.GroundSet - 1};
P.cache.minimalElements = {0};
);
P
)
divisorPoset (RingElement, RingElement):= Poset =>(m, n) -> (
if ring m === ring n then (
if n % m === sub(0, ring m) then (
P := divisorPoset (n//m);
poset(apply(P.GroundSet, v -> v * m), apply(P.Relations, r -> {m * first r, m * last r}), P.RelationMatrix, AntisymmetryStrategy => "none")
) else error "The first monomial does not divide the second."
) else error "The monomials must be in the same ring."
)
divisorPoset (List, List, PolynomialRing):= Poset => (m, n, R) -> (
makeMonomialFromDegree := (R, d) -> product apply(numgens R, i-> R_i^(d#i));
if #m === #n and #n === numgens R then divisorPoset(makeMonomialFromDegree(R, m), makeMonomialFromDegree(R, n))
else error "Wrong number of variables in one of the exponent vectors."
)
dominanceLattice = method()
dominanceLattice ZZ := Poset => n -> (
G := toList \ partitions n;
cmp := (a, b) -> (
if #b > #a then return false;
sa := 0;
sb := 0;
for k from 0 to #b - 1 do (
sa = sa + a_k;
sb = sb + b_k;
if sa > sb then return false;
);
true
);
P := poset(G, cmp, AntisymmetryStrategy => "none");
if posets'Precompute then (
P.cache.isLowerSemilattice = P.cache.isUpperSemilattice = true;
P.cache.maximalElements = {0};
P.cache.minimalElements = {#P.GroundSet - 1};
);
P
)
facePoset = method()
facePoset SimplicialComplex := Poset => D -> (
faceList := apply(toList(-1..dim D), i -> support \ toList flatten entries faces(i, D));
P := poset(flatten faceList, isSubset, AntisymmetryStrategy => "none");
if posets'Precompute then (
idx := hashTable apply(#P.GroundSet, i -> P_i => i);
P.cache.connectedComponents = {toList(0 ..< #P.GroundSet)};
P.cache.filtration = apply(faceList, L -> apply(L, l -> idx#l));
P.cache.isLowerSemilattice = true;
P.cache.maximalElements = last P.cache.filtration;
P.cache.minimalElements = first P.cache.filtration;
P.cache.rankFunction = apply(P.GroundSet, f -> #f);
);
P
)
-- non-exported
hyperplaneEquivalence = method()
hyperplaneEquivalence (List, Ring) := List => (L, R) -> (
allideals := unique drop(apply(subsets L, h -> ideal gens gb ideal h), 1);
select(allideals, I -> not I == ideal 1_R)
)
-- non-exported
hyperplaneInclusions = method()
hyperplaneInclusions(List, Ring) := List => (L, R) -> (
H := apply(L, l -> sub(l, R));
flatten for l from 1 to #H - 1 list for k to #H - 1 list
if unique apply(flatten entries gens H_k, f -> f % gens H_l) === {sub(0, R)} then {L_k, H_l} else continue
)
intersectionLattice = method()
intersectionLattice (List, Ring) := Poset => (L, R)-> (
G := hyperplaneEquivalence(L, R);
rel := hyperplaneInclusions(G, R);
adjoinMin(poset(G, rel), ideal 0_R)
)
lcmLattice = method( Options => { symbol Strategy => "recursive" })
lcmLattice Ideal := Poset => opts -> I -> (
str := if isMonomialIdeal I then opts.Strategy else "subsets";
Ground := if str === "subsets" then prepend(1_(ring I), unique (lcm \ drop(subsets I_*, 1)))
else if str === "recursive" then apply(lcmLatticeRecursive I_*, D -> (ring I)_D)
else error "The option Strategy must be either 'subsets' or 'recursive.'";
Rels := flatten for i to #Ground-1 list for j from i+1 to #Ground-1 list
if Ground_i % Ground_j == 0 then {Ground_j, Ground_i}
else if Ground_j % Ground_i == 0 then {Ground_i, Ground_j}
else continue;
RelsMatrix := matrix apply(Ground, r -> apply(Ground, s -> if s % r == 0 then 1 else 0));
poset(Ground, Rels, RelsMatrix, AntisymmetryStrategy => "none")
)
-- non-exported
protect next
lcmLatticeRecursive = G -> (
if #G === 0 then return {{}}; -- empty set has 1 as a divisor.
n := numgens ring first G;
-- Base Case: 1 can be made bigger by *every* generator.
lcmDegrees := {hashTable {symbol degree => toList(n:0), symbol next => first@@exponents \ G}};
-- Recursive Step: Update lcmDegrees so that the multidegrees are updated in the first i variables.
-- The list "next" is all the things that can change the multidegree after the first i variables.
for i from 0 to n-1 do (
lcmDegrees' := flatten apply(lcmDegrees, D -> (
P := partition(E -> E#i, D.next);
Q := partition(d -> d > (D.degree)#i, keys P);
-- Select those D.next that can change D.degree in the i^th variable.
upperPartition := hashTable apply(if Q#?true then Q#true else {}, d -> d => P#d);
-- Make the changes in the i^th variable
newMultiDegrees := flatten apply(keys upperPartition, d -> apply(upperPartition#d, E ->
hashTable {symbol degree => C := max \ transpose {D.degree, E}, symbol next => select(D.next, N -> any(C - N, i -> i < 0)) }
));
-- Update D to only have those that can change D *after* the i^th variable.
D' := hashTable {symbol degree => D.degree, symbol next => flatten apply(if Q#?false then Q#false else {}, d -> P#d)};
prepend(D', newMultiDegrees)
));
-- Get rid of D with duplicate multi-degrees
lcmDegrees = first \ values partition(D -> D.degree, select(lcmDegrees', D -> D =!= null));
);
sort apply(lcmDegrees, D -> D.degree)
)
-- Portions of code for generating NCPartitions contributed by Andrew Hoefel.
-- New Type for Noncrossing Partitions to improve diplay of results.
NCPartition = new Type of List
ncPartition = L -> new NCPartition from toList \ L
net NCPartition := L -> if #L === 0 then net "empty" else horizontalJoin(net \ L#0) | horizontalJoin apply(#L - 1, i -> "/" | horizontalJoin(net \ L#(i + 1)))
-- non-exported
ncpCovers = method()
ncpCovers (NCPartition, ZZ) := List => (P, i) -> (
if #(A := P_i) <= 1 then return {{},{}};
indexSet := flatten apply(toList(1 ..< #A), i -> apply(#A - i + 1, j -> toList(j..j + i - 1)));
gamma := ncPartition \ apply(indexSet, L -> sort flatten apply(#P, j -> if i == j then {A_L, select(A, i -> not member(i, A_L))} else {P#j}));
{gamma, apply(gamma, g -> {P, g})}
)
ncpCovers NCPartition := List => P -> flatten \ transpose apply(#P, i -> ncpCovers(P, i))
ncpCovers ZZ := List => n -> {{ncPartition {toList(0 ..< n)}}, {}}
-- non-exported
ncpGenerator = method()
ncpGenerator ZZ := List => n -> (
levels := {{n}};
flatten \ transpose apply(n, k -> levels = unique@@flatten \ transpose (ncpCovers \ first levels))
)
ncPartitions = method()
ncPartitions ZZ := List => n -> first ncpGenerator n
ncpLattice = method()
ncpLattice ZZ := Poset => n -> (
GR := ncpGenerator n;
M := matrix for w in first GR list for v in first GR list if all(v, v' -> any(w, w' -> isSubset(v', w'))) then 1 else 0;
P := poset(first GR, last GR, M, AntisymmetryStrategy => "none");
if posets'Precompute then (
P.cache.connectedComponents = {toList(0 ..< #P.GroundSet)};
idx := hashTable apply(#P.GroundSet, i -> P_i => i);
P.cache.coveringRelations = apply(last GR, r -> {idx#(first r), idx#(last r)});
pp := partition(v -> #v, P.GroundSet);
P.cache.filtration = apply(sort keys pp, k -> apply(pp#k, v -> idx#v));
P.cache.isLowerSemilattice = true;
P.cache.isUpperSemilattice = true;
P.cache.maximalElements = last P.cache.filtration;
P.cache.minimalElements = first P.cache.filtration;
P.cache.rankFunction = apply(P.GroundSet, f -> #f - 1);
);
P
)
partitionLattice = method()
partitionLattice ZZ := Poset => n -> (
L := toList (1..n);
G := setPartition L;
R := flatten apply(G, i-> partitionRefinementPairs i);
M := matrix for w in G list for v in G list if all(v, v' -> any(w, w' -> isSubset(v', w'))) then 1 else 0;
P := poset(G, R, M, AntisymmetryStrategy => "none");
if posets'Precompute then (
P.cache.connectedComponents = {toList(0 ..< #G)};
idx := hashTable apply(#G, i -> P_i => i);
P.cache.coveringRelations = apply(R, r -> {idx#(first r), idx#(last r)});
pp := partition(v -> #v, G);
P.cache.filtration = apply(sort keys pp, k -> apply(pp#k, v -> idx#v));
P.cache.isLowerSemilattice = true;
P.cache.isUpperSemilattice = true;
P.cache.maximalElements = last P.cache.filtration;
P.cache.minimalElements = first P.cache.filtration;
P.cache.rankFunction = apply(G, f -> #f - 1);
);
P
)
partitionRefinementPairs = method()
partitionRefinementPairs List := List => L-> (
m := unique apply(L, l-> #l);
M := local M;
N := local N;
MM := apply(m, i-> (symbol M)_i);
NN := apply(m, i-> (symbol N)_i);
for i in m do (
subS := subsets toList(0 ..< i);
M_i = take(subS,{1,#subS-2});
N_i = unique apply(M_i, r-> sort {r, select(toList(0 ..< i), k-> not member(k,r))});
);
dropPart := apply(#L, i-> drop(L,{i,i}));
coverSet := flatten for i from 0 to #L-1 list(
splitPairs:=apply(N_(#L_i), m-> {(L_i)_(first m),(L_i)_(last m)});
apply(splitPairs, j-> sort join(dropPart_i,j))
);
apply(coverSet, i -> {L,i})
)
setPartition = method()
setPartition ZZ := List => n -> (
L := {{{1}}};
for i from 2 to n do (
L = flatten for lambda in L list (
lambdaparts := apply(#lambda, l-> for k to #lambda-1 list if k=!=l then lambda_k else continue);
append(apply(#lambda, p-> lambdaparts_p | {lambda_p | {i}}), join(lambda,{{i}}))
);
);
apply(L, sort)
)
setPartition List := List => S -> (
L := {{{first S}}};
for s in drop(S,1) do (
L = flatten for lambda in L list(
dropPart := apply(#lambda, i-> drop(lambda,{i,i}));
protoLevelSet := apply(#lambda, l-> join(dropPart_l,{lambda_l|{s}}));
join(protoLevelSet, {lambda|{{s}}})
);
);
apply(L,sort)
)
plueckerPoset = method()
plueckerPoset ZZ := Poset => n -> (
P := poset(subsets n, (S,T) -> #S >= #T and all(#T, i -> S_i <= T_i), AntisymmetryStrategy => "none");
if posets'Precompute then (
P.cache.connectedComponents = {toList(0 ..< 2^n)};
P.cache.isLowerSemilattice = true;
P.cache.isLowerSemimodular = true;
P.cache.isUpperSemilattice = true;
P.cache.isUpperSemimodular = true;
P.cache.maximalElements = {0};
P.cache.minimalElements = {2^n-1};
);
P
)
projectivizeArrangement = method()
projectivizeArrangement (List, Ring) := Poset => (L, R) -> (
Z := local Z;
S := (coefficientRing R)(monoid [append(gens R, Z)]);
Z = last gens S;
newL := apply(L, h -> homogenize(sub(h, S), Z));
G := hyperplaneEquivalence(newL, S);
rel := hyperplaneInclusions(G, S);
adjoinMin(poset(G, rel), ideal 0_R)
)
randomPoset = method(Options => {symbol Bias => 0.5})
randomPoset (List) := Poset => opts -> (G) -> (
if not instance(opts.Bias, RR) and not instance(opts.Bias, QQ) and not instance(opts.Bias, ZZ) then error "The option Bias must be a ZZ, QQ, or RR.";
b := if instance(opts.Bias, ZZ) then (
if opts.Bias > 0 then 1.0/opts.Bias else error "The option Bias (as an element of ZZ) must be at least 1."
) else opts.Bias;
if b < 0 or b > 1 then error "The option Bias (as an element of QQ or RR) must be at least 0 and at most 1.";
poset(G, flatten for i from 0 to #G-1 list for j from i+1 to #G-1 list if random 1.0 < opts.Bias then {G_i, G_j} else continue, AntisymmetryStrategy => "none")