Skip to content

Commit

Permalink
fix docstring, fix whitespace around = and ,
Browse files Browse the repository at this point in the history
  • Loading branch information
mantepse committed Oct 9, 2024
1 parent b0f09d9 commit bf79d5c
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions src/sage/modular/arithgroup/farey_symbol.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ cdef class Farey:
[ -3 1]
[-40 13]
"""
gens_dict = {g:i+1 for i,g in enumerate(self.generators())}
gens_dict = {g: i+1 for i, g in enumerate(self.generators())}
ans = []
for pm in self.pairing_matrices():
a, b, c, d = pm.matrix().list()
Expand Down Expand Up @@ -331,7 +331,7 @@ cdef class Farey:
sage: (-g.matrix()).is_one()
True
"""
for i,g in enumerate(self.generators()):
for i, g in enumerate(self.generators()):
m = g.matrix()
if (-m).is_one():
return [i + 1]
Expand All @@ -342,15 +342,17 @@ cdef class Farey:
return 3 * [i + 1]
return []

def word_problem(self, M, output = 'standard', check = True):
def word_problem(self, M, output='standard', check=True):
r"""
Solve the word problem (up to sign) using this Farey symbol.
INPUT:
- ``M`` -- an element `M` of `\SL_2(\ZZ)`
- ``output`` -- (default: ``'standard'``) should be one of ``'standard'``,
``'syllables'``, ``'gens'``.
- ``output`` -- (default: ``'standard'``) should be one of
``'standard'``, ``'syllables'``, ``'gens'``.
- ``check`` -- boolean (default: ``True``); whether to check for
correct input and output
Expand All @@ -359,17 +361,17 @@ cdef class Farey:
A solution to the word problem for the matrix `M`.
The format depends on the ``output`` parameter, as follows.
- ``standard`` returns the so called the Tietze representation,
consists of a tuple of nonzero integers `i`, where if `i` > 0
then it indicates the `i`-th generator (that is, ``self.generators()[0]``
would correspond to `i` = 1), and if `i` < 0 then it indicates
the inverse of the `i`-th generator.
- ``syllables`` returns a tuple of tuples of the form `(i,n)`, where
`(i,n)` represents ``self.generators()[i] ^ n``,
- ``'standard'`` returns the so called Tietze representation,
which consists of a tuple of nonzero integers. A positive
integer `i` indicates the `i`-th generator (that is,
``self.generators()[i-1]``), while a negative integer `i`
indicates the inverse of the `i`-th generator.
- ``'syllables'`` returns a tuple of tuples of the form
`(i, n)`, where `(i, n)` represents ``self.generators()[i] ^ n``,
whose product equals `M` up to sign.
- ``gens`` returns tuple of tuples of the form `(g,n)`,
`(g,n)` such that the product of the matrices `g^n`
equals `M` up to sign.
- ``'gens'`` returns a tuple of pairs `(g, n)`, where `g` is a
matrix and `n` an integer, such that the product of the
matrices `g^n` equals `M` up to sign.
EXAMPLES::
Expand All @@ -385,7 +387,7 @@ cdef class Farey:
sage: g
[-5048053 586303]
[-5558280 645563]
sage: F.word_problem(g, output = 'gens')
sage: F.word_problem(g, output='gens')
((
[109 -10]
[120 -11], 1
Expand All @@ -402,7 +404,7 @@ cdef class Farey:
[17 -2]
[60 -7], 1
))
sage: F.word_problem(g, output = 'syllables')
sage: F.word_problem(g, output='syllables')
((3, 1), (10, 2), (8, -1), (5, 1))
TESTS:
Expand All @@ -413,7 +415,7 @@ cdef class Farey:
sage: G = Gamma0(10)
sage: F = G.farey_symbol()
sage: g = G([-701,-137,4600,899])
sage: g1 = prod(F.generators()[i]**a for i,a in F.word_problem(g, output = 'syllables'))
sage: g1 = prod(F.generators()[i]**a for i, a in F.word_problem(g, output='syllables'))
sage: g == g1
True
Expand All @@ -426,15 +428,16 @@ cdef class Farey:
Check that :issue:`20347` is solved::
sage: from sage.misc.misc_c import prod
sage: G = ArithmeticSubgroup_Permutation(S2="(1,2)(3,4)",S3="(1,2,3)")
sage: G = ArithmeticSubgroup_Permutation(S2="(1,2)(3,4)", S3="(1,2,3)")
sage: S = G.farey_symbol()
sage: g1,g2 = S.generators()
sage: g1, g2 = S.generators()
sage: g = g1^3 * g2^-2 * g1 * g2
sage: S.word_problem(g)
(2, 2, 2, 1, 1, 1, 2, 1, 2)
sage: h = prod(S.generators()[i]**a for i,a in S.word_problem(g, output = 'syllables'))
sage: h = prod(S.generators()[i]**a for i, a in S.word_problem(g, output='syllables'))
sage: g == h
True
"""
if output not in ['standard', 'syllables', 'gens']:
raise ValueError('Unrecognized output format')
Expand Down Expand Up @@ -464,7 +467,7 @@ cdef class Farey:
if sgn == -1:
beta, mbeta = mbeta, beta

