Skip to content

Commit 78b1fd0

Browse files
author
Release Manager
committed
Trac #34619: fix some details in doc of charpoly_frobenius
and also pep8 standard for the code in this file URL: https://trac.sagemath.org/34619 Reported by: chapoton Ticket author(s): Frédéric Chapoton Reviewer(s): David Coudert
2 parents 45aacf3 + 0e88192 commit 78b1fd0

File tree

11 files changed

+41
-38
lines changed

11 files changed

+41
-38
lines changed

src/sage/categories/additive_magmas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ def is_empty(self):
730730
731731
TESTS:
732732
733-
We check that the method `is_empty` is inherited from this
733+
We check that the method ``is_empty`` is inherited from this
734734
category in both examples above::
735735
736736
sage: A.is_empty.__module__

src/sage/categories/category.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2236,7 +2236,7 @@ def _sort(categories):
22362236
22372237
.. NOTE::
22382238
2239-
The auxiliary function `_flatten_categories` used in the test
2239+
The auxiliary function ``_flatten_categories`` used in the test
22402240
below expects a second argument, which is a type such that
22412241
instances of that type will be replaced by its super
22422242
categories. Usually, this type is :class:`JoinCategory`.

src/sage/categories/coxeter_groups.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ def _test_reduced_word(self, **options):
668668

669669
def simple_projection(self, i, side='right', length_increasing=True):
670670
r"""
671-
Return the simple projection `\pi_i` (or `\overline\pi_i` if `length_increasing` is ``False``).
671+
Return the simple projection `\pi_i` (or `\overline\pi_i` if ``length_increasing`` is ``False``).
672672
673673
INPUT:
674674

src/sage/categories/crystals.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,9 @@ def to_highest_weight(self, index_set=None):
15631563
r"""
15641564
Return the highest weight element `u` and a list `[i_1,...,i_k]`
15651565
such that `self = f_{i_1} ... f_{i_k} u`, where `i_1,...,i_k` are
1566-
elements in `index_set`. By default the index set is assumed to be
1566+
elements in ``index_set``.
1567+
1568+
By default the index set is assumed to be
15671569
the full index set of self.
15681570
15691571
EXAMPLES::
@@ -1602,8 +1604,10 @@ def to_lowest_weight(self, index_set=None):
16021604
r"""
16031605
Return the lowest weight element `u` and a list `[i_1,...,i_k]`
16041606
such that `self = e_{i_1} ... e_{i_k} u`, where `i_1,...,i_k` are
1605-
elements in `index_set`. By default the index set is assumed to be
1606-
the full index set of self.
1607+
elements in ``index_set``.
1608+
1609+
By default the index set is assumed to be the full index
1610+
set of self.
16071611
16081612
EXAMPLES::
16091613
@@ -1642,7 +1646,7 @@ def to_lowest_weight(self, index_set=None):
16421646
def all_paths_to_highest_weight(self, index_set=None):
16431647
r"""
16441648
Iterate over all paths to the highest weight from ``self``
1645-
with respect to `index_set`.
1649+
with respect to ``index_set``.
16461650
16471651
INPUT:
16481652

src/sage/coding/cyclic_code.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
from sage.misc.cachefunc import cached_method
4848
from sage.rings.all import Zmod
4949

50+
5051
def find_generator_polynomial(code, check=True):
5152
r"""
5253
Returns a possible generator polynomial for ``code``.
@@ -334,7 +335,7 @@ def __init__(self, generator_pol=None, length=None, code=None, check=True,
334335
...
335336
ValueError: The code is not cyclic.
336337
337-
If the `primitive_root` does not lie in an extension of `field`,
338+
If the ``primitive_root`` does not lie in an extension of ``field``,
338339
or is not a primitive `n`-th root of unity, then
339340
an exception is raised::
340341
@@ -1321,7 +1322,7 @@ def decoding_radius(self):
13211322
return self._bch_decoder.decoding_radius()
13221323

13231324

1324-
####################### registration ###############################
1325+
# ###################### registration ##############################
13251326

13261327
CyclicCode._registered_encoders["Polynomial"] = CyclicCodePolynomialEncoder
13271328
CyclicCode._registered_encoders["Vector"] = CyclicCodeVectorEncoder

src/sage/crypto/block_cipher/present.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ def __getitem__(self, r):
838838
Computes the sub key for round ``r`` derived from initial master key.
839839
840840
The key schedule object has to have been initialised with the
841-
`master_key` argument.
841+
``master_key`` argument.
842842
843843
INPUT:
844844
@@ -860,7 +860,7 @@ def __getitem__(self, r):
860860
def __iter__(self):
861861
"""
862862
Iterate over the ``self._rounds + 1`` PRESENT round keys, derived from
863-
`master_key`
863+
``master_key``.
864864
865865
EXAMPLES::
866866

