Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
30352: adding Gauss-code and symmetry type
Browse files Browse the repository at this point in the history
  • Loading branch information
soehms committed Aug 15, 2020
1 parent a79ddf5 commit a8f1bfc
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build/pkgs/knotinfo/SPKG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ https://linkinfo.sitehost.iu.edu'

* #30352: Initial version

The tarbal has been created from the both download files at the
The tarball has been created from the both download files at the
given date:

`knotinfo_data_complete.xls`
Expand Down
7 changes: 7 additions & 0 deletions build/pkgs/knotinfo/spkg-check.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cd $SAGE_ROOT/src/sage/

echo "Testing databases/knotinfo_db.py"
sage -t databases/knotinfo_db.py || sdh_die "Error testing KnotInfo databases"

echo "Testing knots/knotinfo.py"
sage -t knots/knotinfo.py || sdh_die "Error testing KnotInfo funcionality"
26 changes: 21 additions & 5 deletions src/sage/databases/knotinfo_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@
from sage.env import SAGE_SHARE, SAGE_ROOT


def is_knotinfo_available():
r"""
Return wether the KnotInfo databases are installed or not.
EXAMPLES::
sage: from sage.databases.knotinfo_db import is_knotinfo_available
sage: is_knotinfo_available()
True
"""
ki_db = KnotInfoDataBase()
try:
ki_db.read_num_knots()
return True
except FileNotFoundError:
return False


class KnotInfoColumnTypes(Enum):
r"""
Expand Down Expand Up @@ -291,9 +308,6 @@ def __init__(self):
self._knot_prefix = 'K'
self._import_path = os.path.join(SAGE_SHARE, self._package)

from sage.misc.misc import sage_makedirs
sage_makedirs(self._import_path)

self._knot_list = None
self._link_list = None

Expand All @@ -303,7 +317,7 @@ def _create_csv_file(self, filename, path_for_src):
Return the data fetched from the web-page as a csv file
such that it can be parsed via pythons ``csv`` class.
INOUT:
INPUT:
- ``filename`` - instance of :class:`KnotInfoDataBase.filename`
- ``path_for_src`` - string giving the pathname where to store
Expand Down Expand Up @@ -365,7 +379,6 @@ def create_spkg_tarball(self, path_for_src=None):
os.system('cd %s; tar -cvjSf %s/upstream/%s-%s.tar.bz2 src' %(path, SAGE_ROOT, self._package, self._version) )


@cached_method
def version(self):
r"""
Return the current version.
Expand Down Expand Up @@ -439,6 +452,9 @@ def create_col_dict_sobj(self):
link_list = self.link_list()
link_column_names = link_list[0]

from sage.misc.misc import sage_makedirs
sage_makedirs(self._import_path)

num_knots = len_knots - 1
save(num_knots, '%s/%s' %(self._import_path, self.filename.knots.sobj_num_knots()))

Expand Down
123 changes: 111 additions & 12 deletions src/sage/knots/knotinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,6 @@ def eval_knotinfo(string, locals={}, to_tuple=True):



class KnotInfoNotation(Enum):
r"""
"""

braid = 'braid'
PD = 'planar diagram'
DT = 'Docker Thistlewait'
Gauss = 'Gauss code'


class KnotInfoBase(Enum):
r"""
Enum class to select the knots and links provided by http://www.indiana.edu/~knotinfo
Expand All @@ -117,7 +107,7 @@ def items(self):
sage: from sage.knots.knotinfo import KnotInfo
sage: L = KnotInfo.L4a1_0
sage: it = L.items
sage: [it.name for it in it if it.name.endswith('notation')]
sage: [i.name for i in it if i.name.endswith('notation')]
['dt_notation',
'conway_notation',
'two_bridge_notation',
Expand Down Expand Up @@ -498,6 +488,96 @@ def is_knot(self):
"""
return self.num_components() == 1

