passagemath-graphs 10.5.43__cp39-cp39-musllinux_1_2_aarch64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (258) hide show
  1. passagemath_graphs-10.5.43.dist-info/METADATA +293 -0
  2. passagemath_graphs-10.5.43.dist-info/RECORD +258 -0
  3. passagemath_graphs-10.5.43.dist-info/WHEEL +5 -0
  4. passagemath_graphs-10.5.43.dist-info/top_level.txt +2 -0
  5. passagemath_graphs.libs/libgcc_s-69c45f16.so.1 +0 -0
  6. passagemath_graphs.libs/libgmp-8e78bd9b.so.10.5.0 +0 -0
  7. passagemath_graphs.libs/libstdc++-1f1a71be.so.6.0.33 +0 -0
  8. sage/all__sagemath_graphs.py +39 -0
  9. sage/combinat/abstract_tree.py +2552 -0
  10. sage/combinat/all__sagemath_graphs.py +34 -0
  11. sage/combinat/binary_tree.py +5306 -0
  12. sage/combinat/cluster_algebra_quiver/all.py +22 -0
  13. sage/combinat/cluster_algebra_quiver/cluster_seed.py +5208 -0
  14. sage/combinat/cluster_algebra_quiver/interact.py +125 -0
  15. sage/combinat/cluster_algebra_quiver/mutation_class.py +625 -0
  16. sage/combinat/cluster_algebra_quiver/mutation_type.py +1556 -0
  17. sage/combinat/cluster_algebra_quiver/quiver.py +2262 -0
  18. sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py +2468 -0
  19. sage/combinat/designs/MOLS_handbook_data.py +570 -0
  20. sage/combinat/designs/all.py +58 -0
  21. sage/combinat/designs/bibd.py +1655 -0
  22. sage/combinat/designs/block_design.py +1071 -0
  23. sage/combinat/designs/covering_array.py +269 -0
  24. sage/combinat/designs/covering_design.py +534 -0
  25. sage/combinat/designs/database.py +5614 -0
  26. sage/combinat/designs/design_catalog.py +122 -0
  27. sage/combinat/designs/designs_pyx.cpython-39-aarch64-linux-gnu.so +0 -0
  28. sage/combinat/designs/designs_pyx.pxd +21 -0
  29. sage/combinat/designs/designs_pyx.pyx +993 -0
  30. sage/combinat/designs/difference_family.py +3951 -0
  31. sage/combinat/designs/difference_matrices.py +279 -0
  32. sage/combinat/designs/evenly_distributed_sets.cpython-39-aarch64-linux-gnu.so +0 -0
  33. sage/combinat/designs/evenly_distributed_sets.pyx +661 -0
  34. sage/combinat/designs/ext_rep.py +1064 -0
  35. sage/combinat/designs/gen_quadrangles_with_spread.cpython-39-aarch64-linux-gnu.so +0 -0
  36. sage/combinat/designs/gen_quadrangles_with_spread.pyx +339 -0
  37. sage/combinat/designs/group_divisible_designs.py +361 -0
  38. sage/combinat/designs/incidence_structures.py +2357 -0
  39. sage/combinat/designs/latin_squares.py +548 -0
  40. sage/combinat/designs/orthogonal_arrays.py +2243 -0
  41. sage/combinat/designs/orthogonal_arrays_build_recursive.py +1780 -0
  42. sage/combinat/designs/orthogonal_arrays_find_recursive.cpython-39-aarch64-linux-gnu.so +0 -0
  43. sage/combinat/designs/orthogonal_arrays_find_recursive.pyx +966 -0
  44. sage/combinat/designs/resolvable_bibd.py +781 -0
  45. sage/combinat/designs/steiner_quadruple_systems.py +1306 -0
  46. sage/combinat/designs/subhypergraph_search.cpython-39-aarch64-linux-gnu.so +0 -0
  47. sage/combinat/designs/subhypergraph_search.pyx +530 -0
  48. sage/combinat/designs/twographs.py +306 -0
  49. sage/combinat/finite_state_machine.py +14874 -0
  50. sage/combinat/finite_state_machine_generators.py +2006 -0
  51. sage/combinat/graph_path.py +448 -0
  52. sage/combinat/interval_posets.py +3908 -0
  53. sage/combinat/nu_tamari_lattice.py +269 -0
  54. sage/combinat/ordered_tree.py +1446 -0
  55. sage/combinat/posets/all.py +46 -0
  56. sage/combinat/posets/cartesian_product.py +493 -0
  57. sage/combinat/posets/d_complete.py +182 -0
  58. sage/combinat/posets/elements.py +273 -0
  59. sage/combinat/posets/forest.py +30 -0
  60. sage/combinat/posets/hasse_cython.cpython-39-aarch64-linux-gnu.so +0 -0
  61. sage/combinat/posets/hasse_cython.pyx +174 -0
  62. sage/combinat/posets/hasse_diagram.py +3678 -0
  63. sage/combinat/posets/incidence_algebras.py +796 -0
  64. sage/combinat/posets/lattices.py +5119 -0
  65. sage/combinat/posets/linear_extension_iterator.cpython-39-aarch64-linux-gnu.so +0 -0
  66. sage/combinat/posets/linear_extension_iterator.pyx +292 -0
  67. sage/combinat/posets/linear_extensions.py +1039 -0
  68. sage/combinat/posets/mobile.py +275 -0
  69. sage/combinat/posets/moebius_algebra.py +776 -0
  70. sage/combinat/posets/poset_examples.py +2131 -0
  71. sage/combinat/posets/posets.py +9169 -0
  72. sage/combinat/rooted_tree.py +1070 -0
  73. sage/combinat/shard_order.py +239 -0
  74. sage/combinat/tamari_lattices.py +384 -0
  75. sage/combinat/yang_baxter_graph.py +923 -0
  76. sage/databases/all__sagemath_graphs.py +1 -0
  77. sage/databases/knotinfo_db.py +1230 -0
  78. sage/ext_data/all__sagemath_graphs.py +1 -0
  79. sage/ext_data/graphs/graph_plot_js.html +330 -0
  80. sage/ext_data/kenzo/CP2.txt +45 -0
  81. sage/ext_data/kenzo/CP3.txt +349 -0
  82. sage/ext_data/kenzo/CP4.txt +4774 -0
  83. sage/ext_data/kenzo/README.txt +49 -0
  84. sage/ext_data/kenzo/S4.txt +20 -0
  85. sage/graphs/all.py +42 -0
  86. sage/graphs/asteroidal_triples.cpython-39-aarch64-linux-gnu.so +0 -0
  87. sage/graphs/asteroidal_triples.pyx +299 -0
  88. sage/graphs/base/all.py +1 -0
  89. sage/graphs/base/boost_graph.cpython-39-aarch64-linux-gnu.so +0 -0
  90. sage/graphs/base/boost_graph.pxd +106 -0
  91. sage/graphs/base/boost_graph.pyx +3045 -0
  92. sage/graphs/base/c_graph.cpython-39-aarch64-linux-gnu.so +0 -0
  93. sage/graphs/base/c_graph.pxd +106 -0
  94. sage/graphs/base/c_graph.pyx +5096 -0
  95. sage/graphs/base/dense_graph.cpython-39-aarch64-linux-gnu.so +0 -0
  96. sage/graphs/base/dense_graph.pxd +26 -0
  97. sage/graphs/base/dense_graph.pyx +757 -0
  98. sage/graphs/base/graph_backends.cpython-39-aarch64-linux-gnu.so +0 -0
  99. sage/graphs/base/graph_backends.pxd +5 -0
  100. sage/graphs/base/graph_backends.pyx +797 -0
  101. sage/graphs/base/overview.py +85 -0
  102. sage/graphs/base/sparse_graph.cpython-39-aarch64-linux-gnu.so +0 -0
  103. sage/graphs/base/sparse_graph.pxd +90 -0
  104. sage/graphs/base/sparse_graph.pyx +1653 -0
  105. sage/graphs/base/static_dense_graph.cpython-39-aarch64-linux-gnu.so +0 -0
  106. sage/graphs/base/static_dense_graph.pxd +5 -0
  107. sage/graphs/base/static_dense_graph.pyx +1032 -0
  108. sage/graphs/base/static_sparse_backend.cpython-39-aarch64-linux-gnu.so +0 -0
  109. sage/graphs/base/static_sparse_backend.pxd +27 -0
  110. sage/graphs/base/static_sparse_backend.pyx +1580 -0
  111. sage/graphs/base/static_sparse_graph.cpython-39-aarch64-linux-gnu.so +0 -0
  112. sage/graphs/base/static_sparse_graph.pxd +37 -0
  113. sage/graphs/base/static_sparse_graph.pyx +1304 -0
  114. sage/graphs/bipartite_graph.py +2709 -0
  115. sage/graphs/centrality.cpython-39-aarch64-linux-gnu.so +0 -0
  116. sage/graphs/centrality.pyx +965 -0
  117. sage/graphs/cographs.py +519 -0
  118. sage/graphs/comparability.cpython-39-aarch64-linux-gnu.so +0 -0
  119. sage/graphs/comparability.pyx +813 -0
  120. sage/graphs/connectivity.cpython-39-aarch64-linux-gnu.so +0 -0
  121. sage/graphs/connectivity.pxd +157 -0
  122. sage/graphs/connectivity.pyx +4813 -0
  123. sage/graphs/convexity_properties.cpython-39-aarch64-linux-gnu.so +0 -0
  124. sage/graphs/convexity_properties.pxd +16 -0
  125. sage/graphs/convexity_properties.pyx +827 -0
  126. sage/graphs/digraph.py +4410 -0
  127. sage/graphs/digraph_generators.py +1921 -0
  128. sage/graphs/distances_all_pairs.cpython-39-aarch64-linux-gnu.so +0 -0
  129. sage/graphs/distances_all_pairs.pxd +12 -0
  130. sage/graphs/distances_all_pairs.pyx +2938 -0
  131. sage/graphs/domination.py +1363 -0
  132. sage/graphs/dot2tex_utils.py +100 -0
  133. sage/graphs/edge_connectivity.cpython-39-aarch64-linux-gnu.so +0 -0
  134. sage/graphs/edge_connectivity.pyx +1215 -0
  135. sage/graphs/generators/all.py +1 -0
  136. sage/graphs/generators/basic.py +1769 -0
  137. sage/graphs/generators/chessboard.py +538 -0
  138. sage/graphs/generators/classical_geometries.py +1611 -0
  139. sage/graphs/generators/degree_sequence.py +235 -0
  140. sage/graphs/generators/distance_regular.cpython-39-aarch64-linux-gnu.so +0 -0
  141. sage/graphs/generators/distance_regular.pyx +2846 -0
  142. sage/graphs/generators/families.py +4749 -0
  143. sage/graphs/generators/intersection.py +565 -0
  144. sage/graphs/generators/platonic_solids.py +262 -0
  145. sage/graphs/generators/random.py +2623 -0
  146. sage/graphs/generators/smallgraphs.py +5741 -0
  147. sage/graphs/generators/world_map.py +724 -0
  148. sage/graphs/generic_graph.py +26395 -0
  149. sage/graphs/generic_graph_pyx.cpython-39-aarch64-linux-gnu.so +0 -0
  150. sage/graphs/generic_graph_pyx.pxd +34 -0
  151. sage/graphs/generic_graph_pyx.pyx +1626 -0
  152. sage/graphs/genus.cpython-39-aarch64-linux-gnu.so +0 -0
  153. sage/graphs/genus.pyx +623 -0
  154. sage/graphs/graph.py +9362 -0
  155. sage/graphs/graph_coloring.cpython-39-aarch64-linux-gnu.so +0 -0
  156. sage/graphs/graph_coloring.pyx +2284 -0
  157. sage/graphs/graph_database.py +1122 -0
  158. sage/graphs/graph_decompositions/all.py +1 -0
  159. sage/graphs/graph_decompositions/bandwidth.cpython-39-aarch64-linux-gnu.so +0 -0
  160. sage/graphs/graph_decompositions/bandwidth.pyx +428 -0
  161. sage/graphs/graph_decompositions/clique_separators.cpython-39-aarch64-linux-gnu.so +0 -0
  162. sage/graphs/graph_decompositions/clique_separators.pyx +595 -0
  163. sage/graphs/graph_decompositions/cutwidth.cpython-39-aarch64-linux-gnu.so +0 -0
  164. sage/graphs/graph_decompositions/cutwidth.pyx +753 -0
  165. sage/graphs/graph_decompositions/fast_digraph.cpython-39-aarch64-linux-gnu.so +0 -0
  166. sage/graphs/graph_decompositions/fast_digraph.pxd +13 -0
  167. sage/graphs/graph_decompositions/fast_digraph.pyx +212 -0
  168. sage/graphs/graph_decompositions/graph_products.cpython-39-aarch64-linux-gnu.so +0 -0
  169. sage/graphs/graph_decompositions/graph_products.pyx +462 -0
  170. sage/graphs/graph_decompositions/modular_decomposition.cpython-39-aarch64-linux-gnu.so +0 -0
  171. sage/graphs/graph_decompositions/modular_decomposition.pxd +27 -0
  172. sage/graphs/graph_decompositions/modular_decomposition.pyx +1536 -0
  173. sage/graphs/graph_decompositions/slice_decomposition.cpython-39-aarch64-linux-gnu.so +0 -0
  174. sage/graphs/graph_decompositions/slice_decomposition.pxd +18 -0
  175. sage/graphs/graph_decompositions/slice_decomposition.pyx +1080 -0
  176. sage/graphs/graph_decompositions/tree_decomposition.cpython-39-aarch64-linux-gnu.so +0 -0
  177. sage/graphs/graph_decompositions/tree_decomposition.pxd +17 -0
  178. sage/graphs/graph_decompositions/tree_decomposition.pyx +1996 -0
  179. sage/graphs/graph_decompositions/vertex_separation.cpython-39-aarch64-linux-gnu.so +0 -0
  180. sage/graphs/graph_decompositions/vertex_separation.pxd +5 -0
  181. sage/graphs/graph_decompositions/vertex_separation.pyx +1963 -0
  182. sage/graphs/graph_editor.py +82 -0
  183. sage/graphs/graph_generators.py +3301 -0
  184. sage/graphs/graph_generators_pyx.cpython-39-aarch64-linux-gnu.so +0 -0
  185. sage/graphs/graph_generators_pyx.pyx +95 -0
  186. sage/graphs/graph_input.py +812 -0
  187. sage/graphs/graph_latex.py +2064 -0
  188. sage/graphs/graph_list.py +367 -0
  189. sage/graphs/graph_plot.py +1749 -0
  190. sage/graphs/graph_plot_js.py +338 -0
  191. sage/graphs/hyperbolicity.cpython-39-aarch64-linux-gnu.so +0 -0
  192. sage/graphs/hyperbolicity.pyx +1702 -0
  193. sage/graphs/hypergraph_generators.py +364 -0
  194. sage/graphs/independent_sets.cpython-39-aarch64-linux-gnu.so +0 -0
  195. sage/graphs/independent_sets.pxd +13 -0
  196. sage/graphs/independent_sets.pyx +402 -0
  197. sage/graphs/isgci.py +1033 -0
  198. sage/graphs/isoperimetric_inequalities.cpython-39-aarch64-linux-gnu.so +0 -0
  199. sage/graphs/isoperimetric_inequalities.pyx +453 -0
  200. sage/graphs/line_graph.cpython-39-aarch64-linux-gnu.so +0 -0
  201. sage/graphs/line_graph.pyx +627 -0
  202. sage/graphs/lovasz_theta.py +77 -0
  203. sage/graphs/matching.py +1633 -0
  204. sage/graphs/matching_covered_graph.py +3566 -0
  205. sage/graphs/orientations.py +1504 -0
  206. sage/graphs/partial_cube.py +459 -0
  207. sage/graphs/path_enumeration.cpython-39-aarch64-linux-gnu.so +0 -0
  208. sage/graphs/path_enumeration.pyx +2040 -0
  209. sage/graphs/pq_trees.py +1129 -0
  210. sage/graphs/print_graphs.py +201 -0
  211. sage/graphs/schnyder.py +865 -0
  212. sage/graphs/spanning_tree.cpython-39-aarch64-linux-gnu.so +0 -0
  213. sage/graphs/spanning_tree.pyx +1457 -0
  214. sage/graphs/strongly_regular_db.cpython-39-aarch64-linux-gnu.so +0 -0
  215. sage/graphs/strongly_regular_db.pyx +3340 -0
  216. sage/graphs/traversals.cpython-39-aarch64-linux-gnu.so +0 -0
  217. sage/graphs/traversals.pxd +9 -0
  218. sage/graphs/traversals.pyx +1871 -0
  219. sage/graphs/trees.cpython-39-aarch64-linux-gnu.so +0 -0
  220. sage/graphs/trees.pxd +15 -0
  221. sage/graphs/trees.pyx +310 -0
  222. sage/graphs/tutte_polynomial.py +713 -0
  223. sage/graphs/views.cpython-39-aarch64-linux-gnu.so +0 -0
  224. sage/graphs/views.pyx +794 -0
  225. sage/graphs/weakly_chordal.cpython-39-aarch64-linux-gnu.so +0 -0
  226. sage/graphs/weakly_chordal.pyx +562 -0
  227. sage/groups/all__sagemath_graphs.py +1 -0
  228. sage/groups/perm_gps/all__sagemath_graphs.py +1 -0
  229. sage/groups/perm_gps/partn_ref/all__sagemath_graphs.py +1 -0
  230. sage/groups/perm_gps/partn_ref/refinement_graphs.cpython-39-aarch64-linux-gnu.so +0 -0
  231. sage/groups/perm_gps/partn_ref/refinement_graphs.pxd +38 -0
  232. sage/groups/perm_gps/partn_ref/refinement_graphs.pyx +1666 -0
  233. sage/knots/all.py +6 -0
  234. sage/knots/free_knotinfo_monoid.py +507 -0
  235. sage/knots/gauss_code.py +291 -0
  236. sage/knots/knot.py +682 -0
  237. sage/knots/knot_table.py +284 -0
  238. sage/knots/knotinfo.py +2880 -0
  239. sage/knots/link.py +4682 -0
  240. sage/sandpiles/all.py +13 -0
  241. sage/sandpiles/examples.py +225 -0
  242. sage/sandpiles/sandpile.py +6365 -0
  243. sage/topology/all.py +22 -0
  244. sage/topology/cell_complex.py +1214 -0
  245. sage/topology/cubical_complex.py +1977 -0
  246. sage/topology/delta_complex.py +1806 -0
  247. sage/topology/filtered_simplicial_complex.py +744 -0
  248. sage/topology/moment_angle_complex.py +823 -0
  249. sage/topology/simplicial_complex.py +5161 -0
  250. sage/topology/simplicial_complex_catalog.py +86 -0
  251. sage/topology/simplicial_complex_examples.py +1692 -0
  252. sage/topology/simplicial_complex_homset.py +205 -0
  253. sage/topology/simplicial_complex_morphism.py +836 -0
  254. sage/topology/simplicial_set.py +4102 -0
  255. sage/topology/simplicial_set_catalog.py +55 -0
  256. sage/topology/simplicial_set_constructions.py +2954 -0
  257. sage/topology/simplicial_set_examples.py +865 -0
  258. sage/topology/simplicial_set_morphism.py +1464 -0
