Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
gh-36933: More conversion to parent
    
a few more conversions from `Ring` (old coercion framework) to `Parent`
(new coercion framework),

### 📝 Checklist

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.
    
URL: #36933
Reported by: Frédéric Chapoton
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Jan 12, 2024
2 parents 8209075 + 1cb499e commit 6df3377
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,22 +185,23 @@
Classes and Methods
===================
"""
#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2008 Alexander Raichev <[email protected]>
# Copyright (C) 2014, 2016 Daniel Krenn <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
# https://www.gnu.org/licenses/
# ****************************************************************************

from functools import total_ordering
from itertools import combinations_with_replacement

from sage.structure.element import RingElement
from sage.structure.unique_representation import UniqueRepresentation
from sage.rings.ring import Ring
from sage.structure.parent import Parent
from sage.calculus.var import var
from sage.calculus.functional import diff
from sage.symbolic.ring import SR
Expand Down Expand Up @@ -1507,7 +1508,7 @@ def asymptotic_decomposition(self, alpha, asy_var=None):
for f in decomp2:
ff = self.parent()((f.numerator() /
cauchy_stuff).simplify_full().collect(asy_var),
f.denominator_factored())
f.denominator_factored())
decomp3.append(ff)

return decomp3
Expand Down Expand Up @@ -2248,9 +2249,9 @@ def asymptotics_multiple(self, p, alpha, N, asy_var, coordinate=None,
if verbose:
print("Computing derivatives of auxiliary functions...")
m = min(n, N)
end = [X[d-1] for j in range(n)]
end = [X[d - 1] for j in range(n)]
Hprodderivs = diff_all(Hprod, X, 2 * N - 2 + n, ending=end, sub_final=P)
atP.update({U.subs(P): diff(Hprod, X[d - 1], n).subs(P)/factorial(n)})
atP.update({U.subs(P): diff(Hprod, X[d - 1], n).subs(P) / factorial(n)})
Uderivs = {}
k = Hprod.polynomial(CC).degree() - n
if k == 0:
Expand Down Expand Up @@ -2327,7 +2328,7 @@ def asymptotics_multiple(self, p, alpha, N, asy_var, coordinate=None,
(-1) ** (q - j - k)
for (j, k) in product(range(min(n - 1, q) + 1),
range(max(0, q - n),
q + 1))
q + 1))
if j + k <= q])
for q in range(N)])
chunk = chunk.subs(P).simplify()
Expand Down Expand Up @@ -2936,7 +2937,7 @@ def relative_error(self, approx, alpha, interval, exp_scale=Integer(1),
alpha = vector(alpha)
multi_indices = [r * alpha for r in interval]
mac = self.maclaurin_coefficients(multi_indices, numerical=digits)
#mac = self.old_maclaurin_coefficients(alpha, max(interval))
# mac = self.old_maclaurin_coefficients(alpha, max(interval))
mac_approx = {}
stats = []
for r in interval:
Expand Down Expand Up @@ -3010,7 +3011,7 @@ def _mul_(left, right):
return left.parent()(numer, df)


class FractionWithFactoredDenominatorRing(UniqueRepresentation, Ring):
class FractionWithFactoredDenominatorRing(UniqueRepresentation, Parent):
r"""
This is the ring of fractions with factored denominator.
Expand Down Expand Up @@ -3053,7 +3054,8 @@ def __classcall_private__(cls, denominator_ring, numerator_ring=None, category=N
sage: from sage.rings.asymptotic.asymptotics_multivariate_generating_functions import FractionWithFactoredDenominatorRing
sage: R.<x,y> = PolynomialRing(QQ)
sage: FFPD1 = FractionWithFactoredDenominatorRing(R)
sage: FFPD2 = FractionWithFactoredDenominatorRing(R, R, Rings())
sage: cat = Rings().Commutative()
sage: FFPD2 = FractionWithFactoredDenominatorRing(R, R, cat)
sage: FFPD1 is FFPD2
True
"""
Expand All @@ -3063,7 +3065,7 @@ def __classcall_private__(cls, denominator_ring, numerator_ring=None, category=N
raise ValueError('numerator ring {} has no coercion map from the '
'denominator ring {}'.format(
numerator_ring, denominator_ring))
category = Rings().or_subcategory(category)
category = Rings().Commutative().or_subcategory(category)
return super().__classcall__(cls, denominator_ring,
numerator_ring, category)

Expand All @@ -3081,11 +3083,11 @@ def __init__(self, denominator_ring, numerator_ring=None, category=None):
"""
self._numerator_ring = numerator_ring
self._denominator_ring = denominator_ring
Ring.__init__(self, denominator_ring, category=category)
Parent.__init__(self, denominator_ring, category=category)

def _repr_(self):
r"""
Returns a representation.
Return a representation.
OUTPUT:
Expand Down Expand Up @@ -3614,7 +3616,7 @@ def sum(self):


#####################################################################
## Helper functions
# Helper functions


def diff_prod(f_derivs, u, g, X, interval, end, uderivs, atc):
Expand Down Expand Up @@ -3829,7 +3831,7 @@ def subs_all(f, sub, simplify=False):


def diff_all(f, V, n, ending=[], sub=None, sub_final=None,
zero_order=0, rekey=None):
zero_order=0, rekey=None):
r"""
Return a dictionary of representative mixed partial
derivatives of `f` from order 1 up to order `n` with respect to the
Expand Down
6 changes: 3 additions & 3 deletions src/sage/rings/complex_double.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ cdef extern from "<complex.h>":
import sage.rings.abc
cimport sage.rings.ring
cimport sage.rings.integer
from sage.rings.ring import Ring

from sage.structure.element cimport Element, FieldElement
from sage.structure.parent cimport Parent
from sage.structure.parent cimport Parent
from sage.structure.richcmp cimport rich_to_bool
from sage.categories.morphism cimport Morphism
from sage.structure.coerce cimport is_numpy_type
Expand Down Expand Up @@ -149,7 +148,8 @@ cdef class ComplexDoubleField_class(sage.rings.abc.ComplexDoubleField):
(-1.0, -1.0 + 1.2246...e-16*I, False)
"""
from sage.categories.fields import Fields
Ring.__init__(self, self, ('I',), normalize=False, category=Fields().Infinite().Metric().Complete())
Parent.__init__(self, self, names=('I',), normalize=False,
category=Fields().Infinite().Metric().Complete())
self._populate_coercion_lists_()

def __reduce__(self):
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/complex_mpc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ from sage.structure.element cimport Element
from sage.structure.richcmp cimport rich_to_bool
from sage.categories.map cimport Map
from sage.libs.pari.all import pari
from sage.rings.ring import Ring

from sage.rings.integer cimport Integer
from sage.rings.complex_mpfr cimport ComplexNumber
Expand Down Expand Up @@ -319,7 +318,8 @@ cdef class MPComplexField_class(sage.rings.ring.Field):
self.__real_field = real_mpfr.RealField(prec, rnd=_mpfr_rounding_modes[rnd_re(n)])
self.__imag_field = real_mpfr.RealField(prec, rnd=_mpfr_rounding_modes[rnd_im(n)])

Ring.__init__(self, self._real_field(), ('I',), False, category=Fields().Infinite())
Parent.__init__(self, self._real_field(), names=('I',), normalize=False,
category=Fields().Infinite())
self._populate_coercion_lists_(coerce_list=[MPFRtoMPC(self._real_field(), self)])

cdef MPComplexNumber _new(self) noexcept:
Expand Down
7 changes: 4 additions & 3 deletions src/sage/rings/complex_mpfr.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ import sage.misc.misc

from sage.libs.mpfr cimport *

from sage.structure.parent cimport Parent
from sage.structure.element cimport RingElement, Element
from sage.structure.richcmp cimport rich_to_bool
from sage.categories.map cimport Map
from sage.structure.parent import Parent
from sage.rings.ring import Ring

from sage.misc.sage_eval import sage_eval

Expand Down Expand Up @@ -282,7 +281,9 @@ class ComplexField_class(sage.rings.abc.ComplexField):
"""
self._prec = int(prec)
from sage.categories.fields import Fields
Ring.__init__(self, self._real_field(), ('I',), False, category=Fields().Infinite().Metric().Complete())
Parent.__init__(self, self._real_field(), names=('I',),
normalize=False,
category=Fields().Infinite().Metric().Complete())
self._populate_coercion_lists_(coerce_list=[RRtoCC(self._real_field(), self)],
convert_method_name='_complex_mpfr_')

Expand Down
17 changes: 10 additions & 7 deletions src/sage/rings/real_mpfr.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,20 @@ from sage.libs.mpfr cimport *
from sage.libs.mpmath.utils cimport mpfr_to_mpfval
from sage.misc.randstate cimport randstate, current_randstate
from sage.misc.superseded import deprecation_cython as deprecation
from sage.rings.integer cimport Integer
from sage.rings.rational cimport Rational
from sage.rings.real_double cimport RealDoubleElement
from sage.rings.ring import Ring

from sage.structure.element cimport Element
from sage.structure.parent cimport Parent
from sage.structure.element cimport have_same_parent
from sage.structure.parent_gens cimport ParentWithGens
from sage.structure.richcmp cimport rich_to_bool_sgn

cdef bin_op
from sage.structure.element import bin_op

from sage.libs.mpmath.utils cimport mpfr_to_mpfval

from sage.rings.integer cimport Integer
from sage.rings.rational cimport Rational
from sage.rings.real_double cimport RealDoubleElement

try:
from cypari2 import Gen
from sage.libs.pari.convert_sage_real_mpfr import new_gen_from_real_mpfr_element, set_real_mpfr_element_from_gen
Expand Down Expand Up @@ -530,7 +532,8 @@ cdef class RealField_class(sage.rings.abc.RealField):
self.rnd_str = char_to_str(rnd_str + 5) # Strip "MPFR_"

from sage.categories.fields import Fields
Ring.__init__(self, self, tuple(), False, category=Fields().Infinite().Metric().Complete())
Parent.__init__(self, self, names=tuple(), normalize=False,
category=Fields().Infinite().Metric().Complete())

# Initialize zero and one
cdef RealNumber rn
Expand Down

0 comments on commit 6df3377

Please sign in to comment.