Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoeppe committed Jan 24, 2023
2 parents c28996d + a9dacbe commit 81e875b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 7 deletions.
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
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
8 changes: 6 additions & 2 deletions src/sage/rings/number_field/number_field_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ def is_NumberFieldElement(x):
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 +194,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 @@ -3855,7 +3859,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
3 changes: 2 additions & 1 deletion src/sage/schemes/elliptic_curves/heegner.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
from sage.misc.verbose import verbose
from sage.misc.cachefunc import cached_method

from sage.structure.element import NumberFieldElement
from sage.structure.sage_object import SageObject
from sage.structure.richcmp import (richcmp_method, richcmp,
richcmp_not_equal, rich_to_bool)
Expand Down Expand Up @@ -2679,7 +2680,7 @@ def __init__(self, N, D, c=ZZ(1), f=None, check=True):
elif isinstance(f, BinaryQF):
# convert from BinaryQF
f = tuple(f)
elif sage.rings.number_field.number_field_element.is_NumberFieldElement(f):
elif isinstance(f, NumberFieldElement):
# tau = number field element
g = f.minpoly()
if g.degree() != 2:
Expand Down
3 changes: 3 additions & 0 deletions src/sage/structure/element.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ cdef class EuclideanDomainElement(PrincipalIdealDomainElement):
cdef class FieldElement(CommutativeRingElement):
cpdef _floordiv_(self, other)

cdef class NumberFieldElement(FieldElement):
pass

cdef class AlgebraElement(RingElement):
pass

Expand Down
24 changes: 24 additions & 0 deletions src/sage/structure/element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ abstract base classes.
PrincipalIdealDomainElement
EuclideanDomainElement
FieldElement
NumberFieldElement
CommutativeAlgebraElement
Expression
AlgebraElement
Expand Down Expand Up @@ -4276,6 +4277,29 @@ cdef class FieldElement(CommutativeRingElement):
other = self.parent()(other)
return bool(self) or other.is_zero()


cdef class NumberFieldElement(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: sage: k.<a> = NumberField(x^3 + x + 1)
sage: isinstance(a, sage.structure.element.NumberFieldElement)
True
By design, there is a unique direct subclass::
sage: len(sage.structure.element.NumberFieldElement.__subclasses__()) <= 1
True
"""

pass


def is_AlgebraElement(x):
"""
Return ``True`` if x is of type AlgebraElement.
Expand Down

0 comments on commit 81e875b

Please sign in to comment.