@@ -0,0 +1,2131 @@
1
+ # sage_setup: distribution = sagemath-graphs
2
+ # sage.doctest: needs sage.combinat sage.modules
3
+ r"""
4
+ Catalog of posets and lattices
5
+
6
+ Some common posets can be accessed through the ``posets.<tab>`` object::
7
+
8
+ sage: posets.PentagonPoset()
9
+ Finite lattice containing 5 elements
10
+
11
+ Moreover, the set of all posets of order `n` is represented by ``Posets(n)``::
12
+
13
+ sage: Posets(5)
14
+ Posets containing 5 elements
15
+
16
+ The infinite set of all posets can be used to find minimal examples::
17
+
18
+ sage: for P in Posets():
19
+ ....: if not P.is_series_parallel():
20
+ ....: break
21
+ sage: P
22
+ Finite poset containing 4 elements
23
+
24
+ **Catalog of common posets:**
25
+
26
+ .. csv-table::
27
+ :class: contentstable
28
+ :widths: 30, 70
29
+ :delim: |
30
+
31
+ :meth:`~Posets.AntichainPoset` | Return an antichain on `n` elements.
32
+ :meth:`~Posets.BooleanLattice` | Return the Boolean lattice on `2^n` elements.
33
+ :meth:`~Posets.ChainPoset` | Return a chain on `n` elements.
34
+ :meth:`~Posets.Crown` | Return the crown poset on `2n` elements.
35
+ :meth:`~Posets.DexterSemilattice` | Return the Dexter semilattice.
36
+ :meth:`~Posets.DiamondPoset` | Return the lattice of rank two on `n` elements.
37
+ :meth:`~Posets.DivisorLattice` | Return the divisor lattice of an integer.
38
+ :meth:`~Posets.DoubleTailedDiamond` | Return the double tailed diamond poset on `2n + 2` elements.
39
+ :meth:`~Posets.IntegerCompositions` | Return the poset of integer compositions of `n`.
40
+ :meth:`~Posets.IntegerPartitions` | Return the poset of integer partitions of ``n``.
41
+ :meth:`~Posets.IntegerPartitionsDominanceOrder` | Return the lattice of integer partitions on the integer `n` ordered by dominance.
42
+ :meth:`~Posets.MobilePoset` | Return the mobile poset formed by the `ribbon` with `hangers` below and an `anchor` above.
43
+ :meth:`~Posets.NoncrossingPartitions` | Return the poset of noncrossing partitions of a finite Coxeter group ``W``.
44
+ :meth:`~Posets.PentagonPoset` | Return the Pentagon poset.
45
+ :meth:`~Posets.PermutationPattern` | Return the Permutation pattern poset.
46
+ :meth:`~Posets.PermutationPatternInterval` | Return an interval in the Permutation pattern poset.
47
+ :meth:`~Posets.PermutationPatternOccurrenceInterval` | Return the occurrence poset for a pair of comparable elements in the Permutation pattern poset.
48
+ :meth:`~Posets.PowerPoset` | Return a power poset.
49
+ :meth:`~Posets.ProductOfChains` | Return a product of chain posets.
50
+ :meth:`~Posets.RandomLattice` | Return a random lattice on `n` elements.
51
+ :meth:`~Posets.RandomPoset` | Return a random poset on `n` elements.
52
+ :meth:`~Posets.RibbonPoset` | Return a ribbon on `n` elements with descents at `descents`.
53
+ :meth:`~Posets.RestrictedIntegerPartitions` | Return the poset of integer partitions of `n`, ordered by restricted refinement.
54
+ :meth:`~Posets.SetPartitions` | Return the poset of set partitions of the set `\{1,\dots,n\}`.
55
+ :meth:`~Posets.ShardPoset` | Return the shard intersection order.
56
+ :meth:`~Posets.SSTPoset` | Return the poset on semistandard tableaux of shape `s` and largest entry `f` that is ordered by componentwise comparison.
57
+ :meth:`~Posets.StandardExample` | Return the standard example of a poset with dimension `n`.
58
+ :meth:`~Posets.SymmetricGroupAbsoluteOrderPoset` | The poset of permutations with respect to absolute order.
59
+ :meth:`~Posets.SymmetricGroupBruhatIntervalPoset` | The poset of permutations with respect to Bruhat order.
60
+ :meth:`~Posets.SymmetricGroupBruhatOrderPoset` | The poset of permutations with respect to Bruhat order.
61
+ :meth:`~Posets.SymmetricGroupWeakOrderPoset` | The poset of permutations of `\{ 1, 2, \ldots, n \}` with respect to the weak order.
62
+ :meth:`~Posets.TamariLattice` | Return the Tamari lattice.
63
+ :meth:`~Posets.TetrahedralPoset` | Return the Tetrahedral poset with `n-1` layers based on the input colors.
64
+ :meth:`~Posets.UpDownPoset` | Return the up-down poset on `n` elements.
65
+ :meth:`~Posets.YoungDiagramPoset` | Return the poset of cells in the Young diagram of a partition.
66
+ :meth:`~Posets.YoungsLattice` | Return Young's Lattice up to rank `n`.
67
+ :meth:`~Posets.YoungsLatticePrincipalOrderIdeal` | Return the principal order ideal of the partition `lam` in Young's Lattice.
68
+ :meth:`~Posets.YoungFibonacci` | Return the Young-Fibonacci lattice up to rank `n`.
69
+
70
+ **Other available posets:**
71
+
72
+ .. csv-table::
73
+ :class: contentstable
74
+ :widths: 30, 70
75
+ :delim: |
76
+
77
+ :meth:`~sage.geometry.polyhedron.base4.Polyhedron_base4.face_lattice` | Return the face lattice of a polyhedron.
78
+ :meth:`~sage.geometry.polyhedron.combinatorial_polyhedron.base.CombinatorialPolyhedron.face_lattice` | Return the face lattice of a combinatorial polyhedron.
79
+
80
+ Constructions
81
+ -------------
82
+ """
83
+ # ****************************************************************************
84
+ # Copyright (C) 2008 Peter Jipsen <jipsen@chapman.edu>,
85
+ # Franco Saliola <saliola@gmail.com>
86
+ #
87
+ # Distributed under the terms of the GNU General Public License (GPL)
88
+ #
89
+ # This code is distributed in the hope that it will be useful,
90
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
91
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
92
+ # General Public License for more details.
93
+ #
94
+ # The full text of the GPL is available at:
95
+ #
96
+ # https://www.gnu.org/licenses/
97
+ # ****************************************************************************
98
+
99
+ from sage.misc.classcall_metaclass import ClasscallMetaclass
100
+ import sage.categories.posets
101
+ from sage.combinat.permutation import Permutations, Permutation, to_standard
102
+ from sage.combinat.posets.posets import Poset, FinitePoset, FinitePosets_n
103
+ from sage.combinat.posets.d_complete import DCompletePoset
104
+ from sage.combinat.posets.mobile import MobilePoset as Mobile
105
+ from sage.combinat.posets.lattices import (LatticePoset, MeetSemilattice,
106
+ JoinSemilattice, FiniteLatticePoset)
107
+ from sage.categories.finite_posets import FinitePosets
108
+ from sage.categories.finite_lattice_posets import FiniteLatticePosets
109
+ from sage.graphs.digraph import DiGraph
110
+ from sage.rings.integer import Integer
111
+ from sage.sets.non_negative_integers import NonNegativeIntegers
112
+
113
+
114
+ def check_int(n, minimum=0):
115
+ """
116
+ Check that ``n`` is an integer at least equal to ``minimum``.
117
+
118
+ This is a boilerplate function ensuring input safety.
119
+
120
+ INPUT:
121
+
122
+ - ``n`` -- anything
123
+
124
+ - ``minimum`` -- an optional integer (default: 0)
125
+
126
+ EXAMPLES::
127
+
128
+ sage: from sage.combinat.posets.poset_examples import check_int
129
+ sage: check_int(6, 3)
130
+ 6
131
+ sage: check_int(6)
132
+ 6
133
+
134
+ sage: check_int(-1)
135
+ Traceback (most recent call last):
136
+ ...
137
+ ValueError: number of elements must be a nonnegative integer, not -1
138
+
139
+ sage: check_int(1, 3)
140
+ Traceback (most recent call last):
141
+ ...
142
+ ValueError: number of elements must be an integer at least 3, not 1
143
+
144
+ sage: check_int('junk')
145
+ Traceback (most recent call last):
146
+ ...
147
+ ValueError: number of elements must be a nonnegative integer, not junk
148
+ """
149
+ if minimum == 0:
150
+ msg = "a nonnegative integer"
151
+ else:
152
+ msg = f"an integer at least {minimum}"
153
+ if n not in NonNegativeIntegers() or n < minimum:
154
+ raise ValueError("number of elements must be " + msg + f", not {n}")
155
+ return Integer(n)
156
+
157
+
158
+ class Posets(metaclass=ClasscallMetaclass):
159
+ r"""
160
+ A collection of posets and lattices.
161
+
162
+ EXAMPLES::
163
+
164
+ sage: posets.BooleanLattice(3)
165
+ Finite lattice containing 8 elements
166
+ sage: posets.ChainPoset(3)
167
+ Finite lattice containing 3 elements
168
+ sage: posets.RandomPoset(17,.15)
169
+ Finite poset containing 17 elements
170
+
171
+ The category of all posets::
172
+
173
+ sage: Posets()
174
+ Category of posets
175
+
176
+ The enumerated set of all posets on `3` elements, up to an
177
+ isomorphism::
178
+
179
+ sage: Posets(3)
180
+ Posets containing 3 elements
181
+
182
+ .. SEEALSO:: :class:`~sage.categories.posets.Posets`, :class:`FinitePosets`, :func:`Poset`
183
+
184
+ TESTS::
185
+
186
+ sage: P = Posets
187
+ sage: TestSuite(P).run()
188
+ """
189
+ @staticmethod
190
+ def __classcall__(cls, n=None):
191
+ r"""
192
+ Return either the category of all posets, or the finite
193
+ enumerated set of all finite posets on ``n`` elements up to an
194
+ isomorphism.
195
+
196
+ EXAMPLES::
197
+
198
+ sage: Posets()
199
+ Category of posets
200
+ sage: Posets(4)
201
+ Posets containing 4 elements
202
+ """
203
+ if n is None:
204
+ return sage.categories.posets.Posets()
205
+ n = check_int(n)
206
+ return FinitePosets_n(n)
207
+
208
+ @staticmethod
209
+ def BooleanLattice(n, facade=None, use_subsets=False):
210
+ r"""
211
+ Return the Boolean lattice containing `2^n` elements.
212
+
213
+ - ``n`` -- integer; number of elements will be `2^n`
214
+ - ``facade`` -- boolean; whether to make the returned poset a
215
+ facade poset (see :mod:`sage.categories.facade_sets`); the
216
+ default behaviour is the same as the default behaviour of
217
+ the :func:`~sage.combinat.posets.posets.Poset` constructor
218
+ - ``use_subsets`` -- boolean (default: ``False``); if ``True``,
219
+ then label the elements by subsets of `\{1, 2, \ldots, n\}`;
220
+ otherwise label the elements by `0, 1, 2, \ldots, 2^n-1`
221
+
222
+ EXAMPLES::
223
+
224
+ sage: posets.BooleanLattice(5)
225
+ Finite lattice containing 32 elements
226
+
227
+ sage: sorted(posets.BooleanLattice(2))
228
+ [0, 1, 2, 3]
229
+ sage: sorted(posets.BooleanLattice(2, use_subsets=True), key=list)
230
+ [{}, {1}, {1, 2}, {2}]
231
+
232
+ TESTS:
233
+
234
+ Check isomorphism::
235
+
236
+ sage: B5 = posets.BooleanLattice(5)
237
+ sage: B5S = posets.BooleanLattice(5, use_subsets=True)
238
+ sage: B5.is_isomorphic(B5S)
239
+ True
240
+
241
+ Check the corner cases::
242
+
243
+ sage: list(posets.BooleanLattice(0, use_subsets=True))
244
+ [{}]
245
+ sage: list(posets.BooleanLattice(1, use_subsets=True))
246
+ [{}, {1}]
247
+ """
248
+ n = check_int(n)
249
+ if n == 0:
250
+ if use_subsets:
251
+ from sage.sets.set import Set
252
+ return LatticePoset(([Set()], []), facade=facade)
253
+ return LatticePoset(([0], []), facade=facade)
254
+ if n == 1:
255
+ if use_subsets:
256
+ from sage.sets.set import Set
257
+ V = [Set(), Set([1])]
258
+ return LatticePoset((V, [V]), facade=facade)
259
+ return LatticePoset(([0, 1], [[0, 1]]), facade=facade)
260
+
261
+ if use_subsets:
262
+ from sage.sets.set import Set
263
+ cur_level = [frozenset(range(1, n + 1))]
264
+ D = DiGraph()
265
+ D.add_vertex(Set(cur_level[0]))
266
+ while cur_level:
267
+ next_level = set()
268
+ for X in cur_level:
269
+ for i in X:
270
+ Y = X.difference([i])
271
+ D.add_edge(Set(Y), Set(X))
272
+ next_level.add(Y)
273
+ cur_level = next_level
274
+ return FiniteLatticePoset(D, category=FiniteLatticePosets(),
275
+ facade=facade)
276
+
277
+ D = DiGraph({v: [Integer(v | (1 << y))
278
+ for y in range(n) if v & (1 << y) == 0]
279
+ for v in range(2**n)})
280
+ return FiniteLatticePoset(hasse_diagram=D,
281
+ category=FiniteLatticePosets(),
282
+ facade=facade)
283
+
284
+ @staticmethod
285
+ def ChainPoset(n, facade=None):
286
+ r"""
287
+ Return a chain (a totally ordered poset) containing `n` elements.
288
+
289
+ - ``n`` -- integer; number of elements
290
+ - ``facade`` -- boolean; whether to make the returned poset a
291
+ facade poset (see :mod:`sage.categories.facade_sets`); the
292
+ default behaviour is the same as the default behaviour of
293
+ the :func:`~sage.combinat.posets.posets.Poset` constructor
294
+
295
+ EXAMPLES::
296
+
297
+ sage: C = posets.ChainPoset(6); C
298
+ Finite lattice containing 6 elements
299
+ sage: C.linear_extension()
300
+ [0, 1, 2, 3, 4, 5]
301
+
302
+ TESTS::
303
+
304
+ sage: for i in range(5):
305
+ ....: for j in range(5):
306
+ ....: if C.covers(C(i),C(j)) and j != i+1:
307
+ ....: print("TEST FAILED")
308
+
309
+ Check that :issue:`8422` is solved::
310
+
311
+ sage: posets.ChainPoset(0)
312
+ Finite lattice containing 0 elements
313
+ sage: C = posets.ChainPoset(1); C
314
+ Finite lattice containing 1 elements
315
+ sage: C.cover_relations()
316
+ []
317
+ sage: C = posets.ChainPoset(2); C
318
+ Finite lattice containing 2 elements
319
+ sage: C.cover_relations()
320
+ [[0, 1]]
321
+ """
322
+ n = check_int(n)
323
+ D = DiGraph([range(n), [[x, x + 1] for x in range(n - 1)]],
324
+ format='vertices_and_edges')
325
+ return FiniteLatticePoset(hasse_diagram=D,
326
+ category=FiniteLatticePosets(),
327
+ facade=facade)
328
+
329
+ @staticmethod
330
+ def AntichainPoset(n, facade=None):
331
+ """
332
+ Return an antichain (a poset with no comparable elements)
333
+ containing `n` elements.
334
+
335
+ INPUT:
336
+
337
+ - ``n`` -- integer; number of elements
338
+ - ``facade`` -- boolean; whether to make the returned poset a
339
+ facade poset (see :mod:`sage.categories.facade_sets`); the
340
+ default behaviour is the same as the default behaviour of
341
+ the :func:`~sage.combinat.posets.posets.Poset` constructor
342
+
343
+ EXAMPLES::
344
+
345
+ sage: A = posets.AntichainPoset(6); A
346
+ Finite poset containing 6 elements
347
+
348
+ TESTS::
349
+
350
+ sage: for i in range(5):
351
+ ....: for j in range(5):
352
+ ....: if A.covers(A(i),A(j)):
353
+ ....: print("TEST FAILED")
354
+
355
+ TESTS:
356
+
357
+ Check that :issue:`8422` is solved::
358
+
359
+ sage: posets.AntichainPoset(0)
360
+ Finite poset containing 0 elements
361
+ sage: C = posets.AntichainPoset(1); C
362
+ Finite poset containing 1 elements
363
+ sage: C.cover_relations()
364
+ []
365
+ sage: C = posets.AntichainPoset(2); C
366
+ Finite poset containing 2 elements
367
+ sage: C.cover_relations()
368
+ []
369
+ """
370
+ n = check_int(n)
371
+ return Poset((range(n), []), facade=facade)
372
+
373
+ @staticmethod
374
+ def PentagonPoset(facade=None):
375
+ """
376
+ Return the Pentagon poset.
377
+
378
+ INPUT:
379
+
380
+ - ``facade`` -- boolean; whether to make the returned poset a
381
+ facade poset (see :mod:`sage.categories.facade_sets`); the
382
+ default behaviour is the same as the default behaviour of
383
+ the :func:`~sage.combinat.posets.posets.Poset` constructor
384
+
385
+ EXAMPLES::
386
+
387
+ sage: P = posets.PentagonPoset(); P
388
+ Finite lattice containing 5 elements
389
+ sage: P.cover_relations()
390
+ [[0, 1], [0, 2], [1, 4], [2, 3], [3, 4]]
391
+
392
+ TESTS:
393
+
394
+ This is smallest lattice that is not modular::
395
+
396
+ sage: P.is_modular()
397
+ False
398
+
399
+ This poset and the :meth:`DiamondPoset` are the two smallest
400
+ lattices which are not distributive::
401
+
402
+ sage: P.is_distributive()
403
+ False
404
+ sage: posets.DiamondPoset(5).is_distributive()
405
+ False
406
+ """
407
+ return LatticePoset([[1, 2], [4], [3], [4], []], facade=facade)
408
+
409
+ @staticmethod
410
+ def DiamondPoset(n, facade=None):
411
+ """
412
+ Return the lattice of rank two containing ``n`` elements.
413
+
414
+ INPUT:
415
+
416
+ - ``n`` -- number of elements, an integer at least 3
417
+
418
+ - ``facade`` -- boolean; whether to make the returned poset a
419
+ facade poset (see :mod:`sage.categories.facade_sets`); the
420
+ default behaviour is the same as the default behaviour of
421
+ the :func:`~sage.combinat.posets.posets.Poset` constructor
422
+
423
+ EXAMPLES::
424
+
425
+ sage: posets.DiamondPoset(7)
426
+ Finite lattice containing 7 elements
427
+ """
428
+ n = check_int(n, 3)
429
+ c = [[n - 1] for x in range(n)]
430
+ c[0] = list(range(1, n - 1))
431
+ c[n - 1] = []
432
+ D = DiGraph({v: c[v] for v in range(n)}, format='dict_of_lists')
433
+ return FiniteLatticePoset(hasse_diagram=D,
434
+ category=FiniteLatticePosets(),
435
+ facade=facade)
436
+
437
+ @staticmethod
438
+ def Crown(n, facade=None):
439
+ r"""
440
+ Return the crown poset of `2n` elements.
441
+
442
+ In this poset every element `i` for `0 \leq i \leq n-1`
443
+ is covered by elements `i+n` and `i+n+1`, except that
444
+ `n-1` is covered by `n` and `n+1`.
445
+
446
+ INPUT:
447
+
448
+ - ``n`` -- number of elements, an integer at least 2
449
+
450
+ - ``facade`` -- boolean; whether to make the returned poset a
451
+ facade poset (see :mod:`sage.categories.facade_sets`); the
452
+ default behaviour is the same as the default behaviour of
453
+ the :func:`~sage.combinat.posets.posets.Poset` constructor
454
+
455
+ EXAMPLES::
456
+
457
+ sage: posets.Crown(3)
458
+ Finite poset containing 6 elements
459
+ """
460
+ n = check_int(n, 2)
461
+ D = {i: [i + n, i + n + 1] for i in range(n - 1)}
462
+ D[n - 1] = [n, n + n - 1]
463
+ return FinitePoset(hasse_diagram=DiGraph(D), category=FinitePosets(),
464
+ facade=facade)
465
+
466
+ @staticmethod
467
+ def DivisorLattice(n, facade=None):
468
+ """
469
+ Return the divisor lattice of an integer.
470
+
471
+ Elements of the lattice are divisors of `n` and `x < y` in the
472
+ lattice if `x` divides `y`.
473
+
474
+ INPUT:
475
+
476
+ - ``n`` -- integer
477
+ - ``facade`` -- boolean; whether to make the returned poset a
478
+ facade poset (see :mod:`sage.categories.facade_sets`); the
479
+ default behaviour is the same as the default behaviour of
480
+ the :func:`~sage.combinat.posets.posets.Poset` constructor
481
+
482
+ EXAMPLES::
483
+
484
+ sage: P = posets.DivisorLattice(12)
485
+ sage: sorted(P.cover_relations())
486
+ [[1, 2], [1, 3], [2, 4], [2, 6], [3, 6], [4, 12], [6, 12]]
487
+
488
+ sage: P = posets.DivisorLattice(10, facade=False)
489
+ sage: P(2) < P(5)
490
+ False
491
+
492
+ TESTS::
493
+
494
+ sage: posets.DivisorLattice(1)
495
+ Finite lattice containing 1 elements with distinguished linear extension
496
+ """
497
+ from sage.arith.misc import divisors, is_prime
498
+ n = check_int(n, 1)
499
+ Div_n = divisors(n)
500
+ hasse = DiGraph([Div_n, lambda a, b: b % a == 0 and is_prime(b // a)])
501
+ return FiniteLatticePoset(hasse, elements=Div_n, facade=facade,
502
+ category=FiniteLatticePosets())
503
+
504
+ @staticmethod
505
+ def IntegerCompositions(n):
506
+ """
507
+ Return the poset of integer compositions of the integer ``n``.
508
+
509
+ A composition of a positive integer `n` is a list of positive
510
+ integers that sum to `n`. The order is reverse refinement:
511
+ `[p_1,p_2,...,p_l] < [q_1,q_2,...,q_m]` if `q` consists
512
+ of an integer composition of `p_1`, followed by an integer
513
+ composition of `p_2`, and so on.
514
+
515
+ EXAMPLES::
516
+
517
+ sage: P = posets.IntegerCompositions(7); P
518
+ Finite poset containing 64 elements
519
+ sage: len(P.cover_relations())
520
+ 192
521
+ """
522
+ from sage.combinat.composition import Compositions
523
+ C = Compositions(n)
524
+ return Poset((C, [[c, d] for c in C for d in C if d.is_finer(c)]),
525
+ cover_relations=False)
526
+
527
+ @staticmethod
528
+ def IntegerPartitions(n):
529
+ """
530
+ Return the poset of integer partitions on the integer ``n``.
531
+
532
+ A partition of a positive integer `n` is a non-increasing list
533
+ of positive integers that sum to `n`. If `p` and `q` are
534
+ integer partitions of `n`, then `p` covers `q` if and only
535
+ if `q` is obtained from `p` by joining two parts of `p`
536
+ (and sorting, if necessary).
537
+
538
+ EXAMPLES::
539
+
540
+ sage: P = posets.IntegerPartitions(7); P
541
+ Finite poset containing 15 elements
542
+ sage: len(P.cover_relations())
543
+ 28
544
+ """
545
+ def lower_covers(partition):
546
+ r"""
547
+ Nested function for computing the lower covers
548
+ of elements in the poset of integer partitions.
549
+ """
550
+ lc = []
551
+ for i in range(len(partition) - 1):
552
+ for j in range(i + 1, len(partition)):
553
+ new_partition = partition[:]
554
+ del new_partition[j]
555
+ del new_partition[i]
556
+ new_partition.append(partition[i] + partition[j])
557
+ new_partition.sort(reverse=True)
558
+ tup = tuple(new_partition)
559
+ if tup not in lc:
560
+ lc.append(tup)
561
+ return lc
562
+ from sage.combinat.partition import Partitions
563
+ H = DiGraph(dict([[tuple(p), lower_covers(p)] for p in Partitions(n)]))
564
+ return Poset(H.reverse())
565
+
566
+ @staticmethod
567
+ def RestrictedIntegerPartitions(n):
568
+ """
569
+ Return the poset of integer partitions on the integer `n`
570
+ ordered by restricted refinement.
571
+
572
+ That is, if `p` and `q` are integer partitions of `n`, then
573
+ `p` covers `q` if and only if `q` is obtained from `p` by
574
+ joining two distinct parts of `p` (and sorting, if necessary).
575
+
576
+ EXAMPLES::
577
+
578
+ sage: P = posets.RestrictedIntegerPartitions(7); P
579
+ Finite poset containing 15 elements
580
+ sage: len(P.cover_relations())
581
+ 17
582
+ """
583
+ def lower_covers(partition):
584
+ r"""
585
+ Nested function for computing the lower covers of elements in the
586
+ restricted poset of integer partitions.
587
+ """
588
+ lc = []
589
+ for i in range(len(partition) - 1):
590
+ for j in range(i + 1, len(partition)):
591
+ if partition[i] != partition[j]:
592
+ new_partition = partition[:]
593
+ del new_partition[j]
594
+ del new_partition[i]
595
+ new_partition.append(partition[i] + partition[j])
596
+ new_partition.sort(reverse=True)
597
+ tup = tuple(new_partition)
598
+ if tup not in lc:
599
+ lc.append(tup)
600
+ return lc
601
+ from sage.combinat.partition import Partitions
602
+ H = DiGraph(dict([[tuple(p), lower_covers(p)] for p in Partitions(n)]))
603
+ return Poset(H.reverse())
604
+
605
+ @staticmethod
606
+ def IntegerPartitionsDominanceOrder(n):
607
+ r"""
608
+ Return the lattice of integer partitions on the integer `n`
609
+ ordered by dominance.
610
+
611
+ That is, if `p=(p_1,\ldots,p_i)` and `q=(q_1,\ldots,q_j)` are
612
+ integer partitions of `n`, then `p` is greater than `q` if and
613
+ only if `p_1+\cdots+p_k > q_1+\cdots+q_k` for all `k`.
614
+
615
+ INPUT:
616
+
617
+ - ``n`` -- positive integer
618
+
619
+ EXAMPLES::
620
+
621
+ sage: P = posets.IntegerPartitionsDominanceOrder(6); P
622
+ Finite lattice containing 11 elements
623
+ sage: P.cover_relations()
624
+ [[[1, 1, 1, 1, 1, 1], [2, 1, 1, 1, 1]],
625
+ [[2, 1, 1, 1, 1], [2, 2, 1, 1]],
626
+ [[2, 2, 1, 1], [2, 2, 2]],
627
+ [[2, 2, 1, 1], [3, 1, 1, 1]],
628
+ [[2, 2, 2], [3, 2, 1]],
629
+ [[3, 1, 1, 1], [3, 2, 1]],
630
+ [[3, 2, 1], [3, 3]],
631
+ [[3, 2, 1], [4, 1, 1]],
632
+ [[3, 3], [4, 2]],
633
+ [[4, 1, 1], [4, 2]],
634
+ [[4, 2], [5, 1]],
635
+ [[5, 1], [6]]]
636
+ """
637
+ n = check_int(n)
638
+ from sage.combinat.partition import Partitions, Partition
639
+ return LatticePoset((Partitions(n), Partition.dominates)).dual()
640
+
641
+ @staticmethod
642
+ def PowerPoset(n):
643
+ r"""
644
+ Return the power poset on `n` element posets.
645
+
646
+ Elements of the power poset are all posets on
647
+ the set `\{0, 1, \ldots, n-1\}` ordered by extension.
648
+ That is, the antichain of `n` elements is the bottom and
649
+ `P_a \le P_b` in the power poset if `P_b` is an extension
650
+ of `P_a`.
651
+
652
+ These were studied in [Bru1994]_.
653
+
654
+ EXAMPLES::
655
+
656
+ sage: P3 = posets.PowerPoset(3); P3
657
+ Finite meet-semilattice containing 19 elements
658
+ sage: all(P.is_chain() for P in P3.maximal_elements())
659
+ True
660
+
661
+ TESTS::
662
+
663
+ sage: P0 = posets.PowerPoset(0); P0
664
+ Finite meet-semilattice containing 1 elements
665
+ sage: P0[0]
666
+ Finite poset containing 0 elements
667
+ sage: P1 = posets.PowerPoset(1); P1
668
+ Finite meet-semilattice containing 1 elements
669
+ sage: P1[0]
670
+ Finite poset containing 1 elements
671
+ sage: P1[0][0]
672
+ 0
673
+ """
674
+ # Todo: Make this faster.
675
+ n = check_int(n)
676
+ all_pos_n = set()
677
+ Pn = list(Posets(n))
678
+ for P in Pn:
679
+ for r in Permutations(P):
680
+ all_pos_n.add(P.relabel(list(r)))
681
+
682
+ return MeetSemilattice((all_pos_n,
683
+ lambda A, B: all(B.is_lequal(x, y)
684
+ for x, y in A.cover_relations_iterator())))
685
+
686
+ @staticmethod
687
+ def ProductOfChains(chain_lengths, facade=None):
688
+ """
689
+ Return a product of chains.
690
+
691
+ - ``chain_lengths`` -- list of nonnegative integers; number of
692
+ elements in each chain
693
+
694
+ - ``facade`` -- boolean; whether to make the returned poset a
695
+ facade poset (see :mod:`sage.categories.facade_sets`); the
696
+ default behaviour is the same as the default behaviour of
697
+ the :func:`~sage.combinat.posets.posets.Poset` constructor
698
+
699
+ EXAMPLES::
700
+
701
+ sage: P = posets.ProductOfChains([2, 2]); P
702
+ Finite lattice containing 4 elements
703
+ sage: P.linear_extension()
704
+ [(0, 0), (0, 1), (1, 0), (1, 1)]
705
+ sage: P.upper_covers((0,0))
706
+ [(0, 1), (1, 0)]
707
+ sage: P.lower_covers((1,1))
708
+ [(0, 1), (1, 0)]
709
+
710
+ TESTS::
711
+
712
+ sage: P = posets.ProductOfChains([]); P
713
+ Finite lattice containing 0 elements
714
+ sage: P = posets.ProductOfChains([3, 0, 1]); P
715
+ Finite lattice containing 0 elements
716
+ sage: P = posets.ProductOfChains([1,1,1,1]); P
717
+ Finite lattice containing 1 elements
718
+ """
719
+ try:
720
+ l = [Integer(x) for x in chain_lengths]
721
+ except TypeError:
722
+ raise TypeError("parameter chain_lengths must be a list of integers, not {}".format(chain_lengths))
723
+ if any(x < 0 for x in l):
724
+ raise TypeError("parameter chain_lengths must be a list of nonnegative integers, not {}".format(l))
725
+
726
+ # given the empty list, we expect the empty poset.
727
+ if not chain_lengths:
728
+ return LatticePoset(facade=facade)
729
+ from sage.categories.cartesian_product import cartesian_product
730
+ elements = cartesian_product([range(i) for i in l])
731
+
732
+ def compare(a, b):
733
+ return all(x <= y for x, y in zip(a, b))
734
+ return LatticePoset([elements, compare], facade=facade)
735
+
736
+ @staticmethod
737
+ def RandomPoset(n, p):
738
+ r"""
739
+ Generate a random poset on ``n`` elements according to a
740
+ probability ``p``.
741
+
742
+ INPUT:
743
+
744
+ - ``n`` -- number of elements, a nonnegative integer
745
+
746
+ - ``p`` -- a probability, a real number between 0 and 1 (inclusive)
747
+
748
+ OUTPUT:
749
+
750
+ A poset on `n` elements. The probability `p` roughly measures
751
+ width/height of the output: `p=0` always generates an antichain,
752
+ `p=1` will return a chain. To create interesting examples,
753
+ keep the probability small, perhaps on the order of `1/n`.
754
+
755
+ EXAMPLES::
756
+
757
+ sage: set_random_seed(0) # Results are reproducible
758
+ sage: P = posets.RandomPoset(5, 0.3)
759
+ sage: P.cover_relations()
760
+ [[5, 4], [4, 2], [1, 2]]
761
+
762
+ .. SEEALSO:: :meth:`RandomLattice`
763
+
764
+ TESTS::
765
+
766
+ sage: posets.RandomPoset(6, 'garbage')
767
+ Traceback (most recent call last):
768
+ ...
769
+ TypeError: probability must be a real number, not garbage
770
+
771
+ sage: posets.RandomPoset(6, -0.5)
772
+ Traceback (most recent call last):
773
+ ...
774
+ ValueError: probability must be between 0 and 1, not -0.5
775
+
776
+ sage: posets.RandomPoset(0, 0.5)
777
+ Finite poset containing 0 elements
778
+ """
779
+ from sage.misc.prandom import random
780
+ n = check_int(n)
781
+ try:
782
+ p = float(p)
783
+ except (TypeError, ValueError):
784
+ raise TypeError(f"probability must be a real number, not {p}")
785
+ if p < 0 or p > 1:
786
+ raise ValueError(f"probability must be between 0 and 1, not {p}")
787
+
788
+ D = DiGraph(loops=False, multiedges=False)
789
+ D.add_vertices(range(n))
790
+ for i in range(n):
791
+ for j in range(i + 1, n):
792
+ if random() < p:
793
+ D.add_edge(i, j)
794
+ D.relabel(list(Permutations(n).random_element()))
795
+ return Poset(D, cover_relations=False)
796
+
797
+ @staticmethod
798
+ def RandomLattice(n, p, properties=None):
799
+ r"""
800
+ Return a random lattice on ``n`` elements.
801
+
802
+ INPUT:
803
+
804
+ - ``n`` -- number of elements, a nonnegative integer
805
+
806
+ - ``p`` -- a probability, a positive real number less than one
807
+
808
+ - ``properties`` -- list of properties for the lattice. Currently
809
+ implemented:
810
+
811
+ * ``None``, no restrictions for lattices to create
812
+ * ``'planar'``, the lattice has an upward planar drawing
813
+ * ``'dismantlable'`` (implicated by ``'planar'``)
814
+ * ``'distributive'`` (implicated by ``'stone'``)
815
+ * ``'stone'``
816
+
817
+ OUTPUT:
818
+
819
+ A lattice on `n` elements. When ``properties`` is ``None``,
820
+ the probability `p` roughly measures number of covering
821
+ relations of the lattice. To create interesting examples, make
822
+ the probability a little below one, for example `0.9`.
823
+
824
+ Currently parameter ``p`` has no effect only when ``properties``
825
+ is not ``None``.
826
+
827
+ .. NOTE::
828
+
829
+ Results are reproducible in same Sage version only. Underlying
830
+ algorithm may change in future versions.
831
+
832
+ EXAMPLES::
833
+
834
+ sage: set_random_seed(0) # Results are reproducible
835
+ sage: L = posets.RandomLattice(8, 0.995); L
836
+ Finite lattice containing 8 elements
837
+ sage: L.cover_relations()
838
+ [[7, 6], [7, 3], [7, 1], ..., [5, 4], [2, 4], [1, 4], [0, 4]]
839
+ sage: L = posets.RandomLattice(10, 0, properties=['dismantlable'])
840
+ sage: L.is_dismantlable()
841
+ True
842
+
843
+ .. SEEALSO:: :meth:`RandomPoset`
844
+
845
+ TESTS::
846
+
847
+ sage: posets.RandomLattice(6, 'garbage')
848
+ Traceback (most recent call last):
849
+ ...
850
+ TypeError: probability must be a real number, not garbage
851
+
852
+ sage: posets.RandomLattice(6, -0.5)
853
+ Traceback (most recent call last):
854
+ ...
855
+ ValueError: probability must be a positive real number and below 1, not -0.5
856
+
857
+ sage: posets.RandomLattice(10, 0.5, properties=['junk'])
858
+ Traceback (most recent call last):
859
+ ...
860
+ ValueError: unknown value junk for 'properties'
861
+
862
+ sage: posets.RandomLattice(0, 0.5)
863
+ Finite lattice containing 0 elements
864
+ """
865
+ from copy import copy
866
+ n = check_int(n)
867
+ try:
868
+ p = float(p)
869
+ except Exception:
870
+ raise TypeError(f"probability must be a real number, not {p}")
871
+ if p < 0 or p >= 1:
872
+ raise ValueError("probability must be a positive real number and below 1, not {}".format(p))
873
+
874
+ if properties is None:
875
+ # Basic case, no special properties for lattice asked.
876
+ if n <= 3:
877
+ return posets.ChainPoset(n)
878
+ covers = _random_lattice(n, p)
879
+ covers_dict = {i: covers[i] for i in range(n)}
880
+ D = DiGraph(covers_dict)
881
+ D.relabel([i - 1 for i in Permutations(n).random_element()])
882
+ return LatticePoset(D, cover_relations=True)
883
+
884
+ if isinstance(properties, str):
885
+ properties = {properties}
886
+ else:
887
+ properties = set(properties)
888
+
889
+ known_properties = {'planar', 'dismantlable', 'distributive', 'stone'}
890
+ errors = properties.difference(known_properties)
891
+ if errors:
892
+ raise ValueError("unknown value %s for 'properties'" % errors.pop())
893
+
894
+ if n <= 3:
895
+ # Change this, if property='complemented' is added
896
+ return posets.ChainPoset(n)
897
+
898
+ # Handling properties: planar => dismantlable, stone => distributive
899
+ if 'planar' in properties:
900
+ properties.discard('dismantlable')
901
+ if 'stone' in properties:
902
+ properties.discard('distributive')
903
+
904
+ # Test property combinations that are not implemented.
905
+ if 'distributive' in properties and len(properties) > 1:
906
+ raise NotImplementedError("combining 'distributive' with other properties is not implemented")
907
+ if 'stone' in properties and len(properties) > 1:
908
+ raise NotImplementedError("combining 'stone' with other properties is not implemented")
909
+
910
+ if properties == {'planar'}:
911
+ D = _random_planar_lattice(n)
912
+ D.relabel([i - 1 for i in Permutations(n).random_element()])
913
+ return LatticePoset(D)
914
+
915
+ if properties == {'dismantlable'}:
916
+ D = _random_dismantlable_lattice(n)
917
+ D.relabel([i - 1 for i in Permutations(n).random_element()])
918
+ return LatticePoset(D)
919
+
920
+ if properties == {'stone'}:
921
+ D = _random_stone_lattice(n)
922
+ D.relabel([i - 1 for i in Permutations(n).random_element()])
923
+ return LatticePoset(D)
924
+
925
+ if properties == {'distributive'}:
926
+ tmp = Poset(_random_distributive_lattice(n)).order_ideals_lattice(as_ideals=False)
927
+ D = copy(tmp._hasse_diagram)
928
+ D.relabel([i - 1 for i in Permutations(n).random_element()])
929
+ return LatticePoset(D)
930
+
931
+ raise AssertionError("bug in RandomLattice()")
932
+
933
+ @staticmethod
934
+ def SetPartitions(n):
935
+ r"""
936
+ Return the lattice of set partitions of the set `\{1,\ldots,n\}`
937
+ ordered by refinement.
938
+
939
+ INPUT:
940
+
941
+ - ``n`` -- positive integer
942
+
943
+ EXAMPLES::
944
+
945
+ sage: posets.SetPartitions(4)
946
+ Finite lattice containing 15 elements
947
+ """
948
+ from sage.combinat.set_partition import SetPartitions
949
+ n = check_int(n)
950
+ S = SetPartitions(n)
951
+
952
+ def covers(x):
953
+ for i, s in enumerate(x):
954
+ for j in range(i + 1, len(x)):
955
+ L = list(x)
956
+ L[i] = s.union(x[j])
957
+ L.pop(j)
958
+ yield S(L)
959
+
960
+ return LatticePoset({x: list(covers(x)) for x in S},
961
+ cover_relations=True)
962
+
963
+ @staticmethod
964
+ def SSTPoset(s, f=None):
965
+ """
966
+ The lattice poset on semistandard tableaux of shape ``s`` and largest
967
+ entry ``f`` that is ordered by componentwise comparison of the
968
+ entries.
969
+
970
+ INPUT:
971
+
972
+ - ``s`` -- shape of the tableaux
973
+
974
+ - ``f`` -- integer (default: ``None``); the maximum fill number.
975
+ By default (``None``), the method uses the number of cells in the shape.
976
+
977
+ .. NOTE::
978
+
979
+ This is a basic implementation and most certainly
980
+ not the most efficient.
981
+
982
+ EXAMPLES::
983
+
984
+ sage: posets.SSTPoset([2,1])
985
+ Finite lattice containing 8 elements
986
+
987
+ sage: posets.SSTPoset([2,1],4)
988
+ Finite lattice containing 20 elements
989
+
990
+ sage: posets.SSTPoset([2,1],2).cover_relations()
991
+ [[[[1, 1], [2]], [[1, 2], [2]]]]
992
+
993
+ sage: posets.SSTPoset([3,2]).bottom() # long time (6s on sage.math, 2012)
994
+ [[1, 1, 1], [2, 2]]
995
+
996
+ sage: posets.SSTPoset([3,2],4).maximal_elements()
997
+ [[[3, 3, 4], [4, 4]]]
998
+ """
999
+ from sage.combinat.tableau import SemistandardTableaux
1000
+
1001
+ def tableaux_is_less_than(a, b):
1002
+ return all(ix <= iy for x, y in zip(a, b) for ix, iy in zip(x, y))
1003
+
1004
+ if f is None:
1005
+ f = sum(s)
1006
+ E = SemistandardTableaux(s, max_entry=f)
1007
+ return LatticePoset((E, tableaux_is_less_than))
1008
+
1009
+ @staticmethod
1010
+ def StandardExample(n, facade=None):
1011
+ r"""
1012
+ Return the partially ordered set on `2n` elements with
1013
+ dimension `n`.
1014
+
1015
+ Let `P` be the poset on `\{0, 1, 2, \ldots, 2n-1\}` whose defining
1016
+ relations are that `i < j` for every `0 \leq i < n \leq j < 2n`
1017
+ except when `i + n = j`. The poset `P` is the so-called
1018
+ *standard example* of a poset with dimension `n`.
1019
+
1020
+ INPUT:
1021
+
1022
+ - ``n`` -- integer `\ge 2`; dimension of the constructed poset
1023
+
1024
+ - ``facade`` -- boolean; whether to make the returned poset a
1025
+ facade poset (see :mod:`sage.categories.facade_sets`); the
1026
+ default behaviour is the same as the default behaviour of
1027
+ the :func:`~sage.combinat.posets.posets.Poset` constructor
1028
+
1029
+ OUTPUT: the standard example of a poset of dimension `n`
1030
+
1031
+ EXAMPLES::
1032
+
1033
+ sage: A = posets.StandardExample(3); A
1034
+ Finite poset containing 6 elements
1035
+ sage: A.dimension() # needs networkx
1036
+ 3
1037
+
1038
+ REFERENCES:
1039
+
1040
+ - [Gar2015]_
1041
+ - [Ros1999]_
1042
+
1043
+ TESTS::
1044
+
1045
+ sage: A = posets.StandardExample(10); A
1046
+ Finite poset containing 20 elements
1047
+ sage: len(A.cover_relations())
1048
+ 90
1049
+
1050
+ sage: P = posets.StandardExample(5, facade=False)
1051
+ sage: P(4) < P(3), P(4) > P(3)
1052
+ (False, False)
1053
+ """
1054
+ n = check_int(n, 2)
1055
+ return Poset((range(2 * n), [[i, j + n] for i in range(n)
1056
+ for j in range(n) if i != j]),
1057
+ facade=facade)
1058
+
1059
+ @staticmethod
1060
+ def SymmetricGroupBruhatOrderPoset(n):
1061
+ """
1062
+ The poset of permutations with respect to Bruhat order.
1063
+
1064
+ EXAMPLES::
1065
+
1066
+ sage: posets.SymmetricGroupBruhatOrderPoset(4)
1067
+ Finite poset containing 24 elements
1068
+ """
1069
+ if n < 10:
1070
+ element_labels = {s: "".join(str(x) for x in s)
1071
+ for s in Permutations(n)}
1072
+ return Poset({s: s.bruhat_succ() for s in Permutations(n)},
1073
+ element_labels)
1074
+
1075
+ @staticmethod
1076
+ def SymmetricGroupBruhatIntervalPoset(start, end):
1077
+ """
1078
+ The poset of permutations with respect to Bruhat order.
1079
+
1080
+ INPUT:
1081
+
1082
+ - ``start`` -- list permutation
1083
+
1084
+ - ``end`` -- list permutation (same n, of course)
1085
+
1086
+ .. NOTE::
1087
+
1088
+ Must have ``start`` <= ``end``.
1089
+
1090
+ EXAMPLES:
1091
+
1092
+ Any interval is rank symmetric if and only if it avoids these
1093
+ permutations::
1094
+
1095
+ sage: P1 = posets.SymmetricGroupBruhatIntervalPoset([1,2,3,4], [3,4,1,2])
1096
+ sage: P2 = posets.SymmetricGroupBruhatIntervalPoset([1,2,3,4], [4,2,3,1])
1097
+ sage: ranks1 = [P1.rank(v) for v in P1]
1098
+ sage: ranks2 = [P2.rank(v) for v in P2]
1099
+ sage: [ranks1.count(i) for i in sorted(set(ranks1))]
1100
+ [1, 3, 5, 4, 1]
1101
+ sage: [ranks2.count(i) for i in sorted(set(ranks2))]
1102
+ [1, 3, 5, 6, 4, 1]
1103
+ """
1104
+ start = Permutation(start)
1105
+ end = Permutation(end)
1106
+ if len(start) != len(end):
1107
+ raise TypeError(f"start ({start}) and end ({end}) must have same length")
1108
+ if not start.bruhat_lequal(end):
1109
+ raise TypeError(f"must have start ({start}) <= end ({end}) in Bruhat order")
1110
+ unseen = [start]
1111
+ nodes = {}
1112
+ while unseen:
1113
+ perm = unseen.pop(0)
1114
+ nodes[perm] = [succ_perm for succ_perm in perm.bruhat_succ()
1115
+ if succ_perm.bruhat_lequal(end)]
1116
+ unseen.extend(succ_perm for succ_perm in nodes[perm]
1117
+ if succ_perm not in nodes)
1118
+ return Poset(nodes)
1119
+
1120
+ @staticmethod
1121
+ def SymmetricGroupWeakOrderPoset(n, labels='permutations', side='right'):
1122
+ r"""
1123
+ The poset of permutations of `\{ 1, 2, \ldots, n \}` with respect
1124
+ to the weak order (also known as the permutohedron order, cf.
1125
+ :meth:`~sage.combinat.permutation.Permutation.permutohedron_lequal`).
1126
+
1127
+ The optional variable ``labels`` (default: ``'permutations'``)
1128
+ determines the labelling of the elements if `n < 10`. The optional
1129
+ variable ``side`` (default: ``'right'``) determines whether the
1130
+ right or the left permutohedron order is to be used.
1131
+
1132
+ EXAMPLES::
1133
+
1134
+ sage: posets.SymmetricGroupWeakOrderPoset(4)
1135
+ Finite poset containing 24 elements
1136
+ """
1137
+ if n < 10 and labels == "permutations":
1138
+ element_labels = dict([[s, "".join(map(str, s))]
1139
+ for s in Permutations(n)])
1140
+ if n < 10 and labels == "reduced_words":
1141
+ element_labels = dict([[s, "".join(map(str, s.reduced_word_lexmin()))]
1142
+ for s in Permutations(n)])
1143
+ if side == "left":
1144
+
1145
+ def weak_covers(s):
1146
+ r"""
1147
+ Nested function for computing the covers of elements in the
1148
+ poset of left weak order for the symmetric group.
1149
+ """
1150
+ return [v for v in s.bruhat_succ() if
1151
+ s.length() + (s.inverse().right_action_product(v)).length() == v.length()]
1152
+ else:
1153
+ def weak_covers(s):
1154
+ r"""
1155
+ Nested function for computing the covers of elements in the
1156
+ poset of right weak order for the symmetric group.
1157
+ """
1158
+ return [v for v in s.bruhat_succ() if
1159
+ s.length() + (s.inverse().left_action_product(v)).length() == v.length()]
1160
+ return Poset(dict([[s, weak_covers(s)] for s in Permutations(n)]),
1161
+ element_labels)
1162
+
1163
+ @staticmethod
1164
+ def TetrahedralPoset(n, *colors, **labels):
1165
+ r"""
1166
+ Return the tetrahedral poset based on the input colors.
1167
+
1168
+ This method will return the tetrahedral poset with `n-1` layers and
1169
+ covering relations based on the input colors of 'green', 'red',
1170
+ 'orange', 'silver', 'yellow' and 'blue' as defined in [Striker2011]_.
1171
+ For particular color choices, the order ideals of the resulting
1172
+ tetrahedral poset will be isomorphic to known combinatorial objects.
1173
+
1174
+ For example, for the colors 'blue', 'yellow', 'orange', and 'green',
1175
+ the order ideals will be in bijection with alternating sign matrices.
1176
+ For the colors 'yellow', 'orange', and 'green', the order ideals will
1177
+ be in bijection with semistandard Young tableaux of staircase shape.
1178
+ For the colors 'red', 'orange', 'green', and optionally 'yellow', the
1179
+ order ideals will be in bijection with totally symmetric
1180
+ self-complementary plane partitions in a `2n \times 2n \times 2n` box.
1181
+
1182
+ INPUT:
1183
+
1184
+ - ``n`` -- defines the number (n-1) of layers in the poset
1185
+
1186
+ - ``colors`` -- the colors that define the covering relations of the
1187
+ poset; colors used are 'green', 'red', 'yellow', 'orange', 'silver',
1188
+ and 'blue'
1189
+
1190
+ - ``labels`` -- keyword variable used to determine whether the poset
1191
+ is labeled with integers or tuples. To label with integers, the
1192
+ method should be called with ``labels='integers'``. Otherwise, the
1193
+ labeling will default to tuples.
1194
+
1195
+ EXAMPLES::
1196
+
1197
+ sage: posets.TetrahedralPoset(4,'green','red','yellow','silver','blue','orange')
1198
+ Finite poset containing 10 elements
1199
+
1200
+ sage: posets.TetrahedralPoset(4,'green','red','yellow','silver','blue','orange',
1201
+ ....: labels='integers')
1202
+ Finite poset containing 10 elements
1203
+
1204
+ sage: A = AlternatingSignMatrices(3)
1205
+ sage: p = A.lattice()
1206
+ sage: ji = p.join_irreducibles_poset()
1207
+ sage: tet = posets.TetrahedralPoset(3, 'green','yellow','blue','orange')
1208
+ sage: ji.is_isomorphic(tet)
1209
+ True
1210
+
1211
+ TESTS::
1212
+
1213
+ sage: posets.TetrahedralPoset(4,'scarlet')
1214
+ Traceback (most recent call last):
1215
+ ...
1216
+ ValueError: color input must be among: 'green', 'red', 'yellow',
1217
+ 'orange', 'silver', and 'blue'
1218
+ """
1219
+ n = check_int(n, 2)
1220
+ n = n - 1
1221
+ for c in colors:
1222
+ if c not in ('green', 'red', 'yellow', 'orange', 'silver', 'blue'):
1223
+ raise ValueError("color input must be among: 'green', 'red', 'yellow', 'orange', 'silver', and 'blue'")
1224
+ elem = [(i, j, k) for i in range(n)
1225
+ for j in range(n - i) for k in range(n - i - j)]
1226
+ rels = []
1227
+ elem_labels = {}
1228
+ if 'labels' in labels:
1229
+ if labels['labels'] == 'integers':
1230
+ labelcount = 0
1231
+ for (i, j, k) in elem:
1232
+ elem_labels[(i, j, k)] = labelcount
1233
+ labelcount += 1
1234
+ for c in colors:
1235
+ for (i, j, k) in elem:
1236
+ if i + j + k < n - 1:
1237
+ if c == 'green':
1238
+ rels.append([(i, j, k), (i + 1, j, k)])
1239
+ if c == 'red':
1240
+ rels.append([(i, j, k), (i, j, k + 1)])
1241
+ if c == 'yellow':
1242
+ rels.append([(i, j, k), (i, j + 1, k)])
1243
+ if j < n - 1 and k > 0:
1244
+ if c == 'orange':
1245
+ rels.append([(i, j, k), (i, j + 1, k - 1)])
1246
+ if i < n - 1 and j > 0:
1247
+ if c == 'silver':
1248
+ rels.append([(i, j, k), (i + 1, j - 1, k)])
1249
+ if i < n - 1 and k > 0:
1250
+ if c == 'blue':
1251
+ rels.append([(i, j, k), (i + 1, j, k - 1)])
1252
+ return Poset([elem, rels], elem_labels)
1253
+
1254
+ # shard intersection order
1255
+ import sage.combinat.shard_order
1256
+ ShardPoset = staticmethod(sage.combinat.shard_order.shard_poset)
1257
+
1258
+ # Tamari lattices
1259
+ import sage.combinat.tamari_lattices
1260
+ TamariLattice = staticmethod(sage.combinat.tamari_lattices.TamariLattice)
1261
+ DexterSemilattice = staticmethod(sage.combinat.tamari_lattices.DexterSemilattice)
1262
+
1263
+ @staticmethod
1264
+ def CoxeterGroupAbsoluteOrderPoset(W, use_reduced_words=True):
1265
+ r"""
1266
+ Return the poset of elements of a Coxeter group with respect
1267
+ to absolute order.
1268
+
1269
+ INPUT:
1270
+
1271
+ - ``W`` -- a Coxeter group
1272
+ - ``use_reduced_words`` -- boolean (default: ``True``); if
1273
+ ``True``, then the elements are labeled by their lexicographically
1274
+ minimal reduced word
1275
+
1276
+ EXAMPLES::
1277
+
1278
+ sage: W = CoxeterGroup(['B', 3]) # needs sage.groups
1279
+ sage: posets.CoxeterGroupAbsoluteOrderPoset(W) # needs sage.groups
1280
+ Finite poset containing 48 elements
1281
+
1282
+ sage: W = WeylGroup(['B', 2], prefix='s') # needs sage.groups
1283
+ sage: posets.CoxeterGroupAbsoluteOrderPoset(W, False) # needs sage.groups
1284
+ Finite poset containing 8 elements
1285
+ """
1286
+ if use_reduced_words:
1287
+ element_labels = {s: tuple(s.reduced_word()) for s in W}
1288
+ return Poset({s: list(s.absolute_covers()) for s in W}, element_labels)
1289
+ return Poset({s: list(s.absolute_covers()) for s in W})
1290
+
1291
+ @staticmethod
1292
+ def NoncrossingPartitions(W):
1293
+ """
1294
+ Return the lattice of noncrossing partitions.
1295
+
1296
+ INPUT:
1297
+
1298
+ - ``W`` -- a finite Coxeter group or a Weyl group
1299
+
1300
+ EXAMPLES::
1301
+
1302
+ sage: W = CoxeterGroup(['A', 3]) # needs sage.groups
1303
+ sage: posets.NoncrossingPartitions(W) # needs sage.groups
1304
+ Finite lattice containing 14 elements
1305
+
1306
+ sage: W = WeylGroup(['B', 2], prefix='s') # needs sage.groups
1307
+ sage: posets.NoncrossingPartitions(W) # needs sage.groups
1308
+ Finite lattice containing 6 elements
1309
+ """
1310
+ return W.noncrossing_partition_lattice()
1311
+
1312
+ @staticmethod
1313
+ def SymmetricGroupAbsoluteOrderPoset(n, labels='permutations'):
1314
+ r"""
1315
+ Return the poset of permutations with respect to absolute order.
1316
+
1317
+ INPUT:
1318
+
1319
+ - ``n`` -- a positive integer
1320
+
1321
+ - ``label`` -- (default: ``'permutations'``) a label for the elements
1322
+ of the poset returned by the function; the options are
1323
+
1324
+ * ``'permutations'`` -- labels the elements by their
1325
+ one-line notation
1326
+ * ``'reduced_words'`` -- labels the elements by the
1327
+ lexicographically minimal reduced word
1328
+ * ``'cycles'`` -- labels the elements by their expression
1329
+ as a product of cycles
1330
+
1331
+ EXAMPLES::
1332
+
1333
+ sage: posets.SymmetricGroupAbsoluteOrderPoset(4) # needs sage.groups
1334
+ Finite poset containing 24 elements
1335
+ sage: posets.SymmetricGroupAbsoluteOrderPoset(3, labels='cycles') # needs sage.groups
1336
+ Finite poset containing 6 elements
1337
+ sage: posets.SymmetricGroupAbsoluteOrderPoset(3, labels='reduced_words') # needs sage.groups
1338
+ Finite poset containing 6 elements
1339
+ """
1340
+ from sage.groups.perm_gps.permgroup_named import SymmetricGroup
1341
+ W = SymmetricGroup(n)
1342
+ if labels == "permutations":
1343
+ element_labels = {s: s.tuple() for s in W}
1344
+ if labels == "reduced_words":
1345
+ element_labels = {s: tuple(s.reduced_word()) for s in W}
1346
+ if labels == "cycles":
1347
+ element_labels = {s: "".join(x for x in s.cycle_string() if x != ',')
1348
+ for s in W}
1349
+
1350
+ return Poset({s: list(s.absolute_covers()) for s in W}, element_labels)
1351
+
1352
+ @staticmethod
1353
+ def UpDownPoset(n, m=1):
1354
+ r"""
1355
+ Return the up-down poset on `n` elements where every `(m+1)`
1356
+ step is down and the rest are up.
1357
+
1358
+ The case where `m=1` is sometimes referred to as the zig-zag poset
1359
+ or the fence.
1360
+
1361
+ INPUT:
1362
+
1363
+ - ``n`` -- nonnegative integer; number of elements in the poset
1364
+ - ``m`` -- nonnegative integer (default: 1); how frequently down
1365
+ steps occur
1366
+
1367
+ OUTPUT:
1368
+
1369
+ The partially ordered set on `\{ 0, 1, \ldots, n-1 \}`
1370
+ where `i` covers `i+1` if `m` divides `i+1`, and `i+1` covers `i`
1371
+ otherwise.
1372
+
1373
+ EXAMPLES::
1374
+
1375
+ sage: P = posets.UpDownPoset(7, 2); P
1376
+ Finite poset containing 7 elements
1377
+ sage: sorted(P.cover_relations())
1378
+ [[0, 1], [1, 2], [3, 2], [3, 4], [4, 5], [6, 5]]
1379
+
1380
+ Fibonacci numbers as the number of antichains of a poset::
1381
+
1382
+ sage: [len(posets.UpDownPoset(n).antichains().list()) for n in range(6)]
1383
+ [1, 2, 3, 5, 8, 13]
1384
+
1385
+ TESTS::
1386
+
1387
+ sage: P = posets.UpDownPoset(0); P
1388
+ Finite poset containing 0 elements
1389
+ """
1390
+ n = check_int(n)
1391
+ try:
1392
+ m = Integer(m)
1393
+ except TypeError:
1394
+ raise TypeError(f"parameter m must be an integer, not {m}")
1395
+ if m < 1:
1396
+ raise ValueError(f"parameter m must be positive, not {m}")
1397
+
1398
+ covers = [[i, i + 1] if (i + 1) % (m + 1) else [i + 1, i]
1399
+ for i in range(n - 1)]
1400
+ return Poset((range(n), covers), cover_relations=True)
1401
+
1402
+ @staticmethod
1403
+ def YoungDiagramPoset(lam, dual=False):
1404
+ """
1405
+ Return the poset of cells in the Young diagram of a partition.
1406
+
1407
+ INPUT:
1408
+
1409
+ - ``lam`` -- a partition
1410
+ - ``dual`` -- boolean (default: ``False``); determines the orientation
1411
+ of the poset. If ``True``, then it is a join semilattice,
1412
+ otherwise it is a meet semilattice.
1413
+
1414
+ EXAMPLES::
1415
+
1416
+ sage: P = posets.YoungDiagramPoset(Partition([2, 2])); P
1417
+ Finite meet-semilattice containing 4 elements
1418
+
1419
+ sage: sorted(P.cover_relations())
1420
+ [[(0, 0), (0, 1)], [(0, 0), (1, 0)], [(0, 1), (1, 1)], [(1, 0), (1, 1)]]
1421
+
1422
+ sage: posets.YoungDiagramPoset([3, 2], dual=True)
1423
+ Finite join-semilattice containing 5 elements
1424
+ """
1425
+ from sage.combinat.partition import Partition
1426
+ lam = Partition(lam)
1427
+ if dual:
1428
+ def cell_geq(a, b):
1429
+ """
1430
+ Nested function that returns ``True`` if the cell `a` is to the
1431
+ right or below the cell `b` in the (English) Young diagram.
1432
+ """
1433
+ return ((a[0] == b[0] + 1 and a[1] == b[1]) or
1434
+ (a[1] == b[1] + 1 and a[0] == b[0]))
1435
+ return JoinSemilattice((lam.cells(), cell_geq), cover_relations=True)
1436
+ else:
1437
+ def cell_leq(a, b):
1438
+ """
1439
+ Nested function that returns ``True`` if the cell `a` is
1440
+ to the left or above
1441
+ the cell `b` in the (English) Young diagram.
1442
+ """
1443
+ return ((a[0] == b[0] - 1 and a[1] == b[1]) or
1444
+ (a[1] == b[1] - 1 and a[0] == b[0]))
1445
+ return MeetSemilattice((lam.cells(), cell_leq), cover_relations=True)
1446
+
1447
+ @staticmethod
1448
+ def YoungsLattice(n):
1449
+ """
1450
+ Return Young's Lattice up to rank `n`.
1451
+
1452
+ In other words, the poset of partitions
1453
+ of size less than or equal to `n` ordered by inclusion.
1454
+
1455
+ INPUT:
1456
+
1457
+ - ``n`` -- positive integer
1458
+
1459
+ EXAMPLES::
1460
+
1461
+ sage: P = posets.YoungsLattice(3); P
1462
+ Finite meet-semilattice containing 7 elements
1463
+ sage: P.cover_relations()
1464
+ [[[], [1]],
1465
+ [[1], [1, 1]],
1466
+ [[1], [2]],
1467
+ [[1, 1], [1, 1, 1]],
1468
+ [[1, 1], [2, 1]],
1469
+ [[2], [2, 1]],
1470
+ [[2], [3]]]
1471
+ """
1472
+ from sage.combinat.partition import Partitions, Partition
1473
+ from sage.misc.flatten import flatten
1474
+ partitions = flatten([list(Partitions(i)) for i in range(n + 1)])
1475
+ return JoinSemilattice((partitions, Partition.contains)).dual()
1476
+
1477
+ @staticmethod
1478
+ def YoungsLatticePrincipalOrderIdeal(lam):
1479
+ """
1480
+ Return the principal order ideal of the
1481
+ partition `lam` in Young's Lattice.
1482
+
1483
+ INPUT:
1484
+
1485
+ - ``lam`` -- a partition
1486
+
1487
+ EXAMPLES::
1488
+
1489
+ sage: P = posets.YoungsLatticePrincipalOrderIdeal(Partition([2,2]))
1490
+ sage: P
1491
+ Finite lattice containing 6 elements
1492
+ sage: P.cover_relations()
1493
+ [[[], [1]],
1494
+ [[1], [1, 1]],
1495
+ [[1], [2]],
1496
+ [[1, 1], [2, 1]],
1497
+ [[2], [2, 1]],
1498
+ [[2, 1], [2, 2]]]
1499
+ """
1500
+ ideal = {}
1501
+ level = [lam]
1502
+ while level:
1503
+ new_level = set()
1504
+ for mu in level:
1505
+ down = mu.down_list()
1506
+ ideal[mu] = down
1507
+ new_level.update(down)
1508
+ level = new_level
1509
+
1510
+ H = DiGraph(ideal)
1511
+ return LatticePoset(H.reverse())
1512
+
1513
+ @staticmethod
1514
+ def YoungFibonacci(n):
1515
+ """
1516
+ Return the Young-Fibonacci lattice up to rank `n`.
1517
+
1518
+ Elements of the (infinite) lattice are words with letters '1'
1519
+ and '2'. The covers of a word are the words with another '1'
1520
+ added somewhere not after the first occurrence of an existing
1521
+ '1' and, additionally, the words where the first '1' is replaced by a
1522
+ '2'. The lattice is truncated to have rank `n`.
1523
+
1524
+ See :wikipedia:`Young-Fibonacci lattice`.
1525
+
1526
+ EXAMPLES::
1527
+
1528
+ sage: Y5 = posets.YoungFibonacci(5); Y5
1529
+ Finite meet-semilattice containing 20 elements
1530
+ sage: sorted(Y5.upper_covers(Word('211')))
1531
+ [word: 1211, word: 2111, word: 221]
1532
+
1533
+ TESTS::
1534
+
1535
+ sage: posets.YoungFibonacci(0)
1536
+ Finite meet-semilattice containing 1 elements
1537
+ sage: posets.YoungFibonacci(1)
1538
+ Finite meet-semilattice containing 2 elements
1539
+ """
1540
+ from sage.combinat.posets.lattices import FiniteMeetSemilattice
1541
+ from sage.categories.finite_posets import FinitePosets
1542
+ from sage.combinat.words.word import Word
1543
+
1544
+ n = check_int(n)
1545
+
1546
+ if n == 0:
1547
+ return MeetSemilattice({'': []})
1548
+
1549
+ covers = []
1550
+ current_level = ['']
1551
+ for _ in range(1, n + 1):
1552
+ new_level = set()
1553
+ for low in current_level:
1554
+ ind = low.find('1')
1555
+ if ind != -1: # = found a '1' -> change first '1' to '2'
1556
+ up = low[:ind] + '2' + low[ind + 1:]
1557
+ new_level.add(up)
1558
+ covers.append((low, up))
1559
+ else: # no '1' in low
1560
+ ind = len(low)
1561
+
1562
+ # add '1' to every position not after first existing '1'
1563
+ for j in range(ind + 1):
1564
+ up = '2' * j + '1' + low[j:len(low)]
1565
+ new_level.add(up)
1566
+ covers.append((low, up))
1567
+
1568
+ current_level = new_level
1569
+
1570
+ D = DiGraph([[], covers], format='vertices_and_edges')
1571
+ D.relabel(Word, inplace=True)
1572
+ return FiniteMeetSemilattice(hasse_diagram=D, category=FinitePosets())
1573
+
1574
+ @staticmethod
1575
+ def DoubleTailedDiamond(n):
1576
+ r"""
1577
+ Return a double-tailed diamond of `2n + 2` elements.
1578
+
1579
+ INPUT:
1580
+
1581
+ - ``n`` -- positive integer
1582
+
1583
+ EXAMPLES::
1584
+
1585
+ sage: P = posets.DoubleTailedDiamond(2); P
1586
+ Finite d-complete poset containing 6 elements
1587
+ sage: P.cover_relations()
1588
+ [[1, 2], [2, 3], [2, 4], [3, 5], [4, 5], [5, 6]]
1589
+ """
1590
+ n = check_int(n, 1)
1591
+
1592
+ edges = [(i, i + 1) for i in range(1, n)]
1593
+ edges.extend([(n, n + 1), (n, n + 2), (n + 1, n + 3), (n + 2, n + 3)])
1594
+ edges.extend((i, i + 1) for i in range(n + 3, 2 * n + 2))
1595
+ p = DiGraph([list(range(1, 2 * n + 3)), edges])
1596
+ return DCompletePoset(p)
1597
+
1598
+ @staticmethod
1599
+ def PermutationPattern(n):
1600
+ r"""
1601
+ Return the poset of permutations under pattern containment
1602
+ up to rank `n`.
1603
+
1604
+ INPUT:
1605
+
1606
+ - ``n`` -- positive integer
1607
+
1608
+ A permutation `u = u_1 \cdots u_n` contains the pattern
1609
+ `v = v_1 \cdots v_m` if there is a (not necessarily consecutive)
1610
+ subsequence of `u` of length `m` whose entries have the same
1611
+ relative order as `v`.
1612
+
1613
+ See :wikipedia:`Permutation_pattern`.
1614
+
1615
+ EXAMPLES::
1616
+
1617
+ sage: P4 = posets.PermutationPattern(4); P4
1618
+ Finite poset containing 33 elements
1619
+ sage: sorted(P4.lower_covers(Permutation([2,4,1,3])))
1620
+ [[1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2]]
1621
+
1622
+ .. SEEALSO::
1623
+
1624
+ :meth:`~sage.combinat.permutation.Permutation.has_pattern`
1625
+
1626
+ TESTS::
1627
+
1628
+ sage: posets.PermutationPattern(1)
1629
+ Finite poset containing 1 elements
1630
+ sage: posets.PermutationPattern(2)
1631
+ Finite poset containing 3 elements
1632
+ """
1633
+ n = check_int(n, 1)
1634
+ elem = []
1635
+ for i in range(1, n + 1):
1636
+ elem += Permutations(i)
1637
+ return Poset((elem, lambda a, b: b.has_pattern(a)))
1638
+
1639
+ @staticmethod
1640
+ def PermutationPatternInterval(bottom, top):
1641
+ r"""
1642
+ Return the poset consisting of an interval in the poset of permutations
1643
+ under pattern containment between ``bottom`` and ``top``.
1644
+
1645
+ INPUT:
1646
+
1647
+ - ``bottom``, ``top`` -- permutations where ``top`` contains
1648
+ ``bottom`` as a pattern
1649
+
1650
+ A permutation `u = u_1 \cdots u_n` contains the pattern
1651
+ `v = v_1 \cdots v_m` if there is a (not necessarily consecutive)
1652
+ subsequence of `u` of length `m` whose entries have the same
1653
+ relative order as `v`.
1654
+
1655
+ See :wikipedia:`Permutation_pattern`.
1656
+
1657
+ EXAMPLES::
1658
+
1659
+ sage: t = Permutation([2,3,1])
1660
+ sage: b = Permutation([4,6,2,3,5,1])
1661
+ sage: R = posets.PermutationPatternInterval(t, b); R
1662
+ Finite poset containing 14 elements
1663
+ sage: R.moebius_function(R.bottom(),R.top())
1664
+ -4
1665
+
1666
+ .. SEEALSO::
1667
+
1668
+ :meth:`~sage.combinat.permutation.Permutation.has_pattern`,
1669
+ :meth:`PermutationPattern`
1670
+
1671
+ TESTS::
1672
+
1673
+ sage: p = Permutation([1])
1674
+ sage: posets.PermutationPatternInterval(p, p)
1675
+ Finite poset containing 1 elements
1676
+ """
1677
+ P = Permutations()
1678
+ top = P(top)
1679
+ bottom = P(bottom)
1680
+ if not top.has_pattern(bottom):
1681
+ raise ValueError(f"{top} doesn't contain {bottom} as a pattern")
1682
+ # Make a list of lists of elements in the interval divided by rank.
1683
+ # List will be flattened at the end
1684
+ elem = [[top]]
1685
+ level = 0 # Consider the top element to be level 0, and then go down from there.
1686
+ rel = [] # List of covering relations to be fed into poset constructor.
1687
+ while len(top) - len(bottom) >= level + 1:
1688
+ elem.append([]) # Add a new empty level
1689
+ for upper in elem[level]:
1690
+ # Run through all permutations on current level
1691
+ # and find relations for which it is upper cover
1692
+ upper_perm = P(upper)
1693
+ for i in range(len(top) - level):
1694
+ # Try and remove the ith element from the permutation
1695
+ lower = list(upper)
1696
+ j = lower.pop(i)
1697
+ for k in range(len(top) - level - 1): # Standardize result
1698
+ if lower[k] > j:
1699
+ lower[k] = lower[k] - 1
1700
+ lower_perm = P(lower)
1701
+ if lower_perm.has_pattern(bottom): # Check to see if result is in interval
1702
+ rel += [[lower_perm, upper_perm]]
1703
+ if lower not in elem[level + 1]:
1704
+ elem[level + 1].append(lower_perm)
1705
+ level += 1
1706
+ elem = [item for sublist in elem for item in sublist]
1707
+ return Poset((elem, rel))
1708
+
1709
+ @staticmethod
1710
+ def PermutationPatternOccurrenceInterval(bottom, top, pos):
1711
+ r"""
1712
+ Return the poset consisting of an interval in the poset of
1713
+ permutations under pattern containment between ``bottom`` and
1714
+ ``top``, where a specified instance of ``bottom`` in ``top``
1715
+ must be maintained.
1716
+
1717
+ INPUT:
1718
+
1719
+ - ``bottom``, ``top`` -- permutations where ``top`` contains
1720
+ ``bottom`` as a pattern
1721
+ - ``pos`` -- list of indices indicating a distinguished copy of
1722
+ ``bottom`` inside ``top`` (indexed starting at 0)
1723
+
1724
+ For further information (and picture illustrating included example),
1725
+ see [ST2010]_ .
1726
+
1727
+ See :wikipedia:`Permutation_pattern`.
1728
+
1729
+ EXAMPLES::
1730
+
1731
+ sage: t = Permutation([3,2,1])
1732
+ sage: b = Permutation([6,3,4,5,2,1])
1733
+ sage: A = posets.PermutationPatternOccurrenceInterval(t, b, (0,2,4)); A
1734
+ Finite poset containing 8 elements
1735
+
1736
+ .. SEEALSO::
1737
+
1738
+ :meth:`~sage.combinat.permutation.Permutation.has_pattern`,
1739
+ :meth:`PermutationPattern`, :meth:`PermutationPatternInterval`
1740
+ """
1741
+ P = Permutations()
1742
+ top = P(top)
1743
+ bottom = P(bottom)
1744
+ if not to_standard([top[z] for z in pos]) == list(bottom): # check input
1745
+ raise ValueError("cannot find 'bottom' in 'top' given by 'pos'")
1746
+ elem = [[(top, pos)]]
1747
+ level = 0
1748
+ rel = []
1749
+ while len(top) - len(bottom) >= level + 1:
1750
+ elem.append([]) # Add a new empty level
1751
+ for upper in elem[level]:
1752
+ for i in range(len(top) - level):
1753
+ # Try and remove the ith element from the permutation
1754
+ if i in upper[1]:
1755
+ continue
1756
+ lower_perm = list(upper[0])
1757
+ j = lower_perm.pop(i)
1758
+ for e in range(len(top) - level - 1):
1759
+ if lower_perm[e] > j:
1760
+ lower_perm[e] = lower_perm[e] - 1
1761
+ lower_pos = list(upper[1])
1762
+ for f in range(len(upper[1])):
1763
+ if upper[1][f] > i:
1764
+ lower_pos[f] = upper[1][f] - 1
1765
+ rel += [[(P(lower_perm), tuple(lower_pos)),
1766
+ (P(upper[0]), upper[1])]]
1767
+ if (P(lower_perm), tuple(lower_pos)) not in elem[level + 1]:
1768
+ elem[level + 1].append((P(lower_perm), tuple(lower_pos)))
1769
+ level += 1
1770
+ elem = [item for sublist in elem for item in sublist]
1771
+ return Poset([elem, rel])
1772
+
1773
+ @staticmethod
1774
+ def RibbonPoset(n, descents):
1775
+ r"""
1776
+ Return a ribbon poset on ``n`` vertices with descents at ``descents``.
1777
+
1778
+ INPUT:
1779
+
1780
+ - ``n`` -- the number of vertices
1781
+ - ``descents`` -- an iterable; the indices on the ribbon where `y > x`
1782
+
1783
+ EXAMPLES::
1784
+
1785
+ sage: R = Posets.RibbonPoset(5, [1,2])
1786
+ sage: sorted(R.cover_relations())
1787
+ [[0, 1], [2, 1], [3, 2], [3, 4]]
1788
+ """
1789
+ n = check_int(n)
1790
+ return Mobile(DiGraph([list(range(n)),
1791
+ [(i + 1, i) if i in descents else (i, i + 1)
1792
+ for i in range(n - 1)]]))
1793
+
1794
+ @staticmethod
1795
+ def MobilePoset(ribbon, hangers, anchor=None):
1796
+ r"""
1797
+ Return a mobile poset with the ribbon ``ribbon`` and
1798
+ with hanging d-complete posets specified in ``hangers``
1799
+ and a d-complete poset attached above, specified in ``anchor``.
1800
+
1801
+ INPUT:
1802
+
1803
+ - ``ribbon`` -- a finite poset that is a ribbon
1804
+ - ``hangers`` -- dictionary mapping an element on the ribbon
1805
+ to a list of d-complete posets that it covers
1806
+ - ``anchor`` -- (optional) a ``tuple`` (``ribbon_elmt``,
1807
+ ``anchor_elmt``, ``anchor_poset``), where ``anchor_elmt`` covers
1808
+ ``ribbon_elmt``, and ``anchor_elmt`` is an acyclic element of
1809
+ ``anchor_poset``
1810
+
1811
+ EXAMPLES::
1812
+
1813
+ sage: R = Posets.RibbonPoset(5, [1,2])
1814
+ sage: H = Poset([[5, 6, 7], [(5, 6), (6,7)]])
1815
+ sage: M = Posets.MobilePoset(R, {3: [H]})
1816
+ sage: len(M.cover_relations())
1817
+ 7
1818
+
1819
+ sage: P = posets.MobilePoset(posets.RibbonPoset(7, [1,3]),
1820
+ ....: {1: [posets.YoungDiagramPoset([3, 2], dual=True)],
1821
+ ....: 3: [posets.DoubleTailedDiamond(6)]},
1822
+ ....: anchor=(4, 2, posets.ChainPoset(6)))
1823
+ sage: len(P.cover_relations())
1824
+ 33
1825
+ """
1826
+ elements = []
1827
+ cover_relations = []
1828
+
1829
+ cover_relations.extend(ribbon.cover_relations())
1830
+ elements.extend(ribbon._elements)
1831
+
1832
+ if anchor:
1833
+ cover_relations.extend(((anchor[0], cr[0]), (anchor[0], cr[1]))
1834
+ for cr in anchor[2].cover_relations())
1835
+ cover_relations.append((anchor[0], (anchor[0], anchor[1])))
1836
+
1837
+ elements.extend((anchor[0], elmt) for elmt in anchor[2]._elements)
1838
+
1839
+ for r, hangs in hangers.items():
1840
+ for i, h in enumerate(hangs):
1841
+ elements.extend((r, i, v) for v in h._elements)
1842
+ cover_relations.extend(((r, i, cr[0]), (r, i, cr[1]))
1843
+ for cr in h.cover_relations())
1844
+ cover_relations.append(((r, i, h.top()), r))
1845
+
1846
+ return Mobile(DiGraph([elements, cover_relations]))
1847
+
1848
+
1849
+ # RANDOM LATTICES
1850
+
1851
+ # Following are helper functions for random lattice generation.
1852
+ # There is no parameter checking, 0, 1, ..., n may or may not be a
1853
+ # linear extension, exact output type may vary, etc. Direct use is
1854
+ # discouraged. Use by posets.RandomLattice(..., properties=[...]).
1855
+
1856
+
1857
+ def _random_lattice(n, p):
1858
+ r"""
1859
+ Return a random lattice.
1860
+
1861
+ INPUT:
1862
+
1863
+ - ``n`` -- number of elements, a nonnegative integer
1864
+ - ``p`` -- a number at least zero and less than one; higher number
1865
+ means more covering relations
1866
+
1867
+ OUTPUT:
1868
+
1869
+ A list of lists. Interpreted as a list of lower covers
1870
+ for a poset, it is a lattice with ``0..n-1`` as a linear
1871
+ extension.
1872
+
1873
+ EXAMPLES::
1874
+
1875
+ sage: set_random_seed(42) # Results are reproducible
1876
+ sage: sage.combinat.posets.poset_examples._random_lattice(7, 0.4)
1877
+ [[], [0], [0], [1, 2], [1], [0], [3, 4, 5]]
1878
+
1879
+ ALGORITHM::
1880
+
1881
+ We add elements one by one. We check that adding a maximal
1882
+ element `e` to a meet-semilattice `L` with maximal elements
1883
+ `M` will create a semilattice by checking that there is a
1884
+ meet for `e, m` for all `m \in M`. We do that by keeping
1885
+ track of meet matrix and list of maximal elements.
1886
+ """
1887
+ from sage.arith.misc import integer_floor as floor
1888
+ from sage.misc.functional import sqrt
1889
+ from sage.misc.prandom import random
1890
+
1891
+ n = n - 1
1892
+ meets = [[None] * n for _ in range(n)]
1893
+ meets[0][0] = 0
1894
+ maxs = {0}
1895
+ lc_all = [[]] # No lower covers for the bottom element.
1896
+
1897
+ for i in range(1, n):
1898
+
1899
+ # Look for an admissible lower cover for the next element i
1900
+ while True:
1901
+ # Generate a random antichain
1902
+ lc_list = [i - 1 - floor(i * sqrt(random()))]
1903
+ while random() < p and 0 not in lc_list:
1904
+ new = i - 1 - floor(i * sqrt(random()))
1905
+ if any(meets[new][lc] in [new, lc] for lc in lc_list):
1906
+ continue
1907
+ lc_list.append(new)
1908
+ # Check whether it is admissible as a new lower cover
1909
+ if all(any(all(meets[m][meets[a][a1]] == meets[m][a1] for a1 in lc_list if a1 != a) for a in lc_list) for m in maxs):
1910
+ break
1911
+
1912
+ # We've found a suitable lower cover for i
1913
+ maxs.difference_update(lc_list)
1914
+
1915
+ # Now compute new row and column to meet matrix.
1916
+ meets[i][i] = i
1917
+ for lc in lc_list:
1918
+ meets[i][lc] = meets[lc][i] = lc
1919
+ for e in range(i):
1920
+ meets[i][e] = meets[e][i] = max(meets[e][lc] for lc in lc_list)
1921
+
1922
+ maxs.add(i)
1923
+ lc_all.append(lc_list)
1924
+
1925
+ lc_all.append(list(maxs)) # Add the top element.
1926
+ return lc_all
1927
+
1928
+
1929
+ def _random_dismantlable_lattice(n):
1930
+ r"""
1931
+ Return a random dismantlable lattice on `n` elements.
1932
+
1933
+ INPUT:
1934
+
1935
+ - ``n`` -- number of elements, a nonnegative integer
1936
+
1937
+ OUTPUT:
1938
+
1939
+ A digraph that can be interpreted as the Hasse diagram of a random
1940
+ dismantlable lattice. It has `0` as the bottom element and `n-1` as
1941
+ the top element, but otherwise `0, \ldots, n-1` *is not* usually a
1942
+ linear extension of the lattice.
1943
+
1944
+ EXAMPLES::
1945
+
1946
+ sage: set_random_seed(78) # Results are reproducible
1947
+ sage: D = sage.combinat.posets.poset_examples._random_dismantlable_lattice(10); D
1948
+ Digraph on 10 vertices
1949
+ sage: D.neighbors_in(8)
1950
+ [0]
1951
+
1952
+ ALGORITHM::
1953
+
1954
+ We add elements one by one by "de-dismantling", i.e. select
1955
+ a random pair of comparable elements and add a new element
1956
+ between them.
1957
+ """
1958
+ from sage.misc.prandom import randint
1959
+
1960
+ D = DiGraph({0: [n - 1]})
1961
+ for i in range(1, n - 1):
1962
+ a = randint(0, i // 2)
1963
+ b_ = list(D.depth_first_search(a))
1964
+ b = b_[randint(1, len(b_) - 1)]
1965
+ D.add_vertex(i)
1966
+ D.add_edge(a, i)
1967
+ D.add_edge(i, b)
1968
+ D.delete_edge(a, b)
1969
+ return D
1970
+
1971
+
1972
+ def _random_planar_lattice(n):
1973
+ r"""
1974
+ Return a random planar lattice on `n` elements.
1975
+
1976
+ INPUT:
1977
+
1978
+ - ``n`` -- number of elements, a nonnegative integer
1979
+
1980
+ OUTPUT:
1981
+
1982
+ A random planar lattice. It has `0` as the bottom
1983
+ element and `n-1` as the top element, but otherwise
1984
+ `0, \ldots, n-1` *is not* usually a linear extension of
1985
+ the lattice.
1986
+
1987
+ EXAMPLES::
1988
+
1989
+ sage: # needs planarity
1990
+ sage: set_random_seed(78) # Results are reproducible
1991
+ sage: D = sage.combinat.posets.poset_examples._random_planar_lattice(10); D
1992
+ Digraph on 10 vertices
1993
+ sage: D.neighbors_in(8)
1994
+ [1]
1995
+
1996
+ ALGORITHM::
1997
+
1998
+ Every planar lattice is dismantlable.
1999
+
2000
+ We add elements one by one like when generating
2001
+ dismantlable lattices, and after every addition
2002
+ check that we still have a planar lattice.
2003
+ """
2004
+ from sage.misc.prandom import randint
2005
+
2006
+ G = DiGraph({0: [n - 1]})
2007
+ while G.order() < n:
2008
+ i = G.order() - 1
2009
+ a = randint(0, i // 2)
2010
+ b_ = list(G.depth_first_search(a))
2011
+ b = b_[randint(1, len(b_) - 1)]
2012
+ G1 = G.copy()
2013
+ G.add_vertex(i)
2014
+ G.add_edge(a, i)
2015
+ G.add_edge(i, b)
2016
+ G.delete_edge(a, b)
2017
+ G2 = G.copy()
2018
+ G2.add_edge(n - 1, 0)
2019
+ if not G2.is_planar():
2020
+ G = G1.copy()
2021
+ return G
2022
+
2023
+
2024
+ def _random_distributive_lattice(n):
2025
+ """
2026
+ Return a random poset that has `n` antichains.
2027
+
2028
+ INPUT:
2029
+
2030
+ - ``n`` -- number of elements, a nonnegative integer
2031
+
2032
+ OUTPUT:
2033
+
2034
+ A random poset (as DiGraph) that has `n` antichains; i.e. a poset
2035
+ that's order ideals lattice has `n` elements.
2036
+
2037
+ EXAMPLES::
2038
+
2039
+ sage: g = sage.combinat.posets.poset_examples._random_distributive_lattice(10)
2040
+ sage: Poset(g).order_ideals_lattice(as_ideals=False).cardinality()
2041
+ 10
2042
+
2043
+ ALGORITHM:
2044
+
2045
+ Add elements until there are at least `n` antichains.
2046
+ Remove elements until there are at most `n` antichains.
2047
+ Repeat.
2048
+ """
2049
+ from sage.combinat.posets.hasse_diagram import HasseDiagram
2050
+ from copy import copy
2051
+ from sage.combinat.subset import Subsets
2052
+ from sage.graphs.digraph_generators import digraphs
2053
+
2054
+ if n < 4:
2055
+ return digraphs.Path(n - 1)
2056
+
2057
+ H = HasseDiagram({0: []})
2058
+ while sum(1 for _ in H.antichains_iterator()) < n:
2059
+ D = copy(H)
2060
+ newcover = Subsets(H).random_element()
2061
+ new_element = H.order()
2062
+ D.add_vertex(new_element)
2063
+ for e in newcover:
2064
+ D.add_edge(e, new_element)
2065
+
2066
+ D = D.transitive_reduction()
2067
+ H = HasseDiagram(D)
2068
+
2069
+ while sum(1 for _ in H.antichains_iterator()) > n:
2070
+ D = copy(H)
2071
+ to_delete = H.random_vertex()
2072
+ for a in D.neighbors_in(to_delete):
2073
+ for b in D.neighbors_out(to_delete):
2074
+ D.add_edge(a, b)
2075
+ D.delete_vertex(to_delete)
2076
+ D.relabel({z: z - 1 for z in range(to_delete + 1, D.order() + 1)})
2077
+ H = HasseDiagram(D)
2078
+ return D
2079
+
2080
+
2081
+ def _random_stone_lattice(n):
2082
+ """
2083
+ Return a random Stone lattice on `n` elements.
2084
+
2085
+ INPUT:
2086
+
2087
+ - ``n`` -- number of elements, a nonnegative integer
2088
+
2089
+ OUTPUT:
2090
+
2091
+ A random lattice (as a digraph) of `n` elements.
2092
+
2093
+ EXAMPLES::
2094
+
2095
+ sage: g = sage.combinat.posets.poset_examples._random_stone_lattice(10)
2096
+ sage: LatticePoset(g).is_stone()
2097
+ True
2098
+
2099
+ ALGORITHM:
2100
+
2101
+ Randomly split `n` to some factors. For every factor `p` generate
2102
+ a random distributive lattice on `p-1` elements and add a new bottom
2103
+ element to it. Compute the cartesian product of those lattices.
2104
+ """
2105
+ from sage.arith.misc import factor
2106
+ from sage.combinat.partition import Partitions
2107
+ from sage.misc.misc_c import prod
2108
+ from copy import copy
2109
+
2110
+ factors = sum([[f[0]] * f[1] for f in factor(n)], [])
2111
+ sage.misc.prandom.shuffle(factors)
2112
+
2113
+ part_lengths = list(Partitions(len(factors)).random_element())
2114
+ parts = []
2115
+ while part_lengths:
2116
+ x = part_lengths.pop()
2117
+ parts.append(prod(factors[:x]))
2118
+ factors = factors[x:]
2119
+
2120
+ result = DiGraph(1)
2121
+ for p in parts:
2122
+ g = _random_distributive_lattice(p - 1)
2123
+ g = copy(Poset(g).order_ideals_lattice(as_ideals=False)._hasse_diagram)
2124
+ g.add_edge(-1, 0)
2125
+ result = result.cartesian_product(g)
2126
+ result.relabel()
2127
+
2128
+ return result
2129
+
2130
+
2131
+ posets = Posets