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
sage/knots/link.py ADDED
@@ -0,0 +1,4682 @@
1
+ # sage_setup: distribution = sagemath-graphs
2
+ # sage.doctest: needs sage.graphs sage.groups
3
+ r"""
4
+ Links
5
+
6
+ A knot is defined as embedding of the circle `\mathbb{S}^1` in the
7
+ 3-dimensional sphere `\mathbb{S}^3`, considered up to ambient isotopy.
8
+ They represent the physical idea of a knotted rope, but with the
9
+ particularity that the rope is closed. That is, the ends of the
10
+ rope are joined.
11
+
12
+ A link is an embedding of one or more copies of `\mathbb{S}^1` in
13
+ `\mathbb{S}^3`, considered up to ambient isotopy. That is, a link
14
+ represents the idea of one or more tied ropes. Every knot is a link,
15
+ but not every link is a knot.
16
+
17
+ Generically, the projection of a link on `\RR^2` is a curve with
18
+ crossings. The crossings are represented to show which strand goes
19
+ over the other. This curve is called a planar diagram of the link.
20
+ If we remove the crossings, the resulting connected components are
21
+ segments. These segments are called the edges of the diagram.
22
+
23
+ REFERENCES:
24
+
25
+ - :wikipedia:`Knot_(mathematics)`
26
+ - [Col2013]_
27
+ - [KnotAtlas]_
28
+
29
+ .. SEEALSO::
30
+
31
+ There are also tables of link and knot invariants at web-pages
32
+ `KnotInfo <https://knotinfo.math.indiana.edu/>`__ and
33
+ `LinkInfo <https://linkinfo.sitehost.iu.edu>`__. These can be
34
+ used inside Sage after installing the optional package
35
+ ``database_knotinfo`` (type ``sage -i database_knotinfo`` in a command shell,
36
+ see :mod:`~sage.knots.knotinfo`).
37
+
38
+ AUTHORS:
39
+
40
+ - Miguel Angel Marco Buzunariz
41
+ - Amit Jamadagni
42
+ - Sebastian Oehms (October 2020, add :meth:`get_knotinfo` and :meth:`is_isotopic`)
43
+ - Sebastian Oehms (May 2022): add :meth:`links_gould_polynomial`
44
+ - Sebastian Oehms (May 2023): change the convention about the ``pd_code`` from
45
+ clockwise to anti-clockwise (see :issue:`35665`).
46
+ """
47
+
48
+ # ****************************************************************************
49
+ # Copyright (C) 2014 Miguel Angel Marco Buzunariz
50
+ # Amit Jamadagni
51
+ #
52
+ # This program is free software: you can redistribute it and/or modify
53
+ # it under the terms of the GNU General Public License as published by
54
+ # the Free Software Foundation, either version 2 of the License, or
55
+ # (at your option) any later version.
56
+ #
57
+ # https://www.gnu.org/licenses/
58
+ # ****************************************************************************
59
+
60
+ from copy import deepcopy, copy
61
+ from itertools import combinations
62
+
63
+ from sage.rings.integer_ring import ZZ
64
+ from sage.graphs.digraph import DiGraph
65
+ from sage.graphs.graph import Graph
66
+ from sage.rings.polynomial.laurent_polynomial_ring import LaurentPolynomialRing
67
+ from sage.misc.lazy_import import lazy_import
68
+ from sage.rings.integer import Integer
69
+ from sage.misc.flatten import flatten
70
+ from sage.misc.cachefunc import cached_method
71
+ from sage.structure.sage_object import SageObject
72
+
73
+ lazy_import("sage.functions.generalized", "sign")
74
+ lazy_import('sage.groups.braid', ['Braid', 'BraidGroup'])
75
+ lazy_import('sage.homology.chain_complex', 'ChainComplex')
76
+ lazy_import('sage.matrix.constructor', 'matrix')
77
+ lazy_import('sage.numerical.mip', 'MixedIntegerLinearProgram')
78
+ lazy_import("sage.symbolic.ring", "SR")
79
+
80
+
81
+ class Link(SageObject):
82
+ r"""
83
+ A link.
84
+
85
+ A link is an embedding of one or more copies of `\mathbb{S}^1` in
86
+ `\mathbb{S}^3`, considered up to ambient isotopy. That is, a link
87
+ represents the idea of one or more tied ropes. Every knot is a link,
88
+ but not every link is a knot.
89
+
90
+ A link can be created by using one of the conventions mentioned below:
91
+
92
+ Braid:
93
+
94
+ - The closure of a braid is a link::
95
+
96
+ sage: B = BraidGroup(8)
97
+ sage: L = Link(B([-1, -1, -1, -2, 1, -2, 3, -2, 3])); L
98
+ Link with 1 component represented by 9 crossings
99
+ sage: L = Link(B([1, 2, 1, -2, -1])); L
100
+ Link with 2 components represented by 5 crossings
101
+
102
+ .. NOTE::
103
+
104
+ The strands of the braid that have no crossings at all
105
+ are removed.
106
+
107
+ - Oriented Gauss Code:
108
+
109
+ Label the crossings from `1` to `n` (where `n` is the number of
110
+ crossings) and start moving along the link. Trace every component of
111
+ the link, by starting at a particular point on one component of the
112
+ link and writing down each of the crossings that you encounter until
113
+ returning to the starting point. The crossings are written with sign
114
+ depending on whether we cross them as over or undercrossing. Each
115
+ component is then represented as a list whose elements are the
116
+ crossing numbers. A second list of `+1` and `-1`'s keeps track of
117
+ the orientation of each crossing::
118
+
119
+ sage: L = Link([[[-1, 2, 3, -4, 5, -6, 7, 8, -2, -5, 6, 1, -8, -3, 4, -7]],
120
+ ....: [-1, -1, -1, -1, 1, 1, -1, 1]])
121
+ sage: L
122
+ Link with 1 component represented by 8 crossings
123
+
124
+ For links there may be more than one component and the input is
125
+ as follows::
126
+
127
+ sage: L = Link([[[-1, 2], [-3, 4], [1, 3, -4, -2]], [-1, -1, 1, 1]])
128
+ sage: L
129
+ Link with 3 components represented by 4 crossings
130
+
131
+ - Planar Diagram (PD) Code:
132
+
133
+ The diagram of the link is formed by segments that are adjacent to
134
+ the crossings. Label each one of this segments with a positive number,
135
+ and for each crossing, write down the four incident segments. The
136
+ order of these segments is anti-clockwise, starting with the incoming
137
+ undercrossing.
138
+
139
+ There is no particular distinction between knots and links for
140
+ this input.
141
+
142
+ EXAMPLES:
143
+
144
+ One of the representations of the trefoil knot::
145
+
146
+ sage: L = Link([[1, 5, 2, 4], [5, 3, 6, 2], [3, 1, 4, 6]])
147
+ sage: L
148
+ Link with 1 component represented by 3 crossings
149
+
150
+ .. PLOT::
151
+ :width: 300 px
152
+
153
+ L = Link([[1, 5, 2, 4], [5, 3, 6, 2], [3, 1, 4, 6]])
154
+ sphinx_plot(L.plot())
155
+
156
+ One of the representations of the Hopf link::
157
+
158
+ sage: L = Link([[1, 4, 2, 3], [4, 1, 3, 2]])
159
+ sage: L
160
+ Link with 2 components represented by 2 crossings
161
+
162
+ .. PLOT::
163
+ :width: 300 px
164
+
165
+ L = Link([[1, 4, 2, 3], [4, 1, 3, 2]])
166
+ sphinx_plot(L.plot())
167
+
168
+ We can construct links from the braid group::
169
+
170
+ sage: B = BraidGroup(4)
171
+ sage: L = Link(B([-1, -1, -1, -2, 1, -2, 3, -2])); L
172
+ Link with 2 components represented by 8 crossings
173
+
174
+ .. PLOT::
175
+ :width: 300 px
176
+
177
+ B = BraidGroup(4)
178
+ L = Link(B([-1, -1, -1, -2, 1, -2, 3, -2]))
179
+ sphinx_plot(L.plot())
180
+
181
+ ::
182
+
183
+ sage: L = Link(B([1, 2, 1, 3])); L
184
+ Link with 2 components represented by 4 crossings
185
+
186
+ .. PLOT::
187
+ :width: 300 px
188
+
189
+ B = BraidGroup(4)
190
+ L = Link(B([1, 2, 1, 3]))
191
+ sphinx_plot(L.plot())
192
+
193
+ We construct the "monster" unknot using a planar code, and
194
+ then construct the oriented Gauss code and braid representation::
195
+
196
+ sage: L = Link([[3,4,2,1], [8,7,1,9], [5,3,7,6], [4,5,6,18],
197
+ ....: [17,18,8,19], [9,14,11,10], [10,11,13,12],
198
+ ....: [12,13,15,19], [20,15,14,16], [16,2,17,20]])
199
+ sage: L.oriented_gauss_code()
200
+ [[[1, -4, 3, -1, 10, -9, 6, -7, 8, 5, 4, -3, 2, -6, 7, -8, 9, -10, -5, -2]],
201
+ [1, -1, 1, 1, 1, -1, -1, -1, -1, -1]]
202
+ sage: L.braid()
203
+ s0*s1^-3*s2^-1*s1*s3*s2^2*s1^-1*s0^-1*s2*s1^-1*s3^-1*s2*s1^-1
204
+
205
+ .. PLOT::
206
+ :width: 300 px
207
+
208
+ L = Link([[3,4,2,1], [8,7,1,9], [5,3,7,6], [4,5,6,18],
209
+ [17,18,8,19], [9,14,11,10], [10,11,13,12],
210
+ [12,13,15,19], [20,15,14,16], [16,2,17,20]])
211
+ sphinx_plot(L.plot())
212
+
213
+ We construct the Ochiai unknot by using an oriented Gauss code::
214
+
215
+ sage: L = Link([[[1,-2,-3,-8,-12,13,-14,15,-7,-1,2,-4,10,11,-13,12,
216
+ ....: -11,-16,4,3,-5,6,-9,7,-15,14,16,-10,8,9,-6,5]],
217
+ ....: [-1,-1,1,1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1]])
218
+ sage: L.pd_code()
219
+ [[10, 1, 11, 2], [2, 11, 3, 12], [3, 21, 4, 20], [12, 20, 13, 19],
220
+ [21, 1, 22, 32], [31, 23, 32, 22], [9, 24, 10, 25], [4, 30, 5, 29],
221
+ [23, 31, 24, 30], [28, 13, 29, 14], [17, 15, 18, 14], [5, 16, 6, 17],
222
+ [15, 6, 16, 7], [7, 26, 8, 27], [25, 8, 26, 9], [18, 27, 19, 28]]
223
+
224
+ .. PLOT::
225
+ :width: 300 px
226
+
227
+ L = Link([[[1,-2,-3,-8,-12,13,-14,15,-7,-1,2,-4,10,11,-13,12,
228
+ -11,-16,4,3,-5,6,-9,7,-15,14,16,-10,8,9,-6,5]],
229
+ [-1,-1,1,1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1]])
230
+ sphinx_plot(L.plot())
231
+
232
+ We construct the knot `7_1` and compute some invariants::
233
+
234
+ sage: B = BraidGroup(2)
235
+ sage: L = Link(B([1]*7))
236
+
237
+ .. PLOT::
238
+ :width: 300 px
239
+
240
+ B = BraidGroup(2)
241
+ L = Link(B([1]*7))
242
+ sphinx_plot(L.plot())
243
+
244
+ ::
245
+
246
+ sage: L.alexander_polynomial()
247
+ t^-3 - t^-2 + t^-1 - 1 + t - t^2 + t^3
248
+ sage: L.jones_polynomial() # needs sage.symbolic
249
+ -t^10 + t^9 - t^8 + t^7 - t^6 + t^5 + t^3
250
+ sage: L.determinant()
251
+ 7
252
+ sage: L.signature()
253
+ -6
254
+
255
+ The links here have removed components in which no strand is used::
256
+
257
+ sage: B = BraidGroup(8)
258
+ sage: b = B([1])
259
+ sage: L = Link(b)
260
+ sage: b.components_in_closure()
261
+ 7
262
+ sage: L.number_of_components()
263
+ 1
264
+ sage: L.braid().components_in_closure()
265
+ 1
266
+ sage: L.braid().parent()
267
+ Braid group on 2 strands
268
+
269
+ .. WARNING::
270
+
271
+ Equality of knots is done by comparing the corresponding braids,
272
+ which may give false negatives.
273
+
274
+ .. NOTE::
275
+
276
+ The behavior of removing unused strands from an element of a
277
+ braid group may change without notice in the future. Do not
278
+ rely on this feature.
279
+
280
+ .. TODO::
281
+
282
+ Implement methods to creating new links from previously created links.
283
+ """
284
+
285
+ def __init__(self, data):
286
+ r"""
287
+ Initialize ``self``.
288
+
289
+ TESTS::
290
+
291
+ sage: B = BraidGroup(8)
292
+ sage: L = Link(B([-1, -1, -1, -2,1, -2, 3, -2]))
293
+ sage: TestSuite(L).run()
294
+ sage: L = Link(B([1, 2, 1]))
295
+ sage: TestSuite(L).run()
296
+ sage: L = Link(B.one())
297
+
298
+ sage: L = Link([[1, 1, 2, 2]])
299
+ sage: TestSuite(L).run()
300
+ sage: L = Link([])
301
+ sage: L = Link([[], []])
302
+
303
+ sage: Link([[[-1, 2, -1, 2]], [1, 1, 1, 1]])
304
+ Traceback (most recent call last):
305
+ ...
306
+ ValueError: invalid input: data is not a valid oriented Gauss code
307
+
308
+ sage: Link([[[-1, 2, 3, 4]]])
309
+ Traceback (most recent call last):
310
+ ...
311
+ ValueError: invalid PD code: crossings must be represented by four segments
312
+
313
+ sage: L = Link([[1, 5, 2, 4], [5, 3, 6, 2], [3, 1, 4, 3]])
314
+ Traceback (most recent call last):
315
+ ...
316
+ ValueError: invalid PD code: each segment must appear twice
317
+
318
+ Segments in PD code must be labelled by positive integers::
319
+
320
+ sage: code = [(2, 5, 3, 0), (4, 1, 5, 2), (0, 3, 1, 4)]
321
+ sage: Knot(code)
322
+ Traceback (most recent call last):
323
+ ...
324
+ ValueError: invalid PD code: segment label 0 not allowed
325
+
326
+ sage: L = Link(5)
327
+ Traceback (most recent call last):
328
+ ...
329
+ ValueError: invalid input: data must be either a list or a braid
330
+
331
+ Verify that :issue:`29692` is fixed::
332
+
333
+ sage: B = BraidGroup(5)
334
+ sage: L = Link(B([3,4,3,-4])); L
335
+ Link with 1 component represented by 4 crossings
336
+ sage: L.braid()
337
+ s0*s1*s0*s1^-1
338
+
339
+ PD code can be a list of 4-tuples::
340
+
341
+ sage: code = [(2, 5, 3, 6), (4, 1, 5, 2), (6, 3, 1, 4)]
342
+ sage: K = Knot(code); K.alexander_polynomial()
343
+ t^-1 - 1 + t
344
+ """
345
+ if isinstance(data, list):
346
+ # either oriented Gauss or PD code
347
+ if len(data) != 2 or not all(isinstance(i, list) for i in data[0]):
348
+ # PD code
349
+ if any(len(i) != 4 for i in data):
350
+ raise ValueError("invalid PD code: crossings must be represented by four segments")
351
+ flat = flatten(data)
352
+ if 0 in flat:
353
+ raise ValueError("invalid PD code: segment label 0 not allowed")
354
+ if any(flat.count(i) != 2 for i in set(flat)):
355
+ raise ValueError("invalid PD code: each segment must appear twice")
356
+ self._pd_code = [list(vertex) for vertex in data]
357
+ self._oriented_gauss_code = None
358
+ self._braid = None
359
+ else:
360
+ # oriented Gauss code
361
+ flat = flatten(data[0])
362
+ if flat:
363
+ a, b = max(flat), min(flat)
364
+ if 2 * len(data[1]) != len(flat) or set(range(b, a + 1)) - set([0]) != set(flat):
365
+ raise ValueError("invalid input: data is not a valid oriented Gauss code")
366
+ self._oriented_gauss_code = data
367
+ self._pd_code = None
368
+ self._braid = None
369
+
370
+ else:
371
+ if isinstance(data, Braid):
372
+ # Remove all unused strands
373
+ support = sorted(set().union(*((abs(x), abs(x) + 1) for x in data.Tietze())))
374
+ d = {}
375
+ for i, s in enumerate(support):
376
+ d[s] = i + 1
377
+ d[-s] = -i - 1
378
+ if not support:
379
+ B = BraidGroup(2)
380
+ else:
381
+ B = BraidGroup(len(support))
382
+ self._braid = B([d[x] for x in data.Tietze()])
383
+ self._oriented_gauss_code = None
384
+ self._pd_code = None
385
+
386
+ else:
387
+ raise ValueError("invalid input: data must be either a list or a braid")
388
+
389
+ self._mirror = None # set on invocation of :meth:`mirror_image`
390
+ self._reverse = None # set on invocation of :meth:`reverse`
391
+
392
+ def arcs(self, presentation='pd'):
393
+ r"""
394
+ Return the arcs of ``self``.
395
+
396
+ Arcs are the connected components of the planar diagram.
397
+
398
+ INPUT:
399
+
400
+ - ``presentation`` -- one of the following:
401
+
402
+ * ``'pd'`` -- the arcs are returned as lists of parts in the PD code
403
+ * ``'gauss_code'`` -- the arcs are returned as pieces of the Gauss
404
+ code that start with a negative number, and end with the
405
+ following negative one; of there exist a closed arc,
406
+ it is returned as a list of positive numbers only
407
+
408
+ OUTPUT: list of lists representing the arcs based upon ``presentation``
409
+
410
+ EXAMPLES::
411
+
412
+ sage: K = Knot([[[1,-2,3,-1,2,-3]],[1,1,1]])
413
+ sage: K.arcs()
414
+ [[1, 2], [3, 4], [5, 6]]
415
+ sage: K.arcs(presentation='gauss_code')
416
+ [[-3, 1, -2], [-2, 3, -1], [-1, 2, -3]]
417
+
418
+ ::
419
+
420
+ sage: L = Link([[1, 2, 3, 4], [3, 2, 1, 4]])
421
+ sage: L.arcs()
422
+ [[2, 4], [1], [3]]
423
+ sage: L.arcs(presentation='gauss_code')
424
+ [[-2, -1], [-1, -2], [2, 1]]
425
+ sage: L.gauss_code()
426
+ [[-1, -2], [2, 1]]
427
+ """
428
+ if presentation == 'pd':
429
+ pd_code = self.pd_code()
430
+ G = DiGraph()
431
+ for e in set(flatten(pd_code)):
432
+ G.add_vertex(e)
433
+ for cr in zip(pd_code, self.orientation()):
434
+ if cr[1] == 1:
435
+ G.add_edge(cr[0][3], cr[0][1])
436
+ else:
437
+ G.add_edge(cr[0][1], cr[0][3])
438
+ res = []
439
+ for S in G.connected_components_subgraphs():
440
+ check = S.is_directed_acyclic(certificate=True)
441
+ if check[0]:
442
+ source = S.sources()[0]
443
+ sink = S.sinks()[0]
444
+ res.append(S.shortest_path(source, sink))
445
+ else:
446
+ res.append(check[1])
447
+ return res
448
+ elif presentation == 'gauss_code':
449
+ res = []
450
+ for comp in self.gauss_code():
451
+ if not any(i < 0 for i in comp):
452
+ res.append(comp)
453
+ else:
454
+ rescom = []
455
+ par = []
456
+ for i in comp:
457
+ par.append(i)
458
+ if i < 0:
459
+ rescom.append(copy(par))
460
+ par = [i]
461
+ rescom[0] = par + rescom[0]
462
+ res = res + rescom
463
+ return res
464
+
465
+ def fundamental_group(self, presentation='wirtinger'):
466
+ r"""
467
+ Return the fundamental group of the complement of ``self``.
468
+
469
+ INPUT:
470
+
471
+ - ``presentation`` -- string; one of the following:
472
+
473
+ * ``'wirtinger'`` -- (default) the Wirtinger presentation
474
+ (see :wikipedia:`Link_group`)
475
+ * ``'braid'`` -- the presentation is given by the braid action
476
+ on the free group (see chapter 2 of [Bir1975]_)
477
+
478
+ OUTPUT: a finitely presented group
479
+
480
+ EXAMPLES::
481
+
482
+ sage: L = Link([[1, 4, 3, 2], [3, 4, 1, 2]])
483
+ sage: L.fundamental_group()
484
+ Finitely presented group < x0, x1, x2 | x1*x0^-1*x2^-1*x0, x2*x0*x1^-1*x0^-1 >
485
+ sage: L.fundamental_group('braid')
486
+ Finitely presented group < x0, x1 | 1, 1 >
487
+
488
+ We can see, for instance, that the two presentations of the group
489
+ of the figure eight knot correspond to isomorphic groups::
490
+
491
+ sage: K8 = Knot([[[1, -2, 4, -3, 2, -1, 3, -4]], [1, 1, -1, -1]])
492
+ sage: GA = K8.fundamental_group(); GA
493
+ Finitely presented group < x0, x1, x2, x3 |
494
+ x2*x0*x3^-1*x0^-1, x0*x2*x1^-1*x2^-1,
495
+ x1*x3^-1*x2^-1*x3, x3*x1^-1*x0^-1*x1 >
496
+ sage: GB = K8.fundamental_group(presentation='braid'); GB
497
+ Finitely presented group
498
+ < x0, x1, x2 | x1*x2^-1*x1^-1*x0*x1*x2*x1*x2^-1*x1^-1*x0^-1*x1*x2*x1^-1*x0^-1,
499
+ x1*x2^-1*x1^-1*x0*x1*x2*x1^-1*x2^-1*x1^-1*x0^-1*x1*x2*x1^-1*x0*x1*x2*x1*x2^-1*x1^-1*x0^-1*x1*x2*x1^-2,
500
+ x1*x2^-1*x1^-1*x0*x1*x2*x1^-1*x2^-1 >
501
+ sage: GA.simplified()
502
+ Finitely presented group
503
+ < x0, x1 | x1^-1*x0*x1*x0^-1*x1*x0*x1^-1*x0^-1*x1*x0^-1 >
504
+ sage: GB.simplified()
505
+ Finitely presented group
506
+ < x0, x2 | x2^-1*x0*x2^-1*x0^-1*x2*x0*x2^-1*x0*x2*x0^-1 >
507
+ """
508
+ from sage.groups.free_group import FreeGroup
509
+ if presentation == 'braid':
510
+ b = self.braid()
511
+ F = FreeGroup(b.strands())
512
+ rels = [x * b / x for x in F.gens()]
513
+ return F.quotient(rels)
514
+ elif presentation == 'wirtinger':
515
+ arcs = self.arcs(presentation='pd')
516
+ F = FreeGroup(len(arcs))
517
+ rels = []
518
+ for crossing, orientation in zip(self.pd_code(), self.orientation()):
519
+ a = next(idx for idx, i in enumerate(arcs) if crossing[0] in i)
520
+ b = next(idx for idx, i in enumerate(arcs) if crossing[3] in i)
521
+ c = next(idx for idx, i in enumerate(arcs) if crossing[2] in i)
522
+ ela = F.gen(a)
523
+ elb = F.gen(b)
524
+ if orientation < 0:
525
+ elb = elb.inverse()
526
+ elc = F.gen(c)
527
+ rels.append(ela * elb / elc / elb)
528
+ return F.quotient(rels)
529
+
530
+ def _repr_(self) -> str:
531
+ r"""
532
+ Return a string representation.
533
+
534
+ OUTPUT: string representation
535
+
536
+ EXAMPLES::
537
+
538
+ sage: B = BraidGroup(8)
539
+ sage: L = Link(B([1, 2, 1, 2])); L
540
+ Link with 1 component represented by 4 crossings
541
+
542
+ sage: L = Link([[[-1, 2], [-3, 4], [1, 3, -4, -2]], [-1, -1, 1, 1]])
543
+ sage: L
544
+ Link with 3 components represented by 4 crossings
545
+ """
546
+ number_of_components = self.number_of_components()
547
+ if number_of_components > 1:
548
+ plural = 's'
549
+ else:
550
+ plural = ''
551
+ pd_len = len(self.pd_code())
552
+ return 'Link with {} component{} represented by {} crossings'.format(number_of_components, plural, pd_len)
553
+
554
+ def __eq__(self, other):
555
+ r"""
556
+ Check equality.
557
+
558
+ TESTS::
559
+
560
+ sage: B = BraidGroup(8)
561
+ sage: L1 = Link(B([-1, -1, -1, -2, 1, -2, 3, -2, 5, 4]))
562
+ sage: L2 = Link(B([-1, -1, -1, -2, 1, -2, 3, -2, 5, 4]))
563
+ sage: L1 == L2
564
+ True
565
+ sage: L3 = Link(B([-1, -1, -1, -2, 1, -2, 3, -2]))
566
+ sage: L1 == L3
567
+ False
568
+ """
569
+ if not isinstance(other, self.__class__):
570
+ return False
571
+ if self._pd_code is not None:
572
+ if self.pd_code() == other.pd_code():
573
+ return True
574
+ if self._oriented_gauss_code is not None:
575
+ if self.oriented_gauss_code() == other.oriented_gauss_code():
576
+ return True
577
+ return self.braid() == other.braid()
578
+
579
+ def __hash__(self):
580
+ r"""
581
+ Return the hash of ``self``.
582
+
583
+ EXAMPLES::
584
+
585
+ sage: B = BraidGroup(8)
586
+ sage: L1 = Link(B([-1, -1, -1, -2, 1, -2, 3, -2, 5, 4]))
587
+ sage: H = hash(L1) # needs sage.libs.braiding
588
+ """
589
+ return hash(self.braid())
590
+
591
+ def __ne__(self, other):
592
+ r"""
593
+ Check inequality.
594
+
595
+ TESTS::
596
+
597
+ sage: B = BraidGroup(8)
598
+ sage: L1 = Link(B([-1, -1, -1, -2, 1, -2, 3, -2, 5, 4]))
599
+ sage: L2 = Link(B([-1, -1, -1, -2, 1, -2, 3, -2, 5, 4]))
600
+ sage: L1 != L2
601
+ False
602
+ sage: L3 = Link(B([-1, -1, -1, -2, 1, -2, 3, -2]))
603
+ sage: L1 != L3
604
+ True
605
+ """
606
+ return not self.__eq__(other)
607
+
608
+ def braid(self, remove_loops=False):
609
+ r"""
610
+ Return a braid representation of ``self``.
611
+
612
+ INPUT:
613
+
614
+ - ``remove_loops`` -- boolean (default: ``False``); if set to ``True``
615
+ loops will be removed first. This can reduce the number of strands
616
+ needed for an ambient isotopic braid closure. However, this can lead
617
+ to a loss of the regular isotopy.
618
+
619
+ OUTPUT: an element in the braid group
620
+
621
+ .. WARNING::
622
+
623
+ For the unknot with no crossings, this returns the identity
624
+ of the braid group with 2 strands because this disregards
625
+ strands with no crossings.
626
+
627
+ EXAMPLES::
628
+
629
+ sage: L = Link([[2, 4, 1, 3], [4, 2, 3, 1]])
630
+ sage: L.braid()
631
+ s^2
632
+ sage: L = Link([[[-1, 2, -3, 1, -2, 3]], [-1, -1, -1]])
633
+ sage: L.braid()
634
+ s^-3
635
+ sage: L = Link([[1,7,2,8], [8,5,9,4], [3,10,4,9], [10,6,7,1], [5,2,6,3]])
636
+ sage: L.braid()
637
+ (s0*s1^-1)^2*s1^-1
638
+
639
+ using ``remove_loops=True``::
640
+
641
+ sage: L = Link([[2, 7, 1, 1], [7, 3, 9, 2], [4, 11, 3, 9], [11, 5, 5, 4]])
642
+ sage: L.braid()
643
+ s0*s1^-1*s2*s3^-1
644
+ sage: L.braid(remove_loops=True)
645
+ 1
646
+
647
+ TESTS::
648
+
649
+ sage: L = Link([])
650
+ sage: L.braid()
651
+ 1
652
+ sage: L = Link([[], []])
653
+ sage: L.braid()
654
+ 1
655
+
656
+ Check that :issue:`25050` is solved::
657
+
658
+ sage: A = Link([[[1, 2, -2, -1, -3, -4, 4, 3]], [1, 1, 1, 1]])
659
+ sage: A.braid()
660
+ s0*s1*s2*s3
661
+
662
+ Check that :issue:`36884` is solved::
663
+
664
+ sage: L = Link([[1, 7, 2, 6], [3, 1, 4, 8], [5, 5, 6, 4], [7, 3, 8, 2]])
665
+ sage: L.braid()
666
+ s0^3*s1*s0*s1^-1
667
+ sage: L.braid(remove_loops=True)
668
+ s^3
669
+ """
670
+ if remove_loops:
671
+ L = self.remove_loops()
672
+ if L != self:
673
+ return L.braid(remove_loops=remove_loops)
674
+
675
+ if self._braid is not None:
676
+ return self._braid
677
+
678
+ from sage.groups.braid import BraidGroup
679
+ comp = self._isolated_components()
680
+ if len(comp) > 1:
681
+ L1 = Link(comp[0])
682
+ L2 = Link(flatten(comp[1:], max_level=1))
683
+ b1 = L1.braid(remove_loops=remove_loops)
684
+ b2 = L2.braid(remove_loops=remove_loops)
685
+ n1 = b1.parent().strands()
686
+ n2 = b2.parent().strands()
687
+ t1 = list(b1.Tietze())
688
+ t2 = [sign(x) * (abs(x) + n1) for x in b2.Tietze()]
689
+ B = BraidGroup(n1 + n2)
690
+ self._braid = B(t1 + t2)
691
+ return self._braid
692
+
693
+ pd_code = self.pd_code()
694
+ if not pd_code:
695
+ B = BraidGroup(2)
696
+ self._braid = B.one()
697
+ return self._braid
698
+
699
+ # look for possible Vogel moves, perform them and call recursively to the modified link
700
+ def idx(cross, edge):
701
+ r"""
702
+ Return the index of an edge in a crossing taking loops into account.
703
+ A loop appears as an edge which occurs twice in the crossing.
704
+ In all cases the second occurrence is the correct one needed in
705
+ the Vogel algorithm (see :issue:`36884`).
706
+ """
707
+ i = cross.index(edge)
708
+ if cross.count(edge) > 1:
709
+ return cross.index(edge, i + 1)
710
+ return i
711
+
712
+ seifert_circles = self.seifert_circles()
713
+ newedge = max(flatten(pd_code)) + 1
714
+ for region in self.regions():
715
+ n = len(region)
716
+ for i in range(n - 1):
717
+ a = region[i]
718
+ seifcirca = [x for x in seifert_circles if abs(a) in x]
719
+ for j in range(i + 1, n):
720
+ b = region[j]
721
+ seifcircb = [x for x in seifert_circles if abs(b) in x]
722
+ if seifcirca != seifcircb and sign(a) == sign(b):
723
+ tails, heads = self._directions_of_edges()
724
+
725
+ newPD = [list(vertex) for vertex in pd_code]
726
+ if sign(a) == 1:
727
+ # -------------------------------------------------
728
+ # Visualize insertion of the two new crossings D, E
729
+ # \ /
730
+ # a\ /b existing edges, a down, b up
731
+ # D
732
+ # n3/ \n0 newedge + 3, newedge
733
+ # \ /
734
+ # E
735
+ # n1/ \n2 newedge + 1, newedge + 2
736
+ # / \
737
+ # C1 C2 existing crossings
738
+ # -------------------------------------------------
739
+ C1 = newPD[newPD.index(heads[a])]
740
+ C1[idx(C1, a)] = newedge + 1
741
+ C2 = newPD[newPD.index(tails[b])]
742
+ C2[idx(C2, b)] = newedge + 2
743
+ newPD.append([newedge + 3, newedge, b, a]) # D
744
+ newPD.append([newedge + 2, newedge, newedge + 3, newedge + 1]) # E
745
+ self._braid = Link(newPD).braid(remove_loops=remove_loops)
746
+ return self._braid
747
+ else:
748
+ # -------------------------------------------------
749
+ # Visualize insertion of the two new crossings D, E
750
+ # C1 C2 existing crossings
751
+ # \ /
752
+ # n1\ /n2 newedge + 1, newedge + 2
753
+ # D
754
+ # n3/ \n0 newedge + 3, newedge
755
+ # \ /
756
+ # E
757
+ # a/ \b existing edges, a up, b down
758
+ # / \
759
+ # -------------------------------------------------
760
+ C1 = newPD[newPD.index(heads[-a])]
761
+ C1[idx(C1, -a)] = newedge + 1
762
+ C2 = newPD[newPD.index(tails[-b])]
763
+ C2[idx(C2, -b)] = newedge + 2
764
+ newPD.append([newedge + 2, newedge + 1, newedge + 3, newedge]) # D
765
+ newPD.append([newedge + 3, -a, -b, newedge]) # E
766
+ self._braid = Link(newPD).braid(remove_loops=remove_loops)
767
+ return self._braid
768
+
769
+ # We are in the case where no Vogel moves are necessary.
770
+ G = DiGraph()
771
+ G.add_vertices([tuple(c) for c in seifert_circles])
772
+ for i, c in enumerate(pd_code):
773
+ if self.orientation()[i] == 1:
774
+ a = next(x for x in seifert_circles if c[3] in x)
775
+ b = next(x for x in seifert_circles if c[0] in x)
776
+ else:
777
+ a = next(x for x in seifert_circles if c[0] in x)
778
+ b = next(x for x in seifert_circles if c[1] in x)
779
+ G.add_edge(tuple(a), tuple(b))
780
+
781
+ # Get a simple path from a source to a sink in the digraph
782
+ it = G.all_paths_iterator(starting_vertices=G.sources(), ending_vertices=G.sinks(), simple=True)
783
+ ordered_cycles = next(it)
784
+
785
+ B = BraidGroup(len(ordered_cycles))
786
+ available_crossings = copy(pd_code)
787
+ oc_set = set(ordered_cycles[0])
788
+ for i, x in enumerate(pd_code):
789
+ if any(elt in oc_set for elt in x):
790
+ crossing = x
791
+ crossing_index = i
792
+ break
793
+ available_crossings.remove(crossing)
794
+ status = [None for i in ordered_cycles]
795
+ orientation = self.orientation()
796
+ if orientation[crossing_index] == 1:
797
+ b = B([1])
798
+ status[0] = crossing[2]
799
+ status[1] = crossing[1]
800
+ else:
801
+ b = B([-1])
802
+ status[0] = crossing[3]
803
+ status[1] = crossing[2]
804
+ counter = 0
805
+ while available_crossings:
806
+ possibles = [x for x in available_crossings if status[counter] in x]
807
+ if len(status) < counter + 2 or status[counter + 1] is not None:
808
+ possibles = [x for x in possibles if status[counter + 1] in x]
809
+ if possibles:
810
+ added = possibles[0]
811
+ if orientation[pd_code.index(added)] == 1:
812
+ b *= B([counter + 1])
813
+ status[counter] = added[2]
814
+ status[counter + 1] = added[1]
815
+ else:
816
+ b *= B([-counter - 1])
817
+ status[counter] = added[3]
818
+ status[counter + 1] = added[2]
819
+ if counter > 0:
820
+ counter -= 1
821
+ available_crossings.remove(added)
822
+ else:
823
+ counter += 1
824
+ self._braid = b
825
+ return b
826
+
827
+ def _directions_of_edges(self):
828
+ r"""
829
+ Return the directions of the edges given by the PD code of ``self``.
830
+
831
+ OUTPUT:
832
+
833
+ A tuple of two dictionaries. The first one assigns
834
+ each edge of the PD code to the crossing where it starts.
835
+ The second dictionary assigns it to where it ends.
836
+
837
+ EXAMPLES::
838
+
839
+ sage: L = Link([[1, 4, 2, 3], [2, 4, 1, 3]])
840
+ sage: tails, heads = L._directions_of_edges()
841
+ sage: tails
842
+ {1: [2, 4, 1, 3], 2: [1, 4, 2, 3], 3: [1, 4, 2, 3], 4: [2, 4, 1, 3]}
843
+ sage: heads
844
+ {1: [1, 4, 2, 3], 2: [2, 4, 1, 3], 3: [2, 4, 1, 3], 4: [1, 4, 2, 3]}
845
+
846
+ ::
847
+
848
+ sage: L = Link([[1,4,2,5], [5,2,6,3], [3,6,4,1]])
849
+ sage: tails, heads = L._directions_of_edges()
850
+ sage: tails
851
+ {1: [3, 6, 4, 1],
852
+ 2: [1, 4, 2, 5],
853
+ 3: [5, 2, 6, 3],
854
+ 4: [3, 6, 4, 1],
855
+ 5: [1, 4, 2, 5],
856
+ 6: [5, 2, 6, 3]}
857
+ sage: heads
858
+ {1: [1, 4, 2, 5],
859
+ 2: [5, 2, 6, 3],
860
+ 3: [3, 6, 4, 1],
861
+ 4: [1, 4, 2, 5],
862
+ 5: [5, 2, 6, 3],
863
+ 6: [3, 6, 4, 1]}
864
+
865
+ ::
866
+
867
+ sage: L = Link([[1,3,3,2], [2,5,5,4], [4,7,7,1]])
868
+ sage: tails, heads = L._directions_of_edges()
869
+ sage: tails
870
+ {1: [4, 7, 7, 1],
871
+ 2: [1, 3, 3, 2],
872
+ 3: [1, 3, 3, 2],
873
+ 4: [2, 5, 5, 4],
874
+ 5: [2, 5, 5, 4],
875
+ 7: [4, 7, 7, 1]}
876
+ sage: heads
877
+ {1: [1, 3, 3, 2],
878
+ 2: [2, 5, 5, 4],
879
+ 3: [1, 3, 3, 2],
880
+ 4: [4, 7, 7, 1],
881
+ 5: [2, 5, 5, 4],
882
+ 7: [4, 7, 7, 1]}
883
+ """
884
+ tails = {}
885
+ heads = {}
886
+ pd_code = self.pd_code()
887
+ for C in pd_code:
888
+ tails[C[2]] = C
889
+ a = C[2]
890
+ D = C
891
+ while a not in heads:
892
+ next_crossing = [x for x in pd_code if a in x and x != D]
893
+ if not next_crossing:
894
+ heads[a] = D
895
+ tails[a] = D
896
+ if D[0] == a:
897
+ a = D[2]
898
+ elif D[3] == a:
899
+ a = D[1]
900
+ else:
901
+ a = D[3]
902
+ else:
903
+ heads[a] = next_crossing[0]
904
+ tails[a] = D
905
+ D = next_crossing[0]
906
+ a = D[(D.index(a) + 2) % 4]
907
+
908
+ unassigned = set(flatten(pd_code)).difference(set(tails))
909
+ while unassigned:
910
+ a = unassigned.pop()
911
+ for x in pd_code:
912
+ if a in x:
913
+ D = x
914
+ break
915
+ while a not in heads:
916
+ tails[a] = D
917
+ for x in pd_code:
918
+ if a in x and x != D:
919
+ next_crossing = x
920
+ break
921
+ heads[a] = next_crossing
922
+ D = next_crossing
923
+ a = D[(D.index(a) + 2) % 4]
924
+ if a in unassigned:
925
+ unassigned.remove(a)
926
+ return tails, heads
927
+
928
+ @cached_method
929
+ def _enhanced_states(self):
930
+ r"""
931
+ Return the enhanced states of the diagram.
932
+
933
+ Each enhanced state is represented as a tuple containing:
934
+
935
+ - A tuple with the type of smoothing made at each crossing (0 represents
936
+ a A-type smoothing, and 1 represents B-type).
937
+
938
+ - A tuple with the circles marked as negative. Each circle is
939
+ represented by the smoothings it goes through. Each smoothing
940
+ is represented by the indices of the two strands, and the
941
+ index of the chord, counted clockwise.
942
+
943
+ - A tuple with the circles marked as negative.
944
+
945
+ - The i-index (degree) corresponding to the state.
946
+
947
+ - the j-index (height) corresponding to the state.
948
+
949
+ EXAMPLES::
950
+
951
+ sage: K = Link([[[1,-2,3,-1,2,-3]],[-1,-1,-1]])
952
+ sage: K.pd_code()
953
+ [[4, 1, 5, 2], [2, 5, 3, 6], [6, 3, 1, 4]]
954
+ sage: K._enhanced_states()
955
+ (((0, 0, 0),
956
+ (((1, 4, 7), (4, 1, 9)), ((2, 5, 7), (5, 2, 8)), ((3, 6, 9), (6, 3, 8))),
957
+ (),
958
+ -3,
959
+ -9),
960
+ ((0, 0, 0),
961
+ (((2, 5, 7), (5, 2, 8)), ((3, 6, 9), (6, 3, 8))),
962
+ (((1, 4, 7), (4, 1, 9)),),
963
+ -3,
964
+ -7),
965
+ ((0, 0, 0),
966
+ (((1, 4, 7), (4, 1, 9)), ((3, 6, 9), (6, 3, 8))),
967
+ (((2, 5, 7), (5, 2, 8)),),
968
+ -3,
969
+ -7),
970
+ ((0, 0, 0),
971
+ (((1, 4, 7), (4, 1, 9)), ((2, 5, 7), (5, 2, 8))),
972
+ (((3, 6, 9), (6, 3, 8)),),
973
+ -3,
974
+ -7),
975
+ ((0, 0, 0),
976
+ (((3, 6, 9), (6, 3, 8)),),
977
+ (((1, 4, 7), (4, 1, 9)), ((2, 5, 7), (5, 2, 8))),
978
+ -3,
979
+ -5),
980
+ ((0, 0, 0),
981
+ (((2, 5, 7), (5, 2, 8)),),
982
+ (((1, 4, 7), (4, 1, 9)), ((3, 6, 9), (6, 3, 8))),
983
+ -3,
984
+ -5),
985
+ ((0, 0, 0),
986
+ (((1, 4, 7), (4, 1, 9)),),
987
+ (((2, 5, 7), (5, 2, 8)), ((3, 6, 9), (6, 3, 8))),
988
+ -3,
989
+ -5),
990
+ ((0, 0, 0),
991
+ (),
992
+ (((1, 4, 7), (4, 1, 9)), ((2, 5, 7), (5, 2, 8)), ((3, 6, 9), (6, 3, 8))),
993
+ -3,
994
+ -3),
995
+ ((1, 0, 0),
996
+ (((3, 6, 9), (6, 3, 8)), ((4, 1, 9), (4, 2, 7), (5, 1, 7), (5, 2, 8))),
997
+ (),
998
+ -2,
999
+ -7),
1000
+ ((1, 0, 0),
1001
+ (((4, 1, 9), (4, 2, 7), (5, 1, 7), (5, 2, 8)),),
1002
+ (((3, 6, 9), (6, 3, 8)),),
1003
+ -2,
1004
+ -5),
1005
+ ((1, 0, 0),
1006
+ (((3, 6, 9), (6, 3, 8)),),
1007
+ (((4, 1, 9), (4, 2, 7), (5, 1, 7), (5, 2, 8)),),
1008
+ -2,
1009
+ -5),
1010
+ ((1, 0, 0),
1011
+ (),
1012
+ (((3, 6, 9), (6, 3, 8)), ((4, 1, 9), (4, 2, 7), (5, 1, 7), (5, 2, 8))),
1013
+ -2,
1014
+ -3),
1015
+ ((0, 1, 0),
1016
+ (((1, 4, 7), (4, 1, 9)), ((2, 5, 7), (2, 6, 8), (3, 5, 8), (3, 6, 9))),
1017
+ (),
1018
+ -2,
1019
+ -7),
1020
+ ((0, 1, 0),
1021
+ (((2, 5, 7), (2, 6, 8), (3, 5, 8), (3, 6, 9)),),
1022
+ (((1, 4, 7), (4, 1, 9)),),
1023
+ -2,
1024
+ -5),
1025
+ ((0, 1, 0),
1026
+ (((1, 4, 7), (4, 1, 9)),),
1027
+ (((2, 5, 7), (2, 6, 8), (3, 5, 8), (3, 6, 9)),),
1028
+ -2,
1029
+ -5),
1030
+ ((0, 1, 0),
1031
+ (),
1032
+ (((1, 4, 7), (4, 1, 9)), ((2, 5, 7), (2, 6, 8), (3, 5, 8), (3, 6, 9))),
1033
+ -2,
1034
+ -3),
1035
+ ((1, 1, 0),
1036
+ (((2, 6, 8), (3, 5, 8), (3, 6, 9), (4, 1, 9), (4, 2, 7), (5, 1, 7)),),
1037
+ (),
1038
+ -1,
1039
+ -5),
1040
+ ((1, 1, 0),
1041
+ (),
1042
+ (((2, 6, 8), (3, 5, 8), (3, 6, 9), (4, 1, 9), (4, 2, 7), (5, 1, 7)),),
1043
+ -1,
1044
+ -3),
1045
+ ((0, 0, 1),
1046
+ (((1, 3, 9), (1, 4, 7), (6, 3, 8), (6, 4, 9)), ((2, 5, 7), (5, 2, 8))),
1047
+ (),
1048
+ -2,
1049
+ -7),
1050
+ ((0, 0, 1),
1051
+ (((2, 5, 7), (5, 2, 8)),),
1052
+ (((1, 3, 9), (1, 4, 7), (6, 3, 8), (6, 4, 9)),),
1053
+ -2,
1054
+ -5),
1055
+ ((0, 0, 1),
1056
+ (((1, 3, 9), (1, 4, 7), (6, 3, 8), (6, 4, 9)),),
1057
+ (((2, 5, 7), (5, 2, 8)),),
1058
+ -2,
1059
+ -5),
1060
+ ((0, 0, 1),
1061
+ (),
1062
+ (((1, 3, 9), (1, 4, 7), (6, 3, 8), (6, 4, 9)), ((2, 5, 7), (5, 2, 8))),
1063
+ -2,
1064
+ -3),
1065
+ ((1, 0, 1),
1066
+ (((1, 3, 9), (4, 2, 7), (5, 1, 7), (5, 2, 8), (6, 3, 8), (6, 4, 9)),),
1067
+ (),
1068
+ -1,
1069
+ -5),
1070
+ ((1, 0, 1),
1071
+ (),
1072
+ (((1, 3, 9), (4, 2, 7), (5, 1, 7), (5, 2, 8), (6, 3, 8), (6, 4, 9)),),
1073
+ -1,
1074
+ -3),
1075
+ ((0, 1, 1),
1076
+ (((1, 3, 9), (1, 4, 7), (2, 5, 7), (2, 6, 8), (3, 5, 8), (6, 4, 9)),),
1077
+ (),
1078
+ -1,
1079
+ -5),
1080
+ ((0, 1, 1),
1081
+ (),
1082
+ (((1, 3, 9), (1, 4, 7), (2, 5, 7), (2, 6, 8), (3, 5, 8), (6, 4, 9)),),
1083
+ -1,
1084
+ -3),
1085
+ ((1, 1, 1),
1086
+ (((1, 3, 9), (3, 5, 8), (5, 1, 7)), ((2, 6, 8), (4, 2, 7), (6, 4, 9))),
1087
+ (),
1088
+ 0,
1089
+ -5),
1090
+ ((1, 1, 1),
1091
+ (((2, 6, 8), (4, 2, 7), (6, 4, 9)),),
1092
+ (((1, 3, 9), (3, 5, 8), (5, 1, 7)),),
1093
+ 0,
1094
+ -3),
1095
+ ((1, 1, 1),
1096
+ (((1, 3, 9), (3, 5, 8), (5, 1, 7)),),
1097
+ (((2, 6, 8), (4, 2, 7), (6, 4, 9)),),
1098
+ 0,
1099
+ -3),
1100
+ ((1, 1, 1),
1101
+ (),
1102
+ (((1, 3, 9), (3, 5, 8), (5, 1, 7)), ((2, 6, 8), (4, 2, 7), (6, 4, 9))),
1103
+ 0,
1104
+ -1))
1105
+ """
1106
+ writhe = self.writhe()
1107
+ crossings = self.pd_code()
1108
+ ncross = len(crossings)
1109
+ smoothings = []
1110
+ nmax = max(flatten(crossings)) + 1
1111
+ for i in range(2 ** ncross):
1112
+ v = Integer(i).bits()
1113
+ v = v + (ncross - len(v)) * [0]
1114
+ G = Graph()
1115
+ for j, cr in enumerate(crossings):
1116
+ n = nmax + j
1117
+ if not v[j]:
1118
+ # For negative crossings, we go from undercrossings to the left
1119
+ G.add_edge((cr[1], cr[0], n), cr[0])
1120
+ G.add_edge((cr[1], cr[0], n), cr[1])
1121
+ G.add_edge((cr[3], cr[2], n), cr[2])
1122
+ G.add_edge((cr[3], cr[2], n), cr[3])
1123
+ else:
1124
+ # positive crossings, from undercrossing to the right
1125
+ G.add_edge((cr[0], cr[3], n), cr[0])
1126
+ G.add_edge((cr[0], cr[3], n), cr[3])
1127
+ G.add_edge((cr[2], cr[1], n), cr[2])
1128
+ G.add_edge((cr[2], cr[1], n), cr[1])
1129
+ sm = set(tuple(sorted(x for x in b if isinstance(x, tuple)))
1130
+ for b in G.connected_components(sort=False))
1131
+ iindex = (writhe - ncross + 2 * sum(v)) // 2
1132
+ jmin = writhe + iindex - len(sm)
1133
+ jmax = writhe + iindex + len(sm)
1134
+ smoothings.append((tuple(v), sm, iindex, jmin, jmax))
1135
+ states = [] # we got all the smoothings, now find all the states
1136
+ for sm in smoothings:
1137
+ for k in range(len(sm[1]) + 1):
1138
+ for circpos in combinations(sorted(sm[1]), k): # Add each state
1139
+ circneg = sm[1].difference(circpos)
1140
+ j = writhe + sm[2] + len(circpos) - len(circneg)
1141
+ states.append((sm[0], tuple(sorted(circneg)), tuple(circpos), sm[2], j))
1142
+ return tuple(states)
1143
+
1144
+ @cached_method
1145
+ def _khovanov_homology_cached(self, height, ring=ZZ):
1146
+ r"""
1147
+ Return the Khovanov homology of the link.
1148
+
1149
+ INPUT:
1150
+
1151
+ - ``height`` -- the height of the homology to compute
1152
+ - ``ring`` -- (default: ``ZZ``) the coefficient ring
1153
+
1154
+ OUTPUT:
1155
+
1156
+ The Khovanov homology of the Link in the given height. It is given
1157
+ as a tuple of key-value pairs, whose keys are the degrees.
1158
+
1159
+ .. NOTE::
1160
+
1161
+ This method is intended only as the cache for
1162
+ :meth:`khovanov_homology`.
1163
+
1164
+ EXAMPLES::
1165
+
1166
+ sage: K = Link([[[1, -2, 3, -1, 2, -3]],[-1, -1, -1]])
1167
+ sage: K._khovanov_homology_cached(-5) # needs sage.modules
1168
+ ((-3, 0), (-2, Z), (-1, 0), (0, 0))
1169
+
1170
+ The figure eight knot::
1171
+
1172
+ sage: L = Link([[1, 6, 2, 7], [5, 2, 6, 3], [3, 1, 4, 8], [7, 5, 8, 4]])
1173
+ sage: L._khovanov_homology_cached(-1) # needs sage.modules
1174
+ ((-2, 0), (-1, Z), (0, Z), (1, 0), (2, 0))
1175
+ """
1176
+ crossings = self.pd_code()
1177
+ ncross = len(crossings)
1178
+ states = [(_0, set(_1), set(_2), _3, _4)
1179
+ for (_0, _1, _2, _3, _4) in self._enhanced_states()]
1180
+ bases = {} # arrange them by (i,j)
1181
+ for st in states:
1182
+ i, j = st[3], st[4]
1183
+ if j == height:
1184
+ if (i, j) in bases:
1185
+ bases[i, j].append(st)
1186
+ else:
1187
+ bases[i, j] = [st]
1188
+ complexes = {}
1189
+ for (i, j), bij in bases.items():
1190
+ if (i + 1, j) in bases:
1191
+ m = matrix(ring, len(bij), len(bases[(i + 1, j)]))
1192
+ for ii in range(m.nrows()):
1193
+ V1 = bij[ii]
1194
+ for jj in range(m.ncols()):
1195
+ V2 = bases[(i + 1, j)][jj]
1196
+ V20 = V2[0]
1197
+ difs = [index for index, value in enumerate(V1[0])
1198
+ if value != V20[index]]
1199
+ if len(difs) == 1 and not (V2[2].intersection(V1[1]) or V2[1].intersection(V1[2])):
1200
+ m[ii, jj] = (-1)**sum(V2[0][x] for x in range(difs[0] + 1, ncross))
1201
+ # Here we have the matrix constructed, now we have to put it in the dictionary of complexes
1202
+ else:
1203
+ m = matrix(ring, len(bij), 0)
1204
+ complexes[i] = m.transpose()
1205
+ if (i - 1, j) not in bases:
1206
+ complexes[i - 1] = matrix(ring, len(bases[(i, j)]), 0)
1207
+ homologies = ChainComplex(complexes).homology()
1208
+ return tuple(sorted(homologies.items()))
1209
+
1210
+ def khovanov_homology(self, ring=ZZ, height=None, degree=None):
1211
+ r"""
1212
+ Return the Khovanov homology of the link.
1213
+
1214
+ INPUT:
1215
+
1216
+ - ``ring`` -- (default: ``ZZ``) the coefficient ring
1217
+
1218
+ - ``height`` -- the height of the homology to compute,
1219
+ if not specified, all the heights are computed
1220
+
1221
+ - ``degree`` -- the degree of the homology to compute,
1222
+ if not specified, all the degrees are computed
1223
+
1224
+ OUTPUT:
1225
+
1226
+ The Khovanov homology of the Link. It is given as a dictionary
1227
+ whose keys are the different heights. For each height, the
1228
+ homology is given as another dictionary whose keys are the degrees.
1229
+
1230
+ EXAMPLES::
1231
+
1232
+ sage: K = Link([[[1, -2, 3, -1, 2, -3]],[-1, -1, -1]])
1233
+ sage: K.khovanov_homology() # needs sage.modules
1234
+ {-9: {-3: Z},
1235
+ -7: {-3: 0, -2: C2},
1236
+ -5: {-3: 0, -2: Z, -1: 0, 0: 0},
1237
+ -3: {-3: 0, -2: 0, -1: 0, 0: Z},
1238
+ -1: {0: Z}}
1239
+
1240
+ The figure eight knot::
1241
+
1242
+ sage: L = Link([[1, 6, 2, 7], [5, 2, 6, 3], [3, 1, 4, 8], [7, 5, 8, 4]])
1243
+ sage: L.khovanov_homology(height=-1) # needs sage.modules
1244
+ {-1: {-2: 0, -1: Z, 0: Z, 1: 0, 2: 0}}
1245
+
1246
+ The Hopf link::
1247
+
1248
+ sage: # needs sage.modules
1249
+ sage: B = BraidGroup(2)
1250
+ sage: b = B([1, 1])
1251
+ sage: K = Link(b)
1252
+ sage: K.khovanov_homology(degree=2)
1253
+ {2: {2: 0}, 4: {2: Z}, 6: {2: Z}}
1254
+
1255
+ TESTS:
1256
+
1257
+ Check that :issue:`31001` is fixed::
1258
+
1259
+ sage: # needs sage.modules
1260
+ sage: L = Link([])
1261
+ sage: L.khovanov_homology()
1262
+ {-1: {0: Z}, 1: {0: Z}}
1263
+ sage: L.khovanov_homology(height=-1)
1264
+ {-1: {0: Z}}
1265
+ sage: L.khovanov_homology(height=0)
1266
+ {}
1267
+ sage: L.khovanov_homology(QQ, height=1)
1268
+ {1: {0: Vector space of dimension 1 over Rational Field}}
1269
+ sage: L.khovanov_homology(GF(2), degree=0)
1270
+ {-1: {0: Vector space of dimension 1 over Finite Field of size 2},
1271
+ 1: {0: Vector space of dimension 1 over Finite Field of size 2}}
1272
+ sage: L.khovanov_homology(degree=1)
1273
+ {}
1274
+ sage: L.khovanov_homology(degree=0, height=1)
1275
+ {1: {0: Z}}
1276
+ sage: L.khovanov_homology(degree=1, height=1)
1277
+ {}
1278
+ """
1279
+ if not self.pd_code(): # special case for the unknot with no crossings
1280
+ from sage.homology.homology_group import HomologyGroup
1281
+ homs = {-1: {0: HomologyGroup(1, ring, [0])},
1282
+ 1: {0: HomologyGroup(1, ring, [0])}}
1283
+ if height is not None:
1284
+ if height not in homs:
1285
+ return {}
1286
+ homs = {height: homs[height]}
1287
+ if degree is not None:
1288
+ homs = {ht: {degree: homs[ht][degree]} for ht in homs if degree in homs[ht]}
1289
+ return homs
1290
+
1291
+ if height is not None:
1292
+ heights = [height]
1293
+ else:
1294
+ heights = sorted(set(state[-1] for state in self._enhanced_states()))
1295
+ if degree is not None:
1296
+ homs = {j: dict(self._khovanov_homology_cached(j, ring)) for j in heights}
1297
+ homologies = {j: {degree: homs[j][degree]} for j in homs if degree in homs[j]}
1298
+ else:
1299
+ homologies = {j: dict(self._khovanov_homology_cached(j, ring)) for j in heights}
1300
+ return homologies
1301
+
1302
+ def oriented_gauss_code(self):
1303
+ r"""
1304
+ Return the oriented Gauss code of ``self``.
1305
+
1306
+ The oriented Gauss code has two parts:
1307
+
1308
+ a. the Gauss code
1309
+
1310
+ b. the orientation of each crossing
1311
+
1312
+ The following orientation was taken into consideration for
1313
+ construction of knots:
1314
+
1315
+ From the outgoing of the overcrossing if we move in the clockwise
1316
+ direction to reach the outgoing of the undercrossing then we label
1317
+ that crossing as `-1`.
1318
+
1319
+ From the outgoing of the overcrossing if we move in the anticlockwise
1320
+ direction to reach the outgoing of the undercrossing then we label
1321
+ that crossing as `+1`.
1322
+
1323
+ One more consideration we take in while constructing the orientation
1324
+ is the order of the orientation is same as the ordering of the
1325
+ crossings in the Gauss code.
1326
+
1327
+ .. NOTE::
1328
+
1329
+ Convention: under is denoted by `-1`, and over by `+1` in the
1330
+ crossing info.
1331
+
1332
+ EXAMPLES::
1333
+
1334
+ sage: L = Link([[1, 10, 2, 11], [6, 3, 7, 2], [3, 9, 4, 12],
1335
+ ....: [9, 6, 10, 5], [8, 4, 5, 1], [11, 7, 12, 8]])
1336
+ sage: L.oriented_gauss_code()
1337
+ [[[-1, 2, -3, 5], [4, -2, 6, -5], [-4, 1, -6, 3]], [-1, 1, 1, 1, -1, -1]]
1338
+ sage: L = Link([[1, 3, 2, 4], [6, 2, 3, 1], [7, 5, 8, 4], [5, 7, 6, 8]])
1339
+ sage: L.oriented_gauss_code()
1340
+ [[[-1, 2], [-3, 4], [1, 3, -4, -2]], [-1, -1, 1, 1]]
1341
+
1342
+ sage: B = BraidGroup(8)
1343
+ sage: b = B([1, 1, 1, 1, 1])
1344
+ sage: L = Link(b)
1345
+ sage: L.oriented_gauss_code()
1346
+ [[[1, -2, 3, -4, 5, -1, 2, -3, 4, -5]], [1, 1, 1, 1, 1]]
1347
+
1348
+ TESTS::
1349
+
1350
+ sage: L = Link([])
1351
+ sage: L.oriented_gauss_code()
1352
+ [[], []]
1353
+
1354
+ sage: L = Link(BraidGroup(2).one())
1355
+ sage: L.oriented_gauss_code()
1356
+ [[], []]
1357
+ """
1358
+ if self._oriented_gauss_code is not None:
1359
+ return self._oriented_gauss_code
1360
+
1361
+ pd = self.pd_code()
1362
+ orient = self.orientation()
1363
+ crossing_info = {}
1364
+ for i, j in enumerate(pd):
1365
+ if orient[i] == -1:
1366
+ crossing_info[(j[0], -1, i + 1)] = j[2]
1367
+ crossing_info[(j[1], 1, i + 1)] = j[3]
1368
+ elif orient[i] == 1:
1369
+ crossing_info[(j[0], -1, i + 1)] = j[2]
1370
+ crossing_info[(j[3], 1, i + 1)] = j[1]
1371
+ edges = {}
1372
+ cross_number = {}
1373
+ for i, j in crossing_info.items():
1374
+ edges[i[0]] = [j]
1375
+ if i[1] == 1:
1376
+ cross_number[i[0]] = i[2]
1377
+ elif i[1] == -1:
1378
+ cross_number[i[0]] = -i[2]
1379
+ edges_graph = DiGraph(edges)
1380
+ d = edges_graph.all_simple_cycles()
1381
+ code = []
1382
+ for i in d:
1383
+ l = [cross_number[j] for j in i]
1384
+ del l[-1]
1385
+ code.append(l)
1386
+ oriented_code = [code, orient]
1387
+ self._oriented_gauss_code = oriented_code
1388
+ return self._oriented_gauss_code
1389
+
1390
+ def pd_code(self):
1391
+ r"""
1392
+ Return the planar diagram code of ``self``.
1393
+
1394
+ The planar diagram is returned in the following format.
1395
+
1396
+ We construct the crossing by starting with the entering component
1397
+ of the undercrossing, move in the anti-clockwise direction (see the
1398
+ note below) and then generate the list. If the crossing is given by
1399
+ `[a, b, c, d]`, then we interpret this information as:
1400
+
1401
+ 1. `a` is the entering component of the undercrossing;
1402
+ 2. `b, d` are the components of the overcrossing;
1403
+ 3. `c` is the leaving component of the undercrossing.
1404
+
1405
+ .. NOTE::
1406
+
1407
+ Until version 10.0 the convention to read the ``PD`` code has been
1408
+ to list the components in clockwise direction. As of version 10.1
1409
+ the convention has changed, since it was opposite to the usage in
1410
+ most other places.
1411
+
1412
+ Thus, if you use ``PD`` codes from former Sage releases with this
1413
+ version you should check for the correct mirror type.
1414
+
1415
+ EXAMPLES::
1416
+
1417
+ sage: L = Link([[[1, -2, 3, -4, 2, -1, 4, -3]], [1, 1, -1, -1]])
1418
+ sage: L.pd_code()
1419
+ [[6, 2, 7, 1], [2, 6, 3, 5], [8, 3, 1, 4], [4, 7, 5, 8]]
1420
+
1421
+ sage: B = BraidGroup(2)
1422
+ sage: b = B([1, 1, 1, 1, 1])
1423
+ sage: L = Link(b)
1424
+ sage: L.pd_code()
1425
+ [[2, 4, 3, 1], [4, 6, 5, 3], [6, 8, 7, 5], [8, 10, 9, 7], [10, 2, 1, 9]]
1426
+ sage: L = Link([[[2, -1], [1, -2]], [1, 1]])
1427
+ sage: L.pd_code()
1428
+ [[2, 4, 1, 3], [4, 2, 3, 1]]
1429
+ sage: L = Link([[1, 2, 3, 3], [2, 4, 5, 5], [4, 1, 7, 7]])
1430
+ sage: L.pd_code()
1431
+ [[1, 2, 3, 3], [2, 4, 5, 5], [4, 1, 7, 7]]
1432
+
1433
+ TESTS::
1434
+
1435
+ sage: L = Link([[], []])
1436
+ sage: L.pd_code()
1437
+ []
1438
+
1439
+ sage: L = Link(BraidGroup(2).one())
1440
+ sage: L.pd_code()
1441
+ []
1442
+ """
1443
+ if self._pd_code is not None:
1444
+ return self._pd_code
1445
+
1446
+ if self._oriented_gauss_code is not None:
1447
+ oriented_gauss_code = self._oriented_gauss_code
1448
+ d_dic = {}
1449
+ if len(oriented_gauss_code[0]) > 1:
1450
+ d = flatten(oriented_gauss_code[0])
1451
+ for i, j in enumerate(d):
1452
+ d_dic[j] = [i + 1, i + 2]
1453
+ # here we collect the final component in each Gauss code
1454
+ last_component = [i[-1] for i in oriented_gauss_code[0]]
1455
+ first_component = [i[0] for i in oriented_gauss_code[0]]
1456
+ # here we correct the last_component
1457
+ for i, j in zip(last_component, first_component):
1458
+ d_dic[i][1] = d_dic[j][0]
1459
+ crossing_dic = {}
1460
+ for i, x in enumerate(oriented_gauss_code[1]):
1461
+ if x == -1:
1462
+ crossing_dic[i + 1] = [d_dic[-(i + 1)][0], d_dic[i + 1][0],
1463
+ d_dic[-(i + 1)][1], d_dic[i + 1][1]]
1464
+ elif x == 1:
1465
+ crossing_dic[i + 1] = [d_dic[-(i + 1)][0], d_dic[i + 1][1],
1466
+ d_dic[-(i + 1)][1], d_dic[i + 1][0]]
1467
+ elif len(oriented_gauss_code[0]) == 1:
1468
+ for i, j in enumerate(oriented_gauss_code[0][0]):
1469
+ d_dic[j] = [i + 1, i + 2]
1470
+ d_dic[oriented_gauss_code[0][0][-1]][1] = 1
1471
+ crossing_dic = {}
1472
+ for i, x in enumerate(oriented_gauss_code[1]):
1473
+ if x == -1:
1474
+ crossing_dic[i + 1] = [d_dic[-(i + 1)][0], d_dic[i + 1][0],
1475
+ d_dic[-(i + 1)][1], d_dic[i + 1][1]]
1476
+ elif x == 1:
1477
+ crossing_dic[i + 1] = [d_dic[-(i + 1)][0], d_dic[i + 1][1],
1478
+ d_dic[-(i + 1)][1], d_dic[i + 1][0]]
1479
+ else:
1480
+ crossing_dic = {}
1481
+
1482
+ pd = list(crossing_dic.values())
1483
+ self._pd_code = pd
1484
+ return self._pd_code
1485
+
1486
+ if self._braid is not None:
1487
+ strings = list(range(1, self._braid.strands() + 1))
1488
+ b = list(self._braid.Tietze())
1489
+ pd = []
1490
+ strings_max = strings[-1]
1491
+ for i in b:
1492
+ if i > 0:
1493
+ pd.append(
1494
+ [strings[i], strings_max + 2, strings_max + 1, strings[i - 1]])
1495
+ else:
1496
+ pd.append(
1497
+ [strings[abs(i) - 1], strings[abs(i)], strings_max + 2, strings_max + 1])
1498
+ strings[abs(i) - 1] = strings_max + 1
1499
+ strings[abs(i)] = strings_max + 2
1500
+ strings_max = strings_max + 2
1501
+ for i in pd:
1502
+ for j in range(4):
1503
+ if i[j] in strings:
1504
+ i[j] = strings.index(i[j]) + 1
1505
+ self._pd_code = pd
1506
+ return pd
1507
+
1508
+ raise AssertionError("invalid state")
1509
+
1510
+ def gauss_code(self):
1511
+ r"""
1512
+ Return the Gauss code of ``self``.
1513
+
1514
+ The Gauss code is generated by the following procedure:
1515
+
1516
+ a. Number the crossings from `1` to `n`.
1517
+ b. Select a point on the knot and start moving along the component.
1518
+ c. At each crossing, take the number of the crossing, along with
1519
+ sign, which is `-` if it is an undercrossing and `+` if it is a
1520
+ overcrossing.
1521
+
1522
+ EXAMPLES::
1523
+
1524
+ sage: L = Link([[1, 4, 2, 3], [4, 1, 3, 2]])
1525
+ sage: L.gauss_code()
1526
+ [[-1, 2], [1, -2]]
1527
+
1528
+ sage: B = BraidGroup(8)
1529
+ sage: L = Link(B([1, -2, 1, -2, -2]))
1530
+ sage: L.gauss_code()
1531
+ [[-1, 3, -4, 5], [1, -2, 4, -5, 2, -3]]
1532
+
1533
+ sage: L = Link([[[-1, 2], [-3, 4], [1, 3, -4, -2]], [-1, -1, 1, 1]])
1534
+ sage: L.gauss_code()
1535
+ [[-1, 2], [-3, 4], [1, 3, -4, -2]]
1536
+ """
1537
+ return self.oriented_gauss_code()[0]
1538
+
1539
+ def dowker_notation(self):
1540
+ r"""
1541
+ Return the Dowker notation of ``self``.
1542
+
1543
+ Similar to the PD code we number the components, so every crossing
1544
+ is represented by four numbers. We focus on the incoming entities
1545
+ of the under and the overcrossing. It is the pair of incoming
1546
+ undercrossing and the incoming overcrossing. This information at
1547
+ every crossing gives the Dowker notation.
1548
+
1549
+ OUTPUT:
1550
+
1551
+ A list containing the pair of incoming under cross and the incoming
1552
+ over cross.
1553
+
1554
+ EXAMPLES::
1555
+
1556
+ sage: L = Link([[[-1, 2, -3, 4, 5, 1, -2, 6, 7, 3, -4, -7, -6,-5]],
1557
+ ....: [-1, -1, -1, -1, 1, -1, 1]])
1558
+ sage: L.dowker_notation()
1559
+ [(1, 6), (7, 2), (3, 10), (11, 4), (14, 5), (13, 8), (12, 9)]
1560
+
1561
+ sage: B = BraidGroup(4)
1562
+ sage: L = Link(B([1, 2, 1, 2]))
1563
+ sage: L.dowker_notation()
1564
+ [(2, 1), (3, 5), (6, 4), (7, 9)]
1565
+ sage: L = Link([[1, 4, 2, 3], [4, 1, 3, 2]])
1566
+ sage: L.dowker_notation()
1567
+ [(1, 3), (4, 2)]
1568
+ """
1569
+ pd = self.pd_code()
1570
+ orient = self.orientation()
1571
+ dn = [(i[0], i[1]) if orient[j] == -1 else (i[0], i[3])
1572
+ for j, i in enumerate(pd)]
1573
+ return dn
1574
+
1575
+ def _braid_word_components(self):
1576
+ r"""
1577
+ Return the disjoint braid components, if any, else return the braid
1578
+ of ``self``.
1579
+
1580
+ For example consider the braid ``[-1, 3, 1, 3]`` this can be viewed
1581
+ as a braid with components as ``[-1, 1]`` and ``[3, 3]``. There is no
1582
+ common crossing to these two (in sense there is a crossing between
1583
+ strand `1` and `2`, crossing between `3` and `4` but no crossing
1584
+ between strand `2` and `3`, so these can be viewed as independent
1585
+ components in the braid).
1586
+
1587
+ OUTPUT: list containing the components
1588
+
1589
+ EXAMPLES::
1590
+
1591
+ sage: B = BraidGroup(4)
1592
+ sage: L = Link(B([-1, 3, 1, 3]))
1593
+ sage: L._braid_word_components()
1594
+ ([-1, 1], [3, 3])
1595
+ sage: B = BraidGroup(8)
1596
+ sage: L = Link(B([-1, 3, 1, 5, 1, 7, 1, 6]))
1597
+ sage: L._braid_word_components()
1598
+ ([-1, 1, 1, 1], [3], [5, 7, 6])
1599
+ sage: L = Link(B([-2, 4, 1, 6, 1, 4]))
1600
+ sage: L._braid_word_components()
1601
+ ([-2, 1, 1], [4, 4], [6])
1602
+ """
1603
+ ml = list(self.braid().Tietze())
1604
+ if not ml:
1605
+ return tuple()
1606
+
1607
+ l = set(abs(k) for k in ml)
1608
+ missing1 = set(range(min(l), max(l) + 1)) - l
1609
+ if not missing1:
1610
+ return (ml,)
1611
+
1612
+ missing = sorted(missing1)
1613
+ x = [[] for i in range(len(missing) + 1)]
1614
+ for i, a in enumerate(missing):
1615
+ for j, mlj in enumerate(ml):
1616
+ if mlj != 0 and abs(mlj) < a:
1617
+ x[i].append(mlj)
1618
+ ml[j] = 0
1619
+ elif mlj != 0 and abs(mlj) > missing[-1]:
1620
+ x[-1].append(mlj)
1621
+ ml[j] = 0
1622
+ return tuple([a for a in x if a])
1623
+
1624
+ def _braid_word_components_vector(self):
1625
+ r"""
1626
+ The list from the :meth:`_braid_word_components` is flattened to
1627
+ give out the vector form.
1628
+
1629
+ OUTPUT: list containing braid word components
1630
+
1631
+ EXAMPLES::
1632
+
1633
+ sage: B = BraidGroup(4)
1634
+ sage: L = Link(B([-1, 3, 1, 3]))
1635
+ sage: L._braid_word_components_vector()
1636
+ [-1, 1, 3, 3]
1637
+ sage: B = BraidGroup(8)
1638
+ sage: L = Link(B([-1, 3, 1, 5, 1, 7, 1, 6]))
1639
+ sage: L._braid_word_components_vector()
1640
+ [-1, 1, 1, 1, 3, 5, 7, 6]
1641
+ sage: L = Link(B([-2, 4, 1, 6, 1, 4]))
1642
+ sage: L._braid_word_components_vector()
1643
+ [-2, 1, 1, 4, 4, 6]
1644
+ """
1645
+ return flatten(self._braid_word_components())
1646
+
1647
+ def _homology_generators(self):
1648
+ r"""
1649
+ The set of generators for the first homology group of the connected
1650
+ Seifert surface of the given link.
1651
+
1652
+ This method uses the :meth:`_braid_word_components_vector` to generate
1653
+ the homology generators. The position of the repeated element w.r.t.
1654
+ the braid word component vector list is compiled into a list.
1655
+
1656
+ This is based on Lemma 3.1 in [Col2013]_.
1657
+
1658
+ OUTPUT:
1659
+
1660
+ A list of integers `i \in \{1, 2, \ldots, n-1\}` corresponding
1661
+ to the simple generators `s_i` that gives a homology generator or
1662
+ `0` if the position does not represent a generator.
1663
+
1664
+ EXAMPLES::
1665
+
1666
+ sage: # needs sage.modules
1667
+ sage: B = BraidGroup(4)
1668
+ sage: L = Link(B([-1, 3, 1, 3]))
1669
+ sage: L._homology_generators()
1670
+ [1, 0, 3]
1671
+ sage: B = BraidGroup(8)
1672
+ sage: L = Link(B([-1, 3, 1, 5, 1, 7, 1, 6]))
1673
+ sage: L._homology_generators()
1674
+ [1, 2, 3, 0, 0, 0, 0]
1675
+ sage: L = Link(B([-2, 4, 1, 6, 1, 4]))
1676
+ sage: L._homology_generators()
1677
+ [0, 2, 0, 4, 0]
1678
+ """
1679
+ x = self._braid_word_components_vector()
1680
+ hom_gen = []
1681
+ for j in range(len(x) - 1):
1682
+ a = abs(x[j])
1683
+ for i in range(j + 1, len(x)):
1684
+ if a == abs(x[i]):
1685
+ hom_gen.append(i)
1686
+ break
1687
+ else:
1688
+ hom_gen.append(0)
1689
+ return hom_gen
1690
+
1691
+ @cached_method
1692
+ def seifert_matrix(self):
1693
+ r"""
1694
+ Return the Seifert matrix associated with ``self``.
1695
+
1696
+ ALGORITHM:
1697
+
1698
+ This is the algorithm presented in Section 3.3 of [Col2013]_.
1699
+
1700
+ OUTPUT:
1701
+
1702
+ The intersection matrix of a (not necessarily minimal) Seifert surface.
1703
+
1704
+ EXAMPLES::
1705
+
1706
+ sage: # needs sage.modules
1707
+ sage: B = BraidGroup(4)
1708
+ sage: L = Link(B([-1, 3, 1, 3]))
1709
+ sage: L.seifert_matrix()
1710
+ [ 0 0]
1711
+ [ 0 -1]
1712
+ sage: B = BraidGroup(8)
1713
+ sage: L = Link(B([-1, 3, 1, 5, 1, 7, 1, 6]))
1714
+ sage: L.seifert_matrix()
1715
+ [ 0 0 0]
1716
+ [ 1 -1 0]
1717
+ [ 0 1 -1]
1718
+ sage: L = Link(B([-2, 4, 1, 6, 1, 4]))
1719
+ sage: L.seifert_matrix()
1720
+ [-1 0]
1721
+ [ 0 -1]
1722
+ """
1723
+ x = self._braid_word_components_vector()
1724
+ h = self._homology_generators()
1725
+ indices = [i for i, hi in enumerate(h) if hi]
1726
+ N = len(indices)
1727
+ A = matrix(ZZ, N, N, 0)
1728
+ for ni, i in enumerate(indices):
1729
+ hi = h[i]
1730
+ A[ni, ni] = -(x[i] + x[hi]).sign()
1731
+ for nj in range(ni + 1, N):
1732
+ j = indices[nj]
1733
+ if hi > h[j] or hi < j:
1734
+ continue
1735
+ if hi == j:
1736
+ if x[j] > 0:
1737
+ A[nj, ni] = 1
1738
+ else:
1739
+ A[ni, nj] = -1
1740
+ elif abs(x[i]) - abs(x[j]) == 1:
1741
+ A[nj, ni] = -1
1742
+ elif abs(x[j]) - abs(x[i]) == 1:
1743
+ A[ni, nj] = 1
1744
+ A.set_immutable()
1745
+ return A
1746
+
1747
+ @cached_method
1748
+ def number_of_components(self):
1749
+ r"""
1750
+ Return the number of connected components of ``self``.
1751
+
1752
+ OUTPUT: number of connected components
1753
+
1754
+ EXAMPLES::
1755
+
1756
+ sage: B = BraidGroup(4)
1757
+ sage: L = Link(B([-1, 3, 1, 3]))
1758
+ sage: L.number_of_components()
1759
+ 4
1760
+ sage: B = BraidGroup(8)
1761
+ sage: L = Link(B([-2, 4, 1, 6, 1, 4]))
1762
+ sage: L.number_of_components()
1763
+ 5
1764
+ sage: L = Link(B([1, 2, 1, 2]))
1765
+ sage: L.number_of_components()
1766
+ 1
1767
+ sage: L = Link(B.one())
1768
+ sage: L.number_of_components()
1769
+ 1
1770
+ """
1771
+ G = Graph()
1772
+ pd = self.pd_code()
1773
+ if not pd:
1774
+ return ZZ.one()
1775
+ G.add_vertices(set(flatten(pd)))
1776
+ for c in pd:
1777
+ G.add_edge(c[0], c[2])
1778
+ G.add_edge(c[3], c[1])
1779
+ return G.connected_components_number()
1780
+
1781
+ def is_knot(self):
1782
+ r"""
1783
+ Return ``True`` if ``self`` is a knot.
1784
+
1785
+ Every knot is a link but the converse is not true.
1786
+
1787
+ EXAMPLES::
1788
+
1789
+ sage: B = BraidGroup(4)
1790
+ sage: L = Link(B([1, 3, 1, -3]))
1791
+ sage: L.is_knot()
1792
+ False
1793
+ sage: B = BraidGroup(8)
1794
+ sage: L = Link(B([1, 2, 3, 4, 5, 6]))
1795
+ sage: L.is_knot()
1796
+ True
1797
+ """
1798
+ return self.number_of_components() == 1
1799
+
1800
+ def genus(self):
1801
+ r"""
1802
+ Return the genus of ``self``.
1803
+
1804
+ EXAMPLES::
1805
+
1806
+ sage: B = BraidGroup(4)
1807
+ sage: L = Link(B([-1, 3, 1, 3]))
1808
+ sage: L.genus()
1809
+ 0
1810
+ sage: L = Link(B([1,3]))
1811
+ sage: L.genus()
1812
+ 0
1813
+ sage: B = BraidGroup(8)
1814
+ sage: L = Link(B([-2, 4, 1, 6, 1, 4]))
1815
+ sage: L.genus()
1816
+ 0
1817
+ sage: L = Link(B([1, 2, 1, 2]))
1818
+ sage: L.genus()
1819
+ 1
1820
+ """
1821
+ b = self.braid().Tietze()
1822
+ if not b:
1823
+ return ZZ.zero()
1824
+
1825
+ B = self.braid().parent()
1826
+ x = self._braid_word_components()
1827
+ q = []
1828
+ s_tmp = []
1829
+ for xi in x:
1830
+ tmp = []
1831
+ b1 = min(abs(k) for k in xi)
1832
+ for xij in xi:
1833
+ if xij > 0:
1834
+ xij = xij - b1 + 1
1835
+ else:
1836
+ xij = xij + b1 - 1
1837
+ tmp.append(xij)
1838
+ s_tmp.append(B(tmp))
1839
+ s = []
1840
+ for i in s_tmp:
1841
+ b = i.Tietze()
1842
+ s.append(list(b))
1843
+ t = [Link(B(si)).number_of_components() for si in s]
1844
+ for i, j in enumerate(s):
1845
+ if not j:
1846
+ j.append(-2)
1847
+ for i in s:
1848
+ q2 = max(abs(k) + 1 for k in i)
1849
+ q.append(q2)
1850
+ g = [((2 - t[i]) + len(x[i]) - q[i]) / 2 for i in range(len(x))]
1851
+ return sum(g, ZZ.zero())
1852
+
1853
+ def signature(self):
1854
+ r"""
1855
+ Return the signature of ``self``.
1856
+
1857
+ This is defined as the signature of the symmetric matrix
1858
+
1859
+ .. MATH::
1860
+
1861
+ V + V^{t},
1862
+
1863
+ where `V` is the :meth:`Seifert matrix <seifert_matrix>`.
1864
+
1865
+ .. SEEALSO:: :meth:`omega_signature`, :meth:`seifert_matrix`
1866
+
1867
+ EXAMPLES::
1868
+
1869
+ sage: # needs sage.modules
1870
+ sage: B = BraidGroup(4)
1871
+ sage: L = Link(B([-1, 3, 1, 3]))
1872
+ sage: L.signature()
1873
+ -1
1874
+ sage: B = BraidGroup(8)
1875
+ sage: L = Link(B([-2, 4, 1, 6, 1, 4]))
1876
+ sage: L.signature()
1877
+ -2
1878
+ sage: L = Link(B([1, 2, 1, 2]))
1879
+ sage: L.signature()
1880
+ -2
1881
+ """
1882
+ V = self.seifert_matrix()
1883
+ m = V + V.transpose()
1884
+ return ZZ.sum(j.real().sign() for j in m.eigenvalues())
1885
+
1886
+ def omega_signature(self, omega):
1887
+ r"""
1888
+ Compute the `\omega`-signature of ``self``.
1889
+
1890
+ INPUT:
1891
+
1892
+ - `\omega` -- a complex number of modulus 1; this is assumed to be
1893
+ coercible to ``QQbar``
1894
+
1895
+ This is defined as the signature of the Hermitian matrix
1896
+
1897
+ .. MATH::
1898
+
1899
+ (1 - \omega) V + (1 - \omega^{-1}) V^{t},
1900
+
1901
+ where `V` is the :meth:`Seifert matrix <seifert_matrix>`,
1902
+ as explained on page 122 of [Liv1993]_.
1903
+
1904
+ According to [Con2018]_, this is also known as the
1905
+ Levine-Tristram signature, the equivariant signature or the
1906
+ Tristram-Levine signature.
1907
+
1908
+ .. SEEALSO:: :meth:`signature`, :meth:`seifert_matrix`
1909
+
1910
+ EXAMPLES::
1911
+
1912
+ sage: # needs sage.modules sage.rings.number_field
1913
+ sage: B = BraidGroup(4)
1914
+ sage: K = Knot(B([1,1,1,2,-1,2,-3,2,-3]))
1915
+ sage: omega = QQbar.zeta(3)
1916
+ sage: K.omega_signature(omega)
1917
+ -2
1918
+ """
1919
+ from sage.rings.qqbar import QQbar
1920
+ omega = QQbar(omega)
1921
+ V = self.seifert_matrix()
1922
+ m = (1 - omega) * V + (1 - omega.conjugate()) * V.transpose()
1923
+ return ZZ.sum(j.real().sign() for j in m.eigenvalues())
1924
+
1925
+ def alexander_polynomial(self, var='t'):
1926
+ r"""
1927
+ Return the Alexander polynomial of ``self``.
1928
+
1929
+ INPUT:
1930
+
1931
+ - ``var`` -- (default: ``'t'``) the variable in the polynomial
1932
+
1933
+ EXAMPLES:
1934
+
1935
+ We begin by computing the Alexander polynomial for the
1936
+ figure-eight knot::
1937
+
1938
+ sage: # needs sage.modules
1939
+ sage: B = BraidGroup(3)
1940
+ sage: L = Link(B([1, -2, 1, -2]))
1941
+ sage: L.alexander_polynomial()
1942
+ -t^-1 + 3 - t
1943
+
1944
+ The "monster" unknot::
1945
+
1946
+ sage: L = Link([[3,1,2,4],[8,9,1,7],[5,6,7,3],[4,18,6,5],
1947
+ ....: [17,19,8,18],[9,10,11,14],[10,12,13,11],
1948
+ ....: [12,19,15,13],[20,16,14,15],[16,20,17,2]])
1949
+ sage: L.alexander_polynomial() # needs sage.modules
1950
+ 1
1951
+
1952
+ Some additional examples::
1953
+
1954
+ sage: # needs sage.modules
1955
+ sage: B = BraidGroup(2)
1956
+ sage: L = Link(B([1]))
1957
+ sage: L.alexander_polynomial()
1958
+ 1
1959
+ sage: L = Link(B.one())
1960
+ sage: L.alexander_polynomial()
1961
+ 1
1962
+ sage: B = BraidGroup(3)
1963
+ sage: L = Link(B([1, 2, 1, 2]))
1964
+ sage: L.alexander_polynomial()
1965
+ t^-1 - 1 + t
1966
+
1967
+ When the Seifert surface is disconnected, the Alexander
1968
+ polynomial is defined to be `0`::
1969
+
1970
+ sage: # needs sage.modules
1971
+ sage: B = BraidGroup(4)
1972
+ sage: L = Link(B([1,3]))
1973
+ sage: L.alexander_polynomial()
1974
+ 0
1975
+
1976
+ TESTS::
1977
+
1978
+ sage: # needs sage.modules
1979
+ sage: B = BraidGroup(4)
1980
+ sage: L = Link(B([-1, 3, 1, 3]))
1981
+ sage: L.alexander_polynomial()
1982
+ 0
1983
+ sage: L = Link(B([1,3,1,1,3,3]))
1984
+ sage: L.alexander_polynomial()
1985
+ 0
1986
+ sage: B = BraidGroup(8)
1987
+ sage: L = Link(B([-2, 4, 1, 6, 1, 4]))
1988
+ sage: L.alexander_polynomial()
1989
+ 0
1990
+
1991
+ .. SEEALSO:: :meth:`conway_polynomial`
1992
+ """
1993
+ R = LaurentPolynomialRing(ZZ, var)
1994
+ # The Alexander polynomial of disjoint links are defined to be 0
1995
+ if len(self._braid_word_components()) > 1:
1996
+ return R.zero()
1997
+ t = R.gen()
1998
+ seifert_matrix = self.seifert_matrix()
1999
+ f = (seifert_matrix - t * seifert_matrix.transpose()).determinant()
2000
+ # could we use a charpoly here ? or faster determinant ?
2001
+ if f != 0:
2002
+ exp = f.exponents()
2003
+ return t ** ((-max(exp) - min(exp)) // 2) * f
2004
+ return f
2005
+
2006
+ def conway_polynomial(self):
2007
+ """
2008
+ Return the Conway polynomial of ``self``.
2009
+
2010
+ This is closely related to the Alexander polynomial.
2011
+
2012
+ See :wikipedia:`Alexander_polynomial` for the definition.
2013
+
2014
+ EXAMPLES::
2015
+
2016
+ sage: # needs sage.modules
2017
+ sage: B = BraidGroup(3)
2018
+ sage: L = Link(B([1, -2, 1, -2]))
2019
+ sage: L.conway_polynomial()
2020
+ -t^2 + 1
2021
+ sage: Link([[1, 5, 2, 4], [3, 9, 4, 8], [5, 1, 6, 10],
2022
+ ....: [7, 3, 8, 2], [9, 7, 10, 6]])
2023
+ Link with 1 component represented by 5 crossings
2024
+ sage: _.conway_polynomial()
2025
+ 2*t^2 + 1
2026
+ sage: B = BraidGroup(4)
2027
+ sage: L = Link(B([1,3]))
2028
+ sage: L.conway_polynomial()
2029
+ 0
2030
+
2031
+ .. SEEALSO:: :meth:`alexander_polynomial`
2032
+ """
2033
+ alex = self.alexander_polynomial()
2034
+ L = alex.parent()
2035
+ R = L.polynomial_ring()
2036
+ if alex == 0:
2037
+ return R.zero()
2038
+
2039
+ t = L.gen()
2040
+ alex = alex(t**2)
2041
+ exp = alex.exponents()
2042
+ alex = t**((-max(exp) - min(exp)) // 2) * alex
2043
+
2044
+ conway = R.zero()
2045
+ t_poly = R.gen()
2046
+ binom = t - ~t
2047
+ while alex:
2048
+ M = max(alex.exponents())
2049
+ coeff = alex[M]
2050
+ alex -= coeff * binom**M
2051
+ conway += coeff * t_poly**M
2052
+ return conway
2053
+
2054
+ def khovanov_polynomial(self, var1='q', var2='t', base_ring=ZZ):
2055
+ r"""
2056
+ Return the Khovanov polynomial of ``self``.
2057
+
2058
+ This is the Poincaré polynomial of the Khovanov homology.
2059
+
2060
+ INPUT:
2061
+
2062
+ - ``var1`` -- (default: ``'q'``) the first variable. Its exponents
2063
+ give the (torsion free) rank of the height of Khovanov homology
2064
+ - ``var2`` -- (default: ``'t'``) the second variable. Its exponents
2065
+ give the (torsion free) rank of the degree of Khovanov homology
2066
+ - ``base_ring`` -- (default: ``ZZ``) the ring of the polynomial's
2067
+ coefficients
2068
+
2069
+ OUTPUT:
2070
+
2071
+ A two variate Laurent Polynomial over the ``base_ring``, more precisely an
2072
+ instance of :class:`~sage.rings.polynomial.laurent_polynomial.LaurentPolynomial`.
2073
+
2074
+ EXAMPLES::
2075
+
2076
+ sage: K = Link([[[1, -2, 3, -1, 2, -3]],[-1, -1, -1]])
2077
+ sage: K.khovanov_polynomial() # needs sage.modules
2078
+ q^-1 + q^-3 + q^-5*t^-2 + q^-9*t^-3
2079
+ sage: K.khovanov_polynomial(base_ring=GF(2)) # needs sage.modules
2080
+ q^-1 + q^-3 + q^-5*t^-2 + q^-7*t^-2 + q^-9*t^-3
2081
+
2082
+ The figure eight knot::
2083
+
2084
+ sage: L = Link([[1, 6, 2, 7], [5, 2, 6, 3], [3, 1, 4, 8], [7, 5, 8, 4]])
2085
+ sage: L.khovanov_polynomial(var1='p') # needs sage.modules
2086
+ p^5*t^2 + p*t + p + p^-1 + p^-1*t^-1 + p^-5*t^-2
2087
+ sage: L.khovanov_polynomial(var1='p', var2='s', base_ring=GF(4)) # needs sage.modules sage.rings.finite_rings
2088
+ p^5*s^2 + p^3*s^2 + p*s + p + p^-1 + p^-1*s^-1 + p^-3*s^-1 + p^-5*s^-2
2089
+
2090
+ The Hopf link::
2091
+
2092
+ sage: B = BraidGroup(2)
2093
+ sage: b = B([1, 1])
2094
+ sage: K = Link(b)
2095
+ sage: K.khovanov_polynomial() # needs sage.modules
2096
+ q^6*t^2 + q^4*t^2 + q^2 + 1
2097
+
2098
+ .. SEEALSO:: :meth:`khovanov_homology`
2099
+ """
2100
+ L = LaurentPolynomialRing(base_ring, [var1, var2])
2101
+ ch = base_ring.characteristic()
2102
+ coeff = {}
2103
+ kh = self.khovanov_homology()
2104
+ from sage.rings.infinity import infinity
2105
+ for h in kh:
2106
+ for d in kh[h]:
2107
+ H = kh[h][d]
2108
+ gens = [g for g in H.gens() if g.order() == infinity or ch.divides(g.order())]
2109
+ l = len(gens)
2110
+ if l:
2111
+ coeff[(h, d)] = l
2112
+ return L(coeff)
2113
+
2114
+ def determinant(self):
2115
+ r"""
2116
+ Return the determinant of ``self``.
2117
+
2118
+ EXAMPLES::
2119
+
2120
+ sage: # needs sage.modules
2121
+ sage: B = BraidGroup(4)
2122
+ sage: L = Link(B([-1, 2, 1, 2]))
2123
+ sage: L.determinant()
2124
+ 1
2125
+ sage: B = BraidGroup(8)
2126
+ sage: L = Link(B([2, 4, 2, 3, 1, 2]))
2127
+ sage: L.determinant()
2128
+ 3
2129
+ sage: L = Link(B([1]*16 + [2,1,2,1,2,2,2,2,2,2,2,1,2,1,2,-1,2,-2]))
2130
+ sage: L.determinant()
2131
+ 65
2132
+ sage: B = BraidGroup(3)
2133
+ sage: Link(B([1, 2, 1, 1, 2])).determinant()
2134
+ 4
2135
+
2136
+ TESTS::
2137
+
2138
+ sage: # needs sage.modules
2139
+ sage: B = BraidGroup(3)
2140
+ sage: Link(B([1, 2, 1, -2, -1])).determinant()
2141
+ 0
2142
+
2143
+ REFERENCES:
2144
+
2145
+ - Definition 6.6.3 in [Cro2004]_
2146
+ """
2147
+ V = self.seifert_matrix()
2148
+ m = V + V.transpose()
2149
+ return Integer(abs(m.det()))
2150
+
2151
+ def is_alternating(self):
2152
+ r"""
2153
+ Return whether the given knot diagram is alternating.
2154
+
2155
+ Alternating diagram implies every overcross is followed by an
2156
+ undercross or the vice-versa.
2157
+
2158
+ We look at the Gauss code if the sign is alternating, ``True``
2159
+ is returned else the knot is not alternating ``False`` is returned.
2160
+
2161
+ .. WARNING::
2162
+
2163
+ This does not check if a knot admits an alternating diagram
2164
+ or not. Thus, this term is used differently than in some of
2165
+ the literature, such as in Hoste-Thistlethwaite table.
2166
+
2167
+ .. NOTE::
2168
+
2169
+ Links with more than one component are considered to not
2170
+ be alternating (knots) even when such a diagram exists.
2171
+
2172
+ EXAMPLES::
2173
+
2174
+ sage: B = BraidGroup(4)
2175
+ sage: L = Link(B([-1, -1, -1, -1]))
2176
+ sage: L.is_alternating()
2177
+ False
2178
+ sage: L = Link(B([1, -2, -1, 2]))
2179
+ sage: L.is_alternating()
2180
+ False
2181
+ sage: L = Link(B([-1, 3, 1, 3, 2]))
2182
+ sage: L.is_alternating()
2183
+ False
2184
+ sage: L = Link(B([1]*16 + [2,1,2,1,2,2,2,2,2,2,2,1,2,1,2,-1,2,-2]))
2185
+ sage: L.is_alternating()
2186
+ False
2187
+ sage: L = Link(B([-1,2,-1,2]))
2188
+ sage: L.is_alternating()
2189
+ True
2190
+
2191
+ We give the `5_2` knot with an alternating diagram and a
2192
+ non-alternating diagram::
2193
+
2194
+ sage: K5_2 = Link([[1, 4, 2, 5], [3, 8, 4, 9], [5, 10, 6, 1],
2195
+ ....: [7, 2, 8, 3], [9, 6, 10, 7]])
2196
+ sage: K5_2.is_alternating()
2197
+ True
2198
+
2199
+ sage: K5_2b = Link(K5_2.braid())
2200
+ sage: K5_2b.is_alternating()
2201
+ False
2202
+
2203
+ TESTS:
2204
+
2205
+ Check that :issue:`31001` is fixed::
2206
+
2207
+ sage: L = Knot([])
2208
+ sage: L.is_alternating()
2209
+ True
2210
+ """
2211
+ if not self.is_knot():
2212
+ return False
2213
+ x = self.gauss_code()
2214
+ if not x:
2215
+ return True
2216
+ s = [Integer(i).sign() for i in x[0]]
2217
+ return (s == [(-1) ** (i + 1) for i in range(len(x[0]))]
2218
+ or s == [(-1) ** i for i in range(len(x[0]))])
2219
+
2220
+ def orientation(self):
2221
+ r"""
2222
+ Return the orientation of the crossings of the link diagram
2223
+ of ``self``.
2224
+
2225
+ EXAMPLES::
2226
+
2227
+ sage: L = Link([[1, 2, 5, 4], [3, 7, 6, 5], [4, 6, 9, 8], [7, 11, 10, 9],
2228
+ ....: [8, 10, 13, 1], [11, 3, 2, 13]])
2229
+ sage: L.orientation()
2230
+ [-1, 1, -1, 1, -1, 1]
2231
+ sage: L = Link([[1, 6, 2, 7], [7, 2, 8, 3], [3, 10, 4, 11], [11, 4, 12, 5],
2232
+ ....: [14, 6, 1, 5], [13, 8, 14, 9], [12, 10, 13, 9]])
2233
+ sage: L.orientation()
2234
+ [-1, -1, -1, -1, 1, -1, 1]
2235
+ sage: L = Link([[1, 3, 3, 2], [2, 5, 5, 4], [4, 7, 7, 1]])
2236
+ sage: L.orientation()
2237
+ [-1, -1, -1]
2238
+ """
2239
+ directions = self._directions_of_edges()[0]
2240
+ orientation = []
2241
+ for C in self.pd_code():
2242
+ if C[0] == C[3] or C[2] == C[1]:
2243
+ orientation.append(-1)
2244
+ elif C[3] == C[2] or C[0] == C[1]:
2245
+ orientation.append(1)
2246
+ elif directions[C[3]] == C:
2247
+ orientation.append(-1)
2248
+ else:
2249
+ orientation.append(1)
2250
+ return orientation
2251
+
2252
+ def seifert_circles(self):
2253
+ r"""
2254
+ Return the Seifert circles from the link diagram of ``self``.
2255
+
2256
+ Seifert circles are the circles obtained by smoothing all crossings
2257
+ respecting the orientation of the segments.
2258
+
2259
+ Each Seifert circle is represented as a list of the segments
2260
+ that form it.
2261
+
2262
+ EXAMPLES::
2263
+
2264
+ sage: L = Link([[[1, -2, 3, -4, 2, -1, 4, -3]], [1, 1, -1, -1]])
2265
+ sage: L.seifert_circles()
2266
+ [[1, 7, 5, 3], [2, 6], [4, 8]]
2267
+ sage: L = Link([[[-1, 2, 3, -4, 5, -6, 7, 8, -2, -5, 6, 1, -8, -3, 4, -7]],
2268
+ ....: [-1, -1, -1, -1, 1, 1, -1, 1]])
2269
+ sage: L.seifert_circles()
2270
+ [[1, 13, 9, 3, 15, 5, 11, 7], [2, 10, 6, 12], [4, 16, 8, 14]]
2271
+ sage: L = Link([[[-1, 2, -3, 4, 5, 1, -2, 6, 7, 3, -4, -7, -6, -5]],
2272
+ ....: [-1, -1, -1, -1, 1, -1, 1]])
2273
+ sage: L.seifert_circles()
2274
+ [[1, 7, 3, 11, 5], [2, 8, 14, 6], [4, 12, 10], [9, 13]]
2275
+ sage: L = Link([[1, 7, 2, 6], [7, 3, 8, 2], [3, 11, 4, 10], [11, 5, 12, 4],
2276
+ ....: [14, 5, 1, 6], [13, 9, 14, 8], [12, 9, 13, 10]])
2277
+ sage: L.seifert_circles()
2278
+ [[1, 7, 3, 11, 5], [2, 8, 14, 6], [4, 12, 10], [9, 13]]
2279
+ sage: L = Link([[[-1, 2, -3, 5], [4, -2, 6, -5], [-4, 1, -6, 3]],
2280
+ ....: [-1, 1, 1, 1, -1, -1]])
2281
+ sage: L.seifert_circles()
2282
+ [[1, 11, 8], [2, 7, 12, 4, 5, 10], [3, 9, 6]]
2283
+
2284
+ sage: B = BraidGroup(2)
2285
+ sage: L = Link(B([1, 1, 1]))
2286
+ sage: L.seifert_circles()
2287
+ [[1, 3, 5], [2, 4, 6]]
2288
+
2289
+ TESTS:
2290
+
2291
+ Check that :issue:`25050` is solved::
2292
+
2293
+ sage: A = Link([[[1, 2, -2, -1, -3, -4, 4, 3]], [1, 1, 1, 1]])
2294
+ sage: A.seifert_circles()
2295
+ [[3], [7], [1, 5], [2, 4], [6, 8]]
2296
+ """
2297
+ pd = self.pd_code()
2298
+ available_segments = set(flatten(pd))
2299
+ # detect looped segments. They must be their own Seifert circles
2300
+ result = [[a] for a in available_segments
2301
+ if any(C.count(a) > 1 for C in pd)]
2302
+
2303
+ # remove the looped segments from the available
2304
+ for a in result:
2305
+ available_segments.remove(a[0])
2306
+ tails, heads = self._directions_of_edges()
2307
+ while available_segments:
2308
+ a = available_segments.pop()
2309
+ if heads[a] == tails[a]:
2310
+ result.append([a])
2311
+ else:
2312
+ C = heads[a]
2313
+ par = []
2314
+ while a not in par:
2315
+ par.append(a)
2316
+ posnext = C[(C.index(a) - 1) % 4]
2317
+ if tails[posnext] == C and [posnext] not in result:
2318
+ a = posnext
2319
+ else:
2320
+ a = C[(C.index(a) + 1) % 4]
2321
+ if a in available_segments:
2322
+ available_segments.remove(a)
2323
+ C = heads[a]
2324
+ result.append(par)
2325
+ return result
2326
+
2327
+ def regions(self):
2328
+ r"""
2329
+ Return the regions from the link diagram of ``self``.
2330
+
2331
+ Regions are obtained always turning left at each crossing.
2332
+
2333
+ Then the regions are represented as a list with the segments that form
2334
+ its boundary, with a sign depending on the orientation of the segment
2335
+ as part of the boundary.
2336
+
2337
+ EXAMPLES::
2338
+
2339
+ sage: L = Link([[[-1, +2, -3, 4, +5, +1, -2, +6, +7, 3, -4, -7, -6,-5]],
2340
+ ....: [-1, -1, -1, -1, 1, -1, 1]])
2341
+ sage: L.regions()
2342
+ [[14, -5, 12, -9], [13, 9], [11, 5, 1, 7, 3], [10, -3, 8, -13],
2343
+ [6, -1], [4, -11], [2, -7], [-2, -6, -14, -8], [-4, -10, -12]]
2344
+ sage: L = Link([[[1, -2, 3, -4, 2, -1, 4, -3]],[1, 1, -1, -1]])
2345
+ sage: L.regions()
2346
+ [[8, 4], [7, -4, 1], [6, -1, -3], [5, 3, -8], [2, -5, -7], [-2, -6]]
2347
+ sage: L = Link([[[-1, +2, 3, -4, 5, -6, 7, 8, -2, -5, +6, +1, -8, -3, 4, -7]],
2348
+ ....: [-1, -1, -1, -1, 1, 1, -1, 1]])
2349
+ sage: L.regions()
2350
+ [[16, 8, 14, 4], [15, -4], [13, -8, 1], [12, -1, -7], [11, 7, -16, 5],
2351
+ [10, -5, -15, -3], [9, 3, -14], [6, -11], [2, -9, -13], [-2, -12, -6, -10]]
2352
+
2353
+ sage: B = BraidGroup(2)
2354
+ sage: L = Link(B([-1, -1, -1]))
2355
+ sage: L.regions()
2356
+ [[6, -5], [5, 1, 3], [4, -3], [2, -1], [-2, -6, -4]]
2357
+ sage: L = Link([[[1, -2, 3, -4], [-1, 5, -3, 2, -5, 4]],
2358
+ ....: [-1, 1, 1, -1, -1]])
2359
+ sage: L.regions()
2360
+ [[10, -4, -7], [9, 7, -3], [8, 3], [6, -9, -2], [5, 2, -8, 4],
2361
+ [1, -5], [-1, -10, -6]]
2362
+ sage: L = Link([[1, 3, 3, 2], [2, 4, 4, 5], [5, 6, 6, 7], [7, 8, 8, 1]])
2363
+ sage: L.regions()
2364
+ [[-3], [-4], [-6], [-8], [7, 1, 2, 5], [-1, 8, -7, 6, -5, 4, -2, 3]]
2365
+
2366
+ .. NOTE::
2367
+
2368
+ The link diagram is assumed to have only one completely isolated
2369
+ component. This is because otherwise some regions would have
2370
+ disconnected boundary.
2371
+
2372
+ TESTS::
2373
+
2374
+ sage: B = BraidGroup(6)
2375
+ sage: L = Link(B([1, 3, 5]))
2376
+ sage: L.regions()
2377
+ Traceback (most recent call last):
2378
+ ...
2379
+ NotImplementedError: can only have one isolated component
2380
+ """
2381
+ if len(self._isolated_components()) != 1:
2382
+ raise NotImplementedError("can only have one isolated component")
2383
+ pd = self.pd_code()
2384
+ if len(pd) == 1:
2385
+ if pd[0][0] == pd[0][3]:
2386
+ return [[-pd[0][2]], [pd[0][0]], [pd[0][2], -pd[0][0]]]
2387
+ else:
2388
+ return [[pd[0][2]], [-pd[0][0]], [-pd[0][2], pd[0][0]]]
2389
+
2390
+ tails, heads = self._directions_of_edges()
2391
+ available_edges = set(flatten(pd))
2392
+
2393
+ loops = [i for i in available_edges if heads[i] == tails[i]]
2394
+ available_edges = available_edges.union({-i for i in available_edges})
2395
+ regions = []
2396
+
2397
+ for edge in loops:
2398
+ cros = heads[edge]
2399
+ if cros[3] == edge:
2400
+ regions.append([edge])
2401
+ else:
2402
+ regions.append([-edge])
2403
+ available_edges.remove(edge)
2404
+ available_edges.remove(-edge)
2405
+ available_edges = sorted(available_edges)
2406
+
2407
+ while available_edges:
2408
+ edge = available_edges.pop()
2409
+ region = []
2410
+ while edge not in region:
2411
+ region.append(edge)
2412
+ if edge > 0:
2413
+ cros = heads[edge]
2414
+ ind = cros.index(edge)
2415
+ else:
2416
+ cros = tails[-edge]
2417
+ ind = cros.index(-edge)
2418
+ next_edge = cros[(ind - 1) % 4]
2419
+ if [next_edge] in regions:
2420
+ region.append(-next_edge)
2421
+ next_edge = cros[(ind + 1) % 4]
2422
+ elif [-next_edge] in regions:
2423
+ region.append(next_edge)
2424
+ next_edge = cros[(ind + 1) % 4]
2425
+ if tails[next_edge] == cros:
2426
+ edge = next_edge
2427
+ else:
2428
+ edge = -next_edge
2429
+ if edge in available_edges:
2430
+ available_edges.remove(edge)
2431
+ regions.append(region)
2432
+ return regions
2433
+
2434
+ def remove_loops(self):
2435
+ r"""
2436
+ Return an ambient isotopic link in which all loops are removed.
2437
+
2438
+ EXAMPLES::
2439
+
2440
+ sage: b = BraidGroup(4)((3, 2, -1, -1))
2441
+ sage: L = Link(b)
2442
+ sage: L.remove_loops()
2443
+ Link with 2 components represented by 2 crossings
2444
+ sage: K4 = Link([[1, 7, 2, 6], [3, 1, 4, 8], [5, 5, 6, 4], [7, 3, 8, 2]])
2445
+ sage: K3 = K4.remove_loops()
2446
+ sage: K3.pd_code()
2447
+ [[1, 7, 2, 4], [3, 1, 4, 8], [7, 3, 8, 2]]
2448
+ sage: U = Link([[1, 2, 2, 1]])
2449
+ sage: U.remove_loops()
2450
+ Link with 1 component represented by 0 crossings
2451
+ """
2452
+ pd = self.pd_code()
2453
+ new_pd = []
2454
+ loop_crossings = []
2455
+ for cr in pd:
2456
+ if len(set(cr)) == 4:
2457
+ new_pd.append(list(cr))
2458
+ else:
2459
+ loop_crossings.append(cr)
2460
+ if not loop_crossings:
2461
+ return self
2462
+ if not new_pd:
2463
+ # trivial knot
2464
+ return type(self)([])
2465
+ new_edges = flatten(new_pd)
2466
+ for cr in loop_crossings:
2467
+ rem = set([e for e in cr if e in new_edges])
2468
+ if len(rem) == 2:
2469
+ # put remaining edges together
2470
+ a, b = sorted(rem)
2471
+ for ncr in new_pd:
2472
+ if b in ncr:
2473
+ ncr[ncr.index(b)] = a
2474
+ break
2475
+ res = type(self)(new_pd)
2476
+ return res.remove_loops()
2477
+
2478
+ @cached_method
2479
+ def mirror_image(self):
2480
+ r"""
2481
+ Return the mirror image of ``self``.
2482
+
2483
+ EXAMPLES::
2484
+
2485
+ sage: g = BraidGroup(2).gen(0)
2486
+ sage: K = Link(g^3)
2487
+ sage: K2 = K.mirror_image(); K2
2488
+ Link with 1 component represented by 3 crossings
2489
+ sage: K2.braid()
2490
+ s^-3
2491
+
2492
+ .. PLOT::
2493
+ :width: 300 px
2494
+
2495
+ g = BraidGroup(2).gen(0)
2496
+ K = Link(g**3)
2497
+ sphinx_plot(K.plot())
2498
+
2499
+ .. PLOT::
2500
+ :width: 300 px
2501
+
2502
+ g = BraidGroup(2).gen(0)
2503
+ K = Link(g**3)
2504
+ sphinx_plot(K.mirror_image().plot())
2505
+
2506
+ ::
2507
+
2508
+ sage: K = Knot([[[1, -2, 3, -1, 2, -3]], [1, 1, 1]])
2509
+ sage: K2 = K.mirror_image(); K2
2510
+ Knot represented by 3 crossings
2511
+ sage: K.pd_code()
2512
+ [[4, 2, 5, 1], [2, 6, 3, 5], [6, 4, 1, 3]]
2513
+ sage: K2.pd_code()
2514
+ [[4, 1, 5, 2], [2, 5, 3, 6], [6, 3, 1, 4]]
2515
+
2516
+ .. PLOT::
2517
+ :width: 300 px
2518
+
2519
+ K = Link([[[1,-2,3,-1,2,-3]],[1,1,1]])
2520
+ sphinx_plot(K.plot())
2521
+
2522
+ .. PLOT::
2523
+ :width: 300 px
2524
+
2525
+ K = Link([[[1,-2,3,-1,2,-3]],[1,1,1]])
2526
+ K2 = K.mirror_image()
2527
+ sphinx_plot(K2.plot())
2528
+
2529
+ TESTS:
2530
+
2531
+ check that :issue:`30997` is fixed::
2532
+
2533
+ sage: L = Link([[6, 2, 7, 1], [5, 13, 6, 12], [8, 3, 9, 4],
2534
+ ....: [2, 13, 3, 14], [14, 8, 15, 7], [11, 17, 12, 16],
2535
+ ....: [9, 18, 10, 11], [17, 10, 18, 5], [4, 16, 1, 15]]) # L9n25{0}{0} from KnotInfo
2536
+ sage: Lmm = L.mirror_image().mirror_image()
2537
+ sage: L == Lmm
2538
+ True
2539
+ """
2540
+ # Use the braid information if it is the shortest version
2541
+ # of what we have already computed
2542
+ if self._mirror:
2543
+ return self._mirror
2544
+
2545
+ if self._braid:
2546
+ lb = len(self._braid.Tietze())
2547
+
2548
+ if self._pd_code:
2549
+ lpd = len(self.pd_code())
2550
+ else:
2551
+ lpd = float('inf')
2552
+
2553
+ if self._oriented_gauss_code:
2554
+ logc = len(self.oriented_gauss_code()[-1])
2555
+ else:
2556
+ logc = float('inf')
2557
+
2558
+ if lb <= logc and lb <= lpd:
2559
+ self._mirror = type(self)(self._braid.mirror_image())
2560
+ self._mirror._mirror = self
2561
+ return self._mirror
2562
+
2563
+ # Otherwise we fallback to the PD code
2564
+ pd = [[a[0], a[3], a[2], a[1]] for a in self.pd_code()]
2565
+ self._mirror = type(self)(pd)
2566
+ self._mirror._mirror = self
2567
+ return self._mirror
2568
+
2569
+ def reverse(self):
2570
+ r"""
2571
+ Return the reverse of ``self``. This is the link obtained from ``self``
2572
+ by reverting the orientation on all components.
2573
+
2574
+ EXAMPLES::
2575
+
2576
+ sage: K3 = Knot([[5, 2, 4, 1], [3, 6, 2, 5], [1, 4, 6, 3]])
2577
+ sage: K3r = K3.reverse(); K3r.pd_code()
2578
+ [[4, 1, 5, 2], [2, 5, 3, 6], [6, 3, 1, 4]]
2579
+ sage: K3 == K3r
2580
+ True
2581
+
2582
+ a non reversable knot::
2583
+
2584
+ sage: K8_17 = Knot([[6, 1, 7, 2], [14, 7, 15, 8], [8, 4, 9, 3],
2585
+ ....: [2, 14, 3, 13], [12, 6, 13, 5], [4, 10, 5, 9],
2586
+ ....: [16, 11, 1, 12], [10, 15, 11, 16]])
2587
+ sage: K8_17r = K8_17.reverse()
2588
+ sage: b = K8_17.braid(); b
2589
+ s0^2*s1^-1*(s1^-1*s0)^2*s1^-1
2590
+ sage: br = K8_17r.braid(); br
2591
+ s0^-1*s1*s0^-2*s1^2*s0^-1*s1
2592
+
2593
+ sage: # needs sage.libs.braiding
2594
+ sage: b.is_conjugated(br)
2595
+ False
2596
+ sage: b == br.reverse()
2597
+ False
2598
+ sage: b.is_conjugated(br.reverse())
2599
+ True
2600
+ sage: K8_17b = Link(b)
2601
+ sage: K8_17br = K8_17b.reverse()
2602
+ sage: bbr = K8_17br.braid(); bbr
2603
+ (s1^-1*s0)^2*s1^-2*s0^2
2604
+ sage: br == bbr
2605
+ False
2606
+ sage: br.is_conjugated(bbr)
2607
+ True
2608
+ """
2609
+ if self._reverse:
2610
+ return self._reverse
2611
+
2612
+ b = self._braid
2613
+ if b and len(b.Tietze()) <= len(self.pd_code()):
2614
+ self._reverse = type(self)(self._braid.reverse())
2615
+ self._reverse._reverse = self
2616
+ return self._reverse
2617
+
2618
+ # Otherwise we fallback to the PD code
2619
+ pd = [[a[2], a[3], a[0], a[1]] for a in self.pd_code()]
2620
+ self._reverse = type(self)(pd)
2621
+ self._reverse._reverse = self
2622
+ return self._reverse
2623
+
2624
+ def writhe(self):
2625
+ r"""
2626
+ Return the writhe of ``self``.
2627
+
2628
+ EXAMPLES::
2629
+
2630
+ sage: L = Link([[[1, -2, 3, -4, 2, -1, 4, -3]],[1, 1, -1, -1]])
2631
+ sage: L.writhe()
2632
+ 0
2633
+ sage: L = Link([[[-1, 2, -3, 4, 5, 1, -2, 6, 7, 3, -4, -7, -6,-5]],
2634
+ ....: [-1, -1, -1, -1, 1, -1, 1]])
2635
+ sage: L.writhe()
2636
+ -3
2637
+ sage: L = Link([[[-1, 2, 3, -4, 5, -6, 7, 8, -2, -5, 6, 1, -8, -3, 4, -7]],
2638
+ ....: [-1, -1, -1, -1, 1, 1, -1, 1]])
2639
+ sage: L.writhe()
2640
+ -2
2641
+ """
2642
+ x = self.oriented_gauss_code()
2643
+ pos = x[1].count(1)
2644
+ neg = (-1) * x[1].count(-1)
2645
+ return pos + neg
2646
+
2647
+ def jones_polynomial(self, variab=None, skein_normalization=False, algorithm='jonesrep'):
2648
+ r"""
2649
+ Return the Jones polynomial of ``self``.
2650
+
2651
+ The normalization is so that the unknot has Jones polynomial `1`.
2652
+ If ``skein_normalization`` is ``True``, the variable of the result
2653
+ is replaced by a itself to the power of `4`, so that the result
2654
+ agrees with the conventions of [Lic1997]_ (which in particular differs
2655
+ slightly from the conventions used otherwise in this class), had
2656
+ one used the conventional Kauffman bracket variable notation directly.
2657
+
2658
+ If ``variab`` is ``None`` return a polynomial in the variable `A`
2659
+ or `t`, depending on the value ``skein_normalization``. In
2660
+ particular, if ``skein_normalization`` is ``False``, return the
2661
+ result in terms of the variable `t`, also used in [Lic1997]_.
2662
+
2663
+ ALGORITHM:
2664
+
2665
+ The calculation goes through one of two possible algorithms,
2666
+ depending on the value of ``algorithm``. Possible values are
2667
+ ``'jonesrep'`` which uses the Jones representation of a braid
2668
+ representation of ``self`` to compute the polynomial of the
2669
+ trace closure of the braid, and ``statesum`` which recursively
2670
+ computes the Kauffman bracket of ``self``. Depending on how the
2671
+ link is given, there might be significant time gains in using
2672
+ one over the other. When the trace closure of the braid is
2673
+ ``self``, the algorithms give the same result.
2674
+
2675
+ INPUT:
2676
+
2677
+ - ``variab`` -- variable (default: ``None``); the variable in the
2678
+ resulting polynomial; if unspecified, use either a default variable
2679
+ in `\ZZ[A,A^{-1}]` or the variable `t` in the symbolic ring
2680
+
2681
+ - ``skein_normalization`` -- boolean (default: ``False``); determines
2682
+ the variable of the resulting polynomial
2683
+
2684
+ - ``algorithm`` -- string (default: ``'jonesrep'``); algorithm to use
2685
+ and can be one of the following:
2686
+
2687
+ * ``'jonesrep'`` -- use the Jones representation of the braid
2688
+ representation
2689
+
2690
+ * ``'statesum'`` -- recursively computes the Kauffman bracket
2691
+
2692
+ OUTPUT:
2693
+
2694
+ If ``skein_normalization`` if ``False``, this returns an element
2695
+ in the symbolic ring as the Jones polynomial of the link might
2696
+ have fractional powers when the link is not a knot. Otherwise the
2697
+ result is a Laurent polynomial in ``variab``.
2698
+
2699
+ EXAMPLES:
2700
+
2701
+ The unknot::
2702
+
2703
+ sage: B = BraidGroup(9)
2704
+ sage: b = B([1, 2, 3, 4, 5, 6, 7, 8])
2705
+ sage: Link(b).jones_polynomial() # needs sage.symbolic
2706
+ 1
2707
+
2708
+ The "monster" unknot::
2709
+
2710
+ sage: L = Link([[3,1,2,4],[8,9,1,7],[5,6,7,3],[4,18,6,5],
2711
+ ....: [17,19,8,18],[9,10,11,14],[10,12,13,11],
2712
+ ....: [12,19,15,13],[20,16,14,15],[16,20,17,2]])
2713
+ sage: L.jones_polynomial() # needs sage.symbolic
2714
+ 1
2715
+
2716
+ The Ochiai unknot::
2717
+
2718
+ sage: L = Link([[[1,-2,-3,-8,-12,13,-14,15,-7,-1,2,-4,10,11,-13,12,
2719
+ ....: -11,-16,4,3,-5,6,-9,7,-15,14,16,-10,8,9,-6,5]],
2720
+ ....: [-1,-1,1,1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1]])
2721
+ sage: L.jones_polynomial() # long time # needs sage.symbolic
2722
+ 1
2723
+
2724
+ Two unlinked unknots::
2725
+
2726
+ sage: B = BraidGroup(4)
2727
+ sage: b = B([1, 3])
2728
+ sage: Link(b).jones_polynomial() # needs sage.symbolic
2729
+ -sqrt(t) - 1/sqrt(t)
2730
+
2731
+ The Hopf link::
2732
+
2733
+ sage: B = BraidGroup(2)
2734
+ sage: b = B([-1,-1])
2735
+ sage: Link(b).jones_polynomial() # needs sage.symbolic
2736
+ -1/sqrt(t) - 1/t^(5/2)
2737
+
2738
+ Different representations of the trefoil and one of its mirror::
2739
+
2740
+ sage: B = BraidGroup(2)
2741
+ sage: b = B([-1, -1, -1])
2742
+ sage: Link(b).jones_polynomial(skein_normalization=True)
2743
+ -A^-16 + A^-12 + A^-4
2744
+ sage: Link(b).jones_polynomial() # needs sage.symbolic
2745
+ 1/t + 1/t^3 - 1/t^4
2746
+ sage: B = BraidGroup(3)
2747
+ sage: b = B([-1, -2, -1, -2])
2748
+ sage: Link(b).jones_polynomial(skein_normalization=True)
2749
+ -A^-16 + A^-12 + A^-4
2750
+ sage: R.<x> = LaurentPolynomialRing(GF(2))
2751
+ sage: Link(b).jones_polynomial(skein_normalization=True, variab=x)
2752
+ x^-16 + x^-12 + x^-4
2753
+ sage: B = BraidGroup(3)
2754
+ sage: b = B([1, 2, 1, 2])
2755
+ sage: Link(b).jones_polynomial(skein_normalization=True)
2756
+ A^4 + A^12 - A^16
2757
+
2758
+ `K11n42` (the mirror of the "Kinoshita-Terasaka" knot) and `K11n34`
2759
+ (the mirror of the "Conway" knot) in [KnotAtlas]_::
2760
+
2761
+ sage: B = BraidGroup(4)
2762
+ sage: K11n42 = Link(B([1, -2, 3, -2, 3, -2, -2, -1, 2, -3, -3, 2, 2]))
2763
+ sage: K11n34 = Link(B([1, 1, 2, -3, 2, -3, 1, -2, -2, -3, -3]))
2764
+ sage: bool(K11n42.jones_polynomial() == K11n34.jones_polynomial()) # needs sage.symbolic
2765
+ True
2766
+
2767
+ The two algorithms for computation give the same result when the
2768
+ trace closure of the braid representation is the link itself::
2769
+
2770
+ sage: # needs sage.symbolic
2771
+ sage: L = Link([[[-1, 2, -3, 4, 5, 1, -2, 6, 7, 3, -4, -7, -6, -5]],
2772
+ ....: [-1, -1, -1, -1, 1, -1, 1]])
2773
+ sage: jonesrep = L.jones_polynomial(algorithm='jonesrep')
2774
+ sage: statesum = L.jones_polynomial(algorithm='statesum')
2775
+ sage: bool(jonesrep == statesum)
2776
+ True
2777
+
2778
+ When we have thrown away unknots so that the trace closure of the
2779
+ braid is not necessarily the link itself, this is only true up to a
2780
+ power of the Jones polynomial of the unknot::
2781
+
2782
+ sage: B = BraidGroup(3)
2783
+ sage: b = B([1])
2784
+ sage: L = Link(b)
2785
+ sage: b.components_in_closure()
2786
+ 2
2787
+ sage: L.number_of_components()
2788
+ 1
2789
+ sage: b.jones_polynomial() # needs sage.symbolic
2790
+ -sqrt(t) - 1/sqrt(t)
2791
+ sage: L.jones_polynomial() # needs sage.symbolic
2792
+ 1
2793
+ sage: L.jones_polynomial(algorithm='statesum') # needs sage.symbolic
2794
+ 1
2795
+
2796
+ TESTS::
2797
+
2798
+ sage: L = Link([])
2799
+ sage: L.jones_polynomial(algorithm='statesum') # needs sage.symbolic
2800
+ 1
2801
+
2802
+ sage: L.jones_polynomial(algorithm='other')
2803
+ Traceback (most recent call last):
2804
+ ...
2805
+ ValueError: bad value of algorithm
2806
+
2807
+ Check that :issue:`31001` is fixed::
2808
+
2809
+ sage: L.jones_polynomial() # needs sage.symbolic
2810
+ 1
2811
+ """
2812
+ if algorithm == 'statesum':
2813
+ poly = self._bracket()
2814
+ t = poly.parent().gens()[0]
2815
+ writhe = self.writhe()
2816
+ jones = poly * (-t)**(-3 * writhe)
2817
+ # Switch to the variable A to have the result agree with the output
2818
+ # of the jonesrep algorithm
2819
+ A = LaurentPolynomialRing(ZZ, 'A').gen()
2820
+ jones = jones(A**-1)
2821
+
2822
+ if skein_normalization:
2823
+ if variab is None:
2824
+ return jones
2825
+ else:
2826
+ return jones(variab)
2827
+ else:
2828
+ if variab is None:
2829
+ variab = 't'
2830
+ # We force the result to be in the symbolic ring because of the expand
2831
+ return jones(SR(variab)**(ZZ.one() / ZZ(4))).expand()
2832
+ elif algorithm == 'jonesrep':
2833
+ braid = self.braid()
2834
+ # Special case for the trivial knot with no crossings
2835
+ if not braid.Tietze():
2836
+ if skein_normalization:
2837
+ return LaurentPolynomialRing(ZZ, 'A').one()
2838
+ else:
2839
+ return SR.one()
2840
+ return braid.jones_polynomial(variab, skein_normalization)
2841
+
2842
+ raise ValueError("bad value of algorithm")
2843
+
2844
+ @cached_method
2845
+ def _bracket(self):
2846
+ r"""
2847
+ Return the Kaufmann bracket polynomial of the diagram of ``self``.
2848
+
2849
+ Note that this is not an invariant of the link, but of the diagram.
2850
+ In particular, it is not invariant under Reidemeister I moves.
2851
+
2852
+ EXAMPLES::
2853
+
2854
+ sage: L = Link([[[-1, 2, 3, -4, 5, -6, 7, 8, -2, -5, 6, 1, -8, -3, 4, -7]],
2855
+ ....: [-1, -1, -1, -1, 1, 1, -1, 1]])
2856
+ sage: L._bracket()
2857
+ -t^-10 + 2*t^-6 - t^-2 + 2*t^2 - t^6 + t^10 - t^14
2858
+ sage: L = Link([[2, 1, 3, 4], [4, 3, 1, 2]])
2859
+ sage: L._bracket()
2860
+ -t^-4 - t^4
2861
+ """
2862
+ t = LaurentPolynomialRing(ZZ, 't').gen()
2863
+ pd_code = self.pd_code()
2864
+ if not pd_code:
2865
+ return t.parent().one()
2866
+ if len(pd_code) == 1:
2867
+ if pd_code[0][0] == pd_code[0][3]:
2868
+ return -t**(-3)
2869
+ else:
2870
+ return -t**3
2871
+
2872
+ cross = pd_code[0]
2873
+ rest = [list(vertex) for vertex in pd_code[1:]]
2874
+ [a, b, c, d] = cross
2875
+ if a == d and c == b and len(rest) > 0:
2876
+ return (~t + t**(-5)) * Link(rest)._bracket()
2877
+ elif a == b and c == d and len(rest) > 0:
2878
+ return (t + t**5) * Link(rest)._bracket()
2879
+ elif a == d:
2880
+ for cross in rest:
2881
+ if b in cross:
2882
+ cross[cross.index(b)] = c
2883
+ return -t**(-3) * Link(rest)._bracket()
2884
+ elif a == b:
2885
+ for cross in rest:
2886
+ if c in cross:
2887
+ cross[cross.index(c)] = d
2888
+ return -t**3 * Link(rest)._bracket()
2889
+ elif c == d:
2890
+ for cross in rest:
2891
+ if b in cross:
2892
+ cross[cross.index(b)] = a
2893
+ return -t**3 * Link(rest)._bracket()
2894
+ elif c == b:
2895
+ for cross in rest:
2896
+ if d in cross:
2897
+ cross[cross.index(d)] = a
2898
+ return -t**(-3) * Link(rest)._bracket()
2899
+ else:
2900
+ rest_2 = [list(vertex) for vertex in rest]
2901
+ for cross in rest:
2902
+ if b in cross:
2903
+ cross[cross.index(b)] = a
2904
+ if c in cross:
2905
+ cross[cross.index(c)] = d
2906
+ for cross in rest_2:
2907
+ if b in cross:
2908
+ cross[cross.index(b)] = c
2909
+ if d in cross:
2910
+ cross[cross.index(d)] = a
2911
+ return t * Link(rest)._bracket() + ~t * Link(rest_2)._bracket()
2912
+
2913
+ @cached_method
2914
+ def _isolated_components(self):
2915
+ r"""
2916
+ Return the PD codes of the isolated components of ``self``.
2917
+
2918
+ Isolated components are links corresponding to subdiagrams that
2919
+ do not have any common crossing.
2920
+
2921
+ EXAMPLES::
2922
+
2923
+ sage: L = Link([[1, 1, 2, 2], [3, 3, 4, 4]])
2924
+ sage: L._isolated_components()
2925
+ [[[1, 1, 2, 2]], [[3, 3, 4, 4]]]
2926
+ """
2927
+ G = Graph()
2928
+ for c in self.pd_code():
2929
+ G.add_vertex(tuple(c))
2930
+ V = G.vertices(sort=True)
2931
+ setV = [set(c) for c in V]
2932
+ for i in range(len(V) - 1):
2933
+ for j in range(i + 1, len(V)):
2934
+ if setV[i].intersection(setV[j]):
2935
+ G.add_edge(V[i], V[j])
2936
+ return [[list(i) for i in j]
2937
+ for j in G.connected_components(sort=False)]
2938
+
2939
+ @cached_method
2940
+ def homfly_polynomial(self, var1=None, var2=None, normalization='lm'):
2941
+ r"""
2942
+ Return the HOMFLY polynomial of ``self``.
2943
+
2944
+ The HOMFLY polynomial `P(K)` of a link `K` is a Laurent polynomial
2945
+ in two variables defined using skein relations and for the unknot
2946
+ `U`, we have `P(U) = 1`.
2947
+
2948
+ INPUT:
2949
+
2950
+ - ``var1`` -- (default: ``'L'``) the first variable. If ``normalization``
2951
+ is set to ``az`` resp. ``vz`` the default is ``a`` resp. ``v``
2952
+ - ``var2`` -- (default: ``'M'``) the second variable. If ``normalization``
2953
+ is set to ``az`` resp. ``vz`` the default is ``z``
2954
+ - ``normalization`` -- (default: ``lm``) the system of coordinates
2955
+ and can be one of the following:
2956
+
2957
+ * ``'lm'`` -- corresponding to the Skein relation
2958
+ `L\cdot P(K _+) + L^{-1}\cdot P(K _-) + M\cdot P(K _0) = 0`
2959
+
2960
+ * ``'az'`` -- corresponding to the Skein relation
2961
+ `a\cdot P(K _+) - a^{-1}\cdot P(K _-) = z \cdot P(K _0)`
2962
+
2963
+ * ``'vz'`` -- corresponding to the Skein relation
2964
+ `v^{-1}\cdot P(K _+) - v\cdot P(K _-) = z \cdot P(K _0)`
2965
+
2966
+ where `P(K _+)`, `P(K _-)` and `P(K _0)` represent the HOMFLY
2967
+ polynomials of three links that vary only in one crossing;
2968
+ that is the positive, negative, or smoothed links respectively
2969
+
2970
+ OUTPUT: a Laurent polynomial over the integers
2971
+
2972
+ .. NOTE::
2973
+
2974
+ Use the ``'az'`` normalization to agree with the data
2975
+ in [KnotAtlas]_
2976
+
2977
+ Use the ``'vz'`` normalization to agree with the data
2978
+ `KnotInfo <http://www.indiana.edu/~knotinfo/>`__.
2979
+
2980
+ EXAMPLES:
2981
+
2982
+ We give some examples::
2983
+
2984
+ sage: g = BraidGroup(2).gen(0)
2985
+ sage: K = Knot(g^5)
2986
+ sage: K.homfly_polynomial() # needs sage.libs.homfly
2987
+ L^-4*M^4 - 4*L^-4*M^2 + 3*L^-4 - L^-6*M^2 + 2*L^-6
2988
+
2989
+ The Hopf link::
2990
+
2991
+ sage: L = Link([[1,4,2,3],[4,1,3,2]])
2992
+ sage: L.homfly_polynomial('x', 'y') # needs sage.libs.homfly
2993
+ -x^-1*y + x^-1*y^-1 + x^-3*y^-1
2994
+
2995
+ Another version of the Hopf link where the orientation
2996
+ has been changed. Therefore we substitute `x \mapsto L^{-1}`
2997
+ and `y \mapsto M`::
2998
+
2999
+ sage: L = Link([[1,3,2,4], [4,2,3,1]])
3000
+ sage: L.homfly_polynomial() # needs sage.libs.homfly
3001
+ L^3*M^-1 - L*M + L*M^-1
3002
+ sage: L = Link([[1,3,2,4], [4,2,3,1]])
3003
+ sage: L.homfly_polynomial(normalization='az') # needs sage.libs.homfly
3004
+ a^3*z^-1 - a*z - a*z^-1
3005
+
3006
+ The figure-eight knot::
3007
+
3008
+ sage: L = Link([[2,5,4,1], [5,3,7,6], [6,9,1,4], [9,7,3,2]])
3009
+ sage: L.homfly_polynomial() # needs sage.libs.homfly
3010
+ -L^2 + M^2 - 1 - L^-2
3011
+ sage: L.homfly_polynomial('a', 'z', 'az') # needs sage.libs.homfly
3012
+ a^2 - z^2 - 1 + a^-2
3013
+
3014
+ The "monster" unknot::
3015
+
3016
+ sage: L = Link([[3,1,2,4], [8,9,1,7], [5,6,7,3], [4,18,6,5],
3017
+ ....: [17,19,8,18], [9,10,11,14], [10,12,13,11],
3018
+ ....: [12,19,15,13], [20,16,14,15], [16,20,17,2]])
3019
+ sage: L.homfly_polynomial() # needs sage.libs.homfly
3020
+ 1
3021
+
3022
+ Comparison with KnotInfo::
3023
+
3024
+ sage: # needs sage.libs.homfly
3025
+ sage: KI = K.get_knotinfo(mirror_version=False); KI
3026
+ <KnotInfo.K5_1: '5_1'>
3027
+ sage: K.homfly_polynomial(normalization='vz') == KI.homfly_polynomial()
3028
+ True
3029
+
3030
+ The knot `9_6`::
3031
+
3032
+ sage: # needs sage.libs.homfly
3033
+ sage: B = BraidGroup(3)
3034
+ sage: K = Knot(B([-1,-1,-1,-1,-1,-1,-2,1,-2,-2]))
3035
+ sage: K.homfly_polynomial()
3036
+ L^10*M^4 - L^8*M^6 - 3*L^10*M^2 + 4*L^8*M^4 + L^6*M^6 + L^10
3037
+ - 3*L^8*M^2 - 5*L^6*M^4 - L^8 + 7*L^6*M^2 - 3*L^6
3038
+ sage: K.homfly_polynomial('a', 'z', normalization='az')
3039
+ -a^10*z^4 + a^8*z^6 - 3*a^10*z^2 + 4*a^8*z^4 + a^6*z^6 - a^10
3040
+ + 3*a^8*z^2 + 5*a^6*z^4 - a^8 + 7*a^6*z^2 + 3*a^6
3041
+
3042
+ TESTS:
3043
+
3044
+ This works with isolated components::
3045
+
3046
+ sage: # needs sage.libs.homfly
3047
+ sage: L = Link([[[1, -1], [2, -2]], [1, 1]])
3048
+ sage: L2 = Link([[1, 4, 2, 3], [2, 4, 1, 3]])
3049
+ sage: L2.homfly_polynomial()
3050
+ -L*M^-1 - L^-1*M^-1
3051
+ sage: L.homfly_polynomial()
3052
+ -L*M^-1 - L^-1*M^-1
3053
+ sage: L.homfly_polynomial(normalization='az')
3054
+ a*z^-1 - a^-1*z^-1
3055
+ sage: L2.homfly_polynomial('α', 'ζ', 'az')
3056
+ α*ζ^-1 - α^-1*ζ^-1
3057
+ sage: L.homfly_polynomial(normalization='vz')
3058
+ -v*z^-1 + v^-1*z^-1
3059
+ sage: L2.homfly_polynomial('ν', 'ζ', 'vz')
3060
+ -ν*ζ^-1 + ν^-1*ζ^-1
3061
+
3062
+ Check that :issue:`30346` is fixed::
3063
+
3064
+ sage: L = Link([])
3065
+ sage: L.homfly_polynomial() # needs sage.libs.homfly
3066
+ 1
3067
+
3068
+ REFERENCES:
3069
+
3070
+ - :wikipedia:`HOMFLY_polynomial`
3071
+ - http://mathworld.wolfram.com/HOMFLYPolynomial.html
3072
+ """
3073
+ if not var1:
3074
+ if normalization == 'az':
3075
+ var1 = 'a'
3076
+ elif normalization == 'vz':
3077
+ var1 = 'v'
3078
+ else:
3079
+ var1 = 'L'
3080
+ if not var2:
3081
+ if normalization == 'lm':
3082
+ var2 = 'M'
3083
+ else:
3084
+ var2 = 'z'
3085
+
3086
+ L = LaurentPolynomialRing(ZZ, [var1, var2])
3087
+ if len(self._isolated_components()) > 1:
3088
+ if normalization == 'lm':
3089
+ fact = L({(1, -1): -1, (-1, -1): -1})
3090
+ elif normalization == 'az':
3091
+ fact = L({(1, -1): 1, (-1, -1): -1})
3092
+ elif normalization == 'vz':
3093
+ fact = L({(1, -1): -1, (-1, -1): 1})
3094
+ else:
3095
+ raise ValueError('normalization must be either `lm`, `az` or `vz`')
3096
+ fact = fact ** (len(self._isolated_components()) - 1)
3097
+ for i in self._isolated_components():
3098
+ fact = fact * Link(i).homfly_polynomial(var1, var2, normalization)
3099
+ return fact
3100
+ s = '{}'.format(self.number_of_components())
3101
+ ogc = self.oriented_gauss_code()
3102
+ if not ogc[0]:
3103
+ return L.one()
3104
+ for comp in ogc[0]:
3105
+ s += ' {}'.format(len(comp))
3106
+ for cr in comp:
3107
+ s += ' {} {}'.format(abs(cr) - 1, sign(cr))
3108
+ for i, cr in enumerate(ogc[1]):
3109
+ s += ' {} {}'.format(i, cr)
3110
+ from sage.libs.homfly import homfly_polynomial_dict
3111
+ dic = homfly_polynomial_dict(s)
3112
+ if normalization == 'lm':
3113
+ return L(dic)
3114
+ elif normalization == 'az':
3115
+ auxdic = {}
3116
+ for a in dic:
3117
+ if (a[0] + a[1]) % 4 == 0:
3118
+ auxdic[a] = dic[a]
3119
+ else:
3120
+ auxdic[a] = -dic[a]
3121
+ if self.number_of_components() % 2:
3122
+ return L(auxdic)
3123
+ else:
3124
+ return -L(auxdic)
3125
+ elif normalization == 'vz':
3126
+ h_az = self.homfly_polynomial(var1=var1, var2=var2, normalization='az')
3127
+ a, z = h_az.parent().gens()
3128
+ v = ~a
3129
+ return h_az.subs({a: v})
3130
+ else:
3131
+ raise ValueError('normalization must be either `lm`, `az` or `vz`')
3132
+
3133
+ def links_gould_polynomial(self, varnames='t0, t1'):
3134
+ r"""
3135
+ Return the Links-Gould polynomial of ``self``. See [MW2012]_, section 3
3136
+ and references given there. See also the docstring of
3137
+ :meth:`~sage.groups.braid.Braid.links_gould_polynomial`.
3138
+
3139
+ INPUT:
3140
+
3141
+ - ``varnames`` -- string (default: ``'t0, t1'``)
3142
+
3143
+ OUTPUT: a Laurent polynomial in the given variable names
3144
+
3145
+ EXAMPLES::
3146
+
3147
+ sage: Hopf = Link([[1, 3, 2, 4], [4, 2, 3, 1]])
3148
+ sage: Hopf.links_gould_polynomial() # needs sage.libs.singular
3149
+ -1 + t1^-1 + t0^-1 - t0^-1*t1^-1
3150
+ """
3151
+ return self.braid().links_gould_polynomial(varnames=varnames)
3152
+
3153
+ def _coloring_matrix(self, n=None):
3154
+ r"""
3155
+ Return the coloring matrix of ``self``.
3156
+
3157
+ The coloring matrix is a matrix over a prime field
3158
+ whose right kernel gives the colorings of the diagram.
3159
+
3160
+ INPUT:
3161
+
3162
+ - ``n`` -- the number of colors to consider (if ommitted the
3163
+ value of the determinant of ``self`` will be taken)
3164
+
3165
+ OUTPUT: a matrix over the residue class ring of integers modulo ``n``
3166
+
3167
+ EXAMPLES::
3168
+
3169
+ sage: # needs sage.libs.pari sage.modules
3170
+ sage: K = Link([[[1, -2, 3, -1, 2, -3]], [1, 1, 1]])
3171
+ sage: K._coloring_matrix(3)
3172
+ [2 2 2]
3173
+ [2 2 2]
3174
+ [2 2 2]
3175
+ sage: K8 = Knot([[[1, -2, 4, -3, 2, -1, 3, -4]], [1, 1, -1, -1]])
3176
+ sage: K8._coloring_matrix(4)
3177
+ [2 0 3 3]
3178
+ [3 3 2 0]
3179
+ [0 3 3 2]
3180
+ [3 2 0 3]
3181
+
3182
+ REFERENCES:
3183
+
3184
+ - :wikipedia:`Fox_n-coloring`
3185
+ """
3186
+ if not n:
3187
+ n = self.determinant()
3188
+ from sage.rings.finite_rings.integer_mod_ring import IntegerModRing
3189
+ R = IntegerModRing(n)
3190
+ arcs = self.arcs(presentation='pd')
3191
+ di = len(arcs)
3192
+ M = matrix(R, di, di)
3193
+ crossings = self.pd_code()
3194
+ for i in range(di):
3195
+ crossing = crossings[i]
3196
+ for j in range(di):
3197
+ arc = arcs[j]
3198
+ if crossing[3] in arc:
3199
+ M[i, j] += 2
3200
+ if crossing[0] in arc:
3201
+ M[i, j] -= 1
3202
+ if crossing[2] in arc:
3203
+ M[i, j] -= 1
3204
+ return M
3205
+
3206
+ def is_colorable(self, n=None):
3207
+ r"""
3208
+ Return whether the link is ``n``-colorable.
3209
+
3210
+ A link is ``n``-colorable if its arcs can be painted with
3211
+ ``n`` colours, labeled from ``0`` to ``n - 1``, in such a way
3212
+ that at any crossing, the average of the indices of the
3213
+ undercrossings equals twice the index of the overcrossing.
3214
+
3215
+ INPUT:
3216
+
3217
+ - ``n`` -- the number of colors to consider (if ommitted the
3218
+ value of the determinant of ``self`` will be taken)
3219
+
3220
+ EXAMPLES:
3221
+
3222
+ We show that the trefoil knot is 3-colorable::
3223
+
3224
+ sage: K = Link([[[1, -2, 3, -1, 2, -3]], [1, 1, 1]])
3225
+ sage: K.is_colorable(3) # needs sage.libs.pari sage.modules
3226
+ True
3227
+
3228
+ But the figure eight knot is not::
3229
+
3230
+ sage: K8 = Link([[[1, -2, 4, -3, 2, -1, 3, -4]], [1, 1, -1, -1]])
3231
+ sage: K8.is_colorable(3) # needs sage.libs.pari sage.modules
3232
+ False
3233
+
3234
+ But it is colorable with respect to the value of its determinant::
3235
+
3236
+ sage: K8.determinant()
3237
+ 5
3238
+ sage: K8.is_colorable()
3239
+ True
3240
+
3241
+ An examples with non prime determinant::
3242
+
3243
+ sage: K = Knots().from_table(6, 1)
3244
+ sage: K.determinant()
3245
+ 9
3246
+ sage: K.is_colorable()
3247
+ True
3248
+
3249
+ REFERENCES:
3250
+
3251
+ - :wikipedia:`Fox_n-coloring`
3252
+
3253
+ - Chapter 3 of [Liv1993]_
3254
+
3255
+ .. SEEALSO:: :meth:`colorings` and :meth:`coloring_maps`
3256
+ """
3257
+ M = self._coloring_matrix(n=n)
3258
+ if M.base_ring().is_field():
3259
+ return self._coloring_matrix(n=n).nullity() > 1
3260
+ else:
3261
+ # nullity is not implemented in this case
3262
+ return M.right_kernel_matrix().dimensions()[0] > 1
3263
+
3264
+ def colorings(self, n=None):
3265
+ r"""
3266
+ Return the ``n``-colorings of ``self``.
3267
+
3268
+ INPUT:
3269
+
3270
+ - ``n`` -- the number of colors to consider (if ommitted the value
3271
+ of the determinant of ``self`` will be taken). Note that there
3272
+ are no colorings if n is coprime to the determinant of ``self``
3273
+
3274
+ OUTPUT:
3275
+
3276
+ a list with the colorings. Each coloring is represented as
3277
+ a dictionary that maps a tuple of the edges forming each arc
3278
+ (as in the PD code) to the index of the corresponding color.
3279
+
3280
+ EXAMPLES::
3281
+
3282
+ sage: K = Link([[[1, -2, 3, -1, 2, -3]], [1, 1, 1]])
3283
+ sage: K.colorings(3) # needs sage.libs.pari sage.modules
3284
+ [{(1, 2): 0, (3, 4): 1, (5, 6): 2},
3285
+ {(1, 2): 0, (3, 4): 2, (5, 6): 1},
3286
+ {(1, 2): 1, (3, 4): 0, (5, 6): 2},
3287
+ {(1, 2): 1, (3, 4): 2, (5, 6): 0},
3288
+ {(1, 2): 2, (3, 4): 0, (5, 6): 1},
3289
+ {(1, 2): 2, (3, 4): 1, (5, 6): 0}]
3290
+ sage: K.pd_code()
3291
+ [[4, 2, 5, 1], [2, 6, 3, 5], [6, 4, 1, 3]]
3292
+ sage: K.arcs('pd')
3293
+ [[1, 2], [3, 4], [5, 6]]
3294
+
3295
+ Note that ``n`` is not the number of different colors to be used. It
3296
+ can be looked upon the size of the color palette::
3297
+
3298
+ sage: K = Knots().from_table(9, 15)
3299
+ sage: cols = K.colorings(13); len(cols)
3300
+ 156
3301
+ sage: max(cols[0].values())
3302
+ 12
3303
+ sage: max(cols[13].values())
3304
+ 9
3305
+
3306
+ REFERENCES:
3307
+
3308
+ - :wikipedia:`Fox_n-coloring`
3309
+
3310
+ - Chapter 3 of [Liv1993]_
3311
+
3312
+ .. SEEALSO:: :meth:`is_colorable` and :meth:`coloring_maps`
3313
+ """
3314
+ from sage.modules.free_module import FreeModule
3315
+ M = self._coloring_matrix(n=n)
3316
+ KM = M.right_kernel_matrix()
3317
+ F = FreeModule(M.base_ring(), KM.dimensions()[0])
3318
+ K = [v * KM for v in F]
3319
+ res = set()
3320
+ arcs = self.arcs('pd')
3321
+ for coloring in K:
3322
+ colors = sorted(set(coloring))
3323
+ if len(colors) >= 2:
3324
+ res.add(tuple(coloring))
3325
+ return [{tuple(arc): col for arc, col in zip(arcs, c)}
3326
+ for c in sorted(res)]
3327
+
3328
+ def coloring_maps(self, n=None, finitely_presented=False):
3329
+ r"""
3330
+ Return the `n`-coloring maps of ``self``. These are group
3331
+ homomorphisms from the fundamental group of ``self`` to the
3332
+ `n`-th dihedral group.
3333
+
3334
+ INPUT:
3335
+
3336
+ - ``n`` -- the number of colors to consider (if ommitted the value
3337
+ of the determinant of ``self`` will be taken). Note that there
3338
+ are no coloring maps if n is coprime to the determinant of ``self``
3339
+
3340
+ - ``finitely_presented`` -- boolean (default: ``False``); whether to
3341
+ choose the dihedral groups as finitely presented groups. If not set
3342
+ to ``True`` they are represented as permutation groups.
3343
+
3344
+ OUTPUT:
3345
+
3346
+ a list of group homomporhisms from the fundamental group of ``self``
3347
+ to the `n`-th dihedral group (represented according to the key
3348
+ argument ``finitely_presented``).
3349
+
3350
+ EXAMPLES::
3351
+
3352
+ sage: L5a1_1 = Link([[8, 2, 9, 1], [10, 7, 5, 8], [4, 10, 1, 9],
3353
+ ....: [2, 5, 3, 6], [6, 3, 7, 4]])
3354
+ sage: L5a1_1.determinant()
3355
+ 8
3356
+ sage: L5a1_1.coloring_maps(2)
3357
+ [Group morphism:
3358
+ From: Finitely presented group < x0, x1, x2, x3, x4 | x4*x1*x0^-1*x1^-1, x0*x4^-1*x3^-1*x4, x2*x0*x1^-1*x0^-1, x1*x3^-1*x2^-1*x3, x3*x2^-1*x4^-1*x2 >
3359
+ To: Dihedral group of order 4 as a permutation group,
3360
+ Group morphism:
3361
+ From: Finitely presented group < x0, x1, x2, x3, x4 | x4*x1*x0^-1*x1^-1, x0*x4^-1*x3^-1*x4, x2*x0*x1^-1*x0^-1, x1*x3^-1*x2^-1*x3, x3*x2^-1*x4^-1*x2 >
3362
+ To: Dihedral group of order 4 as a permutation group]
3363
+ sage: col_maps = L5a1_1.coloring_maps(4); len(col_maps)
3364
+ 12
3365
+ sage: col_maps = L5a1_1.coloring_maps(5); len(col_maps)
3366
+ 0
3367
+ sage: col_maps = L5a1_1.coloring_maps(12); len(col_maps)
3368
+ 36
3369
+ sage: col_maps = L5a1_1.coloring_maps(); len(col_maps)
3370
+ 56
3371
+
3372
+ applying the map::
3373
+
3374
+ sage: cm1 = col_maps[0]
3375
+ sage: gs = L5a1_1.fundamental_group().gens()
3376
+ sage: d = cm1(gs[0]); d
3377
+ (1,8)(2,7)(3,6)(4,5)
3378
+ sage: d.parent()
3379
+ Dihedral group of order 16 as a permutation group
3380
+
3381
+ using the finitely presented dihedral group::
3382
+
3383
+ sage: col_maps = L5a1_1.coloring_maps(2, finitely_presented=True)
3384
+ sage: d = col_maps[0](gs[1]); d
3385
+ b*a
3386
+ sage: d.parent()
3387
+ Finitely presented group < a, b | a^2, b^2, (a*b)^2 >
3388
+
3389
+ REFERENCES:
3390
+
3391
+ - :wikipedia:`Fox_n-coloring`
3392
+
3393
+ - Chapter 3 of [Liv1993]_
3394
+
3395
+ .. SEEALSO:: :meth:`is_colorable` and :meth:`colorings`
3396
+ """
3397
+ if not n:
3398
+ n = self.determinant()
3399
+
3400
+ if finitely_presented:
3401
+ from sage.groups.finitely_presented_named import DihedralPresentation
3402
+ D = DihedralPresentation(n)
3403
+ else:
3404
+ from sage.groups.perm_gps.permgroup_named import DihedralGroup
3405
+ D = DihedralGroup(n)
3406
+
3407
+ a, b = D.gens()
3408
+ gr = self.fundamental_group()
3409
+ cols = self.colorings(n=n)
3410
+ maps = []
3411
+ for c in cols:
3412
+ t = list(c.values())
3413
+ ims = [b * a**i for i in t]
3414
+ maps.append(gr.hom(ims))
3415
+ return maps
3416
+
3417
+ def plot(self, gap=0.1, component_gap=0.5, solver=None,
3418
+ color='blue', **kwargs):
3419
+ r"""
3420
+ Plot ``self``.
3421
+
3422
+ INPUT:
3423
+
3424
+ - ``gap`` -- (default: 0.1) the size of the blank gap left for
3425
+ the crossings
3426
+
3427
+ - ``component_gap`` -- (default: 0.5) the gap between isolated
3428
+ components
3429
+
3430
+ - ``solver`` -- the linear solver to use, see
3431
+ :class:`~sage.numerical.mip.MixedIntegerLinearProgram`
3432
+
3433
+ - ``color`` -- string (default: ``'blue'``); a color or a coloring (as
3434
+ returned by :meth:`colorings`
3435
+
3436
+ The usual keywords for plots can be used here too.
3437
+
3438
+ EXAMPLES:
3439
+
3440
+ We construct the simplest version of the unknot::
3441
+
3442
+ sage: L = Link([[2, 1, 1, 2]])
3443
+ sage: L.plot() # needs sage.plot
3444
+ Graphics object consisting of ... graphics primitives
3445
+
3446
+ .. PLOT::
3447
+ :width: 300 px
3448
+
3449
+ B = BraidGroup(2)
3450
+ L = Link([[2, 1, 1, 2]])
3451
+ sphinx_plot(L.plot())
3452
+
3453
+ We construct a more interesting example of the unknot::
3454
+
3455
+ sage: L = Link([[2, 1, 4, 5], [3, 5, 6, 7], [4, 1, 9, 6], [9, 2, 3, 7]])
3456
+ sage: L.plot() # needs sage.plot
3457
+ Graphics object consisting of ... graphics primitives
3458
+
3459
+ .. PLOT::
3460
+ :width: 300 px
3461
+
3462
+ L = Link([[2,1,4,5], [3,5,6,7], [4,1,9,6], [9,2,3,7]])
3463
+ sphinx_plot(L.plot())
3464
+
3465
+ The "monster" unknot::
3466
+
3467
+ sage: L = Link([[3,1,2,4], [8,9,1,7], [5,6,7,3], [4,18,6,5],
3468
+ ....: [17,19,8,18], [9,10,11,14], [10,12,13,11],
3469
+ ....: [12,19,15,13], [20,16,14,15], [16,20,17,2]])
3470
+ sage: L.plot() # needs sage.plot
3471
+ Graphics object consisting of ... graphics primitives
3472
+
3473
+ .. PLOT::
3474
+ :width: 300 px
3475
+
3476
+ L = Link([[3,1,2,4],[8,9,1,7],[5,6,7,3],[4,18,6,5],
3477
+ [17,19,8,18],[9,10,11,14],[10,12,13,11],
3478
+ [12,19,15,13],[20,16,14,15],[16,20,17,2]])
3479
+ sphinx_plot(L.plot())
3480
+
3481
+ The Ochiai unknot::
3482
+
3483
+ sage: L = Link([[[1,-2,-3,-8,-12,13,-14,15,-7,-1,2,-4,10,11,-13,12,
3484
+ ....: -11,-16,4,3,-5,6,-9,7,-15,14,16,-10,8,9,-6,5]],
3485
+ ....: [-1,-1,1,1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1]])
3486
+ sage: L.plot() # needs sage.plot
3487
+ Graphics object consisting of ... graphics primitives
3488
+
3489
+ .. PLOT::
3490
+ :width: 300 px
3491
+
3492
+ L = Link([[[1,-2,-3,-8,-12,13,-14,15,-7,-1,2,-4,10,11,-13,12,
3493
+ -11,-16,4,3,-5,6,-9,7,-15,14,16,-10,8,9,-6,5]],
3494
+ [-1,-1,1,1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1]])
3495
+ sphinx_plot(L.plot())
3496
+
3497
+ One of the representations of the trefoil knot::
3498
+
3499
+ sage: L = Link([[1, 5, 2, 4], [5, 3, 6, 2], [3, 1, 4, 6]])
3500
+ sage: L.plot() # needs sage.plot
3501
+ Graphics object consisting of 14 graphics primitives
3502
+
3503
+ .. PLOT::
3504
+ :width: 300 px
3505
+
3506
+ L = Link([[1, 5, 2, 4], [5, 3, 6, 2], [3, 1, 4, 6]])
3507
+ sphinx_plot(L.plot())
3508
+
3509
+ The figure-eight knot::
3510
+
3511
+ sage: L = Link([[2, 1, 4, 5], [5, 6, 7, 3], [6, 4, 1, 9], [9, 2, 3, 7]])
3512
+ sage: L.plot() # needs sage.plot
3513
+ Graphics object consisting of ... graphics primitives
3514
+
3515
+ .. PLOT::
3516
+ :width: 300 px
3517
+
3518
+ L = Link([[2,1,4,5], [5,6,7,3], [6,4,1,9], [9,2,3,7]])
3519
+ sphinx_plot(L.plot())
3520
+
3521
+ The knot `K11n121` in [KnotAtlas]_::
3522
+
3523
+ sage: L = Link([[4,2,5,1], [10,3,11,4], [5,16,6,17], [7,12,8,13],
3524
+ ....: [18,9,19,10], [2,11,3,12], [13,20,14,21], [15,6,16,7],
3525
+ ....: [22,18,1,17], [8,19,9,20], [21,14,22,15]])
3526
+ sage: L.plot() # needs sage.plot
3527
+ Graphics object consisting of ... graphics primitives
3528
+
3529
+ .. PLOT::
3530
+ :width: 300 px
3531
+
3532
+ L = Link([[4,2,5,1], [10,3,11,4], [5,16,6,17], [7,12,8,13],
3533
+ [18,9,19,10], [2,11,3,12], [13,20,14,21], [15,6,16,7],
3534
+ [22,18,1,17], [8,19,9,20], [21,14,22,15]])
3535
+ sphinx_plot(L.plot())
3536
+
3537
+ One of the representations of the Hopf link::
3538
+
3539
+ sage: L = Link([[1, 4, 2, 3], [4, 1, 3, 2]])
3540
+ sage: L.plot() # needs sage.plot
3541
+ Graphics object consisting of ... graphics primitives
3542
+
3543
+ .. PLOT::
3544
+ :width: 300 px
3545
+
3546
+ L = Link([[1, 4, 2, 3], [4, 1, 3, 2]])
3547
+ sphinx_plot(L.plot())
3548
+
3549
+ Plotting links with multiple isolated components::
3550
+
3551
+ sage: L = Link([[[-1, 2, -3, 1, -2, 3], [4, -5, 6, -4, 5, -6]],
3552
+ ....: [1, 1, 1, 1, 1, 1]])
3553
+ sage: L.plot() # needs sage.plot
3554
+ Graphics object consisting of ... graphics primitives
3555
+
3556
+ .. PLOT::
3557
+ :width: 300 px
3558
+
3559
+ L = Link([[[-1,2,-3,1,-2,3], [4,-5,6,-4,5,-6]], [1,1,1,1,1,1]])
3560
+ sphinx_plot(L.plot())
3561
+
3562
+ If a coloring is passed, the different arcs are plotted with
3563
+ the corresponding colors (see :meth:`colorings`)::
3564
+
3565
+ sage: B = BraidGroup(4)
3566
+ sage: b = B([1,2,3,1,2,-1,-3,2,3])
3567
+ sage: L = Link(b)
3568
+ sage: L.plot(color=L.colorings()[0]) # needs sage.plot
3569
+ Graphics object consisting of ... graphics primitives
3570
+
3571
+ .. PLOT::
3572
+ :width: 300 px
3573
+
3574
+ B = BraidGroup(4)
3575
+ b = B([1, 2, 3, 1, 2, -1, -3, 2, 3])
3576
+ L = Link(b)
3577
+ sphinx_plot(L.plot(color=L.colorings()[0]))
3578
+
3579
+ TESTS:
3580
+
3581
+ Check that :issue:`20315` is fixed::
3582
+
3583
+ sage: # needs sage.plot
3584
+ sage: L = Link([[2,1,4,5], [5,6,7,3], [6,4,1,9], [9,2,3,7]])
3585
+ sage: L.plot(solver='GLPK')
3586
+ Graphics object consisting of ... graphics primitives
3587
+ sage: L.plot(solver='Coin') # optional - sage_numerical_backends_coin
3588
+ Graphics object consisting of ... graphics primitives
3589
+ sage: L.plot(solver='CPLEX') # optional - CPLEX
3590
+ Graphics object consisting of ... graphics primitives
3591
+ sage: L.plot(solver='Gurobi') # optional - Gurobi
3592
+ Graphics object consisting of ... graphics primitives
3593
+ """
3594
+ pd_code = self.pd_code()
3595
+ if type(color) is not dict:
3596
+ coloring = {int(i): color for i in set(flatten(pd_code))}
3597
+ else:
3598
+ from sage.plot.colors import rainbow
3599
+ ncolors = max([int(i) for i in color.values()]) + 1
3600
+ arcs = self.arcs()
3601
+ rainb = rainbow(ncolors)
3602
+ coloring = {int(i): rainb[color[tuple(j)]] for j in arcs for i in j}
3603
+ comp = self._isolated_components()
3604
+ # Handle isolated components individually
3605
+ if len(comp) > 1:
3606
+ L1 = Link(comp[0])
3607
+ L2 = Link(flatten(comp[1:], max_level=1))
3608
+ P1 = L1.plot(gap, **kwargs)
3609
+ P2 = L2.plot(gap, **kwargs)
3610
+ xtra = P1.get_minmax_data()['xmax'] + component_gap - P2.get_minmax_data()['xmin']
3611
+ for P in P2:
3612
+ if hasattr(P, 'path'):
3613
+ for p in P.path[0]:
3614
+ p[0] += xtra
3615
+ for p in P.vertices:
3616
+ p[0] += xtra
3617
+ else:
3618
+ P.xdata = [p + xtra for p in P.xdata]
3619
+ return P1 + P2
3620
+
3621
+ if 'axes' not in kwargs:
3622
+ kwargs['axes'] = False
3623
+ if 'aspect_ratio' not in kwargs:
3624
+ kwargs['aspect_ratio'] = 1
3625
+
3626
+ from sage.plot.line import line
3627
+ from sage.plot.bezier_path import bezier_path
3628
+ from sage.plot.circle import circle
3629
+
3630
+ # Special case for the unknot
3631
+ if not pd_code:
3632
+ return circle((0, 0), ZZ.one() / ZZ(2), color=color, **kwargs)
3633
+
3634
+ # The idea is the same followed in spherogram, but using MLP instead of
3635
+ # network flows.
3636
+ # We start by computing a way to bend the edges left or right
3637
+ # such that the resulting regions are in fact closed regions
3638
+ # with straight angles, and using the minimal number of bends.
3639
+ regions = sorted(self.regions(), key=len)
3640
+ edges = list(set(flatten(pd_code)))
3641
+ edges.sort()
3642
+ MLP = MixedIntegerLinearProgram(maximization=False, solver=solver)
3643
+ # v will be the list of variables in the MLP problem. There will be
3644
+ # two variables for each edge counting the number of bendings needed.
3645
+ # The one with even index corresponds to the flow of this number from
3646
+ # the left-hand-side region to the right-hand-side region if the edge
3647
+ # is positive oriented. The one with odd index corresponds to the
3648
+ # flow in the opposite direction. For a negative oriented edge the
3649
+ # same is true but with exchanged directions. At the end, since we
3650
+ # are minimizing the total, only one of each will be nonzero.
3651
+ v = MLP.new_variable(nonnegative=True, integer=True)
3652
+
3653
+ def flow_from_source(e):
3654
+ r"""
3655
+ Return the flow variable from the source.
3656
+ """
3657
+ if e > 0:
3658
+ return v[2 * edges.index(e)]
3659
+ else:
3660
+ return v[2 * edges.index(-e) + 1]
3661
+
3662
+ def flow_to_sink(e):
3663
+ r"""
3664
+ Return the flow variable to the sink.
3665
+ """
3666
+ return flow_from_source(-e)
3667
+
3668
+ # one condition for each region
3669
+ lr = len(regions)
3670
+ for i in range(lr):
3671
+ r = regions[i]
3672
+ if i < lr - 1:
3673
+ # capacity of interior region, sink if positive, source if negative
3674
+ capacity = len(r) - 4
3675
+ else:
3676
+ # capacity of exterior region, only sink (added to fix :issue:`37587`).
3677
+ capacity = len(r) + 4
3678
+ flow = sum(flow_to_sink(e) - flow_from_source(e) for e in r)
3679
+ MLP.add_constraint(flow == capacity) # exterior region only sink
3680
+
3681
+ MLP.set_objective(MLP.sum(v.values()))
3682
+ MLP.solve()
3683
+ # we store the result in a vector s packing right bends as negative left ones
3684
+ values = MLP.get_values(v, convert=ZZ, tolerance=1e-3)
3685
+ s = [values[2 * i] - values[2 * i + 1] for i in range(len(edges))]
3686
+ # segments represents the different parts of the previous edges after bending
3687
+ segments = {e: [(e, i) for i in range(abs(s[edges.index(e)]) + 1)]
3688
+ for e in edges}
3689
+ pieces = {tuple(i): [i] for j in segments.values() for i in j}
3690
+ nregions = []
3691
+ for r in regions[:-1]: # interior regions
3692
+ nregion = []
3693
+ for e in r:
3694
+ if e > 0:
3695
+ rev = segments[e][:-1]
3696
+ sig = sign(s[edges.index(e)])
3697
+ nregion += [[a, sig] for a in rev]
3698
+ nregion.append([segments[e][-1], 1])
3699
+ else:
3700
+ rev = segments[-e][1:]
3701
+ rev.reverse()
3702
+ sig = sign(s[edges.index(-e)])
3703
+ nregion += [[a, -sig] for a in rev]
3704
+ nregion.append([segments[-e][0], 1])
3705
+ nregions.append(nregion)
3706
+ N = max(segments) + 1
3707
+ segments = [i for j in segments.values() for i in j]
3708
+ badregions = [nr for nr in nregions if any(-1 == x[1] for x in nr)]
3709
+ while badregions:
3710
+ badregion = badregions[0]
3711
+ a = 0
3712
+ while badregion[a][1] != -1:
3713
+ a += 1
3714
+ c = -1
3715
+ b = a
3716
+ while c != 2:
3717
+ if b == len(badregion) - 1:
3718
+ b = 0
3719
+ else:
3720
+ b += 1
3721
+ c += badregion[b][1]
3722
+ otherregion = [nr for nr in nregions
3723
+ if any(badregion[b][0] == x[0] for x in nr)]
3724
+ if len(otherregion) == 1:
3725
+ otherregion = None
3726
+ elif otherregion[0] == badregion:
3727
+ otherregion = otherregion[1]
3728
+ else:
3729
+ otherregion = otherregion[0]
3730
+ N1 = N
3731
+ N = N + 2
3732
+ N2 = N1 + 1
3733
+ segments.append(N1)
3734
+ segments.append(N2)
3735
+ if type(badregion[b][0]) in (int, Integer):
3736
+ segmenttoadd = [x for x in pieces
3737
+ if badregion[b][0] in pieces[x]]
3738
+ if len(segmenttoadd) > 0:
3739
+ pieces[segmenttoadd[0]].append(N2)
3740
+ else:
3741
+ pieces[tuple(badregion[b][0])].append(N2)
3742
+
3743
+ if a < b:
3744
+ r1 = badregion[:a] + [[badregion[a][0], 0], [N1, 1]] + badregion[b:]
3745
+ r2 = badregion[a + 1:b] + [[N2, 1], [N1, 1]]
3746
+ else:
3747
+ r1 = badregion[b:a] + [[badregion[a][0], 0], [N1, 1]]
3748
+ r2 = badregion[:b] + [[N2, 1], [N1, 1]] + badregion[a + 1:]
3749
+
3750
+ if otherregion:
3751
+ c = [x for x in otherregion if badregion[b][0] == x[0]]
3752
+ c = otherregion.index(c[0])
3753
+ otherregion.insert(c + 1, [N2, otherregion[c][1]])
3754
+ otherregion[c][1] = 0
3755
+ nregions.remove(badregion)
3756
+ nregions.append(r1)
3757
+ nregions.append(r2)
3758
+ badregions = [nr for nr in nregions if any(x[1] == -1 for x in nr)]
3759
+ MLP = MixedIntegerLinearProgram(maximization=False, solver=solver)
3760
+ v = MLP.new_variable(nonnegative=True, integer=True)
3761
+ for e in segments:
3762
+ MLP.set_min(v[e], 1)
3763
+ for r in nregions:
3764
+ horp = []
3765
+ horm = []
3766
+ verp = []
3767
+ verm = []
3768
+ direction = 0
3769
+ for se in r:
3770
+ if direction % 4 == 0:
3771
+ horp.append(v[se[0]])
3772
+ elif direction == 1:
3773
+ verp.append(v[se[0]])
3774
+ elif direction == 2:
3775
+ horm.append(v[se[0]])
3776
+ elif direction == 3:
3777
+ verm.append(v[se[0]])
3778
+ if se[1] == 1:
3779
+ direction += 1
3780
+ MLP.add_constraint(MLP.sum(horp) - MLP.sum(horm) == 0)
3781
+ MLP.add_constraint(MLP.sum(verp) - MLP.sum(verm) == 0)
3782
+ MLP.set_objective(MLP.sum(v.values()))
3783
+ MLP.solve()
3784
+ v = MLP.get_values(v)
3785
+ lengths = {piece: sum(v[a] for a in pieces[piece]) for piece in pieces}
3786
+ image = line([], **kwargs)
3787
+ crossings = {tuple(pd_code[0]): (0, 0, 0)}
3788
+ availables = pd_code[1:]
3789
+ used_edges = []
3790
+ ims = line([], **kwargs)
3791
+ while len(used_edges) < len(edges):
3792
+ cross_keys = list(crossings.keys())
3793
+ i = 0
3794
+ j = 0
3795
+ while cross_keys[i][j] in used_edges:
3796
+ if j < 3:
3797
+ j += 1
3798
+ else:
3799
+ j = 0
3800
+ i += 1
3801
+ c = cross_keys[i]
3802
+ e = c[j]
3803
+ kwargs['color'] = coloring[e]
3804
+ used_edges.append(e)
3805
+ direction = (crossings[c][2] + c.index(e)) % 4
3806
+ orien = self.orientation()[pd_code.index(list(c))]
3807
+ if s[edges.index(e)] < 0:
3808
+ turn = -1
3809
+ else:
3810
+ turn = 1
3811
+ lengthse = [lengths[(e, k)] for k in range(abs(s[edges.index(e)]) + 1)]
3812
+ if c.index(e) == 0 or (c.index(e) == 3 and orien == 1) or (c.index(e) == 1 and orien == -1):
3813
+ turn = -turn
3814
+ lengthse.reverse()
3815
+ tailshort = (c.index(e) % 2 == 0)
3816
+ x0 = crossings[c][0]
3817
+ y0 = crossings[c][1]
3818
+ im = []
3819
+ for l in lengthse:
3820
+ if direction == 0:
3821
+ x1 = x0 + l
3822
+ y1 = y0
3823
+ elif direction == 1:
3824
+ x1 = x0
3825
+ y1 = y0 + l
3826
+ elif direction == 2:
3827
+ x1 = x0 - l
3828
+ y1 = y0
3829
+ elif direction == 3:
3830
+ x1 = x0
3831
+ y1 = y0 - l
3832
+ im.append(([[x0, y0], [x1, y1]], l, direction))
3833
+ direction = (direction + turn) % 4
3834
+ x0 = x1
3835
+ y0 = y1
3836
+ direction = (direction - turn) % 4
3837
+ c2 = [ee for ee in availables if e in ee]
3838
+ if len(c2) == 1:
3839
+ availables.remove(c2[0])
3840
+ crossings[tuple(c2[0])] = (x1, y1, (direction - c2[0].index(e) + 2) % 4)
3841
+ c2 = [ee for ee in pd_code if e in ee and ee != list(c)]
3842
+ if not c2:
3843
+ headshort = not tailshort
3844
+ else:
3845
+ headshort = (c2[0].index(e) % 2 == 0)
3846
+ a = deepcopy(im[0][0])
3847
+ b = deepcopy(im[-1][0])
3848
+
3849
+ def delta(u, v):
3850
+ if u < v:
3851
+ return -gap
3852
+ if u > v:
3853
+ return gap
3854
+ return 0
3855
+
3856
+ if tailshort:
3857
+ im[0][0][0][0] += delta(a[1][0], im[0][0][0][0])
3858
+ im[0][0][0][1] += delta(a[1][1], im[0][0][0][1])
3859
+ if headshort:
3860
+ im[-1][0][1][0] -= delta(b[1][0], im[-1][0][0][0])
3861
+ im[-1][0][1][1] -= delta(b[1][1], im[-1][0][0][1])
3862
+ l = line([], **kwargs)
3863
+ c = 0
3864
+ p = im[0][0][0]
3865
+ if len(im) == 4 and max(x[1] for x in im) == 1:
3866
+ l = bezier_path([[im[0][0][0], im[0][0][1], im[-1][0][0], im[-1][0][1]]], **kwargs)
3867
+ p = im[-1][0][1]
3868
+ else:
3869
+ while c < len(im)-1:
3870
+ if im[c][1] > 1:
3871
+ (a, b) = im[c][0]
3872
+ if b[0] > a[0]:
3873
+ e = [b[0] - 1, b[1]]
3874
+ elif b[0] < a[0]:
3875
+ e = [b[0] + 1, b[1]]
3876
+ elif b[1] > a[1]:
3877
+ e = [b[0], b[1] - 1]
3878
+ elif b[1] < a[1]:
3879
+ e = [b[0], b[1] + 1]
3880
+ l += line((p, e), **kwargs)
3881
+ p = e
3882
+ if im[c+1][1] == 1 and c < len(im) - 2:
3883
+ xr = round(im[c+2][0][1][0])
3884
+ yr = round(im[c+2][0][1][1])
3885
+ xp = xr - im[c+2][0][1][0]
3886
+ yp = yr - im[c+2][0][1][1]
3887
+ q = [p[0] + im[c+1][0][1][0] - im[c+1][0][0][0] - xp,
3888
+ p[1] + im[c+1][0][1][1] - im[c+1][0][0][1] - yp]
3889
+ l += bezier_path([[p, im[c+1][0][0], im[c+1][0][1], q]], **kwargs)
3890
+ c += 2
3891
+ p = q
3892
+ else:
3893
+ if im[c+1][1] == 1:
3894
+ q = im[c+1][0][1]
3895
+ else:
3896
+ q = [im[c+1][0][0][0] + sign(im[c+1][0][1][0] - im[c+1][0][0][0]),
3897
+ im[c+1][0][0][1] + sign(im[c+1][0][1][1] - im[c+1][0][0][1])]
3898
+ l += bezier_path([[p, im[c+1][0][0], q]], **kwargs)
3899
+ p = q
3900
+ c += 1
3901
+ l += line([p, im[-1][0][1]], **kwargs)
3902
+ image += l
3903
+ ims += sum(line(a[0], **kwargs) for a in im)
3904
+ return image
3905
+
3906
+ def _markov_move_cmp(self, braid):
3907
+ r"""
3908
+ Return whether ``self`` can be transformed to the closure of ``braid``
3909
+ by a sequence of Markov moves.
3910
+
3911
+ More precisely it is checked whether the braid of ``self`` is conjugated
3912
+ to the given braid in the following sense. If both braids have the same
3913
+ number of strands it is checked if they are conjugated to each other in
3914
+ their common braid group (Markov move I). If the number of strands differs,
3915
+ the braid having less strands is extended by Markov moves II (appending
3916
+ the largest generator or its inverse recursively) until a common braid
3917
+ group can be achieved, where conjugation is tested.
3918
+
3919
+ Be aware, that a negative result does not ensure that ``self`` is not
3920
+ isotopic to the closure of ``braid``.
3921
+
3922
+ EXAMPLES::
3923
+
3924
+ sage: # needs sage.libs.braiding
3925
+ sage: b = BraidGroup(4)((1, 2, -3, 2, 2, 2, 2, 2, 2, -1, 2, 3, 2))
3926
+ sage: L = Link([[2, 5, 4, 1], [5, 7, 6, 4], [7, 9, 8, 6], [9, 11, 10, 8],
3927
+ ....: [11, 13, 12, 10], [13, 15, 14, 12], [15, 17, 16, 14],
3928
+ ....: [3, 19, 18, 17], [16, 18, 21, 1], [19, 3, 2, 21]])
3929
+ sage: L._markov_move_cmp(b) # both are isotopic to ``9_3``
3930
+ True
3931
+ sage: bL = L.braid(); bL
3932
+ s0^7*s1*s0^-1*s1
3933
+ sage: Lb = Link(b); Lb
3934
+ Link with 1 component represented by 13 crossings
3935
+ sage: Lb._markov_move_cmp(bL)
3936
+ True
3937
+ sage: L == Lb
3938
+ False
3939
+ sage: b.strands() > bL.strands()
3940
+ True
3941
+
3942
+ REFERENCES:
3943
+
3944
+ - :wikipedia:`Markov_theorem`
3945
+ """
3946
+ sb = self.braid()
3947
+ sb_ind = sb.strands()
3948
+
3949
+ ob = braid
3950
+ ob_ind = ob.strands()
3951
+
3952
+ if sb_ind == ob_ind:
3953
+ return sb.is_conjugated(ob)
3954
+
3955
+ if sb_ind > ob_ind:
3956
+ # if the braid of self has more strands we have to perfom
3957
+ # Markov II moves
3958
+ B = sb.parent()
3959
+ g = B.gen(ob_ind-1)
3960
+ ob = B(ob)
3961
+ if sb_ind > ob_ind+1:
3962
+ # proceed by recursion
3963
+ res = self._markov_move_cmp(ob*g)
3964
+ if not res:
3965
+ res = self._markov_move_cmp(ob*~g)
3966
+ else:
3967
+ res = sb.is_conjugated(ob*g)
3968
+ if not res:
3969
+ res = sb.is_conjugated(ob*~g)
3970
+ return res
3971
+ else:
3972
+ L = Link(ob)
3973
+ return L._markov_move_cmp(sb)
3974
+
3975
+ @cached_method
3976
+ def _knotinfo_matching_list(self):
3977
+ r"""
3978
+ Return a list of links from the KnotInfo and LinkInfo databases which match
3979
+ the properties of ``self`` as much as possible.
3980
+
3981
+ OUTPUT:
3982
+
3983
+ A tuple ``(l, proved)`` where ``l`` is the matching list and ``proved`` a boolean
3984
+ telling if the entries of ``l`` are checked to be isotopic to ``self`` or not.
3985
+
3986
+ EXAMPLES::
3987
+
3988
+ sage: KnotInfo.L5a1_0.inject()
3989
+ Defining L5a1_0
3990
+ sage: ML = L5a1_0.link()._knotinfo_matching_list(); ML # needs sage.libs.homfly
3991
+ ([<KnotInfo.L5a1_0: 'L5a1{0}'>, <KnotInfo.L5a1_1: 'L5a1{1}'>], True)
3992
+ sage: ML == Link(L5a1_0.braid())._knotinfo_matching_list() # needs sage.libs.homfly
3993
+ True
3994
+
3995
+ Care is needed for links having non irreducible HOMFLY-PT polynomials::
3996
+
3997
+ sage: k4_1 = KnotInfo.K4_1.link()
3998
+ sage: k5_2 = KnotInfo.K5_2.link()
3999
+ sage: k = k4_1.connected_sum(k5_2)
4000
+ sage: k._knotinfo_matching_list() # optional - database_knotinfo # needs sage.libs.homfly
4001
+ ([<KnotInfo.K9_12: '9_12'>], False)
4002
+ """
4003
+ from sage.knots.knotinfo import KnotInfoSeries
4004
+ pd_code = self.pd_code()
4005
+ cr = len(pd_code)
4006
+ co = self.number_of_components()
4007
+
4008
+ # set the limits for the KnotInfoSeries
4009
+ if cr > 11 and co > 1:
4010
+ cr = 11
4011
+ cr = min(cr, 13)
4012
+
4013
+ Hp = self.homfly_polynomial(normalization='vz')
4014
+
4015
+ det = None
4016
+ if cr > 6:
4017
+ # for larger crossing numbers the KnotInfoSeries become very
4018
+ # large, as well. For better performance we restrict the cached
4019
+ # lists by the determinant and number of components.
4020
+ #
4021
+ # Since :meth:`determinant` is not implemented for proper links
4022
+ # we have to go back to the roots.
4023
+ ap = self.alexander_polynomial()
4024
+ det = Integer(abs(ap(-1)))
4025
+
4026
+ is_knot = self.is_knot()
4027
+ if is_knot and cr < 11:
4028
+ S = KnotInfoSeries(cr, True, None)
4029
+ l = S.lower_list(oriented=True, comp=co, det=det, homfly=Hp)
4030
+ else:
4031
+ # the result of :meth:`is_alternating` depends on the specific
4032
+ # diagram of the link. For example ``K11a_2`` is an alternating
4033
+ # knot but ``Link(KnotInfo.K11a_2.braid()).is_alternating()``
4034
+ # gives ``False``. Therefore, we have to take both series
4035
+ # into consideration.
4036
+ Sa = KnotInfoSeries(cr, is_knot, True)
4037
+ Sn = KnotInfoSeries(cr, is_knot, False)
4038
+ la = Sa.lower_list(oriented=True, comp=co, det=det, homfly=Hp)
4039
+ ln = Sn.lower_list(oriented=True, comp=co, det=det, homfly=Hp)
4040
+ l = sorted(set(la + ln))
4041
+
4042
+ br = self.braid()
4043
+ br_ind = br.strands()
4044
+
4045
+ res = []
4046
+ for L in l:
4047
+ if L.pd_notation() == pd_code:
4048
+ # pd_notation is unique in the KnotInfo database
4049
+ res.append(L)
4050
+ continue
4051
+
4052
+ Lbraid = L.braid()
4053
+ if Lbraid.strands() <= br_ind:
4054
+ if self._markov_move_cmp(Lbraid):
4055
+ res.append(L)
4056
+
4057
+ if res:
4058
+ if len(res) > 1 or res[0].is_unique():
4059
+ return res, True
4060
+ return l, False
4061
+
4062
+ def _knotinfo_matching_dict(self):
4063
+ r"""
4064
+ Return a dictionary mapping items of the enum :class:`~sage.knots.knotinfo.SymmetryMutant`
4065
+ to list of links from the KnotInfo and LinkInfo databases which match
4066
+ the properties of the according symmetry mutant of ``self`` as much as
4067
+ possible.
4068
+
4069
+ OUTPUT:
4070
+
4071
+ A pair (``match_lists, proves``) of dictionaries with keys from the
4072
+ enum :class:`~sage.knots.knotinfo.SymmetryMutant`. The first dictionary maps these keys to
4073
+ the corresponding matching list and ``proves`` maps them to booleans
4074
+ telling if the entries of the corresponding ``match_lists`` are checked
4075
+ to be isotopic to the symmetry mutant of ``self`` or not.
4076
+
4077
+ EXAMPLES::
4078
+
4079
+ sage: # needs sage.libs.homfly
4080
+ sage: KnotInfo.L4a1_0.inject()
4081
+ Defining L4a1_0
4082
+ sage: L4a1_0.link()._knotinfo_matching_dict()
4083
+ ({<SymmetryMutant.itself: 's'>: [<KnotInfo.L4a1_0: 'L4a1{0}'>],
4084
+ <SymmetryMutant.reverse: 'r'>: [<KnotInfo.L4a1_0: 'L4a1{0}'>],
4085
+ <SymmetryMutant.mirror_image: 'm'>: [],
4086
+ <SymmetryMutant.concordance_inverse: 'c'>: []},
4087
+ {<SymmetryMutant.itself: 's'>: True,
4088
+ <SymmetryMutant.reverse: 'r'>: True,
4089
+ <SymmetryMutant.mirror_image: 'm'>: False,
4090
+ <SymmetryMutant.concordance_inverse: 'c'>: False})
4091
+ """
4092
+ from sage.knots.knotinfo import SymmetryMutant
4093
+ mutant = {}
4094
+ mutant[SymmetryMutant.itself] = self
4095
+ mutant[SymmetryMutant.reverse] = self.reverse()
4096
+ mutant[SymmetryMutant.mirror_image] = self.mirror_image()
4097
+ mutant[SymmetryMutant.concordance_inverse] = mutant[SymmetryMutant.mirror_image].reverse()
4098
+ match_lists = {k: list(mutant[k]._knotinfo_matching_list()[0]) for k in mutant.keys()}
4099
+ proves = {k: mutant[k]._knotinfo_matching_list()[1] for k in mutant.keys()}
4100
+ return match_lists, proves
4101
+
4102
+ def get_knotinfo(self, mirror_version=True, unique=True):
4103
+ r"""
4104
+ Identify this link as an item of the KnotInfo database (if possible).
4105
+
4106
+ INPUT:
4107
+
4108
+ - ``mirror_version`` -- boolean (default: ``True``); if set to ``False``
4109
+ the result of the method will be just the instance of :class:`~sage.knots.knotinfo.KnotInfoBase`
4110
+ (by default the result is a tuple of the instance and an enum, see
4111
+ explanation of the output below)
4112
+
4113
+ - ``unique`` -- boolean (default: ``True``); this only affects the case
4114
+ where a unique identification is not possible. If set to ``False`` you
4115
+ can obtain a matching list (see explanation of the output below).
4116
+
4117
+ OUTPUT:
4118
+
4119
+ If ``self`` is a knot, then an element of the free monoid over prime
4120
+ knots constructed from the KnotInfo database is returned. More explicitly
4121
+ this is an element of :class:`~sage.knots.free_knotinfo_monoid.FreeKnotInfoMonoidElement`.
4122
+ Else a tuple ``(K, m)`` is returned where ``K`` is an instance of
4123
+ :class:`~sage.knots.knotinfo.KnotInfoBase` and ``m`` an instance of
4124
+ :class:`~sage.knots.knotinfo.SymmetryMutant` (for chiral links) specifying
4125
+ the symmetry mutant of ``K`` to which ``self`` is isotopic. The value of
4126
+ ``m`` is ``unknown`` if it cannot be determined uniquely and the keyword
4127
+ option ``unique=False`` is given.
4128
+
4129
+ For proper links, if the orientation mutant cannot be uniquely determined,
4130
+ K will be a series of links gathering all links having the same unoriented
4131
+ name, that is an instance of :class:`~sage.knots.knotinfo.KnotInfoSeries`.
4132
+
4133
+ If ``mirror_version`` is set to ``False`` then the result is just ``K``
4134
+ (that is: ``m`` is suppressed).
4135
+
4136
+ If it is not possible to determine a unique result
4137
+ a :exc:`NotImplementedError`
4138
+ will be raised. To avoid this you can set ``unique`` to ``False``. You
4139
+ will get a list of matching candidates instead.
4140
+
4141
+ .. NOTE::
4142
+
4143
+ The identification of proper links may fail to be unique due to the
4144
+ following fact: In opposite to the database for knots, there are pairs
4145
+ of oriented mutants of an unoriented link which are isotopic to each
4146
+ other. For example ``L5a1_0`` and ``L5a1_1`` is such a pair.
4147
+
4148
+ This is because all combinatorial possible oriented mutants are
4149
+ listed with individual names regardless whether they are pairwise
4150
+ non isotopic or not. In such a case the identification is not
4151
+ unique and therefore a series of the links will be returned which
4152
+ gathers all having the same unoriented name.
4153
+
4154
+ To obtain the individual oriented links being isotopic to ``self``
4155
+ use the keyword ``unique`` (see the examples for ``L2a1_1`` and
4156
+ ``L5a1_0`` below).
4157
+
4158
+ EXAMPLES::
4159
+
4160
+ sage: # optional - database_knotinfo
4161
+ sage: L = Link([[4,1,5,2], [10,4,11,3], [5,17,6,16], [7,13,8,12],
4162
+ ....: [18,10,19,9], [2,12,3,11], [13,21,14,20], [15,7,16,6],
4163
+ ....: [22,17,1,18], [8,20,9,19], [21,15,22,14]])
4164
+ sage: L.get_knotinfo()
4165
+ KnotInfo['K11n_121m']
4166
+ sage: K = KnotInfo.K10_25
4167
+ sage: l = K.link()
4168
+ sage: l.get_knotinfo()
4169
+ KnotInfo['K10_25']
4170
+ sage: k11 = KnotInfo.K11n_82.link()
4171
+ sage: k11m = k11.mirror_image()
4172
+ sage: k11mr = k11m.reverse()
4173
+ sage: k11mr.get_knotinfo()
4174
+ KnotInfo['K11n_82m']
4175
+ sage: k11r = k11.reverse()
4176
+ sage: k11r.get_knotinfo()
4177
+ KnotInfo['K11n_82']
4178
+ sage: k11rm = k11r.mirror_image()
4179
+ sage: k11rm.get_knotinfo()
4180
+ KnotInfo['K11n_82m']
4181
+
4182
+ Knots with more than 13 and multi-component links having more than 11
4183
+ crossings cannot be identified. In addition non prime multi-component
4184
+ links or even links whose HOMFLY-PT polynomial is not irreducible cannot
4185
+ be identified::
4186
+
4187
+ sage: b, = BraidGroup(2).gens()
4188
+ sage: Link(b**13).get_knotinfo() # optional - database_knotinfo
4189
+ KnotInfo['K13a_4878']
4190
+ sage: Link(b**14).get_knotinfo() # needs libhomfly
4191
+ Traceback (most recent call last):
4192
+ ...
4193
+ NotImplementedError: this link having more than 11 crossings cannot be determined
4194
+
4195
+ sage: Link([[1, 4, 2, 5], [3, 8, 4, 1], [5, 2, 6, 3],
4196
+ ....: [6, 10, 7, 9], [10, 8, 9, 7]])
4197
+ Link with 2 components represented by 5 crossings
4198
+ sage: _.get_knotinfo() # needs sage.libs.homfly
4199
+ Traceback (most recent call last):
4200
+ ...
4201
+ NotImplementedError: this (possibly non prime) link cannot be determined
4202
+
4203
+ Lets identify the monster unknot::
4204
+
4205
+ sage: # needs sage.libs.homfly
4206
+ sage: L = Link([[3,1,2,4], [8,9,1,7], [5,6,7,3], [4,18,6,5],
4207
+ ....: [17,19,8,18], [9,10,11,14], [10,12,13,11],
4208
+ ....: [12,19,15,13], [20,16,14,15], [16,20,17,2]])
4209
+ sage: L.get_knotinfo()
4210
+ KnotInfo['K0_1']
4211
+
4212
+ Usage of option ``mirror_version``::
4213
+
4214
+ sage: L.get_knotinfo(mirror_version=False) == KnotInfo.K0_1 # needs sage.libs.homfly
4215
+ True
4216
+
4217
+ Usage of option ``unique``::
4218
+
4219
+ sage: # optional - database_knotinfo
4220
+ sage: l = K.link(K.items.gauss_notation)
4221
+ sage: l.get_knotinfo()
4222
+ Traceback (most recent call last):
4223
+ ...
4224
+ NotImplementedError: this link cannot be uniquely determined
4225
+ use keyword argument `unique` to obtain more details
4226
+ sage: l.get_knotinfo(unique=False)
4227
+ [KnotInfo['K10_25'], KnotInfo['K10_56']]
4228
+ sage: t = (1, -2, 1, 1, -2, 1, -2, -2)
4229
+ sage: l8 = Link(BraidGroup(3)(t))
4230
+ sage: l8.get_knotinfo()
4231
+ Traceback (most recent call last):
4232
+ ...
4233
+ NotImplementedError: this link cannot be uniquely determined
4234
+ use keyword argument `unique` to obtain more details
4235
+ sage: l8.get_knotinfo(unique=False)
4236
+ [(<KnotInfo.L8a19_0_0: 'L8a19{0,0}'>, <SymmetryMutant.itself: 's'>),
4237
+ (<KnotInfo.L8a19_1_1: 'L8a19{1,1}'>, <SymmetryMutant.itself: 's'>)]
4238
+ sage: t = (2, -3, -3, -2, 3, 3, -2, 3, 1, -2, -2, 1)
4239
+ sage: l12 = Link(BraidGroup(5)(t))
4240
+ sage: l12.get_knotinfo()
4241
+ Traceback (most recent call last):
4242
+ ...
4243
+ NotImplementedError: this link having more than 11 crossings
4244
+ cannot be uniquely determined
4245
+ use keyword argument `unique` to obtain more details
4246
+ sage: l12.get_knotinfo(unique=False)
4247
+ [(<KnotInfo.L10n36_0: 'L10n36{0}'>, <SymmetryMutant.unknown: '?'>),
4248
+ (<KnotInfo.L10n36_1: 'L10n36{1}'>, <SymmetryMutant.unknown: '?'>),
4249
+ (<KnotInfo.L10n59_0: 'L10n59{0}'>, <SymmetryMutant.itself: 's'>),
4250
+ (<KnotInfo.L10n59_1: 'L10n59{1}'>, <SymmetryMutant.itself: 's'>)]
4251
+
4252
+ Furthermore, if the result is a complete series of oriented links having
4253
+ the same unoriented name (according to the note above) the option can be
4254
+ used to achieve more detailed information::
4255
+
4256
+ sage: # needs sage.libs.homfly
4257
+ sage: L2a1 = Link(b**2)
4258
+ sage: L2a1.get_knotinfo()
4259
+ (Series of links L2a1, <SymmetryMutant.mixed: 'x'>)
4260
+ sage: L2a1.get_knotinfo(unique=False)
4261
+ [(<KnotInfo.L2a1_0: 'L2a1{0}'>, <SymmetryMutant.mirror_image: 'm'>),
4262
+ (<KnotInfo.L2a1_1: 'L2a1{1}'>, <SymmetryMutant.itself: 's'>)]
4263
+
4264
+ sage: # needs sage.libs.homfly
4265
+ sage: KnotInfo.L5a1_0.inject()
4266
+ Defining L5a1_0
4267
+ sage: l5 = Link(L5a1_0.braid())
4268
+ sage: l5.get_knotinfo()
4269
+ (Series of links L5a1, <SymmetryMutant.itself: 's'>)
4270
+ sage: _[0].inject()
4271
+ Defining L5a1
4272
+ sage: list(L5a1)
4273
+ [<KnotInfo.L5a1_0: 'L5a1{0}'>, <KnotInfo.L5a1_1: 'L5a1{1}'>]
4274
+ sage: l5.get_knotinfo(unique=False)
4275
+ [(<KnotInfo.L5a1_0: 'L5a1{0}'>, <SymmetryMutant.itself: 's'>),
4276
+ (<KnotInfo.L5a1_1: 'L5a1{1}'>, <SymmetryMutant.itself: 's'>)]
4277
+
4278
+ Clarifying the series around the Perko pair (:wikipedia:`Perko_pair`)::
4279
+
4280
+ sage: for i in range(160, 166): # optional - database_knotinfo
4281
+ ....: K = Knots().from_table(10, i)
4282
+ ....: print('%s_%s' %(10, i), '--->', K.get_knotinfo())
4283
+ 10_160 ---> KnotInfo['K10_160']
4284
+ 10_161 ---> KnotInfo['K10_161m']
4285
+ 10_162 ---> KnotInfo['K10_162']
4286
+ 10_163 ---> KnotInfo['K10_163']
4287
+ 10_164 ---> KnotInfo['K10_164']
4288
+ 10_165 ---> KnotInfo['K10_165m']
4289
+
4290
+ Clarifying ther Perko series against `SnapPy
4291
+ <https://snappy.math.uic.edu/index.html>`__::
4292
+
4293
+ sage: import snappy # optional - snappy
4294
+ ...
4295
+
4296
+ sage: # optional - database_knotinfo snappy
4297
+ sage: from sage.knots.knotinfo import KnotInfoSeries
4298
+ sage: KnotInfoSeries(10, True, True)
4299
+ Series of knots K10
4300
+ sage: _.inject()
4301
+ Defining K10
4302
+ sage: for i in range(160, 166):
4303
+ ....: K = K10(i)
4304
+ ....: k = K.link(K.items.name, snappy=True)
4305
+ ....: print(k, '--->', k.sage_link().get_knotinfo())
4306
+ <Link 10_160: 1 comp; 10 cross> ---> KnotInfo['K10_160']
4307
+ <Link 10_161: 1 comp; 10 cross> ---> KnotInfo['K10_161m']
4308
+ <Link 10_162: 1 comp; 10 cross> ---> KnotInfo['K10_161']
4309
+ <Link 10_163: 1 comp; 10 cross> ---> KnotInfo['K10_162']
4310
+ <Link 10_164: 1 comp; 10 cross> ---> KnotInfo['K10_163']
4311
+ <Link 10_165: 1 comp; 10 cross> ---> KnotInfo['K10_164']
4312
+ sage: snappy.Link('10_166')
4313
+ <Link 10_166: 1 comp; 10 cross>
4314
+ sage: _.sage_link().get_knotinfo()
4315
+ KnotInfo['K10_165m']
4316
+
4317
+ Another pair of confusion (see the corresponding `Warning
4318
+ <http://katlas.math.toronto.edu/wiki/10_86>`__)::
4319
+
4320
+ sage: # optional - database_knotinfo snappy
4321
+ sage: Ks10_86 = snappy.Link('10_86')
4322
+ sage: Ks10_83 = snappy.Link('10_83')
4323
+ sage: Ks10_86.sage_link().get_knotinfo(unique=False)
4324
+ [KnotInfo['K10_83c'], KnotInfo['K10_83m']]
4325
+ sage: Ks10_83.sage_link().get_knotinfo(unique=False)
4326
+ [KnotInfo['K10_86'], KnotInfo['K10_86r']]
4327
+
4328
+ Non prime knots can be detected, as well::
4329
+
4330
+ sage: b = BraidGroup(4)((1, 2, 2, 2, -1, 2, 2, 2, -3, -3, -3))
4331
+ sage: Kb = Knot(b)
4332
+ sage: Kb.get_knotinfo() # optional - database_knotinfo, needs sage.libs.homfly
4333
+ KnotInfo['K3_1']^2*KnotInfo['K3_1m']
4334
+
4335
+ sage: K = Link([[4, 2, 5, 1], [8, 6, 9, 5], [6, 3, 7, 4], [2, 7, 3, 8],
4336
+ ....: [10, 15, 11, 16], [12, 21, 13, 22], [14, 11, 15, 12], [16, 9, 17, 10],
4337
+ ....: [18, 25, 19, 26], [20, 23, 21, 24], [22, 13, 23, 14], [24, 19, 25, 20],
4338
+ ....: [26, 17, 1, 18]])
4339
+ sage: K.get_knotinfo() # optional - database_knotinfo, long time, needs sage.libs.homfly
4340
+ KnotInfo['K4_1']*KnotInfo['K9_2m']
4341
+
4342
+ TESTS::
4343
+
4344
+ sage: # optional - database_knotinfo
4345
+ sage: L = KnotInfo.L10a171_1_1_0
4346
+ sage: l = L.link(L.items.braid_notation)
4347
+ sage: l.get_knotinfo(unique=False)
4348
+ [(<KnotInfo.L10a171_0_1_0: 'L10a171{0,1,0}'>, <SymmetryMutant.unknown: '?'>),
4349
+ (<KnotInfo.L10a171_1_0_1: 'L10a171{1,0,1}'>, <SymmetryMutant.unknown: '?'>),
4350
+ (<KnotInfo.L10a171_1_1_0: 'L10a171{1,1,0}'>, <SymmetryMutant.unknown: '?'>),
4351
+ (<KnotInfo.L10a171_1_1_1: 'L10a171{1,1,1}'>, <SymmetryMutant.unknown: '?'>)]
4352
+ sage: KnotInfo.L10a151_0_0.link().get_knotinfo()
4353
+ Traceback (most recent call last):
4354
+ ...
4355
+ NotImplementedError: this link cannot be uniquely determined (unknown chirality)
4356
+ use keyword argument `unique` to obtain more details
4357
+ sage: KnotInfo.L10a151_0_0.link().get_knotinfo(unique=False)
4358
+ [(<KnotInfo.L10a151_0_0: 'L10a151{0,0}'>, <SymmetryMutant.unknown: '?'>),
4359
+ (<KnotInfo.L10a151_0_1: 'L10a151{0,1}'>, <SymmetryMutant.unknown: '?'>),
4360
+ (<KnotInfo.L10a151_1_0: 'L10a151{1,0}'>, <SymmetryMutant.unknown: '?'>),
4361
+ (<KnotInfo.L10a151_1_1: 'L10a151{1,1}'>, <SymmetryMutant.unknown: '?'>)]
4362
+
4363
+ sage: L = KnotInfo.L6a2_0
4364
+ sage: L1 = L.link()
4365
+ sage: L2 = L.link(L.items.braid_notation)
4366
+ sage: L1.get_knotinfo() == L2.get_knotinfo() # optional - database_knotinfo, needs sage.libs.homfly
4367
+ True
4368
+ """
4369
+ non_unique_hint = '\nuse keyword argument `unique` to obtain more details'
4370
+ from sage.knots.knotinfo import SymmetryMutant
4371
+
4372
+ def answer(L):
4373
+ r"""
4374
+ Return a single item of the KnotInfo database according to the keyword
4375
+ arguments ``mirror_version``.
4376
+ """
4377
+ if not mirror_version:
4378
+ return L
4379
+
4380
+ def find_mutant(proved=True):
4381
+ r"""
4382
+ Return the according symmetry mutant from the matching list
4383
+ and removes the entry from the list.
4384
+ """
4385
+ for k in match_lists:
4386
+ if proved:
4387
+ prove = proves[k] or any(proves[m] for m in k.matches(L))
4388
+ if not prove:
4389
+ continue
4390
+ if k.is_minimal(L):
4391
+ lk = match_lists[k]
4392
+ if L in lk:
4393
+ lk.remove(L)
4394
+ return k
4395
+
4396
+ sym_mut = None
4397
+ if SymmetryMutant.unknown.matches(L):
4398
+ if unique:
4399
+ raise NotImplementedError('this link cannot be uniquely determined (unknown chirality)%s' % non_unique_hint)
4400
+ sym_mut = SymmetryMutant.unknown
4401
+
4402
+ if not sym_mut:
4403
+ sym_mut = find_mutant()
4404
+
4405
+ if not sym_mut:
4406
+ sym_mut = find_mutant(proved=False)
4407
+
4408
+ if not unique and not sym_mut:
4409
+ return None
4410
+
4411
+ if not sym_mut:
4412
+ # In case of a chiral link this means that the HOMFLY-PT
4413
+ # polynomial does not distinguish mirror images (see the above
4414
+ # example ``L10n36_0``).
4415
+ sym_mut = SymmetryMutant.unknown
4416
+
4417
+ if unique and sym_mut is SymmetryMutant.unknown:
4418
+ raise NotImplementedError('symmetry mutant of this link cannot be uniquely determined%s' % non_unique_hint)
4419
+
4420
+ if L.is_knot():
4421
+ from sage.knots.free_knotinfo_monoid import FreeKnotInfoMonoid
4422
+ FKIM = FreeKnotInfoMonoid()
4423
+ return FKIM((L, sym_mut))
4424
+
4425
+ return L, sym_mut
4426
+
4427
+ def answer_unori(S):
4428
+ r"""
4429
+ Return a series of oriented links having the same unoriented name
4430
+ according to the keyword ``mirror_version``.
4431
+ """
4432
+ if not mirror_version:
4433
+ return S
4434
+
4435
+ sym_mut = [answer(L)[1] for L in S]
4436
+ if all(i is SymmetryMutant.mirror_image for i in sym_mut):
4437
+ # all matching links are mirrored to self
4438
+ return S, SymmetryMutant.mirror_image
4439
+ if all(i is SymmetryMutant.itself for i in sym_mut):
4440
+ # all matching links are self itself
4441
+ return S, SymmetryMutant.itself
4442
+ if any(i is SymmetryMutant.unknown for i in sym_mut):
4443
+ # unknown chirality for a matching link
4444
+ return S, SymmetryMutant.unknown
4445
+ # finally several mirror types match
4446
+ return S, SymmetryMutant.mixed
4447
+
4448
+ def answer_list(l):
4449
+ r"""
4450
+ Return a list of items of the KnotInfo database according to the keyword
4451
+ argument ``unique``.
4452
+ """
4453
+ if not unique:
4454
+ ansl = []
4455
+ for L in l:
4456
+ a = answer(L)
4457
+ if a:
4458
+ ansl.append(a)
4459
+ return sorted(set(ansl))
4460
+
4461
+ if len(set(l)) == 1:
4462
+ return answer(l[0])
4463
+
4464
+ if not l[0].is_knot():
4465
+ S = l[0].series(oriented=True)
4466
+ if set(S) == set(l):
4467
+ return answer_unori(S)
4468
+
4469
+ raise NotImplementedError('this link cannot be uniquely determined%s' % non_unique_hint)
4470
+
4471
+ H = self.homfly_polynomial(normalization='vz')
4472
+ num_fac = sum(exp for f, exp in H.factor())
4473
+ if num_fac > 1 and self.is_knot():
4474
+ # we cannot be sure if this is a prime knot (see the example for the connected
4475
+ # sum of K4_1 and K5_2 in the doctest of :meth:`_knotinfo_matching_list`)
4476
+ # Therefor we calculate it directly in the free KnotInfo monoid
4477
+ from sage.knots.free_knotinfo_monoid import FreeKnotInfoMonoid
4478
+ FKIM = FreeKnotInfoMonoid()
4479
+ return FKIM.from_knot(self, unique=unique)
4480
+
4481
+ match_lists, proves = self._knotinfo_matching_dict()
4482
+
4483
+ # first add only proved matching lists
4484
+ proved = any(proves[k] for k in proves.keys())
4485
+
4486
+ l = []
4487
+ if proved and unique and self.is_knot():
4488
+ for k in match_lists.keys():
4489
+ if proves[k]:
4490
+ l += match_lists[k]
4491
+ else:
4492
+ # for multi-component links there could regularily be more than one
4493
+ # matching entry
4494
+ for k in match_lists.keys():
4495
+ l += match_lists[k]
4496
+
4497
+ if l and not unique:
4498
+ return answer_list(l)
4499
+
4500
+ if proved:
4501
+ return answer_list(l)
4502
+
4503
+ # here we come if we cannot be sure about the found result
4504
+
4505
+ uniq_txt = ('', '')
4506
+ if l:
4507
+ uniq_txt = (' uniquely', non_unique_hint)
4508
+
4509
+ cr = len(self.pd_code())
4510
+ if self.is_knot() and cr > 13:
4511
+ # we cannot not be sure if this link is recorded in the KnotInfo database
4512
+ raise NotImplementedError('this knot having more than 13 crossings cannot be%s determined%s' % uniq_txt)
4513
+
4514
+ if not self.is_knot() and cr > 11:
4515
+ # we cannot not be sure if this link is recorded in the KnotInfo database
4516
+ raise NotImplementedError('this link having more than 11 crossings cannot be%s determined%s' % uniq_txt)
4517
+
4518
+ if num_fac > 1:
4519
+ raise NotImplementedError('this (possibly non prime) link cannot be%s determined%s' % uniq_txt)
4520
+
4521
+ if not l:
4522
+ from sage.features.databases import DatabaseKnotInfo
4523
+ DatabaseKnotInfo().require()
4524
+ return l
4525
+
4526
+ return answer_list(l)
4527
+
4528
+ def is_isotopic(self, other):
4529
+ r"""
4530
+ Check whether ``self`` is isotopic to ``other``.
4531
+
4532
+ INPUT:
4533
+
4534
+ - ``other`` -- another instance of :class:`Link`
4535
+
4536
+ EXAMPLES::
4537
+
4538
+ sage: l1 = Link([[2, 9, 3, 10], [4, 13, 5, 14], [6, 11, 7, 12],
4539
+ ....: [8, 1, 9, 2], [10, 7, 11, 8], [12, 5, 13, 6],
4540
+ ....: [14, 3, 1, 4]])
4541
+ sage: l2 = Link([[1, 8, 2, 9], [9, 2, 10, 3], [3, 14, 4, 1],
4542
+ ....: [13, 4, 14, 5], [5, 12, 6, 13], [11, 6, 12, 7],
4543
+ ....: [7, 10, 8, 11]])
4544
+ sage: l1.is_isotopic(l2) # needs sage.libs.braiding sage.libs.homfly
4545
+ True
4546
+
4547
+ sage: l3 = l2.mirror_image()
4548
+ sage: l1.is_isotopic(l3) # needs sage.libs.braiding sage.libs.homfly
4549
+ False
4550
+
4551
+ sage: # optional - database_knotinfo
4552
+ sage: L = KnotInfo.L7a7_0_0
4553
+ sage: L.series(oriented=True).inject()
4554
+ Defining L7a7
4555
+ sage: L == L7a7(0)
4556
+ True
4557
+ sage: l = L.link()
4558
+ sage: l.is_isotopic(L7a7(1).link()) # needs sage.libs.braiding sage.libs.homf;y
4559
+ Traceback (most recent call last):
4560
+ ...
4561
+ NotImplementedError: comparison not possible!
4562
+ sage: l.is_isotopic(L7a7(2).link()) # needs sage.libs.braiding sage.libs.homf;y
4563
+ True
4564
+ sage: l.is_isotopic(L7a7(3).link()) # needs sage.libs.braiding sage.libs.homf;y
4565
+ False
4566
+
4567
+ Using verbosity::
4568
+
4569
+ sage: set_verbose(1)
4570
+ sage: l1.is_isotopic(l2) # needs sage.libs.braiding sage.libs.homf;y
4571
+ verbose 1 (... link.py, is_isotopic) identified by KnotInfo (KnotInfo.K7_2, SymmetryMutant.mirror_image)
4572
+ True
4573
+ sage: l1.is_isotopic(l3) # needs sage.libs.braiding sage.libs.homf;y
4574
+ verbose 1 (... link.py, is_isotopic) different Homfly-PT polynomials
4575
+ False
4576
+ sage: set_verbose(0)
4577
+
4578
+ TESTS:
4579
+
4580
+ Check that :issue:`37668` is fixed::
4581
+
4582
+ sage: L = KnotInfo.L6a2_0
4583
+ sage: L1 = L.link()
4584
+ sage: L2 = L.link(L.items.braid_notation)
4585
+ sage: set_verbose(1)
4586
+ sage: L1.is_isotopic(L2) # needs sage.libs.braiding sage.libs.homf;y
4587
+ verbose 1 (... link.py, is_isotopic) identified by KnotInfo uniquely (KnotInfo.L6a2_0, SymmetryMutant.itself)
4588
+ True
4589
+ sage: KnotInfo.K0_1.link().is_isotopic(KnotInfo.L2a1_0.link()) # needs sage.libs.braiding sage.libs.homf;y
4590
+ verbose 1 (... link.py, is_isotopic) different number of components
4591
+ False
4592
+
4593
+ sage: # optional - database_knotinfo, needs sage.libs.braiding sage.libs.homf;y
4594
+ sage: K = KnotInfo.K10_67
4595
+ sage: K1 = K.link()
4596
+ sage: K1r = K.link().reverse()
4597
+ sage: K1.is_isotopic(K1r)
4598
+ verbose 1 (... link.py, is_isotopic) unidentified by KnotInfo ([<KnotInfo.K10_67: '10_67'>], SymmetryMutant.itself != [<KnotInfo.K10_67: '10_67'>], SymmetryMutant.reverse)
4599
+ False
4600
+ sage: KnotInfo.K10_25.link().is_isotopic(KnotInfo.K10_56.link())
4601
+ verbose 1 (... link.py, is_isotopic) unidentified by KnotInfo ([<KnotInfo.K10_25: '10_25'>] != [<KnotInfo.K10_56: '10_56'>], SymmetryMutant.itself)
4602
+ False
4603
+ sage: KnotInfo.L8n2_0.link().is_isotopic(KnotInfo.L8n2_1.link())
4604
+ verbose 1 (... link.py, is_isotopic) identified by KnotInfoSeries ([<KnotInfo.L8n2_0: 'L8n2{0}'>, <KnotInfo.L8n2_1: 'L8n2{1}'>], SymmetryMutant.reverse)
4605
+ True
4606
+ sage: set_verbose(0)
4607
+ """
4608
+ from sage.misc.verbose import verbose
4609
+ if not isinstance(other, Link):
4610
+ verbose('other is not a link')
4611
+ return False
4612
+
4613
+ if self == other:
4614
+ # surely isotopic
4615
+ verbose('identified by representation')
4616
+ return True
4617
+
4618
+ if self.number_of_components() != other.number_of_components():
4619
+ # surely non isotopic
4620
+ verbose('different number of components')
4621
+ return False
4622
+
4623
+ if self.homfly_polynomial() != other.homfly_polynomial():
4624
+ # surely non isotopic
4625
+ verbose('different Homfly-PT polynomials')
4626
+ return False
4627
+
4628
+ if self._markov_move_cmp(other.braid()):
4629
+ # surely isotopic
4630
+ verbose('identified via Markov moves')
4631
+ return True
4632
+
4633
+ slists, sproves = self._knotinfo_matching_dict()
4634
+ olists, oproves = other._knotinfo_matching_dict()
4635
+ proved_s = None
4636
+ proved_o = None
4637
+ for k in slists.keys():
4638
+ sl = slists[k]
4639
+ ol = olists[k]
4640
+ sp = sproves[k]
4641
+ op = oproves[k]
4642
+ if sp and op:
4643
+ if sorted(sl) == sorted(ol):
4644
+ if len(sl) == 1:
4645
+ verbose('identified by KnotInfo uniquely (%s, %s)' % (sl[0], k))
4646
+ return True
4647
+ elif not self.is_knot():
4648
+ if len(set([l.series(oriented=True) for l in sl])) == 1:
4649
+ # all matches are orientation mutants of each other
4650
+ verbose('identified by KnotInfoSeries (%s, %s)' % (sl, k))
4651
+ return True
4652
+ else:
4653
+ verbose('KnotInfoSeries non-unique (%s, %s)' % (sl, k))
4654
+ else:
4655
+ verbose('KnotInfo non-unique (%s, %s)' % (sl, k))
4656
+ else:
4657
+ common = [l for l in sl if l in ol]
4658
+ if common:
4659
+ # better don't trust
4660
+ verbose('KnotInfo common: %s' % common)
4661
+ else:
4662
+ verbose('unidentified by KnotInfo (%s != %s, %s)' % (sl, ol, k))
4663
+ return False
4664
+ elif sp:
4665
+ proved_s = (sl, k)
4666
+ elif op:
4667
+ proved_o = (ol, k)
4668
+ if proved_s and proved_o:
4669
+ sl, sk = proved_s
4670
+ ol, ok = proved_o
4671
+ verbose('unidentified by KnotInfo (%s, %s != %s, %s)' % (sl, sk, ol, ok))
4672
+ return False
4673
+
4674
+ for k in slists.keys():
4675
+ # second loop without provings
4676
+ sl = slists[k]
4677
+ ol = olists[k]
4678
+ if sorted(sl) == sorted(ol) and len(sl) == 1:
4679
+ verbose('identified by KnotInfo (%s, %s)' % (sl[0], k))
4680
+ return True
4681
+
4682
+ raise NotImplementedError('comparison not possible!')