Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New ABC sage.structure.element.NumberFieldElement, deprecate is_NumberFieldElement #35100

Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/sage/interfaces/maxima_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,8 @@ def reduce_load_MaximaLib():
import sage.rings.real_double
import sage.symbolic.expression
import sage.symbolic.integration.integral

from sage.rings.number_field.number_field_element_base import NumberFieldElement_base
from sage.symbolic.operators import FDerivativeOperator, add_vararg, mul_vararg

car=EclObject("car")
Expand Down Expand Up @@ -1523,9 +1525,11 @@ def pyobject_to_max(obj):
"""
if isinstance(obj,sage.rings.rational.Rational):
return EclObject(obj) if (obj.denom().is_one()) else EclObject([[rat], obj.numer(),obj.denom()])
elif isinstance(obj,sage.rings.number_field.number_field_element_quadratic.NumberFieldElement_quadratic) and obj.parent().defining_polynomial().list() == [1,0,1]:
re, im = obj.list()
return EclObject([[mplus], pyobject_to_max(re), [[mtimes], pyobject_to_max(im), max_i]])
elif isinstance(obj, NumberFieldElement_base):
from sage.rings.number_field.number_field_element_quadratic import NumberFieldElement_quadratic
if isinstance(obj, NumberFieldElement_quadratic) and obj.parent().defining_polynomial().list() == [1,0,1]:
re, im = obj.list()
return EclObject([[mplus], pyobject_to_max(re), [[mtimes], pyobject_to_max(im), max_i]])
return EclObject(obj)

# This goes from SR to EclObject
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/finite_rings/residue_field.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ from sage.rings.finite_rings.finite_field_ntl_gf2e import FiniteField_ntl_gf2e
from sage.rings.finite_rings.finite_field_prime_modn import FiniteField_prime_modn
from sage.rings.finite_rings.finite_field_pari_ffelt import FiniteField_pari_ffelt
from sage.rings.ideal import is_Ideal
from sage.rings.number_field.number_field_element_base import NumberFieldElement_base
from sage.structure.element cimport Element

from sage.rings.number_field.number_field_element import is_NumberFieldElement
from sage.rings.number_field.number_field_ideal import is_NumberFieldIdeal

from sage.modules.free_module_element import FreeModuleElement
Expand Down Expand Up @@ -295,7 +295,7 @@ class ResidueFieldFactory(UniqueFactory):
if not is_Ideal(p):
if isinstance(p, (int, Integer, Rational)):
p = ZZ.ideal(p)
elif is_NumberFieldElement(p):
elif isinstance(p, NumberFieldElement_base):
if p.parent().is_field():
p = p.parent().ring_of_integers().ideal(p)
else:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/integer_ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import sage.libs.pari.all
import sage.rings.ideal
from sage.categories.basic import EuclideanDomains
from sage.categories.infinite_enumerated_sets import InfiniteEnumeratedSets
from sage.rings.number_field.number_field_element_base import NumberFieldElement_base
from sage.structure.coerce cimport is_numpy_type
from sage.structure.element cimport parent
from sage.structure.parent_gens import ParentWithGens
Expand Down Expand Up @@ -414,8 +415,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain):
if x in self:
return self

from sage.rings.number_field.number_field_element import NumberFieldElement
if isinstance(x, NumberFieldElement):
if isinstance(x, NumberFieldElement_base):
K, from_K = parent(x).subfield(x)
return K.order(K.gen())

Expand Down
Empty file.
5 changes: 3 additions & 2 deletions src/sage/rings/number_field/number_field_element.pxd
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
cimport sage.structure.element
from sage.libs.gmp.types cimport mpz_t
from sage.rings.integer cimport Integer
from sage.rings.number_field.number_field_element_base cimport NumberFieldElement_base
from sage.rings.polynomial.polynomial_element cimport Polynomial
from sage.structure.element cimport FieldElement, RingElement, ModuleElement
from sage.structure.parent cimport Parent
from sage.structure.parent_base cimport ParentWithBase
from sage.libs.ntl.types cimport ZZ_c, ZZX_c
from sage.libs.ntl.ntl_ZZX cimport ntl_ZZX
from sage.libs.ntl.ntl_ZZ cimport ntl_ZZ

cdef class NumberFieldElement(FieldElement):

cdef class NumberFieldElement(NumberFieldElement_base):
cdef ZZX_c __numerator
cdef ZZ_c __denominator
# Pointers to the defining polynomial (with numerator) for the field.
Expand Down
14 changes: 11 additions & 3 deletions src/sage/rings/number_field/number_field_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# distutils: extra_link_args = NTL_LIBEXTRA
# distutils: language = c++
"""
Number Field Elements
Number field elements (implementation using NTL)

