From 2a6ceb47caf3adead7ee6953ae067e60b0cd2d54 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:20:57 +0800 Subject: [PATCH 01/44] rename __cached_methods -> _cached_methods --- src/sage/combinat/integer_lists/base.pxd | 2 +- src/sage/cpython/getattr.pyx | 2 +- .../combinatorial_polyhedron/base.pxd | 2 +- src/sage/misc/cachefunc.pyx | 50 +++++++++---------- src/sage/misc/lazy_attribute.pyx | 6 +-- src/sage/rings/morphism.pxd | 2 +- .../rings/padics/pow_computer_relative.pxd | 2 +- .../rings/polynomial/polynomial_element.pxd | 2 +- .../schemes/elliptic_curves/mod_sym_num.pyx | 20 ++++---- src/sage/structure/category_object.pxd | 2 +- src/sage/structure/category_object.pyx | 6 +-- src/sage/structure/element.pxd | 2 +- src/sage/structure/element.pyx | 6 +-- 13 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/sage/combinat/integer_lists/base.pxd b/src/sage/combinat/integer_lists/base.pxd index ecb5550a9cf..3d373a64fe0 100644 --- a/src/sage/combinat/integer_lists/base.pxd +++ b/src/sage/combinat/integer_lists/base.pxd @@ -12,4 +12,4 @@ cdef class IntegerListsBackend(): cdef readonly min_part, max_part cdef readonly min_slope, max_slope cdef readonly Envelope floor, ceiling - cdef public dict __cached_methods # Support cached_method + cdef public dict _cached_methods # Support cached_method diff --git a/src/sage/cpython/getattr.pyx b/src/sage/cpython/getattr.pyx index 525ea5aa934..5f92d148c83 100644 --- a/src/sage/cpython/getattr.pyx +++ b/src/sage/cpython/getattr.pyx @@ -271,7 +271,7 @@ cpdef getattr_from_other_class(self, cls, name): Caveat: lazy attributes work with extension types only if they allow attribute assignment or have a public attribute - ``__cached_methods`` of type ````. This condition + ``_cached_methods`` of type ````. This condition is satisfied, e.g., by any class that is derived from :class:`Parent`:: diff --git a/src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pxd b/src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pxd index bdd49225ff2..030c9defa45 100644 --- a/src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pxd +++ b/src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pxd @@ -8,7 +8,7 @@ from .polyhedron_face_lattice cimport PolyhedronFaceLattice @cython.final cdef class CombinatorialPolyhedron(SageObject): - cdef public dict __cached_methods + cdef public dict _cached_methods # Do not assume any of those attributes to be initialized, use the corresponding methods instead. cdef tuple _Vrep # the names of VRep, if they exist diff --git a/src/sage/misc/cachefunc.pyx b/src/sage/misc/cachefunc.pyx index dac4c684f47..c11ed7a8df8 100644 --- a/src/sage/misc/cachefunc.pyx +++ b/src/sage/misc/cachefunc.pyx @@ -59,7 +59,7 @@ be used:: We can proceed similarly for cached methods of Cython classes, provided that they allow attribute assignment or have a public -attribute ``__cached_methods`` of type ````. Since +attribute ``_cached_methods`` of type ````. Since :trac:`11115`, this is the case for all classes inheriting from :class:`~sage.structure.parent.Parent`. See below for a more explicit example. By :trac:`12951`, cached methods of extension classes can @@ -294,13 +294,13 @@ ought to be chosen. A typical example is By :trac:`12951`, the cached_method decorator is also supported on non-c(p)def methods of extension classes, as long as they either support attribute assignment -or have a public attribute of type ```` called ``__cached_methods``. The +or have a public attribute of type ```` called ``_cached_methods``. The latter is easy:: sage: cython_code = [ ....: "from sage.misc.cachefunc import cached_method", ....: "cdef class MyClass:", - ....: " cdef public dict __cached_methods", + ....: " cdef public dict _cached_methods", ....: " @cached_method", ....: " def f(self, a,b):", ....: " return a*b"] @@ -1996,7 +1996,7 @@ cdef class CachedMethodCaller(CachedFunction): This getter attempts to assign a bound method as an attribute to the given instance. If this is not possible (for example, for some extension classes), - it is attempted to find an attribute ``__cached_methods``, + it is attempted to find an attribute ``_cached_methods``, and store/retrieve the bound method there. In that way, cached methods can be implemented for extension classes deriving from :class:`~sage.structure.parent.Parent` @@ -2062,7 +2062,7 @@ cdef class CachedMethodCaller(CachedFunction): """ # This is for Parents or Elements that do not allow attribute assignment try: - return (inst.__cached_methods)[self._cachedmethod._cachedfunc.__name__] + return (inst._cached_methods)[self._cachedmethod._cachedfunc.__name__] except (AttributeError, TypeError, KeyError): pass @@ -2077,10 +2077,10 @@ cdef class CachedMethodCaller(CachedFunction): except AttributeError: pass try: - if inst.__cached_methods is None: - inst.__cached_methods = {self._cachedmethod._cachedfunc.__name__ : Caller} + if inst._cached_methods is None: + inst._cached_methods = {self._cachedmethod._cachedfunc.__name__ : Caller} else: - (inst.__cached_methods)[self._cachedmethod._cachedfunc.__name__] = Caller + (inst._cached_methods)[self._cachedmethod._cachedfunc.__name__] = Caller except AttributeError: pass return Caller @@ -2398,7 +2398,7 @@ cdef class CachedMethodCallerNoArgs(CachedFunction): This getter attempts to assign a bound method as an attribute to the given instance. If this is not possible (for example, for some extension classes), - it is attempted to find an attribute ``__cached_methods``, + it is attempted to find an attribute ``_cached_methods``, and store/retrieve the bound method there. In that way, cached methods can be implemented for extension classes deriving from :class:`~sage.structure.parent.Parent` @@ -2449,7 +2449,7 @@ cdef class CachedMethodCallerNoArgs(CachedFunction): """ # This is for Parents or Elements that do not allow attribute assignment try: - return (inst.__cached_methods)[self.__name__] + return (inst._cached_methods)[self.__name__] except (AttributeError, TypeError, KeyError): pass Caller = CachedMethodCallerNoArgs(inst, self.f, name=self.__name__, do_pickle=self.do_pickle) @@ -2459,10 +2459,10 @@ cdef class CachedMethodCallerNoArgs(CachedFunction): except AttributeError: pass try: - if inst.__cached_methods is None: - inst.__cached_methods = {self.__name__ : Caller} + if inst._cached_methods is None: + inst._cached_methods = {self.__name__ : Caller} else: - (inst.__cached_methods)[self.__name__] = Caller + (inst._cached_methods)[self.__name__] = Caller except AttributeError: pass return Caller @@ -2805,7 +2805,7 @@ cdef class CachedMethod(): except AttributeError: name = self.__name__ try: - return (inst.__cached_methods)[name] + return (inst._cached_methods)[name] except (AttributeError, TypeError, KeyError): pass # Apparently we need to construct the caller. @@ -2841,10 +2841,10 @@ cdef class CachedMethod(): except AttributeError: pass try: - if inst.__cached_methods is None: - inst.__cached_methods = {name : Caller} + if inst._cached_methods is None: + inst._cached_methods = {name : Caller} else: - (inst.__cached_methods)[name] = Caller + (inst._cached_methods)[name] = Caller except AttributeError: pass return Caller @@ -2942,12 +2942,12 @@ cdef class CachedSpecialMethod(CachedMethod): D = inst.__dict__ except (TypeError, AttributeError): try: - D = inst.__cached_methods + D = inst._cached_methods except (TypeError, AttributeError): - raise TypeError("For a cached special method, either attribute assignment or a public '__cached_methods' attribute of type is needed") + raise TypeError("For a cached special method, either attribute assignment or a public '_cached_methods' attribute of type is needed") if D is None: - # This can only happen in the case of __cached_methods - D = inst.__cached_methods = {} + # This can only happen in the case of _cached_methods + D = inst._cached_methods = {} else: try: return D[name] @@ -3275,13 +3275,13 @@ cdef class CachedInParentMethod(CachedMethod): return P.__dict__.setdefault(self._cache_name, default) except AttributeError: pass - if not hasattr(P,'__cached_methods'): + if not hasattr(P,'_cached_methods'): raise TypeError("The parent of this element does not allow attribute assignment\n" + " and does not descend from the Parent base class.\n" + " Cannot use CachedInParentMethod.") - if P.__cached_methods is None: - P.__cached_methods = {} - return (P.__cached_methods).setdefault(self._cache_name, default) + if P._cached_methods is None: + P._cached_methods = {} + return (P._cached_methods).setdefault(self._cache_name, default) def __get__(self, inst, cls): """ diff --git a/src/sage/misc/lazy_attribute.pyx b/src/sage/misc/lazy_attribute.pyx index 4f0814f5cc2..e0d6dea9967 100644 --- a/src/sage/misc/lazy_attribute.pyx +++ b/src/sage/misc/lazy_attribute.pyx @@ -111,12 +111,12 @@ cdef class _lazy_attribute(): if a is None: # when doing cls.x for cls a class and x a lazy attribute return self try: - # __cached_methods is supposed to be a public Cython attribute. + # _cached_methods is supposed to be a public Cython attribute. # Apparently, these are *not* subject to name mangling. - CM = getattr(a, '__cached_methods') + CM = getattr(a, '_cached_methods') if CM is None: CM = {} - setattr(a, '__cached_methods', CM) + setattr(a, '_cached_methods', CM) except AttributeError as msg: CM = None if CM is not None: diff --git a/src/sage/rings/morphism.pxd b/src/sage/rings/morphism.pxd index ea6089f29b4..4b8e8d052df 100644 --- a/src/sage/rings/morphism.pxd +++ b/src/sage/rings/morphism.pxd @@ -14,7 +14,7 @@ cdef class RingMap_lift(RingMap): cdef class RingHomomorphism(RingMap): cdef Morphism _lift - cdef public dict __cached_methods + cdef public dict _cached_methods cdef class RingHomomorphism_im_gens(RingHomomorphism): cdef _im_gens diff --git a/src/sage/rings/padics/pow_computer_relative.pxd b/src/sage/rings/padics/pow_computer_relative.pxd index fc7d5b21f42..e0e5aa5600e 100644 --- a/src/sage/rings/padics/pow_computer_relative.pxd +++ b/src/sage/rings/padics/pow_computer_relative.pxd @@ -18,7 +18,7 @@ cdef class PowComputer_relative(PowComputer_class): cdef Polynomial_generic_dense shift_rem cdef Polynomial_generic_dense aliasing # allow cached methods - cdef public dict __cached_methods + cdef public dict _cached_methods cdef unsigned long capdiv(self, unsigned long n) diff --git a/src/sage/rings/polynomial/polynomial_element.pxd b/src/sage/rings/polynomial/polynomial_element.pxd index 083f506b222..e6d935d28fe 100644 --- a/src/sage/rings/polynomial/polynomial_element.pxd +++ b/src/sage/rings/polynomial/polynomial_element.pxd @@ -45,7 +45,7 @@ cdef class Polynomial(CommutativePolynomial): cpdef _mul_(self, right) cpdef _floordiv_(self, right) - cdef public dict __cached_methods + cdef public dict _cached_methods cdef class Polynomial_generic_dense(Polynomial): cdef Polynomial_generic_dense _new_c(self, list coeffs, Parent P) diff --git a/src/sage/schemes/elliptic_curves/mod_sym_num.pyx b/src/sage/schemes/elliptic_curves/mod_sym_num.pyx index 65742f28d72..296a6b5d075 100644 --- a/src/sage/schemes/elliptic_curves/mod_sym_num.pyx +++ b/src/sage/schemes/elliptic_curves/mod_sym_num.pyx @@ -730,7 +730,7 @@ cdef class ModularSymbolNumerical: double _eps_plus, _eps_minus, _eps_unitary_plus, _eps_unitary_minus public RealNumber _om1, _om2 object _E, _epsQs, _Mt, _Epari - public dict __cached_methods + public dict _cached_methods Rational _twist_q Integer _D int _global_sign @@ -785,7 +785,7 @@ cdef class ModularSymbolNumerical: self._set_epsQs() self._initialise_an_coefficients() self._set_den_bounds() - self.__cached_methods = {} + self._cached_methods = {} # self.nc_sums = Integer(0) # self.nc_direct = Integer(0) @@ -1357,7 +1357,7 @@ cdef class ModularSymbolNumerical: sage: M(0) 1/5 """ - cadi = self.__cached_methods + cadi = self._cached_methods for me in cadi: cadi[me].clear_cache() @@ -1833,7 +1833,7 @@ cdef class ModularSymbolNumerical: # if called with a previous (m,z,eps) but a larger eps, # return the cached value - cac = self.__cached_methods['_kappa'].cache + cac = self._cached_methods['_kappa'].cache for ke in cac: mm, zz, eeps = ke[0] if mm == m and zz == z: @@ -2746,16 +2746,16 @@ cdef class ModularSymbolNumerical: sage: ms = ModularSymbolNumerical(E) sage: ms.manin_symbol(4,17) 1 - sage: ms.__cached_methods["_manin_symbol_with_cache"].cache # random + sage: ms._cached_methods["_manin_symbol_with_cache"].cache # random {((1, 5, 1), ()): 1, ((1, 15, 1), ()): -1, ((1, 22, 1), ()): -1, ((1, 32, 1), ()): 1} - sage: ms.__cached_methods["_manin_symbol_with_cache"].cache[(1,15,1),()] + sage: ms._cached_methods["_manin_symbol_with_cache"].cache[(1,15,1),()] -1 sage: ms.manin_symbol(4+17,-4) 0 - sage: ms.__cached_methods["_manin_symbol_with_cache"].cache # random + sage: ms._cached_methods["_manin_symbol_with_cache"].cache # random {((1, 4, 1), ()): 0, ((1, 5, 1), ()): 1, ((1, 8, 1), ()): 1, @@ -2768,7 +2768,7 @@ cdef class ModularSymbolNumerical: ((1, 29, 1), ()): 1, ((1, 32, 1), ()): 1, ((1, 33, 1), ()): 0} - sage: ms.__cached_methods["_manin_symbol_with_cache"].cache[ (1,23,1), () ] + sage: ms._cached_methods["_manin_symbol_with_cache"].cache[ (1,23,1), () ] -1 """ cdef: @@ -2903,7 +2903,7 @@ cdef class ModularSymbolNumerical: # "(%s :%s)"%(un, vn), level=3) # is it already in the cache ? - c = self.__cached_methods + c = self._cached_methods if "_manin_symbol_with_cache" in c: c = c["_manin_symbol_with_cache"] if c.is_in_cache(un,vn,sign): @@ -2919,7 +2919,7 @@ cdef class ModularSymbolNumerical: # we get for free additional values of Manin # symbols that we cache, too. # This sets 6 values in average - c = self.__cached_methods["_manin_symbol_with_cache"] + c = self._cached_methods["_manin_symbol_with_cache"] # (-v:u) = - (u:v) oi = proj_normalise(self._N_E, -v, u, &un, &vn) diff --git a/src/sage/structure/category_object.pxd b/src/sage/structure/category_object.pxd index ff3088ae9b6..83d3d4967d4 100644 --- a/src/sage/structure/category_object.pxd +++ b/src/sage/structure/category_object.pxd @@ -13,7 +13,7 @@ from sage.structure.sage_object cimport SageObject cpdef check_default_category(default_category, category) cdef class CategoryObject(SageObject): - cdef public dict __cached_methods + cdef public dict _cached_methods cdef _category cdef public _base cdef public _names diff --git a/src/sage/structure/category_object.pyx b/src/sage/structure/category_object.pyx index 784a09daf4c..7f4b9eb6fde 100644 --- a/src/sage/structure/category_object.pyx +++ b/src/sage/structure/category_object.pyx @@ -112,7 +112,7 @@ cdef class CategoryObject(SageObject): self._init_category_(category) def __cinit__(self): - self.__cached_methods = {} + self._cached_methods = {} self._hash_value = -1 def _init_category_(self, category): @@ -839,7 +839,7 @@ cdef class CategoryObject(SageObject): # Lookup a method or attribute from the category abstract classes. # See __getattr__ above for documentation. try: - return self.__cached_methods[name] + return self._cached_methods[name] except KeyError: if self._category is None: # Usually, this will just raise AttributeError in @@ -849,7 +849,7 @@ cdef class CategoryObject(SageObject): cls = self._category.parent_class attr = getattr_from_other_class(self, cls, name) - self.__cached_methods[name] = attr + self._cached_methods[name] = attr return attr def __dir__(self): diff --git a/src/sage/structure/element.pxd b/src/sage/structure/element.pxd index 4403ddd685a..984975dddfe 100644 --- a/src/sage/structure/element.pxd +++ b/src/sage/structure/element.pxd @@ -176,7 +176,7 @@ cdef class Element(SageObject): cdef class ElementWithCachedMethod(Element): - cdef public dict __cached_methods + cdef public dict _cached_methods cdef class ModuleElement(Element) # forward declaration diff --git a/src/sage/structure/element.pyx b/src/sage/structure/element.pyx index 70deeeeb8bd..172fc8b7759 100644 --- a/src/sage/structure/element.pyx +++ b/src/sage/structure/element.pyx @@ -2345,18 +2345,18 @@ cdef class ElementWithCachedMethod(Element): True """ try: - return self.__cached_methods[name] + return self._cached_methods[name] except KeyError: attr = getattr_from_other_class(self, self._parent.category().element_class, name) - self.__cached_methods[name] = attr + self._cached_methods[name] = attr return attr except TypeError: attr = getattr_from_other_class(self, self._parent.category().element_class, name) - self.__cached_methods = {name : attr} + self._cached_methods = {name : attr} return attr From 749f11c07eac13437afe0dca2bd4c1b7da0201c6 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:27:05 +0800 Subject: [PATCH 02/44] rename __init_fun -> _init_fun --- src/sage/libs/lcalc/lcalc_Lfunction.pxd | 2 +- src/sage/libs/lcalc/lcalc_Lfunction.pyx | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/sage/libs/lcalc/lcalc_Lfunction.pxd b/src/sage/libs/lcalc/lcalc_Lfunction.pxd index 5edf0844f3e..cc8d0fd2776 100644 --- a/src/sage/libs/lcalc/lcalc_Lfunction.pxd +++ b/src/sage/libs/lcalc/lcalc_Lfunction.pxd @@ -104,7 +104,7 @@ ctypedef double Double cdef class Lfunction: cdef void *thisptr - cdef void __init_fun(self, char *NAME, int what_type, dirichlet_coeff, long long Period, double q, c_Complex w, int A, double *g, c_Complex *l, int n_poles, c_Complex *p, c_Complex *r) + cdef void _init_fun(self, char *NAME, int what_type, dirichlet_coeff, long long Period, double q, c_Complex w, int A, double *g, c_Complex *l, int n_poles, c_Complex *p, c_Complex *r) cdef c_Complex __value(self,c_Complex s,int derivative) cdef c_Complex __hardy_z_function(self,c_Complex s) cdef int __compute_rank(self) diff --git a/src/sage/libs/lcalc/lcalc_Lfunction.pyx b/src/sage/libs/lcalc/lcalc_Lfunction.pyx index 6e9005c502b..c7eafd70837 100644 --- a/src/sage/libs/lcalc/lcalc_Lfunction.pyx +++ b/src/sage/libs/lcalc/lcalc_Lfunction.pyx @@ -99,7 +99,7 @@ cdef class Lfunction: tmpc=CCC(residue[i]) r[i+1] = new_Complex(mpfr_get_d(tmpc.__re, MPFR_RNDN), mpfr_get_d(tmpc.__im, MPFR_RNDN)) - self.__init_fun(NAME, what_type, dirichlet_coefficient, Period, q, w, A, g, l, n_poles, p, r) + self._init_fun(NAME, what_type, dirichlet_coefficient, Period, q, w, A, g, l, n_poles, p, r) if name: name += ': ' @@ -408,7 +408,7 @@ cdef class Lfunction: return returnvalue # Needs to be overriden - cdef void __init_fun(self, char *NAME, int what_type, dirichlet_coeff, long long Period, double q, c_Complex w, int A, double *g, c_Complex *l, int n_poles, c_Complex *p, c_Complex *r): + cdef void _init_fun(self, char *NAME, int what_type, dirichlet_coeff, long long Period, double q, c_Complex w, int A, double *g, c_Complex *l, int n_poles, c_Complex *p, c_Complex *r): raise NotImplementedError cdef c_Complex __value(self,c_Complex s,int derivative): @@ -497,7 +497,7 @@ cdef class Lfunction_I(Lfunction): self._repr += " with integer Dirichlet coefficients" # override - cdef void __init_fun(self, char *NAME, int what_type, dirichlet_coeff, long long Period, double q, c_Complex w, int A, double *g, c_Complex *l, int n_poles, c_Complex *p, c_Complex *r): + cdef void _init_fun(self, char *NAME, int what_type, dirichlet_coeff, long long Period, double q, c_Complex w, int A, double *g, c_Complex *l, int n_poles, c_Complex *p, c_Complex *r): cdef int N = len(dirichlet_coeff) cdef Integer tmpi cdef int * coeffs = new_ints(N+1) #lcalc ignores 0the coefficient @@ -633,7 +633,7 @@ cdef class Lfunction_D(Lfunction): self._repr += " with real Dirichlet coefficients" # override - cdef void __init_fun(self, char *NAME, int what_type, dirichlet_coeff, long long Period, double q, c_Complex w, int A, double *g, c_Complex *l, int n_poles, c_Complex *p, c_Complex *r): + cdef void _init_fun(self, char *NAME, int what_type, dirichlet_coeff, long long Period, double q, c_Complex w, int A, double *g, c_Complex *l, int n_poles, c_Complex *p, c_Complex *r): cdef int i cdef RealNumber tmpr cdef int N = len(dirichlet_coeff) @@ -773,7 +773,7 @@ cdef class Lfunction_C: self._repr += " with complex Dirichlet coefficients" # override - cdef void __init_fun(self, char *NAME, int what_type, dirichlet_coeff, long long Period, double q, c_Complex w, int A, double *g, c_Complex *l, int n_poles, c_Complex *p, c_Complex *r): + cdef void _init_fun(self, char *NAME, int what_type, dirichlet_coeff, long long Period, double q, c_Complex w, int A, double *g, c_Complex *l, int n_poles, c_Complex *p, c_Complex *r): cdef int i cdef int N = len(dirichlet_coeff) cdef ComplexNumber tmpc From 06961a97ec718cf748493b5837fb1e29463cdc31 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:27:18 +0800 Subject: [PATCH 03/44] rename __value -> _value --- src/sage/libs/lcalc/lcalc_Lfunction.pxd | 2 +- src/sage/libs/lcalc/lcalc_Lfunction.pyx | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sage/libs/lcalc/lcalc_Lfunction.pxd b/src/sage/libs/lcalc/lcalc_Lfunction.pxd index cc8d0fd2776..42b8dac62d3 100644 --- a/src/sage/libs/lcalc/lcalc_Lfunction.pxd +++ b/src/sage/libs/lcalc/lcalc_Lfunction.pxd @@ -105,7 +105,7 @@ ctypedef double Double cdef class Lfunction: cdef void *thisptr cdef void _init_fun(self, char *NAME, int what_type, dirichlet_coeff, long long Period, double q, c_Complex w, int A, double *g, c_Complex *l, int n_poles, c_Complex *p, c_Complex *r) - cdef c_Complex __value(self,c_Complex s,int derivative) + cdef c_Complex _value(self,c_Complex s,int derivative) cdef c_Complex __hardy_z_function(self,c_Complex s) cdef int __compute_rank(self) #strange bug, replacing Double with double gives me a compile error diff --git a/src/sage/libs/lcalc/lcalc_Lfunction.pyx b/src/sage/libs/lcalc/lcalc_Lfunction.pyx index c7eafd70837..976aa891f7d 100644 --- a/src/sage/libs/lcalc/lcalc_Lfunction.pyx +++ b/src/sage/libs/lcalc/lcalc_Lfunction.pyx @@ -180,7 +180,7 @@ cdef class Lfunction: """ cdef ComplexNumber complexified_s = CCC(s) cdef c_Complex z = new_Complex(mpfr_get_d(complexified_s.__re, MPFR_RNDN), mpfr_get_d(complexified_s.__im, MPFR_RNDN)) - cdef c_Complex result = self.__value(z, derivative) + cdef c_Complex result = self._value(z, derivative) return CCC(result.real(),result.imag()) def hardy_z_function(self, s): @@ -411,7 +411,7 @@ cdef class Lfunction: cdef void _init_fun(self, char *NAME, int what_type, dirichlet_coeff, long long Period, double q, c_Complex w, int A, double *g, c_Complex *l, int n_poles, c_Complex *p, c_Complex *r): raise NotImplementedError - cdef c_Complex __value(self,c_Complex s,int derivative): + cdef c_Complex _value(self,c_Complex s,int derivative): raise NotImplementedError cdef c_Complex __hardy_z_function(self,c_Complex s): @@ -507,7 +507,7 @@ cdef class Lfunction_I(Lfunction): self.thisptr=new_c_Lfunction_I(NAME, what_type, N, coeffs, Period, q, w, A, g, l, n_poles, p, r) del_ints(coeffs) - cdef inline c_Complex __value(self,c_Complex s,int derivative): + cdef inline c_Complex _value(self,c_Complex s,int derivative): return ((self.thisptr)).value(s, derivative, "pure") cdef inline c_Complex __hardy_z_function(self,c_Complex s): @@ -644,7 +644,7 @@ cdef class Lfunction_D(Lfunction): self.thisptr=new_c_Lfunction_D(NAME, what_type, N, coeffs, Period, q, w, A, g, l, n_poles, p, r) del_doubles(coeffs) - cdef inline c_Complex __value(self,c_Complex s,int derivative): + cdef inline c_Complex _value(self,c_Complex s,int derivative): return ((self.thisptr)).value(s, derivative, "pure") @@ -788,7 +788,7 @@ cdef class Lfunction_C: del_Complexes(coeffs) - cdef inline c_Complex __value(self,c_Complex s,int derivative): + cdef inline c_Complex _value(self,c_Complex s,int derivative): return ((self.thisptr)).value(s, derivative, "pure") @@ -873,7 +873,7 @@ cdef class Lfunction_Zeta(Lfunction): self.thisptr = new_c_Lfunction_Zeta() self._repr = "The Riemann zeta function" - cdef inline c_Complex __value(self,c_Complex s,int derivative): + cdef inline c_Complex _value(self,c_Complex s,int derivative): return ((self.thisptr)).value(s, derivative, "pure") From 347a58c974223a8b2936d7a462ff1c0ddc31ec7e Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:27:29 +0800 Subject: [PATCH 04/44] rename __hardy_z_function -> _hardy_z_function --- src/sage/libs/lcalc/lcalc_Lfunction.pxd | 2 +- src/sage/libs/lcalc/lcalc_Lfunction.pyx | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sage/libs/lcalc/lcalc_Lfunction.pxd b/src/sage/libs/lcalc/lcalc_Lfunction.pxd index 42b8dac62d3..5787e5ad2b9 100644 --- a/src/sage/libs/lcalc/lcalc_Lfunction.pxd +++ b/src/sage/libs/lcalc/lcalc_Lfunction.pxd @@ -106,7 +106,7 @@ cdef class Lfunction: cdef void *thisptr cdef void _init_fun(self, char *NAME, int what_type, dirichlet_coeff, long long Period, double q, c_Complex w, int A, double *g, c_Complex *l, int n_poles, c_Complex *p, c_Complex *r) cdef c_Complex _value(self,c_Complex s,int derivative) - cdef c_Complex __hardy_z_function(self,c_Complex s) + cdef c_Complex _hardy_z_function(self,c_Complex s) cdef int __compute_rank(self) #strange bug, replacing Double with double gives me a compile error cdef Double __typedN(self, double T) diff --git a/src/sage/libs/lcalc/lcalc_Lfunction.pyx b/src/sage/libs/lcalc/lcalc_Lfunction.pyx index 976aa891f7d..abc7fa551f0 100644 --- a/src/sage/libs/lcalc/lcalc_Lfunction.pyx +++ b/src/sage/libs/lcalc/lcalc_Lfunction.pyx @@ -223,7 +223,7 @@ cdef class Lfunction: #This takes s -> .5 + I*s cdef ComplexNumber complexified_s = CCC(0.5)+ CCC(0,1)*CCC(s) cdef c_Complex z = new_Complex(mpfr_get_d(complexified_s.__re, MPFR_RNDN), mpfr_get_d(complexified_s.__im, MPFR_RNDN)) - cdef c_Complex result = self.__hardy_z_function(z) + cdef c_Complex result = self._hardy_z_function(z) return CCC(result.real(),result.imag()) @@ -414,7 +414,7 @@ cdef class Lfunction: cdef c_Complex _value(self,c_Complex s,int derivative): raise NotImplementedError - cdef c_Complex __hardy_z_function(self,c_Complex s): + cdef c_Complex _hardy_z_function(self,c_Complex s): raise NotImplementedError cdef int __compute_rank(self): @@ -510,7 +510,7 @@ cdef class Lfunction_I(Lfunction): cdef inline c_Complex _value(self,c_Complex s,int derivative): return ((self.thisptr)).value(s, derivative, "pure") - cdef inline c_Complex __hardy_z_function(self,c_Complex s): + cdef inline c_Complex _hardy_z_function(self,c_Complex s): return ((self.thisptr)).value(s, 0, "rotated pure") cdef int __compute_rank(self): @@ -648,7 +648,7 @@ cdef class Lfunction_D(Lfunction): return ((self.thisptr)).value(s, derivative, "pure") - cdef inline c_Complex __hardy_z_function(self,c_Complex s): + cdef inline c_Complex _hardy_z_function(self,c_Complex s): return ((self.thisptr)).value(s, 0, "rotated pure") cdef inline int __compute_rank(self): @@ -792,7 +792,7 @@ cdef class Lfunction_C: return ((self.thisptr)).value(s, derivative, "pure") - cdef inline c_Complex __hardy_z_function(self,c_Complex s): + cdef inline c_Complex _hardy_z_function(self,c_Complex s): return ((self.thisptr)).value(s, 0,"rotated pure") cdef inline int __compute_rank(self): @@ -877,7 +877,7 @@ cdef class Lfunction_Zeta(Lfunction): return ((self.thisptr)).value(s, derivative, "pure") - cdef inline c_Complex __hardy_z_function(self,c_Complex s): + cdef inline c_Complex _hardy_z_function(self,c_Complex s): return ((self.thisptr)).value(s, 0, "rotated pure") cdef inline int __compute_rank(self): From dfb0c2b4cb713f08fb83c99d96fc4589a4446345 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:29:01 +0800 Subject: [PATCH 05/44] rename __compute_rank -> _compute_rank --- src/sage/libs/lcalc/lcalc_Lfunction.pxd | 2 +- src/sage/libs/lcalc/lcalc_Lfunction.pyx | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sage/libs/lcalc/lcalc_Lfunction.pxd b/src/sage/libs/lcalc/lcalc_Lfunction.pxd index 5787e5ad2b9..6ebd111a22b 100644 --- a/src/sage/libs/lcalc/lcalc_Lfunction.pxd +++ b/src/sage/libs/lcalc/lcalc_Lfunction.pxd @@ -107,7 +107,7 @@ cdef class Lfunction: cdef void _init_fun(self, char *NAME, int what_type, dirichlet_coeff, long long Period, double q, c_Complex w, int A, double *g, c_Complex *l, int n_poles, c_Complex *p, c_Complex *r) cdef c_Complex _value(self,c_Complex s,int derivative) cdef c_Complex _hardy_z_function(self,c_Complex s) - cdef int __compute_rank(self) + cdef int _compute_rank(self) #strange bug, replacing Double with double gives me a compile error cdef Double __typedN(self, double T) cdef void __find_zeros_v(self, double T1, double T2, double stepsize,doublevec *result) diff --git a/src/sage/libs/lcalc/lcalc_Lfunction.pyx b/src/sage/libs/lcalc/lcalc_Lfunction.pyx index abc7fa551f0..0ac64002b78 100644 --- a/src/sage/libs/lcalc/lcalc_Lfunction.pyx +++ b/src/sage/libs/lcalc/lcalc_Lfunction.pyx @@ -249,7 +249,7 @@ cdef class Lfunction: 3 """ - return self.__compute_rank() + return self._compute_rank() def __N(self, T): """ @@ -417,7 +417,7 @@ cdef class Lfunction: cdef c_Complex _hardy_z_function(self,c_Complex s): raise NotImplementedError - cdef int __compute_rank(self): + cdef int _compute_rank(self): raise NotImplementedError cdef double __typedN(self,double T): @@ -513,7 +513,7 @@ cdef class Lfunction_I(Lfunction): cdef inline c_Complex _hardy_z_function(self,c_Complex s): return ((self.thisptr)).value(s, 0, "rotated pure") - cdef int __compute_rank(self): + cdef int _compute_rank(self): return ((self.thisptr)).compute_rank() cdef void __find_zeros_v(self, double T1, double T2, double stepsize, doublevec *result): @@ -651,7 +651,7 @@ cdef class Lfunction_D(Lfunction): cdef inline c_Complex _hardy_z_function(self,c_Complex s): return ((self.thisptr)).value(s, 0, "rotated pure") - cdef inline int __compute_rank(self): + cdef inline int _compute_rank(self): return ((self.thisptr)).compute_rank() cdef void __find_zeros_v(self, double T1, double T2, double stepsize, doublevec *result): @@ -795,7 +795,7 @@ cdef class Lfunction_C: cdef inline c_Complex _hardy_z_function(self,c_Complex s): return ((self.thisptr)).value(s, 0,"rotated pure") - cdef inline int __compute_rank(self): + cdef inline int _compute_rank(self): return ((self.thisptr)).compute_rank() @@ -880,7 +880,7 @@ cdef class Lfunction_Zeta(Lfunction): cdef inline c_Complex _hardy_z_function(self,c_Complex s): return ((self.thisptr)).value(s, 0, "rotated pure") - cdef inline int __compute_rank(self): + cdef inline int _compute_rank(self): return ((self.thisptr)).compute_rank() From 03323bbf86a7fc37a763e18b6169074c47f6ff14 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:29:31 +0800 Subject: [PATCH 06/44] rename __typedN -> _typedN --- src/sage/libs/lcalc/lcalc_Lfunction.pxd | 4 ++-- src/sage/libs/lcalc/lcalc_Lfunction.pyx | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/sage/libs/lcalc/lcalc_Lfunction.pxd b/src/sage/libs/lcalc/lcalc_Lfunction.pxd index 6ebd111a22b..72067d424b2 100644 --- a/src/sage/libs/lcalc/lcalc_Lfunction.pxd +++ b/src/sage/libs/lcalc/lcalc_Lfunction.pxd @@ -99,7 +99,7 @@ cdef extern from "lcalc_sage.h": ################ # strange bug, I can't compile without this trick ??? -# it's only used in __typedN +# it's only used in _typedN ctypedef double Double cdef class Lfunction: @@ -109,7 +109,7 @@ cdef class Lfunction: cdef c_Complex _hardy_z_function(self,c_Complex s) cdef int _compute_rank(self) #strange bug, replacing Double with double gives me a compile error - cdef Double __typedN(self, double T) + cdef Double _typedN(self, double T) cdef void __find_zeros_v(self, double T1, double T2, double stepsize,doublevec *result) cdef int __find_zeros(self, long count, long start, double max_refine, int rank, const char* message_stamp, doublevec* result) diff --git a/src/sage/libs/lcalc/lcalc_Lfunction.pyx b/src/sage/libs/lcalc/lcalc_Lfunction.pyx index 0ac64002b78..cd277154773 100644 --- a/src/sage/libs/lcalc/lcalc_Lfunction.pyx +++ b/src/sage/libs/lcalc/lcalc_Lfunction.pyx @@ -267,7 +267,7 @@ cdef class Lfunction: """ cdef RealNumber real_T=RRR(T) cdef double double_T = mpfr_get_d(real_T.value, MPFR_RNDN) - cdef double res_d = self.__typedN(double_T) + cdef double res_d = self._typedN(double_T) return RRR(res_d) def find_zeros(self, T1, T2, stepsize): @@ -420,7 +420,7 @@ cdef class Lfunction: cdef int _compute_rank(self): raise NotImplementedError - cdef double __typedN(self,double T): + cdef double _typedN(self,double T): raise NotImplementedError cdef void __find_zeros_v(self,double T1, double T2, double stepsize, doublevec *result): @@ -519,7 +519,7 @@ cdef class Lfunction_I(Lfunction): cdef void __find_zeros_v(self, double T1, double T2, double stepsize, doublevec *result): (self.thisptr).find_zeros_v(T1,T2,stepsize,result[0]) - cdef double __typedN(self, double T): + cdef double _typedN(self, double T): return (self.thisptr).N(T) cdef int __find_zeros(self, long count, long start, double max_refine, int rank, const char* message_stamp, doublevec *result): @@ -657,7 +657,7 @@ cdef class Lfunction_D(Lfunction): cdef void __find_zeros_v(self, double T1, double T2, double stepsize, doublevec *result): (self.thisptr).find_zeros_v(T1,T2,stepsize,result[0]) - cdef double __typedN(self, double T): + cdef double _typedN(self, double T): return (self.thisptr).N(T) cdef int __find_zeros(self, long count, long start,double max_refine, int rank, const char* message_stamp, doublevec *result): @@ -802,7 +802,7 @@ cdef class Lfunction_C: cdef void __find_zeros_v(self, double T1, double T2, double stepsize, doublevec *result): (self.thisptr).find_zeros_v(T1,T2,stepsize,result[0]) - cdef double __typedN(self, double T): + cdef double _typedN(self, double T): return (self.thisptr).N(T) cdef int __find_zeros(self, long count, long start, double max_refine, int rank, const char* message_stamp, doublevec *result): @@ -887,7 +887,7 @@ cdef class Lfunction_Zeta(Lfunction): cdef void __find_zeros_v(self, double T1, double T2, double stepsize, doublevec *result): (self.thisptr).find_zeros_v(T1,T2,stepsize,result[0]) - cdef double __typedN(self, double T): + cdef double _typedN(self, double T): return (self.thisptr).N(T) cdef int __find_zeros(self, long count, long start, double max_refine, int rank, const char* message_stamp, doublevec *result): From ca8a2f67daaf3ed11c6075a30fef71da0e922f7c Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:29:49 +0800 Subject: [PATCH 07/44] rename __find_zeros_v -> _find_zeros_v --- src/sage/libs/lcalc/lcalc_Lfunction.pxd | 2 +- src/sage/libs/lcalc/lcalc_Lfunction.pyx | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sage/libs/lcalc/lcalc_Lfunction.pxd b/src/sage/libs/lcalc/lcalc_Lfunction.pxd index 72067d424b2..f514eaee507 100644 --- a/src/sage/libs/lcalc/lcalc_Lfunction.pxd +++ b/src/sage/libs/lcalc/lcalc_Lfunction.pxd @@ -110,7 +110,7 @@ cdef class Lfunction: cdef int _compute_rank(self) #strange bug, replacing Double with double gives me a compile error cdef Double _typedN(self, double T) - cdef void __find_zeros_v(self, double T1, double T2, double stepsize,doublevec *result) + cdef void _find_zeros_v(self, double T1, double T2, double stepsize,doublevec *result) cdef int __find_zeros(self, long count, long start, double max_refine, int rank, const char* message_stamp, doublevec* result) cdef str _repr diff --git a/src/sage/libs/lcalc/lcalc_Lfunction.pyx b/src/sage/libs/lcalc/lcalc_Lfunction.pyx index cd277154773..46cb9622482 100644 --- a/src/sage/libs/lcalc/lcalc_Lfunction.pyx +++ b/src/sage/libs/lcalc/lcalc_Lfunction.pyx @@ -323,7 +323,7 @@ cdef class Lfunction: cdef RealNumber real_T2 = RRR(T2) cdef RealNumber real_stepsize = RRR(stepsize) sig_on() - self.__find_zeros_v( mpfr_get_d(real_T1.value, MPFR_RNDN), mpfr_get_d(real_T2.value, MPFR_RNDN), mpfr_get_d(real_stepsize.value, MPFR_RNDN),&result) + self._find_zeros_v( mpfr_get_d(real_T1.value, MPFR_RNDN), mpfr_get_d(real_T2.value, MPFR_RNDN), mpfr_get_d(real_stepsize.value, MPFR_RNDN),&result) sig_off() i=result.size() returnvalue = [] @@ -423,7 +423,7 @@ cdef class Lfunction: cdef double _typedN(self,double T): raise NotImplementedError - cdef void __find_zeros_v(self,double T1, double T2, double stepsize, doublevec *result): + cdef void _find_zeros_v(self,double T1, double T2, double stepsize, doublevec *result): raise NotImplementedError cdef int __find_zeros(self, long count, long start, double max_refine, int rank, const char* message_stamp, doublevec *result): @@ -516,7 +516,7 @@ cdef class Lfunction_I(Lfunction): cdef int _compute_rank(self): return ((self.thisptr)).compute_rank() - cdef void __find_zeros_v(self, double T1, double T2, double stepsize, doublevec *result): + cdef void _find_zeros_v(self, double T1, double T2, double stepsize, doublevec *result): (self.thisptr).find_zeros_v(T1,T2,stepsize,result[0]) cdef double _typedN(self, double T): @@ -654,7 +654,7 @@ cdef class Lfunction_D(Lfunction): cdef inline int _compute_rank(self): return ((self.thisptr)).compute_rank() - cdef void __find_zeros_v(self, double T1, double T2, double stepsize, doublevec *result): + cdef void _find_zeros_v(self, double T1, double T2, double stepsize, doublevec *result): (self.thisptr).find_zeros_v(T1,T2,stepsize,result[0]) cdef double _typedN(self, double T): @@ -799,7 +799,7 @@ cdef class Lfunction_C: return ((self.thisptr)).compute_rank() - cdef void __find_zeros_v(self, double T1, double T2, double stepsize, doublevec *result): + cdef void _find_zeros_v(self, double T1, double T2, double stepsize, doublevec *result): (self.thisptr).find_zeros_v(T1,T2,stepsize,result[0]) cdef double _typedN(self, double T): @@ -884,7 +884,7 @@ cdef class Lfunction_Zeta(Lfunction): return ((self.thisptr)).compute_rank() - cdef void __find_zeros_v(self, double T1, double T2, double stepsize, doublevec *result): + cdef void _find_zeros_v(self, double T1, double T2, double stepsize, doublevec *result): (self.thisptr).find_zeros_v(T1,T2,stepsize,result[0]) cdef double _typedN(self, double T): From 834406161663077528c07becfd08bc216907dc90 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:30:01 +0800 Subject: [PATCH 08/44] rename __find_zeros -> _find_zeros --- src/sage/libs/lcalc/lcalc_Lfunction.pxd | 2 +- src/sage/libs/lcalc/lcalc_Lfunction.pyx | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sage/libs/lcalc/lcalc_Lfunction.pxd b/src/sage/libs/lcalc/lcalc_Lfunction.pxd index f514eaee507..1d595180a6f 100644 --- a/src/sage/libs/lcalc/lcalc_Lfunction.pxd +++ b/src/sage/libs/lcalc/lcalc_Lfunction.pxd @@ -111,7 +111,7 @@ cdef class Lfunction: #strange bug, replacing Double with double gives me a compile error cdef Double _typedN(self, double T) cdef void _find_zeros_v(self, double T1, double T2, double stepsize,doublevec *result) - cdef int __find_zeros(self, long count, long start, double max_refine, int rank, const char* message_stamp, doublevec* result) + cdef int _find_zeros(self, long count, long start, double max_refine, int rank, const char* message_stamp, doublevec* result) cdef str _repr diff --git a/src/sage/libs/lcalc/lcalc_Lfunction.pyx b/src/sage/libs/lcalc/lcalc_Lfunction.pyx index 46cb9622482..d8b7221fe55 100644 --- a/src/sage/libs/lcalc/lcalc_Lfunction.pyx +++ b/src/sage/libs/lcalc/lcalc_Lfunction.pyx @@ -399,7 +399,7 @@ cdef class Lfunction: cdef const char* message_stamp = "" cdef doublevec result sig_on() - self.__find_zeros(count, start, max_refine, rank, message_stamp, &result) + self._find_zeros(count, start, max_refine, rank, message_stamp, &result) sig_off() returnvalue = [] for i in range(result.size()): @@ -426,7 +426,7 @@ cdef class Lfunction: cdef void _find_zeros_v(self,double T1, double T2, double stepsize, doublevec *result): raise NotImplementedError - cdef int __find_zeros(self, long count, long start, double max_refine, int rank, const char* message_stamp, doublevec *result): + cdef int _find_zeros(self, long count, long start, double max_refine, int rank, const char* message_stamp, doublevec *result): raise NotImplementedError ############################################################################## @@ -522,7 +522,7 @@ cdef class Lfunction_I(Lfunction): cdef double _typedN(self, double T): return (self.thisptr).N(T) - cdef int __find_zeros(self, long count, long start, double max_refine, int rank, const char* message_stamp, doublevec *result): + cdef int _find_zeros(self, long count, long start, double max_refine, int rank, const char* message_stamp, doublevec *result): (self.thisptr).find_zeros(count, start, max_refine, rank, message_stamp, result) # debug tools @@ -660,7 +660,7 @@ cdef class Lfunction_D(Lfunction): cdef double _typedN(self, double T): return (self.thisptr).N(T) - cdef int __find_zeros(self, long count, long start,double max_refine, int rank, const char* message_stamp, doublevec *result): + cdef int _find_zeros(self, long count, long start,double max_refine, int rank, const char* message_stamp, doublevec *result): (self.thisptr).find_zeros(count, start, max_refine, rank, message_stamp, result) # debug tools @@ -805,7 +805,7 @@ cdef class Lfunction_C: cdef double _typedN(self, double T): return (self.thisptr).N(T) - cdef int __find_zeros(self, long count, long start, double max_refine, int rank, const char* message_stamp, doublevec *result): + cdef int _find_zeros(self, long count, long start, double max_refine, int rank, const char* message_stamp, doublevec *result): (self.thisptr).find_zeros(count, start, max_refine, rank, message_stamp, result) # debug tools @@ -890,7 +890,7 @@ cdef class Lfunction_Zeta(Lfunction): cdef double _typedN(self, double T): return (self.thisptr).N(T) - cdef int __find_zeros(self, long count, long start, double max_refine, int rank, const char* message_stamp, doublevec *result): + cdef int _find_zeros(self, long count, long start, double max_refine, int rank, const char* message_stamp, doublevec *result): (self.thisptr).find_zeros(count, start, max_refine, rank, message_stamp, result) def __dealloc__(self): From 722de4e0aaad133bbfb1ca738eb8a95f09339f06 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:24:36 +0800 Subject: [PATCH 09/44] rename __is_exchange_pair -> _is_exchange_pair --- src/sage/matroids/basis_exchange_matroid.pxd | 2 +- src/sage/matroids/basis_exchange_matroid.pyx | 26 ++++++++++---------- src/sage/matroids/basis_matroid.pyx | 2 +- src/sage/matroids/linear_matroid.pyx | 10 ++++---- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/sage/matroids/basis_exchange_matroid.pxd b/src/sage/matroids/basis_exchange_matroid.pxd index aec3bb54c42..b8207f92156 100644 --- a/src/sage/matroids/basis_exchange_matroid.pxd +++ b/src/sage/matroids/basis_exchange_matroid.pxd @@ -19,7 +19,7 @@ cdef class BasisExchangeMatroid(Matroid): cdef __pack(self, bitset_t, X) cdef __unpack(self, bitset_t) - cdef bint __is_exchange_pair(self, long x, long y) except -1 + cdef bint _is_exchange_pair(self, long x, long y) except -1 cdef int __exchange(self, long x, long y) except -1 cdef int __move(self, bitset_t X, bitset_t Y) except -1 cdef __fundamental_cocircuit(self, bitset_t, long x) diff --git a/src/sage/matroids/basis_exchange_matroid.pyx b/src/sage/matroids/basis_exchange_matroid.pyx index 90d10842d46..00d017d2189 100644 --- a/src/sage/matroids/basis_exchange_matroid.pyx +++ b/src/sage/matroids/basis_exchange_matroid.pyx @@ -57,9 +57,9 @@ cdef class BasisExchangeMatroid(Matroid): This base exchange graph is not stored as such, but should be provided implicitly by the child class in the form of two methods - ``__is_exchange_pair(x, y)`` and ``__exchange(x, y)``, as well as an + ``_is_exchange_pair(x, y)`` and ``__exchange(x, y)``, as well as an initial basis. At any moment, BasisExchangeMatroid keeps a current basis - `B`. The method ``__is_exchange_pair(x, y)`` should return a boolean + `B`. The method ``_is_exchange_pair(x, y)`` should return a boolean indicating whether `B - x + y` is a basis. The method ``__exchange(x, y)`` is called when the current basis `B` is replaced by said `B-x + y`. It is up to the child class to update its internal data structure to make @@ -81,14 +81,14 @@ cdef class BasisExchangeMatroid(Matroid): - :class:`BasisMatroid `: keeps a list of all bases. - - ``__is_exchange_pair(x, y)`` reduces to a query whether `B - x + y` + - ``_is_exchange_pair(x, y)`` reduces to a query whether `B - x + y` is a basis. - ``__exchange(x, y)`` has no work to do. - :class:`LinearMatroid `: keeps a matrix representation `A` of the matroid so that `A[B] = I`. - - ``__is_exchange_pair(x, y)`` reduces to testing whether `A[r, y]` + - ``_is_exchange_pair(x, y)`` reduces to testing whether `A[r, y]` is nonzero, where `A[r, x]=1`. - ``__exchange(x, y)`` should modify the matrix so that `A[B - x + y]` becomes `I`, which means pivoting on `A[r, y]`. @@ -100,7 +100,7 @@ cdef class BasisExchangeMatroid(Matroid): edge `(A_i,e)` if `e` is in the subset `A_i`. At any time you keep a maximum matching `M` of `G` covering the current basis `B`. - - ``__is_exchange_pair(x, y)`` checks for the existence of an + - ``_is_exchange_pair(x, y)`` checks for the existence of an `M`-alternating path `P` from `y` to `x`. - ``__exchange(x, y)`` replaces `M` by the symmetric difference of `M` and `E(P)`. @@ -108,7 +108,7 @@ cdef class BasisExchangeMatroid(Matroid): - ``AlgebraicMatroid`` (not yet implemented): keeps a list of polynomials in variables `E - B + e` for each variable `e` in `B`. - - ``__is_exchange_pair(x, y)`` checks whether the polynomial that + - ``_is_exchange_pair(x, y)`` checks whether the polynomial that relates `y` to `E-B` uses `x`. - ``__exchange(x, y)`` make new list of polynomials by computing resultants. @@ -252,7 +252,7 @@ cdef class BasisExchangeMatroid(Matroid): return frozenset(F) # this method needs to be overridden by child class - cdef bint __is_exchange_pair(self, long x, long y) except -1: + cdef bint _is_exchange_pair(self, long x, long y) except -1: """ Test if current_basis-x + y is a basis """ @@ -275,7 +275,7 @@ cdef class BasisExchangeMatroid(Matroid): while x >= 0: y = bitset_first(Y) while y >= 0: - if self.__is_exchange_pair(x, y): + if self._is_exchange_pair(x, y): self.__exchange(x, y) bitset_discard(Y, y) bitset_discard(X, x) @@ -295,7 +295,7 @@ cdef class BasisExchangeMatroid(Matroid): bitset_complement(self._temp, self._current_basis) y = bitset_first(self._temp) while y >= 0: - if self.__is_exchange_pair(x, y): + if self._is_exchange_pair(x, y): bitset_add(C, y) y = bitset_next(self._temp, y + 1) bitset_add(C, x) @@ -308,7 +308,7 @@ cdef class BasisExchangeMatroid(Matroid): bitset_clear(C) x = bitset_first(self._current_basis) while x >= 0: - if self.__is_exchange_pair(x, y): + if self._is_exchange_pair(x, y): bitset_add(C, x) x = bitset_next(self._current_basis, x + 1) bitset_add(C, y) @@ -335,7 +335,7 @@ cdef class BasisExchangeMatroid(Matroid): while y >= 0: x = bitset_first(self._inside) while x >= 0: - if self.__is_exchange_pair(x, y): + if self._is_exchange_pair(x, y): self.__exchange(x, y) bitset_discard(self._outside, y) bitset_discard(self._inside, x) @@ -387,7 +387,7 @@ cdef class BasisExchangeMatroid(Matroid): while x >= 0: y = bitset_first(self._outside) while y >= 0: - if self.__is_exchange_pair(x, y): + if self._is_exchange_pair(x, y): self.__exchange(x, y) bitset_discard(self._outside, y) bitset_discard(self._inside, x) @@ -2409,7 +2409,7 @@ cdef class BasisExchangeMatroid(Matroid): foundpair = False y = bitset_first(self._input2) while y >= 0: # for y in Y-X - if self.__is_exchange_pair(y, x): + if self._is_exchange_pair(y, x): foundpair = True y = -1 else: diff --git a/src/sage/matroids/basis_matroid.pyx b/src/sage/matroids/basis_matroid.pyx index 3ac43112627..c553c302989 100644 --- a/src/sage/matroids/basis_matroid.pyx +++ b/src/sage/matroids/basis_matroid.pyx @@ -263,7 +263,7 @@ cdef class BasisMatroid(BasisExchangeMatroid): # support for parent BasisExchangeMatroid - cdef bint __is_exchange_pair(self, long x, long y) except -1: # test if current_basis-x + y is a basis + cdef bint _is_exchange_pair(self, long x, long y) except -1: # test if current_basis-x + y is a basis """ Test if `B-e + f` is a basis of the current matroid. diff --git a/src/sage/matroids/linear_matroid.pyx b/src/sage/matroids/linear_matroid.pyx index 11f6b4a2656..27713a4b6a2 100644 --- a/src/sage/matroids/linear_matroid.pyx +++ b/src/sage/matroids/linear_matroid.pyx @@ -391,7 +391,7 @@ cdef class LinearMatroid(BasisExchangeMatroid): """ return characteristic(self._A) - cdef bint __is_exchange_pair(self, long x, long y) except -1: + cdef bint _is_exchange_pair(self, long x, long y) except -1: r""" Check if ``self.basis() - x + y`` is again a basis. Internal method. """ @@ -3152,7 +3152,7 @@ cdef class BinaryMatroid(LinearMatroid): """ return 2 - cdef bint __is_exchange_pair(self, long x, long y) except -1: + cdef bint _is_exchange_pair(self, long x, long y) except -1: r""" Check if ``self.basis() - x + y`` is again a basis. Internal method. """ @@ -4220,7 +4220,7 @@ cdef class TernaryMatroid(LinearMatroid): """ return 3 - cdef bint __is_exchange_pair(self, long x, long y) except -1: + cdef bint _is_exchange_pair(self, long x, long y) except -1: r""" Check if ``self.basis() - x + y`` is again a basis. Internal method. """ @@ -5122,7 +5122,7 @@ cdef class QuaternaryMatroid(LinearMatroid): """ return 2 - cdef bint __is_exchange_pair(self, long x, long y) except -1: + cdef bint _is_exchange_pair(self, long x, long y) except -1: r""" Check if ``self.basis() - x + y`` is again a basis. Internal method. """ @@ -5838,7 +5838,7 @@ cdef class RegularMatroid(LinearMatroid): """ return 0 - cdef bint __is_exchange_pair(self, long x, long y) except -1: + cdef bint _is_exchange_pair(self, long x, long y) except -1: r""" Check if ``self.basis() - x + y`` is again a basis. Internal method. """ From a69534fae8cb1e3a8cd558072fde4e1ec81d2ca4 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:24:58 +0800 Subject: [PATCH 10/44] rename __exchange -> _exchange --- src/sage/matroids/basis_exchange_matroid.pxd | 2 +- src/sage/matroids/basis_exchange_matroid.pyx | 20 ++++++++++---------- src/sage/matroids/linear_matroid.pyx | 20 ++++++++++---------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/sage/matroids/basis_exchange_matroid.pxd b/src/sage/matroids/basis_exchange_matroid.pxd index b8207f92156..daddb350d69 100644 --- a/src/sage/matroids/basis_exchange_matroid.pxd +++ b/src/sage/matroids/basis_exchange_matroid.pxd @@ -20,7 +20,7 @@ cdef class BasisExchangeMatroid(Matroid): cdef __pack(self, bitset_t, X) cdef __unpack(self, bitset_t) cdef bint _is_exchange_pair(self, long x, long y) except -1 - cdef int __exchange(self, long x, long y) except -1 + cdef int _exchange(self, long x, long y) except -1 cdef int __move(self, bitset_t X, bitset_t Y) except -1 cdef __fundamental_cocircuit(self, bitset_t, long x) cdef __fundamental_circuit(self, bitset_t, long y) diff --git a/src/sage/matroids/basis_exchange_matroid.pyx b/src/sage/matroids/basis_exchange_matroid.pyx index 00d017d2189..ab105ddef2f 100644 --- a/src/sage/matroids/basis_exchange_matroid.pyx +++ b/src/sage/matroids/basis_exchange_matroid.pyx @@ -57,10 +57,10 @@ cdef class BasisExchangeMatroid(Matroid): This base exchange graph is not stored as such, but should be provided implicitly by the child class in the form of two methods - ``_is_exchange_pair(x, y)`` and ``__exchange(x, y)``, as well as an + ``_is_exchange_pair(x, y)`` and ``_exchange(x, y)``, as well as an initial basis. At any moment, BasisExchangeMatroid keeps a current basis `B`. The method ``_is_exchange_pair(x, y)`` should return a boolean - indicating whether `B - x + y` is a basis. The method ``__exchange(x, y)`` + indicating whether `B - x + y` is a basis. The method ``_exchange(x, y)`` is called when the current basis `B` is replaced by said `B-x + y`. It is up to the child class to update its internal data structure to make information relative to the new basis more accessible. For instance, a @@ -83,14 +83,14 @@ cdef class BasisExchangeMatroid(Matroid): - ``_is_exchange_pair(x, y)`` reduces to a query whether `B - x + y` is a basis. - - ``__exchange(x, y)`` has no work to do. + - ``_exchange(x, y)`` has no work to do. - :class:`LinearMatroid `: keeps a matrix representation `A` of the matroid so that `A[B] = I`. - ``_is_exchange_pair(x, y)`` reduces to testing whether `A[r, y]` is nonzero, where `A[r, x]=1`. - - ``__exchange(x, y)`` should modify the matrix so that `A[B - x + y]` + - ``_exchange(x, y)`` should modify the matrix so that `A[B - x + y]` becomes `I`, which means pivoting on `A[r, y]`. - ``TransversalMatroid`` (not yet implemented): If `A` is a set of subsets @@ -102,7 +102,7 @@ cdef class BasisExchangeMatroid(Matroid): - ``_is_exchange_pair(x, y)`` checks for the existence of an `M`-alternating path `P` from `y` to `x`. - - ``__exchange(x, y)`` replaces `M` by the symmetric difference of + - ``_exchange(x, y)`` replaces `M` by the symmetric difference of `M` and `E(P)`. - ``AlgebraicMatroid`` (not yet implemented): keeps a list of polynomials @@ -110,7 +110,7 @@ cdef class BasisExchangeMatroid(Matroid): - ``_is_exchange_pair(x, y)`` checks whether the polynomial that relates `y` to `E-B` uses `x`. - - ``__exchange(x, y)`` make new list of polynomials by computing + - ``_exchange(x, y)`` make new list of polynomials by computing resultants. All but the first of the above matroids are algebraic, and all @@ -259,7 +259,7 @@ cdef class BasisExchangeMatroid(Matroid): raise NotImplementedError # if this method is overridden by a child class, the child class needs to call this method - cdef int __exchange(self, long x, long y) except -1: + cdef int _exchange(self, long x, long y) except -1: """ put current_basis <-- current_basis-x + y """ @@ -276,7 +276,7 @@ cdef class BasisExchangeMatroid(Matroid): y = bitset_first(Y) while y >= 0: if self._is_exchange_pair(x, y): - self.__exchange(x, y) + self._exchange(x, y) bitset_discard(Y, y) bitset_discard(X, x) if bitset_isempty(Y): @@ -336,7 +336,7 @@ cdef class BasisExchangeMatroid(Matroid): x = bitset_first(self._inside) while x >= 0: if self._is_exchange_pair(x, y): - self.__exchange(x, y) + self._exchange(x, y) bitset_discard(self._outside, y) bitset_discard(self._inside, x) if bitset_isempty(self._outside): @@ -388,7 +388,7 @@ cdef class BasisExchangeMatroid(Matroid): y = bitset_first(self._outside) while y >= 0: if self._is_exchange_pair(x, y): - self.__exchange(x, y) + self._exchange(x, y) bitset_discard(self._outside, y) bitset_discard(self._inside, x) if bitset_isempty(self._inside): diff --git a/src/sage/matroids/linear_matroid.pyx b/src/sage/matroids/linear_matroid.pyx index 27713a4b6a2..f6e12756c33 100644 --- a/src/sage/matroids/linear_matroid.pyx +++ b/src/sage/matroids/linear_matroid.pyx @@ -397,7 +397,7 @@ cdef class LinearMatroid(BasisExchangeMatroid): """ return self._A.is_nonzero(self._prow[x], self._prow[y]) - cdef int __exchange(self, long x, long y) except -1: + cdef int _exchange(self, long x, long y) except -1: """ Put element indexed by ``x`` into basis, taking out element ``y``. Assumptions are that this is a valid basis exchange. @@ -420,7 +420,7 @@ cdef class LinearMatroid(BasisExchangeMatroid): self._A.set_unsafe(px, py, pivi) self._prow[y] = px self._prow[x] = py - BasisExchangeMatroid.__exchange(self, x, y) + BasisExchangeMatroid._exchange(self, x, y) cdef __exchange_value(self, long x, long y): r""" @@ -3158,14 +3158,14 @@ cdef class BinaryMatroid(LinearMatroid): """ return (self._A).is_nonzero(self._prow[x], y) - cdef int __exchange(self, long x, long y) except -1: + cdef int _exchange(self, long x, long y) except -1: r""" Replace ``self.basis() with ``self.basis() - x + y``. Internal method, does no checks. """ cdef long p = self._prow[x] self._A.pivot(p, y) # Not a Sage matrix operation self._prow[y] = p - BasisExchangeMatroid.__exchange(self, x, y) + BasisExchangeMatroid._exchange(self, x, y) cdef __fundamental_cocircuit(self, bitset_t C, long x): r""" @@ -4226,14 +4226,14 @@ cdef class TernaryMatroid(LinearMatroid): """ return (self._A).is_nonzero(self._prow[x], y) - cdef int __exchange(self, long x, long y) except -1: + cdef int _exchange(self, long x, long y) except -1: r""" Replace ``self.basis() with ``self.basis() - x + y``. Internal method, does no checks. """ cdef long p = self._prow[x] self._A.pivot(p, y) # Not a Sage matrix operation self._prow[y] = p - BasisExchangeMatroid.__exchange(self, x, y) + BasisExchangeMatroid._exchange(self, x, y) cdef __fundamental_cocircuit(self, bitset_t C, long x): r""" @@ -5128,14 +5128,14 @@ cdef class QuaternaryMatroid(LinearMatroid): """ return (self._A).is_nonzero(self._prow[x], y) - cdef int __exchange(self, long x, long y) except -1: + cdef int _exchange(self, long x, long y) except -1: r""" Replace ``self.basis() with ``self.basis() - x + y``. Internal method, does no checks. """ cdef long p = self._prow[x] self._A.pivot(p, y) # Not a Sage matrix operation self._prow[y] = p - BasisExchangeMatroid.__exchange(self, x, y) + BasisExchangeMatroid._exchange(self, x, y) cdef __fundamental_cocircuit(self, bitset_t C, long x): r""" @@ -5844,7 +5844,7 @@ cdef class RegularMatroid(LinearMatroid): """ return (self._A).is_nonzero(self._prow[x], self._prow[y]) - cdef int __exchange(self, long x, long y) except -1: + cdef int _exchange(self, long x, long y) except -1: """ Put element indexed by ``x`` into basis, taking out element ``y``. Assumptions are that this is a valid basis exchange. @@ -5867,7 +5867,7 @@ cdef class RegularMatroid(LinearMatroid): (self._A).set(px, py, pivi) # Not a Sage matrix operation self._prow[y] = px self._prow[x] = py - BasisExchangeMatroid.__exchange(self, x, y) + BasisExchangeMatroid._exchange(self, x, y) cdef __exchange_value(self, long x, long y): r""" From edef800baab5587b412180d1354a7539e6af76a1 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:25:28 +0800 Subject: [PATCH 11/44] rename __exchange_value -> _exchange_value_internal --- src/sage/matroids/linear_matroid.pxd | 2 +- src/sage/matroids/linear_matroid.pyx | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sage/matroids/linear_matroid.pxd b/src/sage/matroids/linear_matroid.pxd index 014c8aef57d..9aebd446b68 100644 --- a/src/sage/matroids/linear_matroid.pxd +++ b/src/sage/matroids/linear_matroid.pxd @@ -15,7 +15,7 @@ cdef class LinearMatroid(BasisExchangeMatroid): cpdef characteristic(self) cdef list _setup_internal_representation(self, matrix, reduced_matrix, ring, keep_initial_representation) - cdef __exchange_value(self, long x, long y) + cdef _exchange_value_internal(self, long x, long y) cpdef representation(self, B=*, reduced=*, labels=*, order=*, lift_map=*) cpdef _current_rows_cols(self, B=*) diff --git a/src/sage/matroids/linear_matroid.pyx b/src/sage/matroids/linear_matroid.pyx index f6e12756c33..7d0f5bef171 100644 --- a/src/sage/matroids/linear_matroid.pyx +++ b/src/sage/matroids/linear_matroid.pyx @@ -422,7 +422,7 @@ cdef class LinearMatroid(BasisExchangeMatroid): self._prow[x] = py BasisExchangeMatroid._exchange(self, x, y) - cdef __exchange_value(self, long x, long y): + cdef _exchange_value_internal(self, long x, long y): r""" Return the (x, y) entry of the current representation. """ @@ -1493,7 +1493,7 @@ cdef class LinearMatroid(BasisExchangeMatroid): sage: M._exchange_value(1, 3) 4 """ - return self.__exchange_value(self._idx[e], self._idx[f]) + return self._exchange_value_internal(self._idx[e], self._idx[f]) cpdef fundamental_cycle(self, B, e): """ @@ -3196,7 +3196,7 @@ cdef class BinaryMatroid(LinearMatroid): bitset_add(R, y) y = bitset_next(self._inside, y + 1) - cdef __exchange_value(self, long x, long y): + cdef _exchange_value_internal(self, long x, long y): r""" Return the (x, y) entry of the current representation. """ @@ -4264,7 +4264,7 @@ cdef class TernaryMatroid(LinearMatroid): bitset_add(R, y) y = bitset_next(self._inside, y + 1) - cdef __exchange_value(self, long x, long y): + cdef _exchange_value_internal(self, long x, long y): r""" Return the (x, y) entry of the current representation. """ @@ -5166,7 +5166,7 @@ cdef class QuaternaryMatroid(LinearMatroid): bitset_add(R, y) y = bitset_next(self._inside, y + 1) - cdef __exchange_value(self, long x, long y): + cdef _exchange_value_internal(self, long x, long y): r""" Return the (x, y) entry of the current representation. """ @@ -5869,7 +5869,7 @@ cdef class RegularMatroid(LinearMatroid): self._prow[x] = py BasisExchangeMatroid._exchange(self, x, y) - cdef __exchange_value(self, long x, long y): + cdef _exchange_value_internal(self, long x, long y): r""" Return the (x, y) entry of the current representation. From 2307d0f58f861f38281798b426536622e52a5f63 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:31:01 +0800 Subject: [PATCH 12/44] rename __coclosure -> _coclosure_internal --- src/sage/matroids/basis_exchange_matroid.pxd | 2 +- src/sage/matroids/basis_exchange_matroid.pyx | 8 ++++---- src/sage/matroids/linear_matroid.pyx | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/sage/matroids/basis_exchange_matroid.pxd b/src/sage/matroids/basis_exchange_matroid.pxd index daddb350d69..73bdef652e9 100644 --- a/src/sage/matroids/basis_exchange_matroid.pxd +++ b/src/sage/matroids/basis_exchange_matroid.pxd @@ -30,7 +30,7 @@ cdef class BasisExchangeMatroid(Matroid): cdef __closure(self, bitset_t, bitset_t) cdef __max_coindependent(self, bitset_t, bitset_t) cdef __cocircuit(self, bitset_t, bitset_t) - cdef __coclosure(self, bitset_t, bitset_t) + cdef _coclosure_internal(self, bitset_t, bitset_t) cdef __augment(self, bitset_t, bitset_t, bitset_t) cdef bint __is_independent(self, bitset_t F) except -1 diff --git a/src/sage/matroids/basis_exchange_matroid.pyx b/src/sage/matroids/basis_exchange_matroid.pyx index ab105ddef2f..f1017950684 100644 --- a/src/sage/matroids/basis_exchange_matroid.pyx +++ b/src/sage/matroids/basis_exchange_matroid.pyx @@ -401,7 +401,7 @@ cdef class BasisExchangeMatroid(Matroid): return x = bitset_next(self._inside, x + 1) - cdef __coclosure(self, bitset_t R, bitset_t F): + cdef _coclosure_internal(self, bitset_t R, bitset_t F): """ Bitpacked version of ``closure``. """ @@ -944,7 +944,7 @@ cdef class BasisExchangeMatroid(Matroid): """ self.__pack(self._input, F) - self.__coclosure(self._output, self._input) + self._coclosure_internal(self._output, self._input) return self.__unpack(self._output) cpdef _augment(self, X, Y): @@ -1421,7 +1421,7 @@ cdef class BasisExchangeMatroid(Matroid): Rcoflats = SetSystem(self._E) i = 0 bitset_clear(todo[0]) - self.__coclosure(coflats[0], todo[0]) + self._coclosure_internal(coflats[0], todo[0]) bitset_complement(todo[0], coflats[0]) self._coflats_rec(Rcoflats, r, coflats, todo, 0, 0) for i in range(r + 1): @@ -1443,7 +1443,7 @@ cdef class BasisExchangeMatroid(Matroid): while e >= 0: bitset_copy(self._input, coflats[i]) bitset_add(self._input, e) - self.__coclosure(coflats[i + 1], self._input) + self._coclosure_internal(coflats[i + 1], self._input) bitset_difference(todo[i], todo[i], coflats[i + 1]) bitset_difference(todo[i + 1], coflats[i + 1], coflats[i]) if bitset_first(todo[i + 1]) == e: diff --git a/src/sage/matroids/linear_matroid.pyx b/src/sage/matroids/linear_matroid.pyx index 7d0f5bef171..abaf28bbc5b 100644 --- a/src/sage/matroids/linear_matroid.pyx +++ b/src/sage/matroids/linear_matroid.pyx @@ -3173,11 +3173,11 @@ cdef class BinaryMatroid(LinearMatroid): """ bitset_copy(C, (self._A)._M[self._prow[x]]) - cdef __coclosure(self, bitset_t R, bitset_t F): + cdef _coclosure_internal(self, bitset_t R, bitset_t F): """ Bitpacked version of ``coclosure``. - This function overrides the internal function BasisExchangeMatroid.__coclosure() of the parent class. + This function overrides the internal function BasisExchangeMatroid._coclosure_internal() of the parent class. The implementation should be more efficient for BinaryMatroid, due to the fact that in this class, __fundamental_cocircuit is much faster than __fundamental_circuit. """ @@ -4241,11 +4241,11 @@ cdef class TernaryMatroid(LinearMatroid): """ bitset_copy(C, (self._A)._M0[self._prow[x]]) - cdef __coclosure(self, bitset_t R, bitset_t F): + cdef _coclosure_internal(self, bitset_t R, bitset_t F): """ Bitpacked version of ``coclosure``. - This function overrides the internal function BasisExchangeMatroid.__coclosure() of the parent class. + This function overrides the internal function BasisExchangeMatroid._coclosure_internal() of the parent class. The implementation should be more efficient for TernaryMatroid, due to the fact that in this class, __fundamental_cocircuit is much faster than __fundamental_circuit. """ @@ -5143,11 +5143,11 @@ cdef class QuaternaryMatroid(LinearMatroid): """ bitset_union(C, (self._A)._M0[self._prow[x]], (self._A)._M1[self._prow[x]]) - cdef __coclosure(self, bitset_t R, bitset_t F): + cdef _coclosure_internal(self, bitset_t R, bitset_t F): """ Bitpacked version of ``coclosure``. - This function overrides the internal function BasisExchangeMatroid.__coclosure() of the parent class. + This function overrides the internal function BasisExchangeMatroid._coclosure_internal() of the parent class. The implementation should be more efficient for QuaternaryMatroid, due to the fact that in this class, __fundamental_cocircuit is much faster than __fundamental_circuit. """ From 9d12ba3925f2bae98a0b83b168335cee36fc4868 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:32:34 +0800 Subject: [PATCH 13/44] fix use of private __pack --- src/sage/matroids/basis_matroid.pyx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sage/matroids/basis_matroid.pyx b/src/sage/matroids/basis_matroid.pyx index c553c302989..da6268be982 100644 --- a/src/sage/matroids/basis_matroid.pyx +++ b/src/sage/matroids/basis_matroid.pyx @@ -219,7 +219,7 @@ cdef class BasisMatroid(BasisExchangeMatroid): raise ValueError("basis has wrong cardinality.") if not b.issubset(self._groundset): raise ValueError("basis is not a subset of the groundset") - self.__pack(self._b, b) + self._BasisExchangeMatroid__pack(self._b, b) i = set_to_index(self._b) if not bitset_in(self._bb, i): self._bcount += 1 @@ -234,7 +234,7 @@ cdef class BasisMatroid(BasisExchangeMatroid): raise ValueError("nonbasis has wrong cardinality") if not b.issubset(self._groundset): raise ValueError("nonbasis is not a subset of the groundset") - self.__pack(self._b, b) + self._BasisExchangeMatroid__pack(self._b, b) i = set_to_index(self._b) if bitset_in(self._bb, i): self._bcount -= 1 @@ -326,7 +326,7 @@ cdef class BasisMatroid(BasisExchangeMatroid): sage: M._is_basis(set(['a', 'b', 'c', 'd'])) False """ - self.__pack(self._b, X) + self._BasisExchangeMatroid__pack(self._b, X) return bitset_in(self._bb, set_to_index(self._b)) # dual and minors From 9e8ebeb2f7539e2e9769a7ed4b27ca84d6c9c2f2 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:33:10 +0800 Subject: [PATCH 14/44] fix use of private __pack --- src/sage/matroids/linear_matroid.pyx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sage/matroids/linear_matroid.pyx b/src/sage/matroids/linear_matroid.pyx index abaf28bbc5b..dd29eb157a6 100644 --- a/src/sage/matroids/linear_matroid.pyx +++ b/src/sage/matroids/linear_matroid.pyx @@ -3184,7 +3184,7 @@ cdef class BinaryMatroid(LinearMatroid): bitset_complement(R, F) bitset_difference(self._inside, self._current_basis, R) bitset_difference(self._outside, R, self._current_basis) - self.__move(self._inside, self._outside) + self._BasisExchangeMatroid__move(self._inside, self._outside) bitset_copy(R, F) bitset_difference(self._inside, self._current_basis, F) @@ -4252,7 +4252,7 @@ cdef class TernaryMatroid(LinearMatroid): bitset_complement(R, F) bitset_difference(self._inside, self._current_basis, R) bitset_difference(self._outside, R, self._current_basis) - self.__move(self._inside, self._outside) + self._BasisExchangeMatroid__move(self._inside, self._outside) bitset_copy(R, F) bitset_difference(self._inside, self._current_basis, F) @@ -5154,7 +5154,7 @@ cdef class QuaternaryMatroid(LinearMatroid): bitset_complement(R, F) bitset_difference(self._inside, self._current_basis, R) bitset_difference(self._outside, R, self._current_basis) - self.__move(self._inside, self._outside) + self._BasisExchangeMatroid__move(self._inside, self._outside) bitset_copy(R, F) bitset_difference(self._inside, self._current_basis, F) From 4d19b07fdf85616bd7f4f3c28cd624025f812e2e Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:34:59 +0800 Subject: [PATCH 15/44] rename __modulus -> _modulus --- src/sage/libs/ntl/ntl_lzz_p.pyx | 6 +- src/sage/libs/ntl/ntl_lzz_pX.pyx | 6 +- src/sage/rings/finite_rings/integer_mod.pxd | 2 +- src/sage/rings/finite_rings/integer_mod.pyx | 208 ++++++++++---------- src/sage/rings/fraction_field_FpT.pyx | 2 +- 5 files changed, 112 insertions(+), 112 deletions(-) diff --git a/src/sage/libs/ntl/ntl_lzz_p.pyx b/src/sage/libs/ntl/ntl_lzz_p.pyx index 161d0782bc2..af86b9bcf69 100644 --- a/src/sage/libs/ntl/ntl_lzz_p.pyx +++ b/src/sage/libs/ntl/ntl_lzz_p.pyx @@ -89,19 +89,19 @@ cdef class ntl_zz_p(): #self.c.restore_c() ## This was done in __new__ if isinstance(a, IntegerMod_int): - if (self.c.p == (a).__modulus.int32): ## this is slow + if (self.c.p == (a)._modulus.int32): ## this is slow self.x = (a).ivalue else: raise ValueError("Mismatched modulus for converting to zz_p.") elif isinstance(a, IntegerMod_int64): - if (self.c.p == (a).__modulus.int64): ## this is slow + if (self.c.p == (a)._modulus.int64): ## this is slow self.x = (a).ivalue else: raise ValueError("Mismatched modulus for converting to zz_p.") elif isinstance(a, IntegerMod_gmp): - if (p_sage == (a).__modulus.sageInteger): ## this is slow + if (p_sage == (a)._modulus.sageInteger): ## this is slow self.x = mpz_get_si((a).value) else: raise ValueError("Mismatched modulus for converting to zz_p.") diff --git a/src/sage/libs/ntl/ntl_lzz_pX.pyx b/src/sage/libs/ntl/ntl_lzz_pX.pyx index 24b503a9a62..7d19cc55e37 100644 --- a/src/sage/libs/ntl/ntl_lzz_pX.pyx +++ b/src/sage/libs/ntl/ntl_lzz_pX.pyx @@ -108,17 +108,17 @@ cdef class ntl_zz_pX(): a = ls[i] if isinstance(a, IntegerMod_int): - if (self.c.p == (a).__modulus.int32): ## this is slow + if (self.c.p == (a)._modulus.int32): ## this is slow zz_pX_SetCoeff_long(self.x, i, (a).ivalue) else: raise ValueError("Mismatched modulus for converting to zz_pX.") elif isinstance(a, IntegerMod_int64): - if (self.c.p == (a).__modulus.int64): ## this is slow + if (self.c.p == (a)._modulus.int64): ## this is slow zz_pX_SetCoeff_long(self.x, i, (a).ivalue) else: raise ValueError("Mismatched modulus for converting to zz_pX.") elif isinstance(a, IntegerMod_gmp): - if (p_sage == (a).__modulus.sageInteger): ## this is slow + if (p_sage == (a)._modulus.sageInteger): ## this is slow zz_pX_SetCoeff_long(self.x, i, mpz_get_si((a).value)) else: raise ValueError("Mismatched modulus for converting to zz_pX.") diff --git a/src/sage/rings/finite_rings/integer_mod.pxd b/src/sage/rings/finite_rings/integer_mod.pxd index 1e3cb81c148..351ffa25e1b 100644 --- a/src/sage/rings/finite_rings/integer_mod.pxd +++ b/src/sage/rings/finite_rings/integer_mod.pxd @@ -20,7 +20,7 @@ cdef class NativeIntStruct: cdef class IntegerMod_abstract(FiniteRingElement): - cdef NativeIntStruct __modulus + cdef NativeIntStruct _modulus cdef _new_c_from_long(self, long value) cdef IntegerMod_abstract _new_c_fast(self, unsigned long value) cdef void set_from_mpz(self, mpz_t value) diff --git a/src/sage/rings/finite_rings/integer_mod.pyx b/src/sage/rings/finite_rings/integer_mod.pyx index 9a77aadd7c3..3bb48513faa 100644 --- a/src/sage/rings/finite_rings/integer_mod.pyx +++ b/src/sage/rings/finite_rings/integer_mod.pyx @@ -356,7 +356,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): ZeroDivisionError: inverse of Mod(4, 30) does not exist """ self._parent = parent - self.__modulus = parent._pyx_order + self._modulus = parent._pyx_order if value is None: return @@ -368,7 +368,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): if isinstance(value, Integer): z = value elif isinstance(value, rational.Rational): - z = value % self.__modulus.sageInteger + z = value % self._modulus.sageInteger elif integer_check_long_py(value, &longval, &err) and not err: self.set_from_long(longval) return @@ -383,7 +383,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): value = py_scalar_to_element(value) if isinstance(value, Element) and value.parent().is_exact(): value = sage.rings.rational_field.QQ(value) - z = value % self.__modulus.sageInteger + z = value % self._modulus.sageInteger else: raise self.set_from_mpz(z.value) @@ -392,7 +392,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): cdef type t = type(self) x = t.__new__(t) x._parent = self._parent - x.__modulus = self.__modulus + x._modulus = self._modulus x.set_from_ulong_fast(value) return x @@ -400,7 +400,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): cdef type t = type(self) cdef IntegerMod_abstract x = t.__new__(t) x._parent = self._parent - x.__modulus = self.__modulus + x._modulus = self._modulus x.set_from_long(value) return x @@ -524,17 +524,17 @@ cdef class IntegerMod_abstract(FiniteRingElement): """ if self.is_zero(): return True - m = self.__modulus.sageInteger.exact_log(2) + 1 + m = self._modulus.sageInteger.exact_log(2) + 1 return (self**m).is_zero() ################################################################# # Interfaces ################################################################# def _pari_init_(self): - return 'Mod(%s,%s)'%(str(self), self.__modulus.sageInteger) + return 'Mod(%s,%s)'%(str(self), self._modulus.sageInteger) def __pari__(self): - return self.lift().__pari__().Mod(self.__modulus.sageInteger) + return self.lift().__pari__().Mod(self._modulus.sageInteger) def _gap_init_(self): r""" @@ -552,7 +552,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): sage: gap(Mod(4, 48)) # optional - sage.libs.gap ZmodnZObj( 4, 48 ) """ - return '%s*One(ZmodnZ(%s))' % (self, self.__modulus.sageInteger) + return '%s*One(ZmodnZ(%s))' % (self, self._modulus.sageInteger) def _magma_init_(self, magma): """ @@ -858,7 +858,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): sage: Mod(3,17).modulus() 17 """ - return self.__modulus.sageInteger + return self._modulus.sageInteger def charpoly(self, var='x'): """ @@ -1211,7 +1211,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): modulus = R.gen()**2 - R(self) if self._parent.is_field(): from .finite_field_constructor import FiniteField - Q = FiniteField(self.__modulus.sageInteger**2, y, modulus) + Q = FiniteField(self._modulus.sageInteger**2, y, modulus) else: R = self.parent()['x'] Q = R.quotient(modulus, names=(y,)) @@ -1232,7 +1232,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): if all and e > 1 and not self.is_unit(): if self.is_zero(): # All multiples of p^ciel(e/2) vanish - return [self._parent(x) for x in range(0, self.__modulus.sageInteger, p**((e+1)/2))] + return [self._parent(x) for x in range(0, self._modulus.sageInteger, p**((e+1)/2))] else: z = self.lift() val = z.valuation(p)/2 # square => valuation is even @@ -1254,7 +1254,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): p_exp = p**exp w = [self._parent(a.lift() * p_val + b) for a in u.sqrt(all=True) - for b in range(0, self.__modulus.sageInteger, p_exp)] + for b in range(0, self._modulus.sageInteger, p_exp)] if p == 2: w = list(set(w)) w.sort() @@ -1603,7 +1603,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): despite the possibly probabilistic nature of the underlying algorithm. """ - if self.lift() > self.__modulus.sageInteger >> 1: + if self.lift() > self._modulus.sageInteger >> 1: return -self return self @@ -1684,8 +1684,8 @@ cdef class IntegerMod_abstract(FiniteRingElement): cdef int_fast64_t new_modulus if not isinstance(self, IntegerMod_gmp) and not isinstance(other, IntegerMod_gmp): - if other.__modulus.int64 == 1: return self - new_modulus = self.__modulus.int64 * other.__modulus.int64 + if other._modulus.int64 == 1: return self + new_modulus = self._modulus.int64 * other._modulus.int64 if new_modulus < INTEGER_MOD_INT32_LIMIT: return self.__crt(other) @@ -1697,11 +1697,11 @@ cdef class IntegerMod_abstract(FiniteRingElement): return self.__crt(other) if not isinstance(self, IntegerMod_gmp): - if self.__modulus.int64 == 1: return other + if self._modulus.int64 == 1: return other self = IntegerMod_gmp(self._parent, self.lift()) if not isinstance(other, IntegerMod_gmp): - if other.__modulus.int64 == 1: return self + if other._modulus.int64 == 1: return self other = IntegerMod_gmp(other._parent, other.lift()) return self.__crt(other) @@ -1721,7 +1721,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): sage: Integers(90308402384902)(2).additive_order() 45154201192451 """ - n = self.__modulus.sageInteger + n = self._modulus.sageInteger return sage.rings.integer.Integer(n // self.lift().gcd(n)) def is_primitive_root(self): @@ -1835,7 +1835,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): return sage.rings.integer.Integer(self.__pari__().znorder()) except PariError: raise ArithmeticError("multiplicative order of %s not defined since it is not a unit modulo %s"%( - self, self.__modulus.sageInteger)) + self, self._modulus.sageInteger)) def valuation(self, p): """ @@ -1884,7 +1884,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): 2 """ - p=self.__modulus.sageInteger.gcd(p) + p=self._modulus.sageInteger.gcd(p) if p==1: raise ValueError("Valuation with respect to a unit is not defined.") r = 0 @@ -1892,7 +1892,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): while not (self % power): # self % power == 0 r += 1 power *= p - if not power.divides(self.__modulus.sageInteger): + if not power.divides(self._modulus.sageInteger): from sage.rings.infinity import infinity return infinity return r @@ -1959,7 +1959,7 @@ cdef class IntegerMod_gmp(IntegerMod_abstract): cdef IntegerMod_gmp _new_c(self): cdef IntegerMod_gmp x x = IntegerMod_gmp.__new__(IntegerMod_gmp) - x.__modulus = self.__modulus + x._modulus = self._modulus x._parent = self._parent return x @@ -1968,7 +1968,7 @@ cdef class IntegerMod_gmp(IntegerMod_abstract): cdef void set_from_mpz(self, mpz_t value): cdef sage.rings.integer.Integer modulus - modulus = self.__modulus.sageInteger + modulus = self._modulus.sageInteger mpz_mod(self.value, value, modulus.value) cdef void set_from_long(self, long value): @@ -1980,7 +1980,7 @@ cdef class IntegerMod_gmp(IntegerMod_abstract): 1 """ mpz_set_si(self.value, value) - mpz_mod(self.value, self.value, self.__modulus.sageInteger.value) + mpz_mod(self.value, self.value, self._modulus.sageInteger.value) cdef void set_from_ulong_fast(self, unsigned long value): mpz_set_ui(self.value, value) @@ -2050,7 +2050,7 @@ cdef class IntegerMod_gmp(IntegerMod_abstract): x = self._new_c() if k > 0: mpz_mul_2exp(x.value, self.value, k) - mpz_fdiv_r(x.value, x.value, self.__modulus.sageInteger.value) + mpz_fdiv_r(x.value, x.value, self._modulus.sageInteger.value) else: mpz_fdiv_q_2exp(x.value, self.value, -k) return x @@ -2115,8 +2115,8 @@ cdef class IntegerMod_gmp(IntegerMod_abstract): cdef IntegerMod_gmp lift, x cdef sage.rings.integer.Integer modulus, other_modulus - modulus = self.__modulus.sageInteger - other_modulus = other.__modulus.sageInteger + modulus = self._modulus.sageInteger + other_modulus = other._modulus.sageInteger from .integer_mod_ring import IntegerModRing lift = IntegerMod_gmp(IntegerModRing(modulus*other_modulus)) try: @@ -2167,8 +2167,8 @@ cdef class IntegerMod_gmp(IntegerMod_abstract): cdef IntegerMod_gmp x x = self._new_c() mpz_add(x.value, self.value, (right).value) - if mpz_cmp(x.value, self.__modulus.sageInteger.value) >= 0: - mpz_sub(x.value, x.value, self.__modulus.sageInteger.value) + if mpz_cmp(x.value, self._modulus.sageInteger.value) >= 0: + mpz_sub(x.value, x.value, self._modulus.sageInteger.value) return x cpdef _sub_(self, right): @@ -2183,7 +2183,7 @@ cdef class IntegerMod_gmp(IntegerMod_abstract): x = self._new_c() mpz_sub(x.value, self.value, (right).value) if mpz_sgn(x.value) == -1: - mpz_add(x.value, x.value, self.__modulus.sageInteger.value) + mpz_add(x.value, x.value, self._modulus.sageInteger.value) return x cpdef _neg_(self): @@ -2199,7 +2199,7 @@ cdef class IntegerMod_gmp(IntegerMod_abstract): return self cdef IntegerMod_gmp x x = self._new_c() - mpz_sub(x.value, self.__modulus.sageInteger.value, self.value) + mpz_sub(x.value, self._modulus.sageInteger.value, self.value) return x cpdef _mul_(self, right): @@ -2213,7 +2213,7 @@ cdef class IntegerMod_gmp(IntegerMod_abstract): cdef IntegerMod_gmp x x = self._new_c() mpz_mul(x.value, self.value, (right).value) - mpz_fdiv_r(x.value, x.value, self.__modulus.sageInteger.value) + mpz_fdiv_r(x.value, x.value, self._modulus.sageInteger.value) return x cpdef _div_(self, right): @@ -2289,7 +2289,7 @@ cdef class IntegerMod_gmp(IntegerMod_abstract): cdef IntegerMod_gmp x = self._new_c() sig_on() try: - mpz_pow_helper(x.value, self.value, exp, self.__modulus.sageInteger.value) + mpz_pow_helper(x.value, self.value, exp, self._modulus.sageInteger.value) finally: sig_off() return x @@ -2310,12 +2310,12 @@ cdef class IntegerMod_gmp(IntegerMod_abstract): ZeroDivisionError: inverse of Mod(2, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) does not exist """ if self.is_zero(): - raise ZeroDivisionError(f"inverse of Mod(0, {self.__modulus.sageInteger}) does not exist") + raise ZeroDivisionError(f"inverse of Mod(0, {self._modulus.sageInteger}) does not exist") cdef IntegerMod_gmp x x = self._new_c() - if not mpz_invert(x.value, self.value, self.__modulus.sageInteger.value): - raise ZeroDivisionError(f"inverse of Mod({self}, {self.__modulus.sageInteger}) does not exist") + if not mpz_invert(x.value, self.value, self._modulus.sageInteger.value): + raise ZeroDivisionError(f"inverse of Mod({self}, {self._modulus.sageInteger}) does not exist") return x def lift(IntegerMod_gmp self): @@ -2370,10 +2370,10 @@ cdef class IntegerMod_gmp(IntegerMod_abstract): """ cdef IntegerMod_gmp ans = self._new_c() sig_on() - mpz_gcd(ans.value, self.value, self.__modulus.sageInteger.value) + mpz_gcd(ans.value, self.value, self._modulus.sageInteger.value) mpz_gcd(ans.value, ans.value, other.value) sig_off() - if mpz_cmp(ans.value, self.__modulus.sageInteger.value) == 0: + if mpz_cmp(ans.value, self._modulus.sageInteger.value) == 0: # self = other = 0 mpz_set_ui(ans.value, 0) return ans @@ -2401,30 +2401,30 @@ cdef class IntegerMod_int(IntegerMod_abstract): """ cdef IntegerMod_int _new_c(self, int_fast32_t value): - if self.__modulus.table is not None: - return self.__modulus.table[value] + if self._modulus.table is not None: + return self._modulus.table[value] cdef IntegerMod_int x = IntegerMod_int.__new__(IntegerMod_int) x._parent = self._parent - x.__modulus = self.__modulus + x._modulus = self._modulus x.ivalue = value return x cdef void set_from_mpz(self, mpz_t value): - self.ivalue = mpz_fdiv_ui(value, self.__modulus.int32) + self.ivalue = mpz_fdiv_ui(value, self._modulus.int32) cdef void set_from_long(self, long value): - self.ivalue = value % self.__modulus.int32 + self.ivalue = value % self._modulus.int32 if self.ivalue < 0: - self.ivalue += self.__modulus.int32 + self.ivalue += self._modulus.int32 cdef void set_from_ulong_fast(self, unsigned long value): self.ivalue = value cdef void set_from_int(IntegerMod_int self, int_fast32_t ivalue): if ivalue < 0: - self.ivalue = self.__modulus.int32 + (ivalue % self.__modulus.int32) - elif ivalue >= self.__modulus.int32: - self.ivalue = ivalue % self.__modulus.int32 + self.ivalue = self._modulus.int32 + (ivalue % self._modulus.int32) + elif ivalue >= self._modulus.int32: + self.ivalue = ivalue % self._modulus.int32 else: self.ivalue = ivalue @@ -2469,7 +2469,7 @@ cdef class IntegerMod_int(IntegerMod_abstract): sage: Zmod(1).one().is_one() True """ - return self.ivalue == 1 or self.__modulus.int32 == 1 + return self.ivalue == 1 or self._modulus.int32 == 1 def __bool__(IntegerMod_int self): """ @@ -2498,7 +2498,7 @@ cdef class IntegerMod_int(IntegerMod_abstract): sage: a.is_unit() False """ - return gcd_int(self.ivalue, self.__modulus.int32) == 1 + return gcd_int(self.ivalue, self._modulus.int32) == 1 def __crt(IntegerMod_int self, IntegerMod_int other): """ @@ -2522,11 +2522,11 @@ cdef class IntegerMod_int(IntegerMod_abstract): cdef int_fast32_t x from .integer_mod_ring import IntegerModRing - lift = IntegerMod_int(IntegerModRing(self.__modulus.int32 * other.__modulus.int32)) + lift = IntegerMod_int(IntegerModRing(self._modulus.int32 * other._modulus.int32)) try: - x = (other.ivalue - self.ivalue % other.__modulus.int32) * mod_inverse_int(self.__modulus.int32, other.__modulus.int32) - lift.set_from_int( x * self.__modulus.int32 + self.ivalue ) + x = (other.ivalue - self.ivalue % other._modulus.int32) * mod_inverse_int(self._modulus.int32, other._modulus.int32) + lift.set_from_int( x * self._modulus.int32 + self.ivalue ) return lift except ZeroDivisionError: raise ZeroDivisionError("moduli must be coprime") @@ -2565,8 +2565,8 @@ cdef class IntegerMod_int(IntegerMod_abstract): """ cdef int_fast32_t x x = self.ivalue + (right).ivalue - if x >= self.__modulus.int32: - x = x - self.__modulus.int32 + if x >= self._modulus.int32: + x = x - self._modulus.int32 return self._new_c(x) cpdef _sub_(self, right): @@ -2580,7 +2580,7 @@ cdef class IntegerMod_int(IntegerMod_abstract): cdef int_fast32_t x x = self.ivalue - (right).ivalue if x < 0: - x = x + self.__modulus.int32 + x = x + self._modulus.int32 return self._new_c(x) cpdef _neg_(self): @@ -2594,7 +2594,7 @@ cdef class IntegerMod_int(IntegerMod_abstract): """ if self.ivalue == 0: return self - return self._new_c(self.__modulus.int32 - self.ivalue) + return self._new_c(self._modulus.int32 - self.ivalue) cpdef _mul_(self, right): """ @@ -2604,7 +2604,7 @@ cdef class IntegerMod_int(IntegerMod_abstract): sage: R(7) * R(8) 6 """ - return self._new_c((self.ivalue * (right).ivalue) % self.__modulus.int32) + return self._new_c((self.ivalue * (right).ivalue) % self._modulus.int32) cpdef _div_(self, right): """ @@ -2614,16 +2614,16 @@ cdef class IntegerMod_int(IntegerMod_abstract): sage: R(2)/3 4 """ - if self.__modulus.inverses is not None: - right_inverse = self.__modulus.inverses[(right).ivalue] + if self._modulus.inverses is not None: + right_inverse = self._modulus.inverses[(right).ivalue] if right_inverse is None: - raise ZeroDivisionError(f"inverse of Mod({right}, {self.__modulus.sageInteger}) does not exist") + raise ZeroDivisionError(f"inverse of Mod({right}, {self._modulus.sageInteger}) does not exist") else: - return self._new_c((self.ivalue * (right_inverse).ivalue) % self.__modulus.int32) + return self._new_c((self.ivalue * (right_inverse).ivalue) % self._modulus.int32) cdef int_fast32_t x - x = self.ivalue * mod_inverse_int((right).ivalue, self.__modulus.int32) - return self._new_c(x% self.__modulus.int32) + x = self.ivalue * mod_inverse_int((right).ivalue, self._modulus.int32) + return self._new_c(x% self._modulus.int32) def __int__(IntegerMod_int self): """ @@ -2718,7 +2718,7 @@ cdef class IntegerMod_int(IntegerMod_abstract): if k == 0: return self elif k > 0: - return self._new_c((self.ivalue << k) % self.__modulus.int32) + return self._new_c((self.ivalue << k) % self._modulus.int32) else: return self._new_c(self.ivalue >> (-k)) @@ -2781,7 +2781,7 @@ cdef class IntegerMod_int(IntegerMod_abstract): sig_on() try: mpz_init(res_mpz) - mpz_pow_helper(res_mpz, (base).value, exp, self.__modulus.sageInteger.value) + mpz_pow_helper(res_mpz, (base).value, exp, self._modulus.sageInteger.value) res = mpz_get_ui(res_mpz) mpz_clear(res_mpz) finally: @@ -2790,12 +2790,12 @@ cdef class IntegerMod_int(IntegerMod_abstract): if long_exp == 0 and self.ivalue == 0: # Return 0 if the modulus is 1, otherwise return 1. - return self._new_c(self.__modulus.int32 != 1) + return self._new_c(self._modulus.int32 != 1) cdef bint invert = False if long_exp < 0: invert = True long_exp = -long_exp - res = mod_pow_int(self.ivalue, long_exp, self.__modulus.int32) + res = mod_pow_int(self.ivalue, long_exp, self._modulus.int32) if invert: return ~self._new_c(res) else: @@ -2812,14 +2812,14 @@ cdef class IntegerMod_int(IntegerMod_abstract): sage: Mod(0,1)^-1 0 """ - if self.__modulus.inverses is not None: - x = self.__modulus.inverses[self.ivalue] + if self._modulus.inverses is not None: + x = self._modulus.inverses[self.ivalue] if x is None: - raise ZeroDivisionError(f"inverse of Mod({self}, {self.__modulus.sageInteger}) does not exist") + raise ZeroDivisionError(f"inverse of Mod({self}, {self._modulus.sageInteger}) does not exist") else: return x else: - return self._new_c(mod_inverse_int(self.ivalue, self.__modulus.int32)) + return self._new_c(mod_inverse_int(self.ivalue, self._modulus.int32)) def lift(IntegerMod_int self): """ @@ -2982,15 +2982,15 @@ cdef class IntegerMod_int(IntegerMod_abstract): sage: GF(103)(-1).sqrt(extend=False, all=True) # optional - sage.rings.finite_rings [] """ - cdef int_fast32_t i, n = self.__modulus.int32 + cdef int_fast32_t i, n = self._modulus.int32 if n > 100: moduli = self._parent.factored_order() # Unless the modulus is tiny, test to see if we're in the really # easy case of n prime, n = 3 mod 4. if n > 100 and n % 4 == 3 and len(moduli) == 1 and moduli[0][1] == 1: - if jacobi_int(self.ivalue, self.__modulus.int32) == 1: + if jacobi_int(self.ivalue, self._modulus.int32) == 1: # it's a non-zero square, sqrt(a) = a^(p+1)/4 - i = mod_pow_int(self.ivalue, (self.__modulus.int32+1)/4, n) + i = mod_pow_int(self.ivalue, (self._modulus.int32+1)/4, n) if i > n / 2: i = n - i if all: @@ -3025,7 +3025,7 @@ cdef class IntegerMod_int(IntegerMod_abstract): 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: + if self.ivalue > self._modulus.int32 / 2: return -self return self @@ -3058,9 +3058,9 @@ cdef class IntegerMod_int(IntegerMod_abstract): sage: mod(0,1).gcd(mod(0,1)) 0 """ - cdef int_fast32_t g = gcd_int(self.ivalue, self.__modulus.int32) + cdef int_fast32_t g = gcd_int(self.ivalue, self._modulus.int32) g = gcd_int(g, other.ivalue) - if g == self.__modulus.int32: # self = other = 0 + if g == self._modulus.int32: # self = other = 0 g = 0 return self._new_c(g) @@ -3232,27 +3232,27 @@ cdef class IntegerMod_int64(IntegerMod_abstract): cdef IntegerMod_int64 _new_c(self, int_fast64_t value): cdef IntegerMod_int64 x x = IntegerMod_int64.__new__(IntegerMod_int64) - x.__modulus = self.__modulus + x._modulus = self._modulus x._parent = self._parent x.ivalue = value return x cdef void set_from_mpz(self, mpz_t value): - self.ivalue = mpz_fdiv_ui(value, self.__modulus.int64) + self.ivalue = mpz_fdiv_ui(value, self._modulus.int64) cdef void set_from_long(self, long value): - self.ivalue = value % self.__modulus.int64 + self.ivalue = value % self._modulus.int64 if self.ivalue < 0: - self.ivalue += self.__modulus.int64 + self.ivalue += self._modulus.int64 cdef void set_from_ulong_fast(self, unsigned long value): self.ivalue = value cdef void set_from_int(IntegerMod_int64 self, int_fast64_t ivalue): if ivalue < 0: - self.ivalue = self.__modulus.int64 + (ivalue % self.__modulus.int64) # Is ivalue % self.__modulus.int64 actually negative? - elif ivalue >= self.__modulus.int64: - self.ivalue = ivalue % self.__modulus.int64 + self.ivalue = self._modulus.int64 + (ivalue % self._modulus.int64) # Is ivalue % self._modulus.int64 actually negative? + elif ivalue >= self._modulus.int64: + self.ivalue = ivalue % self._modulus.int64 else: self.ivalue = ivalue @@ -3320,7 +3320,7 @@ cdef class IntegerMod_int64(IntegerMod_abstract): sage: mod(25, 5^10).is_unit() False """ - return gcd_int64(self.ivalue, self.__modulus.int64) == 1 + return gcd_int64(self.ivalue, self._modulus.int64) == 1 def __crt(IntegerMod_int64 self, IntegerMod_int64 other): """ @@ -3355,11 +3355,11 @@ cdef class IntegerMod_int64(IntegerMod_abstract): cdef int_fast64_t x from .integer_mod_ring import IntegerModRing - lift = IntegerMod_int64(IntegerModRing(self.__modulus.int64 * other.__modulus.int64)) + lift = IntegerMod_int64(IntegerModRing(self._modulus.int64 * other._modulus.int64)) try: - x = (other.ivalue - self.ivalue % other.__modulus.int64) * mod_inverse_int64(self.__modulus.int64, other.__modulus.int64) - lift.set_from_int( x * self.__modulus.int64 + self.ivalue ) + x = (other.ivalue - self.ivalue % other._modulus.int64) * mod_inverse_int64(self._modulus.int64, other._modulus.int64) + lift.set_from_int( x * self._modulus.int64 + self.ivalue ) return lift except ZeroDivisionError: raise ZeroDivisionError("moduli must be coprime") @@ -3398,8 +3398,8 @@ cdef class IntegerMod_int64(IntegerMod_abstract): """ cdef int_fast64_t x x = self.ivalue + (right).ivalue - if x >= self.__modulus.int64: - x = x - self.__modulus.int64 + if x >= self._modulus.int64: + x = x - self._modulus.int64 return self._new_c(x) cpdef _sub_(self, right): @@ -3413,7 +3413,7 @@ cdef class IntegerMod_int64(IntegerMod_abstract): cdef int_fast64_t x x = self.ivalue - (right).ivalue if x < 0: - x = x + self.__modulus.int64 + x = x + self._modulus.int64 return self._new_c(x) cpdef _neg_(self): @@ -3427,7 +3427,7 @@ cdef class IntegerMod_int64(IntegerMod_abstract): """ if self.ivalue == 0: return self - return self._new_c(self.__modulus.int64 - self.ivalue) + return self._new_c(self._modulus.int64 - self.ivalue) cpdef _mul_(self, right): """ @@ -3437,7 +3437,7 @@ cdef class IntegerMod_int64(IntegerMod_abstract): sage: R(700) * R(800) 60000 """ - return self._new_c((self.ivalue * (right).ivalue) % self.__modulus.int64) + return self._new_c((self.ivalue * (right).ivalue) % self._modulus.int64) cpdef _div_(self, right): @@ -3449,7 +3449,7 @@ cdef class IntegerMod_int64(IntegerMod_abstract): 33334 """ return self._new_c((self.ivalue * mod_inverse_int64((right).ivalue, - self.__modulus.int64) ) % self.__modulus.int64) + self._modulus.int64) ) % self._modulus.int64) def __int__(IntegerMod_int64 self): return self.ivalue @@ -3535,7 +3535,7 @@ cdef class IntegerMod_int64(IntegerMod_abstract): if k == 0: return self elif k > 0: - return self._new_c((self.ivalue << k) % self.__modulus.int64) + return self._new_c((self.ivalue << k) % self._modulus.int64) else: return self._new_c(self.ivalue >> (-k)) @@ -3609,7 +3609,7 @@ cdef class IntegerMod_int64(IntegerMod_abstract): sig_on() try: mpz_init(res_mpz) - mpz_pow_helper(res_mpz, (base).value, exp, self.__modulus.sageInteger.value) + mpz_pow_helper(res_mpz, (base).value, exp, self._modulus.sageInteger.value) res = mpz_get_ui(res_mpz) mpz_clear(res_mpz) finally: @@ -3618,14 +3618,14 @@ cdef class IntegerMod_int64(IntegerMod_abstract): if long_exp == 0 and self.ivalue == 0: # Return 0 if the modulus is 1, otherwise return 1. - return self._new_c(self.__modulus.int64 != 1) + return self._new_c(self._modulus.int64 != 1) cdef bint invert = False if long_exp < 0: invert = True long_exp = -long_exp - res = mod_pow_int64(self.ivalue, long_exp, self.__modulus.int64) + res = mod_pow_int64(self.ivalue, long_exp, self._modulus.int64) if invert: - return self._new_c(mod_inverse_int64(res, self.__modulus.int64)) + return self._new_c(mod_inverse_int64(res, self._modulus.int64)) else: return self._new_c(res) @@ -3642,7 +3642,7 @@ cdef class IntegerMod_int64(IntegerMod_abstract): sage: a 7 """ - return self._new_c(mod_inverse_int64(self.ivalue, self.__modulus.int64)) + return self._new_c(mod_inverse_int64(self.ivalue, self._modulus.int64)) def lift(IntegerMod_int64 self): """ @@ -3691,7 +3691,7 @@ cdef class IntegerMod_int64(IntegerMod_abstract): 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: + if self.ivalue > self._modulus.int64 / 2: return -self return self @@ -3714,9 +3714,9 @@ cdef class IntegerMod_int64(IntegerMod_abstract): sage: mod(0,17^5).gcd(mod(0,17^5)) 0 """ - cdef int_fast64_t g = gcd_int64(self.ivalue, self.__modulus.int64) + cdef int_fast64_t g = gcd_int64(self.ivalue, self._modulus.int64) g = gcd_int64(g, other.ivalue) - if g == self.__modulus.int64: # self = other = 0 + if g == self._modulus.int64: # self = other = 0 g = 0 return self._new_c(g) diff --git a/src/sage/rings/fraction_field_FpT.pyx b/src/sage/rings/fraction_field_FpT.pyx index 0a25191a11c..c9bb5d5a384 100644 --- a/src/sage/rings/fraction_field_FpT.pyx +++ b/src/sage/rings/fraction_field_FpT.pyx @@ -1650,7 +1650,7 @@ cdef class FpT_Fp_section(Section): raise ValueError("not constant") ans = IntegerMod_int.__new__(IntegerMod_int) ans._parent = self.codomain() - ans.__modulus = ans._parent._pyx_order + ans._modulus = ans._parent._pyx_order if nmod_poly_get_coeff_ui(x._denom, 0) != 1: normalize(x._numer, x._denom, self.p) ans.ivalue = nmod_poly_get_coeff_ui(x._numer, 0) From 945435c363152bea254e6d0237fae739651648e8 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:36:18 +0800 Subject: [PATCH 16/44] rename __normalize -> _normalize --- .../libs/linkages/padics/Polynomial_ram.pxi | 2 +- src/sage/modular/modsym/p1list.pxd | 2 +- src/sage/modular/modsym/p1list.pyx | 14 +++---- .../rings/laurent_series_ring_element.pxd | 2 +- .../rings/laurent_series_ring_element.pyx | 4 +- .../rings/polynomial/laurent_polynomial.pxd | 2 +- .../rings/polynomial/laurent_polynomial.pyx | 40 +++++++++---------- .../polynomial/ore_polynomial_element.pxd | 2 +- .../polynomial/ore_polynomial_element.pyx | 10 ++--- .../rings/polynomial/polynomial_element.pxd | 2 +- .../rings/polynomial/polynomial_element.pyx | 24 +++++------ 11 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/sage/libs/linkages/padics/Polynomial_ram.pxi b/src/sage/libs/linkages/padics/Polynomial_ram.pxi index 1ac51f1211f..4a8e0b11d83 100644 --- a/src/sage/libs/linkages/padics/Polynomial_ram.pxi +++ b/src/sage/libs/linkages/padics/Polynomial_ram.pxi @@ -64,7 +64,7 @@ cdef inline bint creduce(celement out, celement a, long prec, PowComputer_ prime if i == break_pt: coeff_prec -= 1 out.__coeffs[i] = out.__coeffs[i].add_bigoh(coeff_prec) - out.__normalize() + out._normalize() return out == 0 cdef inline bint creduce_small(celement out, celement a, long prec, PowComputer_ prime_pow) except -1: diff --git a/src/sage/modular/modsym/p1list.pxd b/src/sage/modular/modsym/p1list.pxd index cc24a33139b..b66f28b8ad6 100644 --- a/src/sage/modular/modsym/p1list.pxd +++ b/src/sage/modular/modsym/p1list.pxd @@ -21,7 +21,7 @@ cdef class P1List: # Here we use a pointer to a function, so the if logic # for normalizing an element does not need to be used # every time the user calls the normalize function. - cdef int (*__normalize)(int N, int u, int v, + cdef int (*_normalize)(int N, int u, int v, int* uu, int* vv, int* ss, int compute_s) except -1 cpdef index(self, int u, int v) diff --git a/src/sage/modular/modsym/p1list.pyx b/src/sage/modular/modsym/p1list.pyx index 78f1c6d647c..79888d512e6 100644 --- a/src/sage/modular/modsym/p1list.pyx +++ b/src/sage/modular/modsym/p1list.pyx @@ -723,10 +723,10 @@ cdef class P1List(): self.__N = N if N <= 46340: self.__list = p1list_int(N) - self.__normalize = c_p1_normalize_int + self._normalize = c_p1_normalize_int elif N <= 2147483647: self.__list = p1list_llong(N) - self.__normalize = c_p1_normalize_llong + self._normalize = c_p1_normalize_llong else: raise OverflowError("p1list not defined for such large N.") self.__list.sort() @@ -921,7 +921,7 @@ cdef class P1List(): """ cdef int u, v, uu, vv, ss u,v = self.__list[i] - self.__normalize(self.__N, -u, v, &uu, &vv, &ss, 0) + self._normalize(self.__N, -u, v, &uu, &vv, &ss, 0) _, j = search(self.__list, (uu,vv)) return j @@ -954,7 +954,7 @@ cdef class P1List(): """ cdef int u, v, uu, vv, ss u,v = self.__list[i] - self.__normalize(self.__N, -v, u, &uu, &vv, &ss, 0) + self._normalize(self.__N, -v, u, &uu, &vv, &ss, 0) _, j = search(self.__list, (uu,vv)) return j @@ -987,7 +987,7 @@ cdef class P1List(): """ cdef int u, v, uu, vv, ss u,v = self.__list[i] - self.__normalize(self.__N, v, -u-v, &uu, &vv, &ss, 0) + self._normalize(self.__N, v, -u-v, &uu, &vv, &ss, 0) _, j = search(self.__list, (uu,vv)) return j @@ -1153,7 +1153,7 @@ cdef class P1List(): True """ cdef int uu, vv, ss - self.__normalize(self.__N, u, v, &uu, &vv, &ss, 0) + self._normalize(self.__N, u, v, &uu, &vv, &ss, 0) return (uu,vv) def normalize_with_scalar(self, int u, int v): @@ -1186,7 +1186,7 @@ cdef class P1List(): True """ cdef int uu, vv, ss - self.__normalize(self.__N, u, v, &uu, &vv, &ss, 1) + self._normalize(self.__N, u, v, &uu, &vv, &ss, 1) return (uu, vv, ss) def N(self): diff --git a/src/sage/rings/laurent_series_ring_element.pxd b/src/sage/rings/laurent_series_ring_element.pxd index d190645ce52..8df5a92c9e7 100644 --- a/src/sage/rings/laurent_series_ring_element.pxd +++ b/src/sage/rings/laurent_series_ring_element.pxd @@ -4,7 +4,7 @@ cdef class LaurentSeries(AlgebraElement): cdef ModuleElement __u cdef long __n - cdef __normalize(self) + cdef _normalize(self) cpdef _add_(self, other) cpdef _mul_(self, other) diff --git a/src/sage/rings/laurent_series_ring_element.pyx b/src/sage/rings/laurent_series_ring_element.pyx index 8e950478045..9bef72396b7 100644 --- a/src/sage/rings/laurent_series_ring_element.pyx +++ b/src/sage/rings/laurent_series_ring_element.pyx @@ -302,7 +302,7 @@ cdef class LaurentSeries(AlgebraElement): x = im_gens[0] return codomain(self.__u._im_gens_(codomain, im_gens, base_map=base_map) * x**self.__n) - cdef __normalize(self): + cdef _normalize(self): r""" A Laurent series is a pair (u(t), n), where either u=0 (to some precision) or u is a unit. This pair corresponds to @@ -725,7 +725,7 @@ cdef class LaurentSeries(AlgebraElement): R = self._parent.base_ring() coeffs = [value] + [R(0) for _ in range(1,-j)] + self.__u.list() self.__u = self.__u._parent(coeffs) - self.__normalize() + self._normalize() cpdef _add_(self, right_m): """ diff --git a/src/sage/rings/polynomial/laurent_polynomial.pxd b/src/sage/rings/polynomial/laurent_polynomial.pxd index 3648d6d1ed1..8e9107aeb47 100644 --- a/src/sage/rings/polynomial/laurent_polynomial.pxd +++ b/src/sage/rings/polynomial/laurent_polynomial.pxd @@ -12,6 +12,6 @@ cdef class LaurentPolynomial(CommutativeAlgebraElement): cdef class LaurentPolynomial_univariate(LaurentPolynomial): cdef ModuleElement __u cdef long __n - cpdef __normalize(self) + cpdef _normalize(self) cpdef _unsafe_mutate(self, i, value) diff --git a/src/sage/rings/polynomial/laurent_polynomial.pyx b/src/sage/rings/polynomial/laurent_polynomial.pyx index b9aa5a69f8e..dc0b207ec2f 100644 --- a/src/sage/rings/polynomial/laurent_polynomial.pyx +++ b/src/sage/rings/polynomial/laurent_polynomial.pyx @@ -361,7 +361,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): # self is that t^n * u: self.__u = f self.__n = n - self.__normalize() + self._normalize() def __reduce__(self): """ @@ -525,7 +525,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): u = u.map_coefficients(base_map) return codomain(u(x) * x**self.__n) - cpdef __normalize(self): + cpdef _normalize(self): r""" A Laurent series is a pair `(u(t), n)`, where either `u = 0` (to some precision) or `u` is a unit. This pair corresponds to @@ -757,7 +757,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): ret = self._new_c() ret.__u = f ret.__n = self.__n - ret.__normalize() + ret._normalize() return ret return self.__u[i - self.__n] @@ -913,7 +913,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): R = self._parent.base_ring() coeffs = [value] + [R.zero() for _ in range(1,-j)] + self.__u.list() self.__u = self.__u._parent(coeffs) - self.__normalize() + self._normalize() cpdef _add_(self, right_m): """ @@ -966,7 +966,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): ret = self._new_c() ret.__u = (f1 + f2) ret.__n = m - ret.__normalize() + ret._normalize() return ret cpdef _sub_(self, right_m): @@ -1006,7 +1006,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): ret = self._new_c() ret.__u = (f1 - f2) ret.__n = m - ret.__normalize() + ret._normalize() return ret def degree(self): @@ -1057,7 +1057,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): ret = self._new_c() ret.__u = (self.__u * right.__u) ret.__n = self.__n + right.__n - ret.__normalize() + ret._normalize() return ret cpdef _rmul_(self, Element c): @@ -1073,7 +1073,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): ret = self._new_c() ret.__u = self.__u._rmul_(c) ret.__n = self.__n - ret.__normalize() + ret._normalize() return ret cpdef _lmul_(self, Element c): @@ -1089,7 +1089,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): ret = self._new_c() ret.__u = self.__u._lmul_(c) ret.__n = self.__n - ret.__normalize() + ret._normalize() return ret def is_monomial(self): @@ -1169,7 +1169,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): ret = self._new_c() ret.__u = (self.__u // right.__u) ret.__n = self.__n - right.__n - ret.__normalize() + ret._normalize() return ret def shift(self, k): @@ -1281,7 +1281,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): if self.__u.is_unit(): ret.__u = self.__u.inverse_of_unit() ret.__n = -self.__n - ret.__normalize() + ret._normalize() return ret # Enlarge the ring so we can divide by the coefficient R = self._parent.base_ring().fraction_field() @@ -1356,7 +1356,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): ret = self._new_c() ret.__u = self.__u.gcd(b.__u) ret.__n = min(self.__n, b.__n) - ret.__normalize() + ret._normalize() return ret @coerce_binop @@ -1402,11 +1402,11 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): ql = self._new_c() ql.__u = q ql.__n = self.__n - right.__n - ql.__normalize() + ql._normalize() qr = self._new_c() qr.__u = r qr.__n = self.__n - qr.__normalize() + qr._normalize() return ql, qr cpdef _richcmp_(self, right_r, int op): @@ -1513,7 +1513,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): ret = self._new_c() ret.__u = self.__u.truncate(n - self.__n) ret.__n = self.__n - ret.__normalize() + ret._normalize() return ret def variable_name(self): @@ -1769,7 +1769,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): ret = self._new_c() ret.__u = self._parent._R(u) ret.__n = self.__n - ret.__normalize() + ret._normalize() return ret except AttributeError: raise ValueError('cannot differentiate with respect to {}'.format(var)) @@ -1784,7 +1784,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): ret = self._new_c() ret.__u = self._parent._R(a) ret.__n = self.__n - 1 - ret.__normalize() + ret._normalize() return ret def integral(self): @@ -1849,7 +1849,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): ret = self._new_c() ret.__u = u ret.__n = n + 1 - ret.__normalize() + ret._normalize() return ret def __call__(self, *x, **kwds): @@ -1911,14 +1911,14 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): u = self._new_c() u.__u = pf.unit() u.__n = self.__n - u.__normalize() + u._normalize() f = [] for t in pf: d = self._new_c() d.__u = t[0] d.__n = 0 - d.__normalize() + d._normalize() if d.is_unit(): u *= d ** t[1] else: diff --git a/src/sage/rings/polynomial/ore_polynomial_element.pxd b/src/sage/rings/polynomial/ore_polynomial_element.pxd index 3a3fe0a0d54..aa36112ab90 100644 --- a/src/sage/rings/polynomial/ore_polynomial_element.pxd +++ b/src/sage/rings/polynomial/ore_polynomial_element.pxd @@ -33,7 +33,7 @@ cdef void lmul_gen(list A, Morphism m, d) cdef class OrePolynomial_generic_dense(OrePolynomial): cdef list _coeffs - cdef void __normalize(self) + cdef void _normalize(self) cpdef _add_(self, other) cdef list _mul_list(self, list A) cpdef _mul_(self, other) diff --git a/src/sage/rings/polynomial/ore_polynomial_element.pyx b/src/sage/rings/polynomial/ore_polynomial_element.pyx index 5b19d50dc3d..90f717f8040 100644 --- a/src/sage/rings/polynomial/ore_polynomial_element.pyx +++ b/src/sage/rings/polynomial/ore_polynomial_element.pyx @@ -2246,7 +2246,7 @@ cdef class OrePolynomial_generic_dense(OrePolynomial): if isinstance(x, list): if check: self._coeffs = [R(t) for t in x] - self.__normalize() + self._normalize() else: self._coeffs = x return @@ -2265,7 +2265,7 @@ cdef class OrePolynomial_generic_dense(OrePolynomial): else: self._coeffs = [R(a, **kwds) for a in x.list()] if check: - self.__normalize() + self._normalize() return elif isinstance(x, int) and x == 0: @@ -2279,7 +2279,7 @@ cdef class OrePolynomial_generic_dense(OrePolynomial): x = [x] if check: self._coeffs = [R(z, **kwds) for z in x] - self.__normalize() + self._normalize() else: self._coeffs = x @@ -2354,10 +2354,10 @@ cdef class OrePolynomial_generic_dense(OrePolynomial): f._parent = P f._coeffs = coeffs if check: - f.__normalize() + f._normalize() return f - cdef void __normalize(self): + cdef void _normalize(self): r""" Remove higher order `0`-coefficients from the representation of ``self``. diff --git a/src/sage/rings/polynomial/polynomial_element.pxd b/src/sage/rings/polynomial/polynomial_element.pxd index e6d935d28fe..f439aef123c 100644 --- a/src/sage/rings/polynomial/polynomial_element.pxd +++ b/src/sage/rings/polynomial/polynomial_element.pxd @@ -50,7 +50,7 @@ cdef class Polynomial(CommutativePolynomial): cdef class Polynomial_generic_dense(Polynomial): cdef Polynomial_generic_dense _new_c(self, list coeffs, Parent P) cdef list __coeffs - cdef int __normalize(self) except -1 + cdef int _normalize(self) except -1 cpdef list list(self, bint copy=*) cdef class Polynomial_generic_dense_inexact(Polynomial_generic_dense): diff --git a/src/sage/rings/polynomial/polynomial_element.pyx b/src/sage/rings/polynomial/polynomial_element.pyx index fcf63acf7fa..ca5edc7cd81 100644 --- a/src/sage/rings/polynomial/polynomial_element.pyx +++ b/src/sage/rings/polynomial/polynomial_element.pyx @@ -11326,7 +11326,7 @@ cdef class Polynomial_generic_dense(Polynomial): if isinstance(x, (list, tuple)): if check: self.__coeffs = [R(t) for t in x] - self.__normalize() + self._normalize() else: self.__coeffs = x return @@ -11351,7 +11351,7 @@ cdef class Polynomial_generic_dense(Polynomial): else: self.__coeffs = [R(a, **kwds) for a in x.list(copy=False)] if check: - self.__normalize() + self._normalize() return elif isinstance(x, int) and x == 0: @@ -11372,7 +11372,7 @@ cdef class Polynomial_generic_dense(Polynomial): # x = [] # zero polynomial if check: self.__coeffs = [R(z, **kwds) for z in x] - self.__normalize() + self._normalize() else: self.__coeffs = x @@ -11474,10 +11474,10 @@ cdef class Polynomial_generic_dense(Polynomial): cdef Polynomial_generic_dense res = self._new_c(v, self._parent) #if not v[len(v)-1]: # "normalize" checks this anyway... - res.__normalize() + res._normalize() return res - cdef int __normalize(self) except -1: + cdef int _normalize(self) except -1: """ TESTS: @@ -11550,7 +11550,7 @@ cdef class Polynomial_generic_dense(Polynomial): if n >= 0 and n < len(self.__coeffs): self.__coeffs[n] = value if n == len(self.__coeffs) and value == 0: - self.__normalize() + self._normalize() elif n < 0: raise IndexError("polynomial coefficient index must be nonnegative") elif value != 0: @@ -11598,7 +11598,7 @@ cdef class Polynomial_generic_dense(Polynomial): P = parent(self) d = P.base_ring()(right) cdef Polynomial_generic_dense res = (self)._new_c([c // d for c in (self).__coeffs], P) - res.__normalize() + res._normalize() return res cpdef _add_(self, right): @@ -11627,7 +11627,7 @@ cdef class Polynomial_generic_dense(Polynomial): cdef list low = [x[i] + y[i] for i from 0 <= i < min] if len(x) == len(y): res = self._new_c(low, self._parent) - res.__normalize() + res._normalize() return res else: return self._new_c(low + high, self._parent) @@ -11648,7 +11648,7 @@ cdef class Polynomial_generic_dense(Polynomial): low = [x[i] - y[i] for i from 0 <= i < min] if len(x) == len(y): res = self._new_c(low, self._parent) - res.__normalize() + res._normalize() return res else: return self._new_c(low + high, self._parent) @@ -11662,7 +11662,7 @@ cdef class Polynomial_generic_dense(Polynomial): cdef Polynomial_generic_dense res = self._new_c(v, self._parent) #if not v[len(v)-1]: # "normalize" checks this anyway... - res.__normalize() + res._normalize() return res cpdef _lmul_(self, Element c): @@ -11674,7 +11674,7 @@ cdef class Polynomial_generic_dense(Polynomial): cdef Polynomial_generic_dense res = self._new_c(v, self._parent) #if not v[len(v)-1]: # "normalize" checks this anyway... - res.__normalize() + res._normalize() return res cpdef constant_coefficient(self): @@ -12076,7 +12076,7 @@ cdef class Polynomial_generic_dense_inexact(Polynomial_generic_dense): - Xavier Caruso (2013-03) """ - cdef int __normalize(self) except -1: + cdef int _normalize(self) except -1: r""" TESTS:: From 98c48fa4ba7b299c7c6e03915d170dae6af11edd Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:36:58 +0800 Subject: [PATCH 17/44] rename __coeffs -> _coeffs --- .../libs/linkages/padics/Polynomial_ram.pxi | 30 ++--- .../linkages/padics/Polynomial_shared.pxi | 50 ++++---- src/sage/rings/padics/CA_template.pxi | 8 +- src/sage/rings/padics/CR_template.pxi | 8 +- src/sage/rings/padics/FM_template.pxi | 8 +- src/sage/rings/padics/FP_template.pxi | 8 +- .../rings/polynomial/polynomial_element.pxd | 2 +- .../rings/polynomial/polynomial_element.pyx | 112 +++++++++--------- 8 files changed, 113 insertions(+), 113 deletions(-) diff --git a/src/sage/libs/linkages/padics/Polynomial_ram.pxi b/src/sage/libs/linkages/padics/Polynomial_ram.pxi index 4a8e0b11d83..e0584ecb8ad 100644 --- a/src/sage/libs/linkages/padics/Polynomial_ram.pxi +++ b/src/sage/libs/linkages/padics/Polynomial_ram.pxi @@ -55,15 +55,15 @@ cdef inline bint creduce(celement out, celement a, long prec, PowComputer_ prime """ cdef celement ared = a % prime_pow.modulus if ared is a and out is not a: - out.__coeffs = ared.__coeffs[:] + out._coeffs = ared._coeffs[:] else: - out.__coeffs = ared.__coeffs + out._coeffs = ared._coeffs cdef long coeff_prec = prec / prime_pow.e + 1 cdef long break_pt = prec % prime_pow.e - for i in range(len(out.__coeffs)): + for i in range(len(out._coeffs)): if i == break_pt: coeff_prec -= 1 - out.__coeffs[i] = out.__coeffs[i].add_bigoh(coeff_prec) + out._coeffs[i] = out._coeffs[i].add_bigoh(coeff_prec) out._normalize() return out == 0 @@ -116,7 +116,7 @@ cdef inline long cvaluation(celement a, long prec, PowComputer_ prime_pow) excep higher. """ - C = a.__coeffs + C = a._coeffs if not C: return prec cdef long ret = maxordp @@ -161,7 +161,7 @@ cdef inline int cshift(celement shifted, celement rem, celement a, long n, long v = cvaluation(a, prec, prime_pow) notrunc = (v >= -n) if notrunc: - rem.__coeffs = [] + rem._coeffs = [] return cshift_notrunc(shifted, a, n, prec, prime_pow, reduce_afterward) if v > 0: b = prime_pow.poly_ring(0) @@ -185,7 +185,7 @@ cdef inline int cshift(celement shifted, celement rem, celement a, long n, long if reduce_afterward: creduce(shifted, a, prec, prime_pow) else: - shifted.__coeffs = a.__coeffs[:] + shifted._coeffs = a._coeffs[:] cdef inline int cshift_notrunc(celement out, celement a, long n, long prec, PowComputer_ prime_pow, bint reduce_afterward) except -1: r""" @@ -236,7 +236,7 @@ cdef inline int cshift_notrunc(celement out, celement a, long n, long prec, PowC if reduce_afterward: creduce(out, a, prec, prime_pow) else: - out.__coeffs = a.__coeffs[:] + out._coeffs = a._coeffs[:] cdef inline int cinvert(celement out, celement a, long prec, PowComputer_ prime_pow) except -1: r""" @@ -253,7 +253,7 @@ cdef inline int cinvert(celement out, celement a, long prec, PowComputer_ prime_ - ``prime_pow`` -- the ``PowComputer`` for the ring """ - out.__coeffs = prime_pow.invert(a, prec).__coeffs + out._coeffs = prime_pow.invert(a, prec)._coeffs creduce(out, out, prec, prime_pow) cdef inline int cdivunit(celement out, celement a, celement b, long prec, PowComputer_ prime_pow) except -1: @@ -335,7 +335,7 @@ cdef inline cexpansion_next(celement value, expansion_mode mode, long curpower, # the following is specific to the ramified over unramified case. modp_rep, term = value[0]._modp_rep(mode == smallest_mode) if term: - value.__coeffs[0] -= modp_rep + value._coeffs[0] -= modp_rep cshift_notrunc(value, value, -1, curpower, prime_pow, False) return term @@ -354,10 +354,10 @@ cdef inline cexpansion_getitem(celement value, long m, PowComputer_ prime_pow): while m >= 0: modp_rep, term = value[0]._modp_rep() if m: - if len(value.__coeffs): - value.__coeffs[0] -= modp_rep + if len(value._coeffs): + value._coeffs[0] -= modp_rep else: - value.__coeffs.append(-modp_rep) + value._coeffs.append(-modp_rep) cshift_notrunc(value, value, -1, 1, prime_pow, False) m -= 1 return term @@ -379,9 +379,9 @@ cdef int cteichmuller(celement out, celement value, long prec, PowComputer_ prim """ if value[0].valuation() > 0: - out.__coeffs = [] + out._coeffs = [] else: - out.__coeffs = [value[0].parent().teichmuller(value[0])] + out._coeffs = [value[0].parent().teichmuller(value[0])] cdef list ccoefficients(celement x, long valshift, long prec, PowComputer_ prime_pow): """ diff --git a/src/sage/libs/linkages/padics/Polynomial_shared.pxi b/src/sage/libs/linkages/padics/Polynomial_shared.pxi index 495dc6b0848..367bbc2f33d 100644 --- a/src/sage/libs/linkages/padics/Polynomial_shared.pxi +++ b/src/sage/libs/linkages/padics/Polynomial_shared.pxi @@ -106,7 +106,7 @@ cdef inline int ccmp(celement a, celement b, long prec, bint reduce_a, bint redu if not (reduce_a or reduce_b): return 0 if a == b else 1 csub(prime_pow.tmp_ccmp_a, a, b, prec, prime_pow) - coeffs = prime_pow.tmp_ccmp_a.__coeffs + coeffs = prime_pow.tmp_ccmp_a._coeffs cdef long i, coeff_prec, break_pt if prime_pow.e == 1: for i in range(prime_pow.tmp_ccmp_a.degree()+1): @@ -186,9 +186,9 @@ cdef inline int cneg(celement out, celement a, long prec, PowComputer_ prime_pow """ cdef celement ma = -a if ma is a: - out.__coeffs = ma.__coeffs[:] + out._coeffs = ma._coeffs[:] else: - out.__coeffs = ma.__coeffs + out._coeffs = ma._coeffs cdef inline int cadd(celement out, celement a, celement b, long prec, PowComputer_ prime_pow) except -1: r""" @@ -211,9 +211,9 @@ cdef inline int cadd(celement out, celement a, celement b, long prec, PowCompute """ cdef celement sm = a + b if sm is a or sm is b: - out.__coeffs = sm.__coeffs[:] + out._coeffs = sm._coeffs[:] else: - out.__coeffs = sm.__coeffs + out._coeffs = sm._coeffs cdef inline int csub(celement out, celement a, celement b, long prec, PowComputer_ prime_pow) except -1: r""" @@ -236,9 +236,9 @@ cdef inline int csub(celement out, celement a, celement b, long prec, PowCompute """ cdef celement df = a - b if df is a or df is b: - out.__coeffs = df.__coeffs[:] + out._coeffs = df._coeffs[:] else: - out.__coeffs = df.__coeffs + out._coeffs = df._coeffs cdef inline int cmul(celement out, celement a, celement b, long prec, PowComputer_ prime_pow) except -1: r""" @@ -261,9 +261,9 @@ cdef inline int cmul(celement out, celement a, celement b, long prec, PowCompute """ cdef celement pd = a*b if pd is a or pd is b: - out.__coeffs = pd.__coeffs[:] + out._coeffs = pd._coeffs[:] else: - out.__coeffs = pd.__coeffs + out._coeffs = pd._coeffs cdef inline int csetone(celement out, PowComputer_ prime_pow) except -1: r""" @@ -276,7 +276,7 @@ cdef inline int csetone(celement out, PowComputer_ prime_pow) except -1: - ``prime_pow`` -- the ``PowComputer`` for the ring """ - out.__coeffs = [prime_pow.base_ring(1)] + out._coeffs = [prime_pow.base_ring(1)] cdef inline int csetzero(celement out, PowComputer_ prime_pow) except -1: r""" @@ -289,7 +289,7 @@ cdef inline int csetzero(celement out, PowComputer_ prime_pow) except -1: - ``prime_pow`` -- the ``PowComputer`` for the ring """ - out.__coeffs = [] + out._coeffs = [] cdef inline bint cisone(celement a, PowComputer_ prime_pow) except -1: r""" @@ -330,7 +330,7 @@ cdef inline int ccopy(celement out, celement a, PowComputer_ prime_pow) except - - ``prime_pow`` -- the ``PowComputer`` for the ring """ - out.__coeffs = a.__coeffs[:] + out._coeffs = a._coeffs[:] cdef inline cpickle(celement a, PowComputer_ prime_pow): r""" @@ -343,7 +343,7 @@ cdef inline cpickle(celement a, PowComputer_ prime_pow): - ``prime_pow`` the ``PowComputer`` for the ring """ - return a.__coeffs + return a._coeffs cdef inline int cunpickle(celement out, x, PowComputer_ prime_pow) except -1: r""" @@ -358,7 +358,7 @@ cdef inline int cunpickle(celement out, x, PowComputer_ prime_pow) except -1: - ``prime_pow`` -- the ``PowComputer`` for the ring """ - out.__coeffs = x + out._coeffs = x cdef inline long chash(celement a, long ordp, long prec, PowComputer_ prime_pow) except -1: r""" @@ -413,9 +413,9 @@ cdef int cconv(celement out, x, long prec, long valshift, PowComputer_ prime_pow else: xx = prime_pow.poly_ring(x) if xx is x: - out.__coeffs = xx.__coeffs[:] + out._coeffs = xx._coeffs[:] else: - out.__coeffs = xx.__coeffs + out._coeffs = xx._coeffs if valshift > 0: cshift_notrunc(out, out, -valshift, prec, prime_pow, True) elif valshift == 0: @@ -458,12 +458,12 @@ cdef inline long cconv_mpz_t(celement out, mpz_t x, long prec, bint absolute, Po mpz_set(n.value, x) if n: - out.__coeffs = [prime_pow.base_ring(n)] + out._coeffs = [prime_pow.base_ring(n)] if not absolute: valuation = cremove(out, out, prec, prime_pow) creduce(out, out, prec, prime_pow) else: - out.__coeffs = [] + out._coeffs = [] return valuation @@ -492,12 +492,12 @@ cdef inline int cconv_mpz_t_out(mpz_t out, celement x, long valshift, long prec, else: prime_pow.powhelper_cconv_out = x - if len(prime_pow.powhelper_cconv_out.__coeffs) == 0: + if len(prime_pow.powhelper_cconv_out._coeffs) == 0: mpz_set_ui(out, 0) - elif len(prime_pow.powhelper_cconv_out.__coeffs) == 1: + elif len(prime_pow.powhelper_cconv_out._coeffs) == 1: # recursively let the underlying polynomial convert the constant # coefficient to an integer (if possible) - n = ZZ(prime_pow.powhelper_cconv_out.__coeffs[0]) + n = ZZ(prime_pow.powhelper_cconv_out._coeffs[0]) mpz_set(out, n.value) else: raise ValueError("cannot convert to integer") @@ -532,7 +532,7 @@ cdef inline long cconv_mpq_t(celement out, mpq_t x, long prec, bint absolute, Po """ cdef Rational r = PY_NEW(Rational) mpq_set(r.value, x) - out.__coeffs = [prime_pow.base_ring(r)] + out._coeffs = [prime_pow.base_ring(r)] if not absolute: return cremove(out, out, prec, prime_pow) @@ -565,12 +565,12 @@ cdef inline int cconv_mpq_t_out(mpq_t out, celement x, long valshift, long prec, else: prime_pow.powhelper_cconv_out = x - if len(prime_pow.powhelper_cconv_out.__coeffs) == 0: + if len(prime_pow.powhelper_cconv_out._coeffs) == 0: mpq_set_ui(out, 0, 1) - elif len(prime_pow.powhelper_cconv_out.__coeffs) == 1: + elif len(prime_pow.powhelper_cconv_out._coeffs) == 1: # recursively let the underlying polynomial convert the constant # coefficient to a rational (if possible) - c = QQ(prime_pow.powhelper_cconv_out.__coeffs[0]) + c = QQ(prime_pow.powhelper_cconv_out._coeffs[0]) mpq_set(out, c.value) else: raise ValueError("cannot convert to rational") diff --git a/src/sage/rings/padics/CA_template.pxi b/src/sage/rings/padics/CA_template.pxi index a0a66c19621..d821b5c1576 100644 --- a/src/sage/rings/padics/CA_template.pxi +++ b/src/sage/rings/padics/CA_template.pxi @@ -1463,7 +1463,7 @@ cdef class pAdicCoercion_CA_frac_field(RingHomomorphism): IF CELEMENT_IS_PY_OBJECT: # The base ring is wrong, so we fix it. K = ans.unit.base_ring() - ans.unit.__coeffs = [K(c) for c in ans.unit.__coeffs] + ans.unit._coeffs = [K(c) for c in ans.unit._coeffs] ans._normalize() return ans @@ -1516,7 +1516,7 @@ cdef class pAdicCoercion_CA_frac_field(RingHomomorphism): IF CELEMENT_IS_PY_OBJECT: # The base ring is wrong, so we fix it. K = ans.unit.base_ring() - ans.unit.__coeffs = [K(c) for c in ans.unit.__coeffs] + ans.unit._coeffs = [K(c) for c in ans.unit._coeffs] pass return ans @@ -1686,7 +1686,7 @@ cdef class pAdicConvert_CA_frac_field(Morphism): IF CELEMENT_IS_PY_OBJECT: # The base ring is wrong, so we fix it. R = ans.value.base_ring() - ans.value.__coeffs = [R(c) for c in ans.value.__coeffs] + ans.value._coeffs = [R(c) for c in ans.value._coeffs] return ans cpdef Element _call_with_args(self, _x, args=(), kwds={}): @@ -1741,7 +1741,7 @@ cdef class pAdicConvert_CA_frac_field(Morphism): IF CELEMENT_IS_PY_OBJECT: # The base ring is wrong, so we fix it. R = ans.value.base_ring() - ans.value.__coeffs = [R(c) for c in ans.value.__coeffs] + ans.value._coeffs = [R(c) for c in ans.value._coeffs] return ans cdef dict _extra_slots(self): diff --git a/src/sage/rings/padics/CR_template.pxi b/src/sage/rings/padics/CR_template.pxi index cb57bb2cb48..863c612587c 100644 --- a/src/sage/rings/padics/CR_template.pxi +++ b/src/sage/rings/padics/CR_template.pxi @@ -2184,7 +2184,7 @@ cdef class pAdicCoercion_CR_frac_field(RingHomomorphism): IF CELEMENT_IS_PY_OBJECT: # The base ring is wrong, so we fix it. K = ans.unit.base_ring() - ans.unit.__coeffs = [K(c) for c in ans.unit.__coeffs] + ans.unit._coeffs = [K(c) for c in ans.unit._coeffs] return ans cpdef Element _call_with_args(self, _x, args=(), kwds={}): @@ -2241,7 +2241,7 @@ cdef class pAdicCoercion_CR_frac_field(RingHomomorphism): IF CELEMENT_IS_PY_OBJECT: # The base ring is wrong, so we fix it. K = ans.unit.base_ring() - ans.unit.__coeffs = [K(c) for c in ans.unit.__coeffs] + ans.unit._coeffs = [K(c) for c in ans.unit._coeffs] return ans def section(self): @@ -2404,7 +2404,7 @@ cdef class pAdicConvert_CR_frac_field(Morphism): IF CELEMENT_IS_PY_OBJECT: # The base ring is wrong, so we fix it. K = ans.unit.base_ring() - ans.unit.__coeffs = [K(c) for c in ans.unit.__coeffs] + ans.unit._coeffs = [K(c) for c in ans.unit._coeffs] return ans cpdef Element _call_with_args(self, _x, args=(), kwds={}): @@ -2463,7 +2463,7 @@ cdef class pAdicConvert_CR_frac_field(Morphism): IF CELEMENT_IS_PY_OBJECT: # The base ring is wrong, so we fix it. K = ans.unit.base_ring() - ans.unit.__coeffs = [K(c) for c in ans.unit.__coeffs] + ans.unit._coeffs = [K(c) for c in ans.unit._coeffs] return ans cdef dict _extra_slots(self): diff --git a/src/sage/rings/padics/FM_template.pxi b/src/sage/rings/padics/FM_template.pxi index ea7d4055660..f47200074ea 100644 --- a/src/sage/rings/padics/FM_template.pxi +++ b/src/sage/rings/padics/FM_template.pxi @@ -1227,7 +1227,7 @@ cdef class pAdicCoercion_FM_frac_field(RingHomomorphism): IF CELEMENT_IS_PY_OBJECT: # The base ring is wrong, so we fix it. K = ans.unit.base_ring() - ans.unit.__coeffs = [K(c) for c in ans.unit.__coeffs] + ans.unit._coeffs = [K(c) for c in ans.unit._coeffs] return ans cpdef Element _call_with_args(self, _x, args=(), kwds={}): @@ -1277,7 +1277,7 @@ cdef class pAdicCoercion_FM_frac_field(RingHomomorphism): IF CELEMENT_IS_PY_OBJECT: # The base ring is wrong, so we fix it. K = ans.unit.base_ring() - ans.unit.__coeffs = [K(c) for c in ans.unit.__coeffs] + ans.unit._coeffs = [K(c) for c in ans.unit._coeffs] return ans def section(self): @@ -1435,7 +1435,7 @@ cdef class pAdicConvert_FM_frac_field(Morphism): IF CELEMENT_IS_PY_OBJECT: # The base ring is wrong, so we fix it. R = ans.value.base_ring() - ans.value.__coeffs = [R(c) for c in ans.value.__coeffs] + ans.value._coeffs = [R(c) for c in ans.value._coeffs] return ans cpdef Element _call_with_args(self, _x, args=(), kwds={}): @@ -1483,7 +1483,7 @@ cdef class pAdicConvert_FM_frac_field(Morphism): IF CELEMENT_IS_PY_OBJECT: # The base ring is wrong, so we fix it. R = ans.value.base_ring() - ans.value.__coeffs = [R(c) for c in ans.value.__coeffs] + ans.value._coeffs = [R(c) for c in ans.value._coeffs] return ans cdef dict _extra_slots(self): diff --git a/src/sage/rings/padics/FP_template.pxi b/src/sage/rings/padics/FP_template.pxi index 57ec619b278..c718c0a5f8d 100644 --- a/src/sage/rings/padics/FP_template.pxi +++ b/src/sage/rings/padics/FP_template.pxi @@ -1849,7 +1849,7 @@ cdef class pAdicCoercion_FP_frac_field(RingHomomorphism): IF CELEMENT_IS_PY_OBJECT: # The base ring is wrong, so we fix it. K = ans.unit.base_ring() - ans.unit.__coeffs = [K(c) for c in ans.unit.__coeffs] + ans.unit._coeffs = [K(c) for c in ans.unit._coeffs] return ans cpdef Element _call_with_args(self, _x, args=(), kwds={}): @@ -1903,7 +1903,7 @@ cdef class pAdicCoercion_FP_frac_field(RingHomomorphism): IF CELEMENT_IS_PY_OBJECT: # The base ring is wrong, so we fix it. K = ans.unit.base_ring() - ans.unit.__coeffs = [K(c) for c in ans.unit.__coeffs] + ans.unit._coeffs = [K(c) for c in ans.unit._coeffs] return ans def section(self): @@ -2025,7 +2025,7 @@ cdef class pAdicConvert_FP_frac_field(Morphism): IF CELEMENT_IS_PY_OBJECT: # The base ring is wrong, so we fix it. K = ans.unit.base_ring() - ans.unit.__coeffs = [K(c) for c in ans.unit.__coeffs] + ans.unit._coeffs = [K(c) for c in ans.unit._coeffs] return ans cpdef Element _call_with_args(self, _x, args=(), kwds={}): @@ -2081,7 +2081,7 @@ cdef class pAdicConvert_FP_frac_field(Morphism): IF CELEMENT_IS_PY_OBJECT: # The base ring is wrong, so we fix it. K = ans.unit.base_ring() - ans.unit.__coeffs = [K(c) for c in ans.unit.__coeffs] + ans.unit._coeffs = [K(c) for c in ans.unit._coeffs] return ans cdef dict _extra_slots(self): diff --git a/src/sage/rings/polynomial/polynomial_element.pxd b/src/sage/rings/polynomial/polynomial_element.pxd index f439aef123c..5dcbf4597d0 100644 --- a/src/sage/rings/polynomial/polynomial_element.pxd +++ b/src/sage/rings/polynomial/polynomial_element.pxd @@ -49,7 +49,7 @@ cdef class Polynomial(CommutativePolynomial): cdef class Polynomial_generic_dense(Polynomial): cdef Polynomial_generic_dense _new_c(self, list coeffs, Parent P) - cdef list __coeffs + cdef list _coeffs cdef int _normalize(self) except -1 cpdef list list(self, bint copy=*) diff --git a/src/sage/rings/polynomial/polynomial_element.pyx b/src/sage/rings/polynomial/polynomial_element.pyx index ca5edc7cd81..380ff5ddbaa 100644 --- a/src/sage/rings/polynomial/polynomial_element.pyx +++ b/src/sage/rings/polynomial/polynomial_element.pyx @@ -9598,7 +9598,7 @@ cdef class Polynomial(CommutativePolynomial): 0 """ # __getitem__ already returns a polynomial!! - # We must not have check=False, since 0 must not have __coeffs = [0]. + # We must not have check=False, since 0 must not have _coeffs = [0]. return self._parent(self[:n])#, check=False) cdef _inplace_truncate(self, long prec): @@ -11319,16 +11319,16 @@ cdef class Polynomial_generic_dense(Polynomial): def __init__(self, parent, x=None, int check=1, is_gen=False, int construct=0, **kwds): Polynomial.__init__(self, parent, is_gen=is_gen) if x is None: - self.__coeffs = [] + self._coeffs = [] return R = parent.base_ring() if isinstance(x, (list, tuple)): if check: - self.__coeffs = [R(t) for t in x] + self._coeffs = [R(t) for t in x] self._normalize() else: - self.__coeffs = x + self._coeffs = x return if sage.rings.fraction_field_element.is_FractionFieldElement(x): @@ -11343,19 +11343,19 @@ cdef class Polynomial_generic_dense(Polynomial): elif R.has_coerce_map_from((x)._parent):# is R or (x)._parent == R: try: if x.is_zero(): - self.__coeffs = [] + self._coeffs = [] return except (AttributeError, TypeError): pass x = [x] else: - self.__coeffs = [R(a, **kwds) for a in x.list(copy=False)] + self._coeffs = [R(a, **kwds) for a in x.list(copy=False)] if check: self._normalize() return elif isinstance(x, int) and x == 0: - self.__coeffs = [] + self._coeffs = [] return elif isinstance(x, dict): @@ -11371,16 +11371,16 @@ cdef class Polynomial_generic_dense(Polynomial): # else: # x = [] # zero polynomial if check: - self.__coeffs = [R(z, **kwds) for z in x] + self._coeffs = [R(z, **kwds) for z in x] self._normalize() else: - self.__coeffs = x + self._coeffs = x cdef Polynomial_generic_dense _new_c(self, list coeffs, Parent P): cdef type t = type(self) cdef Polynomial_generic_dense f = t.__new__(t) f._parent = P - f.__coeffs = coeffs + f._coeffs = coeffs return f cpdef Polynomial _new_constant_poly(self, a, Parent P): @@ -11422,10 +11422,10 @@ cdef class Polynomial_generic_dense(Polynomial): sage: type(f) """ - return make_generic_polynomial, (self._parent, self.__coeffs) + return make_generic_polynomial, (self._parent, self._coeffs) def __bool__(self): - return bool(self.__coeffs) + return bool(self._coeffs) cpdef bint is_term(self) except -1: """ @@ -11444,10 +11444,10 @@ cdef class Polynomial_generic_dense(Polynomial): sage: (1 + 3*x^5).is_term() # optional - sage.symbolic False """ - if not self.__coeffs: + if not self._coeffs: return False - for c in self.__coeffs[:-1]: + for c in self._coeffs[:-1]: if c: return False return True @@ -11459,9 +11459,9 @@ cdef class Polynomial_generic_dense(Polynomial): Return the product ``self * term``, where ``term`` is a polynomial with a single term. """ - cdef Py_ssize_t d = len( ( term).__coeffs ) - 1 + cdef Py_ssize_t d = len( ( term)._coeffs ) - 1 cdef Py_ssize_t i - cdef list x = self.__coeffs + cdef list x = self._coeffs cdef Py_ssize_t ell = len(x) c = term.get_unsafe(d) cdef list v = [self.base_ring().zero()] * (d + ell) @@ -11495,7 +11495,7 @@ cdef class Polynomial_generic_dense(Polynomial): ... NotImplementedError: cannot check whether number is non-zero """ - cdef list x = self.__coeffs + cdef list x = self._coeffs cdef Py_ssize_t n = len(x) - 1 while n >= 0 and not x[n]: del x[n] @@ -11524,7 +11524,7 @@ cdef class Polynomial_generic_dense(Polynomial): sage: f[:3] 40.0*x^2 + 10.0*x + 1.0 """ - return self.__coeffs[n] + return self._coeffs[n] def _unsafe_mutate(self, n, value): """ @@ -11547,17 +11547,17 @@ cdef class Polynomial_generic_dense(Polynomial): """ n = int(n) value = self.base_ring()(value) - if n >= 0 and n < len(self.__coeffs): - self.__coeffs[n] = value - if n == len(self.__coeffs) and value == 0: + if n >= 0 and n < len(self._coeffs): + self._coeffs[n] = value + if n == len(self._coeffs) and value == 0: self._normalize() elif n < 0: raise IndexError("polynomial coefficient index must be nonnegative") elif value != 0: zero = self.base_ring().zero() - for _ in range(len(self.__coeffs), n): - self.__coeffs.append(zero) - self.__coeffs.append(value) + for _ in range(len(self._coeffs), n): + self._coeffs.append(zero) + self._coeffs.append(value) def __floordiv__(self, right): """ @@ -11597,7 +11597,7 @@ cdef class Polynomial_generic_dense(Polynomial): return (self)._floordiv_(right) P = parent(self) d = P.base_ring()(right) - cdef Polynomial_generic_dense res = (self)._new_c([c // d for c in (self).__coeffs], P) + cdef Polynomial_generic_dense res = (self)._new_c([c // d for c in (self)._coeffs], P) res._normalize() return res @@ -11614,8 +11614,8 @@ cdef class Polynomial_generic_dense(Polynomial): """ cdef Polynomial_generic_dense res cdef Py_ssize_t check=0, i, min - x = (self).__coeffs - y = (right).__coeffs + x = (self)._coeffs + y = (right)._coeffs if len(x) > len(y): min = len(y) high = x[min:] @@ -11635,8 +11635,8 @@ cdef class Polynomial_generic_dense(Polynomial): cpdef _sub_(self, right): cdef Polynomial_generic_dense res cdef Py_ssize_t check=0, i, min - x = (self).__coeffs - y = (right).__coeffs + x = (self)._coeffs + y = (right)._coeffs if len(x) > len(y): min = len(y) high = x[min:] @@ -11654,11 +11654,11 @@ cdef class Polynomial_generic_dense(Polynomial): return self._new_c(low + high, self._parent) cpdef _rmul_(self, Element c): - if not self.__coeffs: + if not self._coeffs: return self - if c._parent is not (self.__coeffs[0])._parent: - c = (self.__coeffs[0])._parent.coerce(c) - v = [c * a for a in self.__coeffs] + if c._parent is not (self._coeffs[0])._parent: + c = (self._coeffs[0])._parent.coerce(c) + v = [c * a for a in self._coeffs] cdef Polynomial_generic_dense res = self._new_c(v, self._parent) #if not v[len(v)-1]: # "normalize" checks this anyway... @@ -11666,11 +11666,11 @@ cdef class Polynomial_generic_dense(Polynomial): return res cpdef _lmul_(self, Element c): - if not self.__coeffs: + if not self._coeffs: return self - if c._parent is not (self.__coeffs[0])._parent: - c = (self.__coeffs[0])._parent.coerce(c) - v = [a * c for a in self.__coeffs] + if c._parent is not (self._coeffs[0])._parent: + c = (self._coeffs[0])._parent.coerce(c) + v = [a * c for a in self._coeffs] cdef Polynomial_generic_dense res = self._new_c(v, self._parent) #if not v[len(v)-1]: # "normalize" checks this anyway... @@ -11691,10 +11691,10 @@ cdef class Polynomial_generic_dense(Polynomial): sage: f.constant_coefficient() t """ - if not self.__coeffs: + if not self._coeffs: return self.base_ring().zero() else: - return self.__coeffs[0] + return self._coeffs[0] cpdef list list(self, bint copy=True): """ @@ -11709,9 +11709,9 @@ cdef class Polynomial_generic_dense(Polynomial): [1, 9, 12, 8] """ if copy: - return list(self.__coeffs) + return list(self._coeffs) else: - return self.__coeffs + return self._coeffs def degree(self, gen=None): """ @@ -11730,7 +11730,7 @@ cdef class Polynomial_generic_dense(Polynomial): """ - return smallInteger(len(self.__coeffs) - 1) + return smallInteger(len(self._coeffs) - 1) def shift(self, Py_ssize_t n): r""" @@ -11768,13 +11768,13 @@ cdef class Polynomial_generic_dense(Polynomial): return self if n > 0: output = [self.base_ring().zero()] * n - output.extend(self.__coeffs) + output.extend(self._coeffs) return self._new_c(output, self._parent) if n < 0: - if n > len(self.__coeffs) - 1: + if n > len(self._coeffs) - 1: return self._parent([]) else: - return self._new_c(self.__coeffs[-int(n):], self._parent) + return self._new_c(self._coeffs[-int(n):], self._parent) @coerce_binop def quo_rem(self, other): @@ -11847,8 +11847,8 @@ cdef class Polynomial_generic_dense(Polynomial): return self, self R = self._parent.base_ring() - cdef list x = list((self).__coeffs) # make a copy - cdef list y = (other).__coeffs + cdef list x = list((self)._coeffs) # make a copy + cdef list y = (other)._coeffs cdef Py_ssize_t m = len(x) # deg(self)=m-1 cdef Py_ssize_t n = len(y) # deg(other)=n-1 if m < n: @@ -11909,18 +11909,18 @@ cdef class Polynomial_generic_dense(Polynomial): sage: type(f) """ - l = len(self.__coeffs) + l = len(self._coeffs) if n > l: n = l - while n > 0 and not self.__coeffs[n-1]: + while n > 0 and not self._coeffs[n-1]: n -= 1 - return self._new_c(self.__coeffs[:n], self._parent) + return self._new_c(self._coeffs[:n], self._parent) cdef _inplace_truncate(self, long n): - if n < len(self.__coeffs): - while n > 0 and not self.__coeffs[n-1]: + if n < len(self._coeffs): + while n > 0 and not self._coeffs[n-1]: n -= 1 - self.__coeffs = self.__coeffs[:n] + self._coeffs = self._coeffs[:n] return self def make_generic_polynomial(parent, coeffs): @@ -12087,7 +12087,7 @@ cdef class Polynomial_generic_dense_inexact(Polynomial_generic_dense): sage: S([1, R(0, 20)]) # optional - sage.rings.padics O(5^20)*x + 1 + O(5^20) """ - cdef list x = self.__coeffs + cdef list x = self._coeffs cdef Py_ssize_t n = len(x) - 1 cdef RingElement c while n >= 0: @@ -12145,7 +12145,7 @@ cdef class Polynomial_generic_dense_inexact(Polynomial_generic_dense): - Xavier Caruso (2013-03) """ - coeffs = self.__coeffs + coeffs = self._coeffs d = len(coeffs) - 1 while d >= 0: c = coeffs[d] @@ -12188,7 +12188,7 @@ cdef class Polynomial_generic_dense_inexact(Polynomial_generic_dense): - Xavier Caruso (2013-03) """ - return len(self.__coeffs) - 1 + return len(self._coeffs) - 1 cdef class ConstantPolynomialSection(Map): From efbdfe5d1d5512872e97c53293f558d40cc9440a Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:38:21 +0800 Subject: [PATCH 18/44] rename __ngens -> _ngens --- .../letterplace/free_algebra_letterplace.pxd | 4 +-- .../letterplace/free_algebra_letterplace.pyx | 34 +++++++++---------- .../multi_polynomial_libsingular.pyx | 8 ++--- .../polynomial/multi_polynomial_ring_base.pxd | 2 +- .../polynomial/multi_polynomial_ring_base.pyx | 10 +++--- src/sage/rings/polynomial/pbori/pbori.pyx | 2 +- src/sage/rings/polynomial/plural.pxd | 2 +- src/sage/rings/polynomial/plural.pyx | 14 ++++---- 8 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/sage/algebras/letterplace/free_algebra_letterplace.pxd b/src/sage/algebras/letterplace/free_algebra_letterplace.pxd index d1d162c3b40..5623a1bb6d4 100644 --- a/src/sage/algebras/letterplace/free_algebra_letterplace.pxd +++ b/src/sage/algebras/letterplace/free_algebra_letterplace.pxd @@ -20,13 +20,13 @@ cdef class FreeAlgebra_letterplace_libsingular(): cdef ring* _lp_ring cdef MPolynomialRing_libsingular _commutative_ring cdef MPolynomialRing_libsingular _lp_ring_internal - cdef object __ngens + cdef object _ngens cdef class FreeAlgebra_letterplace(Algebra): cdef MPolynomialRing_libsingular _commutative_ring cdef MPolynomialRing_libsingular _current_ring cdef int _degbound - cdef int __ngens + cdef int _ngens cdef int _nb_slackvars cdef object __monoid cdef public object __custom_name diff --git a/src/sage/algebras/letterplace/free_algebra_letterplace.pyx b/src/sage/algebras/letterplace/free_algebra_letterplace.pyx index 6913bbc26fc..14910d11b35 100644 --- a/src/sage/algebras/letterplace/free_algebra_letterplace.pyx +++ b/src/sage/algebras/letterplace/free_algebra_letterplace.pyx @@ -256,7 +256,7 @@ cdef class FreeAlgebra_letterplace(Algebra): """ if not isinstance(R, MPolynomialRing_libsingular): raise TypeError("a letterplace algebra must be provided by a polynomial ring of type %s" % MPolynomialRing_libsingular) - self.__ngens = R.ngens() + self._ngens = R.ngens() if degrees is None: varnames = R.variable_names() self._nb_slackvars = 0 @@ -270,12 +270,12 @@ cdef class FreeAlgebra_letterplace(Algebra): self._current_ring = make_letterplace_ring(R, 1) self._degbound = 1 if degrees is None: - self._degrees = tuple([int(1)] * self.__ngens) + self._degrees = tuple([int(1)] * self._ngens) else: if (not isinstance(degrees, (tuple, list))) \ - or len(degrees) != self.__ngens - self._nb_slackvars \ + or len(degrees) != self._ngens - self._nb_slackvars \ or any(i <= 0 for i in degrees): - raise TypeError("the generator degrees must be given by a list or tuple of %d positive integers" % (self.__ngens - 1)) + raise TypeError("the generator degrees must be given by a list or tuple of %d positive integers" % (self._ngens - 1)) self._degrees = tuple([int(i) for i in degrees]) self.set_degbound(max(self._degrees)) self._populate_coercion_lists_(coerce_list=[base_ring]) @@ -306,7 +306,7 @@ cdef class FreeAlgebra_letterplace(Algebra): sage: F.ngens() 3 """ - return self.__ngens - self._nb_slackvars + return self._ngens - self._nb_slackvars def gen(self, i): """ @@ -328,17 +328,17 @@ cdef class FreeAlgebra_letterplace(Algebra): sage: F.gen(2) c """ - if i >= self.__ngens - self._nb_slackvars: - raise ValueError("this free algebra only has %d generators" % (self.__ngens - self._nb_slackvars)) + if i >= self._ngens - self._nb_slackvars: + raise ValueError("this free algebra only has %d generators" % (self._ngens - self._nb_slackvars)) if self._gens is not None: return self._gens[i] deg = self._degrees[i] # self.set_degbound(deg) p = self._current_ring.gen(i) cdef int n - cdef int j = self.__ngens - 1 + cdef int j = self._ngens - 1 for n in range(1, deg): - j += self.__ngens + j += self._ngens p *= self._current_ring.gen(j) return FreeAlgebraElement_letterplace(self, p) @@ -414,7 +414,7 @@ cdef class FreeAlgebra_letterplace(Algebra): sage: FreeAlgebra(QQ, implementation='letterplace', names=['x']).is_commutative() True """ - return self.__ngens - self._nb_slackvars <= 1 + return self._ngens - self._nb_slackvars <= 1 def is_field(self, proof=True): """ @@ -431,7 +431,7 @@ cdef class FreeAlgebra_letterplace(Algebra): sage: F.is_field() False """ - return (not (self.__ngens - self._nb_slackvars)) and self._base.is_field(proof=proof) + return (not (self._ngens - self._nb_slackvars)) and self._base.is_field(proof=proof) def _repr_(self): """ @@ -447,7 +447,7 @@ cdef class FreeAlgebra_letterplace(Algebra): sage: F Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field """ - return "Free Associative Unital Algebra on %d generators %s over %s" % (self.__ngens - self._nb_slackvars, self.gens(), self._base) + return "Free Associative Unital Algebra on %d generators %s over %s" % (self._ngens - self._nb_slackvars, self.gens(), self._base) def _latex_(self): r""" @@ -587,7 +587,7 @@ cdef class FreeAlgebra_letterplace(Algebra): generated free abelian monoid. In principle, this is correct, but it is not implemented, yet.> """ - cdef int ngens = self.__ngens + cdef int ngens = self._ngens cdef int nblocks = len(E) // ngens cdef int i, j, base, exp, var_ind cdef list out = [] @@ -619,7 +619,7 @@ cdef class FreeAlgebra_letterplace(Algebra): sage: latex(-(a*b*(z+1)-c)^2) # indirect doctest \left(2 z + 1\right) a b a b + \left(z + 1\right) a b c + \left(z + 1\right) c a b - c c """ - cdef int ngens = self.__ngens + cdef int ngens = self._ngens cdef int nblocks = len(E) // ngens cdef int i, j, base, exp, var_ind cdef list out = [] @@ -679,7 +679,7 @@ cdef class FreeAlgebra_letterplace(Algebra): cdef list out = [] C = self.current_ring() cdef FreeAlgebraElement_letterplace x - ngens = self.__ngens + ngens = self._ngens degbound = self._degbound cdef list G = [C(x._poly) for x in g] from sage.groups.perm_gps.permgroup_named import CyclicPermutationGroup @@ -813,7 +813,7 @@ cdef class FreeAlgebra_letterplace(Algebra): l = len(e) break cdef dict out = {} - self.set_degbound(l // self.__ngens) + self.set_degbound(l // self._ngens) cdef Py_ssize_t n = self._current_ring.ngens() for e, c in D.iteritems(): out[tuple(e) + (0,) * (n - l)] = c @@ -898,7 +898,7 @@ cdef class FreeAlgebra_letterplace_libsingular(): self._commutative_ring = commutative_ring def __init__(self, commutative_ring, degbound): - self.__ngens = commutative_ring.ngens() * degbound + self._ngens = commutative_ring.ngens() * degbound def __dealloc__(self): r""" diff --git a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx index 45e14eb320d..015a12d7a35 100644 --- a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx @@ -381,7 +381,7 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): ... NotImplementedError: polynomials in -1 variables are not supported in Singular """ - self.__ngens = n + self._ngens = n self._ring = singular_ring_new(base_ring, n, names, order) self._zero_element = new_MP(self, NULL) cdef MPolynomial_libsingular one = new_MP(self, p_ISet(1, self._ring)) @@ -1018,7 +1018,7 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): Multivariate Polynomial Ring in x, y over Rational Field """ varstr = ", ".join(char_to_str(rRingVar(i,self._ring)) - for i in range(self.__ngens)) + for i in range(self._ngens)) return "Multivariate Polynomial Ring in %s over %s" % (varstr, self.base_ring()) def ngens(self): @@ -1036,7 +1036,7 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): sage: P.ngens() 1000 """ - return int(self.__ngens) + return int(self._ngens) def gen(self, int n=0): """ @@ -1064,7 +1064,7 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): cdef poly *_p cdef ring *_ring = self._ring - if n < 0 or n >= self.__ngens: + if n < 0 or n >= self._ngens: raise ValueError("Generator not defined.") rChangeCurrRing(_ring) diff --git a/src/sage/rings/polynomial/multi_polynomial_ring_base.pxd b/src/sage/rings/polynomial/multi_polynomial_ring_base.pxd index fc81cf6d298..e54dd1e9ce6 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ring_base.pxd +++ b/src/sage/rings/polynomial/multi_polynomial_ring_base.pxd @@ -2,7 +2,7 @@ cimport sage.rings.ring from sage.structure.parent cimport Parent cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): - cdef object __ngens + cdef object _ngens cdef object __term_order cdef public object _has_singular cdef public object _magma_gens diff --git a/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx b/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx index 41b2e4c50ee..bab3b08d522 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx @@ -85,7 +85,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): raise ValueError("Multivariate Polynomial Rings must " "have more than 0 variables.") order = TermOrder(order, n) - self.__ngens = n + self._ngens = n self.__term_order = order self._has_singular = False # cannot convert to Singular by default self._magma_cache = {} @@ -640,10 +640,10 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): lft = left other = right - lx = (lft.base_ring(), lft.__ngens, + lx = (lft.base_ring(), lft._ngens, lft.variable_names(), lft.__term_order) - rx = (other.base_ring(), other.__ngens, + rx = (other.base_ring(), other._ngens, other.variable_names(), other.__term_order) return richcmp(lx, rx, op) @@ -864,7 +864,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): return self.base_ring().characteristic() def gen(self, n=0): - if n < 0 or n >= self.__ngens: + if n < 0 or n >= self._ngens: raise ValueError("Generator not defined.") return self._gens[int(n)] @@ -924,7 +924,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): return self.base_ring().krull_dimension() + self.ngens() def ngens(self): - return self.__ngens + return self._ngens def _monomial_order_function(self): raise NotImplementedError diff --git a/src/sage/rings/polynomial/pbori/pbori.pyx b/src/sage/rings/polynomial/pbori/pbori.pyx index 38d52a6273d..0a987fb2d5e 100644 --- a/src/sage/rings/polynomial/pbori/pbori.pyx +++ b/src/sage/rings/polynomial/pbori/pbori.pyx @@ -547,7 +547,7 @@ cdef class BooleanPolynomialRing(BooleanPolynomialRing_base): """ return tuple(new_BP_from_PBVar(self, self._pbring.variable(self.pbind[i])) - for i in range(self.__ngens)) + for i in range(self._ngens)) def change_ring(self, base_ring=None, names=None, order=None): """ diff --git a/src/sage/rings/polynomial/plural.pxd b/src/sage/rings/polynomial/plural.pxd index 41db2a144e7..5d05e4d0e25 100644 --- a/src/sage/rings/polynomial/plural.pxd +++ b/src/sage/rings/polynomial/plural.pxd @@ -13,7 +13,7 @@ cdef extern from *: ctypedef long Py_hash_t cdef class NCPolynomialRing_plural(Ring): - cdef object __ngens + cdef object _ngens cdef object _c cdef object _d cdef object __term_order diff --git a/src/sage/rings/polynomial/plural.pyx b/src/sage/rings/polynomial/plural.pyx index ebc17a01e50..fc55b9a8886 100644 --- a/src/sage/rings/polynomial/plural.pyx +++ b/src/sage/rings/polynomial/plural.pyx @@ -336,7 +336,7 @@ cdef class NCPolynomialRing_plural(Ring): self._ring = singular_ring_reference(rw._ring) self._ring.ShortOut = 0 - self.__ngens = n + self._ngens = n self.__term_order = order Ring.__init__(self, base_ring, names, category=category) @@ -727,7 +727,7 @@ cdef class NCPolynomialRing_plural(Ring): from sage.repl.rich_output.backend_base import BackendBase from sage.repl.display.pretty_print import SagePrettyPrinter varstr = ", ".join(char_to_str(rRingVar(i, self._ring)) - for i in range(self.__ngens)) + for i in range(self._ngens)) backend = BackendBase() relations = backend._apply_pretty_printer(SagePrettyPrinter, self.relations()) @@ -830,7 +830,7 @@ cdef class NCPolynomialRing_plural(Ring): sage: P.ngens() 3 """ - return int(self.__ngens) + return int(self._ngens) def gen(self, int n=0): """ @@ -857,7 +857,7 @@ cdef class NCPolynomialRing_plural(Ring): cdef poly *_p cdef ring *_ring = self._ring - if n < 0 or n >= self.__ngens: + if n < 0 or n >= self._ngens: raise ValueError("Generator not defined.") rChangeCurrRing(_ring) @@ -2353,7 +2353,7 @@ cdef class NCPolynomial_plural(RingElement): except TypeError: x = (x,) - if len(x) != (self._parent).__ngens: + if len(x) != (self._parent)._ngens: raise TypeError("x must have length self.ngens()") m = p_ISet(1,r) @@ -2890,7 +2890,7 @@ cpdef MPolynomialRing_libsingular new_CRing(RingWrap rw, base_ring): self._ring.ShortOut = 0 - self.__ngens = rw.ngens() + self._ngens = rw.ngens() self.__term_order = TermOrder(rw.ordering_string(), force=True) ParentWithGens.__init__(self, base_ring, tuple(rw.var_names()), @@ -2962,7 +2962,7 @@ cpdef NCPolynomialRing_plural new_NRing(RingWrap rw, base_ring): self._ring.ShortOut = 0 - self.__ngens = rw.ngens() + self._ngens = rw.ngens() self.__term_order = TermOrder(rw.ordering_string(), force=True) ParentWithGens.__init__(self, base_ring, rw.var_names()) From ae64ab94095290a6dde6eeb0ea813fce87ea27ff Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:39:18 +0800 Subject: [PATCH 19/44] fix use of private __ideal_monoid --- src/sage/rings/ring.pyx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sage/rings/ring.pyx b/src/sage/rings/ring.pyx index 4cba2c9ba7f..cac195cf5a4 100644 --- a/src/sage/rings/ring.pyx +++ b/src/sage/rings/ring.pyx @@ -1345,12 +1345,12 @@ cdef class CommutativeRing(Ring): sage: R.=QQ[]; R.ideal_monoid() Monoid of ideals of Univariate Polynomial Ring in x over Rational Field """ - if self.__ideal_monoid is not None: - return self.__ideal_monoid + if self._Ring__ideal_monoid is not None: + return self._Ring__ideal_monoid else: from sage.rings.ideal_monoid import IdealMonoid M = IdealMonoid(self) - self.__ideal_monoid = M + self._Ring__ideal_monoid = M return M def extension(self, poly, name=None, names=None, **kwds): From 98657c4a4aae2b6d77ec343eac12060d50cad216 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:39:44 +0800 Subject: [PATCH 20/44] rename __allocated -> _allocated --- src/sage/rings/padics/pow_computer.pxd | 2 +- src/sage/rings/padics/pow_computer.pyx | 6 +++--- src/sage/rings/padics/pow_computer_flint.pyx | 12 ++++++------ src/sage/rings/padics/pow_computer_relative.pyx | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/sage/rings/padics/pow_computer.pxd b/src/sage/rings/padics/pow_computer.pxd index 2a93e42254e..8766725882e 100644 --- a/src/sage/rings/padics/pow_computer.pxd +++ b/src/sage/rings/padics/pow_computer.pxd @@ -6,7 +6,7 @@ cdef class PowComputer_class(SageObject): cdef Integer prime cdef Integer p2 # floor(p/2) cdef bint in_field - cdef int __allocated + cdef int _allocated cdef public object _prec_type cdef long ram_prec_cap # = prec_cap * e diff --git a/src/sage/rings/padics/pow_computer.pyx b/src/sage/rings/padics/pow_computer.pyx index c2fa8031086..1c5bdf86897 100644 --- a/src/sage/rings/padics/pow_computer.pyx +++ b/src/sage/rings/padics/pow_computer.pyx @@ -65,7 +65,7 @@ cdef class PowComputer_class(SageObject): sig_on() mpz_init(self.temp_m) sig_off() - self.__allocated = 1 + self._allocated = 1 def __init__(self, Integer prime, long cache_limit, long prec_cap, long ram_prec_cap, bint in_field, poly=None, shift_seed=None): """ @@ -485,7 +485,7 @@ cdef class PowComputer_base(PowComputer_class): finally: sig_off() - self.__allocated = 2 + self._allocated = 2 def __init__(self, Integer prime, long cache_limit, long prec_cap, long ram_prec_cap, bint in_field, poly=None, shift_seed=None): """ @@ -529,7 +529,7 @@ cdef class PowComputer_base(PowComputer_class): """ cdef Py_ssize_t i - if self.__allocated >= 2: + if self._allocated >= 2: for i in range(self.cache_limit + 1): mpz_clear(self.small_powers[i]) mpz_clear(self.top_power) diff --git a/src/sage/rings/padics/pow_computer_flint.pyx b/src/sage/rings/padics/pow_computer_flint.pyx index 9f914defcc6..ae9e9f954a2 100644 --- a/src/sage/rings/padics/pow_computer_flint.pyx +++ b/src/sage/rings/padics/pow_computer_flint.pyx @@ -59,7 +59,7 @@ cdef class PowComputer_flint(PowComputer_class): finally: sig_off() - self.__allocated = 4 + self._allocated = 4 def __init__(self, Integer prime, long cache_limit, long prec_cap, long ram_prec_cap, bint in_field, poly=None, shift_seed=None): """ @@ -87,7 +87,7 @@ cdef class PowComputer_flint(PowComputer_class): sage: A = PowComputer_flint(5, 20, 20, 20, False) sage: del A """ - if self.__allocated >= 4: + if self._allocated >= 4: fmpz_clear(self.fprime) fmpz_clear(self.half_prime) fmpz_clear(self._fpow_variable) @@ -251,7 +251,7 @@ cdef class PowComputer_flint_1step(PowComputer_flint): finally: sig_off() - self.__allocated = 8 + self._allocated = 8 def __init__(self, Integer prime, long cache_limit, long prec_cap, long ram_prec_cap, bint in_field, _poly, shift_seed=None): """ @@ -296,7 +296,7 @@ cdef class PowComputer_flint_1step(PowComputer_flint): """ cdef Py_ssize_t i - if self.__allocated >= 8: + if self._allocated >= 8: fmpz_clear(self.q) fmpz_poly_clear(self.modulus) fmpz_poly_clear(self.powhelper_oneunit) @@ -501,7 +501,7 @@ cdef class PowComputer_flint_unram(PowComputer_flint_1step): mpz_init(self.mpz_matmod) sig_off() - self.__allocated = 16 + self._allocated = 16 def __dealloc__(self): """ @@ -515,7 +515,7 @@ cdef class PowComputer_flint_unram(PowComputer_flint_1step): sage: del A """ - if self.__allocated >= 16: + if self._allocated >= 16: fmpz_clear(self.fmpz_ccmp) fmpz_clear(self.fmpz_cval) fmpz_clear(self.fmpz_cinv) diff --git a/src/sage/rings/padics/pow_computer_relative.pyx b/src/sage/rings/padics/pow_computer_relative.pyx index 39051a681de..2253281bd35 100644 --- a/src/sage/rings/padics/pow_computer_relative.pyx +++ b/src/sage/rings/padics/pow_computer_relative.pyx @@ -69,7 +69,7 @@ cdef class PowComputer_relative(PowComputer_class): sage: PC = PowComputer_relative_maker(3, 20, 20, 60, False, f, shift_seed, 'fixed-mod') """ - self.__allocated = 4 + self._allocated = 4 def __init__(self, Integer prime, long cache_limit, long prec_cap, long ram_prec_cap, bint in_field, poly, shift_seed): r""" From 01fe8f213312c7271c89683113ede7d39ed270ea Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:40:17 +0800 Subject: [PATCH 21/44] rename __denominator -> _denominator --- .../quatalg/quaternion_algebra_element.pyx | 10 +- src/sage/matrix/matrix_cyclo_dense.pyx | 2 +- src/sage/rings/fraction_field_element.pyx | 100 +++++++++--------- .../number_field/number_field_element.pxd | 2 +- .../number_field/number_field_element.pyx | 84 +++++++-------- .../number_field_element_quadratic.pyx | 4 +- 6 files changed, 101 insertions(+), 101 deletions(-) diff --git a/src/sage/algebras/quatalg/quaternion_algebra_element.pyx b/src/sage/algebras/quatalg/quaternion_algebra_element.pyx index f6e87440fe9..0e93d2f3f55 100644 --- a/src/sage/algebras/quatalg/quaternion_algebra_element.pyx +++ b/src/sage/algebras/quatalg/quaternion_algebra_element.pyx @@ -1705,10 +1705,10 @@ cdef class QuaternionAlgebraElement_number_field(QuaternionAlgebraElement_abstra fmpz_poly_set_ZZX(self.z, (z).__numerator) fmpz_poly_set_ZZX(self.w, (w).__numerator) - ZZ_to_mpz(T1, &(x).__denominator) - ZZ_to_mpz(T2, &(y).__denominator) - ZZ_to_mpz(t3, &(z).__denominator) - ZZ_to_mpz(t4, &(w).__denominator) + ZZ_to_mpz(T1, &(x)._denominator) + ZZ_to_mpz(T2, &(y)._denominator) + ZZ_to_mpz(t3, &(z)._denominator) + ZZ_to_mpz(t4, &(w)._denominator) mpz_lcm(self.d, T1, T2) mpz_lcm(self.d, self.d, t3) @@ -1766,7 +1766,7 @@ cdef class QuaternionAlgebraElement_number_field(QuaternionAlgebraElement_abstra else: raise IndexError("quaternion element index out of range") - mpz_to_ZZ(&item.__denominator, self.d) + mpz_to_ZZ(&item._denominator, self.d) return item diff --git a/src/sage/matrix/matrix_cyclo_dense.pyx b/src/sage/matrix/matrix_cyclo_dense.pyx index 0b78bb7fd78..4e1865880be 100644 --- a/src/sage/matrix/matrix_cyclo_dense.pyx +++ b/src/sage/matrix/matrix_cyclo_dense.pyx @@ -400,7 +400,7 @@ cdef class Matrix_cyclo_dense(Matrix_dense): # Set the denominator of x to denom. fmpz_get_mpz(tmp, denom) - mpz_to_ZZ(&x.__denominator, tmp) + mpz_to_ZZ(&x._denominator, tmp) fmpz_clear(denom) mpz_clear(tmp) fmpz_clear(ftmp) diff --git a/src/sage/rings/fraction_field_element.pyx b/src/sage/rings/fraction_field_element.pyx index 11a2b646d35..0ed690cb28e 100644 --- a/src/sage/rings/fraction_field_element.pyx +++ b/src/sage/rings/fraction_field_element.pyx @@ -79,7 +79,7 @@ cdef class FractionFieldElement(FieldElement): (1, 0) """ cdef object __numerator - cdef object __denominator + cdef object _denominator cdef bint _is_reduced def __init__(self, parent, numerator, denominator=1, @@ -109,16 +109,16 @@ cdef class FractionFieldElement(FieldElement): FieldElement.__init__(self, parent) if coerce: self.__numerator = parent.ring()(numerator) - self.__denominator = parent.ring()(denominator) + self._denominator = parent.ring()(denominator) else: self.__numerator = numerator - self.__denominator = denominator + self._denominator = denominator if reduce and parent.is_exact(): try: self.reduce() except ArithmeticError: pass - if self.__denominator.is_zero(): + if self._denominator.is_zero(): raise ZeroDivisionError("fraction field element division by zero") def _im_gens_(self, codomain, im_gens, base_map=None): @@ -155,7 +155,7 @@ cdef class FractionFieldElement(FieldElement): ((-i))/b """ nnum = codomain.coerce(self.__numerator._im_gens_(codomain, im_gens, base_map=base_map)) - nden = codomain.coerce(self.__denominator._im_gens_(codomain, im_gens, base_map=base_map)) + nden = codomain.coerce(self._denominator._im_gens_(codomain, im_gens, base_map=base_map)) return codomain.coerce(nnum/nden) cpdef reduce(self): @@ -191,10 +191,10 @@ cdef class FractionFieldElement(FieldElement): if self._is_reduced: return try: - g = self.__numerator.gcd(self.__denominator) + g = self.__numerator.gcd(self._denominator) if not g.is_unit(): self.__numerator //= g - self.__denominator //= g + self._denominator //= g self._is_reduced = True except AttributeError: raise ArithmeticError("unable to reduce because lack of gcd or quo_rem algorithm") @@ -202,14 +202,14 @@ cdef class FractionFieldElement(FieldElement): raise ArithmeticError("unable to reduce because gcd algorithm doesn't work on input") except NotImplementedError: raise ArithmeticError("unable to reduce because gcd algorithm not implemented on input") - if not self.__denominator.is_one() and self.__denominator.is_unit(): + if not self._denominator.is_one() and self._denominator.is_unit(): try: - inv = self.__denominator.inverse_of_unit() + inv = self._denominator.inverse_of_unit() except Exception: pass else: self.__numerator *= inv - self.__denominator = self.__denominator.parent().one() + self._denominator = self._denominator.parent().one() def __copy__(self): """ @@ -224,7 +224,7 @@ cdef class FractionFieldElement(FieldElement): (x + y)/y """ return self.__class__(self._parent, self.__numerator, - self.__denominator, coerce=False, reduce=False) + self._denominator, coerce=False, reduce=False) def numerator(self): """ @@ -252,7 +252,7 @@ cdef class FractionFieldElement(FieldElement): sage: f.denominator() y """ - return self.__denominator + return self._denominator def is_square(self,root=False): @@ -399,7 +399,7 @@ cdef class FractionFieldElement(FieldElement): sage: ((x+1)/(x^2+1)).subs({x: 1}) # optional - sage.rings.number_field 1 """ - if self.__denominator.is_one(): + if self._denominator.is_one(): # Handle this case even over rings that don't support reduction, to # avoid breaking existing code that carelessly mixes p and p/1 return hash(self.__numerator) @@ -414,7 +414,7 @@ cdef class FractionFieldElement(FieldElement): self.reduce() # Same algorithm as for elements of QQ n = hash(self.__numerator) - d = hash(self.__denominator) + d = hash(self._denominator) if d == 1: return n else: @@ -443,7 +443,7 @@ cdef class FractionFieldElement(FieldElement): sage: h(x0=1) (-2*x1*x2 + x1 + 1)/(x1 + x2) """ - return self.__numerator(*x, **kwds) / self.__denominator(*x, **kwds) + return self.__numerator(*x, **kwds) / self._denominator(*x, **kwds) def _is_atomic(self): """ @@ -456,7 +456,7 @@ cdef class FractionFieldElement(FieldElement): sage: f._is_atomic() False """ - return self.__numerator._is_atomic() and self.__denominator._is_atomic() + return self.__numerator._is_atomic() and self._denominator._is_atomic() def _repr_(self): """ @@ -477,9 +477,9 @@ cdef class FractionFieldElement(FieldElement): if self.is_zero(): return "0" s = "%s" % self.__numerator - if self.__denominator != 1: - denom_string = str( self.__denominator ) - if self.__denominator._is_atomic() and not ('*' in denom_string or '/' in denom_string): + if self._denominator != 1: + denom_string = str( self._denominator ) + if self._denominator._is_atomic() and not ('*' in denom_string or '/' in denom_string): s = "%s/%s"%(self.__numerator._coeff_repr(no_space=False),denom_string) else: s = "%s/(%s)"%(self.__numerator._coeff_repr(no_space=False),denom_string) @@ -518,10 +518,10 @@ cdef class FractionFieldElement(FieldElement): """ if self.is_zero(): return "0" - if self.__denominator == 1: + if self._denominator == 1: return latex.latex(self.__numerator) return "\\frac{%s}{%s}"%(latex.latex(self.__numerator), - latex.latex(self.__denominator)) + latex.latex(self._denominator)) def _magma_init_(self, magma): """ @@ -578,9 +578,9 @@ cdef class FractionFieldElement(FieldElement): (t^2 + 6)/t """ rnum = self.__numerator - rden = self.__denominator + rden = self._denominator snum = ( right).__numerator - sden = ( right).__denominator + sden = ( right)._denominator if (rnum.is_zero()): return right @@ -602,7 +602,7 @@ cdef class FractionFieldElement(FieldElement): self._parent.ring().one(), coerce=False, reduce=False) else: - tden = self.__denominator * sden + tden = self._denominator * sden e = tnum.gcd(d) if not e.is_unit(): tnum = tnum // e @@ -625,9 +625,9 @@ cdef class FractionFieldElement(FieldElement): pass rnum = self.__numerator - rden = self.__denominator + rden = self._denominator snum = ( right).__numerator - sden = ( right).__denominator + sden = ( right)._denominator return self.__class__(self._parent, rnum*sden + rden*snum, rden*sden, coerce=False, reduce=False) @@ -653,9 +653,9 @@ cdef class FractionFieldElement(FieldElement): 3/(t + 1) """ rnum = self.__numerator - rden = self.__denominator + rden = self._denominator snum = ( right).__numerator - sden = ( right).__denominator + sden = ( right)._denominator if (rnum.is_zero() or snum.is_zero()): return self._parent.zero() @@ -690,9 +690,9 @@ cdef class FractionFieldElement(FieldElement): pass rnum = self.__numerator - rden = self.__denominator + rden = self._denominator snum = ( right).__numerator - sden = ( right).__denominator + sden = ( right)._denominator return self.__class__(self._parent, rnum * snum, rden * sden, coerce=False, reduce=False) @@ -718,7 +718,7 @@ cdef class FractionFieldElement(FieldElement): (x*z - x + z - 1)/(z - 3) """ snum = ( right).__numerator - sden = ( right).__denominator + sden = ( right)._denominator if snum.is_zero(): raise ZeroDivisionError("fraction field element division by zero") @@ -743,9 +743,9 @@ cdef class FractionFieldElement(FieldElement): sage: int(K(.5)) 0 """ - if self.__denominator != 1: + if self._denominator != 1: self.reduce() - if self.__denominator == 1: + if self._denominator == 1: return int(self.__numerator) else: raise TypeError("denominator must equal 1") @@ -758,7 +758,7 @@ cdef class FractionFieldElement(FieldElement): sage: float(x/x + y/y) 2.0 """ - return float(self.__numerator) / float(self.__denominator) + return float(self.__numerator) / float(self._denominator) def __complex__(self): """ @@ -768,7 +768,7 @@ cdef class FractionFieldElement(FieldElement): sage: complex(x/(I*x) + (I*y)/y) 0j """ - return complex(self.__numerator) / complex(self.__denominator) + return complex(self.__numerator) / complex(self._denominator) def _rational_(self): r""" @@ -822,12 +822,12 @@ cdef class FractionFieldElement(FieldElement): sage: A(C(u)) # optional - sage.rings.number_field u """ - if self.__denominator.is_one(): + if self._denominator.is_one(): return R(self.__numerator) else: self.reduce() num = R(self.__numerator) - inv_den = R(self.__denominator).inverse_of_unit() + inv_den = R(self._denominator).inverse_of_unit() return num * inv_den _real_double_ = _conversion @@ -847,7 +847,7 @@ cdef class FractionFieldElement(FieldElement): Returns self raised to the `right^{th}` power. Note that we need to check whether or not right is negative so we - don't set ``__numerator`` or ``__denominator`` to an element of the + don't set ``__numerator`` or ``_denominator`` to an element of the fraction field instead of the underlying ring. EXAMPLES:: @@ -877,7 +877,7 @@ cdef class FractionFieldElement(FieldElement): 1 """ snum = ( self).__numerator - sden = ( self).__denominator + sden = ( self)._denominator if right == 0: R = self.parent().ring() return self.__class__(self.parent(), @@ -904,7 +904,7 @@ cdef class FractionFieldElement(FieldElement): (4*t^2 + 4*t)/(t + 2) """ return self.__class__(self._parent, - -self.__numerator, self.__denominator, + -self.__numerator, self._denominator, coerce=False, reduce=False) def __abs__(self): @@ -915,7 +915,7 @@ cdef class FractionFieldElement(FieldElement): sage: abs(FractionFieldElement(QQ, -2, 3, coerce=False)) 2/3 """ - return abs(self.__numerator) / abs(self.__denominator) + return abs(self.__numerator) / abs(self._denominator) def __invert__(self): """ @@ -929,7 +929,7 @@ cdef class FractionFieldElement(FieldElement): if self.is_zero(): raise ZeroDivisionError("Cannot invert 0") return self.__class__(self._parent, - self.__denominator, self.__numerator, coerce=False, reduce=False) + self._denominator, self.__numerator, coerce=False, reduce=False) cpdef _richcmp_(self, other, int op): """ @@ -952,8 +952,8 @@ cdef class FractionFieldElement(FieldElement): False """ return richcmp(self.__numerator * - (other).__denominator, - self.__denominator * + (other)._denominator, + self._denominator * (other).__numerator, op) def valuation(self, v=None): @@ -972,7 +972,7 @@ cdef class FractionFieldElement(FieldElement): sage: f.valuation(x^2 + 1) 1 """ - return self.__numerator.valuation(v) - self.__denominator.valuation(v) + return self.__numerator.valuation(v) - self._denominator.valuation(v) def __bool__(self): """ @@ -1025,7 +1025,7 @@ cdef class FractionFieldElement(FieldElement): sage: (x/y).is_one() False """ - return self.__numerator == self.__denominator + return self.__numerator == self._denominator def _symbolic_(self, ring): """ @@ -1044,7 +1044,7 @@ cdef class FractionFieldElement(FieldElement): sage: symbolic_expression(elt) # optional - sage.symbolic 2/3*(x + y)/(x - y) """ - return ring(self.__numerator)/ring(self.__denominator) + return ring(self.__numerator)/ring(self._denominator) def __reduce__(self): """ @@ -1058,7 +1058,7 @@ cdef class FractionFieldElement(FieldElement): True """ return (make_element, - (self._parent, self.__numerator, self.__denominator)) + (self._parent, self.__numerator, self._denominator)) def _evaluate_polynomial(self, pol): """ @@ -1170,8 +1170,8 @@ cdef class FractionFieldElement_1poly_field(FractionFieldElement): """ See :meth:`reduce`. """ - invlc = ~self.__denominator.leading_coefficient() - self.__denominator = self.__denominator.monic() + invlc = ~self._denominator.leading_coefficient() + self._denominator = self._denominator.monic() self.__numerator *= invlc def is_integral(self): diff --git a/src/sage/rings/number_field/number_field_element.pxd b/src/sage/rings/number_field/number_field_element.pxd index 9b6917223a0..dd2530caf45 100644 --- a/src/sage/rings/number_field/number_field_element.pxd +++ b/src/sage/rings/number_field/number_field_element.pxd @@ -12,7 +12,7 @@ from sage.libs.ntl.ntl_ZZ cimport ntl_ZZ cdef class NumberFieldElement(NumberFieldElement_base): cdef ZZX_c __numerator - cdef ZZ_c __denominator + cdef ZZ_c _denominator # Pointers to the defining polynomial (with numerator) for the field. # I keep these as pointers for arithmetic speed. cdef ntl_ZZX __fld_numerator diff --git a/src/sage/rings/number_field/number_field_element.pyx b/src/sage/rings/number_field/number_field_element.pyx index 1ffd5cf07c9..03de9148f50 100644 --- a/src/sage/rings/number_field/number_field_element.pyx +++ b/src/sage/rings/number_field/number_field_element.pyx @@ -325,12 +325,12 @@ cdef class NumberFieldElement(NumberFieldElement_base): # fast pathway mpz_to_ZZ(&coeff, (ZZ(f)).value) ZZX_SetCoeff( self.__numerator, 0, coeff ) - ZZ_conv_from_int( self.__denominator, 1 ) + ZZ_conv_from_int( self._denominator, 1 ) return elif isinstance(f, NumberFieldElement): if type(self) is type(f): self.__numerator = (f).__numerator - self.__denominator = (f).__denominator + self._denominator = (f)._denominator return else: f = f.polynomial() @@ -342,7 +342,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef long i den = f.denominator() - mpz_to_ZZ(&self.__denominator, (ZZ(den)).value) + mpz_to_ZZ(&self._denominator, (ZZ(den)).value) num = f * den for i from 0 <= i <= num.degree(): mpz_to_ZZ(&coeff, (ZZ(num[i])).value) @@ -418,7 +418,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef NumberFieldElement x = t.__new__(t) x._parent = new_parent x.__fld_numerator, x.__fld_denominator = new_parent.polynomial_ntl() - x.__denominator = self.__denominator + x._denominator = self._denominator cdef ZZX_c result cdef ZZ_c tmp cdef int i @@ -858,7 +858,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef int res # fast equality check - res = left.__numerator == _right.__numerator and left.__denominator == _right.__denominator + res = left.__numerator == _right.__numerator and left._denominator == _right._denominator if res: if op == Py_EQ or op == Py_GE or op == Py_LE: return True @@ -883,8 +883,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): if P._embedded_real: mpz_init(ld) mpz_init(rd) - ZZ_to_mpz(ld, &left.__denominator) - ZZ_to_mpz(rd, &_right.__denominator) + ZZ_to_mpz(ld, &left._denominator) + ZZ_to_mpz(rd, &_right._denominator) v = P._get_embedding_approx(0) mpfi_init2(la, mpfi_get_prec(v.value)) @@ -951,7 +951,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): # It seems like a simpler approach would be to simply generate # random integers for each coefficient of self.__numerator - # and an integer for self.__denominator. However, this would + # and an integer for self._denominator. However, this would # generate things with a fairly fixed shape: in particular, # we'd be very unlikely to get elements like 1/3*a^3 + 1/7, # or anything where the denominators are actually unrelated @@ -965,7 +965,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): # set the denominator mpz_set_si(denom_temp.value, 1) - mpz_to_ZZ(&self.__denominator, (denom_temp).value) + mpz_to_ZZ(&self._denominator, (denom_temp).value) for i from 0 <= i < ZZX_deg(self.__fld_numerator.x): tmp_integer = (ZZ.random_element(x=num_bound, distribution=distribution)) @@ -989,7 +989,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): # scale the numerators and set everything appropriately # first, the denominator (easy) - mpz_to_ZZ(&self.__denominator, (denom_temp).value) + mpz_to_ZZ(&self._denominator, (denom_temp).value) # now the coefficients themselves. for i from 0 <= i < ZZX_deg(self.__fld_numerator.x): @@ -1158,7 +1158,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): mpz_init(den) ZZX_getitem_as_mpz(num, &self.__numerator, 0) - ZZ_to_mpz(den, &self.__denominator) + ZZ_to_mpz(den, &self._denominator) ans = PY_NEW(Integer) mpz_fdiv_q(ans.value, num, den) @@ -1183,7 +1183,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): mpz_init(den) mpfi_init2(a, mpfi_get_prec(v.value)) - ZZ_to_mpz(den, &self.__denominator) + ZZ_to_mpz(den, &self._denominator) ZZX_evaluation_mpfi(a, self.__numerator, v.value) mpfi_div_z(a, a, den) @@ -2483,17 +2483,17 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef ZZ_c gcd cdef ZZ_c t1 cdef ZZX_c t2 - if ZZ_IsOne(self.__denominator): + if ZZ_IsOne(self._denominator): return ZZX_content(t1, self.__numerator) - ZZ_GCD(gcd, t1, self.__denominator) - if ZZ_sign(gcd) != ZZ_sign(self.__denominator): + ZZ_GCD(gcd, t1, self._denominator) + if ZZ_sign(gcd) != ZZ_sign(self._denominator): ZZ_negate(t1, gcd) gcd = t1 ZZX_div_ZZ(t2, self.__numerator, gcd) - ZZ_div(t1, self.__denominator, gcd) + ZZ_div(t1, self._denominator, gcd) self.__numerator = t2 - self.__denominator = t1 + self._denominator = t1 cpdef _add_(self, right): r""" @@ -2509,11 +2509,11 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef NumberFieldElement _right = right cdef ZZ_c g, q1, q2 x = self._new() - ZZ_GCD(g, self.__denominator, _right.__denominator) - ZZ_div(q1, self.__denominator, g) - ZZ_div(q2, _right.__denominator, g) - ZZ_mul(x.__denominator, q1, q2) - ZZ_mul(x.__denominator, x.__denominator, g) + ZZ_GCD(g, self._denominator, _right._denominator) + ZZ_div(q1, self._denominator, g) + ZZ_div(q2, _right._denominator, g) + ZZ_mul(x._denominator, q1, q2) + ZZ_mul(x._denominator, x._denominator, g) cdef ZZX_c t1, t2 ZZX_mul_ZZ(t1, self.__numerator, q2) ZZX_mul_ZZ(t2, _right.__numerator, q1) @@ -2534,11 +2534,11 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef NumberFieldElement _right = right cdef ZZ_c g, q1, q2 x = self._new() - ZZ_GCD(g, self.__denominator, _right.__denominator) - ZZ_div(q1, self.__denominator, g) - ZZ_div(q2, _right.__denominator, g) - ZZ_mul(x.__denominator, q1, q2) - ZZ_mul(x.__denominator, x.__denominator, g) + ZZ_GCD(g, self._denominator, _right._denominator) + ZZ_div(q1, self._denominator, g) + ZZ_div(q2, _right._denominator, g) + ZZ_mul(x._denominator, q1, q2) + ZZ_mul(x._denominator, x._denominator, g) cdef ZZX_c t1, t2 ZZX_mul_ZZ(t1, self.__numerator, q2) ZZX_mul_ZZ(t2, _right.__numerator, q1) @@ -2571,18 +2571,18 @@ cdef class NumberFieldElement(NumberFieldElement_base): sig_on() # MulMod doesn't handle non-monic polynomials. # Therefore, we handle the non-monic case entirely separately. - ZZ_mul(x.__denominator, self.__denominator, _right.__denominator) + ZZ_mul(x._denominator, self._denominator, _right._denominator) if ZZ_IsOne(ZZX_LeadCoeff(self.__fld_numerator.x)): ZZX_MulMod(x.__numerator, self.__numerator, _right.__numerator, self.__fld_numerator.x) else: ZZX_mul(x.__numerator, self.__numerator, _right.__numerator) if ZZX_deg(x.__numerator) >= ZZX_deg(self.__fld_numerator.x): ZZX_mul_ZZ( x.__numerator, x.__numerator, self.__fld_denominator.x ) - ZZX_mul_ZZ( temp, self.__fld_numerator.x, x.__denominator ) + ZZX_mul_ZZ( temp, self.__fld_numerator.x, x._denominator ) ZZ_power(temp1,ZZX_LeadCoeff(temp),ZZX_deg(x.__numerator)-ZZX_deg(self.__fld_numerator.x)+1) ZZX_PseudoRem(x.__numerator, x.__numerator, temp) - ZZ_mul(x.__denominator, x.__denominator, self.__fld_denominator.x) - ZZ_mul(x.__denominator, x.__denominator, temp1) + ZZ_mul(x._denominator, x._denominator, self.__fld_denominator.x) + ZZ_mul(x._denominator, x._denominator, temp1) sig_off() x._reduce_c_() return x @@ -2718,7 +2718,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef NumberFieldElement x x = self._new() ZZX_mul_long(x.__numerator, self.__numerator, -1) - x.__denominator = self.__denominator + x._denominator = self._denominator return x cpdef _copy_for_parent(self, Parent parent): @@ -2739,7 +2739,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef NumberFieldElement x x = self._new() x.__numerator = self.__numerator - x.__denominator = self.__denominator + x._denominator = self._denominator x._set_parent(parent) return x @@ -2835,8 +2835,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): # but may fail if NTL runs out of FFT primes. x = self._new() sig_on() - ZZX_XGCD(x.__denominator, x.__numerator, temp, self.__numerator, self.__fld_numerator.x, 1) - ZZX_mul_ZZ(x.__numerator, x.__numerator, self.__denominator) + ZZX_XGCD(x._denominator, x.__numerator, temp, self.__numerator, self.__fld_numerator.x, 1) + ZZX_mul_ZZ(x.__numerator, x.__numerator, self._denominator) x._reduce_c_() sig_off() except NTLError: @@ -2882,7 +2882,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef Integer num = Integer.__new__(Integer) ZZX_getitem_as_mpz(num.value, &self.__numerator, 0) cdef Integer den = Integer.__new__(Integer) - ZZ_to_mpz(den.value, &self.__denominator) + ZZ_to_mpz(den.value, &self._denominator) return num / den def _algebraic_(self, parent): @@ -3276,7 +3276,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): # magic number below is floor(2^63 / (2+sqrt(2))) h ^= mpz_pythonhash(z) + ( 2701463124188384701) + (h << 16) + (h >> 2) - ZZ_to_mpz(z, &self.__denominator) + ZZ_to_mpz(z, &self._denominator) # magic number below is floor((1+sqrt(5)) * 2^61) h += (mpz_pythonhash(z) - 1) * ( 7461864723258187525) @@ -3305,7 +3305,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef int i cdef mpz_t den mpz_init(den) - ZZ_to_mpz(den, &self.__denominator) + ZZ_to_mpz(den, &self._denominator) cdef int size = ZZX_deg(self.__numerator) + 1 cdef list coeffs = [None]*size for i in range(size): @@ -3325,7 +3325,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef void _ntl_denom_as_mpz(self, mpz_t z): cdef Integer denom = Integer.__new__(Integer) - ZZ_to_mpz(denom.value, &self.__denominator) + ZZ_to_mpz(denom.value, &self._denominator) mpz_set(z, denom.value) def denominator(self): @@ -3344,7 +3344,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): 15 """ cdef Integer ans = Integer.__new__(Integer) - ZZ_to_mpz(ans.value, &self.__denominator) + ZZ_to_mpz(ans.value, &self._denominator) return ans def _set_multiplicative_order(self, n): @@ -3475,7 +3475,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): False """ return ZZX_IsOne(self.__numerator) == 1 and \ - ZZ_IsOne(self.__denominator) == 1 + ZZ_IsOne(self._denominator) == 1 cpdef bint is_rational(self): r""" @@ -3527,7 +3527,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: K(1/2).is_integer() False """ - return ZZX_deg(self.__numerator) <= 0 and ZZ_IsOne(self.__denominator) == 1 + return ZZX_deg(self.__numerator) <= 0 and ZZ_IsOne(self._denominator) == 1 def trace(self, K=None): r""" diff --git a/src/sage/rings/number_field/number_field_element_quadratic.pyx b/src/sage/rings/number_field/number_field_element_quadratic.pyx index 4982fc0cd7d..436f888d111 100644 --- a/src/sage/rings/number_field/number_field_element_quadratic.pyx +++ b/src/sage/rings/number_field/number_field_element_quadratic.pyx @@ -611,7 +611,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): x._parent = new_parent x.__fld_numerator, x.__fld_denominator = new_parent.polynomial_ntl() - x.__denominator = elt_den + x._denominator = elt_den cdef ZZX_c result cdef ZZ_c tmp cdef int i @@ -1642,7 +1642,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): return res ################################################################################# -# We must override everything that makes uses of self.__numerator/__denominator +# We must override everything that makes uses of self.__numerator/_denominator ################################################################################# def __hash__(self): From b6abb70be4e6245adb6122c6ecb7160824d4b255 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:40:31 +0800 Subject: [PATCH 22/44] rename __numerator -> _numerator --- .../quatalg/quaternion_algebra_element.pyx | 20 +-- src/sage/matrix/matrix_cyclo_dense.pyx | 2 +- src/sage/rings/fraction_field_element.pyx | 92 +++++++------- .../number_field/number_field_element.pxd | 2 +- .../number_field/number_field_element.pyx | 114 +++++++++--------- .../number_field_element_quadratic.pyx | 4 +- 6 files changed, 117 insertions(+), 117 deletions(-) diff --git a/src/sage/algebras/quatalg/quaternion_algebra_element.pyx b/src/sage/algebras/quatalg/quaternion_algebra_element.pyx index 0e93d2f3f55..b42182851fa 100644 --- a/src/sage/algebras/quatalg/quaternion_algebra_element.pyx +++ b/src/sage/algebras/quatalg/quaternion_algebra_element.pyx @@ -1700,10 +1700,10 @@ cdef class QuaternionAlgebraElement_number_field(QuaternionAlgebraElement_abstra x, y, z, w = v cdef NumberFieldElement a = (parent._base(parent._a)) cdef NumberFieldElement b = (parent._base(parent._b)) - fmpz_poly_set_ZZX(self.x, (x).__numerator) - fmpz_poly_set_ZZX(self.y, (y).__numerator) - fmpz_poly_set_ZZX(self.z, (z).__numerator) - fmpz_poly_set_ZZX(self.w, (w).__numerator) + fmpz_poly_set_ZZX(self.x, (x)._numerator) + fmpz_poly_set_ZZX(self.y, (y)._numerator) + fmpz_poly_set_ZZX(self.z, (z)._numerator) + fmpz_poly_set_ZZX(self.w, (w)._numerator) ZZ_to_mpz(T1, &(x)._denominator) ZZ_to_mpz(T2, &(y)._denominator) @@ -1724,8 +1724,8 @@ cdef class QuaternionAlgebraElement_number_field(QuaternionAlgebraElement_abstra fmpz_poly_scalar_mul_mpz(self.z, self.z, t3) fmpz_poly_scalar_mul_mpz(self.w, self.w, t4) - fmpz_poly_set_ZZX(self.a, a.__numerator) # we will assume that the denominator of a and b are 1 - fmpz_poly_set_ZZX(self.b, b.__numerator) + fmpz_poly_set_ZZX(self.a, a._numerator) # we will assume that the denominator of a and b are 1 + fmpz_poly_set_ZZX(self.b, b._numerator) fmpz_poly_set_ZZX(self.modulus, (x).__fld_numerator.x) # and same for the modulus @@ -1756,13 +1756,13 @@ cdef class QuaternionAlgebraElement_number_field(QuaternionAlgebraElement_abstra cdef NumberFieldElement item = el._new() if i == 0: - fmpz_poly_get_ZZX(item.__numerator, self.x) + fmpz_poly_get_ZZX(item._numerator, self.x) elif i == 1: - fmpz_poly_get_ZZX(item.__numerator, self.y) + fmpz_poly_get_ZZX(item._numerator, self.y) elif i == 2: - fmpz_poly_get_ZZX(item.__numerator, self.z) + fmpz_poly_get_ZZX(item._numerator, self.z) elif i == 3: - fmpz_poly_get_ZZX(item.__numerator, self.w) + fmpz_poly_get_ZZX(item._numerator, self.w) else: raise IndexError("quaternion element index out of range") diff --git a/src/sage/matrix/matrix_cyclo_dense.pyx b/src/sage/matrix/matrix_cyclo_dense.pyx index 4e1865880be..92991829645 100644 --- a/src/sage/matrix/matrix_cyclo_dense.pyx +++ b/src/sage/matrix/matrix_cyclo_dense.pyx @@ -396,7 +396,7 @@ cdef class Matrix_cyclo_dense(Matrix_dense): # Now set k-th entry of x's numerator to tmp fmpz_get_mpz(tmp, ftmp) mpz_to_ZZ(&coeff, tmp) - ZZX_SetCoeff(x.__numerator, k, coeff) + ZZX_SetCoeff(x._numerator, k, coeff) # Set the denominator of x to denom. fmpz_get_mpz(tmp, denom) diff --git a/src/sage/rings/fraction_field_element.pyx b/src/sage/rings/fraction_field_element.pyx index 0ed690cb28e..75e47af1299 100644 --- a/src/sage/rings/fraction_field_element.pyx +++ b/src/sage/rings/fraction_field_element.pyx @@ -78,7 +78,7 @@ cdef class FractionFieldElement(FieldElement): sage: F.one().quo_rem(F.one()) (1, 0) """ - cdef object __numerator + cdef object _numerator cdef object _denominator cdef bint _is_reduced @@ -108,10 +108,10 @@ cdef class FractionFieldElement(FieldElement): """ FieldElement.__init__(self, parent) if coerce: - self.__numerator = parent.ring()(numerator) + self._numerator = parent.ring()(numerator) self._denominator = parent.ring()(denominator) else: - self.__numerator = numerator + self._numerator = numerator self._denominator = denominator if reduce and parent.is_exact(): try: @@ -154,7 +154,7 @@ cdef class FractionFieldElement(FieldElement): sage: phi(i/a) # optional - sage.rings.number_field ((-i))/b """ - nnum = codomain.coerce(self.__numerator._im_gens_(codomain, im_gens, base_map=base_map)) + nnum = codomain.coerce(self._numerator._im_gens_(codomain, im_gens, base_map=base_map)) nden = codomain.coerce(self._denominator._im_gens_(codomain, im_gens, base_map=base_map)) return codomain.coerce(nnum/nden) @@ -191,9 +191,9 @@ cdef class FractionFieldElement(FieldElement): if self._is_reduced: return try: - g = self.__numerator.gcd(self._denominator) + g = self._numerator.gcd(self._denominator) if not g.is_unit(): - self.__numerator //= g + self._numerator //= g self._denominator //= g self._is_reduced = True except AttributeError: @@ -208,7 +208,7 @@ cdef class FractionFieldElement(FieldElement): except Exception: pass else: - self.__numerator *= inv + self._numerator *= inv self._denominator = self._denominator.parent().one() def __copy__(self): @@ -223,7 +223,7 @@ cdef class FractionFieldElement(FieldElement): sage: copy(f) (x + y)/y """ - return self.__class__(self._parent, self.__numerator, + return self.__class__(self._parent, self._numerator, self._denominator, coerce=False, reduce=False) def numerator(self): @@ -238,7 +238,7 @@ cdef class FractionFieldElement(FieldElement): sage: f.numerator() x + y """ - return self.__numerator + return self._numerator def denominator(self): """ @@ -402,7 +402,7 @@ cdef class FractionFieldElement(FieldElement): if self._denominator.is_one(): # Handle this case even over rings that don't support reduction, to # avoid breaking existing code that carelessly mixes p and p/1 - return hash(self.__numerator) + return hash(self._numerator) if self._parent.is_exact(): # May fail; let the exception propagate then. # (In contrast, over inexact rings, we hash unreduced fractions @@ -413,7 +413,7 @@ cdef class FractionFieldElement(FieldElement): # issues even if we didn't...) self.reduce() # Same algorithm as for elements of QQ - n = hash(self.__numerator) + n = hash(self._numerator) d = hash(self._denominator) if d == 1: return n @@ -443,7 +443,7 @@ cdef class FractionFieldElement(FieldElement): sage: h(x0=1) (-2*x1*x2 + x1 + 1)/(x1 + x2) """ - return self.__numerator(*x, **kwds) / self._denominator(*x, **kwds) + return self._numerator(*x, **kwds) / self._denominator(*x, **kwds) def _is_atomic(self): """ @@ -456,7 +456,7 @@ cdef class FractionFieldElement(FieldElement): sage: f._is_atomic() False """ - return self.__numerator._is_atomic() and self._denominator._is_atomic() + return self._numerator._is_atomic() and self._denominator._is_atomic() def _repr_(self): """ @@ -476,13 +476,13 @@ cdef class FractionFieldElement(FieldElement): """ if self.is_zero(): return "0" - s = "%s" % self.__numerator + s = "%s" % self._numerator if self._denominator != 1: denom_string = str( self._denominator ) if self._denominator._is_atomic() and not ('*' in denom_string or '/' in denom_string): - s = "%s/%s"%(self.__numerator._coeff_repr(no_space=False),denom_string) + s = "%s/%s"%(self._numerator._coeff_repr(no_space=False),denom_string) else: - s = "%s/(%s)"%(self.__numerator._coeff_repr(no_space=False),denom_string) + s = "%s/(%s)"%(self._numerator._coeff_repr(no_space=False),denom_string) return s def _latex_(self): @@ -519,8 +519,8 @@ cdef class FractionFieldElement(FieldElement): if self.is_zero(): return "0" if self._denominator == 1: - return latex.latex(self.__numerator) - return "\\frac{%s}{%s}"%(latex.latex(self.__numerator), + return latex.latex(self._numerator) + return "\\frac{%s}{%s}"%(latex.latex(self._numerator), latex.latex(self._denominator)) def _magma_init_(self, magma): @@ -577,9 +577,9 @@ cdef class FractionFieldElement(FieldElement): sage: t - 1/t # indirect doctest # optional - sage.rings.finite_rings (t^2 + 6)/t """ - rnum = self.__numerator + rnum = self._numerator rden = self._denominator - snum = ( right).__numerator + snum = ( right)._numerator sden = ( right)._denominator if (rnum.is_zero()): @@ -624,9 +624,9 @@ cdef class FractionFieldElement(FieldElement): except TypeError: pass - rnum = self.__numerator + rnum = self._numerator rden = self._denominator - snum = ( right).__numerator + snum = ( right)._numerator sden = ( right)._denominator return self.__class__(self._parent, rnum*sden + rden*snum, rden*sden, @@ -652,9 +652,9 @@ cdef class FractionFieldElement(FieldElement): sage: a * b # indirect doctest # optional - sage.rings.finite_rings 3/(t + 1) """ - rnum = self.__numerator + rnum = self._numerator rden = self._denominator - snum = ( right).__numerator + snum = ( right)._numerator sden = ( right)._denominator if (rnum.is_zero() or snum.is_zero()): @@ -689,9 +689,9 @@ cdef class FractionFieldElement(FieldElement): except TypeError: pass - rnum = self.__numerator + rnum = self._numerator rden = self._denominator - snum = ( right).__numerator + snum = ( right)._numerator sden = ( right)._denominator return self.__class__(self._parent, rnum * snum, rden * sden, @@ -717,7 +717,7 @@ cdef class FractionFieldElement(FieldElement): sage: a/b (x*z - x + z - 1)/(z - 3) """ - snum = ( right).__numerator + snum = ( right)._numerator sden = ( right)._denominator if snum.is_zero(): @@ -746,7 +746,7 @@ cdef class FractionFieldElement(FieldElement): if self._denominator != 1: self.reduce() if self._denominator == 1: - return int(self.__numerator) + return int(self._numerator) else: raise TypeError("denominator must equal 1") @@ -758,7 +758,7 @@ cdef class FractionFieldElement(FieldElement): sage: float(x/x + y/y) 2.0 """ - return float(self.__numerator) / float(self._denominator) + return float(self._numerator) / float(self._denominator) def __complex__(self): """ @@ -768,7 +768,7 @@ cdef class FractionFieldElement(FieldElement): sage: complex(x/(I*x) + (I*y)/y) 0j """ - return complex(self.__numerator) / complex(self._denominator) + return complex(self._numerator) / complex(self._denominator) def _rational_(self): r""" @@ -823,10 +823,10 @@ cdef class FractionFieldElement(FieldElement): u """ if self._denominator.is_one(): - return R(self.__numerator) + return R(self._numerator) else: self.reduce() - num = R(self.__numerator) + num = R(self._numerator) inv_den = R(self._denominator).inverse_of_unit() return num * inv_den @@ -847,7 +847,7 @@ cdef class FractionFieldElement(FieldElement): Returns self raised to the `right^{th}` power. Note that we need to check whether or not right is negative so we - don't set ``__numerator`` or ``_denominator`` to an element of the + don't set ``_numerator`` or ``_denominator`` to an element of the fraction field instead of the underlying ring. EXAMPLES:: @@ -876,7 +876,7 @@ cdef class FractionFieldElement(FieldElement): sage: ((x+y)/(x-y))^0 1 """ - snum = ( self).__numerator + snum = ( self)._numerator sden = ( self)._denominator if right == 0: R = self.parent().ring() @@ -904,7 +904,7 @@ cdef class FractionFieldElement(FieldElement): (4*t^2 + 4*t)/(t + 2) """ return self.__class__(self._parent, - -self.__numerator, self._denominator, + -self._numerator, self._denominator, coerce=False, reduce=False) def __abs__(self): @@ -915,7 +915,7 @@ cdef class FractionFieldElement(FieldElement): sage: abs(FractionFieldElement(QQ, -2, 3, coerce=False)) 2/3 """ - return abs(self.__numerator) / abs(self._denominator) + return abs(self._numerator) / abs(self._denominator) def __invert__(self): """ @@ -929,7 +929,7 @@ cdef class FractionFieldElement(FieldElement): if self.is_zero(): raise ZeroDivisionError("Cannot invert 0") return self.__class__(self._parent, - self._denominator, self.__numerator, coerce=False, reduce=False) + self._denominator, self._numerator, coerce=False, reduce=False) cpdef _richcmp_(self, other, int op): """ @@ -951,10 +951,10 @@ cdef class FractionFieldElement(FieldElement): sage: 1 > y False """ - return richcmp(self.__numerator * + return richcmp(self._numerator * (other)._denominator, self._denominator * - (other).__numerator, op) + (other)._numerator, op) def valuation(self, v=None): """ @@ -972,7 +972,7 @@ cdef class FractionFieldElement(FieldElement): sage: f.valuation(x^2 + 1) 1 """ - return self.__numerator.valuation(v) - self._denominator.valuation(v) + return self._numerator.valuation(v) - self._denominator.valuation(v) def __bool__(self): """ @@ -991,7 +991,7 @@ cdef class FractionFieldElement(FieldElement): sage: bool(1/x) True """ - return not self.__numerator.is_zero() + return not self._numerator.is_zero() def is_zero(self): """ @@ -1010,7 +1010,7 @@ cdef class FractionFieldElement(FieldElement): sage: u.parent() is F True """ - return self.__numerator.is_zero() + return self._numerator.is_zero() def is_one(self): """ @@ -1025,7 +1025,7 @@ cdef class FractionFieldElement(FieldElement): sage: (x/y).is_one() False """ - return self.__numerator == self._denominator + return self._numerator == self._denominator def _symbolic_(self, ring): """ @@ -1044,7 +1044,7 @@ cdef class FractionFieldElement(FieldElement): sage: symbolic_expression(elt) # optional - sage.symbolic 2/3*(x + y)/(x - y) """ - return ring(self.__numerator)/ring(self._denominator) + return ring(self._numerator)/ring(self._denominator) def __reduce__(self): """ @@ -1058,7 +1058,7 @@ cdef class FractionFieldElement(FieldElement): True """ return (make_element, - (self._parent, self.__numerator, self._denominator)) + (self._parent, self._numerator, self._denominator)) def _evaluate_polynomial(self, pol): """ @@ -1172,7 +1172,7 @@ cdef class FractionFieldElement_1poly_field(FractionFieldElement): """ invlc = ~self._denominator.leading_coefficient() self._denominator = self._denominator.monic() - self.__numerator *= invlc + self._numerator *= invlc def is_integral(self): """ diff --git a/src/sage/rings/number_field/number_field_element.pxd b/src/sage/rings/number_field/number_field_element.pxd index dd2530caf45..418e54aba8c 100644 --- a/src/sage/rings/number_field/number_field_element.pxd +++ b/src/sage/rings/number_field/number_field_element.pxd @@ -11,7 +11,7 @@ from sage.libs.ntl.ntl_ZZ cimport ntl_ZZ cdef class NumberFieldElement(NumberFieldElement_base): - cdef ZZX_c __numerator + cdef ZZX_c _numerator cdef ZZ_c _denominator # Pointers to the defining polynomial (with numerator) for the field. # I keep these as pointers for arithmetic speed. diff --git a/src/sage/rings/number_field/number_field_element.pyx b/src/sage/rings/number_field/number_field_element.pyx index 03de9148f50..cfc86bdac6f 100644 --- a/src/sage/rings/number_field/number_field_element.pyx +++ b/src/sage/rings/number_field/number_field_element.pyx @@ -324,12 +324,12 @@ cdef class NumberFieldElement(NumberFieldElement_base): # set it up and exit immediately # fast pathway mpz_to_ZZ(&coeff, (ZZ(f)).value) - ZZX_SetCoeff( self.__numerator, 0, coeff ) + ZZX_SetCoeff( self._numerator, 0, coeff ) ZZ_conv_from_int( self._denominator, 1 ) return elif isinstance(f, NumberFieldElement): if type(self) is type(f): - self.__numerator = (f).__numerator + self._numerator = (f)._numerator self._denominator = (f)._denominator return else: @@ -346,7 +346,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): num = f * den for i from 0 <= i <= num.degree(): mpz_to_ZZ(&coeff, (ZZ(num[i])).value) - ZZX_SetCoeff( self.__numerator, i, coeff ) + ZZX_SetCoeff( self._numerator, i, coeff ) def _lift_cyclotomic_element(self, new_parent, bint check=True, int rel=0): """ @@ -424,10 +424,10 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef int i cdef ntl_ZZX _num cdef ntl_ZZ _den - for i from 0 <= i <= ZZX_deg(self.__numerator): - tmp = ZZX_coeff(self.__numerator, i) + for i from 0 <= i <= ZZX_deg(self._numerator): + tmp = ZZX_coeff(self._numerator, i) ZZX_SetCoeff(result, i*rel, tmp) - ZZX_rem(x.__numerator, result, x.__fld_numerator.x) + ZZX_rem(x._numerator, result, x.__fld_numerator.x) return x def __reduce__(self): @@ -858,7 +858,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef int res # fast equality check - res = left.__numerator == _right.__numerator and left._denominator == _right._denominator + res = left._numerator == _right._numerator and left._denominator == _right._denominator if res: if op == Py_EQ or op == Py_GE or op == Py_LE: return True @@ -889,9 +889,9 @@ cdef class NumberFieldElement(NumberFieldElement_base): v = P._get_embedding_approx(0) mpfi_init2(la, mpfi_get_prec(v.value)) mpfi_init2(ra, mpfi_get_prec(v.value)) - ZZX_evaluation_mpfi(la, left.__numerator, v.value) + ZZX_evaluation_mpfi(la, left._numerator, v.value) mpfi_div_z(la, la, ld) - ZZX_evaluation_mpfi(ra, _right.__numerator, v.value) + ZZX_evaluation_mpfi(ra, _right._numerator, v.value) mpfi_div_z(ra, ra, rd) while mpfr_greaterequal_p(&la.right, &ra.left) \ and mpfr_greaterequal_p(&ra.right, &la.left): @@ -899,9 +899,9 @@ cdef class NumberFieldElement(NumberFieldElement_base): v = P._get_embedding_approx(i) mpfi_set_prec(la, mpfi_get_prec(v.value)) mpfi_set_prec(ra, mpfi_get_prec(v.value)) - ZZX_evaluation_mpfi(la, left.__numerator, v.value) + ZZX_evaluation_mpfi(la, left._numerator, v.value) mpfi_div_z(la, la, ld) - ZZX_evaluation_mpfi(ra, _right.__numerator, v.value) + ZZX_evaluation_mpfi(ra, _right._numerator, v.value) mpfi_div_z(ra, ra, rd) if op == Py_LT or op == Py_LE: res = mpfr_less_p(&la.right, &ra.left) @@ -950,7 +950,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef Rational tmp_rational # It seems like a simpler approach would be to simply generate - # random integers for each coefficient of self.__numerator + # random integers for each coefficient of self._numerator # and an integer for self._denominator. However, this would # generate things with a fairly fixed shape: in particular, # we'd be very unlikely to get elements like 1/3*a^3 + 1/7, @@ -970,7 +970,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): tmp_integer = (ZZ.random_element(x=num_bound, distribution=distribution)) mpz_to_ZZ(&ntl_temp, (tmp_integer).value) - ZZX_SetCoeff(self.__numerator, i, ntl_temp) + ZZX_SetCoeff(self._numerator, i, ntl_temp) else: coeff_list = [] @@ -1006,7 +1006,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): # now set the coefficient of self mpz_to_ZZ(&ntl_temp, (tmp_integer).value) - ZZX_SetCoeff(self.__numerator, i, ntl_temp) + ZZX_SetCoeff(self._numerator, i, ntl_temp) return 0 # No error @@ -1089,10 +1089,10 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: L.zero().sign() 0 """ - if ZZX_deg(self.__numerator) == -1: + if ZZX_deg(self._numerator) == -1: return 0 - if ZZX_deg(self.__numerator) == 0: - return ZZ_sign(ZZX_coeff(self.__numerator, 0)) + if ZZX_deg(self._numerator) == 0: + return ZZ_sign(ZZX_coeff(self._numerator, 0)) if not ( self._parent)._embedded_real: raise TypeError("sign not well defined since no real embedding is specified") @@ -1153,11 +1153,11 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef RealIntervalFieldElement v - if ZZX_deg(self.__numerator) <= 0: + if ZZX_deg(self._numerator) <= 0: mpz_init(num) mpz_init(den) - ZZX_getitem_as_mpz(num, &self.__numerator, 0) + ZZX_getitem_as_mpz(num, &self._numerator, 0) ZZ_to_mpz(den, &self._denominator) ans = PY_NEW(Integer) @@ -1185,7 +1185,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): ZZ_to_mpz(den, &self._denominator) - ZZX_evaluation_mpfi(a, self.__numerator, v.value) + ZZX_evaluation_mpfi(a, self._numerator, v.value) mpfi_div_z(a, a, den) mpfr_floor(&a.left, &a.left) @@ -1197,7 +1197,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): v = P._get_embedding_approx(i) mpfi_set_prec(a, mpfi_get_prec(v.value)) - ZZX_evaluation_mpfi(a, self.__numerator, v.value) + ZZX_evaluation_mpfi(a, self._numerator, v.value) mpfi_div_z(a, a, den) mpfr_floor(&a.left ,&a.left) mpfr_floor(&a.right, &a.right) @@ -1248,7 +1248,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): ... TypeError: ceil not uniquely defined since no real embedding is specified """ - if ZZX_deg(self.__numerator) <= 0: + if ZZX_deg(self._numerator) <= 0: return self._rational_().ceil() if not ( self._parent)._embedded_real: @@ -1311,7 +1311,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): ... TypeError: floor not uniquely defined since no real embedding is specified """ - if ZZX_deg(self.__numerator) <= 0: + if ZZX_deg(self._numerator) <= 0: return self._rational_().round() return (self + QQ((1,2))).floor() @@ -2485,14 +2485,14 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef ZZX_c t2 if ZZ_IsOne(self._denominator): return - ZZX_content(t1, self.__numerator) + ZZX_content(t1, self._numerator) ZZ_GCD(gcd, t1, self._denominator) if ZZ_sign(gcd) != ZZ_sign(self._denominator): ZZ_negate(t1, gcd) gcd = t1 - ZZX_div_ZZ(t2, self.__numerator, gcd) + ZZX_div_ZZ(t2, self._numerator, gcd) ZZ_div(t1, self._denominator, gcd) - self.__numerator = t2 + self._numerator = t2 self._denominator = t1 cpdef _add_(self, right): @@ -2515,9 +2515,9 @@ cdef class NumberFieldElement(NumberFieldElement_base): ZZ_mul(x._denominator, q1, q2) ZZ_mul(x._denominator, x._denominator, g) cdef ZZX_c t1, t2 - ZZX_mul_ZZ(t1, self.__numerator, q2) - ZZX_mul_ZZ(t2, _right.__numerator, q1) - ZZX_add(x.__numerator, t1, t2) + ZZX_mul_ZZ(t1, self._numerator, q2) + ZZX_mul_ZZ(t2, _right._numerator, q1) + ZZX_add(x._numerator, t1, t2) x._reduce_c_() return x @@ -2540,9 +2540,9 @@ cdef class NumberFieldElement(NumberFieldElement_base): ZZ_mul(x._denominator, q1, q2) ZZ_mul(x._denominator, x._denominator, g) cdef ZZX_c t1, t2 - ZZX_mul_ZZ(t1, self.__numerator, q2) - ZZX_mul_ZZ(t2, _right.__numerator, q1) - ZZX_sub(x.__numerator, t1, t2) + ZZX_mul_ZZ(t1, self._numerator, q2) + ZZX_mul_ZZ(t2, _right._numerator, q1) + ZZX_sub(x._numerator, t1, t2) x._reduce_c_() return x @@ -2573,14 +2573,14 @@ cdef class NumberFieldElement(NumberFieldElement_base): # Therefore, we handle the non-monic case entirely separately. ZZ_mul(x._denominator, self._denominator, _right._denominator) if ZZ_IsOne(ZZX_LeadCoeff(self.__fld_numerator.x)): - ZZX_MulMod(x.__numerator, self.__numerator, _right.__numerator, self.__fld_numerator.x) + ZZX_MulMod(x._numerator, self._numerator, _right._numerator, self.__fld_numerator.x) else: - ZZX_mul(x.__numerator, self.__numerator, _right.__numerator) - if ZZX_deg(x.__numerator) >= ZZX_deg(self.__fld_numerator.x): - ZZX_mul_ZZ( x.__numerator, x.__numerator, self.__fld_denominator.x ) + ZZX_mul(x._numerator, self._numerator, _right._numerator) + if ZZX_deg(x._numerator) >= ZZX_deg(self.__fld_numerator.x): + ZZX_mul_ZZ( x._numerator, x._numerator, self.__fld_denominator.x ) ZZX_mul_ZZ( temp, self.__fld_numerator.x, x._denominator ) - ZZ_power(temp1,ZZX_LeadCoeff(temp),ZZX_deg(x.__numerator)-ZZX_deg(self.__fld_numerator.x)+1) - ZZX_PseudoRem(x.__numerator, x.__numerator, temp) + ZZ_power(temp1,ZZX_LeadCoeff(temp),ZZX_deg(x._numerator)-ZZX_deg(self.__fld_numerator.x)+1) + ZZX_PseudoRem(x._numerator, x._numerator, temp) ZZ_mul(x._denominator, x._denominator, self.__fld_denominator.x) ZZ_mul(x._denominator, x._denominator, temp1) sig_off() @@ -2704,7 +2704,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: bool(b + 1) True """ - return not IsZero_ZZX(self.__numerator) + return not IsZero_ZZX(self._numerator) cpdef _neg_(self): r""" @@ -2717,7 +2717,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): """ cdef NumberFieldElement x x = self._new() - ZZX_mul_long(x.__numerator, self.__numerator, -1) + ZZX_mul_long(x._numerator, self._numerator, -1) x._denominator = self._denominator return x @@ -2738,7 +2738,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): """ cdef NumberFieldElement x x = self._new() - x.__numerator = self.__numerator + x._numerator = self._numerator x._denominator = self._denominator x._set_parent(parent) return x @@ -2826,7 +2826,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: L. = K.extension(f) sage: alpha = (a^8 + (zeta22^9 - zeta22^6 + 2*zeta22^4 + 33)*a^7)/(10**2555) #long time """ - if IsZero_ZZX(self.__numerator): + if IsZero_ZZX(self._numerator): raise ZeroDivisionError("number field element division by zero") cdef NumberFieldElement x cdef ZZX_c temp @@ -2835,8 +2835,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): # but may fail if NTL runs out of FFT primes. x = self._new() sig_on() - ZZX_XGCD(x._denominator, x.__numerator, temp, self.__numerator, self.__fld_numerator.x, 1) - ZZX_mul_ZZ(x.__numerator, x.__numerator, self._denominator) + ZZX_XGCD(x._denominator, x._numerator, temp, self._numerator, self.__fld_numerator.x, 1) + ZZX_mul_ZZ(x._numerator, x._numerator, self._denominator) x._reduce_c_() sig_off() except NTLError: @@ -2858,7 +2858,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: (2*I*I)._integer_() -2 """ - if ZZX_deg(self.__numerator) >= 1: + if ZZX_deg(self._numerator) >= 1: raise TypeError("Unable to coerce %s to an integer" % self) return ZZ(self._rational_()) @@ -2877,10 +2877,10 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: (I*I/2)._rational_() -1/2 """ - if ZZX_deg(self.__numerator) >= 1: + if ZZX_deg(self._numerator) >= 1: raise TypeError("Unable to coerce %s to a rational"%self) cdef Integer num = Integer.__new__(Integer) - ZZX_getitem_as_mpz(num.value, &self.__numerator, 0) + ZZX_getitem_as_mpz(num.value, &self._numerator, 0) cdef Integer den = Integer.__new__(Integer) ZZ_to_mpz(den.value, &self._denominator) return num / den @@ -3268,11 +3268,11 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef mpz_t z mpz_init(z) - ZZX_getitem_as_mpz(z, &self.__numerator, 0) + ZZX_getitem_as_mpz(z, &self._numerator, 0) h = mpz_pythonhash(z) - for i from 1 <= i <= ZZX_deg(self.__numerator): - ZZX_getitem_as_mpz(z, &self.__numerator, i) + for i from 1 <= i <= ZZX_deg(self._numerator): + ZZX_getitem_as_mpz(z, &self._numerator, i) # magic number below is floor(2^63 / (2+sqrt(2))) h ^= mpz_pythonhash(z) + ( 2701463124188384701) + (h << 16) + (h >> 2) @@ -3306,11 +3306,11 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef mpz_t den mpz_init(den) ZZ_to_mpz(den, &self._denominator) - cdef int size = ZZX_deg(self.__numerator) + 1 + cdef int size = ZZX_deg(self._numerator) + 1 cdef list coeffs = [None]*size for i in range(size): coeff = Rational.__new__(Rational) - ZZX_getitem_as_mpz(mpq_numref(coeff.value), &self.__numerator, i) + ZZX_getitem_as_mpz(mpq_numref(coeff.value), &self._numerator, i) mpz_set(mpq_denref(coeff.value), den) mpq_canonicalize(coeff.value) coeffs[i] = coeff @@ -3318,10 +3318,10 @@ cdef class NumberFieldElement(NumberFieldElement_base): return coeffs cdef void _ntl_coeff_as_mpz(self, mpz_t z, long i): - if i > ZZX_deg(self.__numerator): + if i > ZZX_deg(self._numerator): mpz_set_ui(z, 0) else: - ZZX_getitem_as_mpz(z, &self.__numerator, i) + ZZX_getitem_as_mpz(z, &self._numerator, i) cdef void _ntl_denom_as_mpz(self, mpz_t z): cdef Integer denom = Integer.__new__(Integer) @@ -3474,7 +3474,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: a.is_one() False """ - return ZZX_IsOne(self.__numerator) == 1 and \ + return ZZX_IsOne(self._numerator) == 1 and \ ZZ_IsOne(self._denominator) == 1 cpdef bint is_rational(self): @@ -3501,7 +3501,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: K(1/2).is_rational() True """ - return ZZX_deg(self.__numerator) <= 0 + return ZZX_deg(self._numerator) <= 0 def is_integer(self): r""" @@ -3527,7 +3527,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: K(1/2).is_integer() False """ - return ZZX_deg(self.__numerator) <= 0 and ZZ_IsOne(self._denominator) == 1 + return ZZX_deg(self._numerator) <= 0 and ZZ_IsOne(self._denominator) == 1 def trace(self, K=None): r""" diff --git a/src/sage/rings/number_field/number_field_element_quadratic.pyx b/src/sage/rings/number_field/number_field_element_quadratic.pyx index 436f888d111..1d7464c3236 100644 --- a/src/sage/rings/number_field/number_field_element_quadratic.pyx +++ b/src/sage/rings/number_field/number_field_element_quadratic.pyx @@ -621,7 +621,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): for i from 0 <= i <= ZZX_deg(elt_num): tmp = ZZX_coeff(elt_num, i) ZZX_SetCoeff(result, i*rel, tmp) - ZZX_rem(x.__numerator, result, _num.x) + ZZX_rem(x._numerator, result, _num.x) (x)._reduce_c_() return x @@ -1642,7 +1642,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): return res ################################################################################# -# We must override everything that makes uses of self.__numerator/_denominator +# We must override everything that makes uses of self._numerator/_denominator ################################################################################# def __hash__(self): From 7b2bd0e8c256f0e9220c68b85826858a8f32477f Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:41:11 +0800 Subject: [PATCH 23/44] rename __temporarily_change_names -> _temporarily_change_names --- src/sage/rings/polynomial/multi_polynomial_libsingular.pyx | 2 +- src/sage/structure/category_object.pyx | 2 +- src/sage/structure/parent_gens.pyx | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx index 015a12d7a35..b37f6dc53ac 100644 --- a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx @@ -1491,7 +1491,7 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): return unpickle_MPolynomialRing_libsingular, \ (self.base_ring(), self.variable_names(), self.term_order()) - def __temporarily_change_names(self, names, latex_names): + def _temporarily_change_names(self, names, latex_names): """ This is used by the variable names context manager. diff --git a/src/sage/structure/category_object.pyx b/src/sage/structure/category_object.pyx index 7f4b9eb6fde..808f1c4c0f6 100644 --- a/src/sage/structure/category_object.pyx +++ b/src/sage/structure/category_object.pyx @@ -489,7 +489,7 @@ cdef class CategoryObject(SageObject): """ return self.variable_names()[0] - def __temporarily_change_names(self, names, latex_names): + def _temporarily_change_names(self, names, latex_names): """ This is used by the variable names context manager. diff --git a/src/sage/structure/parent_gens.pyx b/src/sage/structure/parent_gens.pyx index 43540c75254..f8fea1d259a 100644 --- a/src/sage/structure/parent_gens.pyx +++ b/src/sage/structure/parent_gens.pyx @@ -366,7 +366,7 @@ cdef class localvars: self._latex_names = latex_names def __enter__(self): - self._orig = self._obj.__temporarily_change_names(self._names, self._latex_names) + self._orig = self._obj._temporarily_change_names(self._names, self._latex_names) def __exit__(self, type, value, traceback): - self._obj.__temporarily_change_names(self._orig[0], self._orig[1]) + self._obj._temporarily_change_names(self._orig[0], self._orig[1]) From 34e01aa7c415630fd22143d0c82a10108f076da1 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:41:30 +0800 Subject: [PATCH 24/44] rename __term_order -> _term_order --- src/sage/rings/polynomial/multi_polynomial_ring_base.pxd | 2 +- src/sage/rings/polynomial/multi_polynomial_ring_base.pyx | 8 ++++---- src/sage/rings/polynomial/plural.pxd | 2 +- src/sage/rings/polynomial/plural.pyx | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/sage/rings/polynomial/multi_polynomial_ring_base.pxd b/src/sage/rings/polynomial/multi_polynomial_ring_base.pxd index e54dd1e9ce6..eb6f8b70917 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ring_base.pxd +++ b/src/sage/rings/polynomial/multi_polynomial_ring_base.pxd @@ -3,7 +3,7 @@ from sage.structure.parent cimport Parent cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): cdef object _ngens - cdef object __term_order + cdef object _term_order cdef public object _has_singular cdef public object _magma_gens cdef public dict _magma_cache diff --git a/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx b/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx index bab3b08d522..fbf4b17a4ec 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx @@ -86,7 +86,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): "have more than 0 variables.") order = TermOrder(order, n) self._ngens = n - self.__term_order = order + self._term_order = order self._has_singular = False # cannot convert to Singular by default self._magma_cache = {} # Ring.__init__ already does assign the names. @@ -642,10 +642,10 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): lx = (lft.base_ring(), lft._ngens, lft.variable_names(), - lft.__term_order) + lft._term_order) rx = (other.base_ring(), other._ngens, other.variable_names(), - other.__term_order) + other._term_order) return richcmp(lx, rx, op) def _repr_(self): @@ -846,7 +846,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): return False def term_order(self): - return self.__term_order + return self._term_order def characteristic(self): """ diff --git a/src/sage/rings/polynomial/plural.pxd b/src/sage/rings/polynomial/plural.pxd index 5d05e4d0e25..d3a46f6aa0d 100644 --- a/src/sage/rings/polynomial/plural.pxd +++ b/src/sage/rings/polynomial/plural.pxd @@ -16,7 +16,7 @@ cdef class NCPolynomialRing_plural(Ring): cdef object _ngens cdef object _c cdef object _d - cdef object __term_order + cdef object _term_order cdef public object _has_singular cdef public object _magma_gens, _magma_cache diff --git a/src/sage/rings/polynomial/plural.pyx b/src/sage/rings/polynomial/plural.pyx index fc55b9a8886..bdeb84eb792 100644 --- a/src/sage/rings/polynomial/plural.pyx +++ b/src/sage/rings/polynomial/plural.pyx @@ -337,7 +337,7 @@ cdef class NCPolynomialRing_plural(Ring): self._ring.ShortOut = 0 self._ngens = n - self.__term_order = order + self._term_order = order Ring.__init__(self, base_ring, names, category=category) self._populate_coercion_lists_() @@ -673,7 +673,7 @@ cdef class NCPolynomialRing_plural(Ring): sage: P.term_order() Degree reverse lexicographic term order """ - return self.__term_order + return self._term_order def is_commutative(self): """ @@ -2891,7 +2891,7 @@ cpdef MPolynomialRing_libsingular new_CRing(RingWrap rw, base_ring): self._ring.ShortOut = 0 self._ngens = rw.ngens() - self.__term_order = TermOrder(rw.ordering_string(), force=True) + self._term_order = TermOrder(rw.ordering_string(), force=True) ParentWithGens.__init__(self, base_ring, tuple(rw.var_names()), normalize=False) @@ -2963,7 +2963,7 @@ cpdef NCPolynomialRing_plural new_NRing(RingWrap rw, base_ring): self._ring.ShortOut = 0 self._ngens = rw.ngens() - self.__term_order = TermOrder(rw.ordering_string(), force=True) + self._term_order = TermOrder(rw.ordering_string(), force=True) ParentWithGens.__init__(self, base_ring, rw.var_names()) # self._populate_coercion_lists_() # ??? From 4b593fe2ad8d65ebd8e5ef4612cb019eee97d5d0 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:42:08 +0800 Subject: [PATCH 25/44] rename __custom_name -> _custom_name --- .../letterplace/free_algebra_letterplace.pxd | 2 +- .../categories/hopf_algebras_with_basis.py | 2 +- src/sage/categories/modules_with_basis.py | 4 +-- src/sage/combinat/cluster_complex.py | 6 ++-- src/sage/combinat/subword_complex.py | 2 +- .../groups/perm_gps/permgroup_element.pxd | 2 +- src/sage/interfaces/interface.py | 2 +- src/sage/interfaces/singular.py | 2 +- src/sage/libs/gap/element.pyx | 2 +- src/sage/matroids/basis_matroid.pyx | 6 ++-- .../matroids/circuit_closures_matroid.pyx | 10 +++---- src/sage/matroids/dual_matroid.py | 10 +++---- src/sage/matroids/graphic_matroid.py | 10 +++---- src/sage/matroids/linear_matroid.pyx | 30 +++++++++---------- src/sage/matroids/matroid.pxd | 1 - src/sage/matroids/minor_matroid.py | 10 +++---- src/sage/matroids/rank_matroid.py | 8 ++--- src/sage/quivers/representation.py | 4 +-- .../drinfeld_modules/drinfeld_module.py | 4 +-- src/sage/sets/set_from_iterator.py | 2 +- src/sage/structure/sage_object.pyx | 12 ++++---- src/sage/topology/simplicial_set.py | 16 +++++----- .../topology/simplicial_set_constructions.py | 2 +- 23 files changed, 74 insertions(+), 75 deletions(-) diff --git a/src/sage/algebras/letterplace/free_algebra_letterplace.pxd b/src/sage/algebras/letterplace/free_algebra_letterplace.pxd index 5623a1bb6d4..9bce00e2755 100644 --- a/src/sage/algebras/letterplace/free_algebra_letterplace.pxd +++ b/src/sage/algebras/letterplace/free_algebra_letterplace.pxd @@ -29,7 +29,7 @@ cdef class FreeAlgebra_letterplace(Algebra): cdef int _ngens cdef int _nb_slackvars cdef object __monoid - cdef public object __custom_name + cdef public object _custom_name cdef str exponents_to_string(self, E) cdef str exponents_to_latex(self, E) cdef tuple _degrees diff --git a/src/sage/categories/hopf_algebras_with_basis.py b/src/sage/categories/hopf_algebras_with_basis.py index ea401896ca0..140f37b42e1 100644 --- a/src/sage/categories/hopf_algebras_with_basis.py +++ b/src/sage/categories/hopf_algebras_with_basis.py @@ -36,7 +36,7 @@ class HopfAlgebrasWithBasis(CategoryWithAxiom_over_base_ring): sage: A = C.example(); A # optional - sage.groups An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Rational Field - sage: A.__custom_name = "A" # optional - sage.groups + sage: A._custom_name = "A" # optional - sage.groups sage: A.category() # optional - sage.groups Category of finite dimensional hopf algebras with basis over Rational Field diff --git a/src/sage/categories/modules_with_basis.py b/src/sage/categories/modules_with_basis.py index 85a0d50239a..ded760874ea 100644 --- a/src/sage/categories/modules_with_basis.py +++ b/src/sage/categories/modules_with_basis.py @@ -66,8 +66,8 @@ class ModulesWithBasis(CategoryWithAxiom_over_base_ring): Let `X` and `Y` be two modules with basis. We can build `Hom(X,Y)`:: - sage: X = CombinatorialFreeModule(QQ, [1,2]); X.__custom_name = "X" # optional - sage.modules - sage: Y = CombinatorialFreeModule(QQ, [3,4]); Y.__custom_name = "Y" # optional - sage.modules + sage: X = CombinatorialFreeModule(QQ, [1,2]); X._custom_name = "X" # optional - sage.modules + sage: Y = CombinatorialFreeModule(QQ, [3,4]); Y._custom_name = "Y" # optional - sage.modules sage: H = Hom(X, Y); H # optional - sage.modules Set of Morphisms from X to Y in Category of finite dimensional vector spaces with basis over Rational Field diff --git a/src/sage/combinat/cluster_complex.py b/src/sage/combinat/cluster_complex.py index edc4f235aeb..fccf3877480 100644 --- a/src/sage/combinat/cluster_complex.py +++ b/src/sage/combinat/cluster_complex.py @@ -223,9 +223,9 @@ def __init__(self, W, k, coxeter_element, algorithm): self._w0 = w self._k = k if k == 1: - self.__custom_name = 'Cluster complex' + self._custom_name = 'Cluster complex' else: - self.__custom_name = 'Multi-cluster complex' + self._custom_name = 'Multi-cluster complex' self.set_immutable() @@ -271,7 +271,7 @@ def _repr_(self): sage: ClusterComplex(['A', 2])._repr_() "Cluster complex of type ['A', 2] with 5 vertices and 5 facets" """ - name = self.__custom_name + name = self._custom_name name += (' of type %s with %s vertices and %s facets' % (self.cartan_type(), len(self.vertices()), len(self._facets))) diff --git a/src/sage/combinat/subword_complex.py b/src/sage/combinat/subword_complex.py index b7489bdf754..c4cf1dac47c 100644 --- a/src/sage/combinat/subword_complex.py +++ b/src/sage/combinat/subword_complex.py @@ -1131,7 +1131,7 @@ def __init__(self, Q, w, algorithm="inductive"): SimplicialComplex.__init__(self, maximal_faces=Fs, maximality_check=False, category=cat) - self.__custom_name = 'Subword complex' + self._custom_name = 'Subword complex' self._W = W try: T = W.coxeter_matrix().coxeter_type() diff --git a/src/sage/groups/perm_gps/permgroup_element.pxd b/src/sage/groups/perm_gps/permgroup_element.pxd index a2ac8f20eaa..b1ec2b09a19 100644 --- a/src/sage/groups/perm_gps/permgroup_element.pxd +++ b/src/sage/groups/perm_gps/permgroup_element.pxd @@ -22,7 +22,7 @@ cdef class PermutationGroupElement(MultiplicativeGroupElement): cpdef PermutationGroupElement _generate_new_GAP(self, old) cpdef _gap_list(self) cpdef domain(self) - cdef public __custom_name + cdef public _custom_name cpdef list _act_on_list_on_position(self, list x) cpdef ClonableIntArray _act_on_array_on_position(self, ClonableIntArray x) cpdef ETuple _act_on_etuple_on_position(self, ETuple x) diff --git a/src/sage/interfaces/interface.py b/src/sage/interfaces/interface.py index f8237d3ad94..9679c34ab5b 100644 --- a/src/sage/interfaces/interface.py +++ b/src/sage/interfaces/interface.py @@ -1171,7 +1171,7 @@ def __repr__(self): s = self._repr_() if self._name in s: try: - s = s.replace(self._name, getattr(self, '__custom_name')) + s = s.replace(self._name, getattr(self, '_custom_name')) except AttributeError: pass if cr: diff --git a/src/sage/interfaces/singular.py b/src/sage/interfaces/singular.py index b15cc1c602c..c226d954c1d 100644 --- a/src/sage/interfaces/singular.py +++ b/src/sage/interfaces/singular.py @@ -1417,7 +1417,7 @@ def _repr_(self): """ s = super(SingularElement, self)._repr_() if self._name in s: - if (not hasattr(self, "__custom_name")) and self.type() == 'matrix': + if (not hasattr(self, "_custom_name")) and self.type() == 'matrix': s = self.parent().eval('pmat(%s,20)'%(self.name())) return s diff --git a/src/sage/libs/gap/element.pyx b/src/sage/libs/gap/element.pyx index 1dc53c81f67..964cd18e646 100644 --- a/src/sage/libs/gap/element.pyx +++ b/src/sage/libs/gap/element.pyx @@ -720,7 +720,7 @@ cdef class GapElement(RingElement): ... AttributeError: 'some_name' does not define a GAP function """ - if name in ('__dict__', '_getAttributeNames', '__custom_name', 'keys'): + if name in ('__dict__', '_getAttributeNames', '_custom_name', 'keys'): raise AttributeError('Python special name, not a GAP function.') try: proxy = make_GapElement_MethodProxy\ diff --git a/src/sage/matroids/basis_matroid.pyx b/src/sage/matroids/basis_matroid.pyx index da6268be982..3e9b98ea1ae 100644 --- a/src/sage/matroids/basis_matroid.pyx +++ b/src/sage/matroids/basis_matroid.pyx @@ -1177,7 +1177,7 @@ cdef class BasisMatroid(BasisExchangeMatroid): """ N = BasisMatroid(M=self) - N.rename(getattr(self, '__custom_name')) + N.rename(getattr(self, '_custom_name')) return N def __deepcopy__(self, memo=None): @@ -1201,7 +1201,7 @@ cdef class BasisMatroid(BasisExchangeMatroid): if memo is None: memo = {} N = BasisMatroid(M=self) - N.rename(getattr(self, '__custom_name')) + N.rename(getattr(self, '_custom_name')) return N def __reduce__(self): @@ -1230,7 +1230,7 @@ cdef class BasisMatroid(BasisExchangeMatroid): """ import sage.matroids.unpickling BB = bitset_pickle(self._bb) - data = (self._E, self._matroid_rank, getattr(self, '__custom_name'), BB) + data = (self._E, self._matroid_rank, getattr(self, '_custom_name'), BB) version = 0 return sage.matroids.unpickling.unpickle_basis_matroid, (version, data) diff --git a/src/sage/matroids/circuit_closures_matroid.pyx b/src/sage/matroids/circuit_closures_matroid.pyx index 402822b2dc6..72a95068504 100644 --- a/src/sage/matroids/circuit_closures_matroid.pyx +++ b/src/sage/matroids/circuit_closures_matroid.pyx @@ -513,8 +513,8 @@ cdef class CircuitClosuresMatroid(Matroid): N._groundset = self._groundset N._circuit_closures = self._circuit_closures N._matroid_rank = self._matroid_rank - if getattr(self, '__custom_name') is not None: # because of name wrangling, this is not caught by the default copy - N.rename(getattr(self, '__custom_name')) + if getattr(self, '_custom_name') is not None: # because of name wrangling, this is not caught by the default copy + N.rename(getattr(self, '_custom_name')) return N def __deepcopy__(self, memo=None): @@ -539,8 +539,8 @@ cdef class CircuitClosuresMatroid(Matroid): from copy import deepcopy # Since matroids are immutable, N cannot reference itself in correct code, so no need to worry about the recursion. N = CircuitClosuresMatroid(groundset=deepcopy(self._groundset, memo), circuit_closures=deepcopy(self._circuit_closures, memo)) - if getattr(self, '__custom_name') is not None: # because of name wrangling, this is not caught by the default deepcopy - N.rename(deepcopy(getattr(self, '__custom_name'), memo)) + if getattr(self, '_custom_name') is not None: # because of name wrangling, this is not caught by the default deepcopy + N.rename(deepcopy(getattr(self, '_custom_name'), memo)) return N def __reduce__(self): @@ -570,7 +570,7 @@ cdef class CircuitClosuresMatroid(Matroid): 4: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}}} """ import sage.matroids.unpickling - data = (self._groundset, self._circuit_closures, getattr(self, '__custom_name')) + data = (self._groundset, self._circuit_closures, getattr(self, '_custom_name')) version = 0 return sage.matroids.unpickling.unpickle_circuit_closures_matroid, (version, data) diff --git a/src/sage/matroids/dual_matroid.py b/src/sage/matroids/dual_matroid.py index 804e43f035b..445a78bc43d 100644 --- a/src/sage/matroids/dual_matroid.py +++ b/src/sage/matroids/dual_matroid.py @@ -519,9 +519,9 @@ def __copy__(self): """ N = DualMatroid(self._matroid) - if getattr(self, '__custom_name') is not None: + if getattr(self, '_custom_name') is not None: # because of name wrangling, this is not caught by the default copy - N.rename(getattr(self, '__custom_name')) + N.rename(getattr(self, '_custom_name')) return N def __deepcopy__(self, memo={}): @@ -543,10 +543,10 @@ def __deepcopy__(self, memo={}): """ from copy import deepcopy N = DualMatroid(deepcopy(self._matroid, memo)) - if getattr(self, '__custom_name') is not None: + if getattr(self, '_custom_name') is not None: # because of name wrangling, this is not caught by the # default deepcopy - N.rename(deepcopy(getattr(self, '__custom_name'), memo)) + N.rename(deepcopy(getattr(self, '_custom_name'), memo)) return N def __reduce__(self): @@ -575,6 +575,6 @@ def __reduce__(self): 4: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}}}' """ import sage.matroids.unpickling - data = (self._matroid, getattr(self, '__custom_name')) + data = (self._matroid, getattr(self, '_custom_name')) version = 0 return sage.matroids.unpickling.unpickle_dual_matroid, (version, data) diff --git a/src/sage/matroids/graphic_matroid.py b/src/sage/matroids/graphic_matroid.py index 5216ef11517..106cd68bf71 100644 --- a/src/sage/matroids/graphic_matroid.py +++ b/src/sage/matroids/graphic_matroid.py @@ -481,8 +481,8 @@ def __copy__(self): False """ N = GraphicMatroid(self._G) - if getattr(self, '__custom_name') is not None: # because of name wrangling, this is not caught by the default copy - N.rename(getattr(self, '__custom_name')) + if getattr(self, '_custom_name') is not None: # because of name wrangling, this is not caught by the default copy + N.rename(getattr(self, '_custom_name')) return N def __deepcopy__(self, memo={}): @@ -502,8 +502,8 @@ def __deepcopy__(self, memo={}): """ # The only real difference between this and __copy__() is the memo N = GraphicMatroid(deepcopy(self._G, memo)) - if getattr(self, '__custom_name') is not None: # because of name wrangling, this is not caught by the default deepcopy - N.rename(deepcopy(getattr(self, '__custom_name'), memo)) + if getattr(self, '_custom_name') is not None: # because of name wrangling, this is not caught by the default deepcopy + N.rename(deepcopy(getattr(self, '_custom_name'), memo)) return N def __reduce__(self): @@ -519,7 +519,7 @@ def __reduce__(self): Graphic matroid of rank 9 on 15 elements """ from .unpickling import unpickle_graphic_matroid - data = (self._G, getattr(self, '__custom_name')) + data = (self._G, getattr(self, '_custom_name')) version = 0 return unpickle_graphic_matroid, (version, data) diff --git a/src/sage/matroids/linear_matroid.pyx b/src/sage/matroids/linear_matroid.pyx index dd29eb157a6..691d473a4cb 100644 --- a/src/sage/matroids/linear_matroid.pyx +++ b/src/sage/matroids/linear_matroid.pyx @@ -2909,7 +2909,7 @@ cdef class LinearMatroid(BasisExchangeMatroid): else: rows, cols = self._current_rows_cols() N = LinearMatroid(groundset=rows + cols, reduced_matrix=self._A) - N.rename(getattr(self, '__custom_name')) + N.rename(getattr(self, '_custom_name')) return N def __deepcopy__(self, memo): @@ -2930,7 +2930,7 @@ cdef class LinearMatroid(BasisExchangeMatroid): else: rows, cols = self._current_rows_cols() N = LinearMatroid(groundset=deepcopy(rows + cols, memo), reduced_matrix=deepcopy(self._A, memo)) - N.rename(deepcopy(getattr(self, '__custom_name'), memo)) + N.rename(deepcopy(getattr(self, '_custom_name'), memo)) return N def __reduce__(self): @@ -2979,7 +2979,7 @@ cdef class LinearMatroid(BasisExchangeMatroid): rows, cols = self._current_rows_cols() gs = rows + cols reduced = True - data = (A, gs, reduced, getattr(self, '__custom_name')) + data = (A, gs, reduced, getattr(self, '_custom_name')) return sage.matroids.unpickling.unpickle_linear_matroid, (version, data) # Binary matroid @@ -3964,7 +3964,7 @@ cdef class BinaryMatroid(LinearMatroid): for e in self.basis(): basis[self._prow[self._idx[e]]] = e N = BinaryMatroid(groundset=self._E, matrix=self._A, basis=basis) - N.rename(getattr(self, '__custom_name')) + N.rename(getattr(self, '_custom_name')) return N def __deepcopy__(self, memo): @@ -3989,7 +3989,7 @@ cdef class BinaryMatroid(LinearMatroid): for e in self.basis(): basis[self._prow[self._idx[e]]] = e N = BinaryMatroid(groundset=deepcopy(self._E, memo), matrix=deepcopy(self._A, memo), basis=deepcopy(basis, memo)) - N.rename(deepcopy(getattr(self, '__custom_name'), memo)) + N.rename(deepcopy(getattr(self, '_custom_name'), memo)) return N def __reduce__(self): @@ -4047,7 +4047,7 @@ cdef class BinaryMatroid(LinearMatroid): A = self._A # current basis ordered so matrix cols form identity matrix: basis = self._current_rows_cols()[0] - data = (A, gs, basis, getattr(self, '__custom_name')) + data = (A, gs, basis, getattr(self, '_custom_name')) return sage.matroids.unpickling.unpickle_binary_matroid, (version, data) cdef class TernaryMatroid(LinearMatroid): @@ -4858,7 +4858,7 @@ cdef class TernaryMatroid(LinearMatroid): for e in self.basis(): basis[self._prow[self._idx[e]]] = e N = TernaryMatroid(groundset=self._E, matrix=self._A, basis=basis) - N.rename(getattr(self, '__custom_name')) + N.rename(getattr(self, '_custom_name')) return N def __deepcopy__(self, memo): @@ -4883,7 +4883,7 @@ cdef class TernaryMatroid(LinearMatroid): for e in self.basis(): basis[self._prow[self._idx[e]]] = e N = TernaryMatroid(groundset=deepcopy(self._E, memo), matrix=deepcopy(self._A, memo), basis=deepcopy(basis, memo)) - N.rename(deepcopy(getattr(self, '__custom_name'), memo)) + N.rename(deepcopy(getattr(self, '_custom_name'), memo)) return N def __reduce__(self): @@ -4945,7 +4945,7 @@ cdef class TernaryMatroid(LinearMatroid): A = self._A # current basis ordered so matrix cols form identity matrix: basis = self._current_rows_cols()[0] - data = (A, gs, basis, getattr(self, '__custom_name')) + data = (A, gs, basis, getattr(self, '_custom_name')) return sage.matroids.unpickling.unpickle_ternary_matroid, (version, data) # Quaternary Matroids @@ -5589,7 +5589,7 @@ cdef class QuaternaryMatroid(LinearMatroid): for e in self.basis(): basis[self._prow[self._idx[e]]] = e N = QuaternaryMatroid(groundset=self._E, matrix=self._A, basis=basis) - N.rename(getattr(self, '__custom_name')) + N.rename(getattr(self, '_custom_name')) return N def __deepcopy__(self, memo): @@ -5614,7 +5614,7 @@ cdef class QuaternaryMatroid(LinearMatroid): for e in self.basis(): basis[self._prow[self._idx[e]]] = e N = QuaternaryMatroid(groundset=deepcopy(self._E, memo), matrix=deepcopy(self._A, memo), basis=deepcopy(basis, memo)) - N.rename(deepcopy(getattr(self, '__custom_name'), memo)) + N.rename(deepcopy(getattr(self, '_custom_name'), memo)) return N def __reduce__(self): @@ -5672,7 +5672,7 @@ cdef class QuaternaryMatroid(LinearMatroid): A = self._A # current basis ordered so matrix cols form identity matrix: basis = self._current_rows_cols()[0] - data = (A, gs, basis, getattr(self, '__custom_name')) + data = (A, gs, basis, getattr(self, '_custom_name')) return sage.matroids.unpickling.unpickle_quaternary_matroid, (version, data) # Regular Matroids @@ -6524,7 +6524,7 @@ cdef class RegularMatroid(LinearMatroid): else: rows, cols = self._current_rows_cols() N = RegularMatroid(groundset=rows + cols, reduced_matrix=self._A) - N.rename(getattr(self, '__custom_name')) + N.rename(getattr(self, '_custom_name')) return N def __deepcopy__(self, memo): @@ -6544,7 +6544,7 @@ cdef class RegularMatroid(LinearMatroid): else: rows, cols = self._current_rows_cols() N = RegularMatroid(groundset=deepcopy(rows + cols, memo), reduced_matrix=deepcopy(self._A, memo)) - N.rename(deepcopy(getattr(self, '__custom_name'), memo)) + N.rename(deepcopy(getattr(self, '_custom_name'), memo)) return N def __reduce__(self): @@ -6593,5 +6593,5 @@ cdef class RegularMatroid(LinearMatroid): rows, cols = self._current_rows_cols() gs = rows + cols reduced = True - data = (A, gs, reduced, getattr(self, '__custom_name')) + data = (A, gs, reduced, getattr(self, '_custom_name')) return sage.matroids.unpickling.unpickle_regular_matroid, (version, data) diff --git a/src/sage/matroids/matroid.pxd b/src/sage/matroids/matroid.pxd index fe6c07e3b71..54af72317ba 100644 --- a/src/sage/matroids/matroid.pxd +++ b/src/sage/matroids/matroid.pxd @@ -1,7 +1,6 @@ from sage.structure.sage_object cimport SageObject cdef class Matroid(SageObject): - cdef public __custom_name cdef public _custom_name cdef public _cached_info cdef int _stored_full_rank diff --git a/src/sage/matroids/minor_matroid.py b/src/sage/matroids/minor_matroid.py index c0e756917f5..24dc60d11d0 100644 --- a/src/sage/matroids/minor_matroid.py +++ b/src/sage/matroids/minor_matroid.py @@ -486,8 +486,8 @@ def __copy__(self): True """ N = MinorMatroid(self._matroid, self._contractions, self._deletions) - if getattr(self, '__custom_name') is not None: # because of name wrangling, this is not caught by the default copy - N.rename(getattr(self, '__custom_name')) + if getattr(self, '_custom_name') is not None: # because of name wrangling, this is not caught by the default copy + N.rename(getattr(self, '_custom_name')) return N def __deepcopy__(self, memo={}): @@ -512,8 +512,8 @@ def __deepcopy__(self, memo={}): from copy import deepcopy # Since matroids are immutable, N cannot reference itself in correct code, so no need to worry about the recursion. N = MinorMatroid(deepcopy(self._matroid, memo), deepcopy(self._contractions, memo), deepcopy(self._deletions, memo)) - if getattr(self, '__custom_name') is not None: # because of name wrangling, this is not caught by the default deepcopy - N.rename(deepcopy(getattr(self, '__custom_name'), memo)) + if getattr(self, '_custom_name') is not None: # because of name wrangling, this is not caught by the default deepcopy + N.rename(deepcopy(getattr(self, '_custom_name'), memo)) return N def __reduce__(self): @@ -534,6 +534,6 @@ def __reduce__(self): 4: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}}} """ import sage.matroids.unpickling - data = (self._matroid, self._contractions, self._deletions, getattr(self, '__custom_name')) + data = (self._matroid, self._contractions, self._deletions, getattr(self, '_custom_name')) version = 0 return sage.matroids.unpickling.unpickle_minor_matroid, (version, data) diff --git a/src/sage/matroids/rank_matroid.py b/src/sage/matroids/rank_matroid.py index 4633ff0a792..dd443eb6390 100644 --- a/src/sage/matroids/rank_matroid.py +++ b/src/sage/matroids/rank_matroid.py @@ -267,9 +267,9 @@ def __copy__(self): N = RankMatroid(groundset=[], rank_function=None) N._groundset = self._groundset N._rank_function = self._rank_function - if getattr(self, '__custom_name') is not None: + if getattr(self, '_custom_name') is not None: # because of name wrangling, this is not caught by the default copy - N.rename(getattr(self, '__custom_name')) + N.rename(getattr(self, '_custom_name')) return N def __deepcopy__(self, memo={}): @@ -293,8 +293,8 @@ def __deepcopy__(self, memo={}): from copy import deepcopy # Since matroids are immutable, N cannot reference itself in correct code, so no need to worry about the recursion. N = RankMatroid(groundset=deepcopy(self._groundset), rank_function=deepcopy(self._rank_function)) - if getattr(self, '__custom_name') is not None: # because of name wrangling, this is not caught by the default deepcopy - N.rename(deepcopy(getattr(self, '__custom_name'), memo)) + if getattr(self, '_custom_name') is not None: # because of name wrangling, this is not caught by the default deepcopy + N.rename(deepcopy(getattr(self, '_custom_name'), memo)) return N def __reduce__(self): diff --git a/src/sage/quivers/representation.py b/src/sage/quivers/representation.py index 9c11eb8ad0e..47d113778a6 100644 --- a/src/sage/quivers/representation.py +++ b/src/sage/quivers/representation.py @@ -1297,8 +1297,8 @@ def copy(self): sage: v.get_element(1) (1, 0) """ - if hasattr(self, '__custom_name'): - name = self.__custom_name + if hasattr(self, '_custom_name'): + name = self._custom_name else: name = None return self.parent()(self._elems.copy(), name) diff --git a/src/sage/rings/function_field/drinfeld_modules/drinfeld_module.py b/src/sage/rings/function_field/drinfeld_modules/drinfeld_module.py index ed9994f25ac..9af415f2c38 100644 --- a/src/sage/rings/function_field/drinfeld_modules/drinfeld_module.py +++ b/src/sage/rings/function_field/drinfeld_modules/drinfeld_module.py @@ -804,8 +804,8 @@ def _latex_(self): \phi sage: phi.reset_name() """ - if hasattr(self, '__custom_name'): - return latex_variable_name(getattr(self, '__custom_name')) + if hasattr(self, '_custom_name'): + return latex_variable_name(getattr(self, '_custom_name')) else: return f'\\phi: {latex(self._function_ring.gen())} \\mapsto ' \ f'{latex(self._gen)}' diff --git a/src/sage/sets/set_from_iterator.py b/src/sage/sets/set_from_iterator.py index c47bb76920b..d0e3de48f5c 100644 --- a/src/sage/sets/set_from_iterator.py +++ b/src/sage/sets/set_from_iterator.py @@ -217,7 +217,7 @@ def __reduce__(self): (self._func, # func getattr(self, '_args', None), # args getattr(self, '_kwds', None), # kwds - getattr(self, '__custom_name', None), # name + getattr(self, '_custom_name', None), # name self.category(), # category hasattr(self, '_cache')) # cache ) diff --git a/src/sage/structure/sage_object.pyx b/src/sage/structure/sage_object.pyx index dd98ea5988d..41c0b9a14cb 100644 --- a/src/sage/structure/sage_object.pyx +++ b/src/sage/structure/sage_object.pyx @@ -110,15 +110,15 @@ cdef class SageObject: a lot of memory. To support them for a specific class, add a - ``cdef public __custom_name`` attribute. + ``cdef public _custom_name`` attribute. """ if x is None: - #if hasattr(self, '__custom_name'): + #if hasattr(self, '_custom_name'): # that's tested in reset_name anyway... self.reset_name() else: try: - self.__custom_name = str(x) + self._custom_name = str(x) except AttributeError: raise NotImplementedError("object does not support renaming: %s" % self) @@ -138,8 +138,8 @@ cdef class SageObject: sage: P Univariate Polynomial Ring in x over Rational Field """ - if hasattr(self, '__custom_name'): - del self.__custom_name + if hasattr(self, '_custom_name'): + del self._custom_name def __repr__(self): """ @@ -181,7 +181,7 @@ cdef class SageObject: """ try: - name = self.__custom_name + name = self._custom_name if name is not None: return name except AttributeError: diff --git a/src/sage/topology/simplicial_set.py b/src/sage/topology/simplicial_set.py index 813e2d4defa..8c29b13ffe6 100644 --- a/src/sage/topology/simplicial_set.py +++ b/src/sage/topology/simplicial_set.py @@ -565,13 +565,13 @@ def __lt__(self, other): return True if self.degeneracies() and other.degeneracies() and self.degeneracies() != other.degeneracies(): return self.degeneracies() < other.degeneracies() - if hasattr(self.nondegenerate(), '__custom_name'): - if hasattr(other.nondegenerate(), '__custom_name'): + if hasattr(self.nondegenerate(), '_custom_name'): + if hasattr(other.nondegenerate(), '_custom_name'): return str(self) < str(other) return True - if (hasattr(other, '__custom_name') - or hasattr(other.nondegenerate(), '__custom_name')): + if (hasattr(other, '_custom_name') + or hasattr(other.nondegenerate(), '_custom_name')): return False return id(self) < id(other) @@ -788,7 +788,7 @@ def __copy__(self): # dimension, the degeneracies, and the name (with a prime # added). sigma = AbstractSimplex(self._dim, degeneracies=self.degeneracies()) - if hasattr(self, '__custom_name'): + if hasattr(self, '_custom_name'): sigma.rename(str(self) + "'") return sigma @@ -833,7 +833,7 @@ def __deepcopy__(self, memo): return memo[underlying].apply_degeneracies(*degens) except KeyError: sigma = AbstractSimplex(underlying._dim) - if hasattr(underlying, '__custom_name'): + if hasattr(underlying, '_custom_name'): sigma.rename(str(self) + "'") memo[underlying] = sigma return sigma.apply_degeneracies(*degens) @@ -890,11 +890,11 @@ def _latex_(self): """ if self._latex_name is not None: return self._latex_name - if hasattr(self, '__custom_name'): + if hasattr(self, '_custom_name'): return str(self) if self.nondegenerate()._latex_name is not None: simplex = self.nondegenerate()._latex_name - elif hasattr(self.nondegenerate(), '__custom_name'): + elif hasattr(self.nondegenerate(), '_custom_name'): simplex = str(self.nondegenerate()) else: simplex = "\\Delta^{{{}}}".format(self._dim) diff --git a/src/sage/topology/simplicial_set_constructions.py b/src/sage/topology/simplicial_set_constructions.py index b2b6bbbae7c..f2bd8881944 100644 --- a/src/sage/topology/simplicial_set_constructions.py +++ b/src/sage/topology/simplicial_set_constructions.py @@ -176,7 +176,7 @@ def __init__(self, data, ambient=None): else: SimplicialSet_finite.__init__(self, data) if self == ambient: - if hasattr(ambient, '__custom_name'): + if hasattr(ambient, '_custom_name'): self.rename(str(ambient)) self._latex_name = latex(ambient) # When constructing the inclusion map, we do not need to check From 0b8aace0fe0fa9463569ce33bc2b9506b5f9750a Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:42:36 +0800 Subject: [PATCH 26/44] rename __crt -> _crt --- src/sage/rings/finite_rings/integer_mod.pyx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/sage/rings/finite_rings/integer_mod.pyx b/src/sage/rings/finite_rings/integer_mod.pyx index 3bb48513faa..3eb2b201071 100644 --- a/src/sage/rings/finite_rings/integer_mod.pyx +++ b/src/sage/rings/finite_rings/integer_mod.pyx @@ -1687,14 +1687,14 @@ cdef class IntegerMod_abstract(FiniteRingElement): if other._modulus.int64 == 1: return self new_modulus = self._modulus.int64 * other._modulus.int64 if new_modulus < INTEGER_MOD_INT32_LIMIT: - return self.__crt(other) + return self._crt(other) elif new_modulus < INTEGER_MOD_INT64_LIMIT: if not isinstance(self, IntegerMod_int64): self = IntegerMod_int64(self._parent, self.lift()) if not isinstance(other, IntegerMod_int64): other = IntegerMod_int64(other._parent, other.lift()) - return self.__crt(other) + return self._crt(other) if not isinstance(self, IntegerMod_gmp): if self._modulus.int64 == 1: return other @@ -1704,7 +1704,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): if other._modulus.int64 == 1: return self other = IntegerMod_gmp(other._parent, other.lift()) - return self.__crt(other) + return self._crt(other) def additive_order(self): r""" @@ -2111,7 +2111,7 @@ cdef class IntegerMod_gmp(IntegerMod_abstract): """ return self.lift().gcd(self.modulus()) == 1 - def __crt(IntegerMod_gmp self, IntegerMod_gmp other): + def _crt(IntegerMod_gmp self, IntegerMod_gmp other): cdef IntegerMod_gmp lift, x cdef sage.rings.integer.Integer modulus, other_modulus @@ -2500,7 +2500,7 @@ cdef class IntegerMod_int(IntegerMod_abstract): """ return gcd_int(self.ivalue, self._modulus.int32) == 1 - def __crt(IntegerMod_int self, IntegerMod_int other): + def _crt(IntegerMod_int self, IntegerMod_int other): """ Use the Chinese Remainder Theorem to find an element of the integers modulo the product of the moduli that reduces to self and @@ -3322,7 +3322,7 @@ cdef class IntegerMod_int64(IntegerMod_abstract): """ return gcd_int64(self.ivalue, self._modulus.int64) == 1 - def __crt(IntegerMod_int64 self, IntegerMod_int64 other): + def _crt(IntegerMod_int64 self, IntegerMod_int64 other): """ Use the Chinese Remainder Theorem to find an element of the integers modulo the product of the moduli that reduces to self and From e71dda4f3e18a3c64399cdef499df4ec1f1434b5 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:43:33 +0800 Subject: [PATCH 27/44] fix use of private __is_gen --- src/sage/rings/power_series_mpoly.pyx | 2 +- src/sage/rings/power_series_poly.pyx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/rings/power_series_mpoly.pyx b/src/sage/rings/power_series_mpoly.pyx index 0c901a3557b..61cfbe25021 100644 --- a/src/sage/rings/power_series_mpoly.pyx +++ b/src/sage/rings/power_series_mpoly.pyx @@ -65,7 +65,7 @@ cdef class PowerSeries_mpoly(PowerSeries): def __reduce__(self): # do *not* delete old versions. - return make_powerseries_mpoly_v0, (self._parent, self.__f, self._prec, self.__is_gen) + return make_powerseries_mpoly_v0, (self._parent, self.__f, self._prec, self._PowerSeries__is_gen) def __call__(self, *args, **kwds): if len(kwds) == 0 and len(args) == 1: diff --git a/src/sage/rings/power_series_poly.pyx b/src/sage/rings/power_series_poly.pyx index 7c93168d4b1..bffb849b646 100644 --- a/src/sage/rings/power_series_poly.pyx +++ b/src/sage/rings/power_series_poly.pyx @@ -97,7 +97,7 @@ cdef class PowerSeries_poly(PowerSeries): sage: f == loads(dumps(f)) # indirect doctest True """ - return self.__class__, (self._parent, self.__f, self._prec, self.__is_gen) + return self.__class__, (self._parent, self.__f, self._prec, self._PowerSeries__is_gen) def polynomial(self): """ From 0469f759d44a6726c6007a40f869d0d438738f3f Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:43:52 +0800 Subject: [PATCH 28/44] fix use of private __subset --- src/sage/matroids/linear_matroid.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/matroids/linear_matroid.pyx b/src/sage/matroids/linear_matroid.pyx index 691d473a4cb..74e3aea0514 100644 --- a/src/sage/matroids/linear_matroid.pyx +++ b/src/sage/matroids/linear_matroid.pyx @@ -605,7 +605,7 @@ cdef class LinearMatroid(BasisExchangeMatroid): self._representation = self._basic_representation(B) A = self._representation else: - B = self.__subset(B) + B = self._Matroid__subset(B) A = self._basic_representation(B) A = A.matrix_from_rows_and_columns(range(A.nrows()), order_idx) if lift_map is None: @@ -622,7 +622,7 @@ cdef class LinearMatroid(BasisExchangeMatroid): if B is None: B = frozenset(self.basis()) else: - B = self.__subset(B) + B = self._Matroid__subset(B) A = self._reduced_representation(B) R, C = self._current_rows_cols() Ri = [] From edbdac0cdf5afba51d7c662e63d67125201e0b3c Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:44:17 +0800 Subject: [PATCH 29/44] fix use of private __relabel --- src/sage/matroids/basis_matroid.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/matroids/basis_matroid.pyx b/src/sage/matroids/basis_matroid.pyx index 3e9b98ea1ae..67978b4e565 100644 --- a/src/sage/matroids/basis_matroid.pyx +++ b/src/sage/matroids/basis_matroid.pyx @@ -557,7 +557,7 @@ cdef class BasisMatroid(BasisExchangeMatroid): """ M = BasisMatroid(M=self) - M.__relabel(l) + M._BasisExchangeMatroid__relabel(l) return M # enumeration From 0877c400644d842a58ecb7f284161cf8f11cdf3a Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:44:46 +0800 Subject: [PATCH 30/44] rename __fld_denominator -> _fld_denominator --- .../rings/number_field/number_field_element.pxd | 2 +- .../rings/number_field/number_field_element.pyx | 14 +++++++------- .../number_field_element_quadratic.pyx | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/sage/rings/number_field/number_field_element.pxd b/src/sage/rings/number_field/number_field_element.pxd index 418e54aba8c..fe77101f6cc 100644 --- a/src/sage/rings/number_field/number_field_element.pxd +++ b/src/sage/rings/number_field/number_field_element.pxd @@ -16,7 +16,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): # Pointers to the defining polynomial (with numerator) for the field. # I keep these as pointers for arithmetic speed. cdef ntl_ZZX __fld_numerator - cdef ntl_ZZ __fld_denominator + cdef ntl_ZZ _fld_denominator cdef object __multiplicative_order cdef object __pari cdef object __matrix diff --git a/src/sage/rings/number_field/number_field_element.pyx b/src/sage/rings/number_field/number_field_element.pyx index cfc86bdac6f..343a2e598e1 100644 --- a/src/sage/rings/number_field/number_field_element.pyx +++ b/src/sage/rings/number_field/number_field_element.pyx @@ -219,7 +219,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef NumberFieldElement x = t.__new__(t) x._parent = self._parent x.__fld_numerator = self.__fld_numerator - x.__fld_denominator = self.__fld_denominator + x._fld_denominator = self._fld_denominator return x cdef number_field(self): @@ -317,7 +317,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): True """ FieldElement.__init__(self, parent) - self.__fld_numerator, self.__fld_denominator = parent.absolute_polynomial_ntl() + self.__fld_numerator, self._fld_denominator = parent.absolute_polynomial_ntl() cdef ZZ_c coeff if isinstance(f, (int, Integer_sage)): @@ -417,7 +417,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef type t = type(self) cdef NumberFieldElement x = t.__new__(t) x._parent = new_parent - x.__fld_numerator, x.__fld_denominator = new_parent.polynomial_ntl() + x.__fld_numerator, x._fld_denominator = new_parent.polynomial_ntl() x._denominator = self._denominator cdef ZZX_c result cdef ZZ_c tmp @@ -2577,11 +2577,11 @@ cdef class NumberFieldElement(NumberFieldElement_base): else: ZZX_mul(x._numerator, self._numerator, _right._numerator) if ZZX_deg(x._numerator) >= ZZX_deg(self.__fld_numerator.x): - ZZX_mul_ZZ( x._numerator, x._numerator, self.__fld_denominator.x ) + ZZX_mul_ZZ( x._numerator, x._numerator, self._fld_denominator.x ) ZZX_mul_ZZ( temp, self.__fld_numerator.x, x._denominator ) ZZ_power(temp1,ZZX_LeadCoeff(temp),ZZX_deg(x._numerator)-ZZX_deg(self.__fld_numerator.x)+1) ZZX_PseudoRem(x._numerator, x._numerator, temp) - ZZ_mul(x._denominator, x._denominator, self.__fld_denominator.x) + ZZ_mul(x._denominator, x._denominator, self._fld_denominator.x) ZZ_mul(x._denominator, x._denominator, temp1) sig_off() x._reduce_c_() @@ -5321,7 +5321,7 @@ cdef class OrderElement_absolute(NumberFieldElement_absolute): x._parent = self._parent x._number_field = self._parent.number_field() x.__fld_numerator = self.__fld_numerator - x.__fld_denominator = self.__fld_denominator + x._fld_denominator = self._fld_denominator return x cdef number_field(self): @@ -5442,7 +5442,7 @@ cdef class OrderElement_relative(NumberFieldElement_relative): x._parent = self._parent x._number_field = self._parent.number_field() x.__fld_numerator = self.__fld_numerator - x.__fld_denominator = self.__fld_denominator + x._fld_denominator = self._fld_denominator return x def __invert__(self): diff --git a/src/sage/rings/number_field/number_field_element_quadratic.pyx b/src/sage/rings/number_field/number_field_element_quadratic.pyx index 1d7464c3236..4c52d90703a 100644 --- a/src/sage/rings/number_field/number_field_element_quadratic.pyx +++ b/src/sage/rings/number_field/number_field_element_quadratic.pyx @@ -610,7 +610,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): mpz_clear(tmp_mpz) x._parent = new_parent - x.__fld_numerator, x.__fld_denominator = new_parent.polynomial_ntl() + x.__fld_numerator, x._fld_denominator = new_parent.polynomial_ntl() x._denominator = elt_den cdef ZZX_c result cdef ZZ_c tmp From a4d4ba0a76dbe852ceabcfa7b8c01703ad953f92 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:45:03 +0800 Subject: [PATCH 31/44] rename __fld_numerator -> _fld_numerator --- .../quatalg/quaternion_algebra_element.pyx | 2 +- .../number_field/number_field_element.pxd | 2 +- .../number_field/number_field_element.pyx | 30 +++++++++---------- .../number_field_element_quadratic.pyx | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/sage/algebras/quatalg/quaternion_algebra_element.pyx b/src/sage/algebras/quatalg/quaternion_algebra_element.pyx index b42182851fa..8cb7e848fd0 100644 --- a/src/sage/algebras/quatalg/quaternion_algebra_element.pyx +++ b/src/sage/algebras/quatalg/quaternion_algebra_element.pyx @@ -1727,7 +1727,7 @@ cdef class QuaternionAlgebraElement_number_field(QuaternionAlgebraElement_abstra fmpz_poly_set_ZZX(self.a, a._numerator) # we will assume that the denominator of a and b are 1 fmpz_poly_set_ZZX(self.b, b._numerator) - fmpz_poly_set_ZZX(self.modulus, (x).__fld_numerator.x) # and same for the modulus + fmpz_poly_set_ZZX(self.modulus, (x)._fld_numerator.x) # and same for the modulus def __getitem__(self, int i): """ diff --git a/src/sage/rings/number_field/number_field_element.pxd b/src/sage/rings/number_field/number_field_element.pxd index fe77101f6cc..c3d8a8b4a4b 100644 --- a/src/sage/rings/number_field/number_field_element.pxd +++ b/src/sage/rings/number_field/number_field_element.pxd @@ -15,7 +15,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef ZZ_c _denominator # Pointers to the defining polynomial (with numerator) for the field. # I keep these as pointers for arithmetic speed. - cdef ntl_ZZX __fld_numerator + cdef ntl_ZZX _fld_numerator cdef ntl_ZZ _fld_denominator cdef object __multiplicative_order cdef object __pari diff --git a/src/sage/rings/number_field/number_field_element.pyx b/src/sage/rings/number_field/number_field_element.pyx index 343a2e598e1..5873e0d0e2d 100644 --- a/src/sage/rings/number_field/number_field_element.pyx +++ b/src/sage/rings/number_field/number_field_element.pyx @@ -218,7 +218,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef type t = type(self) cdef NumberFieldElement x = t.__new__(t) x._parent = self._parent - x.__fld_numerator = self.__fld_numerator + x._fld_numerator = self._fld_numerator x._fld_denominator = self._fld_denominator return x @@ -317,7 +317,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): True """ FieldElement.__init__(self, parent) - self.__fld_numerator, self._fld_denominator = parent.absolute_polynomial_ntl() + self._fld_numerator, self._fld_denominator = parent.absolute_polynomial_ntl() cdef ZZ_c coeff if isinstance(f, (int, Integer_sage)): @@ -417,7 +417,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef type t = type(self) cdef NumberFieldElement x = t.__new__(t) x._parent = new_parent - x.__fld_numerator, x._fld_denominator = new_parent.polynomial_ntl() + x._fld_numerator, x._fld_denominator = new_parent.polynomial_ntl() x._denominator = self._denominator cdef ZZX_c result cdef ZZ_c tmp @@ -427,7 +427,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): for i from 0 <= i <= ZZX_deg(self._numerator): tmp = ZZX_coeff(self._numerator, i) ZZX_SetCoeff(result, i*rel, tmp) - ZZX_rem(x._numerator, result, x.__fld_numerator.x) + ZZX_rem(x._numerator, result, x._fld_numerator.x) return x def __reduce__(self): @@ -966,7 +966,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): # set the denominator mpz_set_si(denom_temp.value, 1) mpz_to_ZZ(&self._denominator, (denom_temp).value) - for i from 0 <= i < ZZX_deg(self.__fld_numerator.x): + for i from 0 <= i < ZZX_deg(self._fld_numerator.x): tmp_integer = (ZZ.random_element(x=num_bound, distribution=distribution)) mpz_to_ZZ(&ntl_temp, (tmp_integer).value) @@ -977,7 +977,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): mpz_set_si(denom_temp.value, 1) tmp_integer = Integer.__new__(Integer) - for i from 0 <= i < ZZX_deg(self.__fld_numerator.x): + for i from 0 <= i < ZZX_deg(self._fld_numerator.x): tmp_rational = (QQ.random_element(num_bound=num_bound, den_bound=den_bound, distribution=distribution)) @@ -992,7 +992,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): mpz_to_ZZ(&self._denominator, (denom_temp).value) # now the coefficients themselves. - for i from 0 <= i < ZZX_deg(self.__fld_numerator.x): + for i from 0 <= i < ZZX_deg(self._fld_numerator.x): # calculate the new numerator. if our old entry is # p/q, and the lcm is k, it's just pk/q, which we # also know is integral -- so we can use mpz_divexact @@ -2572,14 +2572,14 @@ cdef class NumberFieldElement(NumberFieldElement_base): # MulMod doesn't handle non-monic polynomials. # Therefore, we handle the non-monic case entirely separately. ZZ_mul(x._denominator, self._denominator, _right._denominator) - if ZZ_IsOne(ZZX_LeadCoeff(self.__fld_numerator.x)): - ZZX_MulMod(x._numerator, self._numerator, _right._numerator, self.__fld_numerator.x) + if ZZ_IsOne(ZZX_LeadCoeff(self._fld_numerator.x)): + ZZX_MulMod(x._numerator, self._numerator, _right._numerator, self._fld_numerator.x) else: ZZX_mul(x._numerator, self._numerator, _right._numerator) - if ZZX_deg(x._numerator) >= ZZX_deg(self.__fld_numerator.x): + if ZZX_deg(x._numerator) >= ZZX_deg(self._fld_numerator.x): ZZX_mul_ZZ( x._numerator, x._numerator, self._fld_denominator.x ) - ZZX_mul_ZZ( temp, self.__fld_numerator.x, x._denominator ) - ZZ_power(temp1,ZZX_LeadCoeff(temp),ZZX_deg(x._numerator)-ZZX_deg(self.__fld_numerator.x)+1) + ZZX_mul_ZZ( temp, self._fld_numerator.x, x._denominator ) + ZZ_power(temp1,ZZX_LeadCoeff(temp),ZZX_deg(x._numerator)-ZZX_deg(self._fld_numerator.x)+1) ZZX_PseudoRem(x._numerator, x._numerator, temp) ZZ_mul(x._denominator, x._denominator, self._fld_denominator.x) ZZ_mul(x._denominator, x._denominator, temp1) @@ -2835,7 +2835,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): # but may fail if NTL runs out of FFT primes. x = self._new() sig_on() - ZZX_XGCD(x._denominator, x._numerator, temp, self._numerator, self.__fld_numerator.x, 1) + ZZX_XGCD(x._denominator, x._numerator, temp, self._numerator, self._fld_numerator.x, 1) ZZX_mul_ZZ(x._numerator, x._numerator, self._denominator) x._reduce_c_() sig_off() @@ -5320,7 +5320,7 @@ cdef class OrderElement_absolute(NumberFieldElement_absolute): cdef OrderElement_absolute x = t.__new__(t) x._parent = self._parent x._number_field = self._parent.number_field() - x.__fld_numerator = self.__fld_numerator + x._fld_numerator = self._fld_numerator x._fld_denominator = self._fld_denominator return x @@ -5441,7 +5441,7 @@ cdef class OrderElement_relative(NumberFieldElement_relative): cdef OrderElement_relative x = t.__new__(t) x._parent = self._parent x._number_field = self._parent.number_field() - x.__fld_numerator = self.__fld_numerator + x._fld_numerator = self._fld_numerator x._fld_denominator = self._fld_denominator return x diff --git a/src/sage/rings/number_field/number_field_element_quadratic.pyx b/src/sage/rings/number_field/number_field_element_quadratic.pyx index 4c52d90703a..ab09e1469d4 100644 --- a/src/sage/rings/number_field/number_field_element_quadratic.pyx +++ b/src/sage/rings/number_field/number_field_element_quadratic.pyx @@ -610,7 +610,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): mpz_clear(tmp_mpz) x._parent = new_parent - x.__fld_numerator, x._fld_denominator = new_parent.polynomial_ntl() + x._fld_numerator, x._fld_denominator = new_parent.polynomial_ntl() x._denominator = elt_den cdef ZZX_c result cdef ZZ_c tmp From 77fc77dc71e8303478b920d614c2591b9c190e8d Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:45:39 +0800 Subject: [PATCH 32/44] rename __prec -> _prec --- src/sage/numerical/gauss_legendre.pyx | 4 +- src/sage/rings/complex_mpc.pxd | 2 +- src/sage/rings/complex_mpc.pyx | 26 ++--- .../polynomial/polynomial_real_mpfr_dense.pyx | 10 +- src/sage/rings/real_mpfi.pxd | 2 +- src/sage/rings/real_mpfi.pyx | 24 ++-- src/sage/rings/real_mpfr.pxd | 2 +- src/sage/rings/real_mpfr.pyx | 104 +++++++++--------- 8 files changed, 87 insertions(+), 87 deletions(-) diff --git a/src/sage/numerical/gauss_legendre.pyx b/src/sage/numerical/gauss_legendre.pyx index 5325797c7aa..96708c5b1ac 100644 --- a/src/sage/numerical/gauss_legendre.pyx +++ b/src/sage/numerical/gauss_legendre.pyx @@ -117,8 +117,8 @@ def nodes_uncached(degree, prec): raise ValueError("degree=%s not supported (degree must be 3 or even)" % degree) R = RealField(int(prec*3/2)) Rout = RealField(prec) - mpfr_init2(u,R.__prec) - mpfr_init2(v,R.__prec) + mpfr_init2(u,R._prec) + mpfr_init2(v,R._prec) ZERO = R.zero() ONE = R.one() HALF = ONE/2 diff --git a/src/sage/rings/complex_mpc.pxd b/src/sage/rings/complex_mpc.pxd index 762c38afbdc..f7d8cb9492c 100644 --- a/src/sage/rings/complex_mpc.pxd +++ b/src/sage/rings/complex_mpc.pxd @@ -11,7 +11,7 @@ cdef class MPComplexNumber(sage.structure.element.FieldElement): cpdef _mul_(self, other) cdef class MPComplexField_class(sage.rings.ring.Field): - cdef readonly int __prec + cdef readonly int _prec cdef mpc_rnd_t __rnd cdef object __rnd_str cdef object __real_field diff --git a/src/sage/rings/complex_mpc.pyx b/src/sage/rings/complex_mpc.pyx index b3681ff724f..bdd5c4e4fe6 100644 --- a/src/sage/rings/complex_mpc.pyx +++ b/src/sage/rings/complex_mpc.pyx @@ -307,7 +307,7 @@ cdef class MPComplexField_class(sage.rings.ring.Field): if prec < mpfr_prec_min() or prec > mpfr_prec_max(): raise ValueError("prec (=%s) must be >= %s and <= %s." % ( prec, mpfr_prec_min(), mpfr_prec_max())) - self.__prec = prec + self._prec = prec if not isinstance(rnd, str): raise TypeError("rnd must be a string") try: @@ -331,7 +331,7 @@ cdef class MPComplexField_class(sage.rings.ring.Field): cdef MPComplexNumber z z = MPComplexNumber.__new__(MPComplexNumber) z._parent = self - mpc_init2(z.value, self.__prec) + mpc_init2(z.value, self._prec) z.init = 1 return z @@ -344,7 +344,7 @@ cdef class MPComplexField_class(sage.rings.ring.Field): sage: MPComplexField(200, 'RNDDU') # indirect doctest Complex Field with 200 bits of precision and rounding RNDDU """ - s = "Complex Field with %s bits of precision"%self.__prec + s = "Complex Field with %s bits of precision"%self._prec if self.__rnd != MPC_RNDNN: s = s + " and rounding %s"%(self.__rnd_str) return s @@ -465,13 +465,13 @@ cdef class MPComplexField_class(sage.rings.ring.Field): if RR.has_coerce_map_from(S): return self._coerce_map_via([RR], S) - if isinstance(S, MPComplexField_class) and S.prec() >= self.__prec: + if isinstance(S, MPComplexField_class) and S.prec() >= self._prec: #FIXME: What map when rounding modes differ but prec is the same ? # How to provide commutativity of morphisms ? # Change _cmp_ when done return MPCtoMPC(S, self) - if isinstance(S, ComplexField_class) and S.prec() >= self.__prec: + if isinstance(S, ComplexField_class) and S.prec() >= self._prec: return CCtoMPC(S, self) late_import() @@ -490,7 +490,7 @@ cdef class MPComplexField_class(sage.rings.ring.Field): sage: loads(dumps(C)) == C True """ - return __create__MPComplexField_version0, (self.__prec, self.__rnd_str) + return __create__MPComplexField_version0, (self._prec, self.__rnd_str) def __richcmp__(left, right, int op): """ @@ -513,7 +513,7 @@ cdef class MPComplexField_class(sage.rings.ring.Field): cdef MPComplexField_class s = left cdef MPComplexField_class o = right - return richcmp(s.__prec, o.__prec, op) + return richcmp(s._prec, o._prec, op) def gen(self, n=0): """ @@ -604,7 +604,7 @@ cdef class MPComplexField_class(sage.rings.ring.Field): sage: C = MPComplexField(10, 'RNDNZ'); C.name() 'MPComplexField10_RNDNZ' """ - return "MPComplexField%s_%s"%(self.__prec, self.__rnd_str) + return "MPComplexField%s_%s"%(self._prec, self.__rnd_str) def __hash__(self): """ @@ -629,7 +629,7 @@ cdef class MPComplexField_class(sage.rings.ring.Field): sage: MPComplexField(22).prec() 22 """ - return self.__prec + return self._prec def rounding_mode(self): """ @@ -707,7 +707,7 @@ cdef class MPComplexNumber(sage.structure.element.FieldElement): cdef MPComplexNumber z z = MPComplexNumber.__new__(MPComplexNumber) z._parent = self._parent - mpc_init2(z.value, (self._parent).__prec) + mpc_init2(z.value, (self._parent)._prec) z.init = 1 return z @@ -760,7 +760,7 @@ cdef class MPComplexNumber(sage.structure.element.FieldElement): if parent is None: raise TypeError self._parent = parent - mpc_init2(self.value, parent.__prec) + mpc_init2(self.value, parent._prec) self.init = 1 if x is None: return self._set(x, y, base) @@ -1010,7 +1010,7 @@ cdef class MPComplexNumber(sage.structure.element.FieldElement): sage: i.prec() 2000 """ - return (self._parent).__prec + return (self._parent)._prec def real(self): """ @@ -2347,7 +2347,7 @@ cdef class MPComplexNumber(sage.structure.element.FieldElement): cdef mpc_rnd_t rnd = ((self._parent)).__rnd - cdef int prec = self._parent.__prec + cdef int prec = self._parent._prec if optimal or algorithm == "principal": if not isinstance(right, MPComplexNumber) or (right)._parent is not self._parent: diff --git a/src/sage/rings/polynomial/polynomial_real_mpfr_dense.pyx b/src/sage/rings/polynomial/polynomial_real_mpfr_dense.pyx index 094aa2a3623..50e041d2af4 100644 --- a/src/sage/rings/polynomial/polynomial_real_mpfr_dense.pyx +++ b/src/sage/rings/polynomial/polynomial_real_mpfr_dense.pyx @@ -111,7 +111,7 @@ cdef class PolynomialRealDense(Polynomial): Polynomial.__init__(self, parent, is_gen=is_gen) self._base_ring = parent._base cdef Py_ssize_t i, degree - cdef int prec = self._base_ring.__prec + cdef int prec = self._base_ring._prec cdef mpfr_rnd_t rnd = self._base_ring.rnd if x is None: self._coeffs = check_allocarray(1, sizeof(mpfr_t)) # degree zero @@ -222,7 +222,7 @@ cdef class PolynomialRealDense(Polynomial): cdef PolynomialRealDense _new(self, Py_ssize_t degree): cdef Py_ssize_t i - cdef int prec = self._base_ring.__prec + cdef int prec = self._base_ring._prec cdef PolynomialRealDense f = PolynomialRealDense.__new__(PolynomialRealDense) f._parent = self._parent f._base_ring = self._base_ring @@ -496,7 +496,7 @@ cdef class PolynomialRealDense(Polynomial): else: f = left._new(left._degree + right._degree) sig_on() - mpfr_init2(tmp, left._base_ring.__prec) + mpfr_init2(tmp, left._base_ring._prec) for i from 0 <= i <= f._degree: # Yes, we could make this more efficient by initializing with # a multiple of left rather than all zeros... @@ -654,7 +654,7 @@ cdef class PolynomialRealDense(Polynomial): q = self._new(self._degree - other._degree) # This is the standard division algorithm sig_on() - mpfr_init2(tmp, self._base_ring.__prec) + mpfr_init2(tmp, self._base_ring._prec) for i from self._degree >= i >= other._degree: mpfr_set(q._coeffs[i-other._degree], r._coeffs[i], rnd) for j from 0 <= j < other._degree: @@ -718,7 +718,7 @@ cdef class PolynomialRealDense(Polynomial): cdef RealNumber x = xx cdef RealNumber res - if (x._parent).__prec < self._base_ring.__prec: + if (x._parent)._prec < self._base_ring._prec: res = RealNumber(x._parent) else: res = RealNumber(self._base_ring) diff --git a/src/sage/rings/real_mpfi.pxd b/src/sage/rings/real_mpfi.pxd index 959a650aafc..4201788d198 100644 --- a/src/sage/rings/real_mpfi.pxd +++ b/src/sage/rings/real_mpfi.pxd @@ -11,7 +11,7 @@ from .real_mpfr cimport RealField_class cdef class RealIntervalFieldElement(RingElement) # forward decl cdef class RealIntervalField_class(sage.rings.abc.RealIntervalField): - cdef mpfr_prec_t __prec + cdef mpfr_prec_t _prec cdef bint sci_not # Cache RealField instances for the lower, upper, and middle bounds. # These have the same precision as the interval field; diff --git a/src/sage/rings/real_mpfi.pyx b/src/sage/rings/real_mpfi.pyx index 1193a14baff..509f6f63da0 100644 --- a/src/sage/rings/real_mpfi.pyx +++ b/src/sage/rings/real_mpfi.pyx @@ -526,7 +526,7 @@ cdef class RealIntervalField_class(sage.rings.abc.RealIntervalField): if prec < MPFR_PREC_MIN or prec > MPFR_PREC_MAX: raise ValueError("prec (=%s) must be >= %s and <= %s." % ( prec, MPFR_PREC_MIN, MPFR_PREC_MAX)) - self.__prec = prec + self._prec = prec self.sci_not = sci_not self.__lower_field = RealField(prec, sci_not, "RNDD") self.__middle_field = RealField(prec, sci_not, "RNDN") @@ -598,7 +598,7 @@ cdef class RealIntervalField_class(sage.rings.abc.RealIntervalField): elif rnd == "RNDU": return self.upper_field() else: - return RealField(self.__prec, self.sci_not, rnd) + return RealField(self._prec, self.sci_not, rnd) def _repr_(self): """ @@ -611,7 +611,7 @@ cdef class RealIntervalField_class(sage.rings.abc.RealIntervalField): sage: RealIntervalField(200) # indirect doctest Real Interval Field with 200 bits of precision """ - s = "Real Interval Field with %s bits of precision"%self.__prec + s = "Real Interval Field with %s bits of precision"%self._prec return s def _latex_(self): @@ -802,7 +802,7 @@ cdef class RealIntervalField_class(sage.rings.abc.RealIntervalField): sage: RIF.has_coerce_map_from(float) False """ - prec = self.__prec + prec = self._prec # Direct and efficient conversions if S is ZZ or S is QQ: @@ -810,7 +810,7 @@ cdef class RealIntervalField_class(sage.rings.abc.RealIntervalField): if S is int or S is long: return True if isinstance(S, RealIntervalField_class): - return (S).__prec >= prec + return (S)._prec >= prec if isinstance(S, sage.rings.abc.NumberField_quadratic): return S.discriminant() > 0 @@ -844,7 +844,7 @@ cdef class RealIntervalField_class(sage.rings.abc.RealIntervalField): cdef RealIntervalField_class right left = self right = other # to access C structure - return richcmp(left.__prec, right.__prec, op) + return richcmp(left._prec, right._prec, op) def __reduce__(self): """ @@ -856,7 +856,7 @@ cdef class RealIntervalField_class(sage.rings.abc.RealIntervalField): sage: loads(dumps(R)) == R True """ - return __create__RealIntervalField_version0, (self.__prec, self.sci_not) + return __create__RealIntervalField_version0, (self._prec, self.sci_not) def random_element(self, *args, **kwds): """ @@ -997,7 +997,7 @@ cdef class RealIntervalField_class(sage.rings.abc.RealIntervalField): sage: RealIntervalField(200).name() 'IntervalRealIntervalField200' """ - return "IntervalRealIntervalField%s"%(self.__prec) + return "IntervalRealIntervalField%s"%(self._prec) def __hash__(self): """ @@ -1023,7 +1023,7 @@ cdef class RealIntervalField_class(sage.rings.abc.RealIntervalField): sage: RealIntervalField(200).precision() 200 """ - return self.__prec + return self._prec prec = precision @@ -1187,7 +1187,7 @@ cdef class RealIntervalFieldElement(RingElement): sage: TestSuite(x).run(skip=["_test_eq", "_test_pickling"]) """ cdef RealIntervalField_class p = parent - mpfi_init2(self.value, p.__prec) + mpfi_init2(self.value, p._prec) self._parent = p def __init__(self, parent, x, int base=10): @@ -1864,7 +1864,7 @@ cdef class RealIntervalFieldElement(RingElement): cdef mp_exp_t self_exp cdef mpz_t self_zz - cdef mpfr_prec_t prec = (self._parent).__prec + cdef mpfr_prec_t prec = (self._parent)._prec cdef char *zz_str cdef size_t zz_str_maxlen @@ -2977,7 +2977,7 @@ cdef class RealIntervalFieldElement(RingElement): sage: RealIntervalField(200)(2.1).precision() 200 """ - return (self._parent).__prec + return (self._parent)._prec prec = precision diff --git a/src/sage/rings/real_mpfr.pxd b/src/sage/rings/real_mpfr.pxd index 3549eccfd03..dd18e87715b 100644 --- a/src/sage/rings/real_mpfr.pxd +++ b/src/sage/rings/real_mpfr.pxd @@ -9,7 +9,7 @@ from sage.libs.mpfr.types cimport mpfr_prec_t cdef class RealNumber(sage.structure.element.RingElement) # forward decl cdef class RealField_class(sage.rings.abc.RealField): - cdef mpfr_prec_t __prec + cdef mpfr_prec_t _prec cdef bint sci_not cdef mpfr_rnd_t rnd cdef object rnd_str diff --git a/src/sage/rings/real_mpfr.pyx b/src/sage/rings/real_mpfr.pyx index ea7ff07a216..11e21af5e98 100644 --- a/src/sage/rings/real_mpfr.pyx +++ b/src/sage/rings/real_mpfr.pyx @@ -524,7 +524,7 @@ cdef class RealField_class(sage.rings.abc.RealField): if prec < MPFR_PREC_MIN or prec > MPFR_PREC_MAX: raise ValueError("prec (=%s) must be >= %s and <= %s" % ( prec, MPFR_PREC_MIN, MPFR_PREC_MAX)) - self.__prec = prec + self._prec = prec self.sci_not = sci_not self.rnd = rnd @@ -561,7 +561,7 @@ cdef class RealField_class(sage.rings.abc.RealField): sage: RealField(17,rnd='RNDD') # indirect doctest Real Field with 17 bits of precision and rounding RNDD """ - s = "Real Field with %s bits of precision"%self.__prec + s = "Real Field with %s bits of precision"%self._prec if self.rnd != MPFR_RNDN: s = s + " and rounding %s"%(self.rnd_str) return s @@ -733,13 +733,13 @@ cdef class RealField_class(sage.rings.abc.RealField): return ZZtoRR(ZZ, self) elif S is QQ: return QQtoRR(QQ, self) - elif (S is RDF or S is float) and self.__prec <= 53: + elif (S is RDF or S is float) and self._prec <= 53: return double_toRR(S, self) elif S is long: return int_toRR(long, self) elif S is int: return int_toRR(int, self) - elif isinstance(S, RealField_class) and S.prec() >= self.__prec: + elif isinstance(S, RealField_class) and S.prec() >= self._prec: return RRtoRR(S, self) elif QQ.has_coerce_map_from(S): return QQtoRR(QQ, self) * QQ._internal_coerce_map_from(S) @@ -786,7 +786,7 @@ cdef class RealField_class(sage.rings.abc.RealField): return NotImplemented _other = other # to access C structure - return (self.__prec == _other.__prec and + return (self._prec == _other._prec and self.rnd == _other.rnd) == (op == Py_EQ) def __reduce__(self): @@ -799,7 +799,7 @@ cdef class RealField_class(sage.rings.abc.RealField): sage: loads(dumps(R)) == R True """ - return __create__RealField_version0, (self.__prec, self.sci_not, self.rnd_str) + return __create__RealField_version0, (self._prec, self.sci_not, self.rnd_str) def construction(self): r""" @@ -968,7 +968,7 @@ cdef class RealField_class(sage.rings.abc.RealField): sage: RealField(100,rnd='RNDU').name() 'RealField100_2' """ - return "RealField%s_%s"%(self.__prec,self.rnd) + return "RealField%s_%s"%(self._prec,self.rnd) def __hash__(self): """ @@ -995,7 +995,7 @@ cdef class RealField_class(sage.rings.abc.RealField): sage: RealField(20).precision() 20 """ - return Integer(self.__prec) + return Integer(self._prec) prec=precision # an alias @@ -1031,7 +1031,7 @@ cdef class RealField_class(sage.rings.abc.RealField): sage: R.to_prec(300) Real Field with 300 bits of precision and rounding RNDZ """ - if prec == self.__prec: + if prec == self._prec: return self else: return RealField(prec, self.sci_not, self.rnd) @@ -1052,7 +1052,7 @@ cdef class RealField_class(sage.rings.abc.RealField): 0.88622692545275801364908374167057259139877473 """ cdef RealNumber x = self._new() - if self.__prec > SIG_PREC_THRESHOLD: sig_on() + if self._prec > SIG_PREC_THRESHOLD: sig_on() # The docs for mpfr_free_cache say "Free the cache used by # the functions computing constants if needed (currently # mpfr_const_log2, mpfr_const_pi and mpfr_const_euler)", so @@ -1062,7 +1062,7 @@ cdef class RealField_class(sage.rings.abc.RealField): # functions, but this free is needed for them too! mpfr_free_cache() mpfr_const_pi(x.value, self.rnd) - if self.__prec > SIG_PREC_THRESHOLD: sig_off() + if self._prec > SIG_PREC_THRESHOLD: sig_off() return x def euler_constant(self): @@ -1091,10 +1091,10 @@ cdef class RealField_class(sage.rings.abc.RealField): 0.91596559417721901505460351493 """ cdef RealNumber x = self._new() - if self.__prec > SIG_PREC_THRESHOLD: sig_on() + if self._prec > SIG_PREC_THRESHOLD: sig_on() mpfr_free_cache() mpfr_const_catalan(x.value, self.rnd) - if self.__prec > SIG_PREC_THRESHOLD: sig_off() + if self._prec > SIG_PREC_THRESHOLD: sig_off() return x def log2(self): @@ -1111,10 +1111,10 @@ cdef class RealField_class(sage.rings.abc.RealField): 0.69314718055994530941723212146 """ cdef RealNumber x = self._new() - if self.__prec > SIG_PREC_THRESHOLD: sig_on() + if self._prec > SIG_PREC_THRESHOLD: sig_on() mpfr_free_cache() mpfr_const_log2(x.value, self.rnd) - if self.__prec > SIG_PREC_THRESHOLD: sig_off() + if self._prec > SIG_PREC_THRESHOLD: sig_off() return x def random_element(self, min=-1, max=1, distribution=None): @@ -1181,9 +1181,9 @@ cdef class RealField_class(sage.rings.abc.RealField): if n < 0: raise ArithmeticError("n must be nonnegative") x = self._new() - if self.__prec > SIG_PREC_THRESHOLD and n < SIG_PREC_THRESHOLD: sig_on() + if self._prec > SIG_PREC_THRESHOLD and n < SIG_PREC_THRESHOLD: sig_on() mpfr_fac_ui(x.value, n, self.rnd) - if self.__prec > SIG_PREC_THRESHOLD and n < SIG_PREC_THRESHOLD: sig_off() + if self._prec > SIG_PREC_THRESHOLD and n < SIG_PREC_THRESHOLD: sig_off() return x def rounding_mode(self): @@ -1346,7 +1346,7 @@ cdef class RealNumber(sage.structure.element.RingElement): NaN """ cdef RealField_class p = parent - mpfr_init2(self.value, p.__prec) + mpfr_init2(self.value, p._prec) self._parent = p def __init__(self, parent, x=0, int base=10): @@ -1446,7 +1446,7 @@ cdef class RealNumber(sage.structure.element.RingElement): sage: numpy.array([1.000000000000000000000000000000000000]).dtype # optional - numpy dtype('O') """ - if (self._parent).__prec <= 53: + if (self._parent)._prec <= 53: return numpy_double_interface else: return numpy_object_interface @@ -2075,7 +2075,7 @@ cdef class RealNumber(sage.structure.element.RingElement): # This avoids the confusion a lot of people have with the last # 1-2 binary digits being wrong due to rounding coming from # representing numbers in binary. - digits = (((self._parent).__prec - 1) * M_LN2_LN10) + digits = (((self._parent)._prec - 1) * M_LN2_LN10) if digits < 2: digits = 2 @@ -2303,7 +2303,7 @@ cdef class RealNumber(sage.structure.element.RingElement): if sgn == 0: return z - cdef mpfr_prec_t prec = (self._parent).__prec + cdef mpfr_prec_t prec = (self._parent)._prec if mpfr_inf_p(self.value): mpz_set_ui(z.value, EXP_MAX+1-EXP_MIN) @@ -2757,7 +2757,7 @@ cdef class RealNumber(sage.structure.element.RingElement): sage: RealField(101)(-1).precision() 101 """ - return Integer((self._parent).__prec) + return Integer((self._parent)._prec) prec = precision # alias @@ -3364,7 +3364,7 @@ cdef class RealNumber(sage.structure.element.RingElement): cdef unsigned long wordsize = sizeof(long)*8 cdef mpfr_prec_t prec - prec = (self._parent).__prec + prec = (self._parent)._prec # We round up the precision to the nearest multiple of wordsize. cdef int rounded_prec @@ -3699,7 +3699,7 @@ cdef class RealNumber(sage.structure.element.RingElement): from .real_mpfi import RealIntervalField cdef mpfr_rnd_t rnd = (self._parent).rnd - cdef mpfr_prec_t prec = (self._parent).__prec + cdef mpfr_prec_t prec = (self._parent)._prec cdef RealNumber low, high cdef int odd @@ -4249,9 +4249,9 @@ cdef class RealNumber(sage.structure.element.RingElement): cdef RealNumber x if mpfr_cmp_ui(self.value, 0) >= 0: x = self._new() - if (self._parent).__prec > 10*SIG_PREC_THRESHOLD: sig_on() + if (self._parent)._prec > 10*SIG_PREC_THRESHOLD: sig_on() mpfr_sqrt(x.value, self.value, (self._parent).rnd) - if (self._parent).__prec > 10*SIG_PREC_THRESHOLD: sig_off() + if (self._parent)._prec > 10*SIG_PREC_THRESHOLD: sig_off() if all: if x.is_zero(): return [x] @@ -4295,9 +4295,9 @@ cdef class RealNumber(sage.structure.element.RingElement): -1.42108547152020e-14 """ cdef RealNumber x = self._new() - if (self._parent).__prec > 10*SIG_PREC_THRESHOLD: sig_on() + if (self._parent)._prec > 10*SIG_PREC_THRESHOLD: sig_on() mpfr_cbrt(x.value, self.value, (self._parent).rnd) - if (self._parent).__prec > 10*SIG_PREC_THRESHOLD: sig_off() + if (self._parent)._prec > 10*SIG_PREC_THRESHOLD: sig_off() return x def __pow(self, RealNumber exponent): @@ -4435,9 +4435,9 @@ cdef class RealNumber(sage.structure.element.RingElement): return self._complex_number_().log(base) if base is None or base == 'e': x = self._new() - if (self._parent).__prec > SIG_PREC_THRESHOLD: sig_on() + if (self._parent)._prec > SIG_PREC_THRESHOLD: sig_on() mpfr_log(x.value, self.value, (self._parent).rnd) - if (self._parent).__prec > SIG_PREC_THRESHOLD: sig_off() + if (self._parent)._prec > SIG_PREC_THRESHOLD: sig_off() return x elif base == 10: return self.log10() @@ -4476,9 +4476,9 @@ cdef class RealNumber(sage.structure.element.RingElement): if self < 0: return self._complex_number_().log(2) x = self._new() - if (self._parent).__prec > SIG_PREC_THRESHOLD: sig_on() + if (self._parent)._prec > SIG_PREC_THRESHOLD: sig_on() mpfr_log2(x.value, self.value, (self._parent).rnd) - if (self._parent).__prec > SIG_PREC_THRESHOLD: sig_off() + if (self._parent)._prec > SIG_PREC_THRESHOLD: sig_off() return x def log10(self): @@ -4513,9 +4513,9 @@ cdef class RealNumber(sage.structure.element.RingElement): if self < 0: return self._complex_number_().log(10) x = self._new() - if (self._parent).__prec > SIG_PREC_THRESHOLD: sig_on() + if (self._parent)._prec > SIG_PREC_THRESHOLD: sig_on() mpfr_log10(x.value, self.value, (self._parent).rnd) - if (self._parent).__prec > SIG_PREC_THRESHOLD: sig_off() + if (self._parent)._prec > SIG_PREC_THRESHOLD: sig_off() return x def log1p(self): @@ -4562,9 +4562,9 @@ cdef class RealNumber(sage.structure.element.RingElement): if self < -1: return (self+1.0)._complex_number_().log() x = self._new() - if (self._parent).__prec > SIG_PREC_THRESHOLD: sig_on() + if (self._parent)._prec > SIG_PREC_THRESHOLD: sig_on() mpfr_log1p(x.value, self.value, (self._parent).rnd) - if (self._parent).__prec > SIG_PREC_THRESHOLD: sig_off() + if (self._parent)._prec > SIG_PREC_THRESHOLD: sig_off() return x def exp(self): @@ -4620,9 +4620,9 @@ cdef class RealNumber(sage.structure.element.RingElement): 1.89117248253021e-10 """ cdef RealNumber x = self._new() - if (self._parent).__prec > SIG_PREC_THRESHOLD: sig_on() + if (self._parent)._prec > SIG_PREC_THRESHOLD: sig_on() mpfr_exp2(x.value, self.value, (self._parent).rnd) - if (self._parent).__prec > SIG_PREC_THRESHOLD: sig_off() + if (self._parent)._prec > SIG_PREC_THRESHOLD: sig_off() return x def exp10(self): @@ -4648,9 +4648,9 @@ cdef class RealNumber(sage.structure.element.RingElement): 5.01187233627276e-33 """ cdef RealNumber x = self._new() - if (self._parent).__prec > SIG_PREC_THRESHOLD: sig_on() + if (self._parent)._prec > SIG_PREC_THRESHOLD: sig_on() mpfr_exp10(x.value, self.value, (self._parent).rnd) - if (self._parent).__prec > SIG_PREC_THRESHOLD: sig_off() + if (self._parent)._prec > SIG_PREC_THRESHOLD: sig_off() return x def expm1(self): @@ -4672,9 +4672,9 @@ cdef class RealNumber(sage.structure.element.RingElement): 1.00000000000000e-16 """ cdef RealNumber x = self._new() - if (self._parent).__prec > SIG_PREC_THRESHOLD: sig_on() + if (self._parent)._prec > SIG_PREC_THRESHOLD: sig_on() mpfr_expm1(x.value, self.value, (self._parent).rnd) - if (self._parent).__prec > SIG_PREC_THRESHOLD: sig_off() + if (self._parent)._prec > SIG_PREC_THRESHOLD: sig_off() return x def eint(self): @@ -4694,9 +4694,9 @@ cdef class RealNumber(sage.structure.element.RingElement): -0.219383934395520 """ cdef RealNumber x = self._new() - if (self._parent).__prec > SIG_PREC_THRESHOLD: sig_on() + if (self._parent)._prec > SIG_PREC_THRESHOLD: sig_on() mpfr_eint(x.value, self.value, (self._parent).rnd) - if (self._parent).__prec > SIG_PREC_THRESHOLD: sig_on() + if (self._parent)._prec > SIG_PREC_THRESHOLD: sig_on() return x def cos(self): @@ -5125,9 +5125,9 @@ cdef class RealNumber(sage.structure.element.RingElement): _other = self._parent(other) x = self._new() - if (self._parent).__prec > 10000: sig_on() + if (self._parent)._prec > 10000: sig_on() mpfr_agm(x.value, self.value, _other.value, (self._parent).rnd) - if (self._parent).__prec > 10000: sig_off() + if (self._parent)._prec > 10000: sig_off() return x def erf(self): @@ -5280,9 +5280,9 @@ cdef class RealNumber(sage.structure.element.RingElement): 0.886226925452758 """ cdef RealNumber x = self._new() - if (self._parent).__prec > SIG_PREC_THRESHOLD: sig_on() + if (self._parent)._prec > SIG_PREC_THRESHOLD: sig_on() mpfr_gamma(x.value, self.value, (self._parent).rnd) - if (self._parent).__prec > SIG_PREC_THRESHOLD: sig_off() + if (self._parent)._prec > SIG_PREC_THRESHOLD: sig_off() return x def log_gamma(self): @@ -5306,10 +5306,10 @@ cdef class RealNumber(sage.structure.element.RingElement): cdef RealNumber x = self._new() parent = (self._parent) if not mpfr_sgn(self.value) < 0: - if parent.__prec > SIG_PREC_THRESHOLD: + if parent._prec > SIG_PREC_THRESHOLD: sig_on() mpfr_lngamma(x.value, self.value, parent.rnd) - if parent.__prec > SIG_PREC_THRESHOLD: + if parent._prec > SIG_PREC_THRESHOLD: sig_off() return x from sage.libs.mpmath.utils import call @@ -5534,7 +5534,7 @@ cdef class RealNumber(sage.structure.element.RingElement): cdef RealField_class fld = self._parent - if algorithm == 0 and n <= 10000 / fld.__prec: + if algorithm == 0 and n <= 10000 / fld._prec: # This is a rough estimate for when it is probably # faster to call mpfr directly. (This is a pretty # good estimate on one particular machine, a @@ -5639,7 +5639,7 @@ cdef class RealNumber(sage.structure.element.RingElement): from .real_mpfi import RealIntervalField - cdef mpfr_prec_t prec = fld.__prec + 10 + cdef mpfr_prec_t prec = fld._prec + 10 cdef RealNumber lower cdef RealNumber upper From a4b597c78944363f701a71a3a16bbe46871b1fa9 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:46:02 +0800 Subject: [PATCH 33/44] rename __poly -> _poly --- src/sage/libs/arb/arith.pyx | 2 +- src/sage/matrix/matrix_complex_ball_dense.pyx | 2 +- src/sage/matrix/matrix_integer_dense.pyx | 6 +- src/sage/matrix/matrix_integer_sparse.pyx | 12 +- src/sage/misc/cython.py | 6 +- src/sage/rings/complex_arb.pyx | 4 +- src/sage/rings/padics/pow_computer_flint.pyx | 12 +- src/sage/rings/polynomial/hilbert.pyx | 28 +- .../polynomial/polynomial_complex_arb.pxd | 2 +- .../polynomial/polynomial_complex_arb.pyx | 122 ++++---- .../polynomial_integer_dense_flint.pxd | 2 +- .../polynomial_integer_dense_flint.pyx | 160 +++++------ .../polynomial_integer_dense_ntl.pxd | 2 +- .../polynomial_integer_dense_ntl.pyx | 102 +++---- .../polynomial/polynomial_modn_dense_ntl.pxd | 2 +- .../polynomial/polynomial_modn_dense_ntl.pyx | 52 ++-- .../polynomial/polynomial_rational_flint.pxd | 2 +- .../polynomial/polynomial_rational_flint.pyx | 266 +++++++++--------- .../polynomial/polynomial_zmod_flint.pyx | 2 +- src/sage/rings/power_series_mpoly.pxd | 2 +- src/sage/rings/power_series_mpoly.pyx | 6 +- 21 files changed, 397 insertions(+), 397 deletions(-) diff --git a/src/sage/libs/arb/arith.pyx b/src/sage/libs/arb/arith.pyx index d885f97b238..3b32fe7e8ed 100644 --- a/src/sage/libs/arb/arith.pyx +++ b/src/sage/libs/arb/arith.pyx @@ -81,5 +81,5 @@ def hilbert_class_polynomial(D): cdef long n = D cdef Polynomial_integer_dense_flint poly poly = PolynomialRing(ZZ, "x", implementation="FLINT")() - acb_modular_hilbert_class_poly(poly.__poly, n) + acb_modular_hilbert_class_poly(poly._poly, n) return poly diff --git a/src/sage/matrix/matrix_complex_ball_dense.pyx b/src/sage/matrix/matrix_complex_ball_dense.pyx index ad57de71deb..6de662de3a1 100644 --- a/src/sage/matrix/matrix_complex_ball_dense.pyx +++ b/src/sage/matrix/matrix_complex_ball_dense.pyx @@ -664,7 +664,7 @@ cdef class Matrix_complex_ball_dense(Matrix_dense): Pol = polynomial_ring_constructor._single_variate(self.base_ring(), var) cdef Polynomial_complex_arb res = Polynomial_complex_arb(Pol) sig_on() - acb_mat_charpoly(res.__poly, self.value, prec(self)) + acb_mat_charpoly(res._poly, self.value, prec(self)) sig_off() return res diff --git a/src/sage/matrix/matrix_integer_dense.pyx b/src/sage/matrix/matrix_integer_dense.pyx index 7fe211835cc..8b5a8f95c5c 100644 --- a/src/sage/matrix/matrix_integer_dense.pyx +++ b/src/sage/matrix/matrix_integer_dense.pyx @@ -1372,12 +1372,12 @@ cdef class Matrix_integer_dense(Matrix_dense): if algorithm == 'flint': g = ( PolynomialRing(ZZ, names=var).gen())._new() sig_on() - fmpz_mat_charpoly(g.__poly, self._matrix) + fmpz_mat_charpoly(g._poly, self._matrix) sig_off() elif algorithm == 'linbox': g = ( PolynomialRing(ZZ, names=var).gen())._new() sig_on() - linbox_fmpz_mat_charpoly(g.__poly, self._matrix) + linbox_fmpz_mat_charpoly(g._poly, self._matrix) sig_off() elif algorithm == 'generic': g = Matrix_dense.charpoly(self, var) @@ -1461,7 +1461,7 @@ cdef class Matrix_integer_dense(Matrix_dense): if algorithm == 'linbox': g = ( PolynomialRing(ZZ, names=var).gen())._new() sig_on() - linbox_fmpz_mat_minpoly(g.__poly, self._matrix) + linbox_fmpz_mat_minpoly(g._poly, self._matrix) sig_off() elif algorithm == 'generic': g = Matrix_dense.minpoly(self, var) diff --git a/src/sage/matrix/matrix_integer_sparse.pyx b/src/sage/matrix/matrix_integer_sparse.pyx index a41677c7b6a..83d5ee42fbe 100644 --- a/src/sage/matrix/matrix_integer_sparse.pyx +++ b/src/sage/matrix/matrix_integer_sparse.pyx @@ -869,10 +869,10 @@ cdef class Matrix_integer_sparse(Matrix_sparse): sig_off() cdef size_t i - fmpz_poly_fit_length(g.__poly, p.size()) + fmpz_poly_fit_length(g._poly, p.size()) for i in range(p.size()): - fmpz_poly_set_coeff_mpz(g.__poly, i, p[0][i].get_mpz_const()) - _fmpz_poly_set_length(g.__poly, p.size()) + fmpz_poly_set_coeff_mpz(g._poly, i, p[0][i].get_mpz_const()) + _fmpz_poly_set_length(g._poly, p.size()) del M del p @@ -968,10 +968,10 @@ cdef class Matrix_integer_sparse(Matrix_sparse): sig_off() cdef size_t i - fmpz_poly_fit_length(g.__poly, p.size()) + fmpz_poly_fit_length(g._poly, p.size()) for i in range(p.size()): - fmpz_poly_set_coeff_mpz(g.__poly, i, p[0][i].get_mpz_const()) - _fmpz_poly_set_length(g.__poly, p.size()) + fmpz_poly_set_coeff_mpz(g._poly, i, p[0][i].get_mpz_const()) + _fmpz_poly_set_length(g._poly, p.size()) del M del p diff --git a/src/sage/misc/cython.py b/src/sage/misc/cython.py index fea06f8a333..0674c83f5d0 100644 --- a/src/sage/misc/cython.py +++ b/src/sage/misc/cython.py @@ -646,9 +646,9 @@ def compile_and_load(code, **kwds): ....: cdef Polynomial_rational_flint res = f._new() ....: cdef unsigned long k ....: cdef Rational z = Rational(0) - ....: for k in range(fmpq_poly_length(f.__poly)): - ....: fmpq_poly_get_coeff_mpq(z.value, f.__poly, k) - ....: fmpq_poly_set_coeff_mpq(res.__poly, n*k, z.value) + ....: for k in range(fmpq_poly_length(f._poly)): + ....: fmpq_poly_get_coeff_mpq(z.value, f._poly, k) + ....: fmpq_poly_set_coeff_mpq(res._poly, n*k, z.value) ....: return res ....: ''' sage: module = compile_and_load(code) # long time diff --git a/src/sage/rings/complex_arb.pyx b/src/sage/rings/complex_arb.pyx index ef432c1e945..95e615f3ee6 100644 --- a/src/sage/rings/complex_arb.pyx +++ b/src/sage/rings/complex_arb.pyx @@ -874,7 +874,7 @@ class ComplexBallField(UniqueRepresentation, sage.rings.abc.ComplexBallField): cdef RealBall rb cdef ComplexBall cb acb_poly_init(rounded_poly) - cdef long deg = acb_poly_degree(poly.__poly) + cdef long deg = acb_poly_degree(poly._poly) if deg < 0: raise ArithmeticError("taking the roots of the zero polynomial") cdef acb_ptr roots = _acb_vec_init(deg) @@ -883,7 +883,7 @@ class ComplexBallField(UniqueRepresentation, sage.rings.abc.ComplexBallField): while ((isolated < deg or any(acb_rel_accuracy_bits(&roots[i]) < tgtprec for i in range(deg))) and prec < maxprec): - acb_poly_set_round(rounded_poly, poly.__poly, prec) + acb_poly_set_round(rounded_poly, poly._poly, prec) maxiter = min(max(deg, 32), prec) if (prec == initial_prec): isolated = acb_poly_find_roots(roots, rounded_poly, NULL, maxiter, prec) diff --git a/src/sage/rings/padics/pow_computer_flint.pyx b/src/sage/rings/padics/pow_computer_flint.pyx index ae9e9f954a2..e521ea6e078 100644 --- a/src/sage/rings/padics/pow_computer_flint.pyx +++ b/src/sage/rings/padics/pow_computer_flint.pyx @@ -208,7 +208,7 @@ cdef class PowComputer_flint_1step(PowComputer_flint): """ cdef Polynomial_integer_dense_flint poly = _poly - cdef long length = fmpz_poly_length(poly.__poly) + cdef long length = fmpz_poly_length(poly._poly) cdef Py_ssize_t i @@ -268,10 +268,10 @@ cdef class PowComputer_flint_1step(PowComputer_flint): PowComputer_flint.__init__(self, prime, cache_limit, prec_cap, ram_prec_cap, in_field, _poly, shift_seed) cdef Polynomial_integer_dense_flint poly = _poly - cdef long length = fmpz_poly_length(poly.__poly) + cdef long length = fmpz_poly_length(poly._poly) self.deg = length - 1 - fmpz_poly_set(self.modulus, poly.__poly) + fmpz_poly_set(self.modulus, poly._poly) cdef Py_ssize_t i cdef fmpz* coeffs = self.modulus.coeffs @@ -427,9 +427,9 @@ cdef class PowComputer_flint_1step(PowComputer_flint): x = R.gen() cdef Polynomial_integer_dense_flint ans = (x)._new() if _n is None: - fmpz_poly_set(ans.__poly, self.modulus) + fmpz_poly_set(ans._poly, self.modulus) else: - fmpz_poly_set(ans.__poly, self.get_modulus(_n)[0]) + fmpz_poly_set(ans._poly, self.get_modulus(_n)[0]) return ans cdef _new_fmpz_poly(self, fmpz_poly_t value, var='x'): @@ -440,7 +440,7 @@ cdef class PowComputer_flint_1step(PowComputer_flint): R = ZZ[var] x = R.gen() cdef Polynomial_integer_dense_flint ans = (x)._new() - fmpz_poly_set(ans.__poly, value) + fmpz_poly_set(ans._poly, value) return ans cdef class PowComputer_flint_unram(PowComputer_flint_1step): diff --git a/src/sage/rings/polynomial/hilbert.pyx b/src/sage/rings/polynomial/hilbert.pyx index ccf5159dfac..e2a693b5108 100644 --- a/src/sage/rings/polynomial/hilbert.pyx +++ b/src/sage/rings/polynomial/hilbert.pyx @@ -167,7 +167,7 @@ cdef bint HilbertBaseCase(Polynomial_integer_dense_flint fhs, Node D, tuple w): cdef int e # First, the easiest cases: if not D.Id: # The zero ideal - fmpz_poly_set_coeff_si(fhs.__poly, 0, 1) # = PR(1) + fmpz_poly_set_coeff_si(fhs._poly, 0, 1) # = PR(1) return True cdef ETuple m = PyList_GET_ITEM(D.Id, len(D.Id)-1) if m._nonzero == 0: # The one ideal @@ -180,18 +180,18 @@ cdef bint HilbertBaseCase(Polynomial_integer_dense_flint fhs, Node D, tuple w): if m._nonzero == 1 and m._data[1] == 1: fmpz_poly_init(poly_tmp) fmpz_poly_set_coeff_si(poly_tmp, 0, 1) - fmpz_poly_set_coeff_si(fhs.__poly, 0, 1) # = PR(1) + fmpz_poly_set_coeff_si(fhs._poly, 0, 1) # = PR(1) if w is None: for i in range(len(D.Id)): exp = (PyList_GET_ITEM(D.Id, i)).unweighted_degree() fmpz_poly_set_coeff_si(poly_tmp, exp, -1) - fmpz_poly_mul(fhs.__poly, fhs.__poly, poly_tmp) + fmpz_poly_mul(fhs._poly, fhs._poly, poly_tmp) fmpz_poly_set_coeff_si(poly_tmp, exp, 0) else: for i in range(len(D.Id)): exp = (PyList_GET_ITEM(D.Id, i)).weighted_degree(w) fmpz_poly_set_coeff_si(poly_tmp, exp, -1) - fmpz_poly_mul(fhs.__poly, fhs.__poly, poly_tmp) + fmpz_poly_mul(fhs._poly, fhs._poly, poly_tmp) fmpz_poly_set_coeff_si(poly_tmp, exp, 0) fmpz_poly_clear(poly_tmp) return True # PR.prod([(1-t**degree(m,w)) for m in D.Id]) @@ -207,18 +207,18 @@ cdef bint HilbertBaseCase(Polynomial_integer_dense_flint fhs, Node D, tuple w): # The ideal is generated by some powers of single variables, i.e., it splits. fmpz_poly_init(poly_tmp) fmpz_poly_set_coeff_si(poly_tmp, 0, 1) - fmpz_poly_set_coeff_si(fhs.__poly, 0, 1) # = PR(1) + fmpz_poly_set_coeff_si(fhs._poly, 0, 1) # = PR(1) if w is None: for i in range(len(D.Id)): exp = (PyList_GET_ITEM(D.Id, i)).unweighted_degree() fmpz_poly_set_coeff_si(poly_tmp, exp, -1) - fmpz_poly_mul(fhs.__poly, fhs.__poly, poly_tmp) + fmpz_poly_mul(fhs._poly, fhs._poly, poly_tmp) fmpz_poly_set_coeff_si(poly_tmp, exp, 0) else: for i in range(len(D.Id)): exp = (PyList_GET_ITEM(D.Id, i)).weighted_degree(w) fmpz_poly_set_coeff_si(poly_tmp, exp, -1) - fmpz_poly_mul(fhs.__poly, fhs.__poly, poly_tmp) + fmpz_poly_mul(fhs._poly, fhs._poly, poly_tmp) fmpz_poly_set_coeff_si(poly_tmp, exp, 0) fmpz_poly_clear(poly_tmp) return True # PR.prod([(1-t**degree(m,w)) for m in D.Id]) @@ -275,8 +275,8 @@ cdef bint HilbertBaseCase(Polynomial_integer_dense_flint fhs, Node D, tuple w): fmpz_poly_mul(SecondSummand, SecondSummand, poly_tmp) fmpz_poly_set_coeff_si(poly_tmp, exp, 0) fmpz_poly_clear(poly_tmp) - fmpz_poly_add(fhs.__poly, fhs.__poly, FirstSummand) - fmpz_poly_add(fhs.__poly, fhs.__poly, SecondSummand) + fmpz_poly_add(fhs._poly, fhs._poly, FirstSummand) + fmpz_poly_add(fhs._poly, fhs._poly, SecondSummand) fmpz_poly_clear(FirstSummand) fmpz_poly_clear(SecondSummand) return True @@ -529,11 +529,11 @@ def first_hilbert_series(I, grading=None, return_grading=False): if AN.Back.Right is None: AN = AN.Back #~ fhs *= AN.LMult - fmpz_poly_mul(fhs.__poly, fhs.__poly, AN.LMult) + fmpz_poly_mul(fhs._poly, fhs._poly, AN.LMult) got_result = True else: - fmpz_poly_set(AN.Back.LeftFHS, fhs.__poly) - fmpz_poly_set_si(fhs.__poly, 0) + fmpz_poly_set(AN.Back.LeftFHS, fhs._poly) + fmpz_poly_set_si(fhs._poly, 0) AN = AN.Back.Right AN.Back.Left = None got_result = HilbertBaseCase(fhs, AN, w) @@ -542,8 +542,8 @@ def first_hilbert_series(I, grading=None, return_grading=False): AN.Right = None #~ fhs = AN.LMult*AN.LeftFHS + AN.RMult*fhs fmpz_poly_mul(AN.LMult, AN.LMult, AN.LeftFHS) - fmpz_poly_mul(AN.RMult, AN.RMult, fhs.__poly) - fmpz_poly_add(fhs.__poly, AN.LMult, AN.RMult) + fmpz_poly_mul(AN.RMult, AN.RMult, fhs._poly) + fmpz_poly_add(fhs._poly, AN.LMult, AN.RMult) got_result = True def hilbert_poincare_series(I, grading=None): diff --git a/src/sage/rings/polynomial/polynomial_complex_arb.pxd b/src/sage/rings/polynomial/polynomial_complex_arb.pxd index aa4e2a1c0dc..e54d85e961b 100644 --- a/src/sage/rings/polynomial/polynomial_complex_arb.pxd +++ b/src/sage/rings/polynomial/polynomial_complex_arb.pxd @@ -2,5 +2,5 @@ from sage.libs.arb.acb_poly cimport * from sage.rings.polynomial.polynomial_element cimport Polynomial cdef class Polynomial_complex_arb(Polynomial): - cdef acb_poly_struct[1] __poly # https://github.com/cython/cython/issues/1984 + cdef acb_poly_struct[1] _poly # https://github.com/cython/cython/issues/1984 cdef Polynomial_complex_arb _new(self) diff --git a/src/sage/rings/polynomial/polynomial_complex_arb.pyx b/src/sage/rings/polynomial/polynomial_complex_arb.pyx index 5fc4ff1f6af..c43d00611e5 100644 --- a/src/sage/rings/polynomial/polynomial_complex_arb.pyx +++ b/src/sage/rings/polynomial/polynomial_complex_arb.pyx @@ -75,7 +75,7 @@ cdef class Polynomial_complex_arb(Polynomial): sage: ComplexBallField(2)['y']() 0 """ - acb_poly_init(self.__poly) + acb_poly_init(self._poly) def __dealloc__(self): r""" @@ -84,7 +84,7 @@ cdef class Polynomial_complex_arb(Polynomial): sage: pol = CBF['x']() sage: del pol """ - acb_poly_clear(self.__poly) + acb_poly_clear(self._poly) cdef Polynomial_complex_arb _new(self): r""" @@ -140,49 +140,49 @@ cdef class Polynomial_complex_arb(Polynomial): Polynomial.__init__(self, parent, is_gen=is_gen) if is_gen: - acb_poly_set_coeff_si(self.__poly, 1, 1) + acb_poly_set_coeff_si(self._poly, 1, 1) elif x is None: - acb_poly_zero(self.__poly) + acb_poly_zero(self._poly) elif isinstance(x, Polynomial_complex_arb): - acb_poly_set(self.__poly, ( x).__poly) + acb_poly_set(self._poly, ( x)._poly) elif isinstance(x, ComplexBall): - acb_poly_set_coeff_acb(self.__poly, 0, ( x).value) + acb_poly_set_coeff_acb(self._poly, 0, ( x).value) else: Coeff = parent.base_ring() if isinstance(x, list): lst = x length = len(lst) - sig_on(); acb_poly_fit_length(self.__poly, length); sig_off() + sig_on(); acb_poly_fit_length(self._poly, length); sig_off() for i in range(length): ball = Coeff(lst[i]) - acb_poly_set_coeff_acb(self.__poly, i, ball.value) + acb_poly_set_coeff_acb(self._poly, i, ball.value) elif isinstance(x, tuple): tpl = x length = len(tpl) - sig_on(); acb_poly_fit_length(self.__poly, length); sig_off() + sig_on(); acb_poly_fit_length(self._poly, length); sig_off() for i in range(length): ball = Coeff(tpl[i]) - acb_poly_set_coeff_acb(self.__poly, i, ball.value) + acb_poly_set_coeff_acb(self._poly, i, ball.value) elif isinstance(x, Polynomial): pol = x length = pol.degree() + 1 - sig_on(); acb_poly_fit_length(self.__poly, length); sig_off() + sig_on(); acb_poly_fit_length(self._poly, length); sig_off() for i in range(length): ball = Coeff(pol.get_unsafe(i)) - acb_poly_set_coeff_acb(self.__poly, i, ball.value) + acb_poly_set_coeff_acb(self._poly, i, ball.value) elif isinstance(x, dict): dct = x if len(dct) == 0: - acb_poly_zero(self.__poly) + acb_poly_zero(self._poly) else: length = max(int(i) for i in dct) + 1 - sig_on(); acb_poly_fit_length(self.__poly, length); sig_off() + sig_on(); acb_poly_fit_length(self._poly, length); sig_off() for i, c in dct.iteritems(): ball = Coeff(c) - acb_poly_set_coeff_acb(self.__poly, i, ball.value) + acb_poly_set_coeff_acb(self._poly, i, ball.value) else: ball = Coeff(x) - acb_poly_set_coeff_acb(self.__poly, 0, ball.value) + acb_poly_set_coeff_acb(self._poly, 0, ball.value) def __reduce__(self): r""" @@ -219,12 +219,12 @@ cdef class Polynomial_complex_arb(Polynomial): sage: Pol([1, 0, 0, 0]).degree() 0 """ - return smallInteger(acb_poly_degree(self.__poly)) + return smallInteger(acb_poly_degree(self._poly)) cdef get_unsafe(self, Py_ssize_t n): cdef ComplexBall res = ComplexBall.__new__(ComplexBall) res._parent = self._parent._base - acb_poly_get_coeff_acb(res.value, self.__poly, n) + acb_poly_get_coeff_acb(res.value, self._poly, n) return res cpdef list list(self, bint copy=True): @@ -241,7 +241,7 @@ cdef class Polynomial_complex_arb(Polynomial): sage: Pol([0, 1, RBF(0, rad=.1), 0]).list() [0, 1.000000000000000, [+/- 0.101]] """ - cdef unsigned long length = acb_poly_length(self.__poly) + cdef unsigned long length = acb_poly_length(self._poly) return [self.get_unsafe(n) for n in range(length)] def __bool__(self): @@ -257,7 +257,7 @@ cdef class Polynomial_complex_arb(Polynomial): sage: bool(z) True """ - return acb_poly_length(self.__poly) + return acb_poly_length(self._poly) # Ring and Euclidean arithmetic @@ -274,9 +274,9 @@ cdef class Polynomial_complex_arb(Polynomial): cdef Polynomial_complex_arb res = self._new() sig_on() acb_poly_add( - res.__poly, - self.__poly, - ( other).__poly, + res._poly, + self._poly, + ( other)._poly, prec(self)) sig_off() return res @@ -293,7 +293,7 @@ cdef class Polynomial_complex_arb(Polynomial): """ cdef Polynomial_complex_arb res = self._new() sig_on() - acb_poly_neg(res.__poly, self.__poly) + acb_poly_neg(res._poly, self._poly) sig_off() return res @@ -310,9 +310,9 @@ cdef class Polynomial_complex_arb(Polynomial): cdef Polynomial_complex_arb res = self._new() sig_on() acb_poly_sub( - res.__poly, - self.__poly, - ( other).__poly, + res._poly, + self._poly, + ( other)._poly, prec(self)) sig_off() return res @@ -331,9 +331,9 @@ cdef class Polynomial_complex_arb(Polynomial): cdef Polynomial_complex_arb res = self._new() sig_on() acb_poly_mul( - res.__poly, - self.__poly, - ( other).__poly, + res._poly, + self._poly, + ( other)._poly, prec(self)) sig_off() return res @@ -354,7 +354,7 @@ cdef class Polynomial_complex_arb(Polynomial): """ cdef Polynomial_complex_arb res = self._new() sig_on() - acb_poly_scalar_mul(res.__poly, self.__poly, ( a).value, prec(self)) + acb_poly_scalar_mul(res._poly, self._poly, ( a).value, prec(self)) sig_off() return res @@ -406,8 +406,8 @@ cdef class Polynomial_complex_arb(Polynomial): cdef Polynomial_complex_arb quo = self._new() cdef Polynomial_complex_arb rem = self._new() sig_on() - cdef bint success = acb_poly_divrem(quo.__poly, rem.__poly, self.__poly, - div.__poly, prec(self)) + cdef bint success = acb_poly_divrem(quo._poly, rem._poly, self._poly, + div._poly, prec(self)) sig_off() if success: return quo, rem @@ -442,15 +442,15 @@ cdef class Polynomial_complex_arb(Polynomial): if n < 0: n = 0 sig_on() - acb_poly_set(res.__poly, self.__poly) - acb_poly_truncate(res.__poly, n) + acb_poly_set(res._poly, self._poly) + acb_poly_truncate(res._poly, n) sig_off() return res cdef _inplace_truncate(self, long n): if n < 0: n = 0 - acb_poly_truncate(self.__poly, n) + acb_poly_truncate(self._poly, n) return self def __lshift__(val, n): @@ -482,7 +482,7 @@ cdef class Polynomial_complex_arb(Polynomial): cdef Polynomial_complex_arb self = ( val) cdef Polynomial_complex_arb res = self._new() sig_on() - acb_poly_shift_left(res.__poly, self.__poly, n) + acb_poly_shift_left(res._poly, self._poly, n) sig_off() return res @@ -515,7 +515,7 @@ cdef class Polynomial_complex_arb(Polynomial): cdef Polynomial_complex_arb self = ( val) cdef Polynomial_complex_arb res = self._new() sig_on() - acb_poly_shift_right(res.__poly, self.__poly, n) + acb_poly_shift_right(res._poly, self._poly, n) sig_off() return res @@ -545,7 +545,7 @@ cdef class Polynomial_complex_arb(Polynomial): if n < 0: n = 0 sig_on() - acb_poly_mullow(res.__poly, self.__poly, my_other.__poly, n, prec(self)) + acb_poly_mullow(res._poly, self._poly, my_other._poly, n, prec(self)) sig_off() return res @@ -573,7 +573,7 @@ cdef class Polynomial_complex_arb(Polynomial): if n < 0: n = 0 sig_on() - acb_poly_inv_series(res.__poly, self.__poly, n, prec(self)) + acb_poly_inv_series(res._poly, self._poly, n, prec(self)) sig_off() return res @@ -609,7 +609,7 @@ cdef class Polynomial_complex_arb(Polynomial): if n < 0: n = 0 sig_on() - acb_poly_pow_ui_trunc_binexp(res.__poly, self.__poly, expo, n, prec(self)) + acb_poly_pow_ui_trunc_binexp(res._poly, self._poly, expo, n, prec(self)) sig_off() return res @@ -645,7 +645,7 @@ cdef class Polynomial_complex_arb(Polynomial): if n < 0: n = 0 sig_on() - acb_poly_log_series(res.__poly, self.__poly, n, prec(self)) + acb_poly_log_series(res._poly, self._poly, n, prec(self)) sig_off() return res @@ -669,7 +669,7 @@ cdef class Polynomial_complex_arb(Polynomial): if n < 0: n = 0 sig_on() - acb_poly_exp_series(res.__poly, self.__poly, n, prec(self)) + acb_poly_exp_series(res._poly, self._poly, n, prec(self)) sig_off() return res @@ -694,7 +694,7 @@ cdef class Polynomial_complex_arb(Polynomial): if n < 0: n = 0 sig_on() - acb_poly_sqrt_series(res.__poly, self.__poly, n, prec(self)) + acb_poly_sqrt_series(res._poly, self._poly, n, prec(self)) sig_off() return res @@ -713,7 +713,7 @@ cdef class Polynomial_complex_arb(Polynomial): if n < 0: n = 0 sig_on() - acb_poly_gamma_series(res.__poly, self.__poly, n, prec(self)) + acb_poly_gamma_series(res._poly, self._poly, n, prec(self)) sig_off() return res @@ -732,7 +732,7 @@ cdef class Polynomial_complex_arb(Polynomial): if n < 0: n = 0 sig_on() - acb_poly_lgamma_series(res.__poly, self.__poly, n, prec(self)) + acb_poly_lgamma_series(res._poly, self._poly, n, prec(self)) sig_off() return res @@ -751,7 +751,7 @@ cdef class Polynomial_complex_arb(Polynomial): if n < 0: n = 0 sig_on() - acb_poly_rgamma_series(res.__poly, self.__poly, n, prec(self)) + acb_poly_rgamma_series(res._poly, self._poly, n, prec(self)) sig_off() return res @@ -781,7 +781,7 @@ cdef class Polynomial_complex_arb(Polynomial): if n < 0: n = 0 sig_on() - acb_poly_lambertw_series(res.__poly, self.__poly, _branch, 0, n, prec(self)) + acb_poly_lambertw_series(res._poly, self._poly, _branch, 0, n, prec(self)) sig_off() fmpz_clear(_branch) return res @@ -811,7 +811,7 @@ cdef class Polynomial_complex_arb(Polynomial): cdef ComplexBall _a = (self._parent._base.coerce(a)) cdef Polynomial_complex_arb res = self._new() sig_on() - acb_poly_zeta_series(res.__poly, self.__poly, _a.value, deflate, n, prec(self)) + acb_poly_zeta_series(res._poly, self._poly, _a.value, deflate, n, prec(self)) sig_off() return res @@ -843,24 +843,24 @@ cdef class Polynomial_complex_arb(Polynomial): cdef Polynomial_complex_arb res = self._new() cdef acb_poly_t self_ts, other_ts cdef acb_ptr cc - if acb_poly_length(other1.__poly) > 0: - cc = acb_poly_get_coeff_ptr(other1.__poly, 0) + if acb_poly_length(other1._poly) > 0: + cc = acb_poly_get_coeff_ptr(other1._poly, 0) if not acb_is_zero(cc): sig_on() try: acb_poly_init(self_ts) acb_poly_init(other_ts) - acb_poly_taylor_shift(self_ts, self.__poly, cc, prec(self)) - acb_poly_set(other_ts, other1.__poly) + acb_poly_taylor_shift(self_ts, self._poly, cc, prec(self)) + acb_poly_set(other_ts, other1._poly) acb_zero(acb_poly_get_coeff_ptr(other_ts, 0)) - acb_poly_compose_series(res.__poly, self_ts, other_ts, n, prec(self)) + acb_poly_compose_series(res._poly, self_ts, other_ts, n, prec(self)) finally: acb_poly_clear(other_ts) acb_poly_clear(self_ts) sig_off() return res sig_on() - acb_poly_compose_series(res.__poly, self.__poly, other1.__poly, n, prec(self)) + acb_poly_compose_series(res._poly, self._poly, other1._poly, n, prec(self)) sig_off() return res @@ -892,12 +892,12 @@ cdef class Polynomial_complex_arb(Polynomial): cdef Polynomial_complex_arb res = self._new() if n < 0: n = 0 - if not acb_is_zero(acb_poly_get_coeff_ptr(self.__poly, 0)): + if not acb_is_zero(acb_poly_get_coeff_ptr(self._poly, 0)): raise ValueError("the constant coefficient must be zero") - if acb_contains_zero(acb_poly_get_coeff_ptr(self.__poly, 1)): + if acb_contains_zero(acb_poly_get_coeff_ptr(self._poly, 1)): raise ValueError("the linear term must be nonzero") sig_on() - acb_poly_revert_series(res.__poly, self.__poly, n, prec(self)) + acb_poly_revert_series(res._poly, self._poly, n, prec(self)) sig_off() return res @@ -935,15 +935,15 @@ cdef class Polynomial_complex_arb(Polynomial): ball = ComplexBall.__new__(ComplexBall) ball._parent = self._parent._base sig_on() - acb_poly_evaluate(ball.value, self.__poly, + acb_poly_evaluate(ball.value, self._poly, ( point).value, prec(self)) sig_off() return ball elif isinstance(point, Polynomial_complex_arb): poly = ( point)._new() sig_on() - acb_poly_compose(poly.__poly, self.__poly, - ( point).__poly, prec(self)) + acb_poly_compose(poly._poly, self._poly, + ( point)._poly, prec(self)) sig_off() return poly # TODO: perhaps add more special cases, e.g. for real ball, diff --git a/src/sage/rings/polynomial/polynomial_integer_dense_flint.pxd b/src/sage/rings/polynomial/polynomial_integer_dense_flint.pxd index 03c5cebbf09..b1b593d6a26 100644 --- a/src/sage/rings/polynomial/polynomial_integer_dense_flint.pxd +++ b/src/sage/rings/polynomial/polynomial_integer_dense_flint.pxd @@ -5,7 +5,7 @@ from sage.rings.integer cimport Integer from sage.structure.parent cimport Parent cdef class Polynomial_integer_dense_flint(Polynomial): - cdef fmpz_poly_t __poly + cdef fmpz_poly_t _poly cdef Polynomial_integer_dense_flint _new(self) cpdef _unsafe_mutate(self, long n, value) diff --git a/src/sage/rings/polynomial/polynomial_integer_dense_flint.pyx b/src/sage/rings/polynomial/polynomial_integer_dense_flint.pyx index e201ac843ad..194eb9263b2 100644 --- a/src/sage/rings/polynomial/polynomial_integer_dense_flint.pyx +++ b/src/sage/rings/polynomial/polynomial_integer_dense_flint.pyx @@ -99,14 +99,14 @@ cdef class Polynomial_integer_dense_flint(Polynomial): r""" This calls the underlying FLINT fmpz_poly constructor """ - fmpz_poly_init(self.__poly) + fmpz_poly_init(self._poly) def __dealloc__(self): r""" calls the underlying FLINT fmpz_poly destructor """ - fmpz_poly_clear(self.__poly) + fmpz_poly_clear(self._poly) cdef Polynomial_integer_dense_flint _new(self): r""" @@ -139,7 +139,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): x._is_gen = 0 if not isinstance(a, Integer): a = ZZ(a) - fmpz_poly_set_coeff_mpz(x.__poly, 0, (a).value) + fmpz_poly_set_coeff_mpz(x._poly, 0, (a).value) return x def __init__(self, parent, x=None, check=True, is_gen=False, @@ -224,8 +224,8 @@ cdef class Polynomial_integer_dense_flint(Polynomial): if isinstance(x, Polynomial): if x.parent() is self.parent(): sig_on() - fmpz_poly_set(self.__poly, - (x).__poly) + fmpz_poly_set(self._poly, + (x)._poly) sig_off() return else: @@ -246,7 +246,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): degree = i try: sig_on() - fmpz_poly_realloc(self.__poly, degree + 1) + fmpz_poly_realloc(self._poly, degree + 1) sig_off() except RuntimeError: raise OverflowError("Cannot allocate memory!") @@ -255,13 +255,13 @@ cdef class Polynomial_integer_dense_flint(Polynomial): i = ii[0] if type(ii) is tuple else ii if is_small_python_int(a): sig_on() - fmpz_poly_set_coeff_si(self.__poly, i, a) + fmpz_poly_set_coeff_si(self._poly, i, a) sig_off() else: if not isinstance(a, Integer): a = ZZ(a) sig_on() - fmpz_poly_set_coeff_mpz(self.__poly, i, (a).value) + fmpz_poly_set_coeff_mpz(self._poly, i, (a).value) sig_off() return @@ -270,7 +270,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): check = False elif isinstance(x, ntl_ZZX): # coercion from ntl.pyx object - fmpz_poly_set_ZZX(self.__poly, (x).x) + fmpz_poly_set_ZZX(self._poly, (x).x) return elif isinstance(x, FractionFieldElement) and \ @@ -278,8 +278,8 @@ cdef class Polynomial_integer_dense_flint(Polynomial): if x.denominator() == 1: # fraction of the form f(x)/1 sig_on() - fmpz_poly_set(self.__poly, - (x.numerator()).__poly) + fmpz_poly_set(self._poly, + (x.numerator())._poly) sig_off() return @@ -287,19 +287,19 @@ cdef class Polynomial_integer_dense_flint(Polynomial): x = [x] # constant polynomials sig_on() - fmpz_poly_realloc(self.__poly, len(x)) + fmpz_poly_realloc(self._poly, len(x)) sig_off() for i from 0 <= i < len(x): a = x[i] if is_small_python_int(a): sig_on() - fmpz_poly_set_coeff_si(self.__poly, i, a) + fmpz_poly_set_coeff_si(self._poly, i, a) sig_off() else: if not isinstance(a, Integer): a = ZZ(a) sig_on() - fmpz_poly_set_coeff_mpz(self.__poly, i, (a).value) + fmpz_poly_set_coeff_mpz(self._poly, i, (a).value) sig_off() def _eval_mpfr_(self, RealNumber a): @@ -327,7 +327,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): """ cdef RealNumber res = a._new() sig_on() - fmpz_poly_evaluation_mpfr(res.value, self.__poly, a.value) + fmpz_poly_evaluation_mpfr(res.value, self._poly, a.value) sig_off() return res @@ -357,7 +357,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): """ cdef RealIntervalFieldElement res = a._new() sig_on() - fmpz_poly_evaluation_mpfi(res.value, self.__poly, a.value) + fmpz_poly_evaluation_mpfi(res.value, self._poly, a.value) sig_off() return res @@ -412,8 +412,8 @@ cdef class Polynomial_integer_dense_flint(Polynomial): if isinstance(x, Polynomial_integer_dense_flint): f = self._new() sig_on() - fmpz_poly_compose(f.__poly, self.__poly, - ( x0).__poly) + fmpz_poly_compose(f._poly, self._poly, + ( x0)._poly) sig_off() return f if is_small_python_int(x0): @@ -422,7 +422,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): fmpz_init(a_fmpz) fmpz_init(z_fmpz) fmpz_set_si(a_fmpz, PyInt_AS_LONG(x0)) - fmpz_poly_evaluate_fmpz(z_fmpz, self.__poly, a_fmpz) + fmpz_poly_evaluate_fmpz(z_fmpz, self._poly, a_fmpz) fmpz_get_mpz(z.value, z_fmpz) fmpz_clear(a_fmpz) fmpz_clear(z_fmpz) @@ -433,7 +433,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): if isinstance(x0, Integer): a = x0 - if fmpz_poly_length(self.__poly) == 0: + if fmpz_poly_length(self._poly) == 0: return ZZ.zero() if mpz_sgn(a.value) == 0: return self[0] @@ -444,7 +444,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): fmpz_init(a_fmpz) fmpz_init(z_fmpz) fmpz_set_mpz(a_fmpz, a.value) - fmpz_poly_evaluate_fmpz(z_fmpz, self.__poly, a_fmpz) + fmpz_poly_evaluate_fmpz(z_fmpz, self._poly, a_fmpz) fmpz_get_mpz(z.value, z_fmpz) fmpz_clear(a_fmpz) fmpz_clear(z_fmpz) @@ -460,14 +460,14 @@ cdef class Polynomial_integer_dense_flint(Polynomial): arb_a = x0 arb_z = arb_a._new() sig_on() - arb_fmpz_poly_evaluate_arb(arb_z.value, self.__poly, arb_a.value, arb_a._parent._prec) + arb_fmpz_poly_evaluate_arb(arb_z.value, self._poly, arb_a.value, arb_a._parent._prec) sig_off() return arb_z if isinstance(x0, ComplexBall): acb_a = x0 acb_z = acb_a._new() sig_on() - arb_fmpz_poly_evaluate_acb(acb_z.value, self.__poly, acb_a.value, acb_a._parent._prec) + arb_fmpz_poly_evaluate_acb(acb_z.value, self._poly, acb_a.value, acb_a._parent._prec) sig_off() return acb_z @@ -510,10 +510,10 @@ cdef class Polynomial_integer_dense_flint(Polynomial): cdef fmpz_t c fmpz_init(c) - fmpz_poly_get_coeff_fmpz(c, self.__poly, fmpz_poly_degree(self.__poly)) + fmpz_poly_get_coeff_fmpz(c, self._poly, fmpz_poly_degree(self._poly)) cdef int sign = fmpz_sgn(c) - fmpz_poly_content(c, self.__poly) + fmpz_poly_content(c, self._poly) cdef Integer z = Integer.__new__(Integer) fmpz_get_mpz(z.value, c) @@ -561,7 +561,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): 5*x^5 + 4*x^4 + 3*x^3 + 2*x^2 + x + 1 """ cdef Integer z = Integer.__new__(Integer) - fmpz_poly_get_coeff_mpz(z.value, self.__poly, n) + fmpz_poly_get_coeff_mpz(z.value, self._poly, n) return z def _repr(self, name=None, bint latex=False): @@ -583,8 +583,8 @@ cdef class Polynomial_integer_dense_flint(Polynomial): cdef long i cdef Integer coef = Integer.__new__(Integer) cdef list all = [] - for i from fmpz_poly_degree(self.__poly) >= i >= 0: - fmpz_poly_get_coeff_mpz(coef.value, self.__poly, i) + for i from fmpz_poly_degree(self._poly) >= i >= 0: + fmpz_poly_get_coeff_mpz(coef.value, self._poly, i) if coef: if coef > 0: sign_str = '+' @@ -649,8 +649,8 @@ cdef class Polynomial_integer_dense_flint(Polynomial): """ cdef Polynomial_integer_dense_flint x = self._new() sig_on() - fmpz_poly_add(x.__poly, self.__poly, - (right).__poly) + fmpz_poly_add(x._poly, self._poly, + (right)._poly) sig_off() return x @@ -669,8 +669,8 @@ cdef class Polynomial_integer_dense_flint(Polynomial): """ cdef Polynomial_integer_dense_flint x = self._new() sig_on() - fmpz_poly_sub(x.__poly, self.__poly, - (right).__poly) + fmpz_poly_sub(x._poly, self._poly, + (right)._poly) sig_off() return x @@ -688,7 +688,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): """ cdef Polynomial_integer_dense_flint x = self._new() sig_on() - fmpz_poly_neg(x.__poly, self.__poly) + fmpz_poly_neg(x._poly, self._poly) sig_off() return x @@ -758,7 +758,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): cdef Polynomial_integer_dense_flint rr = self._new() sig_on() - fmpz_poly_divrem(qq.__poly, rr.__poly, self.__poly, right.__poly) + fmpz_poly_divrem(qq._poly, rr._poly, self._poly, right._poly) sig_off() return qq, rr @@ -776,7 +776,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): sage: x.is_zero() False """ - return (fmpz_poly_degree(self.__poly) == -1) + return (fmpz_poly_degree(self._poly) == -1) cpdef bint is_one(self) except -1: """ @@ -792,7 +792,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): sage: x.is_one() False """ - return fmpz_poly_is_one(self.__poly) + return fmpz_poly_is_one(self._poly) def __bool__(self): """ @@ -808,7 +808,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): sage: bool(x) True """ - return not (fmpz_poly_degree(self.__poly) == -1) + return not (fmpz_poly_degree(self._poly) == -1) @coerce_binop def gcd(self, right): @@ -831,8 +831,8 @@ cdef class Polynomial_integer_dense_flint(Polynomial): return self cdef Polynomial_integer_dense_flint x = self._new() sig_on() - fmpz_poly_gcd(x.__poly, self.__poly, - (right).__poly) + fmpz_poly_gcd(x._poly, self._poly, + (right)._poly) sig_off() return x @@ -941,8 +941,8 @@ cdef class Polynomial_integer_dense_flint(Polynomial): fmpz_init(r) sig_on() - fmpz_poly_xgcd(r, ss.__poly, tt.__poly, self.__poly, - (right).__poly) + fmpz_poly_xgcd(r, ss._poly, tt._poly, self._poly, + (right)._poly) sig_off() cdef Integer rr = Integer.__new__(Integer) fmpz_get_mpz(rr.value, r) @@ -970,8 +970,8 @@ cdef class Polynomial_integer_dense_flint(Polynomial): """ cdef Polynomial_integer_dense_flint x = self._new() sig_on() - fmpz_poly_mul(x.__poly, self.__poly, - (right).__poly) + fmpz_poly_mul(x._poly, self._poly, + (right)._poly) sig_off() return x @@ -1000,8 +1000,8 @@ cdef class Polynomial_integer_dense_flint(Polynomial): cdef Polynomial_integer_dense_flint x = self._new() sig_on() - fmpz_poly_mullow(x.__poly, self.__poly, - (right).__poly, + fmpz_poly_mullow(x._poly, self._poly, + (right)._poly, n) sig_off() return x @@ -1020,7 +1020,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): """ cdef Polynomial_integer_dense_flint x = self._new() sig_on() - fmpz_poly_scalar_mul_mpz(x.__poly, self.__poly, (right).value) + fmpz_poly_scalar_mul_mpz(x._poly, self._poly, (right).value) sig_off() return x @@ -1038,7 +1038,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): """ cdef Polynomial_integer_dense_flint x = self._new() sig_on() - fmpz_poly_scalar_mul_mpz(x.__poly, self.__poly, (right).value) + fmpz_poly_scalar_mul_mpz(x._poly, self._poly, (right).value) sig_off() return x @@ -1132,7 +1132,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): num = n.numerator() den = n.denominator() - if fmpz_poly_degree(self.__poly) == 0: + if fmpz_poly_degree(self._poly) == 0: return self.parent()(self[0].nth_root(den) ** num) return self.nth_root(den) ** num @@ -1142,7 +1142,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): if self.is_zero(): if nn == 0: - fmpz_poly_set_coeff_si(res.__poly, 0, 1) + fmpz_poly_set_coeff_si(res._poly, 0, 1) return res elif nn < 0: raise ZeroDivisionError("negative exponent in power of zero") @@ -1150,17 +1150,17 @@ cdef class Polynomial_integer_dense_flint(Polynomial): return res if nn < 0: sig_on() - fmpz_poly_pow(res.__poly, self.__poly, -nn) + fmpz_poly_pow(res._poly, self._poly, -nn) sig_off() return ~res else: if self is self._parent.gen(): sig_on() - fmpz_poly_set_coeff_ui(res.__poly, nn, 1) + fmpz_poly_set_coeff_ui(res._poly, nn, 1) sig_off() else: sig_on() - fmpz_poly_pow(res.__poly, self.__poly, nn) + fmpz_poly_pow(res._poly, self._poly, nn) sig_off() return res @@ -1187,7 +1187,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): cdef Polynomial_integer_dense_flint res res = self._new() - fmpz_poly_pow_trunc(res.__poly, self.__poly, n, prec) + fmpz_poly_pow_trunc(res._poly, self._poly, n, prec) return res def __floordiv__(Polynomial_integer_dense_flint self, right): @@ -1226,14 +1226,14 @@ cdef class Polynomial_integer_dense_flint(Polynomial): else: res = self._new() sig_on() - fmpz_poly_scalar_fdiv_mpz(res.__poly, self.__poly, + fmpz_poly_scalar_fdiv_mpz(res._poly, self._poly, ( right).value) sig_off() return res elif right in ZZ: res = self._new() sig_on() - fmpz_poly_scalar_fdiv_mpz(res.__poly, self.__poly, + fmpz_poly_scalar_fdiv_mpz(res._poly, self._poly, (ZZ(right)).value) sig_off() return res @@ -1248,7 +1248,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): else: res = self._new() sig_on() - fmpz_poly_div(res.__poly, self.__poly, _right.__poly) + fmpz_poly_div(res._poly, self._poly, _right._poly) sig_off() return res @@ -1293,9 +1293,9 @@ cdef class Polynomial_integer_dense_flint(Polynomial): if prec <= 0: raise ValueError("the precision must be positive, got {}".format(prec)) - if fmpz_poly_degree(self.__poly) == -1: + if fmpz_poly_degree(self._poly) == -1: raise ValueError("constant term is zero") - cdef fmpz_t c = fmpz_poly_get_coeff_ptr(self.__poly, 0) + cdef fmpz_t c = fmpz_poly_get_coeff_ptr(self._poly, 0) if fmpz_cmp_si(c, 1) and fmpz_cmp_si(c, -1): raise ValueError("constant term {} is not a unit".format(self[0])) @@ -1303,7 +1303,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): if prec <= 0: return res sig_on() - fmpz_poly_inv_series(res.__poly, self.__poly, prec) + fmpz_poly_inv_series(res._poly, self._poly, prec) sig_off() return res @@ -1331,16 +1331,16 @@ cdef class Polynomial_integer_dense_flint(Polynomial): raise IndexError("n must be >= 0") if isinstance(value, int): sig_on() - fmpz_poly_set_coeff_si(self.__poly, n, value) + fmpz_poly_set_coeff_si(self._poly, n, value) sig_off() elif isinstance(value, Integer): sig_on() - fmpz_poly_set_coeff_mpz(self.__poly, n, (value).value) + fmpz_poly_set_coeff_mpz(self._poly, n, (value).value) sig_off() else: value = Integer(value) sig_on() - fmpz_poly_set_coeff_mpz(self.__poly, n, (value).value) + fmpz_poly_set_coeff_mpz(self._poly, n, (value).value) sig_off() def real_root_intervals(self): @@ -1364,7 +1364,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): ## def __copy__(self): ## f = Polynomial_integer_dense(self.parent()) -## f.__poly = self.__poly.copy() +## f._poly = self._poly.copy() ## return f @@ -1391,7 +1391,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): sage: type(x.degree()) """ - return smallInteger(fmpz_poly_degree(self.__poly)) + return smallInteger(fmpz_poly_degree(self._poly)) def pseudo_divrem(self, B): r""" @@ -1426,7 +1426,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): """ cdef Polynomial_integer_dense_flint Q = self._new(), R = self._new(), _B = B cdef ulong d - fmpz_poly_pseudo_divrem(Q.__poly, R.__poly, &d, self.__poly, _B.__poly) + fmpz_poly_pseudo_divrem(Q._poly, R._poly, &d, self._poly, _B._poly) return Q, R, Integer(d) def discriminant(self, proof=True): @@ -1460,7 +1460,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): """ cdef ZZX_c ntl_poly cdef ZZ_c* temp - fmpz_poly_get_ZZX(ntl_poly, self.__poly) + fmpz_poly_get_ZZX(ntl_poly, self._poly) temp = ZZX_discriminant(&ntl_poly, proof) cdef Integer x = Integer.__new__(Integer) @@ -1531,12 +1531,12 @@ cdef class Polynomial_integer_dense_flint(Polynomial): # the primitive part returned by FLINT has positive leading # coefficient - fmpz_poly_primitive_part(ppart, self.__poly) + fmpz_poly_primitive_part(ppart, self._poly) fmpz_poly_get_ZZX(ntl_poly, ppart) fmpz_poly_clear(ppart) else: - fmpz_poly_get_ZZX(ntl_poly, self.__poly) + fmpz_poly_get_ZZX(ntl_poly, self._poly) # input is primitive, with positive leading coefficient ZZX_squarefree_decomposition(&v, &e, &n, &ntl_poly) @@ -1544,7 +1544,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): F = [] for i from 0 <= i < n: fac = self._new() - fmpz_poly_set_ZZX(fac.__poly, v[i][0]) + fmpz_poly_set_ZZX(fac._poly, v[i][0]) F.append( (fac,e[i]) ) del v[i] sig_free(v) @@ -1582,9 +1582,9 @@ cdef class Polynomial_integer_dense_flint(Polynomial): cdef ZZ_c content cdef vec_pair_ZZX_long_c factors cdef long i - cdef int sig_me = fmpz_poly_degree(self.__poly) + cdef int sig_me = fmpz_poly_degree(self._poly) - fmpz_poly_get_ZZX(ntl_poly, self.__poly) + fmpz_poly_get_ZZX(ntl_poly, self._poly) if sig_me > 10: sig_on() @@ -1603,13 +1603,13 @@ cdef class Polynomial_integer_dense_flint(Polynomial): fac_py = self._new() fmpz_init(tcontent) fmpz_set_ZZ(tcontent, content) - fmpz_poly_set_coeff_fmpz(fac_py.__poly, 0, tcontent) + fmpz_poly_set_coeff_fmpz(fac_py._poly, 0, tcontent) results.append( (fac_py,1) ) fmpz_clear(tcontent) for i from 0 <= i < factors.length(): fac_py = self._new() - fmpz_poly_set_ZZX(fac_py.__poly, factors.RawGet(i).a) + fmpz_poly_set_ZZX(fac_py._poly, factors.RawGet(i).a) results.append( (fac_py,factors.RawGet(i).b) ) return Factorization(results, unit = unit) @@ -1639,7 +1639,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): (-1) * 2 * 3 * 5 * x """ cdef int i - cdef long deg = fmpz_poly_degree(self.__poly) + cdef long deg = fmpz_poly_degree(self._poly) # it appears that pari has a window from about degrees 30 and 300 # in which it beats NTL. c = self.content() @@ -1783,8 +1783,8 @@ cdef class Polynomial_integer_dense_flint(Polynomial): cdef Integer x = Integer.__new__(Integer) sig_on() - fmpz_poly_resultant(res, self.__poly, - (other).__poly) + fmpz_poly_resultant(res, self._poly, + (other)._poly) sig_off() fmpz_get_mpz(x.value, res) fmpz_clear(res) @@ -1830,10 +1830,10 @@ cdef class Polynomial_integer_dense_flint(Polynomial): if d != degree: raise ValueError("degree argument must be a non-negative integer, got %s" % degree) # FLINT expects length - fmpz_poly_reverse(res.__poly, self.__poly, d+1) + fmpz_poly_reverse(res._poly, self._poly, d+1) else: - fmpz_poly_reverse(res.__poly, self.__poly, - fmpz_poly_length(self.__poly)) + fmpz_poly_reverse(res._poly, self._poly, + fmpz_poly_length(self._poly)) return res def revert_series(self, n): @@ -1867,7 +1867,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): raise ValueError("self must have constant coefficient 0 and a unit for coefficient {}^1".format(self.parent().gen())) sig_on() - fmpz_poly_revert_series(res.__poly, self.__poly, m) + fmpz_poly_revert_series(res._poly, self._poly, m) sig_off() return res diff --git a/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pxd b/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pxd index a7c380b49a2..fcd907e1abe 100644 --- a/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pxd +++ b/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pxd @@ -2,6 +2,6 @@ from sage.libs.ntl.types cimport ZZX_c from sage.rings.polynomial.polynomial_element cimport Polynomial cdef class Polynomial_integer_dense_ntl(Polynomial): - cdef ZZX_c __poly + cdef ZZX_c _poly cdef Polynomial_integer_dense_ntl _new(self) diff --git a/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx b/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx index e7b708bbc51..80a1726bb4e 100644 --- a/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx +++ b/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx @@ -172,7 +172,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): if isinstance(x, Polynomial): if x.parent() is self.parent(): # copy with NTL assignment operator - self.__poly = (x).__poly + self._poly = (x)._poly return else: # coerce coefficients into Sage integers @@ -191,17 +191,17 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): degree = i if degree >= NTL_OVFBND: raise OverflowError("Dense NTL integer polynomials have a maximum degree of %s" % (NTL_OVFBND-1)) - ZZX_SetCoeff_long(self.__poly, degree, 1) + ZZX_SetCoeff_long(self._poly, degree, 1) # now fill them in for ii, a in x: i = ii[0] if type(ii) is tuple else ii if type(a) is int: - ZZX_SetCoeff_long(self.__poly, i, a) + ZZX_SetCoeff_long(self._poly, i, a) else: if not isinstance(a, Integer): a = ZZ(a) mpz_to_ZZ(&y, (a).value) - ZZX_SetCoeff(self.__poly, i, y) + ZZX_SetCoeff(self._poly, i, y) return elif isinstance(x, pari_gen): @@ -210,14 +210,14 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): elif isinstance(x, ntl_ZZX): # coercion from ntl.pyx object # copy with NTL assignment operator - self.__poly = (x).x + self._poly = (x).x return elif isinstance(x, FractionFieldElement) and \ isinstance(x.numerator(), Polynomial_integer_dense_ntl): if x.denominator() == 1: # fraction of the form f(x)/1 - self.__poly = (x.numerator()).__poly + self._poly = (x.numerator())._poly return elif not isinstance(x, (list, tuple)): @@ -229,12 +229,12 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): for i from 0 <= i < len(x): a = x[i] if type(a) is int: - ZZX_SetCoeff_long(self.__poly, i, a) + ZZX_SetCoeff_long(self._poly, i, a) else: if not isinstance(a, Integer): a = ZZ(a) mpz_to_ZZ(&y, (a).value) - ZZX_SetCoeff(self.__poly, i, y) + ZZX_SetCoeff(self._poly, i, y) def content(self): @@ -259,7 +259,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): """ cdef ZZ_c y cdef Integer z = Integer.__new__(Integer) - ZZX_content(y, self.__poly) + ZZX_content(y, self._poly) ZZ_to_mpz(z.value, &y) return z @@ -288,7 +288,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): """ cdef RealNumber res = a._new() sig_on() - ZZX_evaluation_mpfr(res.value, self.__poly, a.value) + ZZX_evaluation_mpfr(res.value, self._poly, a.value) sig_off() return res @@ -318,7 +318,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): """ cdef RealIntervalFieldElement res = a._new() sig_on() - ZZX_evaluation_mpfi(res.value, self.__poly, a.value) + ZZX_evaluation_mpfi(res.value, self._poly, a.value) sig_off() return res @@ -363,7 +363,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): 5*x^5 + 4*x^4 + 3*x^3 + 2*x^2 + x + 1 """ cdef Integer z = Integer.__new__(Integer) - ZZ_to_mpz(z.value, &self.__poly.rep.elts()[n]) + ZZ_to_mpz(z.value, &self._poly.rep.elts()[n]) return z def _repr(self, name=None, bint latex=False): @@ -380,15 +380,15 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): name = self.parent().variable_name() cdef long i cdef list all = [] - for i from ZZX_deg(self.__poly) >= i >= 0: - sign = ZZ_sign(ZZX_coeff(self.__poly, i)) + for i from ZZX_deg(self._poly) >= i >= 0: + sign = ZZ_sign(ZZX_coeff(self._poly, i)) if sign: if sign > 0: sign_str = '+' - coeff_str = ccrepr(self.__poly.rep.elts()[i]) + coeff_str = ccrepr(self._poly.rep.elts()[i]) else: sign_str = '-' - coeff_str = ccrepr(self.__poly.rep.elts()[i])[1:] + coeff_str = ccrepr(self._poly.rep.elts()[i])[1:] if i > 0: if coeff_str == '1': coeff_str = '' @@ -441,8 +441,8 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): -3*x^2 + 2*x + 7 """ cdef Polynomial_integer_dense_ntl x = self._new() - ZZX_add(x.__poly, self.__poly, - (right).__poly) + ZZX_add(x._poly, self._poly, + (right)._poly) return x @@ -459,8 +459,8 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): 3*x^2 + 2*x - 5 """ cdef Polynomial_integer_dense_ntl x = self._new() - ZZX_sub(x.__poly, self.__poly, - (right).__poly) + ZZX_sub(x._poly, self._poly, + (right)._poly) return x @@ -476,7 +476,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): -2*x + 1 """ cdef Polynomial_integer_dense_ntl x = self._new() - ZZX_negate(x.__poly, self.__poly) + ZZX_negate(x._poly, self._poly) return x @@ -533,10 +533,10 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): """ cdef Polynomial_integer_dense_ntl _right = right - if ZZX_IsZero(_right.__poly): + if ZZX_IsZero(_right._poly): raise ArithmeticError("division by zero polynomial") - if ZZX_IsZero(self.__poly): + if ZZX_IsZero(self._poly): return self, self cdef ZZX_c *q @@ -545,19 +545,19 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): cdef Polynomial_integer_dense_ntl rr = self._new() cdef int divisible - if ZZ_IsOne(ZZX_LeadCoeff(_right.__poly)): + if ZZ_IsOne(ZZX_LeadCoeff(_right._poly)): # divisor is monic. Just do the division and remainder - ZZX_quo_rem(&self.__poly, &_right.__poly, &r, &q) - ZZX_swap(qq.__poly, q[0]) - ZZX_swap(rr.__poly, r[0]) + ZZX_quo_rem(&self._poly, &_right._poly, &r, &q) + ZZX_swap(qq._poly, q[0]) + ZZX_swap(rr._poly, r[0]) del q del r else: # Non-monic divisor. Check whether it divides exactly. - q = ZZX_div(&self.__poly, &_right.__poly, &divisible) + q = ZZX_div(&self._poly, &_right._poly, &divisible) if divisible: # exactly divisible - ZZX_swap(q[0], qq.__poly) + ZZX_swap(q[0], qq._poly) del q else: # division failed: clean up and raise exception @@ -584,8 +584,8 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): """ # todo: we're doing an unnecessary copy here cdef Polynomial_integer_dense_ntl x = self._new() - cdef ZZX_c* temp = ZZX_gcd(&self.__poly, &(right).__poly) - x.__poly = temp[0] + cdef ZZX_c* temp = ZZX_gcd(&self._poly, &(right)._poly) + x._poly = temp[0] del temp return x @@ -658,13 +658,13 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): cdef ZZX_c *t cdef ZZ_c *r - ZZX_xgcd(&self.__poly, &(right).__poly, &r, &s, &t, 1) # proof = 1 + ZZX_xgcd(&self._poly, &(right)._poly, &r, &s, &t, 1) # proof = 1 cdef Integer rr = Integer.__new__(Integer) ZZ_to_mpz(rr.value, r) cdef Polynomial_integer_dense_ntl ss = self._new() cdef Polynomial_integer_dense_ntl tt = self._new() - ss.__poly = s[0] - tt.__poly = t[0] + ss._poly = s[0] + tt._poly = t[0] del r del s del t @@ -691,8 +691,8 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): x^3 - 10*x^2 + 32*x - 32 """ cdef Polynomial_integer_dense_ntl x = self._new() - ZZX_mul(x.__poly, self.__poly, - (right).__poly) + ZZX_mul(x._poly, self._poly, + (right)._poly) return x cpdef _lmul_(self, Element right): @@ -711,7 +711,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): cdef ZZ_c _right mpz_to_ZZ(&_right, (right).value) - ZZX_mul_ZZ(x.__poly, self.__poly, _right) + ZZX_mul_ZZ(x._poly, self._poly, _right) return x cpdef _rmul_(self, Element right): @@ -730,7 +730,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): cdef ZZ_c _right mpz_to_ZZ(&_right, (right).value) - ZZX_mul_ZZ(x.__poly, self.__poly, _right) + ZZX_mul_ZZ(x._poly, self._poly, _right) return x @@ -783,7 +783,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): value = Integer(value) cdef ZZ_c y mpz_to_ZZ(&y, (value).value) - ZZX_SetCoeff(self.__poly, n, y) + ZZX_SetCoeff(self._poly, n, y) def real_root_intervals(self): @@ -805,7 +805,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): ## def __copy__(self): ## f = Polynomial_integer_dense(self.parent()) -## f.__poly = self.__poly.copy() +## f._poly = self._poly.copy() ## return f @@ -826,7 +826,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): sage: R(0).degree() -1 """ - return ZZX_deg(self.__poly) + return ZZX_deg(self._poly) def discriminant(self, proof=True): r""" @@ -849,7 +849,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): sage: f.discriminant(proof=False) -339 """ - cdef ZZ_c* temp = ZZX_discriminant(&self.__poly, proof) + cdef ZZ_c* temp = ZZX_discriminant(&self._poly, proof) cdef Integer x = Integer.__new__(Integer) ZZ_to_mpz(x.value, temp) del temp @@ -904,11 +904,11 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): cdef long* e cdef long i, n cdef Polynomial_integer_dense_ntl z - ZZX_squarefree_decomposition(&v, &e, &n, &p.__poly) + ZZX_squarefree_decomposition(&v, &e, &n, &p._poly) F = [] for i from 0 <= i < n: z = self._new() - z.__poly = v[i][0] + z._poly = v[i][0] F.append((z, e[i])) del v[i] sig_free(v) @@ -950,24 +950,24 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): cdef ZZ_c content cdef vec_pair_ZZX_long_c factors cdef long i - cdef int sig_me = ZZX_deg(self.__poly) + cdef int sig_me = ZZX_deg(self._poly) if sig_me > 10: sig_on() - ZZX_factor(content, factors, self.__poly, 0, 0) + ZZX_factor(content, factors, self._poly, 0, 0) if sig_me > 10: sig_off() results = [] unit = None if not ZZ_IsOne(content): fac_py = self._new() - ZZX_SetCoeff(fac_py.__poly, 0, content) - if ZZX_deg(fac_py.__poly) == 0 and ZZ_to_int(fac_py.__poly.rep.elts())==-1: + ZZX_SetCoeff(fac_py._poly, 0, content) + if ZZX_deg(fac_py._poly) == 0 and ZZ_to_int(fac_py._poly.rep.elts())==-1: unit = fac_py else: results.append( (fac_py,1) ) for i from 0 <= i < factors.length(): fac_py = self._new() - fac_py.__poly = factors.RawGet(i).a + fac_py._poly = factors.RawGet(i).a results.append( (fac_py,factors.RawGet(i).b) ) return Factorization(results, unit = unit) @@ -996,7 +996,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): sage: f = -30*x; f.factor() (-1) * 2 * 3 * 5 * x """ - cdef int deg = ZZX_deg(self.__poly) + cdef int deg = ZZX_deg(self._poly) # it appears that pari has a window from about degrees 30 and 300 # in which it beats NTL. c = self.content() @@ -1131,7 +1131,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): True """ cdef Polynomial_integer_dense_ntl _other = (self.parent().coerce(other)) - cdef ZZ_c* temp = ZZX_resultant(&self.__poly, &_other.__poly, proof) + cdef ZZ_c* temp = ZZX_resultant(&self._poly, &_other._poly, proof) cdef Integer x = Integer.__new__(Integer) ZZ_to_mpz(x.value, temp) del temp diff --git a/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pxd b/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pxd index 264f05f3c0d..6934acfee8d 100644 --- a/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pxd +++ b/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pxd @@ -16,7 +16,7 @@ from sage.libs.ntl.lzz_pX cimport * cdef class Polynomial_dense_mod_n(Polynomial): - cdef object __poly + cdef object _poly cdef object __singular cdef class Polynomial_dense_modn_ntl_zz(Polynomial_dense_mod_n): diff --git a/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx b/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx index fd03ece69d6..c1c0dc05f59 100644 --- a/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx +++ b/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx @@ -105,19 +105,19 @@ cdef class Polynomial_dense_mod_n(Polynomial): if construct: if isinstance(x, ZZ_pX): - self.__poly = x + self._poly = x return - self.__poly = ZZ_pX(x, parent.modulus()) + self._poly = ZZ_pX(x, parent.modulus()) return - self.__poly = ZZ_pX([], parent.modulus()) + self._poly = ZZ_pX([], parent.modulus()) if x is None: return # leave initialized to 0 polynomial. if isinstance(x, Polynomial): if x.parent() == self.parent(): - self.__poly = (x).__poly.__copy__() + self._poly = (x)._poly.__copy__() return else: R = parent.base_ring() @@ -130,7 +130,7 @@ cdef class Polynomial_dense_mod_n(Polynomial): elif isinstance(x, ZZX): - self.__poly = x.copy() + self._poly = x.copy() return elif isinstance(x, pari_gen): @@ -142,7 +142,7 @@ cdef class Polynomial_dense_mod_n(Polynomial): if x.denominator().is_unit(): numer = x.numerator() denom = x.denominator().inverse_of_unit() - x = numer.__poly * denom.__poly + x = numer._poly * denom._poly check = False else: raise TypeError("Denominator not a unit.") @@ -154,13 +154,13 @@ cdef class Polynomial_dense_mod_n(Polynomial): R = parent.base_ring() x = [ZZ(R(a)) for a in x] - self.__poly = ZZ_pX(x, parent.modulus()) + self._poly = ZZ_pX(x, parent.modulus()) def __reduce__(self): return make_element, (self.parent(), (self.list(), False, self.is_gen())) def int_list(self): - return eval(str(self.__poly).replace(' ',',')) + return eval(str(self._poly).replace(' ',',')) def __pari__(self, variable=None): """ @@ -186,7 +186,7 @@ cdef class Polynomial_dense_mod_n(Polynomial): You must call ``ntl.set_modulus(ntl.ZZ(n))`` before doing arithmetic with this object! """ - return self.__poly + return self._poly cdef get_unsafe(self, Py_ssize_t n): """ @@ -203,13 +203,13 @@ cdef class Polynomial_dense_mod_n(Polynomial): sage: f[:3] 13*x^2 + 10*x + 5 """ - return self._parent._base(( self.__poly)[n]._integer_()) + return self._parent._base(( self._poly)[n]._integer_()) def _unsafe_mutate(self, n, value): n = int(n) if n < 0: raise IndexError("n must be >= 0") - self.__poly[n] = int(value) + self._poly[n] = int(value) def _pow(self, n): n = int(n) @@ -218,10 +218,10 @@ cdef class Polynomial_dense_mod_n(Polynomial): return self.parent()(self[0]**n) if n < 0: return (~self)**(-n) - return self.parent()(self.__poly**n, construct=True) + return self.parent()(self._poly**n, construct=True) cpdef _add_(self, right): - return self.parent()(self.__poly + (right).__poly, construct=True) + return self.parent()(self._poly + (right)._poly, construct=True) cpdef _mul_(self, right): """ @@ -231,11 +231,11 @@ cdef class Polynomial_dense_mod_n(Polynomial): sage: (x - 2)*(x^2 - 8*x + 16) x^3 + 90*x^2 + 32*x + 68 """ - return self.parent()(self.__poly * (right).__poly, construct=True) + return self.parent()(self._poly * (right)._poly, construct=True) cpdef _lmul_(self, Element c): try: - return self.parent()(ZZ_pX([c], self.parent().modulus()) * self.__poly, construct=True) + return self.parent()(ZZ_pX([c], self.parent().modulus()) * self._poly, construct=True) except RuntimeError as msg: # should this really be a TypeError raise TypeError(msg) @@ -245,7 +245,7 @@ cdef class Polynomial_dense_mod_n(Polynomial): Return a tuple ``(quotient, remainder)`` where ``self = quotient*other + remainder``. """ - v = self.__poly.quo_rem((right).__poly) + v = self._poly.quo_rem((right)._poly) P = self.parent() return (P(v[0], construct=True), P(v[1], construct=True) ) @@ -281,11 +281,11 @@ cdef class Polynomial_dense_mod_n(Polynomial): """ if n == 0 or self.degree() < 0: return self - return self.parent()(self.__poly.left_shift(n), + return self.parent()(self._poly.left_shift(n), construct=True) cpdef _sub_(self, right): - return self.parent()(self.__poly - (right).__poly, construct=True) + return self.parent()(self._poly - (right)._poly, construct=True) def __floordiv__(self, right): q, _ = self.quo_rem(right) @@ -314,7 +314,7 @@ cdef class Polynomial_dense_mod_n(Polynomial): sage: isinstance(x.degree(), Integer) True """ - return smallInteger(max(self.__poly.degree(), -1)) + return smallInteger(max(self._poly.degree(), -1)) cpdef list list(self, bint copy=True): """ @@ -358,7 +358,7 @@ cdef class Polynomial_dense_mod_n(Polynomial): """ if self.is_gen(): raise TypeError("Cannot change the value of the generator.") - self.__poly = ZZ_pX(v, self.parent().modulus()) + self._poly = ZZ_pX(v, self.parent().modulus()) # Polynomial_singular_repr stuff, copied due to lack of multiple inheritance def _singular_(self, singular=singular_default, force=False): @@ -654,8 +654,8 @@ cdef class Polynomial_dense_modn_ntl_zz(Polynomial_dense_mod_n): return Polynomial_dense_mod_n.__init__(self, parent, v, check=check, is_gen=is_gen, construct=construct) - v = [a for a in self.__poly.list()] - self.__poly = None # this will eventually go away + v = [a for a in self._poly.list()] + self._poly = None # this will eventually go away cdef ntl_zz_pX ntl = ntl_zz_pX(v, parent.modulus()) # let it handle the hard work self.x = ntl.x self.c = ntl.c @@ -668,8 +668,8 @@ cdef class Polynomial_dense_modn_ntl_zz(Polynomial_dense_mod_n): # TODO: Get rid of this Polynomial_dense_mod_n.ntl_set_directly(self, v) # verbatim from __init__ - v = [int(a) for a in self.__poly.list()] - self.__poly = None # this will eventually go away + v = [int(a) for a in self._poly.list()] + self._poly = None # this will eventually go away cdef ntl_zz_pX ntl = ntl_zz_pX(v, self._parent.modulus()) # let it handle the hard work self.x = ntl.x self.c = ntl.c @@ -1241,8 +1241,8 @@ cdef class Polynomial_dense_modn_ntl_ZZ(Polynomial_dense_mod_n): return Polynomial_dense_mod_n.__init__(self, parent, v, check=check, is_gen=is_gen, construct=construct) - cdef ntl_ZZ_pX ntl = self.__poly - self.__poly = None # this will eventually go away + cdef ntl_ZZ_pX ntl = self._poly + self._poly = None # this will eventually go away self.x = ntl.x self.c = ntl.c diff --git a/src/sage/rings/polynomial/polynomial_rational_flint.pxd b/src/sage/rings/polynomial/polynomial_rational_flint.pxd index 055d7842668..f4644f19d04 100644 --- a/src/sage/rings/polynomial/polynomial_rational_flint.pxd +++ b/src/sage/rings/polynomial/polynomial_rational_flint.pxd @@ -11,7 +11,7 @@ from sage.libs.flint.types cimport fmpq_poly_t from sage.rings.polynomial.polynomial_element cimport Polynomial cdef class Polynomial_rational_flint(Polynomial): - cdef fmpq_poly_t __poly + cdef fmpq_poly_t _poly cdef Polynomial_rational_flint _new(self) cpdef _mod_(self, right) diff --git a/src/sage/rings/polynomial/polynomial_rational_flint.pyx b/src/sage/rings/polynomial/polynomial_rational_flint.pyx index 8dbe789a410..f851fd20c7d 100644 --- a/src/sage/rings/polynomial/polynomial_rational_flint.pyx +++ b/src/sage/rings/polynomial/polynomial_rational_flint.pyx @@ -155,16 +155,16 @@ cdef class Polynomial_rational_flint(Polynomial): res._parent = P res._is_gen = 0 if isinstance(x, int): - fmpq_poly_set_si(res.__poly, x) + fmpq_poly_set_si(res._poly, x) elif isinstance(x, Integer): - fmpq_poly_set_mpz(res.__poly, ( x).value) + fmpq_poly_set_mpz(res._poly, ( x).value) elif isinstance(x, Rational): - fmpq_poly_set_mpq(res.__poly, ( x).value) + fmpq_poly_set_mpq(res._poly, ( x).value) else: - fmpq_poly_set_si(res.__poly, int(x)) + fmpq_poly_set_si(res._poly, int(x)) return res @@ -177,7 +177,7 @@ cdef class Polynomial_rational_flint(Polynomial): sage: R. = QQ[] sage: f = 2/3 * t - 7 #indirect doctest """ - fmpq_poly_init(self.__poly) + fmpq_poly_init(self._poly) def __dealloc__(self): """ @@ -189,7 +189,7 @@ cdef class Polynomial_rational_flint(Polynomial): sage: f = 1/3 * t sage: del f """ - fmpq_poly_clear(self.__poly) + fmpq_poly_clear(self._poly) def __init__(self, parent, x=None, check=True, is_gen=False, construct=False): """ @@ -227,19 +227,19 @@ cdef class Polynomial_rational_flint(Polynomial): Polynomial.__init__(self, parent, is_gen=is_gen) if is_gen: - fmpq_poly_set_coeff_si(self.__poly, 1, 1) + fmpq_poly_set_coeff_si(self._poly, 1, 1) elif isinstance(x, Polynomial_rational_flint): - fmpq_poly_set(self.__poly, ( x).__poly) + fmpq_poly_set(self._poly, ( x)._poly) elif isinstance(x, int): - fmpq_poly_set_si(self.__poly, x) + fmpq_poly_set_si(self._poly, x) elif isinstance(x, Integer): - fmpq_poly_set_mpz(self.__poly, ( x).value) + fmpq_poly_set_mpz(self._poly, ( x).value) elif isinstance(x, Rational): - fmpq_poly_set_mpq(self.__poly, ( x).value) + fmpq_poly_set_mpq(self._poly, ( x).value) elif isinstance(x, list) or isinstance(x, tuple): @@ -257,7 +257,7 @@ cdef class Polynomial_rational_flint(Polynomial): for deg from 0 <= deg < n: mpq_init(L2[deg]) mpq_set(L2[deg], ( L1[deg]).value) - fmpq_poly_set_array_mpq(self.__poly, L2, n) + fmpq_poly_set_array_mpq(self._poly, L2, n) for deg from 0 <= deg < n: mpq_clear(L2[deg]) sig_free(L2) @@ -266,13 +266,13 @@ cdef class Polynomial_rational_flint(Polynomial): # deg = 0 # for e in x: # c = Rational(e) -# fmpq_poly_set_coeff_mpq(self.__poly, deg, c.value) +# fmpq_poly_set_coeff_mpq(self._poly, deg, c.value) # deg += 1 elif isinstance(x, dict): for deg, e in x.iteritems(): c = Rational(e) - fmpq_poly_set_coeff_mpq(self.__poly, deg, c.value) + fmpq_poly_set_coeff_mpq(self._poly, deg, c.value) elif isinstance(x, pari_gen): k = self._parent.base_ring() @@ -281,7 +281,7 @@ cdef class Polynomial_rational_flint(Polynomial): is_gen=False, construct=construct) elif isinstance(x, Polynomial_integer_dense_flint): - fmpq_poly_set_fmpz_poly(self.__poly, (x).__poly) + fmpq_poly_set_fmpz_poly(self._poly, (x)._poly) elif isinstance(x, Polynomial): k = self._parent.base_ring() @@ -329,7 +329,7 @@ cdef class Polynomial_rational_flint(Polynomial): True """ cdef Polynomial_rational_flint res = self._new() - fmpq_poly_set(res.__poly, self.__poly) + fmpq_poly_set(res._poly, self._poly) return res def _singular_(self, singular=singular_default): @@ -364,7 +364,7 @@ cdef class Polynomial_rational_flint(Polynomial): sage: g.list() [] """ - cdef unsigned long length = fmpq_poly_length(self.__poly) + cdef unsigned long length = fmpq_poly_length(self._poly) return [self.get_unsafe(n) for n in range(length)] ########################################################################### @@ -392,7 +392,7 @@ cdef class Polynomial_rational_flint(Polynomial): sage: type(f.degree()) """ - return smallInteger(fmpq_poly_degree(self.__poly)) + return smallInteger(fmpq_poly_degree(self._poly)) cdef get_unsafe(self, Py_ssize_t n): """ @@ -413,7 +413,7 @@ cdef class Polynomial_rational_flint(Polynomial): 1/2*t^2 + t + 1 """ cdef Rational z = Rational.__new__(Rational) - fmpq_poly_get_coeff_mpq(z.value, self.__poly, n) + fmpq_poly_get_coeff_mpq(z.value, self._poly, n) return z cpdef _unsafe_mutate(self, unsigned long n, value): @@ -434,24 +434,24 @@ cdef class Polynomial_rational_flint(Polynomial): rely on this convention. This method should be used only with the utmost care. """ - cdef bint do_sig = _do_sig(self.__poly) + cdef bint do_sig = _do_sig(self._poly) if isinstance(value, int): if do_sig: sig_str("FLINT exception") - fmpq_poly_set_coeff_si(self.__poly, n, value) + fmpq_poly_set_coeff_si(self._poly, n, value) if do_sig: sig_off() elif isinstance(value, Integer): if do_sig: sig_str("FLINT exception") - fmpq_poly_set_coeff_mpz(self.__poly, n, ( value).value) + fmpq_poly_set_coeff_mpz(self._poly, n, ( value).value) if do_sig: sig_off() elif isinstance(value, Rational): if do_sig: sig_str("FLINT exception") - fmpq_poly_set_coeff_mpq(self.__poly, n, ( value).value) + fmpq_poly_set_coeff_mpq(self._poly, n, ( value).value) if do_sig: sig_off() else: value = Rational(value) if do_sig: sig_str("FLINT exception") - fmpq_poly_set_coeff_mpq(self.__poly, n, ( value).value) + fmpq_poly_set_coeff_mpq(self._poly, n, ( value).value) if do_sig: sig_off() def __call__(self, *x, **kwds): @@ -501,20 +501,20 @@ cdef class Polynomial_rational_flint(Polynomial): if isinstance(a, Polynomial_rational_flint): f = ( a)._new() sig_str("FLINT exception") - fmpq_poly_compose(f.__poly, self.__poly, - ( a).__poly) + fmpq_poly_compose(f._poly, self._poly, + ( a)._poly) sig_off() return f elif isinstance(a, Rational): r = Rational.__new__(Rational) sig_str("FLINT exception") - fmpq_poly_evaluate_mpq(r.value, self.__poly, ( a).value) + fmpq_poly_evaluate_mpq(r.value, self._poly, ( a).value) sig_off() return r elif isinstance(a, Integer): r = Rational.__new__(Rational) sig_str("FLINT exception") - fmpq_poly_evaluate_mpz(r.value, self.__poly, ( a).value) + fmpq_poly_evaluate_mpz(r.value, self._poly, ( a).value) sig_off() return r elif isinstance(a, int): @@ -523,7 +523,7 @@ cdef class Polynomial_rational_flint(Polynomial): fmpz_init(tmpfz) fmpq_init(tmpfq) fmpz_set_si(tmpfz, PyInt_AS_LONG(a)) - fmpq_poly_evaluate_fmpz(tmpfq, self.__poly, tmpfz) + fmpq_poly_evaluate_fmpz(tmpfq, self._poly, tmpfz) fmpq_get_mpq(r.value, tmpfq) fmpq_clear(tmpfq) fmpz_clear(tmpfz) @@ -533,18 +533,18 @@ cdef class Polynomial_rational_flint(Polynomial): arb_a = a arb_z = arb_a._new() sig_on() - _arb_fmpz_poly_evaluate_arb(arb_z.value, fmpq_poly_numref(self.__poly), - fmpq_poly_length(self.__poly), arb_a.value, arb_a._parent._prec) - arb_div_fmpz(arb_z.value, arb_z.value, fmpq_poly_denref(self.__poly), arb_a._parent._prec) + _arb_fmpz_poly_evaluate_arb(arb_z.value, fmpq_poly_numref(self._poly), + fmpq_poly_length(self._poly), arb_a.value, arb_a._parent._prec) + arb_div_fmpz(arb_z.value, arb_z.value, fmpq_poly_denref(self._poly), arb_a._parent._prec) sig_off() return arb_z if isinstance(a, ComplexBall): acb_a = a acb_z = acb_a._new() sig_on() - _arb_fmpz_poly_evaluate_acb(acb_z.value, fmpq_poly_numref(self.__poly), - fmpq_poly_length(self.__poly), acb_a.value, acb_a._parent._prec) - acb_div_fmpz(acb_z.value, acb_z.value, fmpq_poly_denref(self.__poly), acb_a._parent._prec) + _arb_fmpz_poly_evaluate_acb(acb_z.value, fmpq_poly_numref(self._poly), + fmpq_poly_length(self._poly), acb_a.value, acb_a._parent._prec) + acb_div_fmpz(acb_z.value, acb_z.value, fmpq_poly_denref(self._poly), acb_a._parent._prec) sig_off() return acb_z @@ -570,14 +570,14 @@ cdef class Polynomial_rational_flint(Polynomial): cdef Polynomial_rational_flint res cdef bint do_sig - if (n >= fmpq_poly_length(self.__poly)): + if (n >= fmpq_poly_length(self._poly)): return self else: res = self._new() if n > 0: - do_sig = _do_sig(self.__poly) + do_sig = _do_sig(self._poly) if do_sig: sig_str("FLINT exception") - fmpq_poly_get_slice(res.__poly, self.__poly, 0, n) + fmpq_poly_get_slice(res._poly, self._poly, 0, n) if do_sig: sig_off() return res @@ -664,7 +664,7 @@ cdef class Polynomial_rational_flint(Polynomial): cdef bint do_sig if degree is None: - len = fmpq_poly_length(self.__poly) + len = fmpq_poly_length(self._poly) else: try: len = (degree + 1) @@ -672,9 +672,9 @@ cdef class Polynomial_rational_flint(Polynomial): raise ValueError('degree must be convertible to long') res = self._new() - do_sig = _do_sig(self.__poly) + do_sig = _do_sig(self._poly) if do_sig: sig_str("FLINT exception") - fmpq_poly_reverse(res.__poly, self.__poly, len) + fmpq_poly_reverse(res._poly, self._poly, len) if do_sig: sig_off() return res @@ -709,7 +709,7 @@ cdef class Polynomial_rational_flint(Polynomial): raise ValueError("self must have constant coefficient 0 and a unit for coefficient {}^1".format(self.parent().gen())) sig_str("FLINT exception") - fmpq_poly_revert_series(res.__poly, self.__poly, m) + fmpq_poly_revert_series(res._poly, self._poly, m) sig_off() return res @@ -731,7 +731,7 @@ cdef class Polynomial_rational_flint(Polynomial): sage: R(0).is_zero() True """ - return fmpq_poly_is_zero(self.__poly) + return fmpq_poly_is_zero(self._poly) cpdef bint is_one(self) except -1: r""" @@ -751,7 +751,7 @@ cdef class Polynomial_rational_flint(Polynomial): sage: R([1,1]).is_one() False """ - return fmpq_poly_is_one(self.__poly) + return fmpq_poly_is_one(self._poly) def __bool__(self): """ @@ -766,7 +766,7 @@ cdef class Polynomial_rational_flint(Polynomial): sage: bool(R(0)) False """ - return not fmpq_poly_is_zero(self.__poly) + return not fmpq_poly_is_zero(self._poly) ########################################################################### # Shifting # @@ -794,14 +794,14 @@ cdef class Polynomial_rational_flint(Polynomial): cdef Polynomial_rational_flint res cdef bint do_sig - if k == 0 or fmpq_poly_is_zero(f.__poly): + if k == 0 or fmpq_poly_is_zero(f._poly): return self else: res = f._new() - do_sig = fmpq_poly_length(f.__poly) > 5000 or n > 5000 + do_sig = fmpq_poly_length(f._poly) > 5000 or n > 5000 if do_sig: sig_str("FLINT exception") - fmpq_poly_shift_left(res.__poly, f.__poly, k) + fmpq_poly_shift_left(res._poly, f._poly, k) if do_sig: sig_off() return res @@ -822,14 +822,14 @@ cdef class Polynomial_rational_flint(Polynomial): cdef Polynomial_rational_flint res cdef bint do_sig - if k == 0 or fmpq_poly_is_zero(f.__poly): + if k == 0 or fmpq_poly_is_zero(f._poly): return self else: res = f._new() - do_sig = _do_sig(f.__poly) + do_sig = _do_sig(f._poly) if do_sig: sig_str("FLINT exception") - fmpq_poly_shift_right(res.__poly, f.__poly, k) + fmpq_poly_shift_right(res._poly, f._poly, k) if do_sig: sig_off() return res @@ -858,10 +858,10 @@ cdef class Polynomial_rational_flint(Polynomial): """ cdef Polynomial_rational_flint op2 = right cdef Polynomial_rational_flint res = self._new() - cdef bint do_sig = _do_sig(self.__poly) or _do_sig(op2.__poly) + cdef bint do_sig = _do_sig(self._poly) or _do_sig(op2._poly) if do_sig: sig_str("FLINT exception") - fmpq_poly_add(res.__poly, self.__poly, op2.__poly) + fmpq_poly_add(res._poly, self._poly, op2._poly) if do_sig: sig_off() return res @@ -886,10 +886,10 @@ cdef class Polynomial_rational_flint(Polynomial): """ cdef Polynomial_rational_flint op2 = right cdef Polynomial_rational_flint res = self._new() - cdef bint do_sig = _do_sig(self.__poly) or _do_sig(op2.__poly) + cdef bint do_sig = _do_sig(self._poly) or _do_sig(op2._poly) if do_sig: sig_str("FLINT exception") - fmpq_poly_sub(res.__poly, self.__poly, op2.__poly) + fmpq_poly_sub(res._poly, self._poly, op2._poly) if do_sig: sig_off() return res @@ -912,10 +912,10 @@ cdef class Polynomial_rational_flint(Polynomial): True """ cdef Polynomial_rational_flint res = self._new() - cdef bint do_sig = _do_sig(self.__poly) + cdef bint do_sig = _do_sig(self._poly) if do_sig: sig_str("FLINT exception") - fmpq_poly_neg(res.__poly, self.__poly) + fmpq_poly_neg(res._poly, self._poly) if do_sig: sig_off() return res @@ -945,8 +945,8 @@ cdef class Polynomial_rational_flint(Polynomial): cdef Polynomial_rational_flint rr = self._new() sig_str("FLINT exception") - fmpq_poly_divrem(qq.__poly, rr.__poly, self.__poly, - ( right).__poly) + fmpq_poly_divrem(qq._poly, rr._poly, self._poly, + ( right)._poly) sig_off() return qq, rr @@ -974,8 +974,8 @@ cdef class Polynomial_rational_flint(Polynomial): cdef Polynomial_rational_flint res = self._new() sig_str("FLINT exception") - fmpq_poly_gcd(res.__poly, self.__poly, - ( right).__poly) + fmpq_poly_gcd(res._poly, self._poly, + ( right)._poly) sig_off() return res @@ -1001,8 +1001,8 @@ cdef class Polynomial_rational_flint(Polynomial): cdef Polynomial_rational_flint res = self._new() sig_str("FLINT exception") - fmpq_poly_lcm(res.__poly, self.__poly, - ( right).__poly) + fmpq_poly_lcm(res._poly, self._poly, + ( right)._poly) sig_off() return res @@ -1043,7 +1043,7 @@ cdef class Polynomial_rational_flint(Polynomial): cdef Polynomial_rational_flint t = self._new() sig_str("FLINT exception") - fmpq_poly_xgcd(d.__poly, s.__poly, t.__poly, self.__poly, (right).__poly) + fmpq_poly_xgcd(d._poly, s._poly, t._poly, self._poly, (right)._poly) sig_off() return d, s, t @@ -1069,10 +1069,10 @@ cdef class Polynomial_rational_flint(Polynomial): """ cdef Polynomial_rational_flint op2 = right cdef Polynomial_rational_flint res = self._new() - cdef bint do_sig = _do_sig(self.__poly) or _do_sig(op2.__poly) + cdef bint do_sig = _do_sig(self._poly) or _do_sig(op2._poly) if do_sig: sig_str("FLINT exception") - fmpq_poly_mul(res.__poly, self.__poly, op2.__poly) + fmpq_poly_mul(res._poly, self._poly, op2._poly) if do_sig: sig_off() return res @@ -1103,13 +1103,13 @@ cdef class Polynomial_rational_flint(Polynomial): """ cdef Polynomial_rational_flint op2 = right cdef Polynomial_rational_flint res = self._new() - cdef bint do_sig = _do_sig(self.__poly) or _do_sig(op2.__poly) + cdef bint do_sig = _do_sig(self._poly) or _do_sig(op2._poly) if n <= 0: raise ValueError("n must be > 0") if do_sig: sig_str("FLINT exception") - fmpq_poly_mullow(res.__poly, self.__poly, op2.__poly, n) + fmpq_poly_mullow(res._poly, self._poly, op2._poly, n) if do_sig: sig_off() return res @@ -1125,10 +1125,10 @@ cdef class Polynomial_rational_flint(Polynomial): 9*t^3 - 6*t + 2 """ cdef Polynomial_rational_flint res = self._new() - cdef bint do_sig = _do_sig(self.__poly) + cdef bint do_sig = _do_sig(self._poly) if do_sig: sig_str("FLINT exception") - fmpq_poly_scalar_mul_mpq(res.__poly, self.__poly, + fmpq_poly_scalar_mul_mpq(res._poly, self._poly, ( left).value) if do_sig: sig_off() return res @@ -1145,10 +1145,10 @@ cdef class Polynomial_rational_flint(Polynomial): 9*t^3 - 6*t + 2 """ cdef Polynomial_rational_flint res = self._new() - cdef bint do_sig = _do_sig(self.__poly) + cdef bint do_sig = _do_sig(self._poly) if do_sig: sig_str("FLINT exception") - fmpq_poly_scalar_mul_mpq(res.__poly, self.__poly, + fmpq_poly_scalar_mul_mpq(res._poly, self._poly, ( right).value) if do_sig: sig_off() return res @@ -1272,27 +1272,27 @@ cdef class Polynomial_rational_flint(Polynomial): num = r.numerator() den = r.denominator() - if fmpq_poly_degree(self.__poly) == 0: + if fmpq_poly_degree(self._poly) == 0: return self.parent()(self[0].nth_root(den) ** num) return self.nth_root(den) ** num else: if n < 0: - if fmpq_poly_is_zero(self.__poly): + if fmpq_poly_is_zero(self._poly): raise ZeroDivisionError("negative exponent in power of zero") res = self._new() sig_str("FLINT exception") - fmpq_poly_pow(res.__poly, self.__poly, -n) + fmpq_poly_pow(res._poly, self._poly, -n) sig_off() return ~res else: res = self._new() sig_str("FLINT exception") if self._is_gen: - fmpq_poly_set_coeff_si(res.__poly, n, 1) + fmpq_poly_set_coeff_si(res._poly, n, 1) else: - fmpq_poly_pow(res.__poly, self.__poly, n) + fmpq_poly_pow(res._poly, self._poly, n) sig_off() return res @@ -1328,10 +1328,10 @@ cdef class Polynomial_rational_flint(Polynomial): if not isinstance(right, Polynomial_rational_flint): if right in QQ: res = self._new() - do_sig = _do_sig(self.__poly) + do_sig = _do_sig(self._poly) if do_sig: sig_str("FLINT exception") - fmpq_poly_scalar_div_mpq(res.__poly, self.__poly, + fmpq_poly_scalar_div_mpq(res._poly, self._poly, ( QQ(right)).value) if do_sig: sig_off() return res @@ -1340,8 +1340,8 @@ cdef class Polynomial_rational_flint(Polynomial): res = self._new() sig_str("FLINT exception") - fmpq_poly_div(res.__poly, self.__poly, - (right).__poly) + fmpq_poly_div(res._poly, self._poly, + (right)._poly) sig_off() return res @@ -1381,15 +1381,15 @@ cdef class Polynomial_rational_flint(Polynomial): """ if prec <= 0: raise ValueError("the precision must be positive, got {}".format(prec)) - if fmpq_poly_degree(self.__poly) == -1 or \ - fmpz_is_zero(fmpq_poly_numref(self.__poly)): + if fmpq_poly_degree(self._poly) == -1 or \ + fmpz_is_zero(fmpq_poly_numref(self._poly)): raise ValueError("constant term is zero") cdef Polynomial_rational_flint res = self._new() if prec <= 0: return res sig_on() - fmpq_poly_inv_series(res.__poly, self.__poly, prec) + fmpq_poly_inv_series(res._poly, self._poly, prec) sig_off() return res @@ -1423,8 +1423,8 @@ cdef class Polynomial_rational_flint(Polynomial): res = self._new() sig_str("FLINT exception") - fmpq_poly_rem(res.__poly, self.__poly, - (right).__poly) + fmpq_poly_rem(res._poly, self._poly, + (right)._poly) sig_off() return res @@ -1453,7 +1453,7 @@ cdef class Polynomial_rational_flint(Polynomial): Polynomial_integer_dense_flint.__init__(num, parent, x=None, check=False, is_gen=False, construct=False) sig_str("FLINT exception") - fmpq_poly_get_numerator(num.__poly, self.__poly) + fmpq_poly_get_numerator(num._poly, self._poly) sig_off() return num @@ -1469,10 +1469,10 @@ cdef class Polynomial_rational_flint(Polynomial): 3 """ cdef Integer den = Integer.__new__(Integer) - if fmpq_poly_denref(self.__poly) is NULL: + if fmpq_poly_denref(self._poly) is NULL: mpz_set_ui(den.value, 1) else: - fmpz_get_mpz(den.value, fmpq_poly_denref(self.__poly)) + fmpz_get_mpz(den.value, fmpq_poly_denref(self._poly)) return den def _derivative(self, var = None): @@ -1517,10 +1517,10 @@ cdef class Polynomial_rational_flint(Polynomial): raise ValueError("cannot differentiate with respect to {}".format(var)) der = self._new() - do_sig = _do_sig(self.__poly) + do_sig = _do_sig(self._poly) if do_sig: sig_str("FLINT exception") - fmpq_poly_derivative(der.__poly, self.__poly) + fmpq_poly_derivative(der._poly, self._poly) if do_sig: sig_off() return der @@ -1574,8 +1574,8 @@ cdef class Polynomial_rational_flint(Polynomial): cdef fmpq_t t fmpq_init(t) sig_str("FLINT exception") - fmpq_poly_resultant(t, self.__poly, - (right).__poly) + fmpq_poly_resultant(t, self._poly, + (right)._poly) fmpq_get_mpq(res.value, t) sig_off() fmpq_clear(t) @@ -1623,7 +1623,7 @@ cdef class Polynomial_rational_flint(Polynomial): """ cdef Polynomial_integer_dense_flint primitive - cdef unsigned long length = fmpq_poly_length(self.__poly) + cdef unsigned long length = fmpq_poly_length(self._poly) if length < 2: return False @@ -1636,8 +1636,8 @@ cdef class Polynomial_rational_flint(Polynomial): x=None, check=True, is_gen=False, construct=False) sig_str("FLINT exception") - fmpq_poly_get_numerator(primitive.__poly, self.__poly) - fmpz_poly_primitive_part(primitive.__poly, primitive.__poly) + fmpq_poly_get_numerator(primitive._poly, self._poly) + fmpz_poly_primitive_part(primitive._poly, primitive._poly) sig_off() return primitive.is_irreducible() @@ -1669,14 +1669,14 @@ cdef class Polynomial_rational_flint(Polynomial): ... ValueError: constant term should be 1 in order to take logarithm """ - if fmpq_poly_degree(self.__poly) == -1 or \ - fmpz_cmp(fmpq_poly_numref(self.__poly), - fmpq_poly_denref(self.__poly)): + if fmpq_poly_degree(self._poly) == -1 or \ + fmpz_cmp(fmpq_poly_numref(self._poly), + fmpq_poly_denref(self._poly)): raise ValueError("constant term should be 1 in order to take logarithm") cdef Polynomial_rational_flint res = self._new() sig_on() - fmpq_poly_log_series(res.__poly, self.__poly, prec) + fmpq_poly_log_series(res._poly, self._poly, prec) sig_off() return res @@ -1703,14 +1703,14 @@ cdef class Polynomial_rational_flint(Polynomial): sage: _.parent() Univariate Polynomial Ring in x over Rational Field """ - if fmpq_poly_degree(self.__poly) == -1: + if fmpq_poly_degree(self._poly) == -1: return self._parent.one() - elif not fmpz_is_zero(fmpq_poly_numref(self.__poly)): + elif not fmpz_is_zero(fmpq_poly_numref(self._poly)): raise ValueError("constant term should be 0 in order to take exponential") cdef Polynomial_rational_flint res = self._new() sig_on() - fmpq_poly_exp_series(res.__poly, self.__poly, prec) + fmpq_poly_exp_series(res._poly, self._poly, prec) sig_off() return res @@ -1737,14 +1737,14 @@ cdef class Polynomial_rational_flint(Polynomial): sage: _.parent() Univariate Polynomial Ring in x over Rational Field """ - if fmpq_poly_degree(self.__poly) == -1: + if fmpq_poly_degree(self._poly) == -1: return self._parent.zero() - elif not fmpz_is_zero(fmpq_poly_numref(self.__poly)): + elif not fmpz_is_zero(fmpq_poly_numref(self._poly)): raise ValueError("constant term should be 0 in order to take arctangent") cdef Polynomial_rational_flint res = self._new() sig_on() - fmpq_poly_atan_series(res.__poly, self.__poly, prec) + fmpq_poly_atan_series(res._poly, self._poly, prec) sig_off() return res @@ -1768,14 +1768,14 @@ cdef class Polynomial_rational_flint(Polynomial): sage: _.parent() Univariate Polynomial Ring in x over Rational Field """ - if fmpq_poly_degree(self.__poly) == -1: + if fmpq_poly_degree(self._poly) == -1: return self._parent.zero() - elif not fmpz_is_zero(fmpq_poly_numref(self.__poly)): + elif not fmpz_is_zero(fmpq_poly_numref(self._poly)): raise ValueError("constant term should be 0 in order to take hyperbolic arctangent") cdef Polynomial_rational_flint res = self._new() sig_on() - fmpq_poly_atanh_series(res.__poly, self.__poly, prec) + fmpq_poly_atanh_series(res._poly, self._poly, prec) sig_off() return res @@ -1802,14 +1802,14 @@ cdef class Polynomial_rational_flint(Polynomial): sage: _.parent() Univariate Polynomial Ring in x over Rational Field """ - if fmpq_poly_degree(self.__poly) == -1: + if fmpq_poly_degree(self._poly) == -1: return self._parent.zero() - elif not fmpz_is_zero(fmpq_poly_numref(self.__poly)): + elif not fmpz_is_zero(fmpq_poly_numref(self._poly)): raise ValueError("constant term should be 0 in order to take arcsine") cdef Polynomial_rational_flint res = self._new() sig_on() - fmpq_poly_asin_series(res.__poly, self.__poly, prec) + fmpq_poly_asin_series(res._poly, self._poly, prec) sig_off() return res @@ -1837,14 +1837,14 @@ cdef class Polynomial_rational_flint(Polynomial): sage: _.parent() Univariate Polynomial Ring in x over Rational Field """ - if fmpq_poly_degree(self.__poly) == -1: + if fmpq_poly_degree(self._poly) == -1: return self._parent.zero() - elif not fmpz_is_zero(fmpq_poly_numref(self.__poly)): + elif not fmpz_is_zero(fmpq_poly_numref(self._poly)): raise ValueError("constant term should be 0 in order to take hyperbolic arcsine") cdef Polynomial_rational_flint res = self._new() sig_on() - fmpq_poly_asinh_series(res.__poly, self.__poly, prec) + fmpq_poly_asinh_series(res._poly, self._poly, prec) sig_off() return res @@ -1871,14 +1871,14 @@ cdef class Polynomial_rational_flint(Polynomial): sage: _.parent() Univariate Polynomial Ring in x over Rational Field """ - if fmpq_poly_degree(self.__poly) == -1: + if fmpq_poly_degree(self._poly) == -1: return self._parent.zero() - elif not fmpz_is_zero(fmpq_poly_numref(self.__poly)): + elif not fmpz_is_zero(fmpq_poly_numref(self._poly)): raise ValueError("constant term should be 0 in order to take tangent") cdef Polynomial_rational_flint res = self._new() sig_on() - fmpq_poly_tan_series(res.__poly, self.__poly, prec) + fmpq_poly_tan_series(res._poly, self._poly, prec) sig_off() return res @@ -1905,14 +1905,14 @@ cdef class Polynomial_rational_flint(Polynomial): sage: _.parent() Univariate Polynomial Ring in x over Rational Field """ - if fmpq_poly_degree(self.__poly) == -1: + if fmpq_poly_degree(self._poly) == -1: return self._parent.zero() - elif not fmpz_is_zero(fmpq_poly_numref(self.__poly)): + elif not fmpz_is_zero(fmpq_poly_numref(self._poly)): raise ValueError("constant term should be 0 in order to take sine") cdef Polynomial_rational_flint res = self._new() sig_on() - fmpq_poly_sin_series(res.__poly, self.__poly, prec) + fmpq_poly_sin_series(res._poly, self._poly, prec) sig_off() return res @@ -1937,14 +1937,14 @@ cdef class Polynomial_rational_flint(Polynomial): sage: _.parent() Univariate Polynomial Ring in x over Rational Field """ - if fmpq_poly_degree(self.__poly) == -1: + if fmpq_poly_degree(self._poly) == -1: return self._parent.zero() - elif not fmpz_is_zero(fmpq_poly_numref(self.__poly)): + elif not fmpz_is_zero(fmpq_poly_numref(self._poly)): raise ValueError("constant term should be 0 in order to take cosine") cdef Polynomial_rational_flint res = self._new() sig_on() - fmpq_poly_cos_series(res.__poly, self.__poly, prec) + fmpq_poly_cos_series(res._poly, self._poly, prec) sig_off() return res @@ -1969,14 +1969,14 @@ cdef class Polynomial_rational_flint(Polynomial): sage: _.parent() Univariate Polynomial Ring in x over Rational Field """ - if fmpq_poly_degree(self.__poly) == -1: + if fmpq_poly_degree(self._poly) == -1: return self._parent.zero() - elif not fmpz_is_zero(fmpq_poly_numref(self.__poly)): + elif not fmpz_is_zero(fmpq_poly_numref(self._poly)): raise ValueError("constant term should be 0 in order to take hyperbolic sine") cdef Polynomial_rational_flint res = self._new() sig_on() - fmpq_poly_sinh_series(res.__poly, self.__poly, prec) + fmpq_poly_sinh_series(res._poly, self._poly, prec) sig_off() return res @@ -2007,14 +2007,14 @@ cdef class Polynomial_rational_flint(Polynomial): sage: _.parent() Univariate Polynomial Ring in x over Rational Field """ - if fmpq_poly_degree(self.__poly) == -1: + if fmpq_poly_degree(self._poly) == -1: return self._parent.one() - elif not fmpz_is_zero(fmpq_poly_numref(self.__poly)): + elif not fmpz_is_zero(fmpq_poly_numref(self._poly)): raise ValueError("constant term should be 0 in order to take hyperbolic cosine") cdef Polynomial_rational_flint res = self._new() sig_on() - fmpq_poly_cosh_series(res.__poly, self.__poly, prec) + fmpq_poly_cosh_series(res._poly, self._poly, prec) sig_off() return res @@ -2040,14 +2040,14 @@ cdef class Polynomial_rational_flint(Polynomial): sage: _.parent() Univariate Polynomial Ring in x over Rational Field """ - if fmpq_poly_degree(self.__poly) == -1: + if fmpq_poly_degree(self._poly) == -1: return self._parent.zero() - elif not fmpz_is_zero(fmpq_poly_numref(self.__poly)): + elif not fmpz_is_zero(fmpq_poly_numref(self._poly)): raise ValueError("constant term should be 0 in order to take hyperbolic tangent") cdef Polynomial_rational_flint res = self._new() sig_on() - fmpq_poly_tanh_series(res.__poly, self.__poly, prec) + fmpq_poly_tanh_series(res._poly, self._poly, prec) sig_off() return res diff --git a/src/sage/rings/polynomial/polynomial_zmod_flint.pyx b/src/sage/rings/polynomial/polynomial_zmod_flint.pyx index 253ab949fcc..4c480673861 100644 --- a/src/sage/rings/polynomial/polynomial_zmod_flint.pyx +++ b/src/sage/rings/polynomial/polynomial_zmod_flint.pyx @@ -110,7 +110,7 @@ cdef class Polynomial_zmod_flint(Polynomial_template): return elif isinstance(x, Polynomial_integer_dense_flint): Polynomial_template.__init__(self, parent, 0, check, is_gen, construct) - self._set_fmpz_poly((x).__poly) + self._set_fmpz_poly((x)._poly) return else: if isinstance(x, ntl_zz_pX): diff --git a/src/sage/rings/power_series_mpoly.pxd b/src/sage/rings/power_series_mpoly.pxd index f822ecc1227..d358ada1356 100644 --- a/src/sage/rings/power_series_mpoly.pxd +++ b/src/sage/rings/power_series_mpoly.pxd @@ -3,6 +3,6 @@ from .power_series_ring_element cimport PowerSeries cdef class PowerSeries_mpoly(PowerSeries): cdef ModuleElement __f - cdef object __poly + cdef object _poly cdef object __list cdef bint _truncated diff --git a/src/sage/rings/power_series_mpoly.pyx b/src/sage/rings/power_series_mpoly.pyx index 61cfbe25021..cbf9326b4ca 100644 --- a/src/sage/rings/power_series_mpoly.pyx +++ b/src/sage/rings/power_series_mpoly.pyx @@ -92,10 +92,10 @@ cdef class PowerSeries_mpoly(PowerSeries): return self.__list def polynomial(self): - if self.__poly is None: + if self._poly is None: S = self.parent()._mpoly_ring() - self.__poly = self.__f.polynomial(S.gens()[-1]) - return self.__poly + self._poly = self.__f.polynomial(S.gens()[-1]) + return self._poly def _mpoly(self): return self.__f From 31422275d945c6461de8aa552072aeca5aca476b Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:46:55 +0800 Subject: [PATCH 34/44] fix private methods used in doctests --- src/sage/libs/lcalc/lcalc_Lfunction.pyx | 4 ++-- src/sage/rings/real_mpfr.pyx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sage/libs/lcalc/lcalc_Lfunction.pyx b/src/sage/libs/lcalc/lcalc_Lfunction.pyx index d8b7221fe55..7b871ed049f 100644 --- a/src/sage/libs/lcalc/lcalc_Lfunction.pyx +++ b/src/sage/libs/lcalc/lcalc_Lfunction.pyx @@ -251,7 +251,7 @@ cdef class Lfunction: """ return self._compute_rank() - def __N(self, T): + def _N(self, T): """ Compute the number of zeroes upto height `T` using the formula for `N(T)` with the error of `S(T)`. Please do not use this. It is only @@ -262,7 +262,7 @@ cdef class Lfunction: sage: from sage.libs.lcalc.lcalc_Lfunction import * sage: chi = DirichletGroup(5)[2] #This is a quadratic character sage: L=Lfunction_from_character(chi, type="complex") - sage: L.__N(10) # abs tol 1e-8 + sage: L._N(10) # abs tol 1e-8 4.0 """ cdef RealNumber real_T=RRR(T) diff --git a/src/sage/rings/real_mpfr.pyx b/src/sage/rings/real_mpfr.pyx index 11e21af5e98..7440fadd265 100644 --- a/src/sage/rings/real_mpfr.pyx +++ b/src/sage/rings/real_mpfr.pyx @@ -4300,7 +4300,7 @@ cdef class RealNumber(sage.structure.element.RingElement): if (self._parent)._prec > 10*SIG_PREC_THRESHOLD: sig_off() return x - def __pow(self, RealNumber exponent): + def _pow(self, RealNumber exponent): """ Compute ``self`` raised to the power of exponent, rounded in the direction specified by the parent of ``self``. @@ -4309,7 +4309,7 @@ cdef class RealNumber(sage.structure.element.RingElement): sage: R = RealField(30) sage: a = R('1.23456') - sage: a.__pow(20.0) + sage: a._pow(20.0) 67.646297 """ cdef RealNumber x From 58df1a94ca1675869241a70674909c8cd8cb763a Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:47:47 +0800 Subject: [PATCH 35/44] fix PY_NEW signature --- src/sage/ext/stdsage.pxd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/ext/stdsage.pxd b/src/sage/ext/stdsage.pxd index 15abe13b7cd..e2bf7434f35 100644 --- a/src/sage/ext/stdsage.pxd +++ b/src/sage/ext/stdsage.pxd @@ -10,7 +10,7 @@ Standard C helper code for Cython modules # http://www.gnu.org/licenses/ #***************************************************************************** -from cpython.object cimport Py_TYPE, PyTypeObject +from cpython.object cimport Py_TYPE, PyTypeObject, PyObject cdef inline PY_NEW(type t): @@ -19,7 +19,7 @@ cdef inline PY_NEW(type t): :class:`Integer` where we change ``tp_new`` at runtime (Cython optimizations assume that ``tp_new`` doesn't change). """ - return (t).tp_new(t, NULL, NULL) + return (t).tp_new(t, NULL, NULL) cdef inline void PY_SET_TP_NEW(type dst, type src): From 0c3ed272b1f1300e6d03ab769d058cfae3a0f093 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:50:32 +0800 Subject: [PATCH 36/44] avoid naming attributes __module__ in cython 3 --- src/sage/misc/cachefunc.pxd | 4 ++-- src/sage/misc/cachefunc.pyx | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/sage/misc/cachefunc.pxd b/src/sage/misc/cachefunc.pxd index d3cc677dece..8e5d9dfa42a 100644 --- a/src/sage/misc/cachefunc.pxd +++ b/src/sage/misc/cachefunc.pxd @@ -5,7 +5,7 @@ cpdef cache_key(o) cdef class CachedFunction(): cdef public str __name__ - cdef public str __module__ + cdef public str __cached_module__ cdef ArgumentFixer _argument_fixer cdef public f cdef public cache # not always of type @@ -20,7 +20,7 @@ cdef class CachedFunction(): cdef class CachedMethod(): cdef str _cache_name cdef public str __name__ - cdef public str __module__ + cdef public str __cached_module__ cdef CachedFunction _cachedfunc cdef Py_ssize_t nargs cpdef _get_instance_cache(self, inst) diff --git a/src/sage/misc/cachefunc.pyx b/src/sage/misc/cachefunc.pyx index c11ed7a8df8..9002479e340 100644 --- a/src/sage/misc/cachefunc.pyx +++ b/src/sage/misc/cachefunc.pyx @@ -761,13 +761,17 @@ cdef class CachedFunction(): else: self.__name__ = f.__name__ try: - self.__module__ = f.__module__ + self.__cached_module__ = f.__module__ except AttributeError: - self.__module__ = f.__objclass__.__module__ + self.__cached_module__ = f.__objclass__.__module__ if argument_fixer is not None: # it is None unless the argument fixer # was known previously. See #15038. self._argument_fixer = argument_fixer + @property + def __module__(self): + return self.__cached_module__ + cdef get_key_args_kwds(self, tuple args, dict kwds): """ Return the key in the cache to be used when ``args`` and @@ -828,7 +832,7 @@ cdef class CachedFunction(): sage: loads(dumps(hilbert_class_polynomial)) is hilbert_class_polynomial #indirect doctest True """ - return _cached_function_unpickle, (self.__module__, self.__name__, self.cache) + return _cached_function_unpickle, (self.__cached_module__, self.__name__, self.cache) ######### ## Introspection @@ -2675,7 +2679,11 @@ cdef class CachedMethod(): self._cache_name = '_cache__' + (name or f.__name__) self._cachedfunc = CachedFunction(f, classmethod=True, name=name, key=key, do_pickle=do_pickle) self.__name__ = self._cachedfunc.__name__ - self.__module__ = self._cachedfunc.__module__ + self.__cached_module__ = self._cachedfunc.__module__ + + @property + def __module__(self): + return self.__cached_module__ def __call__(self, inst, *args, **kwds): """ From d5f3e3a7e25b847d715a7b130300a1104077d9f4 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:51:30 +0800 Subject: [PATCH 37/44] force __getmetaclass__ to be a METH_NOARGS method --- src/sage/structure/element.pyx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sage/structure/element.pyx b/src/sage/structure/element.pyx index 172fc8b7759..810fa6efc79 100644 --- a/src/sage/structure/element.pyx +++ b/src/sage/structure/element.pyx @@ -379,6 +379,7 @@ cdef class Element(SageObject): .. automethod:: __mod__ """ @cython.binding(False) + @cython.always_allow_keywords(False) def __getmetaclass__(_): from sage.misc.inherit_comparison import InheritComparisonMetaclass return InheritComparisonMetaclass From 5afb2004d56ab9cf7d6ed10de31d7009f18d6ec9 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:52:33 +0800 Subject: [PATCH 38/44] fix structmember.h defines in cython 3 --- src/sage/libs/gap/gap_includes.pxd | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/sage/libs/gap/gap_includes.pxd b/src/sage/libs/gap/gap_includes.pxd index 840b8a0042e..1ed4378a6c7 100644 --- a/src/sage/libs/gap/gap_includes.pxd +++ b/src/sage/libs/gap/gap_includes.pxd @@ -144,3 +144,18 @@ cdef extern from "gap/stringobj.h" nogil: bint IS_STRING(Obj obj) bint IsStringConv(Obj obj) Obj NEW_STRING(Int) + + +cdef extern from "" nogil: + """ + /* Hack: Cython 3.0 automatically includes , which + * defines several macros that collides with enum definitions in + * gap/objects.h. We need to include the header explicitly and + * undefine these macros. + */ + #undef T_INT + #undef T_STRING + #undef T_CHAR + #undef T_BOOL + """ + pass From 4fefac11c6fda6e0bc3cb9b8e84bf862e31ce5e4 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Mon, 7 Aug 2023 23:53:14 +0800 Subject: [PATCH 39/44] avoid StopIteration in generators --- src/sage/numerical/linear_functions.pyx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/sage/numerical/linear_functions.pyx b/src/sage/numerical/linear_functions.pyx index 5549ff436f5..f3fc6fe419c 100644 --- a/src/sage/numerical/linear_functions.pyx +++ b/src/sage/numerical/linear_functions.pyx @@ -1579,7 +1579,10 @@ cdef class LinearConstraint(LinearFunctionOrConstraint): while True: yield (lhs, rhs) lhs = rhs - rhs = next(term_iter) + try: + rhs = next(term_iter) + except StopIteration: + return def inequalities(self): """ @@ -1612,7 +1615,10 @@ cdef class LinearConstraint(LinearFunctionOrConstraint): while True: yield (lhs, rhs) lhs = rhs - rhs = next(term_iter) + try: + rhs = next(term_iter) + except StopIteration: + return def _repr_(self): r""" From 6bcabe46a1803171a02270123099bc09248f205e Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Tue, 8 Aug 2023 00:21:52 +0800 Subject: [PATCH 40/44] update cython to 3.0.0 --- build/pkgs/cython/checksums.ini | 6 +- build/pkgs/cython/install-requires.txt | 2 +- build/pkgs/cython/package-version.txt | 2 +- build/pkgs/cython/patches/4918.patch | 287 ----------------------- build/pkgs/cython/patches/trashcan.patch | 187 --------------- 5 files changed, 5 insertions(+), 479 deletions(-) delete mode 100644 build/pkgs/cython/patches/4918.patch delete mode 100644 build/pkgs/cython/patches/trashcan.patch diff --git a/build/pkgs/cython/checksums.ini b/build/pkgs/cython/checksums.ini index b06052c59aa..cf4d58b7e0c 100644 --- a/build/pkgs/cython/checksums.ini +++ b/build/pkgs/cython/checksums.ini @@ -1,5 +1,5 @@ tarball=Cython-VERSION.tar.gz -sha1=015b737107304a5777f5c6552ffb12713684c924 -md5=91c36ea86c00adcc5c1c11cf48b733c0 -cksum=1793363471 +sha1=cbf05e7e4937388fa21e8fa3113124b036f01eba +md5=63c5672e1f58dcee6854aef8b33a922e +cksum=1763712438 upstream_url=https://pypi.io/packages/source/C/Cython/Cython-VERSION.tar.gz diff --git a/build/pkgs/cython/install-requires.txt b/build/pkgs/cython/install-requires.txt index b8a968fa247..3693d637891 100644 --- a/build/pkgs/cython/install-requires.txt +++ b/build/pkgs/cython/install-requires.txt @@ -1 +1 @@ -cython >=0.29.21, <1.0 +cython >=3.0, <4.0 diff --git a/build/pkgs/cython/package-version.txt b/build/pkgs/cython/package-version.txt index babe4be9be1..4a36342fcab 100644 --- a/build/pkgs/cython/package-version.txt +++ b/build/pkgs/cython/package-version.txt @@ -1 +1 @@ -0.29.32.p2 +3.0.0 diff --git a/build/pkgs/cython/patches/4918.patch b/build/pkgs/cython/patches/4918.patch deleted file mode 100644 index a9dbb0a4a0c..00000000000 --- a/build/pkgs/cython/patches/4918.patch +++ /dev/null @@ -1,287 +0,0 @@ -From 0dade9353e06b052d0da5e512cdc2ce04061904a Mon Sep 17 00:00:00 2001 -From: Matthias Koeppe -Date: Sat, 23 Jul 2022 10:53:49 -0700 -Subject: [PATCH 1/3] Add PEP420 namespace support - -Backport of https://github.com/cython/cython/pull/2946 to 0.29.x ---- - Cython/Compiler/Main.py | 44 +++++++++++++++---- - Cython/Utils.py | 26 ++++++++--- - runtests.py | 1 + - .../build/cythonize_pep420_namespace.srctree | 44 +++++++++++++++++++ - 4 files changed, 99 insertions(+), 16 deletions(-) - create mode 100644 tests/build/cythonize_pep420_namespace.srctree - -diff --git a/Cython/Compiler/Main.py b/Cython/Compiler/Main.py -index dc4add541e..2be7a06a1c 100644 ---- a/Cython/Compiler/Main.py -+++ b/Cython/Compiler/Main.py -@@ -801,32 +801,58 @@ def search_include_directories(dirs, qualified_name, suffix, pos, include=False) - else: - dirs = (Utils.find_root_package_dir(file_desc.filename),) + dirs - -+ # search for dotted filename e.g. /foo.bar.pxd - dotted_filename = qualified_name - if suffix: - dotted_filename += suffix - -+ for dirname in dirs: -+ path = os.path.join(dirname, dotted_filename) -+ if os.path.exists(path): -+ return path -+ -+ # search for filename in package structure e.g. /foo/bar.pxd or /foo/bar/__init__.pxd - if not include: -+ - names = qualified_name.split('.') - package_names = tuple(names[:-1]) - module_name = names[-1] - module_filename = module_name + suffix - package_filename = "__init__" + suffix - -- for dirname in dirs: -- path = os.path.join(dirname, dotted_filename) -- if os.path.exists(path): -- return path -- -- if not include: -- package_dir = Utils.check_package_dir(dirname, package_names) -+ # search for standard packages first - PEP420 -+ namespace_dirs = [] -+ for dirname in dirs: -+ package_dir, is_namespace = Utils.check_package_dir(dirname, package_names) - if package_dir is not None: -+ -+ if is_namespace: -+ namespace_dirs.append(package_dir) -+ continue -+ -+ # matches modules of the form: /foo/bar.pxd - path = os.path.join(package_dir, module_filename) - if os.path.exists(path): - return path -- path = os.path.join(package_dir, module_name, -- package_filename) -+ -+ # matches modules of the form: /foo/bar/__init__.pxd -+ path = os.path.join(package_dir, module_name, package_filename) - if os.path.exists(path): - return path -+ -+ # search for namespaces second - PEP420 -+ for package_dir in namespace_dirs: -+ -+ # matches modules of the form: /foo/bar.pxd -+ path = os.path.join(package_dir, module_filename) -+ if os.path.exists(path): -+ return path -+ -+ # matches modules of the form: /foo/bar/__init__.pxd -+ path = os.path.join(package_dir, module_name, package_filename) -+ if os.path.exists(path): -+ return path -+ - return None - - -diff --git a/Cython/Utils.py b/Cython/Utils.py -index d59d67d78b..305ebf8412 100644 ---- a/Cython/Utils.py -+++ b/Cython/Utils.py -@@ -134,16 +134,21 @@ def find_root_package_dir(file_path): - else: - return dir - -+ - @cached_function --def check_package_dir(dir, package_names): -+def check_package_dir(dir_path, package_names): -+ namespace = True - for dirname in package_names: -- dir = os.path.join(dir, dirname) -- if not is_package_dir(dir): -- return None -- return dir -+ dir_path = os.path.join(dir_path, dirname) -+ has_init = contains_init(dir_path) -+ if not namespace and not has_init: -+ return None, False -+ elif has_init: -+ namespace = False -+ return dir_path, namespace - --@cached_function --def is_package_dir(dir_path): -+ -+def contains_init(dir_path): - for filename in ("__init__.py", - "__init__.pyc", - "__init__.pyx", -@@ -152,6 +157,13 @@ def is_package_dir(dir_path): - if path_exists(path): - return 1 - -+ -+@cached_function -+def is_package_dir(dir_path): -+ if contains_init(dir_path): -+ return 1 -+ -+ - @cached_function - def path_exists(path): - # try on the filesystem first -diff --git a/runtests.py b/runtests.py -index 91a0dd2570..7d04463846 100755 ---- a/runtests.py -+++ b/runtests.py -@@ -415,6 +415,7 @@ def get_openmp_compiler_flags(language): - 'run.special_methods_T561_py2' - ]), - (3,3) : (operator.lt, lambda x: x in ['build.package_compilation', -+ 'build.cythonize_pep420_namespace', - 'run.yield_from_py33', - 'pyximport.pyximport_namespace', - ]), -diff --git a/tests/build/cythonize_pep420_namespace.srctree b/tests/build/cythonize_pep420_namespace.srctree -new file mode 100644 -index 0000000000..6a031e4170 ---- /dev/null -+++ b/tests/build/cythonize_pep420_namespace.srctree -@@ -0,0 +1,44 @@ -+PYTHON setup.py build_ext --inplace -+PYTHON -c "import runner" -+ -+######## setup.py ######## -+ -+from Cython.Build.Dependencies import cythonize -+ -+from distutils.core import setup, Extension -+ -+setup( -+ ext_modules=cythonize([ -+ Extension("nsp.m1.a", ["nsp/m1/a.pyx"]), -+ Extension("nsp.m2.b", ["nsp/m2/b.pyx"]) -+ ]), -+) -+ -+######## nsp/m1/__init__.py ######## -+ -+######## nsp/m1/a.pyx ######## -+ -+cdef class A: -+ pass -+ -+######## nsp/m1/a.pxd ######## -+ -+cdef class A: -+ pass -+ -+######## nsp/m2/__init__.py ######## -+ -+######## nsp/m2/b.pyx ######## -+ -+from nsp.m1.a cimport A -+ -+cdef class B(A): -+ pass -+ -+######## runner.py ######## -+ -+from nsp.m1.a import A -+from nsp.m2.b import B -+ -+a = A() -+b = B() - -From fcd3e7bd1351a0964704f2921ae33b4b57250668 Mon Sep 17 00:00:00 2001 -From: Fedor Alekseev -Date: Mon, 9 Nov 2020 14:34:01 +0300 -Subject: [PATCH 2/3] Support namespace packages inside regular packages - ---- - Cython/Utils.py | 4 +--- - tests/build/cythonize_pep420_namespace.srctree | 17 ++++++++++++++++- - 2 files changed, 17 insertions(+), 4 deletions(-) - -diff --git a/Cython/Utils.py b/Cython/Utils.py -index 305ebf8412..f21d5cddba 100644 ---- a/Cython/Utils.py -+++ b/Cython/Utils.py -@@ -141,9 +141,7 @@ def check_package_dir(dir_path, package_names): - for dirname in package_names: - dir_path = os.path.join(dir_path, dirname) - has_init = contains_init(dir_path) -- if not namespace and not has_init: -- return None, False -- elif has_init: -+ if has_init: - namespace = False - return dir_path, namespace - -diff --git a/tests/build/cythonize_pep420_namespace.srctree b/tests/build/cythonize_pep420_namespace.srctree -index 6a031e4170..04013a3004 100644 ---- a/tests/build/cythonize_pep420_namespace.srctree -+++ b/tests/build/cythonize_pep420_namespace.srctree -@@ -10,7 +10,8 @@ from distutils.core import setup, Extension - setup( - ext_modules=cythonize([ - Extension("nsp.m1.a", ["nsp/m1/a.pyx"]), -- Extension("nsp.m2.b", ["nsp/m2/b.pyx"]) -+ Extension("nsp.m2.b", ["nsp/m2/b.pyx"]), -+ Extension("nsp.m3.c.d", ["nsp/m3/c/d.pyx"]) - ]), - ) - -@@ -31,14 +32,28 @@ cdef class A: - ######## nsp/m2/b.pyx ######## - - from nsp.m1.a cimport A -+from nsp.m3.c.d cimport D - - cdef class B(A): - pass - -+######## nsp/m3/__init__.py ######## -+ -+######## nsp/m3/c/d.pyx ######## -+ -+cdef class D: -+ pass -+ -+######## nsp/m3/c/d.pxd ######## -+ -+cdef class D: -+ pass -+ - ######## runner.py ######## - - from nsp.m1.a import A - from nsp.m2.b import B -+from nsp.m3.c.d import D - - a = A() - b = B() - -From 9d61b95a6a71a4c88a51ab8f30d5b3a8b93998b8 Mon Sep 17 00:00:00 2001 -From: scoder -Date: Sat, 14 Nov 2020 09:42:09 +0100 -Subject: [PATCH 3/3] Anticipate future changes. - ---- - tests/build/cythonize_pep420_namespace.srctree | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/tests/build/cythonize_pep420_namespace.srctree b/tests/build/cythonize_pep420_namespace.srctree -index 04013a3004..99649376a3 100644 ---- a/tests/build/cythonize_pep420_namespace.srctree -+++ b/tests/build/cythonize_pep420_namespace.srctree -@@ -11,7 +11,7 @@ setup( - ext_modules=cythonize([ - Extension("nsp.m1.a", ["nsp/m1/a.pyx"]), - Extension("nsp.m2.b", ["nsp/m2/b.pyx"]), -- Extension("nsp.m3.c.d", ["nsp/m3/c/d.pyx"]) -+ Extension("nsp.m3.c.d", ["nsp/m3/c/d.pyx"]), - ]), - ) - diff --git a/build/pkgs/cython/patches/trashcan.patch b/build/pkgs/cython/patches/trashcan.patch deleted file mode 100644 index e1e88ebe465..00000000000 --- a/build/pkgs/cython/patches/trashcan.patch +++ /dev/null @@ -1,187 +0,0 @@ -See https://github.com/cython/cython/pull/2842 - -and https://github.com/cython/cython/pull/4475 - -commit c47c4ef735c4b7f1863b21bbe6f112b06c4aad05 -Author: Jeroen Demeyer -Date: Thu Feb 14 10:02:41 2019 +0100 - - @cython.trashcan directive to enable the Python trashcan for deallocations - -diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py -index d5742de..27fcad6 100644 ---- a/Cython/Compiler/ModuleNode.py -+++ b/Cython/Compiler/ModuleNode.py -@@ -1426,6 +1426,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): - - is_final_type = scope.parent_type.is_final_type - needs_gc = scope.needs_gc() -+ needs_trashcan = scope.needs_trashcan() - - weakref_slot = scope.lookup_here("__weakref__") if not scope.is_closure_class_scope else None - if weakref_slot not in scope.var_entries: -@@ -1464,6 +1465,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): - # running this destructor. - code.putln("PyObject_GC_UnTrack(o);") - -+ if needs_trashcan: -+ code.globalstate.use_utility_code( -+ UtilityCode.load_cached("PyTrashcan", "ExtensionTypes.c")) -+ code.putln("__Pyx_TRASHCAN_BEGIN(o, %s)" % slot_func_cname) -+ - # call the user's __dealloc__ - self.generate_usr_dealloc_call(scope, code) - -@@ -1537,6 +1543,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): - code.putln("(*Py_TYPE(o)->tp_free)(o);") - if freelist_size: - code.putln("}") -+ -+ if needs_trashcan: -+ code.putln("__Pyx_TRASHCAN_END") -+ - code.putln( - "}") - -diff --git a/Cython/Compiler/Options.py b/Cython/Compiler/Options.py -index d859c19..19d96f1 100644 ---- a/Cython/Compiler/Options.py -+++ b/Cython/Compiler/Options.py -@@ -313,6 +313,7 @@ directive_types = { - 'freelist': int, - 'c_string_type': one_of('bytes', 'bytearray', 'str', 'unicode'), - 'c_string_encoding': normalise_encoding_name, -+ 'trashcan': bool, - } - - for key, val in _directive_defaults.items(): -@@ -355,6 +356,7 @@ directive_scopes = { # defaults to available everywhere - 'np_pythran': ('module',), - 'fast_gil': ('module',), - 'iterable_coroutine': ('module', 'function'), -+ 'trashcan' : ('cclass',), - } - - -diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py -index 3b572d6..f200c5f 100644 ---- a/Cython/Compiler/PyrexTypes.py -+++ b/Cython/Compiler/PyrexTypes.py -@@ -1136,6 +1136,7 @@ class PyObjectType(PyrexType): - is_extern = False - is_subclassed = False - is_gc_simple = False -+ builtin_trashcan = False # builtin type using trashcan - - def __str__(self): - return "Python object" -@@ -1190,10 +1191,14 @@ class PyObjectType(PyrexType): - - - builtin_types_that_cannot_create_refcycles = set([ -- 'bool', 'int', 'long', 'float', 'complex', -+ 'object', 'bool', 'int', 'long', 'float', 'complex', - 'bytearray', 'bytes', 'unicode', 'str', 'basestring' - ]) - -+builtin_types_with_trashcan = set([ -+ 'dict', 'list', 'set', 'frozenset', 'tuple', 'type', -+]) -+ - - class BuiltinObjectType(PyObjectType): - # objstruct_cname string Name of PyObject struct -@@ -1218,6 +1223,7 @@ class BuiltinObjectType(PyObjectType): - self.typeptr_cname = "(&%s)" % cname - self.objstruct_cname = objstruct_cname - self.is_gc_simple = name in builtin_types_that_cannot_create_refcycles -+ self.builtin_trashcan = name in builtin_types_with_trashcan - if name == 'type': - # Special case the type type, as many C API calls (and other - # libraries) actually expect a PyTypeObject* for type arguments. -diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py -index f7443cb..d44484d 100644 ---- a/Cython/Compiler/Symtab.py -+++ b/Cython/Compiler/Symtab.py -@@ -2085,6 +2085,22 @@ class CClassScope(ClassScope): - return not self.parent_type.is_gc_simple - return False - -+ def needs_trashcan(self): -+ # If the trashcan directive is explicitly set to False, -+ # unconditionally disable the trashcan. -+ directive = self.directives.get('trashcan') -+ if directive is False: -+ return False -+ # If the directive is set to True and the class has Python-valued -+ # C attributes, then it should use the trashcan in tp_dealloc. -+ if directive and self.has_cyclic_pyobject_attrs: -+ return True -+ # Use the trashcan if the base class uses it -+ base_type = self.parent_type.base_type -+ if base_type and base_type.scope is not None: -+ return base_type.scope.needs_trashcan() -+ return self.parent_type.builtin_trashcan -+ - def needs_tp_clear(self): - """ - Do we need to generate an implementation for the tp_clear slot? Can -diff --git a/Cython/Utility/ExtensionTypes.c b/Cython/Utility/ExtensionTypes.c -index 50d0e21..ca2adbe 100644 ---- a/Cython/Utility/ExtensionTypes.c -+++ b/Cython/Utility/ExtensionTypes.c -@@ -74,6 +74,54 @@ static int __Pyx_PyType_Ready(PyTypeObject *t) { - return r; - } - -+/////////////// PyTrashcan.proto /////////////// -+ -+// These macros are taken from https://github.com/python/cpython/pull/11841 -+// Unlike the Py_TRASHCAN_SAFE_BEGIN/Py_TRASHCAN_SAFE_END macros, they -+// allow dealing correctly with subclasses. -+ -+// This requires CPython version >= 2.7.4 -+// (or >= 3.2.4 but we don't support such old Python 3 versions anyway) -+#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03080000 -+// https://github.com/python/cpython/pull/11841 merged so Cython reimplementation -+// is no longer necessary -+#define __Pyx_TRASHCAN_BEGIN Py_TRASHCAN_BEGIN -+#define __Pyx_TRASHCAN_END Py_TRASHCAN_END -+#elif CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02070400 -+#define __Pyx_TRASHCAN_BEGIN_CONDITION(op, cond) \ -+ do { \ -+ PyThreadState *_tstate = NULL; \ -+ // If "cond" is false, then _tstate remains NULL and the deallocator -+ // is run normally without involving the trashcan -+ if (cond) { \ -+ _tstate = PyThreadState_GET(); \ -+ if (_tstate->trash_delete_nesting >= PyTrash_UNWIND_LEVEL) { \ -+ // Store the object (to be deallocated later) and jump past -+ // Py_TRASHCAN_END, skipping the body of the deallocator -+ _PyTrash_thread_deposit_object((PyObject*)(op)); \ -+ break; \ -+ } \ -+ ++_tstate->trash_delete_nesting; \ -+ } -+ // The body of the deallocator is here. -+#define __Pyx_TRASHCAN_END \ -+ if (_tstate) { \ -+ --_tstate->trash_delete_nesting; \ -+ if (_tstate->trash_delete_later && _tstate->trash_delete_nesting <= 0) \ -+ _PyTrash_thread_destroy_chain(); \ -+ } \ -+ } while (0); -+ -+#define __Pyx_TRASHCAN_BEGIN(op, dealloc) __Pyx_TRASHCAN_BEGIN_CONDITION(op, \ -+ Py_TYPE(op)->tp_dealloc == (destructor)(dealloc)) -+ -+#else -+// The trashcan is a no-op on other Python implementations -+// or old CPython versions -+#define __Pyx_TRASHCAN_BEGIN(op, dealloc) -+#define __Pyx_TRASHCAN_END -+#endif -+ - /////////////// CallNextTpDealloc.proto /////////////// - - static void __Pyx_call_next_tp_dealloc(PyObject* obj, destructor current_tp_dealloc); From 4a50dc19995c33ce4bffd1775dd242e3584d1818 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Tue, 8 Aug 2023 00:54:01 +0800 Subject: [PATCH 41/44] add cython3 patches for cysignals, cypari2, fpylll, and pplpy --- .../pkgs/cypari/patches/cython3-legacy.patch | 32 ++++++++++++++++ .../cysignals/patches/cython3-legacy.patch | 30 +++++++++++++++ .../pkgs/fpylll/patches/cython3-legacy.patch | 37 +++++++++++++++++++ build/pkgs/pplpy/patches/cython3-legacy.patch | 22 +++++++++++ .../pkgs/pplpy/patches/relative-import.patch | 21 +++++++++++ 5 files changed, 142 insertions(+) create mode 100644 build/pkgs/cypari/patches/cython3-legacy.patch create mode 100644 build/pkgs/cysignals/patches/cython3-legacy.patch create mode 100644 build/pkgs/fpylll/patches/cython3-legacy.patch create mode 100644 build/pkgs/pplpy/patches/cython3-legacy.patch create mode 100644 build/pkgs/pplpy/patches/relative-import.patch diff --git a/build/pkgs/cypari/patches/cython3-legacy.patch b/build/pkgs/cypari/patches/cython3-legacy.patch new file mode 100644 index 00000000000..41392fe80d7 --- /dev/null +++ b/build/pkgs/cypari/patches/cython3-legacy.patch @@ -0,0 +1,32 @@ +commit 8ef356a4eb936c37f55a5c501f3a955e6740c0c5 +Author: Gonzalo Tornaría +Date: Wed Jul 19 19:45:23 2023 -0300 + + cython3 support using legacy directives + +diff --git a/cypari2/gen.pyx b/cypari2/gen.pyx +index 247b1ad..75050a0 100644 +--- a/cypari2/gen.pyx ++++ b/cypari2/gen.pyx +@@ -329,7 +329,7 @@ cdef class Gen(Gen_base): + >>> pari = Pari() + >>> L = pari("vector(10,i,i^2)") + >>> L.__iter__() +- ++ <...generator object at ...> + >>> [x for x in L] + [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] + >>> list(L) +diff --git a/setup.py b/setup.py +index 2188711..455337f 100755 +--- a/setup.py ++++ b/setup.py +@@ -36,6 +36,8 @@ class build_ext(_build_ext): + "binding": True, + "cdivision": True, + "language_level": 2, ++ "legacy_implicit_noexcept": True, ++ "c_api_binop_methods": True, + } + + _build_ext.finalize_options(self) diff --git a/build/pkgs/cysignals/patches/cython3-legacy.patch b/build/pkgs/cysignals/patches/cython3-legacy.patch new file mode 100644 index 00000000000..274575d5d35 --- /dev/null +++ b/build/pkgs/cysignals/patches/cython3-legacy.patch @@ -0,0 +1,30 @@ +commit 9996a4028ddc7f9a5ffda3df65d5b7d3b7df8aa5 +Author: Gonzalo Tornaría +Date: Wed Jul 19 18:34:57 2023 -0300 + + cython3 support using legacy directives + +diff --git a/setup.py b/setup.py +index 37acdfc..f68270b 100755 +--- a/setup.py ++++ b/setup.py +@@ -157,13 +157,17 @@ class build_ext(_build_ext): + # Run Cython with -Werror on continuous integration services + # with Python 3.6 or later + from Cython.Compiler import Options +- Options.warning_errors = True ++ Options.warning_errors = False + + from Cython.Build.Dependencies import cythonize + return cythonize(extensions, + build_dir=cythonize_dir, + include_path=["src", os.path.join(cythonize_dir, "src")], +- compiler_directives=dict(binding=True, language_level=2)) ++ compiler_directives=dict( ++ binding=True, ++ language_level=2, ++ legacy_implicit_noexcept=True, ++ )) + + + class build_py(_build_py): diff --git a/build/pkgs/fpylll/patches/cython3-legacy.patch b/build/pkgs/fpylll/patches/cython3-legacy.patch new file mode 100644 index 00000000000..808c14e9c1b --- /dev/null +++ b/build/pkgs/fpylll/patches/cython3-legacy.patch @@ -0,0 +1,37 @@ +commit b6e12c2b0648e84b26dcf0aac507a5b4d9dde301 +Author: Gonzalo Tornaría +Date: Wed Jul 19 20:38:01 2023 -0300 + + cython3 support using legacy directives + +diff --git a/setup.py b/setup.py +index 274836f..8fc5af5 100755 +--- a/setup.py ++++ b/setup.py +@@ -123,7 +123,12 @@ class build_ext(_build_ext, object): + self.extensions, + include_path=["src"], + build_dir=self.cythonize_dir, +- compiler_directives={"binding": True, "embedsignature": True, "language_level": 2}, ++ compiler_directives={ ++ "binding": True, ++ "embedsignature": True, ++ "language_level": 2, ++ "legacy_implicit_noexcept": True, ++ }, + ) + super(build_ext, self).run() + +diff --git a/src/fpylll/fplll/enumeration_callback_helper.h b/src/fpylll/fplll/enumeration_callback_helper.h +index c099430..706162f 100644 +--- a/src/fpylll/fplll/enumeration_callback_helper.h ++++ b/src/fpylll/fplll/enumeration_callback_helper.h +@@ -5,7 +5,7 @@ + #include + #include + +-extern "C" { ++extern "C++" { + bool evaluator_callback_call_obj(PyObject *obj, int n, double *new_sol_coord); + } + diff --git a/build/pkgs/pplpy/patches/cython3-legacy.patch b/build/pkgs/pplpy/patches/cython3-legacy.patch new file mode 100644 index 00000000000..a038da16d6b --- /dev/null +++ b/build/pkgs/pplpy/patches/cython3-legacy.patch @@ -0,0 +1,22 @@ +commit e6f3e66154138ce3e31e803e74b8c71787c70acc +Author: Gonzalo Tornaría +Date: Wed Jul 19 20:47:52 2023 -0300 + + cython3 support using legacy directives + +diff --git a/setup.py b/setup.py +index 13d543b..55dcd34 100755 +--- a/setup.py ++++ b/setup.py +@@ -38,7 +38,11 @@ class build_ext(_build_ext): + self.extensions[:] = cythonize( + self.extensions, + include_path=sys.path, +- compiler_directives={'embedsignature': True}) ++ compiler_directives={ ++ 'embedsignature': True, ++ 'legacy_implicit_noexcept': True, ++ 'c_api_binop_methods': True, ++ }) + + _build_ext.run(self) diff --git a/build/pkgs/pplpy/patches/relative-import.patch b/build/pkgs/pplpy/patches/relative-import.patch new file mode 100644 index 00000000000..3c011203367 --- /dev/null +++ b/build/pkgs/pplpy/patches/relative-import.patch @@ -0,0 +1,21 @@ +From aaa28537fa7ea061ebb8d5131b1e23673eaf741d Mon Sep 17 00:00:00 2001 +From: Matthias Koeppe +Date: Sun, 31 Jul 2022 12:39:34 -0700 +Subject: [PATCH] ppl/bit_arrays.pxd: Use relative cimport + +--- + ppl/bit_arrays.pxd | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/ppl/bit_arrays.pxd b/ppl/bit_arrays.pxd +index eb57434..145a978 100644 +--- a/ppl/bit_arrays.pxd ++++ b/ppl/bit_arrays.pxd +@@ -1,4 +1,4 @@ +-from ppl_decl cimport * ++from .ppl_decl cimport * + + cdef class Bit_Row(object): + cdef PPL_Bit_Row *thisptr +-- +GitLab From c50d2db2dc500f6a92ff925ae54b848d0eb6a141 Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Tue, 8 Aug 2023 11:29:28 +0800 Subject: [PATCH 42/44] add cython3 patch for scipy --- build/pkgs/scipy/patches/cython3-legacy.patch | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 build/pkgs/scipy/patches/cython3-legacy.patch diff --git a/build/pkgs/scipy/patches/cython3-legacy.patch b/build/pkgs/scipy/patches/cython3-legacy.patch new file mode 100644 index 00000000000..9abf0c02154 --- /dev/null +++ b/build/pkgs/scipy/patches/cython3-legacy.patch @@ -0,0 +1,91 @@ +diff --git a/scipy/linalg.pxd b/scipy/linalg.pxd +index 1f656b87..c7c49f9a 100644 +--- a/scipy/linalg.pxd ++++ b/scipy/linalg.pxd +@@ -1 +1 @@ +-from .linalg cimport cython_blas, cython_lapack ++from scipy.linalg cimport cython_blas, cython_lapack +diff --git a/scipy/meson.build b/scipy/meson.build +index 21ea04d5..71d54804 100644 +--- a/scipy/meson.build ++++ b/scipy/meson.build +@@ -197,7 +197,7 @@ _cython_tree = [ + fs.copyfile('special.pxd'), + ] + +-cython_args = ['-3', '--fast-fail', '--output-file', '@OUTPUT@', '--include-dir', '@BUILD_ROOT@', '@INPUT@'] ++cython_args = ['-3', '--fast-fail', '--directive', 'legacy_implicit_noexcept=True', '--output-file', '@OUTPUT@', '--include-dir', '@BUILD_ROOT@', '@INPUT@'] + cython_cplus_args = ['--cplus'] + cython_args + + cython_gen = generator(cython, +diff --git a/scipy/optimize/cython_optimize.pxd b/scipy/optimize/cython_optimize.pxd +index d5a0bdd7..d35f8da6 100644 +--- a/scipy/optimize/cython_optimize.pxd ++++ b/scipy/optimize/cython_optimize.pxd +@@ -7,5 +7,5 @@ + # support. Changing it causes an ABI forward-compatibility break + # (gh-11793), so we currently leave it as is (no further cimport + # statements should be used in this file). +-from .cython_optimize._zeros cimport ( ++from scipy.optimize.cython_optimize._zeros cimport ( + brentq, brenth, ridder, bisect, zeros_full_output) +diff --git a/scipy/optimize/meson.build b/scipy/optimize/meson.build +index 05db6a68..07d46fb9 100644 +--- a/scipy/optimize/meson.build ++++ b/scipy/optimize/meson.build +@@ -231,6 +231,10 @@ endif + + _dummy_init_optimize = fs.copyfile('__init__.py') + ++_cython_tree = [ ++ fs.copyfile('cython_optimize.pxd'), ++] ++ + opt_gen = generator(cython, + arguments : cython_args, + output : '@BASENAME@.c', +diff --git a/scipy/special.pxd b/scipy/special.pxd +index 62cb8280..1daa9fb3 100644 +--- a/scipy/special.pxd ++++ b/scipy/special.pxd +@@ -1 +1 @@ +-from .special cimport cython_special ++from scipy.special cimport cython_special +diff --git a/scipy/special/meson.build b/scipy/special/meson.build +index f92183f5..09ad0a4f 100644 +--- a/scipy/special/meson.build ++++ b/scipy/special/meson.build +@@ -362,7 +362,7 @@ py3.extension_module('_ufuncs_cxx', + [ufuncs_cxx_sources, + uf_cython_gen_cpp.process(cython_special[2]), # _ufuncs_cxx.pyx + ], +- cpp_args: cython_cpp_args, ++ cpp_args: [cython_cpp_args, '-DCYTHON_EXTERN_C=extern "C"'], + include_directories: [inc_np, '../_lib/boost', '../_lib', + '../_build_utils/src'], + link_args: version_link_args, +diff --git a/scipy/special/setup.py b/scipy/special/setup.py +index 7e8c9608..b38a6ec2 100644 +--- a/scipy/special/setup.py ++++ b/scipy/special/setup.py +@@ -103,7 +103,7 @@ def configuration(parent_package='',top_path=None): + sources=ufuncs_cxx_src, + depends=ufuncs_cxx_dep, + include_dirs=[curdir] + inc_dirs, +- define_macros=define_macros, ++ define_macros=define_macros + [('CYTHON_EXTERN_C', 'extern "C"')], + extra_info=get_info("npymath")) + ufuncs_cxx_ext._pre_build_hook = set_cxx_flags_hook + +diff --git a/tools/cythonize.py b/tools/cythonize.py +index 402824cb..7ad778da 100755 +--- a/tools/cythonize.py ++++ b/tools/cythonize.py +@@ -94,6 +94,7 @@ def process_pyx(fromfile, tofile, cwd): + flags = ['--fast-fail', '-3'] + if tofile.endswith('.cxx'): + flags += ['--cplus'] ++ flags += ['--directive', 'legacy_implicit_noexcept=true'] + + try: + try: From 3409ddc425a1c6caf79c2fe2d2f8bfed061ce82e Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Tue, 8 Aug 2023 11:30:45 +0800 Subject: [PATCH 43/44] use cython legacy directives for sage --- src/sage_setup/cython_options.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/sage_setup/cython_options.py b/src/sage_setup/cython_options.py index 086aa070ca9..9725ce0e1af 100644 --- a/src/sage_setup/cython_options.py +++ b/src/sage_setup/cython_options.py @@ -10,13 +10,17 @@ def compiler_directives(profile: bool): auto_pickle=False, # Do not create __test__ dictionary automatically from docstrings autotestdict=False, + binding=False, + c_api_binop_methods=True, # Do not check for division by 0 (this is about 35% quicker than with check) cdivision=True, + cpow=True, # Embed a textual copy of the call signature in the docstring (to support tools like IPython) embedsignature=True, fast_getattr=True, # Use Python 3 (including source code semantics) for module compilation language_level="3", + legacy_implicit_noexcept=True, # Enable support for late includes (make declarations in Cython code available to C include files) preliminary_late_includes_cy28=True, # Add hooks for Python profilers into the compiled C code From 27acee3cf3789478dae5d31c7356bb0ddcb33fda Mon Sep 17 00:00:00 2001 From: Yutao Yuan Date: Tue, 8 Aug 2023 13:00:55 +0800 Subject: [PATCH 44/44] remove coxeter CoxGraph which fails to compile with cython 3 --- src/sage/libs/coxeter3/coxeter.pxd | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/sage/libs/coxeter3/coxeter.pxd b/src/sage/libs/coxeter3/coxeter.pxd index 9d5cb2a3f5d..dbd2b8a61c6 100644 --- a/src/sage/libs/coxeter3/coxeter.pxd +++ b/src/sage/libs/coxeter3/coxeter.pxd @@ -29,6 +29,3 @@ cdef class CoxGroupElement: cdef CoxGroup _parent_group cdef CoxGroupElement _new(self) cpdef CoxGroup parent_group(self) - -cdef class CoxGraph: - cdef c_CoxGraph x