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 15 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.structure.element import NumberFieldElement
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):
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
5 changes: 2 additions & 3 deletions src/sage/rings/finite_rings/residue_field.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,8 @@ 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.structure.element cimport Element
from sage.structure.element cimport Element, NumberFieldElement

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 +294,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):
if p.parent().is_field():
p = p.parent().ring_of_integers().ideal(p)
else:
Expand Down
3 changes: 1 addition & 2 deletions src/sage/rings/integer_ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import sage.rings.ideal
from sage.categories.basic import EuclideanDomains
from sage.categories.infinite_enumerated_sets import InfiniteEnumeratedSets
from sage.structure.coerce cimport is_numpy_type
from sage.structure.element cimport parent
from sage.structure.element cimport parent, NumberFieldElement
from sage.structure.parent_gens import ParentWithGens
from sage.structure.parent cimport Parent
from sage.structure.richcmp cimport rich_to_bool
Expand Down Expand Up @@ -414,7 +414,6 @@ 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):
K, from_K = parent(x).subfield(x)
return K.order(K.gen())
Expand Down
Empty file.
4 changes: 3 additions & 1 deletion src/sage/rings/number_field/number_field_element.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ from sage.libs.gmp.types cimport mpz_t
from sage.rings.integer cimport Integer
from sage.rings.polynomial.polynomial_element cimport Polynomial
from sage.structure.element cimport FieldElement, RingElement, ModuleElement
from sage.structure.element cimport NumberFieldElement as NumberFieldElement_base
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
12 changes: 10 additions & 2 deletions src/sage/rings/number_field/number_field_element.pyx
Original file line number Diff line number Diff line change
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
4 changes: 2 additions & 2 deletions src/sage/rings/universal_cyclotomic_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@

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.element import FieldElement, parent, NumberFieldElement

from sage.structure.coerce import py_scalar_to_element
from sage.categories.morphism import Morphism
from sage.rings.ring import Field
Expand Down Expand Up @@ -1537,7 +1538,6 @@ 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):
from sage.rings.number_field.number_field import CyclotomicField
n = P.gen().multiplicative_order()
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
20 changes: 12 additions & 8 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.structure.element import NumberFieldElement


@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,7 +626,6 @@ 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:
raise NotImplementedError("is_cm_j_invariant() is only implemented for number field elements")

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
4 changes: 2 additions & 2 deletions src/sage/schemes/elliptic_curves/ell_number_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def height_pairing_matrix(self, points=None, precision=None, normalised=True):
RR = RealField()
else:
RR = RealField(precision)
from sage.matrix.all import MatrixSpace
from sage.matrix.matrix_space import MatrixSpace
M = MatrixSpace(RR, r)
mat = M()
for j in range(r):
Expand Down Expand Up @@ -3892,7 +3892,7 @@ def saturation(self, points, verbose=False,
raise ValueError("points not linearly independent in saturation()")
sat_reg = reg

from sage.rings.all import prime_range
from sage.rings.fast_arith import prime_range
if full_saturation:
if lower_ht_bound is None:
# TODO (robertwb): verify this for rank > 1
Expand Down
8 changes: 6 additions & 2 deletions src/sage/schemes/elliptic_curves/ell_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -2833,7 +2833,9 @@ def archimedean_local_height(self, v=None, prec=None, weighted=False):
4.0000000000000000000000000000000000000000000000000000000000
"""
from sage.rings.number_field.number_field import refine_embedding
from sage.all import RealField, ComplexField, Infinity
from sage.rings.real_mpfr import RealField
from sage.rings.complex_mpfr import ComplexField
from sage.rings.infinity import Infinity

E = self.curve()
K = E.base_ring()
Expand Down Expand Up @@ -3254,7 +3256,9 @@ def elliptic_logarithm(self, embedding=None, precision=100,
0.70448375537782208460499649302 - 0.79246725643650979858266018068*I
"""
from sage.rings.number_field.number_field import refine_embedding
from sage.rings.all import RealField, ComplexField, QQ
from sage.rings.real_mpfr import RealField
from sage.rings.complex_mpfr import ComplexField
from sage.rings.rational_field import QQ

# Check the trivial case:

Expand Down
Loading