Skip to content

Commit

Permalink
Rotating and potentially inverting word to simplify.
Browse files Browse the repository at this point in the history
  • Loading branch information
unhyperbolic committed May 29, 2024
1 parent 8af517b commit 17666e7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
16 changes: 11 additions & 5 deletions python/len_spec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from .tile import compute_length_spectrum_tiles, LengthSpectrumTile
from .geodesic_info import GeodesicInfoBase, GeodesicKeyInfo, CoreCurveGeodesicInfo
from .geodesic_key_info_dict import get_geodesic_key_info_set
from .word import simplify_cyclic_word
from .word import simplify_geodesic_word
from .length_spectrum_geodesic_info import LengthSpectrumGeodesicInfo

from ..geometric_structure import word_list_to_psl2c_matrix
Expand Down Expand Up @@ -31,13 +31,19 @@ def length_spectrum(manifold,
>>> spec = M._length_spectrum_dev()
>>> next(spec) # doctest: +NUMERIC9
Length Word Core curve
0.14742465268510 - 1.78287093565206*I CBAdCBAAb Cusp 0
0.14742465268510 - 1.78287093565206*I aabcDabcB Cusp 0
>>> next(spec) # doctest: +NUMERIC9
0.81161414965959 + 2.72911699294425*I B
0.81161414965959 + 2.72911699294425*I b -
>>> next(spec) # doctest: +NUMERIC9
0.84163270359334 + 2.61245944742151*I aB -
>>> next(spec) # doctest: +NUMERIC9
0.93461379591349 + 2.70060614107722*I A -
0.93461379591349 + 2.70060614107722*I a -
>>> next(spec) # doctest: +NUMERIC9
1.50642474995261 + 3.13101560181284*I ab -
>>> next(spec) # doctest: +NUMERIC9
1.58977016368115 - 3.08892331549756*I abC -
>>> next(spec) # doctest: +NUMERIC9
1.60467656123231 + 3.09975771482376*I aBB -
>>> M = Manifold("m125(3,4)(0,0)")
>>> spec = M._length_spectrum_dev()
Expand Down Expand Up @@ -74,7 +80,7 @@ def length_spectrum(manifold,
_is_first = is_first,
length = geodesic.length,
word = list_as_word(
simplify_cyclic_word(geodesic.word),
simplify_geodesic_word(geodesic.word),
num_generators,
verbose_form=False),
core_curve = core_curve,
Expand Down
35 changes: 26 additions & 9 deletions python/len_spec/word.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
from ..SnapPy import reduce_list_word
from ..SnapPy import reduce_list_word, inverse_list_word

from typing import List

def simplify_cyclic_word(word : List[int]) -> List[int]:
def simplify_geodesic_word(word : List[int]) -> List[int]:
"""
Cancels generator and inverse generator - whether they are next to each
other or at opposite ends of the word.
>>> simplify_cyclic_word([])
>>> simplify_geodesic_word([])
[]
>>> simplify_cyclic_word([1])
>>> simplify_geodesic_word([1])
[1]
>>> simplify_cyclic_word([1, 2])
>>> simplify_geodesic_word([1, 2])
[1, 2]
>>> simplify_cyclic_word([-1, 2, -2, 1])
>>> simplify_geodesic_word([-1, 2, -2, 1])
[]
>>> simplify_cyclic_word([-1, 3, 2, -2, 1])
>>> simplify_geodesic_word([-1, 3, 2, -2, 1])
[3]
>>> simplify_cyclic_word([-1, 3, 4, 2, -2, 1])
>>> simplify_geodesic_word([-1, 3, 4, 2, -2, 1])
[3, 4]
"""

return _cancel_conjugation(reduce_list_word(word))
return (
_rotate_and_optionally_invert(
_cancel_conjugation(
reduce_list_word(word))))

def _cancel_conjugation(word : List[int]) -> List[int]:
n = len(word)
Expand All @@ -30,3 +33,17 @@ def _cancel_conjugation(word : List[int]) -> List[int]:
if word[i] != -word[k]:
return word[i:k+1]
return word[n // 2 : (n + 1) // 2]

def _rotate_and_optionally_invert(word : List[int]) -> List[int]:
n = len(word)

if n == 0:
return word

return min(
(candidates[i:] + candidates[:i]
for candidates in [ word, inverse_list_word(word) ]
for i in range(len(word))),
key=lambda w: [ 2 * l if l > 0 else 2 * -l + 1
for l in w ])

0 comments on commit 17666e7

Please sign in to comment.