Coverage for local/lib/python2.7/site-packages/sage/knots/link.py : 88%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
r""" Links
A knot is defined as embedding of the circle `\mathbb{S}^1` in the 3-dimensional sphere `\mathbb{S}^3`, considered up to ambient isotopy. They represent the physical idea of a knotted rope, but with the particularity that the rope is closed. That is, the ends of the rope are joined.
A link is an embedding of one or more copies of `\mathbb{S}^1` in `\mathbb{S}^3`, considered up to ambient isotopy. That is, a link represents the idea of one or more tied ropes. Every knot is a link, but not every link is a knot.
Generically, the projection of a link on `\RR^2` is a curve with crossings. The crossings are represented to show which strand goes over the other. This curve is called a planar diagram of the link. If we remove the crossings, the resulting connected components are segments. These segments are called the edges of the diagram.
REFERENCES:
- :wikipedia:`Knot_(mathematics)` - [Col2013]_ - [KnotAtlas]_
.. SEEALSO::
There are also tables of link and knot invariants at http://www.indiana.edu/~knotinfo/ and http://www.indiana.edu/~linkinfo/.
AUTHORS:
- Miguel Angel Marco Buzunariz - Amit Jamadagni """
#***************************************************************************** # Copyright (C) 2014 Miguel Angel Marco Buzunariz # Amit Jamadagni # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** from __future__ import division from six.moves import range
from sage.matrix.constructor import matrix from sage.rings.integer_ring import ZZ from sage.graphs.digraph import DiGraph from sage.graphs.graph import Graph from sage.rings.polynomial.laurent_polynomial_ring import LaurentPolynomialRing from sage.symbolic.ring import SR from sage.rings.integer import Integer from sage.numerical.mip import MixedIntegerLinearProgram from sage.functions.generalized import sign from sage.homology.chain_complex import ChainComplex from sage.misc.flatten import flatten from sage.misc.lazy_attribute import lazy_attribute from sage.misc.cachefunc import cached_method from copy import deepcopy, copy from itertools import combinations
class Link(object): r""" A link.
A link is an embedding of one or more copies of `\mathbb{S}^1` in `\mathbb{S}^3`, considered up to ambient isotopy. That is, a link represents the idea of one or more tied ropes. Every knot is a link, but not every link is a knot.
A link can be created by using one of the conventions mentioned below:
Braid:
- The closure of a braid is a link::
sage: B = BraidGroup(8) sage: L = Link(B([-1, -1, -1, -2, 1, -2, 3, -2, 3])) sage: L Link with 1 component represented by 9 crossings sage: L = Link(B([1, 2, 1, -2, -1])) sage: L Link with 2 components represented by 5 crossings
.. NOTE::
The strands of the braid that have no crossings at all are removed.
- Oriented Gauss Code:
Label the crossings from `1` to `n` (where `n` is the number of crossings) and start moving along the link. Trace every component of the link, by starting at a particular point on one component of the link and writing down each of the crossings that you encounter until returning to the starting point. The crossings are written with sign depending on whether we cross them as over or undercrossing. Each component is then represented as a list whose elements are the crossing numbers. A second list of `+1` and `-1`'s keeps track of the orientation of each crossing::
sage: L = Link([[[-1, 2, 3, -4, 5, -6, 7, 8, -2, -5, 6, 1, -8, -3, 4, -7]], ....: [-1, -1, -1, -1, 1, 1, -1, 1]]) sage: L Link with 1 component represented by 8 crossings
For links there may be more than one component and the input is as follows::
sage: L = Link([[[-1, 2], [-3, 4], [1, 3, -4, -2]], [-1, -1, 1, 1]]) sage: L Link with 3 components represented by 4 crossings
- Planar Diagram (PD) Code:
The diagram of the link is formed by segments that are adjacent to the crossings. Label each one of this segments with a positive number, and for each crossing, write down the four incident segments. The order of these segments is clockwise, starting with the incoming undercrossing.
There is no particular distinction between knots and links for this input.
EXAMPLES:
One of the representations of the trefoil knot::
sage: L = Link([[1, 5, 2, 4], [5, 3, 6, 2], [3, 1, 4, 6]]) sage: L Link with 1 component represented by 3 crossings
.. PLOT:: :width: 300 px
L = Link([[1, 5, 2, 4], [5, 3, 6, 2], [3, 1, 4, 6]]) sphinx_plot(L.plot())
One of the representations of the Hopf link::
sage: L = Link([[1, 4, 2, 3], [4, 1, 3, 2]]) sage: L Link with 2 components represented by 2 crossings
.. PLOT:: :width: 300 px
L = Link([[1, 4, 2, 3], [4, 1, 3, 2]]) sphinx_plot(L.plot())
We can construct links from the braid group::
sage: B = BraidGroup(4) sage: L = Link(B([-1, -1, -1, -2, 1, -2, 3, -2])) sage: L Link with 2 components represented by 8 crossings
.. PLOT:: :width: 300 px
B = BraidGroup(4) L = Link(B([-1, -1, -1, -2, 1, -2, 3, -2])) sphinx_plot(L.plot())
::
sage: L = Link(B([1, 2, 1, 3])) sage: L Link with 2 components represented by 4 crossings
.. PLOT:: :width: 300 px
B = BraidGroup(4) L = Link(B([1, 2, 1, 3])) sphinx_plot(L.plot())
We construct the "monster" unknot using a planar code, and then construct the oriented Gauss code and braid representation::
sage: L = Link([[3,1,2,4], [8,9,1,7], [5,6,7,3], [4,18,6,5], ....: [17,19,8,18], [9,10,11,14], [10,12,13,11], ....: [12,19,15,13], [20,16,14,15], [16,20,17,2]]) sage: L.oriented_gauss_code() [[[1, -4, 3, -1, 10, -9, 6, -7, 8, 5, 4, -3, 2, -6, 7, -8, 9, -10, -5, -2]], [1, -1, 1, 1, 1, -1, -1, -1, -1, -1]] sage: L.braid() s0*s1^-1*s2^-1*s3^-1*s2*s1^-1*s0^-1*s1*s2^2*s1^-1*s3*s2*s1^-3
.. PLOT:: :width: 300 px
L = Link([[3,1,2,4],[8,9,1,7],[5,6,7,3],[4,18,6,5], [17,19,8,18],[9,10,11,14],[10,12,13,11], [12,19,15,13],[20,16,14,15],[16,20,17,2]]) sphinx_plot(L.plot())
We construct the Ochiai unknot by using an oriented Gauss code::
sage: L = Link([[[1,-2,-3,-8,-12,13,-14,15,-7,-1,2,-4,10,11,-13,12, ....: -11,-16,4,3,-5,6,-9,7,-15,14,16,-10,8,9,-6,5]], ....: [-1,-1,1,1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1]]) sage: L.pd_code() [[10, 2, 11, 1], [2, 12, 3, 11], [3, 20, 4, 21], [12, 19, 13, 20], [21, 32, 22, 1], [31, 22, 32, 23], [9, 25, 10, 24], [4, 29, 5, 30], [23, 30, 24, 31], [28, 14, 29, 13], [17, 14, 18, 15], [5, 17, 6, 16], [15, 7, 16, 6], [7, 27, 8, 26], [25, 9, 26, 8], [18, 28, 19, 27]]
.. PLOT:: :width: 300 px
L = Link([[[1,-2,-3,-8,-12,13,-14,15,-7,-1,2,-4,10,11,-13,12, -11,-16,4,3,-5,6,-9,7,-15,14,16,-10,8,9,-6,5]], [-1,-1,1,1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1]]) sphinx_plot(L.plot())
We construct the knot `7_1` and compute some invariants::
sage: B = BraidGroup(2) sage: L = Link(B([1]*7))
.. PLOT:: :width: 300 px
B = BraidGroup(2) L = Link(B([1]*7)) sphinx_plot(L.plot())
::
sage: L.alexander_polynomial() t^-3 - t^-2 + t^-1 - 1 + t - t^2 + t^3 sage: L.jones_polynomial() -t^10 + t^9 - t^8 + t^7 - t^6 + t^5 + t^3 sage: L.determinant() 7 sage: L.signature() -6
The links here have removed components in which no strand is used::
sage: B = BraidGroup(8) sage: b = B([1]) sage: L = Link(b) sage: b.components_in_closure() 7 sage: L.number_of_components() 1 sage: L.braid().components_in_closure() 1 sage: L.braid().parent() Braid group on 2 strands
.. WARNING::
Equality of knots is done by comparing the corresponding braids, which may give false negatives.
.. NOTE::
The behavior of removing unused strands from an element of a braid group may change without notice in the future. Do not rely on this feature.
.. TODO::
Implement methods to creating new links from previously created links. """ def __init__(self, data): """ Initialize ``self``.
TESTS::
sage: B = BraidGroup(8) sage: L = Link(B([-1, -1, -1, -2,1, -2, 3, -2])) sage: TestSuite(L).run() sage: L = Link(B([1, 2, 1])) sage: TestSuite(L).run() sage: L = Link([[1, 1, 2, 2]]) sage: TestSuite(L).run()
sage: L = Link(B.one()) sage: L = Link([]) sage: L = Link([[], []])
sage: Link([[[-1, 2, -1, 2]], [1, 1, 1, 1]]) Traceback (most recent call last): ... ValueError: invalid input: data is not a valid oriented Gauss code
sage: Link([[[-1, 2, 3, 4]]]) Traceback (most recent call last): ... ValueError: invalid PD code: crossings must be represented by four segments
sage: L = Link([[1, 5, 2, 4], [5, 3, 6, 2], [3, 1, 4, 3]]) Traceback (most recent call last): ... ValueError: invalid PD code: each segment must appear twice
sage: L = Link(5) Traceback (most recent call last): ... ValueError: invalid input: data must be either a list or a braid """ else:
else:
else: # Remove all unused strands else: cur = support[i] i += 1 else:
else:
def arcs(self, presentation='pd'): r""" Return the arcs of ``self``.
Arcs are the connected components of the planar diagram.
INPUT:
- ``presentation`` -- one of the following:
* ``'pd'`` - the arcs are returned as lists of parts in the PD code * ``'gauss_code'`` - the arcs are returned as pieces of the Gauss code that start with a negative number, and end with the following negative one; of there exist a closed arc, it is returned as a list of positive numbers only
OUTPUT:
A list of lists representing the arcs based upon ``presentation``.
EXAMPLES::
sage: K = Knot([[[1,-2,3,-1,2,-3]],[1,1,1]]) sage: K.arcs() [[1, 2], [3, 4], [5, 6]] sage: K.arcs(presentation='gauss_code') [[-3, 1, -2], [-2, 3, -1], [-1, 2, -3]]
::
sage: L = Link([[1, 2, 3, 4], [3, 2, 1, 4]]) sage: L.arcs() [[2, 4], [1], [3]] sage: L.arcs(presentation='gauss_code') [[-2, -1], [-1, -2], [2, 1]] sage: L.gauss_code() [[-1, -2], [2, 1]] """ else: else: else:
def fundamental_group(self, presentation='wirtinger'): r""" Return the fundamental group of the complement of ``self``.
INPUT:
- ``presentation`` -- string; one of the following:
* ``'wirtinger'`` - (default) the Wirtinger presentation (see :wikipedia:`Link_group`) * ``'braid'`` - the presentation is given by the braid action on the free group (see chapter 2 of [Bir1975]_)
OUTPUT:
- a finitely presented group
EXAMPLES::
sage: L = Link([[1, 2, 3, 4], [3, 2, 1, 4]]) sage: L.fundamental_group() Finitely presented group < x0, x1, x2 | x1*x0^-1*x2^-1*x0, x2*x0*x1^-1*x0^-1 > sage: L.fundamental_group('braid') Finitely presented group < x0, x1 | 1, 1 >
We can see, for instance, that the two presentations of the group of the figure eight knot correspond to isomorphic groups::
sage: K8 = Knot([[[1, -2, 4, -3, 2, -1, 3, -4]], [1, 1, -1, -1]]) sage: GA = K8.fundamental_group() sage: GA Finitely presented group < x0, x1, x2, x3 | x2*x0*x3^-1*x0^-1, x0*x2*x1^-1*x2^-1, x1*x3^-1*x2^-1*x3, x3*x1^-1*x0^-1*x1 > sage: GB = K8.fundamental_group(presentation='braid') sage: GB Finitely presented group < x0, x1, x2 | x1*x2^-1*x1^-1*x0*x1*x2*x1*x2^-1*x1^-1*x0^-1*x1*x2*x1^-1*x0^-1, 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, x1*x2^-1*x1^-1*x0*x1*x2*x1^-1*x2^-1 > sage: GA.simplified() Finitely presented group < x0, x1 | x1^-1*x0*x1*x0^-1*x1*x0*x1^-1*x0^-1*x1*x0^-1 > sage: GB.simplified() Finitely presented group < x0, x2 | x2^-1*x0*x2^-1*x0^-1*x2*x0*x2^-1*x0*x2*x0^-1 > """
def __repr__(self): """ Return a string representation.
OUTPUT: string representation
EXAMPLES::
sage: B = BraidGroup(8) sage: L = Link(B([1, 2, 1, 2])) sage: L Link with 1 component represented by 4 crossings sage: L = Link([[[-1, 2], [-3, 4], [1, 3, -4, -2]], [-1, -1, 1, 1]]) sage: L Link with 3 components represented by 4 crossings """ else:
def __eq__(self, other): """ Check equality.
TESTS::
sage: B = BraidGroup(8) sage: L1 = Link(B([-1, -1, -1, -2, 1, -2, 3, -2, 5, 4])) sage: L2 = Link(B([-1, -1, -1, -2, 1, -2, 3, -2, 5, 4])) sage: L1 == L2 True sage: L3 = Link(B([-1, -1, -1, -2, 1, -2, 3, -2])) sage: L1 == L3 False """ return False if self.oriented_gauss_code() == other.oriented_gauss_code(): return True
def __hash__(self): """ Return the hash of ``self``.
EXAMPLES::
sage: B = BraidGroup(8) sage: L1 = Link(B([-1, -1, -1, -2, 1, -2, 3, -2, 5, 4])) sage: H = hash(L1) """
def __ne__(self, other): """ Check inequality.
TESTS::
sage: B = BraidGroup(8) sage: L1 = Link(B([-1, -1, -1, -2, 1, -2, 3, -2, 5, 4])) sage: L2 = Link(B([-1, -1, -1, -2, 1, -2, 3, -2, 5, 4])) sage: L1 != L2 False sage: L3 = Link(B([-1, -1, -1, -2, 1, -2, 3, -2])) sage: L1 != L3 True """
def braid(self): """ Return a braid representation of ``self``.
OUTPUT: an element in the braid group
EXAMPLES::
sage: L = Link([[2, 3, 1, 4], [4, 1, 3, 2]]) sage: L.braid() s^2 sage: L = Link([[[-1, 2, -3, 1, -2, 3]], [-1, -1, -1]]) sage: L.braid() s^-3 sage: L = Link([[1,8,2,7], [8,4,9,5], [3,9,4,10], [10,1,7,6], [5,3,6,2]]) sage: L.braid() (s0*s1^-1)^2*s1^-1
TESTS::
sage: L = Link([]) sage: L.braid() 1 sage: L = Link([[], []]) sage: L.braid() 1
Check that :trac:`25050` is solved::
sage: A = Link([[[1, 2, -2, -1, -3, -4, 4, 3]], [1, 1, 1, 1]]) sage: A.braid() s0*s1*s2*s3 """
L1 = Link(comp[0]) L2 = Link(flatten(comp[1:], max_level=1)) b1 = L1.braid() b2 = L2.braid() n1 = b1.parent().strands() n2 = b2.parent().strands() t1 = list(b1.Tietze()) t2 = [sign(x)*(abs(x) + n1) for x in b2.Tietze()] B = BraidGroup(n1 + n2) self._braid = B(t1 + t2) return self._braid
# look for possible Vogel moves, perform them and call recursively to the modified link
else:
# We are in the case where no Vogel moves are necessary. else:
# Get a simple path from a source to a sink in the digraph
else: else: else:
def _directions_of_edges(self): r""" Return the directions of the edges given by the PD code of ``self``.
OUTPUT:
A tuple of two dictionaries. The first one assigns each edge of the PD code to the crossing where it starts. The second dictionary assigns it to where it ends.
EXAMPLES::
sage: L = Link([[1, 3, 2, 4], [2, 3, 1, 4]]) sage: L._directions_of_edges() ({1: [2, 3, 1, 4], 2: [1, 3, 2, 4], 3: [1, 3, 2, 4], 4: [2, 3, 1, 4]}, {1: [1, 3, 2, 4], 2: [2, 3, 1, 4], 3: [2, 3, 1, 4], 4: [1, 3, 2, 4]})
::
sage: L = Link([[1,5,2,4], [5,3,6,2], [3,1,4,6]]) sage: L._directions_of_edges() ({1: [3, 1, 4, 6], 2: [1, 5, 2, 4], 3: [5, 3, 6, 2], 4: [3, 1, 4, 6], 5: [1, 5, 2, 4], 6: [5, 3, 6, 2]}, {1: [1, 5, 2, 4], 2: [5, 3, 6, 2], 3: [3, 1, 4, 6], 4: [1, 5, 2, 4], 5: [5, 3, 6, 2], 6: [3, 1, 4, 6]})
::
sage: L = Link([[1,2,3,3], [2,4,5,5], [4,1,7,7]]) sage: L._directions_of_edges() ({1: [4, 1, 7, 7], 2: [1, 2, 3, 3], 3: [1, 2, 3, 3], 4: [2, 4, 5, 5], 5: [2, 4, 5, 5], 7: [4, 1, 7, 7]}, {1: [1, 2, 3, 3], 2: [2, 4, 5, 5], 3: [1, 2, 3, 3], 4: [4, 1, 7, 7], 5: [2, 4, 5, 5], 7: [4, 1, 7, 7]}) """ else: else:
@cached_method def _enhanced_states(self): r""" Return the enhanced states of the diagram.
Each enhanced state is represented as a tuple containing:
- A tuple with the type of smoothing made at each crossing (0 represents a A-type smoothing, and 1 represents B-type).
- A tuple with the circles marked as negative. Each circle is represented by the smoothings it goes through. Each smoothing is represented by the indices of the two strands, and the index of the chord, counted clockwise.
- A tuple with the circles marked as negative.
- The i-index (degree) corresponding to the state.
- the j-index (height) corresponding to the state.
EXAMPLES::
sage: K = Link([[[1,-2,3,-1,2,-3]],[-1,-1,-1]]) sage: K.pd_code() [[4, 2, 5, 1], [2, 6, 3, 5], [6, 4, 1, 3]] sage: K._enhanced_states() (((0, 0, 0), (((1, 4, 7), (4, 1, 9)), ((2, 5, 7), (5, 2, 8)), ((3, 6, 9), (6, 3, 8))), (), -3, -9), ((0, 0, 0), (((2, 5, 7), (5, 2, 8)), ((3, 6, 9), (6, 3, 8))), (((1, 4, 7), (4, 1, 9)),), -3, -7), ((0, 0, 0), (((1, 4, 7), (4, 1, 9)), ((3, 6, 9), (6, 3, 8))), (((2, 5, 7), (5, 2, 8)),), -3, -7), ((0, 0, 0), (((1, 4, 7), (4, 1, 9)), ((2, 5, 7), (5, 2, 8))), (((3, 6, 9), (6, 3, 8)),), -3, -7), ((0, 0, 0), (((3, 6, 9), (6, 3, 8)),), (((1, 4, 7), (4, 1, 9)), ((2, 5, 7), (5, 2, 8))), -3, -5), ((0, 0, 0), (((2, 5, 7), (5, 2, 8)),), (((1, 4, 7), (4, 1, 9)), ((3, 6, 9), (6, 3, 8))), -3, -5), ((0, 0, 0), (((1, 4, 7), (4, 1, 9)),), (((2, 5, 7), (5, 2, 8)), ((3, 6, 9), (6, 3, 8))), -3, -5), ((0, 0, 0), (), (((1, 4, 7), (4, 1, 9)), ((2, 5, 7), (5, 2, 8)), ((3, 6, 9), (6, 3, 8))), -3, -3), ((1, 0, 0), (((3, 6, 9), (6, 3, 8)), ((4, 1, 9), (4, 2, 7), (5, 1, 7), (5, 2, 8))), (), -2, -7), ((1, 0, 0), (((4, 1, 9), (4, 2, 7), (5, 1, 7), (5, 2, 8)),), (((3, 6, 9), (6, 3, 8)),), -2, -5), ((1, 0, 0), (((3, 6, 9), (6, 3, 8)),), (((4, 1, 9), (4, 2, 7), (5, 1, 7), (5, 2, 8)),), -2, -5), ((1, 0, 0), (), (((3, 6, 9), (6, 3, 8)), ((4, 1, 9), (4, 2, 7), (5, 1, 7), (5, 2, 8))), -2, -3), ((0, 1, 0), (((1, 4, 7), (4, 1, 9)), ((2, 5, 7), (2, 6, 8), (3, 5, 8), (3, 6, 9))), (), -2, -7), ((0, 1, 0), (((2, 5, 7), (2, 6, 8), (3, 5, 8), (3, 6, 9)),), (((1, 4, 7), (4, 1, 9)),), -2, -5), ((0, 1, 0), (((1, 4, 7), (4, 1, 9)),), (((2, 5, 7), (2, 6, 8), (3, 5, 8), (3, 6, 9)),), -2, -5), ((0, 1, 0), (), (((1, 4, 7), (4, 1, 9)), ((2, 5, 7), (2, 6, 8), (3, 5, 8), (3, 6, 9))), -2, -3), ((1, 1, 0), (((2, 6, 8), (3, 5, 8), (3, 6, 9), (4, 1, 9), (4, 2, 7), (5, 1, 7)),), (), -1, -5), ((1, 1, 0), (), (((2, 6, 8), (3, 5, 8), (3, 6, 9), (4, 1, 9), (4, 2, 7), (5, 1, 7)),), -1, -3), ((0, 0, 1), (((1, 3, 9), (1, 4, 7), (6, 3, 8), (6, 4, 9)), ((2, 5, 7), (5, 2, 8))), (), -2, -7), ((0, 0, 1), (((2, 5, 7), (5, 2, 8)),), (((1, 3, 9), (1, 4, 7), (6, 3, 8), (6, 4, 9)),), -2, -5), ((0, 0, 1), (((1, 3, 9), (1, 4, 7), (6, 3, 8), (6, 4, 9)),), (((2, 5, 7), (5, 2, 8)),), -2, -5), ((0, 0, 1), (), (((1, 3, 9), (1, 4, 7), (6, 3, 8), (6, 4, 9)), ((2, 5, 7), (5, 2, 8))), -2, -3), ((1, 0, 1), (((1, 3, 9), (4, 2, 7), (5, 1, 7), (5, 2, 8), (6, 3, 8), (6, 4, 9)),), (), -1, -5), ((1, 0, 1), (), (((1, 3, 9), (4, 2, 7), (5, 1, 7), (5, 2, 8), (6, 3, 8), (6, 4, 9)),), -1, -3), ((0, 1, 1), (((1, 3, 9), (1, 4, 7), (2, 5, 7), (2, 6, 8), (3, 5, 8), (6, 4, 9)),), (), -1, -5), ((0, 1, 1), (), (((1, 3, 9), (1, 4, 7), (2, 5, 7), (2, 6, 8), (3, 5, 8), (6, 4, 9)),), -1, -3), ((1, 1, 1), (((1, 3, 9), (3, 5, 8), (5, 1, 7)), ((2, 6, 8), (4, 2, 7), (6, 4, 9))), (), 0, -5), ((1, 1, 1), (((2, 6, 8), (4, 2, 7), (6, 4, 9)),), (((1, 3, 9), (3, 5, 8), (5, 1, 7)),), 0, -3), ((1, 1, 1), (((1, 3, 9), (3, 5, 8), (5, 1, 7)),), (((2, 6, 8), (4, 2, 7), (6, 4, 9)),), 0, -3), ((1, 1, 1), (), (((1, 3, 9), (3, 5, 8), (5, 1, 7)), ((2, 6, 8), (4, 2, 7), (6, 4, 9))), 0, -1)) """ else: # positive crossings, from undercrossing to the right for b in G.connected_components())
@cached_method def _khovanov_homology_cached(self, height, ring=ZZ): r""" Return the Khovanov homology of the link.
INPUT:
- ``height`` -- the height of the homology to compute - ``ring`` -- (default: ``ZZ``) the coefficient ring
OUTPUT:
The Khovanov homology of the Link in the given height. It is given as a tuple of key-value pairs, whose keys are the degrees.
.. NOTE::
This method is intended only as the cache for :meth:`khovanov_homology`.
EXAMPLES::
sage: K = Link([[[1, -2, 3, -1, 2, -3]],[-1, -1, -1]]) sage: K._khovanov_homology_cached(-5) ((-3, 0), (-2, Z), (-1, 0), (0, 0))
The figure eight knot::
sage: L = Link([[1, 6, 2, 7], [5, 2, 6, 3], [3, 1, 4, 8], [7, 5, 8, 4]]) sage: L._khovanov_homology_cached(-1) ((-2, 0), (-1, Z), (0, Z), (1, 0), (2, 0)) """ for (_0, _1, _2, _3, _4) in self._enhanced_states()] else: #Here we have the matrix constructed, now we have to put it in the dictionary of complexes else:
def khovanov_homology(self, ring=ZZ, height=None, degree=None): r""" Return the Khovanov homology of the link.
INPUT:
- ``ring`` -- (default: ``ZZ``) the coefficient ring
- ``height`` -- the height of the homology to compute, if not specified, all the heights are computed
- ``degree`` -- the degree of the homology to compute, if not specified, all the degrees are computed
OUTPUT:
The Khovanov homology of the Link. It is given as a dictionary whose keys are the different heights. For each height, the homology is given as another dictionary whose keys are the degrees.
EXAMPLES::
sage: K = Link([[[1, -2, 3, -1, 2, -3]],[-1, -1, -1]]) sage: K.khovanov_homology() {-9: {-3: Z}, -7: {-3: 0, -2: C2}, -5: {-3: 0, -2: Z, -1: 0, 0: 0}, -3: {-3: 0, -2: 0, -1: 0, 0: Z}, -1: {0: Z}}
The figure eight knot::
sage: L = Link([[1, 6, 2, 7], [5, 2, 6, 3], [3, 1, 4, 8], [7, 5, 8, 4]]) sage: L.khovanov_homology(height=-1) {-1: {-2: 0, -1: Z, 0: Z, 1: 0, 2: 0}}
The Hopf link::
sage: B = BraidGroup(2) sage: b = B([1, 1]) sage: K = Link(b) sage: K.khovanov_homology(degree = 2) {2: {2: 0}, 4: {2: Z}, 6: {2: Z}} """ else: else:
def oriented_gauss_code(self): """ Return the oriented Gauss code of ``self``.
The oriented Gauss code has two parts:
a. the Gauss code
b. the orientation of each crossing
The following orientation was taken into consideration for construction of knots:
From the outgoing of the overcrossing if we move in the clockwise direction to reach the outgoing of the undercrossing then we label that crossing as `-1`.
From the outgoing of the overcrossing if we move in the anticlockwise direction to reach the outgoing of the undercrossing then we label that crossing as `+1`.
One more consideration we take in while constructing the orientation is the order of the orientation is same as the ordering of the crossings in the Gauss code.
.. NOTE::
Convention: under is denoted by `-1`, and over by `+1` in the crossing info.
EXAMPLES::
sage: L = Link([[1, 11, 2, 10], [6, 2, 7, 3], [3, 12, 4, 9], [9, 5, 10, 6], [8, 1, 5, 4], [11, 8, 12, 7]]) sage: L.oriented_gauss_code() [[[-1, 2, -3, 5], [4, -2, 6, -5], [-4, 1, -6, 3]], [-1, 1, 1, 1, -1, -1]] sage: L = Link([[1, 4, 2, 3], [6, 1, 3, 2], [7, 4, 8, 5], [5, 8, 6, 7]]) sage: L.oriented_gauss_code() [[[-1, 2], [-3, 4], [1, 3, -4, -2]], [-1, -1, 1, 1]] sage: B = BraidGroup(8) sage: b = B([1, 1, 1, 1, 1]) sage: L = Link(b) sage: L.oriented_gauss_code() [[[1, -2, 3, -4, 5, -1, 2, -3, 4, -5]], [1, 1, 1, 1, 1]]
TESTS::
sage: L = Link([]) sage: L.oriented_gauss_code() [[], []] sage: L = Link(BraidGroup(2).one()) sage: L.oriented_gauss_code() [[], []] """
def pd_code(self): """ Return the planar diagram code of ``self``.
The planar diagram is returned in the following format.
We construct the crossing by starting with the entering component of the undercrossing, move in the clockwise direction and then generate the list. If the crossing is given by `[a, b, c, d]`, then we interpret this information as:
1. `a` is the entering component of the undercrossing; 2. `b, d` are the components of the overcrossing; 3. `c` is the leaving component of the undercrossing.
EXAMPLES::
sage: L = Link([[[1, -2, 3, -4, 2, -1, 4, -3]], [1, 1, -1, -1]]) sage: L.pd_code() [[6, 1, 7, 2], [2, 5, 3, 6], [8, 4, 1, 3], [4, 8, 5, 7]] sage: B = BraidGroup(2) sage: b = B([1, 1, 1, 1, 1]) sage: L = Link(b) sage: L.pd_code() [[2, 1, 3, 4], [4, 3, 5, 6], [6, 5, 7, 8], [8, 7, 9, 10], [10, 9, 1, 2]] sage: L = Link([[[2, -1], [1, -2]], [1, 1]]) sage: L.pd_code() [[2, 3, 1, 4], [4, 1, 3, 2]] sage: L = Link([[1, 2, 3, 3], [2, 4, 5, 5], [4, 1, 7, 7]]) sage: L.pd_code() [[1, 2, 3, 3], [2, 4, 5, 5], [4, 1, 7, 7]]
TESTS::
sage: L = Link([[], []]) sage: L.pd_code() [] sage: L = Link(BraidGroup(2).one()) sage: L.pd_code() [] """
# here we collect the final component in each Gauss code # here we correct the last_component d_dic[-(i + 1)][1], d_dic[i + 1][0]] d_dic[-(i + 1)][1], d_dic[i + 1][1]] d_dic[-(i + 1)][1], d_dic[i + 1][0]] d_dic[-(i + 1)][1], d_dic[i + 1][1]] else:
[strings[i], strings[i - 1], strings_max + 1, strings_max + 2]) else: [strings[abs(i) - 1], strings_max + 1, strings_max + 2, strings[abs(i)]])
raise AssertionError("invalid state")
def gauss_code(self): """ Return the Gauss code of ``self``.
The Gauss code is generated by the following procedure:
a. Number the crossings from `1` to `n`. b. Select a point on the knot and start moving along the component. c. At each crossing, take the number of the crossing, along with sign, which is `-` if it is an undercrossing and `+` if it is a overcrossing.
EXAMPLES::
sage: L = Link([[1, 4, 2, 3], [4, 1, 3, 2]]) sage: L.gauss_code() [[-1, 2], [1, -2]] sage: B = BraidGroup(8) sage: L = Link(B([1, -2, 1, -2, -2])) sage: L.gauss_code() [[-1, 3, -4, 5], [1, -2, 4, -5, 2, -3]] sage: L = Link([[[-1, 2], [-3, 4], [1, 3, -4, -2]], [-1, -1, 1, 1]]) sage: L.gauss_code() [[-1, 2], [-3, 4], [1, 3, -4, -2]] """
def dowker_notation(self): """ Return the Dowker notation of ``self``.
Similar to the PD code we number the components, so every crossing is represented by four numbers. We focus on the incoming entities of the under and the overcrossing. It is the pair of incoming undercrossing and the incoming overcrossing. This information at every crossing gives the Dowker notation.
OUTPUT:
A list containing the pair of incoming under cross and the incoming over cross.
EXAMPLES::
sage: L = Link([[[-1, 2, -3, 4, 5, 1, -2, 6, 7, 3, -4, -7, -6,-5]], [-1, -1, -1, -1, 1, -1, 1]]) sage: L.dowker_notation() [(1, 6), (7, 2), (3, 10), (11, 4), (14, 5), (13, 8), (12, 9)] sage: B = BraidGroup(4) sage: L = Link(B([1, 2, 1, 2])) sage: L.dowker_notation() [(2, 1), (3, 5), (6, 4), (7, 9)] sage: L = Link([[1, 4, 2, 3], [4, 1, 3, 2]]) sage: L.dowker_notation() [(1, 3), (4, 2)] """ for j, i in enumerate(pd)]
def _braid_word_components(self): """ Return the disjoint braid components, if any, else return the braid of ``self``.
For example consider the braid ``[-1, 3, 1, 3]`` this can be viewed as a braid with components as ``[-1, 1]`` and ``[3, 3]``. There is no common crossing to these two (in sense there is a crossing between strand `1` and `2`, crossing between `3` and `4` but no crossing between strand `2` and `3`, so these can be viewed as independent components in the braid).
OUTPUT: list containing the components
EXAMPLES::
sage: B = BraidGroup(4) sage: L = Link(B([-1, 3, 1, 3])) sage: L._braid_word_components() ([-1, 1], [3, 3]) sage: B = BraidGroup(8) sage: L = Link(B([-1, 3, 1, 5, 1, 7, 1, 6])) sage: L._braid_word_components() ([-1, 1, 1, 1], [3], [5, 7, 6]) sage: L = Link(B([-2, 4, 1, 6, 1, 4])) sage: L._braid_word_components() ([-2, 1, 1], [4, 4], [6]) """
def _braid_word_components_vector(self): """ The list from the :meth:`_braid_word_components` is flattened to give out the vector form.
OUTPUT: list containing braid word components
EXAMPLES::
sage: B = BraidGroup(4) sage: L = Link(B([-1, 3, 1, 3])) sage: L._braid_word_components_vector() [-1, 1, 3, 3] sage: B = BraidGroup(8) sage: L = Link(B([-1, 3, 1, 5, 1, 7, 1, 6])) sage: L._braid_word_components_vector() [-1, 1, 1, 1, 3, 5, 7, 6] sage: L = Link(B([-2, 4, 1, 6, 1, 4])) sage: L._braid_word_components_vector() [-2, 1, 1, 4, 4, 6] """
def _homology_generators(self): """ The set of generators for the first homology group of the connected Seifert surface of the given link.
This method uses the :meth:`_braid_word_components_vector` to generate the homology generators. The position of the repeated element w.r.t. the braid word component vector list is compiled into a list.
This is based on Lemma 3.1 in [Col2013]_.
OUTPUT:
A list of integers `i \in \{1, 2, \ldots, n-1\}` corresponding to the simple generators `s_i` that gives a homology generator or `0` if the position does not represent a generator.
EXAMPLES::
sage: B = BraidGroup(4) sage: L = Link(B([-1, 3, 1, 3])) sage: L._homology_generators() [1, 0, 3] sage: B = BraidGroup(8) sage: L = Link(B([-1, 3, 1, 5, 1, 7, 1, 6])) sage: L._homology_generators() [1, 2, 3, 0, 0, 0, 0] sage: L = Link(B([-2, 4, 1, 6, 1, 4])) sage: L._homology_generators() [0, 2, 0, 4, 0] """ else:
@cached_method def seifert_matrix(self): """ Return the Seifert matrix associated with ``self``.
ALGORITHM:
This is the algorithm presented in Section 3.3 of [Col2013]_.
OUTPUT:
The intersection matrix of a (not necessarily minimal) Seifert surface.
EXAMPLES::
sage: B = BraidGroup(4) sage: L = Link(B([-1, 3, 1, 3])) sage: L.seifert_matrix() [ 0 0] [ 0 -1] sage: B = BraidGroup(8) sage: L = Link(B([-1, 3, 1, 5, 1, 7, 1, 6])) sage: L.seifert_matrix() [ 0 0 0] [ 1 -1 0] [ 0 1 -1] sage: L = Link(B([-2, 4, 1, 6, 1, 4])) sage: L.seifert_matrix() [-1 0] [ 0 -1] """ else: else: # for debugging A[i, j] = 2 A[j, i] = 2
@cached_method def number_of_components(self): """ Return the number of connected components of ``self``.
OUTPUT: number of connected components
EXAMPLES::
sage: B = BraidGroup(4) sage: L = Link(B([-1, 3, 1, 3])) sage: L.number_of_components() 4 sage: B = BraidGroup(8) sage: L = Link(B([-2, 4, 1, 6, 1, 4])) sage: L.number_of_components() 5 sage: L = Link(B([1, 2, 1, 2])) sage: L.number_of_components() 1 sage: L = Link(B.one()) sage: L.number_of_components() 1 """
def is_knot(self): """ Return ``True`` if ``self`` is a knot.
Every knot is a link but the converse is not true.
EXAMPLES::
sage: B = BraidGroup(4) sage: L = Link(B([1, 3, 1, -3])) sage: L.is_knot() False sage: B = BraidGroup(8) sage: L = Link(B([1, 2, 3, 4, 5, 6])) sage: L.is_knot() True """
def genus(self): """ Return the genus of ``self``.
EXAMPLES::
sage: B = BraidGroup(4) sage: L = Link(B([-1, 3, 1, 3])) sage: L.genus() 0 sage: L = Link(B([1,3])) sage: L.genus() 0 sage: B = BraidGroup(8) sage: L = Link(B([-2, 4, 1, 6, 1, 4])) sage: L.genus() 0 sage: L = Link(B([1, 2, 1, 2])) sage: L.genus() 1 """ return ZZ.zero()
else:
def signature(self): """ Return the signature of ``self``.
EXAMPLES::
sage: B = BraidGroup(4) sage: L = Link(B([-1, 3, 1, 3])) sage: L.signature() -1 sage: B = BraidGroup(8) sage: L = Link(B([-2, 4, 1, 6, 1, 4])) sage: L.signature() -2 sage: L = Link(B([1, 2, 1, 2])) sage: L.signature() -2 """
def alexander_polynomial(self, var='t'): """ Return the Alexander polynomial of ``self``.
INPUT:
- ``var`` -- (default: ``'t'``) the variable in the polynomial
EXAMPLES:
We begin by computing the Alexander polynomial for the figure-eight knot::
sage: B = BraidGroup(3) sage: L = Link(B([1, -2, 1, -2])) sage: L.alexander_polynomial() -t^-1 + 3 - t
The "monster" unknot::
sage: L = Link([[3,1,2,4],[8,9,1,7],[5,6,7,3],[4,18,6,5], ....: [17,19,8,18],[9,10,11,14],[10,12,13,11], ....: [12,19,15,13],[20,16,14,15],[16,20,17,2]]) sage: L.alexander_polynomial() 1
Some additional examples::
sage: B = BraidGroup(2) sage: L = Link(B([1])) sage: L.alexander_polynomial() 1 sage: L = Link(B.one()) sage: L.alexander_polynomial() 1 sage: B = BraidGroup(3) sage: L = Link(B([1, 2, 1, 2])) sage: L.alexander_polynomial() t^-1 - 1 + t
When the Seifert surface is disconnected, the Alexander polynomial is defined to be `0`::
sage: B = BraidGroup(4) sage: L = Link(B([1,3])) sage: L.alexander_polynomial() 0
TESTS::
sage: B = BraidGroup(4) sage: L = Link(B([-1, 3, 1, 3])) sage: L.alexander_polynomial() 0 sage: L = Link(B([1,3,1,1,3,3])) sage: L.alexander_polynomial() 0 sage: B = BraidGroup(8) sage: L = Link(B([-2, 4, 1, 6, 1, 4])) sage: L.alexander_polynomial() 0 """ # The Alexander polynomial of disjoint links are defined to be 0 return f
def determinant(self): """ Return the determinant of ``self``.
EXAMPLES::
sage: B = BraidGroup(4) sage: L = Link(B([-1, 2, 1, 2])) sage: L.determinant() 1 sage: B = BraidGroup(8) sage: L = Link(B([2, 4, 2, 3, 1, 2])) sage: L.determinant() 3 sage: L = Link(B([1]*16 + [2,1,2,1,2,2,2,2,2,2,2,1,2,1,2,-1,2,-2])) sage: L.determinant() 65
TESTS::
sage: Link(B([1, 2, 1, -2, -1])).determinant() Traceback (most recent call last): ... NotImplementedError: determinant implemented only for knots """
def is_alternating(self): """ Return ``True`` if the given knot diagram is alternating else returns ``False``.
Alternating diagram implies every overcross is followed by an undercross or the vice-versa.
We look at the Gauss code if the sign is alternating, ``True`` is returned else the knot is not alternating ``False`` is returned.
EXAMPLES::
sage: B = BraidGroup(4) sage: L = Link(B([-1, -1, -1, -1])) sage: L.is_alternating() False sage: L = Link(B([1, -2, -1, 2])) sage: L.is_alternating() False sage: L = Link(B([-1, 3, 1, 3, 2])) sage: L.is_alternating() False sage: L = Link(B([1]*16 + [2,1,2,1,2,2,2,2,2,2,2,1,2,1,2,-1,2,-2])) sage: L.is_alternating() False sage: L = Link(B([-1,2,-1,2])) sage: L.is_alternating() True """ or s == [(-1) ** i for i in range(len(x[0]))])
def orientation(self): r""" Return the orientation of the crossings of the link diagram of ``self``.
EXAMPLES::
sage: L = Link([[1, 4, 5, 2], [3, 5, 6, 7], [4, 8, 9, 6], [7, 9, 10, 11], [8, 1, 13, 10], [11, 13, 2, 3]]) sage: L.orientation() [-1, 1, -1, 1, -1, 1] sage: L = Link([[1, 7, 2, 6], [7, 3, 8, 2], [3, 11, 4, 10], [11, 5, 12, 4], [14, 5, 1, 6], [13, 9, 14, 8], [12, 9, 13, 10]]) sage: L.orientation() [-1, -1, -1, -1, 1, -1, 1] sage: L = Link([[1, 2, 3, 3], [2, 4, 5, 5], [4, 1, 7, 7]]) sage: L.orientation() [-1, -1, -1] """ else:
def seifert_circles(self): """ Return the Seifert circles from the link diagram of ``self``.
Seifert circles are the circles obtained by smoothing all crossings respecting the orientation of the segments.
Each Seifert circle is represented as a list of the segments that form it.
EXAMPLES::
sage: L = Link([[[1, -2, 3, -4, 2, -1, 4, -3]], [1, 1, -1, -1]]) sage: L.seifert_circles() [[1, 7, 5, 3], [2, 6], [4, 8]] sage: L = Link([[[-1, 2, 3, -4, 5, -6, 7, 8, -2, -5, 6, 1, -8, -3, 4, -7]], [-1, -1, -1, -1, 1, 1, -1, 1]]) sage: L.seifert_circles() [[1, 13, 9, 3, 15, 5, 11, 7], [2, 10, 6, 12], [4, 16, 8, 14]] sage: L = Link([[[-1, 2, -3, 4, 5, 1, -2, 6, 7, 3, -4, -7, -6, -5]], [-1, -1, -1, -1, 1, -1, 1]]) sage: L.seifert_circles() [[1, 7, 3, 11, 5], [2, 8, 14, 6], [4, 12, 10], [9, 13]] sage: L = Link([[1, 7, 2, 6], [7, 3, 8, 2], [3, 11, 4, 10], [11, 5, 12, 4], [14, 5, 1, 6], [13, 9, 14, 8], [12, 9, 13, 10]]) sage: L.seifert_circles() [[1, 7, 3, 11, 5], [2, 8, 14, 6], [4, 12, 10], [9, 13]] sage: L = Link([[[-1, 2, -3, 5], [4, -2, 6, -5], [-4, 1, -6, 3]], [-1, 1, 1, 1, -1, -1]]) sage: L.seifert_circles() [[1, 11, 8], [2, 7, 12, 4, 5, 10], [3, 9, 6]] sage: B = BraidGroup(2) sage: L = Link(B([1, 1, 1])) sage: L.seifert_circles() [[1, 3, 5], [2, 4, 6]]
TESTS:
Check that :trac:`25050` is solved::
sage: A = Link([[[1, 2, -2, -1, -3, -4, 4, 3]], [1, 1, 1, 1]]) sage: A.seifert_circles() [[3], [7], [1, 5], [2, 4], [6, 8]] """ # detect looped segments. They must be their own seifert circles # remove the looped segments from the available result.append([a]) else: else:
def regions(self): """ Return the regions from the link diagram of ``self``.
Regions are obtained always turning left at each crossing.
Then the regions are represented as a list with the segments that form its boundary, with a sign depending on the orientation of the segment as part of the boundary.
EXAMPLES::
sage: L = Link([[[-1, +2, -3, 4, +5, +1, -2, +6, +7, 3, -4, -7, -6,-5]],[-1, -1, -1, -1, 1, -1, 1]]) sage: L.regions() [[1, 7, 3, 11, 5], [2, -7], [4, -11], [6, -1], [8, -13, 10, -3], [9, 13], [12, -9, 14, -5], [-14, -8, -2, -6], [-12, -4, -10]] sage: L = Link([[[1, -2, 3, -4, 2, -1, 4, -3]],[1, 1, -1, -1]]) sage: L.regions() [[1, 7, -4], [2, -5, -7], [3, -8, 5], [4, 8], [6, -1, -3], [-2, -6]] sage: L = Link([[[-1, +2, 3, -4, 5, -6, 7, 8, -2, -5, +6, +1, -8, -3, 4, -7]],[-1, -1, -1, -1, 1, 1, -1, 1]]) sage: L.regions() [[1, 13, -8], [2, -9, -13], [3, -14, 9], [4, 16, 8, 14], [5, 11, 7, -16], [6, -11], [10, -5, -15, -3], [12, -1, -7], [15, -4], [-12, -6, -10, -2]] sage: B = BraidGroup(2) sage: L = Link(B([-1, -1, -1])) sage: L.regions() [[1, 3, 5], [2, -1], [4, -3], [6, -5], [-2, -6, -4]] sage: L = Link([[[1, -2, 3, -4], [-1, 5, -3, 2, -5, 4]], [-1, 1, 1, -1, -1]]) sage: L.regions() [[1, -5], [2, -8, 4, 5], [3, 8], [6, -9, -2], [7, -3, 9], [10, -4, -7], [-10, -6, -1]] sage: L = Link([[1, 2, 3, 3], [2, 5, 4, 4], [5, 7, 6, 6], [7, 1, 8, 8]]) sage: L.regions() [[-3], [-4], [-6], [-8], [1, 2, 5, 7], [-2, 3, -1, 8, -7, 6, -5, 4]]
.. NOTE::
The link diagram is assumed to have only one completely isolated component. This is because otherwise some regions would have disconnected boundary.
TESTS::
sage: B = BraidGroup(6) sage: L = Link(B([1, 3, 5])) sage: L.regions() Traceback (most recent call last): ... NotImplementedError: can only have one isolated component """ return [[-pd[0][2]], [pd[0][0]], [pd[0][2], -pd[0][0]]] else:
else:
else: else:
def mirror_image(self): r""" Return the mirror image of ``self``.
EXAMPLES::
sage: g = BraidGroup(2).gen(0) sage: K = Link(g^3) sage: K2 = K.mirror_image(); K2 Link with 1 component represented by 3 crossings sage: K2.braid() s^-3
.. PLOT:: :width: 300 px
g = BraidGroup(2).gen(0) K = Link(g**3) sphinx_plot(K.plot())
.. PLOT:: :width: 300 px
g = BraidGroup(2).gen(0) K = Link(g**3) sphinx_plot(K.mirror_image().plot())
::
sage: K = Knot([[[1, -2, 3, -1, 2, -3]], [1, 1, 1]]) sage: K2 = K.mirror_image(); K2 Knot represented by 3 crossings sage: K.pd_code() [[4, 1, 5, 2], [2, 5, 3, 6], [6, 3, 1, 4]] sage: K2.pd_code() [[4, 2, 5, 1], [2, 6, 3, 5], [6, 4, 1, 3]]
.. PLOT:: :width: 300 px
K = Link([[[1,-2,3,-1,2,-3]],[1,1,1]]) sphinx_plot(K.plot())
.. PLOT:: :width: 300 px
K = Link([[[1,-2,3,-1,2,-3]],[1,1,1]]) K2 = K.mirror_image() sphinx_plot(K2.plot()) """ # Use the braid information if it is the shortest version # of what we have already computed
lpd = len(self.pd_code()) else:
logc = len(self.oriented_gauss_code()[-1]) else:
# Otherwise we fallback to the PD code
def writhe(self): """ Return the writhe of ``self``.
EXAMPLES::
sage: L = Link([[[1, -2, 3, -4, 2, -1, 4, -3]],[1, 1, -1, -1]]) sage: L.writhe() 0 sage: L = Link([[[-1, 2, -3, 4, 5, 1, -2, 6, 7, 3, -4, -7, -6,-5]], ....: [-1, -1, -1, -1, 1, -1, 1]]) sage: L.writhe() -3 sage: L = Link([[[-1, 2, 3, -4, 5, -6, 7, 8, -2, -5, 6, 1, -8, -3, 4, -7]], ....: [-1, -1, -1, -1, 1, 1, -1, 1]]) sage: L.writhe() -2 """
def jones_polynomial(self, variab=None, skein_normalization=False, algorithm='jonesrep'): r""" Return the Jones polynomial of ``self``.
The normalization is so that the unknot has Jones polynomial `1`. If ``skein_normalization`` is ``True``, the variable of the result is replaced by a itself to the power of `4`, so that the result agrees with the conventions of [Lic1997]_ (which in particular differs slightly from the conventions used otherwise in this class), had one used the conventional Kauffman bracket variable notation directly.
If ``variab`` is ``None`` return a polynomial in the variable `A` or `t`, depending on the value ``skein_normalization``. In particular, if ``skein_normalization`` is ``False``, return the result in terms of the variable `t`, also used in [Lic1997]_.
ALGORITHM:
The calculation goes through one of two possible algorithms, depending on the value of ``algorithm``. Possible values are ``'jonesrep'`` which uses the Jones representation of a braid representation of ``self`` to compute the polynomial of the trace closure of the braid, and ``statesum`` which recursively computes the Kauffman bracket of ``self``. Depending on how the link is given, there might be significant time gains in using one over the other. When the trace closure of the braid is ``self``, the algorithms give the same result.
INPUT:
- ``variab`` -- variable (default: ``None``); the variable in the resulting polynomial; if unspecified, use either a default variable in `\ZZ[A,A^{-1}]` or the variable `t` in the symbolic ring
- ``skein_normalization`` -- boolean (default: ``False``); determines the variable of the resulting polynomial
- ``algorithm`` -- string (default: ``'jonesrep'``); algorithm to use and can be one of the following:
* ``'jonesrep'`` - use the Jones representation of the braid representation
* ``'statesum'`` - recursively computes the Kauffman bracket
OUTPUT:
If ``skein_normalization`` if ``False``, this returns an element in the symbolic ring as the Jones polynomial of the link might have fractional powers when the link is not a knot. Otherwise the result is a Laurant polynomial in ``variab``.
EXAMPLES:
The unknot::
sage: B = BraidGroup(9) sage: b = B([1, 2, 3, 4, 5, 6, 7, 8]) sage: Link(b).jones_polynomial() 1
The "monster" unknot::
sage: L = Link([[3,1,2,4],[8,9,1,7],[5,6,7,3],[4,18,6,5], ....: [17,19,8,18],[9,10,11,14],[10,12,13,11], ....: [12,19,15,13],[20,16,14,15],[16,20,17,2]]) sage: L.jones_polynomial() 1
The Ochiai unknot::
sage: L = Link([[[1,-2,-3,-8,-12,13,-14,15,-7,-1,2,-4,10,11,-13,12, ....: -11,-16,4,3,-5,6,-9,7,-15,14,16,-10,8,9,-6,5]], ....: [-1,-1,1,1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1]]) sage: L.jones_polynomial() # long time 1
Two unlinked unknots::
sage: B = BraidGroup(4) sage: b = B([1, 3]) sage: Link(b).jones_polynomial() -sqrt(t) - 1/sqrt(t)
The Hopf link::
sage: B = BraidGroup(2) sage: b = B([-1,-1]) sage: Link(b).jones_polynomial() -1/sqrt(t) - 1/t^(5/2)
Different representations of the trefoil and one of its mirror::
sage: B = BraidGroup(2) sage: b = B([-1, -1, -1]) sage: Link(b).jones_polynomial(skein_normalization=True) -A^-16 + A^-12 + A^-4 sage: Link(b).jones_polynomial() 1/t + 1/t^3 - 1/t^4 sage: B = BraidGroup(3) sage: b = B([-1, -2, -1, -2]) sage: Link(b).jones_polynomial(skein_normalization=True) -A^-16 + A^-12 + A^-4 sage: R.<x> = LaurentPolynomialRing(GF(2)) sage: Link(b).jones_polynomial(skein_normalization=True, variab=x) x^-16 + x^-12 + x^-4 sage: B = BraidGroup(3) sage: b = B([1, 2, 1, 2]) sage: Link(b).jones_polynomial(skein_normalization=True) A^4 + A^12 - A^16
`K11n42` (the mirror of the "Kinoshita-Terasaka" knot) and `K11n34` (the mirror of the "Conway" knot) in [KnotAtlas]_::
sage: B = BraidGroup(4) sage: K11n42 = Link(B([1, -2, 3, -2, 3, -2, -2, -1, 2, -3, -3, 2, 2])) sage: K11n34 = Link(B([1, 1, 2, -3, 2, -3, 1, -2, -2, -3, -3])) sage: bool(K11n42.jones_polynomial() == K11n34.jones_polynomial()) True
The two algorithms for computation give the same result when the trace closure of the braid representation is the link itself::
sage: L = Link([[[-1, 2, -3, 4, 5, 1, -2, 6, 7, 3, -4, -7, -6, -5]], ....: [-1, -1, -1, -1, 1, -1, 1]]) sage: jonesrep = L.jones_polynomial(algorithm='jonesrep') sage: statesum = L.jones_polynomial(algorithm='statesum') sage: bool(jonesrep == statesum) True
When we have thrown away unknots so that the trace closure of the braid is not necessarily the link itself, this is only true up to a power of the Jones polynomial of the unknot::
sage: B = BraidGroup(3) sage: b = B([1]) sage: L = Link(b) sage: b.components_in_closure() 2 sage: L.number_of_components() 1 sage: b.jones_polynomial() -sqrt(t) - 1/sqrt(t) sage: L.jones_polynomial(algorithm='statesum') 1
TESTS::
sage: L = Link([]) sage: L.jones_polynomial(algorithm='statesum') 1
sage: L.jones_polynomial(algorithm='other') Traceback (most recent call last): ... ValueError: bad value of algorithm """ # Switch to the variable A to have the result agree with the output # of the jonesrep algorithm
if variab is None: return jones else: return jones(variab) else: # We force the result to be in the symbolic ring because of the expand
@cached_method def _bracket(self): r""" Return the Kaufmann bracket polynomial of the diagram of ``self``.
Note that this is not an invariant of the link, but of the diagram. In particular, it is not invariant under Reidemeister I moves.
EXAMPLES::
sage: L = Link([[[-1, 2, 3, -4, 5, -6, 7, 8, -2, -5, 6, 1, -8, -3, 4, -7]], ....: [-1, -1, -1, -1, 1, 1, -1, 1]]) sage: L._bracket() -t^-10 + 2*t^-6 - t^-2 + 2*t^2 - t^6 + t^10 - t^14 sage: L = Link([[2, 1, 3, 4], [4, 3, 1, 2]]) sage: L._bracket() -t^-4 - t^4 """ else:
return (~t + t**(-5)) * Link(rest)._bracket() return (t + t**5) * Link(rest)._bracket() else:
def _isolated_components(self): r""" Return the PD codes of the isolated components of ``self``.
Isolated components are links corresponding to subdiagrams that do not have any common crossing.
EXAMPLES::
sage: L = Link([[1, 1, 2, 2], [3, 3, 4, 4]]) sage: L._isolated_components() [[[1, 1, 2, 2]], [[3, 3, 4, 4]]] """
def homfly_polynomial(self, var1='L', var2='M', normalization = 'lm'): r""" Return the HOMFLY polynomial of ``self``.
The HOMFLY polynomial `P(K)` of a link `K` is a Laurent polynomial in two variables defined using skein relations and for the unknot `U`, we have `P(U) = 1`.
INPUT:
- ``var1`` -- (default: ``'L'``) the first variable - ``var2`` -- (default: ``'M'``) the second variable - ``normalization`` -- (default: ``lm``) the system of coordinates and can be one of the following:
* ``'lm'`` -- corresponding to the Skein relation `L\cdot P(K _+) + L^{-1}\cdot P(K _-) + M\cdot P(K _0) = 0`
* ``'az'`` -- corresponding to the Skein relation `a\cdot P(K _+) - a^{-1}\cdot P(K _-) = z \cdot P(K _0)`
where `P(K _+)`, `P(K _-)` and `P(K _0)` represent the HOMFLY polynomials of three links that vary only in one crossing; that is the positive, negative, or smoothed links respectively
OUTPUT:
A Laurent polynomial over the integers.
.. NOTE::
Use the ``'az'`` normalization to agree with the data in [KnotAtlas]_ and http://www.indiana.edu/~knotinfo/.
EXAMPLES:
We give some examples::
sage: g = BraidGroup(2).gen(0) sage: K = Knot(g^5) sage: K.homfly_polynomial() # optional - libhomfly L^-4*M^4 - 4*L^-4*M^2 + 3*L^-4 - L^-6*M^2 + 2*L^-6
The Hopf link::
sage: L = Link([[1,3,2,4],[4,2,3,1]]) sage: L.homfly_polynomial('x', 'y') # optional - libhomfly -x^-1*y + x^-1*y^-1 + x^-3*y^-1
Another version of the Hopf link where the orientation has been changed. Therefore we substitute `x \mapsto L^{-1}` and `y \mapsto M`::
sage: L = Link([[1,4,2,3], [4,1,3,2]]) sage: L.homfly_polynomial() # optional - libhomfly L^3*M^-1 - L*M + L*M^-1 sage: L = Link([[1,4,2,3], [4,1,3,2]]) sage: L.homfly_polynomial('a', 'z', 'az') # optional - libhomfly a^3*z^-1 - a*z - a*z^-1
The figure-eight knot::
sage: L = Link([[2,1,4,5], [5,6,7,3], [6,4,1,9], [9,2,3,7]]) sage: L.homfly_polynomial() # optional - libhomfly -L^2 + M^2 - 1 - L^-2 sage: L.homfly_polynomial('a', 'z', 'az') # optional - libhomfly a^2 - z^2 - 1 + a^-2
The "monster" unknot::
sage: L = Link([[3,1,2,4], [8,9,1,7], [5,6,7,3], [4,18,6,5], ....: [17,19,8,18], [9,10,11,14], [10,12,13,11], ....: [12,19,15,13], [20,16,14,15], [16,20,17,2]]) sage: L.homfly_polynomial() # optional - libhomfly 1
The knot `9_6`::
sage: B = BraidGroup(3) sage: K = Knot(B([-1,-1,-1,-1,-1,-1,-2,1,-2,-2])) sage: K.homfly_polynomial() # optional - libhomfly L^10*M^4 - L^8*M^6 - 3*L^10*M^2 + 4*L^8*M^4 + L^6*M^6 + L^10 - 3*L^8*M^2 - 5*L^6*M^4 - L^8 + 7*L^6*M^2 - 3*L^6 sage: K.homfly_polynomial('a', 'z', normalization='az') # optional - libhomfly -a^10*z^4 + a^8*z^6 - 3*a^10*z^2 + 4*a^8*z^4 + a^6*z^6 - a^10 + 3*a^8*z^2 + 5*a^6*z^4 - a^8 + 7*a^6*z^2 + 3*a^6
TESTS:
This works with isolated components::
sage: L = Link([[[1, -1], [2, -2]], [1, 1]]) sage: L2 = Link([[1, 3, 2, 4], [2, 3, 1, 4]]) sage: L2.homfly_polynomial() # optional - libhomfly -L*M^-1 - L^-1*M^-1 sage: L.homfly_polynomial() # optional - libhomfly -L*M^-1 - L^-1*M^-1 sage: L.homfly_polynomial('a', 'z', 'az') # optional - libhomfly a*z^-1 - a^-1*z^-1 sage: L2.homfly_polynomial('a', 'z', 'az') # optional - libhomfly a*z^-1 - a^-1*z^-1
REFERENCES:
- :wikipedia:`HOMFLY_polynomial` - http://mathworld.wolfram.com/HOMFLYPolynomial.html """ L = LaurentPolynomialRing(ZZ, [var1, var2]) if len(self._isolated_components()) > 1: if normalization == 'lm': fact = L({(1, -1):-1, (-1, -1):-1}) elif normalization == 'az': fact = L({(1, -1):1, (-1, -1):-1}) else: raise ValueError('normalization must be either `lm` or `az`') fact = fact ** (len(self._isolated_components())-1) for i in self._isolated_components(): fact = fact * Link(i).homfly_polynomial(var1, var2, normalization) return fact s = '{}'.format(self.number_of_components()) ogc = self.oriented_gauss_code() for comp in ogc[0]: s += ' {}'.format(len(comp)) for cr in comp: s += ' {} {}'.format(abs(cr)-1, sign(cr)) for i, cr in enumerate(ogc[1]): s += ' {} {}'.format(i, cr) from sage.libs.homfly import homfly_polynomial_dict dic = homfly_polynomial_dict(s) if normalization == 'lm': return L(dic) elif normalization == 'az': auxdic = {} for a in dic: if (a[0] + a[1]) % 4 == 0: auxdic[a] = dic[a] else: auxdic[a] = -dic[a] if self.number_of_components() % 2: return L(auxdic) else: return -L(auxdic) else: raise ValueError('normalization must be either `lm` or `az`')
def plot(self, gap=0.1, component_gap=0.5, solver=None, **kwargs): r""" Plot ``self``.
INPUT:
- ``gap`` -- (default: 0.1) the size of the blank gap left for the crossings
- ``component_gap`` -- (default: 0.5) the gap between isolated components
- ``solver`` -- the linear solver to use, see :class:`~sage.numerical.mip.MixedIntegerLinearProgram`.
The usual keywords for plots can be used here too.
EXAMPLES:
We construct the simplest version of the unknot::
sage: L = Link([[2, 1, 1, 2]]) sage: L.plot() Graphics object consisting of ... graphics primitives
.. PLOT:: :width: 300 px
B = BraidGroup(2) L = Link([[2, 1, 1, 2]]) sphinx_plot(L.plot())
We construct a more interesting example of the unknot::
sage: L = Link([[2, 1, 4, 5], [3, 5, 6, 7], [4, 1, 9, 6], [9, 2, 3, 7]]) sage: L.plot() Graphics object consisting of ... graphics primitives
.. PLOT:: :width: 300 px
L = Link([[2,1,4,5], [3,5,6,7], [4,1,9,6], [9,2,3,7]]) sphinx_plot(L.plot())
The "monster" unknot::
sage: L = Link([[3,1,2,4],[8,9,1,7],[5,6,7,3],[4,18,6,5], ....: [17,19,8,18],[9,10,11,14],[10,12,13,11], ....: [12,19,15,13],[20,16,14,15],[16,20,17,2]]) sage: L.plot() Graphics object consisting of ... graphics primitives
.. PLOT:: :width: 300 px
L = Link([[3,1,2,4],[8,9,1,7],[5,6,7,3],[4,18,6,5], [17,19,8,18],[9,10,11,14],[10,12,13,11], [12,19,15,13],[20,16,14,15],[16,20,17,2]]) sphinx_plot(L.plot())
The Ochiai unknot::
sage: L = Link([[[1,-2,-3,-8,-12,13,-14,15,-7,-1,2,-4,10,11,-13,12, ....: -11,-16,4,3,-5,6,-9,7,-15,14,16,-10,8,9,-6,5]], ....: [-1,-1,1,1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1]]) sage: L.plot() Graphics object consisting of ... graphics primitives
.. PLOT:: :width: 300 px
L = Link([[[1,-2,-3,-8,-12,13,-14,15,-7,-1,2,-4,10,11,-13,12, -11,-16,4,3,-5,6,-9,7,-15,14,16,-10,8,9,-6,5]], [-1,-1,1,1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1]]) sphinx_plot(L.plot())
One of the representations of the trefoil knot::
sage: L = Link([[1, 5, 2, 4], [5, 3, 6, 2], [3, 1, 4, 6]]) sage: L.plot() Graphics object consisting of 14 graphics primitives
.. PLOT:: :width: 300 px
L = Link([[1, 5, 2, 4], [5, 3, 6, 2], [3, 1, 4, 6]]) sphinx_plot(L.plot())
The figure-eight knot::
sage: L = Link([[2, 1, 4, 5], [5, 6, 7, 3], [6, 4, 1, 9], [9, 2, 3, 7]]) sage: L.plot() Graphics object consisting of ... graphics primitives
.. PLOT:: :width: 300 px
L = Link([[2,1,4,5], [5,6,7,3], [6,4,1,9], [9,2,3,7]]) sphinx_plot(L.plot())
The knot `K11n121` in [KnotAtlas]_::
sage: L = Link([[4,2,5,1], [10,3,11,4], [5,16,6,17], [7,12,8,13], ....: [18,9,19,10], [2,11,3,12], [13,20,14,21], [15,6,16,7], ....: [22,18,1,17], [8,19,9,20], [21,14,22,15]]) sage: L.plot() Graphics object consisting of ... graphics primitives
.. PLOT:: :width: 300 px
L = Link([[4,2,5,1], [10,3,11,4], [5,16,6,17], [7,12,8,13], [18,9,19,10], [2,11,3,12], [13,20,14,21], [15,6,16,7], [22,18,1,17], [8,19,9,20], [21,14,22,15]]) sphinx_plot(L.plot())
One of the representations of the Hopf link::
sage: L = Link([[1, 4, 2, 3], [4, 1, 3, 2]]) sage: L.plot() Graphics object consisting of ... graphics primitives
.. PLOT:: :width: 300 px
L = Link([[1, 4, 2, 3], [4, 1, 3, 2]]) sphinx_plot(L.plot())
Plotting links with multiple isolated components::
sage: L = Link([[[-1, 2, -3, 1, -2, 3], [4, -5, 6, -4, 5, -6]], [1, 1, 1, 1, 1, 1]]) sage: L.plot() Graphics object consisting of ... graphics primitives
.. PLOT:: :width: 300 px
L = Link([[[-1,2,-3,1,-2,3], [4,-5,6,-4,5,-6]], [1,1,1,1,1,1]]) sphinx_plot(L.plot())
TESTS:
Check that :trac:`20315` is fixed::
sage: L = Link([[2,1,4,5], [5,6,7,3], [6,4,1,9], [9,2,3,7]]) sage: L.plot(solver='GLPK') Graphics object consisting of ... graphics primitives sage: L.plot(solver='Coin') # optional - cbc Graphics object consisting of ... graphics primitives sage: L.plot(solver='CPLEX') # optional - CPLEX Graphics object consisting of ... graphics primitives sage: L.plot(solver='Gurobi') # optional - Gurobi Graphics object consisting of ... graphics primitives """ # Handle isolated components individually else:
# Special case for the unknot return circle((0,0), ZZ(1)/ZZ(2), **kwargs)
# The idea is the same followed in spherogram, but using MLP instead of # network flows. # We start by computing a way to bend the edges left or right # such that the resulting regions are in fact closed regions # with straight angles, and using the minimal number of bends. # v will be the list of variables in the MLP problem. There will be # two variables for each edge: number of right bendings and number of # left bendings (at the end, since we are minimizing the total, only one # of each will be nonzero # one condition for each region else: # we store the result in a vector s packing right bends as negative left ones # segments represents the different parts of the previous edges after bending else: else: if any(badregion[b][0] == x[0] for x in nr)] else: if badregion[b][0] in pieces[x]] else:
else:
else: else: else:
else: p[1] + im[c+1][0][1][1] - im[c+1][0][0][1] - yp] else: else: im[c+1][0][0][1] + sign(im[c+1][0][1][1] - im[c+1][0][0][1])]
|