AUTHORS:

Expand Down Expand Up @@ -108,11 +108,19 @@ def is_NumberFieldElement(x):

sage: from sage.rings.number_field.number_field_element import is_NumberFieldElement
sage: is_NumberFieldElement(2)
doctest:warning...
DeprecationWarning: is_NumberFieldElement is deprecated;
use isinstance(..., sage.structure.element.NumberFieldElement) instead
See https://trac.sagemath.org/34931 for details.
False
sage: k.<a> = NumberField(x^7 + 17*x + 1)
sage: is_NumberFieldElement(a+1)
True
"""
from sage.misc.superseded import deprecation
deprecation(34931,
'is_NumberFieldElement is deprecated; '
'use isinstance(..., sage.structure.element.NumberFieldElement) instead')
return isinstance(x, NumberFieldElement)


Expand Down Expand Up @@ -190,7 +198,7 @@ def _inverse_mod_generic(elt, I):
return I.small_residue(y)


cdef class NumberFieldElement(FieldElement):
cdef class NumberFieldElement(NumberFieldElement_base):
"""
An element of a number field.

Expand Down Expand Up @@ -3858,7 +3866,7 @@ cdef class NumberFieldElement(FieldElement):
"""
from .number_field_ideal import is_NumberFieldIdeal
if not is_NumberFieldIdeal(P):
if is_NumberFieldElement(P):
if isinstance(P, NumberFieldElement):
P = self.number_field().fractional_ideal(P)
else:
raise TypeError("P must be an ideal")
Expand Down
5 changes: 5 additions & 0 deletions src/sage/rings/number_field/number_field_element_base.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from sage.structure.element cimport FieldElement


cdef class NumberFieldElement_base(FieldElement):
pass
33 changes: 33 additions & 0 deletions src/sage/rings/number_field/number_field_element_base.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
r"""
Number field elements (abstract base class)
"""

# ****************************************************************************
# Copyright (C) 2023 Matthias Koeppe
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# https://www.gnu.org/licenses/
# ****************************************************************************

cdef class NumberFieldElement_base(FieldElement):
r"""
Abstract base class for :class:`~sage.rings.number_field.number_field_element.NumberFieldElement`

This class is defined for the purpose of :func:`isinstance` tests. It should not be
instantiated.

EXAMPLES::

sage: k.<a> = NumberField(x^3 + x + 1)
sage: isinstance(a, sage.rings.number_field.number_field_element_base.NumberFieldElement_base)
True

By design, there is a unique direct subclass::