src/sage/dynamics/finite_dynamical_system_catalog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
dynamical systems.
66
These are accessible through
77
:mod:`sage.dynamics.finite_dynamical_system_catalog. <sage.dynamics.finite_dynamical_system_catalog>`
8-
or just through `finite_dynamical_systems.`
8+
or just through ``finite_dynamical_systems.``
99
(type either of these in Sage and hit ``tab`` for a list).
1010
1111
AUTHORS:

src/sage/graphs/weakly_chordal.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ cdef inline is_long_hole_free_process(g, short_digraph sd, bitset_t dense_graph,
5353
bint certificate,
5454
int a, int b, int c, int n):
5555
"""
56-
This method is part of method `is_long_hole_free`.
56+
This method is part of method ``is_long_hole_free``.
5757
5858
EXAMPLES::
5959
@@ -285,7 +285,7 @@ cdef inline is_long_antihole_free_process(g, short_digraph sd, bitset_t dense_gr
285285
bint certificate,
286286
int a, int b, int c, int n):
287287
"""
288-
This method is part of method `is_long_antihole_free`.
288+
This method is part of method ``is_long_antihole_free``.
289289
290290
EXAMPLES::
291291

src/sage/matrix/matrix_misc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ def prm_mul(p1, p2, mask_free, prec):
3939
4040
- `p1,p2` -- polynomials as dictionaries
4141
42-
- `mask_free` -- an integer mask that give the list of free variables
42+
- ``mask_free`` -- an integer mask that give the list of free variables
4343
(the `i`-th variable is free if the `i`-th bit of ``mask_free`` is `1`)
4444
45-
- `prec` -- if `prec` is not None, truncate the product at precision `prec`
45+
- ``prec`` -- if ``prec`` is not ``None``, truncate the product at precision ``prec``
4646
4747
EXAMPLES::
4848

src/sage/schemes/cyclic_covers/charpoly_frobenius.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
r"""
2-
32
Computation of the Frobenius polynomial using Newton's identities
4-
53
"""
6-
7-
84
# *****************************************************************************
95
# Copyright (C) 2018 Edgar Costa <[email protected]>
106
# Distributed under the terms of the GNU General Public License (GPL)
117
# https://www.gnu.org/licenses/
128
# *****************************************************************************
13-
149
from sage.rings.integer_ring import ZZ
1510
from sage.functions.log import log
1611