@cached_method
def symmetry_type(self):
r"""
Return the symmetry type of ``self``.
From the KnotInfo description page:
If a knot is viewed as the oriented diffeomorphism
class of an oriented pair, `K = (S_3, S_1), with `S_i`
diffeomorphic to `S^i`, there are four oriented knots
associated to any particular knot `K`. In addition to
`K` itself, there is the reverse, `K^r = (S_3, -S_1)`,
the concordance inverse, `-K = (-S_3, -S_1)`, and the
mirror image, `K^m = (-S3, S1)`. A knot is called
reversible if `K = K^r`, negative amphicheiral if
`K = -K`, and positive amphicheiral if `K = K^m`.
A knot possessing any two of these types of symmetry
has all three. Thus, in the table, a knot is called
reversible if that is the only type of symmetry it has,
and likewise for negative amphicheiral. If it has none
of these types of symmetry it is called chiral, and if
it has all three it is called fully amphicheiral.
For prime knots with fewer than 12 crossings, all
amphicheiral knots are negative amphicheiral.
EXAMPLES::
sage: from sage.knots.knotinfo import KnotInfo
sage: [(L.name, L.symmetry_type()) for L in KnotInfo if L.is_knot() and L.crossing_number() < 6]
[('K0_1', 'fully amphicheiral'),
('K3_1', 'reversible'),
('K4_1', 'fully amphicheiral'),
('K5_1', 'reversible'),
('K5_2', 'reversible')]
"""
if not self.is_knot():
raise NotImplementedError('This is only available for knots')
if not self[self.items.symmetry_type] and self.crossing_number() == 0:
return 'fully amphicheiral'
return self[self.items.symmetry_type]


def is_reversible(self):
r"""
Return wether ``self`` is reversible.
EXAMPLES::
sage: from sage.knots.knotinfo import KnotInfo
sage: KnotInfo.K6_3.is_reversible()
True
"""
if self.symmetry_type() == 'reversible':
return True
if self.symmetry_type() == 'fully amphicheiral':
return True
return False

def is_amphicheiral(self, positive=False):
r"""
Return wether ``self`` is amphicheiral.
INPUT:
- ``positive`` -- Boolean (default False) wether to check
if ``self`` is positive or negative amphicheiral (see
doctest of :meth:`symmetry_type`)
EXAMPLES::
sage: from sage.knots.knotinfo import KnotInfo
sage: K = KnotInfo.K12a_427
sage: K.is_amphicheiral()
False
sage: K.is_amphicheiral(positive=True)
True
"""
if positive:
if self.symmetry_type() == 'positive amphicheiral':
return True
else:
if self.symmetry_type() == 'negative amphicheiral':
return True
if self.symmetry_type() == 'fully amphicheiral':
return True
return False


@cached_method
def homfly_polynomial(self, var1='L', var2='M', original=False):
r"""
Expand Down Expand Up @@ -611,7 +691,8 @@ def link(self, use_item=db.columns().pd_notation):
that should be used to construct the link. Allowed values
are:
-- self.items.pd_notation
-- self.items.dt_notation (only for knots)
-- self.items.dt_notation (only for knots)
-- self.items.gauss_notation (only for knots)
-- self.items.braid_notation
.. NOTE::
Expand All @@ -631,6 +712,11 @@ def link(self, use_item=db.columns().pd_notation):
Therefore, we have to take the mirror_image of the
link!
Furthermore, note that the mirror version may depend
on the used KnotInfo-notation. For example for the
knot `5_1` the Gauss- and the DT-notation refer to
the mirror image (see example below).
EXAMPLES::
sage: from sage.knots.knotinfo import KnotInfo
Expand Down Expand Up @@ -670,6 +756,14 @@ def link(self, use_item=db.columns().pd_notation):
[[4, 1, 5, 2], [8, 5, 1, 6], [6, 4, 7, 3], [2, 8, 3, 7]]
sage: K4_1.pd_notation()
[[4, 2, 5, 1], [8, 6, 1, 5], [6, 3, 7, 4], [2, 7, 3, 8]]
sage: K5_1 = KnotInfo.K5_1
sage: K5_1.link().braid()
s^5
sage: K5_1.link(K5_1.items.dt_notation).braid()
s^-5
sage: K5_1.link(K5_1.items.gauss_notation).braid()
s^-5
"""
if not isinstance(use_item, KnotInfoColumns):
raise TypeError('%s must be an instance of %s' %(use_item, KnotInfoColumns))
Expand All @@ -688,6 +782,11 @@ def link(self, use_item=db.columns().pd_notation):
raise NotImplementedError('%s only implemented for knots' %use_item)
from sage.knots.knot import Knots
return Knots().from_dowker_code(self.dt_notation())
elif use_item == self.items.gauss_notation:
if not self.is_knot():
raise NotImplementedError('%s only implemented for knots' %use_item)
from sage.knots.knot import Knots
return Knots().from_gauss_code(self.gauss_notation())
else:
raise ValueError('Construction using %s not possible' %use_item)

Expand Down

0 comments on commit a8f1bfc

Please sign in to comment.