sage: len(sage.rings.number_field.number_field_element_base.NumberFieldElement_base.__subclasses__()) <= 1
True
"""

pass
5 changes: 3 additions & 2 deletions src/sage/rings/universal_cyclotomic_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
from sage.structure.richcmp import rich_to_bool
from sage.structure.unique_representation import UniqueRepresentation
from sage.structure.element import FieldElement, parent

from sage.structure.coerce import py_scalar_to_element
from sage.categories.morphism import Morphism
from sage.rings.ring import Field
Expand All @@ -176,6 +177,7 @@
from sage.rings.rational import Rational

from sage.rings.integer_ring import ZZ
from sage.rings.number_field.number_field_element_base import NumberFieldElement_base
from sage.rings.rational_field import QQ
from sage.rings.infinity import Infinity
from sage.rings.qqbar import AA, QQbar
Expand Down Expand Up @@ -1537,8 +1539,7 @@ def _element_constructor_(self, elt):
import sage.rings.abc
P = parent(elt)
if isinstance(P, sage.rings.abc.NumberField_cyclotomic):
from sage.rings.number_field.number_field_element import NumberFieldElement
if isinstance(elt, NumberFieldElement):
if isinstance(elt, NumberFieldElement_base):
from sage.rings.number_field.number_field import CyclotomicField
n = P.gen().multiplicative_order()
elt = CyclotomicField(n)(elt)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/affine/affine_morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
from sage.misc.cachefunc import cached_method
from sage.misc.lazy_attribute import lazy_attribute

from sage.arith.all import gcd
from sage.arith.misc import GCD as gcd

from sage.rings.integer import Integer
from sage.rings.finite_rings.finite_field_constructor import is_PrimeFiniteField
Expand Down
6 changes: 4 additions & 2 deletions src/sage/schemes/elliptic_curves/BSD.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"Birch and Swinnerton-Dyer formulas"

from sage.arith.misc import prime_divisors
from sage.rings.all import ZZ, Infinity, QuadraticField
from sage.rings.integer_ring import ZZ
from sage.rings.infinity import Infinity
from sage.rings.number_field.number_field import QuadraticField
from sage.functions.other import ceil


Expand Down Expand Up @@ -480,7 +482,7 @@ def prove_BSD(E, verbosity=0, two_desc='mwrank', proof=None, secs_hi=5,
# We do not know BSD(E,p) for even a single p, since it's
# an open problem to show that L^r(E,1)/(Reg*Omega) is
# rational for any curve with r >= 2.
from sage.sets.all import Primes
from sage.sets.primes import Primes
BSD.primes = Primes()
if return_BSD:
BSD.rank = rank_lower_bd
Expand Down
5 changes: 4 additions & 1 deletion src/sage/schemes/elliptic_curves/cardinality.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
# ****************************************************************************
from .constructor import EllipticCurve, EllipticCurve_from_j
from sage.schemes.curves.projective_curve import Hasse_bounds
from sage.rings.all import Integer, ZZ, GF, polygen
from sage.rings.integer import Integer
from sage.rings.integer_ring import ZZ
from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF
from sage.rings.polynomial.polynomial_ring import polygen
from sage.groups.generic import order_from_bounds


Expand Down
22 changes: 13 additions & 9 deletions src/sage/schemes/elliptic_curves/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@
# ****************************************************************************

from sage.interfaces.magma import magma
from sage.rings.all import (Integer,
QQ,
ZZ,
IntegerRing,
is_fundamental_discriminant,
PolynomialRing)
from sage.rings.integer import Integer
from sage.rings.rational_field import QQ
from sage.rings.integer_ring import ZZ
from sage.rings.integer_ring import IntegerRing
from sage.rings.number_field.number_field import is_fundamental_discriminant
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing

from sage.misc.cachefunc import cached_function
from sage.rings.number_field.number_field_element_base import NumberFieldElement_base


@cached_function
def hilbert_class_polynomial(D, algorithm=None):
Expand Down Expand Up @@ -124,7 +126,8 @@ def hilbert_class_polynomial(D, algorithm=None):
raise ValueError("%s is not a valid algorithm" % algorithm)

from sage.quadratic_forms.binary_qf import BinaryQF_reduced_representatives
from sage.rings.all import RR, ComplexField
from sage.rings.real_mpfr import RR
from sage.rings.complex_mpfr import ComplexField
from sage.functions.all import elliptic_j

# get all primitive reduced quadratic forms, (necessary to exclude
Expand Down Expand Up @@ -623,8 +626,7 @@ def is_cm_j_invariant(j, method='new'):
True
"""
# First we check that j is an algebraic number:
from sage.rings.all import NumberFieldElement, NumberField
if not isinstance(j, NumberFieldElement) and j not in QQ:
if not isinstance(j, NumberFieldElement_base) and j not in QQ:
raise NotImplementedError("is_cm_j_invariant() is only implemented for number field elements")

# for j in ZZ we have a lookup-table:
Expand Down Expand Up @@ -670,6 +672,8 @@ def is_cm_j_invariant(j, method='new'):

K = j.parent()
if h < K.absolute_degree():
from sage.rings.number_field.number_field import NumberField

K = NumberField(jpol, 'j')
j = K.gen()