@@ -23,15 +18,15 @@ def charpoly_frobenius(frob_matrix, charpoly_prec, p, weight, a=1, known_factor=
2318
2419
- ``frob_matrix`` -- a matrix representing the Frobenius matrix up to some precision
2520
26-
- ``charpoly_prec`` -- a vector ai, such that, `frob_matrix.change_ring(ZZ).charpoly()[i]`
27-
will be correct mod `p^ai`, this can be easily deduced from the Hodge numbers and
28-
knowing the q-adic precision of ``frob_matrix``
21+
- ``charpoly_prec`` -- a vector ai, such that, ``frob_matrix.change_ring(ZZ).charpoly()[i]``
22+
will be correct mod `p^ai`, this can be easily deduced from the
23+
Hodge numbers and knowing the q-adic precision of ``frob_matrix``
2924
3025
- ``p`` -- prime `p`
3126
3227
- ``weight`` -- weight of the motive
3328
34-
- ``a`` -- `q = q^a`
29+
- ``a`` -- `p = q^a`
3530
3631
- ``known_factor`` -- the list of coefficients of the known factor
3732
@@ -195,14 +190,12 @@ def charpoly_frobenius(frob_matrix, charpoly_prec, p, weight, a=1, known_factor=
195190
sage: F+= F.base_ring()(0).add_bigoh(6)*ones_matrix(*F.dimensions())
196191
sage: charpoly_frobenius(F, [6, 5, 4, 4], 17, 2)
197192
[-4913, -221, 13, 1]
198-
199-
200193
"""
201194
assert known_factor[-1] == 1
202195
try:
203196
cp = frob_matrix.change_ring(ZZ).charpoly().list()
204197
except ValueError:
205-
# the given matrix wasn't integral
198+
# the given matrix was not integral
206199
cp = frob_matrix.charpoly().change_ring(ZZ).list()
207200
assert len(charpoly_prec) == len(cp) - (len(known_factor) - 1)
208201
assert cp[-1] == 1
@@ -216,7 +209,7 @@ def charpoly_frobenius(frob_matrix, charpoly_prec, p, weight, a=1, known_factor=
216209

217210
# figure out the sign
218211
# i.e., if it is a reciprocal or an antireciprocal polynomial
219-
if weight % 2 == 1:
212+
if weight % 2:
220213
# for odd weight the sign is always 1
221214
# it's the charpoly of a USp matrix
222215
# and charpoly of a symplectic matrix is reciprocal
@@ -227,7 +220,7 @@ def charpoly_frobenius(frob_matrix, charpoly_prec, p, weight, a=1, known_factor=
227220
raise NotImplementedError()
228221
# we compare ith coefficient and (degree - i)th coefficient to deduce the sign
229222
# note, if degree is even, the middle coefficient will not help us determine the sign
230-
for i in range((degree + 1)//2):
223+
for i in range((degree + 1) // 2):
231224
# Note: degree*weight is even
232225
p_power = p**min(
233226
charpoly_prec[i],
@@ -248,19 +241,21 @@ def charpoly_frobenius(frob_matrix, charpoly_prec, p, weight, a=1, known_factor=
248241
# note, this includes the middle coefficient if degree is even
249242
halfdegree = degree // 2 + 1
250243

251-
cp[0] = sign * p**((a * degree * weight) // 2) # Note: degree*weight is even
244+
cp[0] = sign * p**((a * degree * weight) // 2)
245+
# Note: degree*weight is even
246+
252247
# calculate the i-th power sum of the roots and correct cp along the way
253248
e = cp[-halfdegree:]
254249
e.reverse()
255250
for k in range(halfdegree):
256-
if k % 2 != 0:
251+
if k % 2:
257252
e[k] = -e[k] % mod[degree - k]
258253
# e[k] = cp[degree - k] if (k%2 ==0) else -cp[degree - k]
259254
if k > 0:
260255
# verify if p^charpoly_prec[degree - k] > 2*degree/k * q^(w*k/2)
261256
assert (
262-
log(k) / log(p) + charpoly_prec[degree - k]
263-
> log(2 * degree) / log(p) + a * 0.5 * weight * k
257+
log(k, p) + charpoly_prec[degree - k]
258+
> log(2 * degree, p) + a * 0.5 * weight * k
264259
), (
265260
"log(k)/log(p) + charpoly_prec[degree - k] <= log(2*degree)/log(p) + a*0.5*weight*k, k = %d"
266261
% k
@@ -271,7 +266,7 @@ def charpoly_frobenius(frob_matrix, charpoly_prec, p, weight, a=1, known_factor=
271266
if len(fix_e) < halfdegree:
272267
fix_e.extend([0] * (halfdegree - len(fix_e)))
273268
for i in range(halfdegree):
274-
if i % 2 != 0:
269+
if i % 2:
275270
fix_e[i] *= -1
276271

277272
# e[k] = \sum x_{i_1} x_{i_2} ... x_{i_k} # where x_* are eigenvalues
@@ -280,7 +275,9 @@ def charpoly_frobenius(frob_matrix, charpoly_prec, p, weight, a=1, known_factor=
280275
# s[k] = \sum x_i ^k for k>0
281276
s = [None] * (halfdegree)
282277
res = [None] * len(charpoly_prec)
283-
res[0] = sign * p**((a * degree * weight) // 2) # Note: degree*weight is even
278+
res[0] = sign * p**((a * degree * weight) // 2)
279+
# Note: degree*weight is even
280+
284281
res[-1] = 1
285282
e[1] -= fix_e[1]
286283
e[1] = e[1] % mod[degree - 1]
@@ -306,8 +303,9 @@ def charpoly_frobenius(frob_matrix, charpoly_prec, p, weight, a=1, known_factor=
306303
# (-1)^(k-1) s[k] - S = k*e[k]
307304
e[k] = (-S + (-1)**(k - 1) * s[k]) // k
308305
assert (-S + (-1)**(k - 1) * s[k]) % k == 0
309-
res[degree - k] = e[k] if k % 2 == 0 else -e[k]
306+
res[degree - k] = e[k] if not k % 2 else -e[k]
310307
# Note: degree*weight is even
308+
311309
res[k] = sign * res[degree - k] * p**((a * (degree - 2 * k) * weight) // 2)
312310
# fix e[k + 1]
313311
if k + 1 < halfdegree:

0 commit comments

Comments
 (0)