Skip to content

Commit

Permalink
Trac #34639: fix some W605 in pyx files in rings
Browse files Browse the repository at this point in the history
namely in polynomials/, number_fields/ and finite_rings/

URL: https://trac.sagemath.org/34639
Reported by: chapoton
Ticket author(s): Frédéric Chapoton
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Oct 11, 2022
2 parents c448d77 + f948791 commit 3384309
Show file tree
Hide file tree
Showing 20 changed files with 88 additions and 91 deletions.
4 changes: 2 additions & 2 deletions src/sage/rings/finite_rings/element_base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -983,9 +983,10 @@ cdef class FinitePolyExtElement(FiniteRingElement):

return self.pth_power(k=k)


cdef class Cache_base(SageObject):
cpdef FinitePolyExtElement fetch_int(self, number):
"""
r"""
Given an integer less than `p^n` with base `2`
representation `a_0 + a_1 \cdot 2 + \cdots + a_k 2^k`, this returns
`a_0 + a_1 x + \cdots + a_k x^k`, where `x` is the
Expand All @@ -998,4 +999,3 @@ cdef class Cache_base(SageObject):
a^33 + a + 1
"""
raise NotImplementedError("this must be implemented by subclasses")

2 changes: 1 addition & 1 deletion src/sage/rings/finite_rings/element_ntl_gf2e.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ cdef class Cache_ntl_gf2e(Cache_base):
raise ValueError("Cannot coerce element %s to this field." % e)

cpdef FiniteField_ntl_gf2eElement fetch_int(self, number):
"""
r"""
Given an integer less than `p^n` with base `2`
representation `a_0 + a_1 \cdot 2 + \cdots + a_k 2^k`, this returns
`a_0 + a_1 x + \cdots + a_k x^k`, where `x` is the
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/finite_rings/finite_field_base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ cdef class FiniteField(Field):
return self._modulus

def polynomial(self, name=None):
"""
r"""
Return the minimal polynomial of the generator of ``self`` over
the prime finite field.
Expand Down
32 changes: 14 additions & 18 deletions src/sage/rings/finite_rings/integer_mod.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ from sage.groups.generic import discrete_log

cdef Integer one_Z = Integer(1)


def Mod(n, m, parent=None):
"""
r"""
Return the equivalence class of `n` modulo `m` as
an element of `\ZZ/m\ZZ`.
Expand Down Expand Up @@ -1598,7 +1599,7 @@ cdef class IntegerMod_abstract(FiniteRingElement):
return [a for a in self.parent() if a**n == self]

def _balanced_abs(self):
"""
r"""
This function returns `x` or `-x`, whichever has a
positive representative in `-n/2 < x \leq n/2`.
Expand All @@ -1608,8 +1609,7 @@ cdef class IntegerMod_abstract(FiniteRingElement):
"""
if self.lift() > self.__modulus.sageInteger >> 1:
return -self
else:
return self
return self

def rational_reconstruction(self):
"""
Expand Down Expand Up @@ -1947,7 +1947,7 @@ cdef class IntegerMod_abstract(FiniteRingElement):


cdef class IntegerMod_gmp(IntegerMod_abstract):
"""
r"""
Elements of `\ZZ/n\ZZ` for n not small enough
to be operated on in word size.
Expand Down Expand Up @@ -2354,7 +2354,7 @@ cdef class IntegerMod_gmp(IntegerMod_abstract):

@coerce_binop
def gcd(self, IntegerMod_gmp other):
"""
r"""
Greatest common divisor
Returns the "smallest" generator in `\ZZ / N\ZZ` of the ideal
Expand Down Expand Up @@ -2387,7 +2387,7 @@ cdef class IntegerMod_gmp(IntegerMod_abstract):


cdef class IntegerMod_int(IntegerMod_abstract):
"""
r"""
Elements of `\ZZ/n\ZZ` for n small enough to
be operated on in 32 bits
Expand Down Expand Up @@ -3022,20 +3022,18 @@ cdef class IntegerMod_int(IntegerMod_abstract):
# Either it failed but extend was True, or the generic algorithm is better
return IntegerMod_abstract.sqrt(self, extend=extend, all=all)


def _balanced_abs(self):
"""
r"""
This function returns `x` or `-x`, whichever has a
positive representative in `-n/2 < x \leq n/2`.
"""
if self.ivalue > self.__modulus.int32 / 2:
return -self
else:
return self
return self

@coerce_binop
def gcd(self, IntegerMod_int other):
"""
r"""
Greatest common divisor
Returns the "smallest" generator in `\ZZ / N\ZZ` of the ideal
Expand Down Expand Up @@ -3213,7 +3211,7 @@ cdef int jacobi_int(int_fast32_t a, int_fast32_t m) except -2:
######################################################################

