Skip to content

Commit

Permalink
gh-37069: Use Parent in number fields and QQ
Browse files Browse the repository at this point in the history
    
Towards the removal of `ParentWithGens` : use parent in number fields
and in QQ

### 📝 Checklist

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
    
URL: #37069
Reported by: Frédéric Chapoton
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Jan 20, 2024
2 parents d79e87b + 936661d commit e31cc79
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
7 changes: 3 additions & 4 deletions src/sage/rings/number_field/number_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@
# ****************************************************************************
from __future__ import annotations
from sage.misc.cachefunc import cached_method
from sage.misc.superseded import (deprecation,
deprecated_function_alias)
from sage.misc.superseded import deprecation


import sage.libs.ntl.all as ntl
Expand Down Expand Up @@ -109,6 +108,7 @@
from .class_group import SClassGroup

from sage.structure.element import is_Element
from sage.structure.parent import Parent
from sage.structure.sequence import Sequence
from sage.structure.factorization import Factorization
from sage.structure.category_object import normalize_names
Expand Down Expand Up @@ -209,7 +209,6 @@ def proof_flag(t):
import sage.groups.abelian_gps.abelian_group
import sage.rings.complex_interval_field

from sage.structure.parent_gens import ParentWithGens
from sage.structure.factory import UniqueFactory
from . import number_field_element
from . import number_field_element_quadratic
Expand Down Expand Up @@ -1379,7 +1378,7 @@ def __init__(self, polynomial, name, latex_name,
else:
assert category.is_subcategory(default_category), "%s is not a subcategory of %s" % (category, default_category)

ParentWithGens.__init__(self, QQ, name, category=category)
Parent.__init__(self, base=QQ, names=name, category=category)
if not isinstance(polynomial, polynomial_element.Polynomial):
raise TypeError("polynomial (=%s) must be a polynomial" % repr(polynomial))

Expand Down
25 changes: 13 additions & 12 deletions src/sage/rings/rational_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
import sage.rings.number_field.number_field_base as number_field_base
from sage.misc.fast_methods import Singleton
from sage.misc.superseded import deprecated_function_alias
from sage.structure.parent_gens import ParentWithGens
from sage.structure.parent import Parent
from sage.structure.sequence import Sequence


Expand Down Expand Up @@ -235,8 +235,9 @@ def __init__(self):
"""
from sage.categories.basic import QuotientFields
from sage.categories.number_fields import NumberFields
ParentWithGens.__init__(self, self, category=[QuotientFields().Metric(),
NumberFields()])
Parent.__init__(self, base=self,
category=[QuotientFields().Metric(),
NumberFields()])
self._assign_names(('x',), normalize=False) # ?????
self._populate_coercion_lists_(init_no_parent=True)

Expand Down Expand Up @@ -862,7 +863,7 @@ def hilbert_symbol_negative_at_S(self, S, b, check=True):
if p != infty:
if check and not is_prime(p):
raise ValueError("all entries in list must be prime"
" or -1 for infinite place")
" or -1 for infinite place")
R = Qp(p)
if R(b).is_square():
raise ValueError("second argument must be a nonsquare with"
Expand Down Expand Up @@ -1055,7 +1056,7 @@ def power_basis(self):
sage: QQ.power_basis()
[1]
"""
return [ self.gen() ]
return [self.gen()]

def extension(self, poly, names, **kwds):
r"""
Expand Down Expand Up @@ -1133,7 +1134,7 @@ def _an_element_(self):
sage: QQ.an_element() # indirect doctest
1/2
"""
return Rational((1,2))
return Rational((1, 2))

def some_elements(self):
r"""
Expand Down Expand Up @@ -1247,7 +1248,7 @@ def random_element(self, num_bound=None, den_bound=None, *args, **kwds):
den = ZZ.random_element(1, den_bound+1, *args, **kwds)
while den == 0:
den = ZZ.random_element(1, den_bound+1, *args, **kwds)
return self((num,den))
return self((num, den))

def zeta(self, n=2):
"""
Expand Down Expand Up @@ -1381,7 +1382,7 @@ def selmer_group_iterator(self, S, m, proof=True):

from sage.misc.misc_c import prod
for ev in product(*[range(o) for o in ords]):
yield prod((p**e for p,e in zip(KSgens, ev)), one)
yield prod((p**e for p, e in zip(KSgens, ev)), one)

def selmer_space(self, S, p, proof=None):
r"""
Expand Down Expand Up @@ -1520,7 +1521,7 @@ def quadratic_defect(self, a, p, check=True):
return v + 1

#################################
## Coercions to interfaces
# Coercions to interfaces
#################################
def _gap_init_(self):
r"""
Expand Down Expand Up @@ -1658,12 +1659,12 @@ def _factor_univariate_polynomial(self, f):
(10) * (x^5 - 1/10)
sage: QQ._factor_univariate_polynomial(10*x^5 - 10)
(10) * (x - 1) * (x^4 + x^3 + x^2 + x + 1)
"""
G = list(f._pari_with_name().factor())
G = f._pari_with_name().factor()

# normalize the leading coefficients
F = [(f.parent()(g).monic(), int(e)) for (g,e) in zip(*G)]
P = f.parent()
F = [(P(g).monic(), int(e)) for g, e in zip(*G)]

from sage.structure.factorization import Factorization
return Factorization(F, f.leading_coefficient())
Expand Down

0 comments on commit e31cc79

Please sign in to comment.