Expand Down
4 changes: 2 additions & 2 deletions src/sage/schemes/elliptic_curves/descent_two_isogeny.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ from sage.rings.integer_ring import ZZ
from sage.rings.polynomial.polynomial_ring import polygen
cdef object x_ZZ = polygen(ZZ)
from sage.rings.polynomial.real_roots import real_roots
from sage.arith.all import prime_divisors
from sage.all import ntl
from sage.arith.misc import prime_divisors
import sage.libs.ntl.all as ntl

from sage.rings.integer cimport Integer
from sage.libs.gmp.mpz cimport *
Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/elliptic_curves/ell_curve_isogeny.py
Original file line number Diff line number Diff line change
Expand Up @@ -2486,7 +2486,7 @@ def __compute_omega_general(self, E, psi, psi_pr, phi, phi_pr):
# thesis are wrong, the correct formulas
# are coded below

from sage.arith.all import binomial
from sage.arith.misc import binomial

for j in range(n - 1):
psi_prpr += binomial(j+2, 2) * psi[j+2] * cur_x_pow
Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/elliptic_curves/ell_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ def isogenies_prime_degree(self, l=None, max_l=31):
raise NotImplementedError("This code could be implemented for QQbar, but has not been yet.")

if l is None:
from sage.rings.all import prime_range
from sage.rings.fast_arith import prime_range
L = prime_range(max_l + 1)
else:
try:
Expand Down
22 changes: 14 additions & 8 deletions src/sage/schemes/elliptic_curves/ell_finite_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,24 @@
# https://www.gnu.org/licenses/
# ****************************************************************************

import sage.groups.generic as generic

from sage.arith.functions import lcm
from sage.arith.misc import binomial, GCD as gcd
from sage.groups.additive_abelian.additive_abelian_wrapper import AdditiveAbelianGroupWrapper
from sage.misc.cachefunc import cached_method
from sage.rings.finite_rings.element_base import is_FiniteFieldElement
from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF
from sage.rings.integer import Integer
from sage.rings.integer_ring import ZZ
from sage.rings.polynomial.polynomial_ring import polygen
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.schemes.curves.projective_curve import Hasse_bounds
from .ell_field import EllipticCurve_field
from .constructor import EllipticCurve
from sage.schemes.hyperelliptic_curves.hyperelliptic_finite_field import HyperellipticCurve_finite_field
from sage.rings.all import Integer, ZZ, PolynomialRing, GF, polygen
from sage.rings.finite_rings.element_base import is_FiniteFieldElement
import sage.groups.generic as generic

from . import ell_point
from sage.arith.all import gcd, lcm, binomial
from sage.misc.cachefunc import cached_method
from sage.groups.additive_abelian.additive_abelian_wrapper import AdditiveAbelianGroupWrapper
from .constructor import EllipticCurve
from .ell_field import EllipticCurve_field


class EllipticCurve_finite_field(EllipticCurve_field, HyperellipticCurve_finite_field):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/schemes/elliptic_curves/ell_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
import sage.groups.additive_abelian.additive_abelian_group as groups
import sage.groups.generic as generic

from sage.arith.all import lcm
from sage.arith.functions import lcm
import sage.rings.all as rings
from sage.misc.cachefunc import cached_method
from sage.misc.fast_methods import WithEqualityById
Expand Down
17 changes: 10 additions & 7 deletions src/sage/schemes/elliptic_curves/ell_modular_symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,22 @@
# http://www.gnu.org/licenses/
#*****************************************************************************

from sage.structure.sage_object import SageObject
from sage.modular.modsym.all import ModularSymbols
from sage.arith.misc import (kronecker as kronecker_symbol,
next_prime,
prime_divisors,
valuation)
from sage.databases.cremona import parse_cremona_label

from sage.arith.all import next_prime, kronecker_symbol, prime_divisors, valuation
from sage.misc.verbose import verbose
from sage.modular.cusps import Cusps
from sage.modular.modsym.all import ModularSymbols
from sage.rings.infinity import unsigned_infinity as infinity
from sage.rings.integer import Integer
from sage.modular.cusps import Cusps
from sage.rings.integer_ring import ZZ
from sage.rings.rational_field import QQ
from sage.misc.verbose import verbose
from sage.structure.sage_object import SageObject

from .constructor import EllipticCurve

from sage.schemes.elliptic_curves.constructor import EllipticCurve

oo = Cusps(infinity)
zero = Integer(0)
Expand Down
Loading