Skip to content

Commit

Permalink
sagemathgh-38124: Deprecate is_NumberFieldOrder, `is_AbsoluteNumber…
Browse files Browse the repository at this point in the history
…Field`, `is_RelativeNumberField`, `is_NumberFieldIdeal`, `is_NumberFieldFractionalIdeal`, `is_NumberFieldFractionalIdeal_rel`

    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->



### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [ ] 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 and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#38124
Reported by: Matthias Köppe
Reviewer(s): Kwankyu Lee, Matthias Köppe
  • Loading branch information
Release Manager committed Jun 3, 2024
2 parents 5a1ca31 + 8f764a6 commit b72d135
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 47 deletions.
3 changes: 1 addition & 2 deletions src/sage/dynamics/arithmetic_dynamics/projective_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -5893,8 +5893,7 @@ def sigma_invariants(self, n, formal=False, embedding=None, type='point',
base_ring = base_ring.base_ring()
elif base_ring in FunctionFields():
base_ring = base_ring.constant_base_field()
from sage.rings.number_field.order import is_NumberFieldOrder
if not (base_ring in NumberFields() or is_NumberFieldOrder(base_ring)
if not (base_ring in NumberFields() or base_ring == ZZ or isinstance(base_ring, sage.rings.abc.Order)
or (base_ring in FiniteFields())):
raise NotImplementedError("incompatible base field, see documentation")

Expand Down
6 changes: 3 additions & 3 deletions src/sage/rings/finite_rings/residue_field.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ from sage.rings.finite_rings.finite_field_constructor import zech_log_bound, Fin
from sage.rings.finite_rings.finite_field_prime_modn import FiniteField_prime_modn
from sage.rings.ideal import is_Ideal
from sage.rings.number_field.number_field_element_base import NumberFieldElement_base
from sage.rings.number_field.number_field_ideal import is_NumberFieldIdeal
from sage.rings.number_field.number_field_ideal import NumberFieldIdeal

from sage.rings.fraction_field import is_FractionField

Expand Down Expand Up @@ -345,7 +345,7 @@ class ResidueFieldFactory(UniqueFactory):
if not p.ring().base_ring().is_prime_field():
# neither of these will work over non-prime fields quite yet. We should use relative finite field extensions.
raise NotImplementedError
elif not (is_NumberFieldIdeal(p) or p.ring() is ZZ):
elif not (isinstance(p, NumberFieldIdeal) or p.ring() is ZZ):
raise NotImplementedError
if isinstance(names, tuple):
if names:
Expand Down Expand Up @@ -411,7 +411,7 @@ class ResidueFieldFactory(UniqueFactory):
raise ValueError("unrecognized finite field type")

# Should generalize to allowing residue fields of relative extensions to be extensions of finite fields.
if is_NumberFieldIdeal(p):
if isinstance(p, NumberFieldIdeal):
characteristic = p.smallest_integer()
else: # ideal of a function field
characteristic = pring.base_ring().characteristic()
Expand Down
25 changes: 15 additions & 10 deletions src/sage/rings/number_field/number_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@


import sage.libs.ntl.all as ntl

import sage.rings.abc
import sage.rings.complex_mpfr
from sage.rings.polynomial.polynomial_element import Polynomial
import sage.rings.real_mpfr
Expand Down Expand Up @@ -212,7 +212,7 @@ def proof_flag(t):
from sage.structure.factory import UniqueFactory
from . import number_field_element
from . import number_field_element_quadratic
from .number_field_ideal import is_NumberFieldIdeal, NumberFieldFractionalIdeal
from .number_field_ideal import NumberFieldIdeal, NumberFieldFractionalIdeal
from sage.libs.pari.all import pari, pari_gen

from sage.rings.rational_field import QQ
Expand Down Expand Up @@ -1018,6 +1018,9 @@ def is_AbsoluteNumberField(x):
sage: from sage.rings.number_field.number_field import is_AbsoluteNumberField
sage: x = polygen(ZZ, 'x')
sage: is_AbsoluteNumberField(NumberField(x^2 + 1, 'a'))
doctest:warning...
DeprecationWarning: The function is_AbsoluteNumberField is deprecated; use 'isinstance(..., NumberField_absolute)' instead.
See https://github.com/sagemath/sage/issues/38124 for details.
True
sage: is_AbsoluteNumberField(NumberField([x^3 + 17, x^2 + 1], 'a'))
False
Expand All @@ -1030,6 +1033,10 @@ def is_AbsoluteNumberField(x):
sage: is_AbsoluteNumberField(QQ)
False
"""
from sage.misc.superseded import deprecation
deprecation(38124,
"The function is_AbsoluteNumberField is deprecated; "
"use 'isinstance(..., NumberField_absolute)' instead.")
return isinstance(x, NumberField_absolute)


Expand Down Expand Up @@ -6953,16 +6960,15 @@ def residue_field(self, prime, names=None, check=True):
...
ValueError: Fractional ideal (5) is not a prime ideal
"""
from sage.rings.number_field.number_field_ideal import is_NumberFieldIdeal
if is_NumberFieldIdeal(prime) and prime.number_field() is not self:
if isinstance(prime, NumberFieldIdeal) and prime.number_field() is not self:
raise ValueError("%s is not an ideal of %s" % (prime, self))
# This allows principal ideals to be specified using a generator:
try:
prime = self.ideal(prime)
except TypeError:
pass

if not is_NumberFieldIdeal(prime) or prime.number_field() is not self:
if not isinstance(prime, NumberFieldIdeal) or prime.number_field() is not self:
raise ValueError("%s is not an ideal of %s" % (prime, self))
if check and not prime.is_prime():
raise ValueError("%s is not a prime ideal" % prime)
Expand Down Expand Up @@ -7088,7 +7094,7 @@ def uniformizer(self, P, others="positive"):
sage: x in (t^2 + 3*t +1, t^2 - 4*t +1)
True
"""
if not is_NumberFieldIdeal(P):
if not isinstance(P, NumberFieldIdeal):
P = self.ideal(P)
P = P.pari_prime()
if others == "positive":
Expand Down Expand Up @@ -8444,10 +8450,9 @@ def _coerce_map_from_(self, R):
"""
if R is int:
return self._generic_coerce_map(R)
elif R in (ZZ, QQ, self.base()):
if R in (ZZ, QQ, self.base()):
return self._generic_coerce_map(R)
from sage.rings.number_field.order import is_NumberFieldOrder
if is_NumberFieldOrder(R) and self.has_coerce_map_from(R.number_field()):
if isinstance(R, sage.rings.abc.Order) and self.has_coerce_map_from(R.number_field()):
return self._generic_coerce_map(R)
# R is not QQ by the above tests
if isinstance(R, number_field_base.NumberField) and R.coerce_embedding() is not None:
Expand Down Expand Up @@ -10348,7 +10353,7 @@ def hilbert_symbol(self, a, b, P=None):
if P(a) > 0 or P(b) > 0:
return 1
return -1
if not is_NumberFieldIdeal(P):
if not isinstance(P, NumberFieldIdeal):
P = self.ideal(P)
if P.number_field() is not self:
raise ValueError("P (=%s) should be an ideal of self (=%s) in hilbert_symbol, not of %s" % (P, self, P.number_field()))
Expand Down
19 changes: 9 additions & 10 deletions src/sage/rings/number_field/number_field_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ from sage.libs.gmp.pylong cimport mpz_pythonhash
from cpython.object cimport Py_EQ, Py_NE, Py_LT, Py_GT, Py_LE, Py_GE
from sage.structure.richcmp cimport rich_to_bool

import sage.rings.abc
import sage.rings.polynomial.polynomial_element
from sage.rings.polynomial.evaluation_ntl cimport ZZX_evaluation_mpfi
import sage.rings.rational_field
Expand Down Expand Up @@ -1663,8 +1664,8 @@ cdef class NumberFieldElement(NumberFieldElement_base):
if not isinstance(L, NumberField):
raise ValueError("L (=%s) must be a NumberField in is_norm" % L)

from sage.rings.number_field.number_field import is_AbsoluteNumberField
if is_AbsoluteNumberField(L):
from sage.rings.number_field.number_field import NumberField_absolute
if isinstance(L, NumberField_absolute):
Lrel = L.relativize(K.hom(L), L.variable_name() + '0')
b, x = self.is_norm(Lrel, element=True, proof=proof)
h = Lrel.structure()[0]
Expand Down Expand Up @@ -1803,8 +1804,8 @@ cdef class NumberFieldElement(NumberFieldElement_base):
- Francis Clarke (2010-12-26)
"""
K = self.parent()
from sage.rings.number_field.number_field_rel import is_RelativeNumberField
if (not is_RelativeNumberField(L)) or L.base_field() != K:
from sage.rings.number_field.number_field_rel import NumberField_relative
if not isinstance(L, NumberField_relative) or L.base_field() != K:
raise ValueError("L (=%s) must be a relative number field with base field K (=%s) in rnfisnorm" % (L, K))

rnf_data = K.pari_rnfnorm_data(L, proof=proof)
Expand Down Expand Up @@ -1988,8 +1989,7 @@ cdef class NumberFieldElement(NumberFieldElement_base):
raise ArithmeticError("factorization of 0 is not defined")

K = self.parent()
from sage.rings.number_field.order import is_NumberFieldOrder
if is_NumberFieldOrder(K):
if isinstance(K, sage.rings.abc.Order):
K = K.number_field()
fac = K.ideal(self).factor()
# Check whether all prime ideals in `fac` are principal
Expand Down Expand Up @@ -2088,8 +2088,7 @@ cdef class NumberFieldElement(NumberFieldElement_base):
if R.is_field():
return R.one()

from sage.rings.number_field.order import is_NumberFieldOrder
if not is_NumberFieldOrder(R):
if not isinstance(R, sage.rings.abc.Order):
raise NotImplementedError("gcd() for %r is not implemented" % R)

K = R.number_field()
Expand Down Expand Up @@ -3914,8 +3913,8 @@ cdef class NumberFieldElement(NumberFieldElement_base):
...
ValueError: P must be prime
"""
from sage.rings.number_field.number_field_ideal import is_NumberFieldIdeal
if not is_NumberFieldIdeal(P):
from sage.rings.number_field.number_field_ideal import NumberFieldIdeal
if not isinstance(P, NumberFieldIdeal):
if isinstance(P, NumberFieldElement):
P = self.number_field().fractional_ideal(P)
else:
Expand Down
16 changes: 16 additions & 0 deletions src/sage/rings/number_field/number_field_ideal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,10 @@ def is_NumberFieldIdeal(x):
sage: from sage.rings.number_field.number_field_ideal import is_NumberFieldIdeal
sage: is_NumberFieldIdeal(2/3)
doctest:warning...
DeprecationWarning: The function is_NumberFieldIdeal is deprecated;
use 'isinstance(..., NumberFieldIdeal)' instead.
See https://github.com/sagemath/sage/issues/38124 for details.
False
sage: is_NumberFieldIdeal(ideal(5))
False
Expand All @@ -1804,6 +1808,10 @@ def is_NumberFieldIdeal(x):
sage: is_NumberFieldIdeal(Z)
True
"""
from sage.misc.superseded import deprecation
deprecation(38124,
"The function is_NumberFieldIdeal is deprecated; "
"use 'isinstance(..., NumberFieldIdeal)' instead.")
return isinstance(x, NumberFieldIdeal)


Expand Down Expand Up @@ -3316,6 +3324,10 @@ def is_NumberFieldFractionalIdeal(x):
sage: from sage.rings.number_field.number_field_ideal import is_NumberFieldFractionalIdeal
sage: is_NumberFieldFractionalIdeal(2/3)
doctest:warning...
DeprecationWarning: The function is_NumberFieldFractionalIdeal is deprecated;
use 'isinstance(..., NumberFieldFractionalIdeal)' instead.
See https://github.com/sagemath/sage/issues/38124 for details.
False
sage: is_NumberFieldFractionalIdeal(ideal(5))
False
Expand All @@ -3330,6 +3342,10 @@ def is_NumberFieldFractionalIdeal(x):
sage: is_NumberFieldFractionalIdeal(Z)
False
"""
from sage.misc.superseded import deprecation
deprecation(38124,
"The function is_NumberFieldFractionalIdeal is deprecated; "
"use 'isinstance(..., NumberFieldFractionalIdeal)' instead.")
return isinstance(x, NumberFieldFractionalIdeal)


Expand Down
10 changes: 8 additions & 2 deletions src/sage/rings/number_field/number_field_ideal_rel.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,10 @@ def is_NumberFieldFractionalIdeal_rel(x):
sage: from sage.rings.number_field.number_field_ideal_rel import is_NumberFieldFractionalIdeal_rel
sage: from sage.rings.number_field.number_field_ideal import is_NumberFieldFractionalIdeal
sage: is_NumberFieldFractionalIdeal_rel(2/3)
doctest:warning...
DeprecationWarning: The function is_NumberFieldFractionalIdeal_rel is deprecated;
use 'isinstance(..., NumberFieldFractionalIdeal_rel' instead.
See https://github.com/sagemath/sage/issues/38124 for details.
False
sage: is_NumberFieldFractionalIdeal_rel(ideal(5))
False
Expand All @@ -911,7 +915,9 @@ def is_NumberFieldFractionalIdeal_rel(x):
Fractional ideal (-a)
sage: is_NumberFieldFractionalIdeal_rel(N)
False
sage: is_NumberFieldFractionalIdeal(N)
True
"""
from sage.misc.superseded import deprecation
deprecation(38124,
"The function is_NumberFieldFractionalIdeal_rel is deprecated; "
"use 'isinstance(..., NumberFieldFractionalIdeal_rel' instead.")
return isinstance(x, NumberFieldFractionalIdeal_rel)
21 changes: 15 additions & 6 deletions src/sage/rings/number_field/number_field_rel.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
from sage.categories.map import is_Map
from sage.structure.sequence import Sequence

import sage.rings.abc
import sage.structure.parent_gens

from . import maps
Expand All @@ -93,12 +94,12 @@

from . import number_field_element
import sage.rings.number_field.number_field_ideal_rel
from .number_field_ideal import is_NumberFieldIdeal
from .number_field_ideal import NumberFieldIdeal
from .number_field import (NumberField, NumberField_generic,
put_natural_embedding_first, proof_flag,
is_NumberFieldHomsetCodomain)
from sage.rings.number_field.number_field_base import NumberField as NumberField_base
from sage.rings.number_field.order import (RelativeOrder, is_NumberFieldOrder,
from sage.rings.number_field.order import (RelativeOrder,
relative_order_from_ring_generators)
from sage.rings.number_field.morphism import RelativeNumberFieldHomomorphism_from_abs
from sage.libs.pari.all import pari_gen
Expand All @@ -122,6 +123,10 @@ def is_RelativeNumberField(x):
sage: from sage.rings.number_field.number_field_rel import is_RelativeNumberField
sage: x = polygen(ZZ, 'x')
sage: is_RelativeNumberField(NumberField(x^2+1,'a'))
doctest:warning...
DeprecationWarning: The function is_RelativeNumberField is deprecated;
use 'isinstance(..., NumberField_relative)' instead.
See https://github.com/sagemath/sage/issues/38124 for details.
False
sage: k.<a> = NumberField(x^3 - 2)
sage: l.<b> = k.extension(x^3 - 3); l
Expand All @@ -131,6 +136,10 @@ def is_RelativeNumberField(x):
sage: is_RelativeNumberField(QQ)
False
"""
from sage.misc.superseded import deprecation
deprecation(38124,
"The function is_RelativeNumberField is deprecated; "
"use 'isinstance(..., NumberField_relative)' instead.")
return isinstance(x, NumberField_relative)


Expand Down Expand Up @@ -1013,9 +1022,9 @@ def _coerce_map_from_(self, R):
"""
if R is int:
return self._generic_coerce_map(R)
elif R in (ZZ, QQ, self.base_field()):
if R in (ZZ, QQ, self.base_field()):
return self._generic_coerce_map(R)
if is_NumberFieldOrder(R) and R.number_field() is self:
if isinstance(R, sage.rings.abc.Order) and R.number_field() is self:
return self._generic_coerce_map(R)
mor = self.base_field()._internal_coerce_map_from(R)
if mor is not None:
Expand Down Expand Up @@ -1310,7 +1319,7 @@ def is_isomorphic_relative(self, other, base_isom=None):
Ring endomorphism of Number Field in z9 with defining polynomial x^6 + x^3 + 1
Defn: z9 |--> z9^4
"""
if is_RelativeNumberField(other):
if isinstance(other, NumberField_relative):
s_base_field = self.base_field()
o_base_field = other.base_field()
if base_isom is None:
Expand Down Expand Up @@ -2722,7 +2731,7 @@ def uniformizer(self, P, others="positive"):
sage: (P, 1) in K.factor(u)
True
"""
if not is_NumberFieldIdeal(P):
if not isinstance(P, NumberFieldIdeal):
P = self.ideal(P)
if not P.is_maximal():
raise ValueError("P (=%s) must be a nonzero prime." % P)
Expand Down
12 changes: 10 additions & 2 deletions src/sage/rings/number_field/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,11 @@ def is_NumberFieldOrder(R):
sage: from sage.rings.number_field.order import is_NumberFieldOrder
sage: x = polygen(ZZ, 'x')
sage: is_NumberFieldOrder(NumberField(x^2 + 1,'a').maximal_order())
sage: is_NumberFieldOrder(NumberField(x^2 + 1, 'a').maximal_order())
doctest:warning...
DeprecationWarning: The function is_NumberFieldOrder is deprecated;
use 'isinstance(..., sage.rings.abc.Order) or ... == ZZ' instead.
See https://github.com/sagemath/sage/issues/38124 for details.
True
sage: is_NumberFieldOrder(ZZ)
True
Expand All @@ -371,6 +375,10 @@ def is_NumberFieldOrder(R):
sage: is_NumberFieldOrder(45)
False
"""
from sage.misc.superseded import deprecation
deprecation(38124,
"The function is_NumberFieldOrder is deprecated; "
"use 'isinstance(..., sage.rings.abc.Order) or ... == ZZ' instead.")
return isinstance(R, Order) or R == ZZ


Expand Down Expand Up @@ -2842,7 +2850,7 @@ def absolute_order_from_module_generators(gens,
raise ValueError("each generator must be integral")

K = gens.universe()
if is_NumberFieldOrder(K):
if isinstance(K, Order) or K == ZZ:
K = K.number_field()
V, from_V, to_V = K.vector_space()
mod_gens = [to_V(x) for x in gens]
Expand Down
7 changes: 3 additions & 4 deletions src/sage/rings/polynomial/multi_polynomial_libsingular.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ from sage.rings.integer_ring import is_IntegerRing, ZZ
from sage.rings.integer cimport Integer
from sage.rings.number_field.number_field_base cimport NumberField

from sage.rings.number_field.order import is_NumberFieldOrder
from sage.categories.number_fields import NumberFields

from sage.structure.element import coerce_binop
Expand Down Expand Up @@ -5614,7 +5613,7 @@ cdef class MPolynomial_libsingular(MPolynomial_libsingular_base):
return RealField(prec).zero()

K = self.base_ring()
if K in NumberFields() or is_NumberFieldOrder(K):
if K in NumberFields() or isinstance(K, sage.rings.abc.Order) or K == ZZ:
f = self
else:
raise TypeError("Must be over a Numberfield or a Numberfield Order.")
Expand Down Expand Up @@ -5666,7 +5665,7 @@ cdef class MPolynomial_libsingular(MPolynomial_libsingular_base):
prec = 53

K = FractionField(self.base_ring())
if K not in NumberFields() or is_NumberFieldOrder(K):
if K not in NumberFields() and not isinstance(K, sage.rings.abc.Order) and K != ZZ:
raise TypeError("must be over a Numberfield or a Numberfield order")

return max([K(c).local_height(v, prec=prec) for c in self.coefficients()])
Expand Down Expand Up @@ -5710,7 +5709,7 @@ cdef class MPolynomial_libsingular(MPolynomial_libsingular_base):
1.0
"""
K = FractionField(self.base_ring())
if K not in NumberFields() or is_NumberFieldOrder(K):
if K not in NumberFields() and not isinstance(K, sage.rings.abc.Order) and K != ZZ:
return TypeError("must be over a Numberfield or a Numberfield Order")

if K == QQ:
Expand Down
Loading

0 comments on commit b72d135

Please sign in to comment.