cdef class IntegerMod_int64(IntegerMod_abstract):
"""
r"""
Elements of `\ZZ/n\ZZ` for n small enough to
be operated on in 64 bits
Expand Down Expand Up @@ -3688,22 +3686,20 @@ cdef class IntegerMod_int64(IntegerMod_abstract):
sage: hash(a)
8943
"""

return hash(self.ivalue)

def _balanced_abs(self):
"""
r"""
This function returns `x` or `-x`, whichever has a
positive representative in `-n/2 < x \leq n/2`.
"""
if self.ivalue > self.__modulus.int64 / 2:
return -self
else:
return self
return self

@coerce_binop
def gcd(self, IntegerMod_int64 other):
"""
r"""
Greatest common divisor
Returns the "smallest" generator in `\ZZ / N\ZZ` of the ideal
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/finite_rings/residue_field.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
r"""
Finite residue fields
We can take the residue field of maximal ideals in the ring of integers
Expand Down Expand Up @@ -1846,7 +1846,7 @@ class ResidueFiniteField_ntl_gf2e(ResidueField_generic, FiniteField_ntl_gf2e):
"""
# we change the order for consistency with FiniteField_ntl_gf2e's __cinit__
def __init__(self, q, name, modulus, repr, p, to_vs, to_order, PB):
"""
r"""
INPUT:
- ``p`` -- the prime ideal defining this residue field
Expand Down
6 changes: 3 additions & 3 deletions src/sage/rings/number_field/number_field_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ cdef class NumberFieldElement(FieldElement):
return codomain(f(im_gens[0]))

def _latex_(self):
"""
r"""
Returns the latex representation for this element.
EXAMPLES::
Expand Down Expand Up @@ -3988,8 +3988,8 @@ cdef class NumberFieldElement(FieldElement):
return ht

def global_height_non_arch(self, prec=None):
"""
Returns the total non-archimedean component of the height of self.
r"""
Return the total non-archimedean component of the height of ``self``.
INPUT:
Expand Down
18 changes: 9 additions & 9 deletions src/sage/rings/number_field/number_field_element_quadratic.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# distutils: library_dirs = NTL_LIBDIR
# distutils: extra_link_args = NTL_LIBEXTRA
# distutils: language = c++
"""
r"""
Optimized Quadratic Number Field Elements
This file defines a Cython class ``NumberFieldElement_quadratic`` to speed up
Expand All @@ -23,16 +23,15 @@ AUTHORS:
The ``_new()`` method should be overridden in this class to copy the ``D``
and ``standard_embedding`` attributes
"""

#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2007 Robert Bradshaw <robertwb@math.washington.edu>
#
# 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/
#*****************************************************************************
# https://www.gnu.org/licenses/
# ****************************************************************************

include "sage/libs/ntl/decl.pxi"
from cpython.object cimport Py_EQ, Py_NE, Py_LE, Py_GE, Py_LT, Py_GT
Expand Down Expand Up @@ -1634,7 +1633,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute):
#################################################################################

def __hash__(self):
"""
r"""
Return hash of this number field element.
For elements in `\ZZ` or `\QQ` the hash coincides with the one in the
Expand Down Expand Up @@ -2019,10 +2018,11 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute):
mpq_canonicalize(res.value)
return res


def norm(self, K=None):
"""
Return the norm of self. If the second argument is None, this is the
r"""
Return the norm of ``self``.
If the second argument is ``None``, this is the
norm down to `\QQ`. Otherwise, return the norm down to K (which had
better be either `\QQ` or this number field).
Expand Down
11 changes: 5 additions & 6 deletions src/sage/rings/number_field/number_field_morphisms.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ Embeddings into ambient fields
This module provides classes to handle embeddings of number fields into ambient
fields (generally `\RR` or `\CC`).
"""

#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2008 Robert Bradshaw <robertwb@math.washington.edu>
#
# Distributed under the terms of the GNU General Public License (GPL)
Expand All @@ -17,8 +16,8 @@ fields (generally `\RR` or `\CC`).
#
# The full text of the GPL is available at:
#
# http://www.gnu.org/licenses/
#*****************************************************************************
# https://www.gnu.org/licenses/
# ****************************************************************************

import sage.rings.complex_double