gens_dict = {g:i+1 for i,g in enumerate(self.generators())}
gens_dict = {g: i+1 for i, g in enumerate(self.generators())}
extra_tietze = []
if beta.is_one():
found = True
Expand Down Expand Up @@ -501,13 +504,13 @@ cdef class Farey:
for i in range(len(tietze)):
t = tietze[i]
tmp = tmp * gens[t-1] if t > 0 else tmp * gens[-t-1]**-1
assert tmp.matrix() == M.matrix(),'%s %s %s' % (tietze, tmp.matrix(),M.matrix())
assert tmp.matrix() == M.matrix(), '%s %s %s' % (tietze, tmp.matrix(), M.matrix())
if output == 'standard':
return tuple(tietze)
if output == 'syllables':
return tuple((a-1,len(list(g))) if a > 0 else (-a-1,-len(list(g))) for a,g in groupby(tietze))
return tuple((a-1, len(list(g))) if a > 0 else (-a-1, -len(list(g))) for a, g in groupby(tietze))
else: # output == 'gens'
return tuple((gens[a-1],len(list(g))) if a > 0 else (gens[-a-1],-len(list(g))) for a, g in groupby(tietze))
return tuple((gens[a-1], len(list(g))) if a > 0 else (gens[-a-1], -len(list(g))) for a, g in groupby(tietze))

def __contains__(self, M):
r"""
Expand Down Expand Up @@ -594,9 +597,9 @@ cdef class Farey:
EXAMPLES::
sage: FareySymbol(Gamma0(11))._latex_(forced_format = 'plain')
sage: FareySymbol(Gamma0(11))._latex_(forced_format='plain')
'\\left( -\\infty\\underbrace{\\quad}_{1} 0\\underbrace{\\quad}_{2} \\frac{1}{3}\\underbrace{\\quad}_{3} \\frac{1}{2}\\underbrace{\\quad}_{2} \\frac{2}{3}\\underbrace{\\quad}_{3} 1\\underbrace{\\quad}_{1} \\infty\\right)'
sage: FareySymbol(Gamma0(11))._latex_(forced_format = 'xymatrix')
sage: FareySymbol(Gamma0(11))._latex_(forced_format='xymatrix')
'\\begin{xy}\\xymatrix{& -\\infty \\ar@{-}@/_1pc/[r]_{1}& 0 \\ar@{-}@/_1pc/[r]_{2}& \\frac{1}{3} \\ar@{-}@/_1pc/[r]_{3}& \\frac{1}{2} \\ar@{-}@/_1pc/[r]_{2}& \\frac{2}{3} \\ar@{-}@/_1pc/[r]_{3}& 1 \\ar@{-}@/_1pc/[r]_{1}& \\infty }\\end{xy}'
sage: 'xymatrix' in FareySymbol(Gamma0(11))._latex_()
Expand Down

0 comments on commit bf79d5c

Please sign in to comment.