Expand Down Expand Up @@ -345,7 +344,7 @@ cpdef matching_root(poly, target, ambient_field=None, margin=1, max_prec=None):
target best approximates as compared in ambient_field.
If the parent of target is exact, the equality is required, otherwise
find closest root (with respect to the \code{abs} function) in the
find closest root (with respect to the ``abs`` function) in the
ambient field to the target, and return the root of poly (if any) that
approximates it best.
Expand Down Expand Up @@ -405,7 +404,7 @@ cpdef matching_root(poly, target, ambient_field=None, margin=1, max_prec=None):
cpdef closest(target, values, margin=1):
"""
This is a utility function that returns the item in values closest to
target (with respect to the \code{abs} function). If margin is greater
target (with respect to the ``abs`` function). If margin is greater
than 1, and x and y are the first and second closest elements to target,
then only return x if x is margin times closer to target than y, i.e.
margin * abs(target-x) < abs(target-y).
Expand Down
5 changes: 3 additions & 2 deletions src/sage/rings/polynomial/laurent_polynomial.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,11 @@ cdef class LaurentPolynomial(CommutativeAlgebraElement):
R = R.change_ring(new_base_ring)
elif isinstance(f, Map):
R = R.change_ring(f.codomain())
return R(dict([(k,f(v)) for (k,v) in self.dict().items()]))
return R(dict([(k, f(v)) for (k, v) in self.dict().items()]))


cdef class LaurentPolynomial_univariate(LaurentPolynomial):
"""
r"""
A univariate Laurent polynomial in the form of `t^n \cdot f`
where `f` is a polynomial in `t`.
Expand Down
15 changes: 8 additions & 7 deletions src/sage/rings/polynomial/multi_polynomial.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ cdef class MPolynomial(CommutativeRingElement):
var = R.variable_name()
if var in self._parent.variable_names():
return R(self.polynomial(self._parent(var)))
else:
return R([self])
return R([self])

def coefficients(self):
"""
r"""
Return the nonzero coefficients of this polynomial in a list.
The returned list is decreasingly ordered by the term ordering
of ``self.parent()``, i.e. the list of coefficients matches the list
of monomials returned by
Expand Down Expand Up @@ -1315,11 +1315,12 @@ cdef class MPolynomial(CommutativeRingElement):
return R(dict([(k,f(v)) for (k,v) in self.dict().items()]))

def _norm_over_nonprime_finite_field(self):
"""
r"""
Given a multivariate polynomial over a nonprime finite field
`\GF{p**e}`, compute the norm of the polynomial down to `\GF{p}`, which
is the product of the conjugates by the Frobenius action on
coefficients, where Frobenius acts by p-th power.
`\GF{p^e}`, compute the norm of the polynomial down to `\GF{p}`.
This is the product of the conjugates by the Frobenius action
on coefficients, where Frobenius acts by p-th power.
This is (currently) an internal function used in factoring over finite
fields.
Expand Down
14 changes: 6 additions & 8 deletions src/sage/rings/polynomial/multi_polynomial_libsingular.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1984,7 +1984,6 @@ cdef class MPolynomial_libsingular(MPolynomial):
sage: R.<x,y> = QQ[]
sage: x._new_constant_poly(2/1,R)
2
"""
if not x:
return new_MP(P, NULL)
Expand All @@ -1993,7 +1992,7 @@ cdef class MPolynomial_libsingular(MPolynomial):
return new_MP(P, _p)

def __call__(self, *x, **kwds):
"""
r"""
Evaluate this multi-variate polynomial at ``x``, where ``x``
is either the tuple of values to substitute in, or one can use
functional notation ``f(a_0,a_1,a_2, \ldots)`` to evaluate
Expand Down Expand Up @@ -2261,7 +2260,7 @@ cdef class MPolynomial_libsingular(MPolynomial):
return new_MP((<MPolynomial_libsingular>left)._parent,_p)

cpdef _div_(left, right_ringelement):
"""
r"""
Divide left by right
EXAMPLES::
Expand Down Expand Up @@ -4576,7 +4575,7 @@ cdef class MPolynomial_libsingular(MPolynomial):
return Sequence(l, check=False, immutable=True)

def reduce(self,I):
"""
r"""
Return a remainder of this polynomial modulo the
polynomials in ``I``.
Expand Down Expand Up @@ -5288,15 +5287,14 @@ cdef class MPolynomial_libsingular(MPolynomial):
return new_MP(self._parent,p)

def integral(self, MPolynomial_libsingular var):
"""
Integrates this polynomial with respect to the provided
variable.
r"""
Integrate this polynomial with respect to the provided variable.
One requires that `\QQ` is contained in the ring.
INPUT:
- ``variable`` - the integral is taken with respect to variable
- ``variable`` -- the integral is taken with respect to variable
EXAMPLES::
Expand Down
8 changes: 4 additions & 4 deletions src/sage/rings/polynomial/ore_polynomial_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1705,11 +1705,11 @@ cdef class OrePolynomial(AlgebraElement):
var = "|%s"%name
else:
var = ""
s += "%s %s"%(x,var)
s += "%s %s" % (x, var)
s = s.replace(" + -", " - ")
s = re.sub(" 1(\.0+)? \|"," ", s)
s = re.sub(" -1(\.0+)? \|", " -", s)
s = s.replace("|","")
s = re.sub(r" 1(\.0+)? \|", " ", s)
s = re.sub(r" -1(\.0+)? \|", " -", s)
s = s.replace("|", "")
if s == " ":
return "0"
return s[1:].lstrip().rstrip()
Expand Down
Loading

0 comments on commit 3384309

Please sign in to comment.